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/accountable.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 PageOwner, public Accountable 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 /* Specialised accounting methods. */ 56 57 unsigned int detach(); 58 59 Accessor *accessor() 60 { return _accessor; } 61 62 /* Interface for the pager. */ 63 64 Flexpage *get(offset_t offset, map_flags_t flags); 65 66 void queue(Flexpage *flexpage); 67 68 void flush_all(offset_t start, offset_t size); 69 70 offset_t get_data_size(); 71 72 void set_data_size(offset_t size); 73 74 /* Data transfer methods, implementing PageOwner. */ 75 76 void fill(Flexpage *flexpage); 77 78 void flush(Flexpage *flexpage, bool purge); 79 80 /* Interface for the page collection, implementing PageOwner. */ 81 82 void remove(Flexpage *flexpage); 83 }; 84 85 // vim: tabstop=4 expandtab shiftwidth=4