Message ID | 20240830-vfs-file-f_version-v1-5-6d3e4816aa7b@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | file: remove f_version | expand |
On Fri 30-08-24 15:04:46, Christian Brauner wrote: > Add a new helper and make vfs_setpos() call it. We will use it in > follow-up patches. > > Signed-off-by: Christian Brauner <brauner@kernel.org> Looks good. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza > --- > fs/read_write.c | 31 +++++++++++++++++++++++++------ > 1 file changed, 25 insertions(+), 6 deletions(-) > > diff --git a/fs/read_write.c b/fs/read_write.c > index 90e283b31ca1..66ff52860496 100644 > --- a/fs/read_write.c > +++ b/fs/read_write.c > @@ -40,18 +40,20 @@ static inline bool unsigned_offsets(struct file *file) > } > > /** > - * vfs_setpos - update the file offset for lseek > + * vfs_setpos_cookie - update the file offset for lseek and reset cookie > * @file: file structure in question > * @offset: file offset to seek to > * @maxsize: maximum file size > + * @cookie: cookie to reset > * > - * This is a low-level filesystem helper for updating the file offset to > - * the value specified by @offset if the given offset is valid and it is > - * not equal to the current file offset. > + * Update the file offset to the value specified by @offset if the given > + * offset is valid and it is not equal to the current file offset and > + * reset the specified cookie to indicate that a seek happened. > * > * Return the specified offset on success and -EINVAL on invalid offset. > */ > -loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) > +static loff_t vfs_setpos_cookie(struct file *file, loff_t offset, > + loff_t maxsize, u64 *cookie) > { > if (offset < 0 && !unsigned_offsets(file)) > return -EINVAL; > @@ -60,10 +62,27 @@ loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) > > if (offset != file->f_pos) { > file->f_pos = offset; > - file->f_version = 0; > + *cookie = 0; > } > return offset; > } > + > +/** > + * vfs_setpos - update the file offset for lseek > + * @file: file structure in question > + * @offset: file offset to seek to > + * @maxsize: maximum file size > + * > + * This is a low-level filesystem helper for updating the file offset to > + * the value specified by @offset if the given offset is valid and it is > + * not equal to the current file offset. > + * > + * Return the specified offset on success and -EINVAL on invalid offset. > + */ > +loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) > +{ > + return vfs_setpos_cookie(file, offset, maxsize, &file->f_version); > +} > EXPORT_SYMBOL(vfs_setpos); > > /** > > -- > 2.45.2 >
diff --git a/fs/read_write.c b/fs/read_write.c index 90e283b31ca1..66ff52860496 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -40,18 +40,20 @@ static inline bool unsigned_offsets(struct file *file) } /** - * vfs_setpos - update the file offset for lseek + * vfs_setpos_cookie - update the file offset for lseek and reset cookie * @file: file structure in question * @offset: file offset to seek to * @maxsize: maximum file size + * @cookie: cookie to reset * - * This is a low-level filesystem helper for updating the file offset to - * the value specified by @offset if the given offset is valid and it is - * not equal to the current file offset. + * Update the file offset to the value specified by @offset if the given + * offset is valid and it is not equal to the current file offset and + * reset the specified cookie to indicate that a seek happened. * * Return the specified offset on success and -EINVAL on invalid offset. */ -loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) +static loff_t vfs_setpos_cookie(struct file *file, loff_t offset, + loff_t maxsize, u64 *cookie) { if (offset < 0 && !unsigned_offsets(file)) return -EINVAL; @@ -60,10 +62,27 @@ loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) if (offset != file->f_pos) { file->f_pos = offset; - file->f_version = 0; + *cookie = 0; } return offset; } + +/** + * vfs_setpos - update the file offset for lseek + * @file: file structure in question + * @offset: file offset to seek to + * @maxsize: maximum file size + * + * This is a low-level filesystem helper for updating the file offset to + * the value specified by @offset if the given offset is valid and it is + * not equal to the current file offset. + * + * Return the specified offset on success and -EINVAL on invalid offset. + */ +loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) +{ + return vfs_setpos_cookie(file, offset, maxsize, &file->f_version); +} EXPORT_SYMBOL(vfs_setpos); /**
Add a new helper and make vfs_setpos() call it. We will use it in follow-up patches. Signed-off-by: Christian Brauner <brauner@kernel.org> --- fs/read_write.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)