1 /* 2 * A page mapper providing memory pages to satisfy file accesses. 3 * 4 * Copyright (C) 2021 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/page_owner.h> 27 28 #include <mutex> 29 30 31 32 /* A file mapper, associating flexpages with file regions. */ 33 34 class PageMapper : public PageOwner 35 { 36 protected: 37 AccessMap _map; 38 Accessor *_accessor; 39 Pages *_pages; 40 41 /* Serialisation of accesses. */ 42 43 std::mutex _lock; 44 45 /* Internal flexpage retrieval methods. */ 46 47 Flexpage *find(offset_t offset); 48 49 Flexpage *flexpage(offset_t offset); 50 51 public: 52 explicit PageMapper(Accessor *accessor, Pages *pages); 53 54 virtual ~PageMapper(); 55 56 Accessor *accessor() 57 { return _accessor; } 58 59 /* Interface for the pager. */ 60 61 Flexpage *get(offset_t offset, map_flags_t flags); 62 63 void queue(Flexpage *flexpage); 64 65 void flush_all(offset_t start, offset_t size); 66 67 offset_t get_data_size(); 68 69 void set_data_size(offset_t size); 70 71 /* Data transfer methods, implementing PageOwner. */ 72 73 void fill(Flexpage *flexpage); 74 75 void flush(Flexpage *flexpage, bool purge); 76 77 /* Interface for the page collection, implementing PageOwner. */ 78 79 void remove(Flexpage *flexpage); 80 }; 81 82 // vim: tabstop=4 expandtab shiftwidth=4