1 /* 2 * A page mapper providing memory pages to satisfy file accesses. 3 * 4 * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <fsserver/access_map.h> 25 #include <fsserver/accessor.h> 26 #include <fsserver/generic_page_mapper.h> 27 #include <fsserver/page_owner.h> 28 29 #include <mutex> 30 31 32 33 /* A file mapper, associating flexpages with file regions. */ 34 35 class PageMapper : public GenericPageMapper, public PageOwner 36 { 37 protected: 38 AccessMap _map; 39 Accessor *_accessor; 40 Pages *_pages; 41 42 /* Serialisation of accesses. */ 43 44 std::mutex _lock; 45 46 /* Internal flexpage retrieval methods. */ 47 48 Flexpage *find(offset_t offset); 49 50 Flexpage *flexpage(offset_t offset); 51 52 public: 53 explicit PageMapper(Accessor *accessor, Pages *pages); 54 55 virtual ~PageMapper(); 56 57 Accessor *accessor() 58 { return _accessor; } 59 60 /* Interface for the pager, implementing GenericPageMapper. */ 61 62 Flexpage *get(offset_t offset, map_flags_t flags); 63 64 void queue(Flexpage *flexpage); 65 66 void flush_all(offset_t start, offset_t size); 67 68 offset_t get_data_size(); 69 70 void set_data_size(offset_t size); 71 72 /* Data transfer methods, implementing PageOwner. */ 73 74 void fill(Flexpage *flexpage); 75 76 void flush(Flexpage *flexpage, bool purge); 77 78 /* Interface for the page collection, implementing PageOwner. */ 79 80 void remove(Flexpage *flexpage); 81 }; 82 83 // vim: tabstop=4 expandtab shiftwidth=4