1 /* 2 * General functionality supporting file paging. 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 <map> 25 #include <mutex> 26 27 #include <fsserver/accessor.h> 28 #include <fsserver/notification.h> 29 #include <fsserver/pager.h> 30 #include <fsserver/page_mapper.h> 31 32 33 34 /* Mapping type from file identifiers to page mappers. */ 35 36 typedef std::map<fileid_t, PageMapper *> FileMapping; 37 typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; 38 39 40 41 /* A registry of mappers for accessors. */ 42 43 class FilePaging : public NotificationSupport 44 { 45 protected: 46 Pages *_pages; 47 48 FileMapping _mappers; 49 std::mutex _lock; 50 51 /* Pager initialisation methods. */ 52 53 PageMapper *get_mapper(const char *path, fileid_t fileid); 54 55 Pager *get_pager(const char *path, fileid_t fileid, map_flags_t flags); 56 57 /* Configurable methods. */ 58 59 virtual map_flags_t get_flags(flags_t flags); 60 61 /* Configurable methods requiring implementation. */ 62 63 virtual fileid_t get_fileid(const char *path) = 0; 64 65 virtual Accessor *make_accessor(const char *path, fileid_t fileid) = 0; 66 67 /* Mapper registry access. */ 68 69 PageMapper *get(fileid_t fileid); 70 71 void remove(fileid_t fileid, PageMapper *mapper); 72 73 void set(fileid_t fileid, PageMapper *mapper); 74 75 public: 76 explicit FilePaging(Pages *pages); 77 78 /* Methods for the pager. */ 79 80 void detach_pager(fileid_t fileid, PageMapper *mapper); 81 }; 82 83 // vim: tabstop=4 expandtab shiftwidth=4