paul@93 | 1 | /* |
paul@144 | 2 | * A registry of objects supporting paging for files. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@9 | 22 | #pragma once |
paul@9 | 23 | |
paul@9 | 24 | #include <map> |
paul@9 | 25 | #include <mutex> |
paul@9 | 26 | |
paul@144 | 27 | #include <fsserver/file_opening.h> |
paul@141 | 28 | #include <fsserver/notification.h> |
paul@144 | 29 | #include <fsserver/page_mapper.h> |
paul@94 | 30 | #include <fsserver/pager.h> |
paul@144 | 31 | #include <fsserver/pages.h> |
paul@9 | 32 | |
paul@9 | 33 | |
paul@9 | 34 | |
paul@131 | 35 | /* Mapping type from file identifiers to page mappers. */ |
paul@9 | 36 | |
paul@78 | 37 | typedef std::map<fileid_t, PageMapper *> FileMapping; |
paul@78 | 38 | typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; |
paul@9 | 39 | |
paul@9 | 40 | |
paul@9 | 41 | |
paul@9 | 42 | /* A registry of mappers for accessors. */ |
paul@9 | 43 | |
paul@141 | 44 | class FilePaging : public NotificationSupport |
paul@9 | 45 | { |
paul@9 | 46 | protected: |
paul@79 | 47 | Pages *_pages; |
paul@78 | 48 | FileMapping _mappers; |
paul@9 | 49 | std::mutex _lock; |
paul@9 | 50 | |
paul@79 | 51 | /* Mapper registry access. */ |
paul@9 | 52 | |
paul@78 | 53 | PageMapper *get(fileid_t fileid); |
paul@9 | 54 | |
paul@106 | 55 | void remove(fileid_t fileid, PageMapper *mapper); |
paul@106 | 56 | |
paul@78 | 57 | void set(fileid_t fileid, PageMapper *mapper); |
paul@79 | 58 | |
paul@144 | 59 | /* Pager initialisation methods. */ |
paul@144 | 60 | |
paul@144 | 61 | map_flags_t get_flags(flags_t flags); |
paul@144 | 62 | |
paul@79 | 63 | public: |
paul@81 | 64 | explicit FilePaging(Pages *pages); |
paul@79 | 65 | |
paul@144 | 66 | /* Pager initialisation methods. */ |
paul@144 | 67 | |
paul@144 | 68 | long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); |
paul@144 | 69 | |
paul@156 | 70 | long get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager); |
paul@144 | 71 | |
paul@79 | 72 | /* Methods for the pager. */ |
paul@79 | 73 | |
paul@79 | 74 | void detach_pager(fileid_t fileid, PageMapper *mapper); |
paul@9 | 75 | }; |
paul@9 | 76 | |
paul@9 | 77 | // vim: tabstop=4 expandtab shiftwidth=4 |