From: Jeff Mahoney <jeffm@suse.com>
Subject: novfs: Fix ioctl usage
Patch-mainline: Whenever novfs is merged

 Upstream commit b19dd42faf413b4705d4adb38521e82d73fa4249 removed support
 for locked ioctls. This patch pushes the BKL into the novfs ioctl calls,
 switches to ->unlocked_ioctl, and removes ioctls that were empty.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/novfs/daemon.c |   22 ++++++++++++++++++----
 fs/novfs/inode.c  |   23 +----------------------
 fs/novfs/proc.c   |    4 ++--
 fs/novfs/vfs.h    |    4 ++--
 4 files changed, 23 insertions(+), 30 deletions(-)

--- a/fs/novfs/daemon.c
+++ b/fs/novfs/daemon.c
@@ -1022,11 +1022,14 @@ int novfs_daemon_debug_cmd_send(char *Co
 	return (retCode);
 }
 
-int novfs_daemon_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+long novfs_daemon_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	int retCode = -ENOSYS;
 	unsigned long cpylen;
 	struct novfs_schandle session_id;
+
+	lock_kernel(); /* needed? */
+
 	session_id = novfs_scope_get_sessionId(NULL);
 
 	switch (cmd) {
@@ -1046,8 +1049,10 @@ int novfs_daemon_ioctl(struct inode *ino
 			char *buf;
 			io.length = 0;
 			cpylen = copy_from_user(&io, (char *)arg, sizeof(io));
-			if (io.length <= 0 || io.length > 1024)
+			if (io.length <= 0 || io.length > 1024) {
+				unlock_kernel();
 				return -EINVAL;
+			}
 			if (io.length) {
 				buf = kmalloc(io.length + 1, GFP_KERNEL);
 				if (buf) {
@@ -1081,6 +1086,9 @@ int novfs_daemon_ioctl(struct inode *ino
 		}
 
 	}
+
+	unlock_kernel();
+
 	return (retCode);
 }
 
@@ -1337,13 +1345,15 @@ loff_t novfs_daemon_lib_llseek(struct fi
 
 #define DbgIocCall(str)		__DbgPrint("[VFS XPLAT] Call " str "\n")
 
-int novfs_daemon_lib_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+long novfs_daemon_lib_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	int retCode = -ENOSYS;
 	struct daemon_handle *dh;
 	void *handle = NULL;
 	unsigned long cpylen;
 
+	lock_kernel(); /* needed? */
+
 	dh = file->private_data;
 
 	DbgPrint("file=0x%p 0x%x 0x%p dh=0x%p", file, cmd, arg, dh);
@@ -1368,8 +1378,10 @@ int novfs_daemon_lib_ioctl(struct inode
 				char *buf;
 				io.length = 0;
 				cpylen = copy_from_user(&io, (void *)arg, sizeof(io));
-				if (io.length <= 0 || io.length > 1024)
+				if (io.length <= 0 || io.length > 1024) {
+					unlock_kernel();
 					return -EINVAL;
+				}
 				if (io.length) {
 					buf = kmalloc(io.length + 1, GFP_KERNEL);
 					if (buf) {
@@ -1596,6 +1608,8 @@ int novfs_daemon_lib_ioctl(struct inode
 		}
 	}
 
+	unlock_kernel();
+
 	return (retCode);
 }
 
--- a/fs/novfs/inode.c
+++ b/fs/novfs/inode.c
@@ -101,7 +101,6 @@ ssize_t novfs_a_direct_IO(int rw, struct
 ssize_t novfs_f_read(struct file *, char *, size_t, loff_t *);
 ssize_t novfs_f_write(struct file *, const char *, size_t, loff_t *);
 int novfs_f_readdir(struct file *, void *, filldir_t);
-int novfs_f_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
 int novfs_f_mmap(struct file *file, struct vm_area_struct *vma);
 int novfs_f_open(struct inode *, struct file *);
 int novfs_f_flush(struct file *, fl_owner_t);
@@ -151,8 +150,6 @@ ssize_t novfs_control_Read(struct file *
 
 ssize_t novfs_control_write(struct file *file, const char *buf, size_t nbytes, loff_t * ppos);
 
-int novfs_control_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
-
 int __init init_novfs(void);
 void __exit exit_novfs(void);
 
@@ -197,7 +194,6 @@ static struct file_operations novfs_file
 	.read = novfs_f_read,
 	.write = novfs_f_write,
 	.readdir = novfs_f_readdir,
-	.ioctl = novfs_f_ioctl,
 	.mmap = novfs_f_mmap,
 	.open = novfs_f_open,
 	.flush = novfs_f_flush,
@@ -254,7 +250,7 @@ static struct inode_operations novfs_fil
 
 static struct super_operations novfs_ops = {
 	.statfs = novfs_statfs,
-	.clear_inode = novfs_clear_inode,
+	.evict_inode = novfs_clear_inode,
 	.drop_inode = generic_delete_inode,
 	.show_options = novfs_show_options,
 
@@ -264,7 +260,6 @@ static struct super_operations novfs_ops
 static struct file_operations novfs_Control_operations = {
    .read    = novfs_Control_read,
    .write   = novfs_Control_write,
-   .ioctl   = novfs_Control_ioctl,
 };
 */
 
@@ -1277,13 +1272,6 @@ int novfs_f_readdir(struct file *file, v
 	return -EISDIR;
 }
 
-int novfs_f_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
-	DbgPrint("file=0x%p cmd=0x%x arg=0x%p", file, cmd, arg);
-
-	return -ENOSYS;
-}
-
 int novfs_f_mmap(struct file *file, struct vm_area_struct *vma)
 {
 	int retCode = -EINVAL;
@@ -3471,15 +3459,6 @@ ssize_t novfs_Control_write(struct file
 
 	return (retval);
 }
-
-int novfs_Control_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
-{
-	int retval = 0;
-
-	DbgPrint("kernel_locked 0x%x", kernel_locked());
-
-	return (retval);
-}
 
 static struct file_system_type novfs_fs_type = {
 	.name = "novfs",
--- a/fs/novfs/proc.c
+++ b/fs/novfs/proc.c
@@ -77,7 +77,7 @@ int novfs_proc_init(void)
 			novfs_daemon_proc_fops.release = novfs_daemon_close_control;
 			novfs_daemon_proc_fops.read = novfs_daemon_cmd_send;
 			novfs_daemon_proc_fops.write = novfs_daemon_recv_reply;
-			novfs_daemon_proc_fops.ioctl = novfs_daemon_ioctl;
+			novfs_daemon_proc_fops.unlocked_ioctl = novfs_daemon_ioctl;
 
 			Novfs_Control->proc_fops = &novfs_daemon_proc_fops;
 		} else {
@@ -99,7 +99,7 @@ int novfs_proc_init(void)
 			novfs_lib_proc_fops.read = novfs_daemon_lib_read;
 			novfs_lib_proc_fops.write = novfs_daemon_lib_write;
 			novfs_lib_proc_fops.llseek = novfs_daemon_lib_llseek;
-			novfs_lib_proc_fops.ioctl = novfs_daemon_lib_ioctl;
+			novfs_lib_proc_fops.unlocked_ioctl = novfs_daemon_lib_ioctl;
 			Novfs_Library->proc_fops = &novfs_lib_proc_fops;
 		} else {
 			remove_proc_entry("Control", novfs_procfs_dir);
--- a/fs/novfs/vfs.h
+++ b/fs/novfs/vfs.h
@@ -246,9 +246,9 @@ extern int novfs_daemon_get_userspace(st
 extern int novfs_daemon_debug_cmd_send(char *Command);
 extern ssize_t novfs_daemon_recv_reply(struct file *file, const char *buf, size_t nbytes, loff_t * ppos);
 extern ssize_t novfs_daemon_cmd_send(struct file *file, char *buf, size_t len, loff_t * off);
-extern int novfs_daemon_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
+extern long novfs_daemon_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 extern int novfs_daemon_lib_close(struct inode *inode, struct file *file);
-extern int novfs_daemon_lib_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
+extern long novfs_daemon_lib_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 extern int novfs_daemon_lib_open(struct inode *inode, struct file *file);
 extern ssize_t novfs_daemon_lib_read(struct file *file, char *buf, size_t len, loff_t * off);
 extern ssize_t novfs_daemon_lib_write(struct file *file, const char *buf, size_t len, loff_t * off);
