diff mbox series

[RFC,13/20] ocfs2: store cookie in private data

Message ID 20240830-vfs-file-f_version-v1-13-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/ocfs2/dir.c  |  3 ++-
 fs/ocfs2/file.c | 11 +++++++++--
 fs/ocfs2/file.h |  1 +
 3 files changed, 12 insertions(+), 3 deletions(-)

Comments

Jan Kara Sept. 3, 2024, 1:27 p.m. UTC | #1
On Fri 30-08-24 15:04:54, 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/ocfs2/dir.c  |  3 ++-
>  fs/ocfs2/file.c | 11 +++++++++--
>  fs/ocfs2/file.h |  1 +
>  3 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
> index f0beb173dbba..ccef3f42b333 100644
> --- a/fs/ocfs2/dir.c
> +++ b/fs/ocfs2/dir.c
> @@ -1932,6 +1932,7 @@ int ocfs2_readdir(struct file *file, struct dir_context *ctx)
>  {
>  	int error = 0;
>  	struct inode *inode = file_inode(file);
> +	struct ocfs2_file_private *fp = file->private_data;
>  	int lock_level = 0;
>  
>  	trace_ocfs2_readdir((unsigned long long)OCFS2_I(inode)->ip_blkno);
> @@ -1952,7 +1953,7 @@ int ocfs2_readdir(struct file *file, struct dir_context *ctx)
>  		goto bail_nolock;
>  	}
>  
> -	error = ocfs2_dir_foreach_blk(inode, &file->f_version, ctx, false);
> +	error = ocfs2_dir_foreach_blk(inode, &fp->cookie, ctx, false);
>  
>  	ocfs2_inode_unlock(inode, lock_level);
>  	if (error)
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index ccc57038a977..115ab2172820 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -2750,6 +2750,13 @@ static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in,
>  	return remapped > 0 ? remapped : ret;
>  }
>  
> +static loff_t ocfs2_dir_llseek(struct file *file, loff_t offset, int whence)
> +{
> +	struct ocfs2_file_private *fp = file->private_data;
> +
> +	return generic_llseek_cookie(file, offset, whence, &fp->cookie);
> +}
> +
>  const struct inode_operations ocfs2_file_iops = {
>  	.setattr	= ocfs2_setattr,
>  	.getattr	= ocfs2_getattr,
> @@ -2797,7 +2804,7 @@ const struct file_operations ocfs2_fops = {
>  
>  WRAP_DIR_ITER(ocfs2_readdir) // FIXME!
>  const struct file_operations ocfs2_dops = {
> -	.llseek		= generic_file_llseek,
> +	.llseek		= ocfs2_dir_llseek,
>  	.read		= generic_read_dir,
>  	.iterate_shared	= shared_ocfs2_readdir,
>  	.fsync		= ocfs2_sync_file,
> @@ -2843,7 +2850,7 @@ const struct file_operations ocfs2_fops_no_plocks = {
>  };
>  
>  const struct file_operations ocfs2_dops_no_plocks = {
> -	.llseek		= generic_file_llseek,
> +	.llseek		= ocfs2_dir_llseek,
>  	.read		= generic_read_dir,
>  	.iterate_shared	= shared_ocfs2_readdir,
>  	.fsync		= ocfs2_sync_file,
> diff --git a/fs/ocfs2/file.h b/fs/ocfs2/file.h
> index 8e53e4ac1120..41e65e45a9f3 100644
> --- a/fs/ocfs2/file.h
> +++ b/fs/ocfs2/file.h
> @@ -20,6 +20,7 @@ struct ocfs2_alloc_context;
>  enum ocfs2_alloc_restarted;
>  
>  struct ocfs2_file_private {
> +	u64			cookie;
>  	struct file		*fp_file;
>  	struct mutex		fp_mutex;
>  	struct ocfs2_lock_res	fp_flock;
> 
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index f0beb173dbba..ccef3f42b333 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -1932,6 +1932,7 @@  int ocfs2_readdir(struct file *file, struct dir_context *ctx)
 {
 	int error = 0;
 	struct inode *inode = file_inode(file);
+	struct ocfs2_file_private *fp = file->private_data;
 	int lock_level = 0;
 
 	trace_ocfs2_readdir((unsigned long long)OCFS2_I(inode)->ip_blkno);
@@ -1952,7 +1953,7 @@  int ocfs2_readdir(struct file *file, struct dir_context *ctx)
 		goto bail_nolock;
 	}
 
-	error = ocfs2_dir_foreach_blk(inode, &file->f_version, ctx, false);
+	error = ocfs2_dir_foreach_blk(inode, &fp->cookie, ctx, false);
 
 	ocfs2_inode_unlock(inode, lock_level);
 	if (error)
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index ccc57038a977..115ab2172820 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2750,6 +2750,13 @@  static loff_t ocfs2_remap_file_range(struct file *file_in, loff_t pos_in,
 	return remapped > 0 ? remapped : ret;
 }
 
+static loff_t ocfs2_dir_llseek(struct file *file, loff_t offset, int whence)
+{
+	struct ocfs2_file_private *fp = file->private_data;
+
+	return generic_llseek_cookie(file, offset, whence, &fp->cookie);
+}
+
 const struct inode_operations ocfs2_file_iops = {
 	.setattr	= ocfs2_setattr,
 	.getattr	= ocfs2_getattr,
@@ -2797,7 +2804,7 @@  const struct file_operations ocfs2_fops = {
 
 WRAP_DIR_ITER(ocfs2_readdir) // FIXME!
 const struct file_operations ocfs2_dops = {
-	.llseek		= generic_file_llseek,
+	.llseek		= ocfs2_dir_llseek,
 	.read		= generic_read_dir,
 	.iterate_shared	= shared_ocfs2_readdir,
 	.fsync		= ocfs2_sync_file,
@@ -2843,7 +2850,7 @@  const struct file_operations ocfs2_fops_no_plocks = {
 };
 
 const struct file_operations ocfs2_dops_no_plocks = {
-	.llseek		= generic_file_llseek,
+	.llseek		= ocfs2_dir_llseek,
 	.read		= generic_read_dir,
 	.iterate_shared	= shared_ocfs2_readdir,
 	.fsync		= ocfs2_sync_file,
diff --git a/fs/ocfs2/file.h b/fs/ocfs2/file.h
index 8e53e4ac1120..41e65e45a9f3 100644
--- a/fs/ocfs2/file.h
+++ b/fs/ocfs2/file.h
@@ -20,6 +20,7 @@  struct ocfs2_alloc_context;
 enum ocfs2_alloc_restarted;
 
 struct ocfs2_file_private {
+	u64			cookie;
 	struct file		*fp_file;
 	struct mutex		fp_mutex;
 	struct ocfs2_lock_res	fp_flock;