L4Re/departure

Annotated libfsserver/lib/files/file_pager.cc

206:0d2ae38e5142
2021-09-26 Paul Boddie Fixed subscription commentary for files.
paul@93 1
/*
paul@93 2
 * File-specific pager functionality.
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@8 22
#include "file_pager.h"
paul@10 23
#include "mapped_file_object_server.h"
paul@8 24
paul@93 25
paul@93 26
paul@200 27
/* Initialise a pager for a file with a unique file identifier, file provider,
paul@202 28
   mapping flags and a file registry. The provider offers a shared page mapper
paul@202 29
   for moderating access to loaded pages. */
paul@8 30
paul@200 31
FilePager::FilePager(fileid_t fileid, FileProvider *provider, map_flags_t flags,
paul@202 32
                     FileRegistry *registry)
paul@200 33
: Pager(provider->mapper(), flags),
paul@202 34
  _registry(registry), _provider(provider), fileid(fileid)
paul@8 35
{
paul@8 36
}
paul@8 37
paul@10 38
int FilePager::expected_items()
paul@10 39
{
paul@10 40
    return MappedFileObject_expected_items;
paul@10 41
}
paul@10 42
paul@10 43
ipc_server_handler_type FilePager::handler()
paul@10 44
{
paul@10 45
    return (ipc_server_handler_type) handle_MappedFileObject;
paul@10 46
}
paul@10 47
paul@78 48
paul@78 49
paul@201 50
/* Close the pager, removing the provider from the registry if appropriate. */
paul@79 51
paul@79 52
void FilePager::close()
paul@79 53
{
paul@141 54
    /* Notify other users of the file. */
paul@141 55
paul@200 56
    _provider->notify_others(_endpoint, NOTIFY_PEER_CLOSED);
paul@193 57
paul@200 58
    /* Detach the pager, potentially removing the file provider. */
paul@200 59
paul@202 60
    _registry->detach(fileid, _provider);
paul@79 61
}
paul@79 62
paul@79 63
paul@79 64
paul@78 65
/* File-specific operations. */
paul@78 66
paul@53 67
long FilePager::flush(offset_t populated_size, offset_t *size)
paul@53 68
{
paul@141 69
    long err = Pager::flush(populated_size, size);
paul@141 70
paul@141 71
    if (_resized)
paul@141 72
    {
paul@200 73
        _provider->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE);
paul@141 74
        _resized = false;
paul@141 75
    }
paul@141 76
paul@141 77
    return err;
paul@53 78
}
paul@53 79
paul@55 80
long FilePager::resize(offset_t *size)
paul@55 81
{
paul@141 82
    offset_t old_size = get_data_size();
paul@141 83
    long err = Pager::resize(size);
paul@141 84
paul@141 85
    /* If the size has changed, notify other users, but only after data has been
paul@141 86
       flushed. */
paul@141 87
paul@141 88
    if (old_size < get_data_size())
paul@141 89
        _resized = true;
paul@141 90
paul@141 91
    return err;
paul@55 92
}
paul@55 93
paul@90 94
long FilePager::mmap(offset_t position, offset_t length, offset_t *start_pos,
paul@90 95
                     offset_t *end_pos, offset_t *size)
paul@8 96
{
paul@8 97
    /* Set the limits of the paged region. */
paul@8 98
paul@90 99
    return Pager::mmap(position, length, start_pos, end_pos, size);
paul@8 100
}
paul@8 101
paul@78 102
paul@78 103
paul@78 104
/* Generic pager operations. */
paul@78 105
paul@121 106
long FilePager::map(offset_t offset, address_t hot_spot, map_flags_t flags, l4_snd_fpage_t *region)
paul@16 107
{
paul@16 108
    return Pager::map(offset, hot_spot, flags, region);
paul@16 109
}
paul@16 110
paul@141 111
paul@141 112
paul@141 113
/* Subscribe to notifications. */
paul@141 114
paul@193 115
long FilePager::subscribe(l4_cap_idx_t endpoint, notify_flags_t flags)
paul@141 116
{
paul@206 117
    /* Readers can subscribe to new data (flush) and file closed events.
paul@206 118
       Writers can subscribe to file closed events. */
paul@141 119
paul@200 120
    _endpoint = _provider->subscribe(endpoint, flags);
paul@141 121
    return L4_EOK;
paul@141 122
}
paul@141 123
paul@193 124
long FilePager::unsubscribe(l4_cap_idx_t endpoint)
paul@141 125
{
paul@200 126
    _provider->unsubscribe(_endpoint, endpoint);
paul@141 127
    return L4_EOK;
paul@141 128
}
paul@141 129
paul@8 130
// vim: tabstop=4 expandtab shiftwidth=4