LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl
@ 2008-01-17 12:44 Mathieu Segaud
  2008-01-17 12:44 ` [PATCH] reiserfs: coding style fixes Mathieu Segaud
  2008-01-28  5:54 ` [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Mathieu Segaud @ 2008-01-17 12:44 UTC (permalink / raw)
  To: reiserfs-devel; +Cc: reiserfs-devel, linux-kernel, akpm, Mathieu Segaud

Signed-off-by: Mathieu Segaud <mathieu.segaud@regala.cx>
---
 fs/reiserfs/dir.c           |    2 +-
 fs/reiserfs/file.c          |    2 +-
 fs/reiserfs/ioctl.c         |   96 +++++++++++++++++++++++++++---------------
 include/linux/reiserfs_fs.h |    2 +-
 4 files changed, 65 insertions(+), 37 deletions(-)

diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index e6b03d2..f267cf9 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -20,7 +20,7 @@ const struct file_operations reiserfs_dir_operations = {
 	.read = generic_read_dir,
 	.readdir = reiserfs_readdir,
 	.fsync = reiserfs_dir_fsync,
-	.ioctl = reiserfs_ioctl,
+	.unlocked_ioctl = reiserfs_ioctl,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = reiserfs_compat_ioctl,
 #endif
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index a804903..e4d415c 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -284,7 +284,7 @@ static ssize_t reiserfs_file_write(struct file *file,	/* the file we are going t
 const struct file_operations reiserfs_file_operations = {
 	.read = do_sync_read,
 	.write = reiserfs_file_write,
-	.ioctl = reiserfs_ioctl,
+	.unlocked_ioctl = reiserfs_ioctl,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = reiserfs_compat_ioctl,
 #endif
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index e0f0f09..691008d 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -21,80 +21,110 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp);
 **  2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
 **  3) That's all for a while ...
 */
-int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
-		   unsigned long arg)
+long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	unsigned int flags;
+	struct inode *inode;
+	long retval = 0;
+
+	lock_kernel();
+	inode = filp->f_dentry->d_inode;
 
 	switch (cmd) {
 	case REISERFS_IOC_UNPACK:
 		if (S_ISREG(inode->i_mode)) {
 			if (arg)
-				return reiserfs_unpack(inode, filp);
-			else
-				return 0;
+				retval = reiserfs_unpack(inode, filp);
 		} else
-			return -ENOTTY;
+			retval = -ENOTTY;
+		goto out;
 		/* following two cases are taken from fs/ext2/ioctl.c by Remy
 		   Card (card@masi.ibp.fr) */
 	case REISERFS_IOC_GETFLAGS:
-		if (!reiserfs_attrs(inode->i_sb))
-			return -ENOTTY;
+		if (!reiserfs_attrs(inode->i_sb)) {
+			retval = -ENOTTY;
+			goto out;
+		}
 
 		flags = REISERFS_I(inode)->i_attrs;
 		i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
-		return put_user(flags, (int __user *)arg);
+		retval = put_user(flags, (int __user *)arg);
+		goto out;
 	case REISERFS_IOC_SETFLAGS:{
-			if (!reiserfs_attrs(inode->i_sb))
-				return -ENOTTY;
+			if (!reiserfs_attrs(inode->i_sb)) {
+				retval = -ENOTTY;
+				goto out;
+			}
 
-			if (IS_RDONLY(inode))
-				return -EROFS;
+			if (IS_RDONLY(inode)) {
+				retval = -EROFS;
+				goto out;
+			}
 
-			if (!is_owner_or_cap(inode))
-				return -EPERM;
+			if (!is_owner_or_cap(inode)) {
+				retval = -EPERM;
+				goto out;
+			}
 
-			if (get_user(flags, (int __user *)arg))
-				return -EFAULT;
+			if (get_user(flags, (int __user *)arg)) {
+				retval = -EFAULT;
+				goto out;
+			}
 
 			/* Is it quota file? Do not allow user to mess with it. */
-			if (IS_NOQUOTA(inode))
-				return -EPERM;
+			if (IS_NOQUOTA(inode)) {
+				retval = -EPERM;
+				goto out;
+			}
 			if (((flags ^ REISERFS_I(inode)->
 			      i_attrs) & (REISERFS_IMMUTABLE_FL |
 					  REISERFS_APPEND_FL))
-			    && !capable(CAP_LINUX_IMMUTABLE))
-				return -EPERM;
+			    && !capable(CAP_LINUX_IMMUTABLE)) {
+				retval = -EPERM;
+				goto out;
+			}
 
 			if ((flags & REISERFS_NOTAIL_FL) &&
 			    S_ISREG(inode->i_mode)) {
 				int result;
 
 				result = reiserfs_unpack(inode, filp);
-				if (result)
+				if (result) {
+					unlock_kernel();
 					return result;
+				}
 			}
 			sd_attrs_to_i_attrs(flags, inode);
 			REISERFS_I(inode)->i_attrs = flags;
 			inode->i_ctime = CURRENT_TIME_SEC;
 			mark_inode_dirty(inode);
-			return 0;
+			goto out;
 		}
 	case REISERFS_IOC_GETVERSION:
-		return put_user(inode->i_generation, (int __user *)arg);
+		retval = put_user(inode->i_generation, (int __user *)arg);
+		goto out;
 	case REISERFS_IOC_SETVERSION:
-		if (!is_owner_or_cap(inode))
-			return -EPERM;
-		if (IS_RDONLY(inode))
-			return -EROFS;
-		if (get_user(inode->i_generation, (int __user *)arg))
-			return -EFAULT;
+		if (!is_owner_or_cap(inode)) {
+			retval = -EPERM;
+			goto out;
+		}
+		if (IS_RDONLY(inode)) {
+			retval = -EROFS;
+			goto out;
+		}
+		if (get_user(inode->i_generation, (int __user *)arg)) {
+			retval = -EFAULT;
+			goto out;
+		}
 		inode->i_ctime = CURRENT_TIME_SEC;
 		mark_inode_dirty(inode);
-		return 0;
+		goto out;
 	default:
-		return -ENOTTY;
+		retval = -ENOTTY;
 	}
+out:
+	unlock_kernel();
+	return retval;
 }
 
 #ifdef CONFIG_COMPAT
@@ -124,9 +154,7 @@ long reiserfs_compat_ioctl(struct file *file, unsigned int cmd,
 	default:
 		return -ENOIOCTLCMD;
 	}
-	lock_kernel();
 	ret = reiserfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
-	unlock_kernel();
 	return ret;
 }
 #endif
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 422eab4..4994327 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -2172,7 +2172,7 @@ __u32 r5_hash(const signed char *msg, int len);
 #define SPARE_SPACE 500
 
 /* prototypes from ioctl.c */
-int reiserfs_ioctl(struct inode *inode, struct file *filp,
+long reiserfs_ioctl(struct file *filp,
 		   unsigned int cmd, unsigned long arg);
 long reiserfs_compat_ioctl(struct file *filp,
 		   unsigned int cmd, unsigned long arg);
-- 
1.5.3.8


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] reiserfs: coding style fixes
  2008-01-17 12:44 [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl Mathieu Segaud
@ 2008-01-17 12:44 ` Mathieu Segaud
  2008-01-28  5:54 ` [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl Andrew Morton
  1 sibling, 0 replies; 4+ messages in thread
From: Mathieu Segaud @ 2008-01-17 12:44 UTC (permalink / raw)
  To: reiserfs-devel; +Cc: reiserfs-devel, linux-kernel, akpm, Mathieu Segaud

Signed-off-by: Mathieu Segaud <mathieu.segaud@regala.cx>
---
 fs/reiserfs/ioctl.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 691008d..1468be5 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -17,7 +17,8 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp);
 ** reiserfs_ioctl - handler for ioctl for inode
 ** supported commands:
 **  1) REISERFS_IOC_UNPACK - try to unpack tail from direct item into indirect
-**                           and prevent packing file (argument arg has to be non-zero)
+**                           and prevent packing file (argument arg has to be
+**			     non-zero)
 **  2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
 **  3) That's all for a while ...
 */
@@ -47,7 +48,7 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		}
 
 		flags = REISERFS_I(inode)->i_attrs;
-		i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
+		i_attrs_to_sd_attrs(inode, (__u16 *) &flags);
 		retval = put_user(flags, (int __user *)arg);
 		goto out;
 	case REISERFS_IOC_SETFLAGS:{
@@ -71,7 +72,10 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 				goto out;
 			}
 
-			/* Is it quota file? Do not allow user to mess with it. */
+			/*
+			 * Is it quota file?
+			 * Do not allow user to mess with it.
+			 */
 			if (IS_NOQUOTA(inode)) {
 				retval = -EPERM;
 				goto out;
@@ -182,9 +186,8 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp)
 		return 0;
 	}
 	/* ioctl already done */
-	if (REISERFS_I(inode)->i_flags & i_nopack_mask) {
+	if (REISERFS_I(inode)->i_flags & i_nopack_mask)
 		return 0;
-	}
 
 	/* we need to make sure nobody is changing the file size beneath
 	 ** us
@@ -200,16 +203,15 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp)
 	}
 
 	/* we unpack by finding the page with the tail, and calling
-	 ** reiserfs_prepare_write on that page.  This will force a 
+	 ** reiserfs_prepare_write on that page.  This will force a
 	 ** reiserfs_get_block to unpack the tail for us.
 	 */
 	index = inode->i_size >> PAGE_CACHE_SHIFT;
 	mapping = inode->i_mapping;
 	page = grab_cache_page(mapping, index);
 	retval = -ENOMEM;
-	if (!page) {
+	if (!page)
 		goto out;
-	}
 	retval = reiserfs_prepare_write(NULL, page, write_from, write_from);
 	if (retval)
 		goto out_unlock;
@@ -219,11 +221,11 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp)
 	retval = reiserfs_commit_write(NULL, page, write_from, write_from);
 	REISERFS_I(inode)->i_flags |= i_nopack_mask;
 
-      out_unlock:
+out_unlock:
 	unlock_page(page);
 	page_cache_release(page);
 
-      out:
+out:
 	mutex_unlock(&inode->i_mutex);
 	reiserfs_write_unlock(inode->i_sb);
 	return retval;
-- 
1.5.3.8


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl
  2008-01-17 12:44 [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl Mathieu Segaud
  2008-01-17 12:44 ` [PATCH] reiserfs: coding style fixes Mathieu Segaud
@ 2008-01-28  5:54 ` Andrew Morton
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2008-01-28  5:54 UTC (permalink / raw)
  To: Mathieu Segaud; +Cc: linux-kernel


I get a massive reject when applying this.  As usual.

I'm afraid that the days when one could prepare 2.6.x patches against the
2.6.x-1 tree are long past us.

Please resend after 2.6.25-rc1 or, better, redo against the
most-recently-released -mm kernel or, better, redo against
http://userweb.kernel.org/~akpm/mmotm/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl
@ 2008-01-17 11:54 Mathieu Segaud
  0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Segaud @ 2008-01-17 11:54 UTC (permalink / raw)
  To: reiserfs-devel; +Cc: reiserfs-devel, linux-kernel, akpm, Mathieu Segaud

Signed-off-by: Mathieu Segaud <mathieu.segaud@regala.cx>
---
 fs/reiserfs/dir.c           |    2 +-
 fs/reiserfs/file.c          |    2 +-
 fs/reiserfs/ioctl.c         |   94 ++++++++++++++++++++++++++++---------------
 include/linux/reiserfs_fs.h |    2 +-
 4 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index e6b03d2..f267cf9 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -20,7 +20,7 @@ const struct file_operations reiserfs_dir_operations = {
 	.read = generic_read_dir,
 	.readdir = reiserfs_readdir,
 	.fsync = reiserfs_dir_fsync,
-	.ioctl = reiserfs_ioctl,
+	.unlocked_ioctl = reiserfs_ioctl,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = reiserfs_compat_ioctl,
 #endif
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index a804903..e4d415c 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -284,7 +284,7 @@ static ssize_t reiserfs_file_write(struct file *file,	/* the file we are going t
 const struct file_operations reiserfs_file_operations = {
 	.read = do_sync_read,
 	.write = reiserfs_file_write,
-	.ioctl = reiserfs_ioctl,
+	.unlocked_ioctl = reiserfs_ioctl,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = reiserfs_compat_ioctl,
 #endif
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index e0f0f09..5da64ab 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -21,80 +21,110 @@ static int reiserfs_unpack(struct inode *inode, struct file *filp);
 **  2) REISERFS_IOC_[GS]ETFLAGS, REISERFS_IOC_[GS]ETVERSION
 **  3) That's all for a while ...
 */
-int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
-		   unsigned long arg)
+long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	unsigned int flags;
+	struct inode *inode;
+	long retval = 0;
+
+	lock_kernel();
+	inode = filp->f_dentry->d_inode;
 
 	switch (cmd) {
 	case REISERFS_IOC_UNPACK:
 		if (S_ISREG(inode->i_mode)) {
 			if (arg)
-				return reiserfs_unpack(inode, filp);
-			else
-				return 0;
+				retval = reiserfs_unpack(inode, filp);
 		} else
-			return -ENOTTY;
+			retval = -ENOTTY;
+		goto out;
 		/* following two cases are taken from fs/ext2/ioctl.c by Remy
 		   Card (card@masi.ibp.fr) */
 	case REISERFS_IOC_GETFLAGS:
-		if (!reiserfs_attrs(inode->i_sb))
-			return -ENOTTY;
+		if (!reiserfs_attrs(inode->i_sb)) {
+			retval = -ENOTTY;
+			goto out;
+		}
 
 		flags = REISERFS_I(inode)->i_attrs;
 		i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
-		return put_user(flags, (int __user *)arg);
+		retval = put_user(flags, (int __user *)arg);
+		goto out;
 	case REISERFS_IOC_SETFLAGS:{
-			if (!reiserfs_attrs(inode->i_sb))
-				return -ENOTTY;
+			if (!reiserfs_attrs(inode->i_sb)) {
+				retval = -ENOTTY;
+				goto out;
+			}
 
-			if (IS_RDONLY(inode))
-				return -EROFS;
+			if (IS_RDONLY(inode)) {
+				retval = -EROFS;
+				goto out;
+			}
 
-			if (!is_owner_or_cap(inode))
-				return -EPERM;
+			if (!is_owner_or_cap(inode)) {
+				retval = -EPERM;
+				goto out;
+			}
 
-			if (get_user(flags, (int __user *)arg))
-				return -EFAULT;
+			if (get_user(flags, (int __user *)arg)) {
+				retval = -EFAULT;
+				goto out;
+			}
 
 			/* Is it quota file? Do not allow user to mess with it. */
-			if (IS_NOQUOTA(inode))
-				return -EPERM;
+			if (IS_NOQUOTA(inode)) {
+				retval = -EPERM;
+				goto out;
+			}
 			if (((flags ^ REISERFS_I(inode)->
 			      i_attrs) & (REISERFS_IMMUTABLE_FL |
 					  REISERFS_APPEND_FL))
-			    && !capable(CAP_LINUX_IMMUTABLE))
-				return -EPERM;
+			    && !capable(CAP_LINUX_IMMUTABLE)) {
+				retval = -EPERM;
+				goto out;
+			}
 
 			if ((flags & REISERFS_NOTAIL_FL) &&
 			    S_ISREG(inode->i_mode)) {
 				int result;
 
 				result = reiserfs_unpack(inode, filp);
-				if (result)
+				if (result) {
+					unlock_kernel();
 					return result;
+				}
 			}
 			sd_attrs_to_i_attrs(flags, inode);
 			REISERFS_I(inode)->i_attrs = flags;
 			inode->i_ctime = CURRENT_TIME_SEC;
 			mark_inode_dirty(inode);
-			return 0;
+			goto out;
 		}
 	case REISERFS_IOC_GETVERSION:
-		return put_user(inode->i_generation, (int __user *)arg);
+		retval = put_user(inode->i_generation, (int __user *)arg);
+		goto out;
 	case REISERFS_IOC_SETVERSION:
-		if (!is_owner_or_cap(inode))
-			return -EPERM;
-		if (IS_RDONLY(inode))
-			return -EROFS;
-		if (get_user(inode->i_generation, (int __user *)arg))
-			return -EFAULT;
+		if (!is_owner_or_cap(inode)) {
+			retval = -EPERM;
+			goto out;
+		}
+		if (IS_RDONLY(inode)) {
+			retval = -EROFS;
+			goto out;
+		}
+		if (get_user(inode->i_generation, (int __user *)arg)) {
+			retval = -EFAULT;
+			goto out;
+		}
 		inode->i_ctime = CURRENT_TIME_SEC;
 		mark_inode_dirty(inode);
-		return 0;
+		goto out;
 	default:
-		return -ENOTTY;
+		retval = -ENOTTY;
 	}
+out:
+	unlock_kernel();
+	return retval;
 }
 
 #ifdef CONFIG_COMPAT
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index 422eab4..4994327 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -2172,7 +2172,7 @@ __u32 r5_hash(const signed char *msg, int len);
 #define SPARE_SPACE 500
 
 /* prototypes from ioctl.c */
-int reiserfs_ioctl(struct inode *inode, struct file *filp,
+long reiserfs_ioctl(struct file *filp,
 		   unsigned int cmd, unsigned long arg);
 long reiserfs_compat_ioctl(struct file *filp,
 		   unsigned int cmd, unsigned long arg);
-- 
1.5.3.8


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-01-28  5:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-17 12:44 [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl Mathieu Segaud
2008-01-17 12:44 ` [PATCH] reiserfs: coding style fixes Mathieu Segaud
2008-01-28  5:54 ` [PATCH] Convert reiserfs_ioctl() to an unlocked_ioctl Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2008-01-17 11:54 Mathieu Segaud

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).