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