Re: [PATCH v2 3/5]add metadata_readahead ioctl in vfs

Previous thread: [PATCH v2 2/5] implement metadata_incore in btrfs by Shaohua Li on Monday, January 3, 2011 - 10:40 pm. (1 message)

Next thread: [PATCH v2 4/5] implement metadata_ra in btrfs by Shaohua Li on Monday, January 3, 2011 - 10:40 pm. (1 message)
From: Shaohua Li
Date: Monday, January 3, 2011 - 10:40 pm

Add metadata readahead ioctl in vfs. Filesystem can hook to
super_operations.metadata_readahead to handle filesystem specific task.
Next patch will give an example how btrfs implements it.

Signed-off-by: Shaohua Li <shaohua.li@intel.com>

---
 fs/compat_ioctl.c  |    1 +
 fs/ioctl.c         |   21 +++++++++++++++++++++
 include/linux/fs.h |    8 ++++++++
 3 files changed, 30 insertions(+)

Index: linux/fs/ioctl.c
===================================================================
--- linux.orig/fs/ioctl.c	2011-01-03 21:15:48.000000000 +0800
+++ linux/fs/ioctl.c	2011-01-03 21:16:06.000000000 +0800
@@ -601,6 +601,24 @@ static int ioctl_metadata_incore(struct
 	return entries;
 }
 
+static int ioctl_metadata_readahead(struct file *filp, void __user *argp)
+{
+	struct super_block *sb = filp->f_path.dentry->d_inode->i_sb;
+	struct metadata_readahead_args args;
+
+	if (!sb->s_op->metadata_readahead)
+		return -EINVAL;
+
+	if (copy_from_user(&args, argp, sizeof(args)))
+		return -EFAULT;
+
+	/* readahead in page unit */
+	if ((args.offset & ~PAGE_CACHE_MASK) || (args.size & ~PAGE_CACHE_MASK))
+		return -EINVAL;
+
+	return sb->s_op->metadata_readahead(sb, args.offset, args.size);
+}
+
 /*
  * When you add any new common ioctls to the switches above and below
  * please update compat_sys_ioctl() too.
@@ -664,6 +682,9 @@ int do_vfs_ioctl(struct file *filp, unsi
 	case FIMETADATA_INCORE:
 		return ioctl_metadata_incore(filp, argp);
 
+	case FIMETADATA_READAHEAD:
+		return ioctl_metadata_readahead(filp, argp);
+
 	default:
 		if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
 			error = file_ioctl(filp, cmd, arg);
Index: linux/include/linux/fs.h
===================================================================
--- linux.orig/include/linux/fs.h	2011-01-03 21:15:48.000000000 +0800
+++ linux/include/linux/fs.h	2011-01-03 21:16:06.000000000 +0800
@@ -65,6 +65,11 @@ struct metadata_incore_args {
 	__u32 unused;
 };
 
+struct metadata_readahead_args {
+	__u64 ...
From: Arnd Bergmann
Date: Tuesday, January 4, 2011 - 2:51 am

Did you notice the comment above the function? ;-)

You should really add the new ioctls to compat_sys_ioctl, not
to the COMPATIBLE_IOCTL() list, in order to make the behavior
consistent between 32 and 64 bit user space. The main difference
is that all ioctl commands that are hardcoded in the functions
get called before trying to call the file system specific

This should be _IOW, not _IOR.

Otherwise looks good.

	Arnd
--

Previous thread: [PATCH v2 2/5] implement metadata_incore in btrfs by Shaohua Li on Monday, January 3, 2011 - 10:40 pm. (1 message)

Next thread: [PATCH v2 4/5] implement metadata_ra in btrfs by Shaohua Li on Monday, January 3, 2011 - 10:40 pm. (1 message)