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