1.1 --- a/docs/wiki/Components Fri May 10 15:09:04 2024 +0200
1.2 +++ b/docs/wiki/Components Fri May 10 19:19:33 2024 +0200
1.3 @@ -404,11 +404,13 @@
1.4 operation:
1.5
1.6 {{{
1.7 -current_region(out offset_t populated_size, out offset_t size)
1.8 +current_region(inout offset_t position, out offset_t populated_size, out offset_t size)
1.9 }}}
1.10
1.11 -This provides details of the populated size (or amount of written data) in a
1.12 -region along with the size of the region.
1.13 +This provides details of the recorded access position in a region, the
1.14 +populated size (or amount of written data) in a region along with the size of
1.15 +the region. For a writing endpoint, the position and populated size will be
1.16 +the same.
1.17
1.18 Navigation to the next available region of the pipe is performed using the
1.19 following operation:
2.1 --- a/libfsclient/include/fsclient/file.h Fri May 10 15:09:04 2024 +0200
2.2 +++ b/libfsclient/include/fsclient/file.h Fri May 10 19:19:33 2024 +0200
2.3 @@ -162,7 +162,7 @@
2.4
2.5 /* Pipe region operations. */
2.6
2.7 -long pipe_current(file_t *pipe);
2.8 +long pipe_current(file_t *pipe, int sync);
2.9 long pipe_next(file_t *pipe);
2.10 long pipe_written(file_t *pipe, offset_t size);
2.11
3.1 --- a/libfsclient/lib/src/client.cc Fri May 10 15:09:04 2024 +0200
3.2 +++ b/libfsclient/lib/src/client.cc Fri May 10 19:19:33 2024 +0200
3.3 @@ -209,7 +209,7 @@
3.4 if (file->object_flags & OBJECT_SUPPORTS_MMAP)
3.5 return client_mmap(file, client_tell(file), count, 0, 0,
3.6 file_region_flags(file->flags));
3.7 - else if (pipe_current(file))
3.8 + else if (pipe_current(file, 0))
3.9 return NULL;
3.10 }
3.11
3.12 @@ -305,17 +305,16 @@
3.13 return stream;
3.14 }
3.15
3.16 -/* Initialise the stream data position to the end of any existing data. */
3.17 +/* Initialise the stream data position to the end of any existing data for an
3.18 + output stream. For an input stream, initialise the position to the end of
3.19 + consumed data, preserving any unconsumed data. */
3.20
3.21 long client_sync_stream(file_t *file)
3.22 {
3.23 - long err = client_current_region(file);
3.24 + if (!client_opened(file))
3.25 + return -L4_EINVAL;
3.26
3.27 - if (err)
3.28 - return err;
3.29 -
3.30 - file->data_current = file->data_end;
3.31 - return err;
3.32 + return pipe_current(file, 1);
3.33 }
3.34
3.35
3.36 @@ -558,24 +557,15 @@
3.37
3.38
3.39
3.40 -/* Obtain the current region of a pipe. */
3.41 +/* Obtain the current region of a pipe, updating the extent of populated data
3.42 + and only changing the current position if no populated data exists. */
3.43
3.44 long client_current_region(file_t *file)
3.45 {
3.46 if (!client_opened(file))
3.47 return -L4_EINVAL;
3.48
3.49 - long err = pipe_current(file);
3.50 -
3.51 - if (err)
3.52 - return err;
3.53 -
3.54 - /* Handle any case where the current region has been exhausted. */
3.55 -
3.56 - if (!file_populated_span(file))
3.57 - file->data_current = 0;
3.58 -
3.59 - return L4_EOK;
3.60 + return pipe_current(file, 0);
3.61 }
3.62
3.63
3.64 @@ -616,13 +606,7 @@
3.65 if (!client_opened(file))
3.66 return -L4_EINVAL;
3.67
3.68 - long err = pipe_next(file);
3.69 -
3.70 - if (err)
3.71 - return err;
3.72 -
3.73 - file->data_current = 0;
3.74 - return L4_EOK;
3.75 + return pipe_next(file);
3.76 }
3.77
3.78
4.1 --- a/libfsclient/lib/src/file.cc Fri May 10 15:09:04 2024 +0200
4.2 +++ b/libfsclient/lib/src/file.cc Fri May 10 19:19:33 2024 +0200
4.3 @@ -680,16 +680,27 @@
4.4
4.5 /* Access the current region for a pipe endpoint. */
4.6
4.7 -long pipe_current(file_t *pipe)
4.8 +long pipe_current(file_t *pipe, int sync)
4.9 {
4.10 client_Pipe _pipe(pipe->ref);
4.11 - long err = _pipe.current_region(&pipe->data_end, &pipe->size);
4.12 + offset_t data_current;
4.13 + long err = _pipe.current_region(&data_current, &pipe->data_end, &pipe->size);
4.14
4.15 if (err)
4.16 return err;
4.17
4.18 pipe->end_pos = pipe->size;
4.19
4.20 + /* Obtain the current position if synchronising position state. */
4.21 +
4.22 + if (sync)
4.23 + pipe->data_current = data_current;
4.24 +
4.25 + /* Handle any case where the current region has been exhausted. */
4.26 +
4.27 + if (!file_populated_span(pipe))
4.28 + pipe->data_current = 0;
4.29 +
4.30 /* Attach memory if necessary. */
4.31
4.32 if (pipe->memory == NULL)
4.33 @@ -720,6 +731,7 @@
4.34 return err;
4.35
4.36 pipe->end_pos = pipe->size;
4.37 + pipe->data_current = 0;
4.38 pipe->memory = NULL;
4.39
4.40 err = ipc_attach_dataspace(pipe->ref, file_span(pipe), (void **) &pipe->memory);
5.1 --- a/libfsserver/include/fsserver/file_pager.h Fri May 10 15:09:04 2024 +0200
5.2 +++ b/libfsserver/include/fsserver/file_pager.h Fri May 10 19:19:33 2024 +0200
5.3 @@ -1,7 +1,7 @@
5.4 /*
5.5 * File-specific pager functionality.
5.6 *
5.7 - * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
5.8 + * Copyright (C) 2021, 2022, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
5.9 *
5.10 * This program is free software; you can redistribute it and/or
5.11 * modify it under the terms of the GNU General Public License as
5.12 @@ -63,7 +63,7 @@
5.13
5.14 /* File methods. */
5.15
5.16 - virtual long flush(offset_t populated_size, offset_t *size);
5.17 + virtual long flush(offset_t position, offset_t *size);
5.18
5.19 virtual long reopen(flags_t flags, offset_t *size, l4_cap_idx_t *file,
5.20 object_flags_t *object_flags);
6.1 --- a/libfsserver/include/fsserver/pager.h Fri May 10 15:09:04 2024 +0200
6.2 +++ b/libfsserver/include/fsserver/pager.h Fri May 10 19:19:33 2024 +0200
6.3 @@ -1,7 +1,7 @@
6.4 /*
6.5 * Generic pager functionality.
6.6 *
6.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
6.8 + * Copyright (C) 2021, 2022, 2024 Paul Boddie <paul@boddie.org.uk>
6.9 *
6.10 * This program is free software; you can redistribute it and/or
6.11 * modify it under the terms of the GNU General Public License as
6.12 @@ -53,7 +53,7 @@
6.13
6.14 /* File methods. */
6.15
6.16 - virtual long flush(offset_t populated_size, offset_t *size);
6.17 + virtual long flush(offset_t position, offset_t *size);
6.18
6.19 virtual long resize(offset_t *size);
6.20
7.1 --- a/libfsserver/include/fsserver/pipe_pager.h Fri May 10 15:09:04 2024 +0200
7.2 +++ b/libfsserver/include/fsserver/pipe_pager.h Fri May 10 19:19:33 2024 +0200
7.3 @@ -35,6 +35,7 @@
7.4 protected:
7.5 PipePaging *_paging;
7.6 bool _writing;
7.7 + offset_t _data_current;
7.8 l4_cap_idx_t _notifier = L4_INVALID_CAP;
7.9
7.10 /* Helper methods. */
7.11 @@ -65,13 +66,13 @@
7.12
7.13 virtual long closed(int *closed);
7.14
7.15 - virtual long current_region(offset_t *populated_size, offset_t *size);
7.16 + virtual long current_region(offset_t *position, offset_t *populated_size, offset_t *size);
7.17
7.18 virtual long next_region(offset_t *populated_size, offset_t *size);
7.19
7.20 /* Flushing/synchronisation. */
7.21
7.22 - virtual long flush(offset_t populated_size, offset_t *size);
7.23 + virtual long flush(offset_t position, offset_t *size);
7.24
7.25 /* Notification methods. */
7.26
8.1 --- a/libfsserver/lib/files/file_pager.cc Fri May 10 15:09:04 2024 +0200
8.2 +++ b/libfsserver/lib/files/file_pager.cc Fri May 10 19:19:33 2024 +0200
8.3 @@ -1,7 +1,7 @@
8.4 /*
8.5 * File-specific pager functionality.
8.6 *
8.7 - * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
8.8 + * Copyright (C) 2021, 2022, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
8.9 *
8.10 * This program is free software; you can redistribute it and/or
8.11 * modify it under the terms of the GNU General Public License as
8.12 @@ -64,9 +64,9 @@
8.13
8.14 /* File-specific operations. */
8.15
8.16 -long FilePager::flush(offset_t populated_size, offset_t *size)
8.17 +long FilePager::flush(offset_t position, offset_t *size)
8.18 {
8.19 - long err = Pager::flush(populated_size, size);
8.20 + long err = Pager::flush(position, size);
8.21
8.22 if (_resized)
8.23 {
9.1 --- a/libfsserver/lib/generic/pager.cc Fri May 10 15:09:04 2024 +0200
9.2 +++ b/libfsserver/lib/generic/pager.cc Fri May 10 19:19:33 2024 +0200
9.3 @@ -1,7 +1,7 @@
9.4 /*
9.5 * Generic pager functionality.
9.6 *
9.7 - * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
9.8 + * Copyright (C) 2021, 2022, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
9.9 *
9.10 * This program is free software; you can redistribute it and/or
9.11 * modify it under the terms of the GNU General Public License as
9.12 @@ -59,9 +59,9 @@
9.13
9.14 /* Flush data to the file. */
9.15
9.16 -long Pager::flush(offset_t populated_size, offset_t *size)
9.17 +long Pager::flush(offset_t position, offset_t *size)
9.18 {
9.19 - _mapper->flush_all(_start, populated_size);
9.20 + _mapper->flush_all(_start, position);
9.21
9.22 *size = _mapper->get_data_size();
9.23 return L4_EOK;
10.1 --- a/libfsserver/lib/pipes/pipe_pager.cc Fri May 10 15:09:04 2024 +0200
10.2 +++ b/libfsserver/lib/pipes/pipe_pager.cc Fri May 10 19:19:33 2024 +0200
10.3 @@ -36,6 +36,10 @@
10.4
10.5 _size = _paging->region_size();
10.6
10.7 + /* Initialise any recorded position in the region. */
10.8 +
10.9 + _data_current = 0;
10.10 +
10.11 /* Obtain any initial page mapper, this having been set up in the paging
10.12 coordinator. */
10.13
10.14 @@ -92,10 +96,13 @@
10.15
10.16 /* Return details of the current region. */
10.17
10.18 -long PipePager::current_region(offset_t *populated_size, offset_t *size)
10.19 +long PipePager::current_region(offset_t *position, offset_t *populated_size, offset_t *size)
10.20 {
10.21 if (_mapper != NULL)
10.22 {
10.23 + if (position != NULL)
10.24 + *position = _data_current;
10.25 +
10.26 *populated_size = _mapper->get_data_size();
10.27 *size = _size;
10.28 return L4_EOK;
10.29 @@ -124,8 +131,9 @@
10.30 return pipe_error();
10.31
10.32 _mapper = mapper;
10.33 + _data_current = 0;
10.34
10.35 - return current_region(populated_size, size);
10.36 + return current_region(NULL, populated_size, size);
10.37 }
10.38
10.39 long PipePager::next_region_for_writer(offset_t *populated_size, offset_t *size)
10.40 @@ -143,8 +151,9 @@
10.41 return pipe_error();
10.42
10.43 _mapper = mapper;
10.44 + _data_current = 0;
10.45
10.46 - return current_region(populated_size, size);
10.47 + return current_region(NULL, populated_size, size);
10.48 }
10.49
10.50 long PipePager::pipe_error()
10.51 @@ -157,12 +166,19 @@
10.52
10.53
10.54
10.55 -/* Update the populated size of a pipe region and notify the other endpoint. */
10.56 +/* Update the consumed or populated size of a pipe region and notify the other
10.57 + endpoint. The consumed size is recorded to allow pipes to be shared between
10.58 + programs. */
10.59
10.60 -long PipePager::flush(offset_t populated_size, offset_t *size)
10.61 +long PipePager::flush(offset_t position, offset_t *size)
10.62 {
10.63 - if (_writing && (_mapper != NULL))
10.64 - _mapper->set_data_size(populated_size);
10.65 + if (_mapper != NULL)
10.66 + {
10.67 + _data_current = position;
10.68 +
10.69 + if (_writing)
10.70 + _mapper->set_data_size(position);
10.71 + }
10.72
10.73 *size = _size;
10.74
11.1 --- a/libsystypes/idl/flush.idl Fri May 10 15:09:04 2024 +0200
11.2 +++ b/libsystypes/idl/flush.idl Fri May 10 19:19:33 2024 +0200
11.3 @@ -4,7 +4,9 @@
11.4
11.5 interface Flush
11.6 {
11.7 - /* Flush data and update the size, if appropriate. */
11.8 + /* Flush data and update the size, if appropriate. When writing, the position
11.9 + indicates the populated size of the object; when reading, the position
11.10 + indicates the point from which data is being consumed by a client. */
11.11
11.12 - [opcode(5)] void flush(in offset_t populated_size, out offset_t size);
11.13 + [opcode(5)] void flush(in offset_t position, out offset_t size);
11.14 };
12.1 --- a/libsystypes/idl/pipe.idl Fri May 10 15:09:04 2024 +0200
12.2 +++ b/libsystypes/idl/pipe.idl Fri May 10 19:19:33 2024 +0200
12.3 @@ -6,7 +6,7 @@
12.4 {
12.5 /* Obtain details of the current region of shared memory. */
12.6
12.7 - [opcode(16)] void current_region(out offset_t populated_size, out offset_t size);
12.8 + [opcode(16)] void current_region(inout offset_t position, out offset_t populated_size, out offset_t size);
12.9
12.10 /* Advance to the next region of shared memory, indicating and obtaining the
12.11 populated limit of the region and obtaining the region size. */