paul@93 | 1 | /* |
paul@93 | 2 | * A page mapper providing memory pages to satisfy file accesses. |
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@6 | 22 | #pragma once |
paul@6 | 23 | |
paul@94 | 24 | #include <fsserver/access_map.h> |
paul@94 | 25 | #include <fsserver/accessor.h> |
paul@94 | 26 | #include <fsserver/page_owner.h> |
paul@6 | 27 | |
paul@6 | 28 | #include <mutex> |
paul@6 | 29 | |
paul@93 | 30 | |
paul@93 | 31 | |
paul@6 | 32 | /* A file mapper, associating flexpages with file regions. */ |
paul@6 | 33 | |
paul@6 | 34 | class PageMapper : public PageOwner |
paul@6 | 35 | { |
paul@6 | 36 | protected: |
paul@6 | 37 | AccessMap _map; |
paul@6 | 38 | Accessor *_accessor; |
paul@72 | 39 | Pages *_pages; |
paul@6 | 40 | unsigned int _attached; |
paul@78 | 41 | |
paul@78 | 42 | /* Serialisation of accesses. */ |
paul@78 | 43 | |
paul@6 | 44 | std::mutex _lock; |
paul@6 | 45 | |
paul@6 | 46 | /* Internal flexpage retrieval methods. */ |
paul@6 | 47 | |
paul@6 | 48 | Flexpage *find(offset_t offset); |
paul@6 | 49 | |
paul@6 | 50 | Flexpage *flexpage(offset_t offset); |
paul@6 | 51 | |
paul@6 | 52 | public: |
paul@72 | 53 | explicit PageMapper(Accessor *accessor, Pages *pages); |
paul@6 | 54 | |
paul@6 | 55 | /* Accounting methods. */ |
paul@6 | 56 | |
paul@6 | 57 | void attach(); |
paul@6 | 58 | |
paul@6 | 59 | unsigned int detach(); |
paul@6 | 60 | |
paul@78 | 61 | Accessor *accessor() |
paul@78 | 62 | { return _accessor; } |
paul@78 | 63 | |
paul@80 | 64 | /* Interface for the pager. */ |
paul@80 | 65 | |
paul@54 | 66 | Flexpage *get(offset_t offset, flags_t flags); |
paul@6 | 67 | |
paul@6 | 68 | void queue(Flexpage *flexpage); |
paul@6 | 69 | |
paul@6 | 70 | void flush_all(offset_t start, offset_t size); |
paul@6 | 71 | |
paul@6 | 72 | offset_t get_data_size(); |
paul@6 | 73 | |
paul@53 | 74 | void set_data_size(offset_t size); |
paul@53 | 75 | |
paul@6 | 76 | /* Data transfer methods, implementing PageOwner. */ |
paul@6 | 77 | |
paul@6 | 78 | void fill(Flexpage *flexpage); |
paul@6 | 79 | |
paul@6 | 80 | void flush(Flexpage *flexpage, bool purge); |
paul@6 | 81 | |
paul@6 | 82 | /* Interface for the page collection, implementing PageOwner. */ |
paul@6 | 83 | |
paul@6 | 84 | void remove(Flexpage *flexpage); |
paul@6 | 85 | }; |
paul@6 | 86 | |
paul@6 | 87 | // vim: tabstop=4 expandtab shiftwidth=4 |