diff mbox series

[RFC,15/20] udf: store cookie in private data

Message ID 20240830-vfs-file-f_version-v1-15-6d3e4816aa7b@kernel.org (mailing list archive)
State New
Headers show
Series file: remove f_version | expand

Commit Message

Christian Brauner Aug. 30, 2024, 1:04 p.m. UTC
Store the cookie to detect concurrent seeks on directories in
file->private_data.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/udf/dir.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Comments

Jan Kara Sept. 3, 2024, 1:37 p.m. UTC | #1
On Fri 30-08-24 15:04:56, Christian Brauner wrote:
> Store the cookie to detect concurrent seeks on directories in
> file->private_data.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/udf/dir.c | 28 +++++++++++++++++++++++++---
>  1 file changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/udf/dir.c b/fs/udf/dir.c
> index f94f45fe2c91..5023dfe191e8 100644
> --- a/fs/udf/dir.c
> +++ b/fs/udf/dir.c
> @@ -60,7 +60,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
>  	 * identifying beginning of dir entry (names are under user control),
>  	 * we need to scan the directory from the beginning.
>  	 */
> -	if (!inode_eq_iversion(dir, file->f_version)) {
> +	if (!inode_eq_iversion(dir, *(u64 *)file->private_data)) {
>  		emit_pos = nf_pos;
>  		nf_pos = 0;
>  	} else {
> @@ -122,15 +122,37 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
>  	udf_fiiter_release(&iter);
>  out:
>  	if (pos_valid)
> -		file->f_version = inode_query_iversion(dir);
> +		*(u64 *)file->private_data = inode_query_iversion(dir);
>  	kfree(fname);
>  
>  	return ret;
>  }
>  
> +static int udf_dir_open(struct inode *inode, struct file *file)
> +{
> +	file->private_data = kzalloc(sizeof(u64), GFP_KERNEL);
> +	if (!file->private_data)
> +		return -ENOMEM;
> +	return 0;
> +}
> +
> +static int udf_dir_release(struct inode *inode, struct file *file)
> +{
> +	kfree(file->private_data);
> +	return 0;
> +}
> +
> +static loff_t udf_dir_llseek(struct file *file, loff_t offset, int whence)
> +{
> +	return generic_llseek_cookie(file, offset, whence,
> +				     (u64 *)file->private_data);
> +}
> +
>  /* readdir and lookup functions */
>  const struct file_operations udf_dir_operations = {
> -	.llseek			= generic_file_llseek,
> +	.open			= udf_dir_open,
> +	.release		= udf_dir_release,
> +	.llseek			= udf_dir_llseek,
>  	.read			= generic_read_dir,
>  	.iterate_shared		= udf_readdir,
>  	.unlocked_ioctl		= udf_ioctl,
> 
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index f94f45fe2c91..5023dfe191e8 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -60,7 +60,7 @@  static int udf_readdir(struct file *file, struct dir_context *ctx)
 	 * identifying beginning of dir entry (names are under user control),
 	 * we need to scan the directory from the beginning.
 	 */
-	if (!inode_eq_iversion(dir, file->f_version)) {
+	if (!inode_eq_iversion(dir, *(u64 *)file->private_data)) {
 		emit_pos = nf_pos;
 		nf_pos = 0;
 	} else {
@@ -122,15 +122,37 @@  static int udf_readdir(struct file *file, struct dir_context *ctx)
 	udf_fiiter_release(&iter);
 out:
 	if (pos_valid)
-		file->f_version = inode_query_iversion(dir);
+		*(u64 *)file->private_data = inode_query_iversion(dir);
 	kfree(fname);
 
 	return ret;
 }
 
+static int udf_dir_open(struct inode *inode, struct file *file)
+{
+	file->private_data = kzalloc(sizeof(u64), GFP_KERNEL);
+	if (!file->private_data)
+		return -ENOMEM;
+	return 0;
+}
+
+static int udf_dir_release(struct inode *inode, struct file *file)
+{
+	kfree(file->private_data);
+	return 0;
+}
+
+static loff_t udf_dir_llseek(struct file *file, loff_t offset, int whence)
+{
+	return generic_llseek_cookie(file, offset, whence,
+				     (u64 *)file->private_data);
+}
+
 /* readdir and lookup functions */
 const struct file_operations udf_dir_operations = {
-	.llseek			= generic_file_llseek,
+	.open			= udf_dir_open,
+	.release		= udf_dir_release,
+	.llseek			= udf_dir_llseek,
 	.read			= generic_read_dir,
 	.iterate_shared		= udf_readdir,
 	.unlocked_ioctl		= udf_ioctl,