Merge tag 'usb-3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[firefly-linux-kernel-4.4.55.git] / fs / xfs / xfs_ioctl.c
index 3a05a41b5d76b8bfbbc6399d287f78b56e06ccc4..0e0232c3b6d98039eb2b73fb556faec1b9069016 100644 (file)
@@ -208,6 +208,7 @@ xfs_open_by_handle(
        struct inode            *inode;
        struct dentry           *dentry;
        fmode_t                 fmode;
+       struct path             path;
 
        if (!capable(CAP_SYS_ADMIN))
                return -XFS_ERROR(EPERM);
@@ -252,8 +253,10 @@ xfs_open_by_handle(
                goto out_dput;
        }
 
-       filp = dentry_open(dentry, mntget(parfilp->f_path.mnt),
-                          hreq->oflags, cred);
+       path.mnt = parfilp->f_path.mnt;
+       path.dentry = dentry;
+       filp = dentry_open(&path, hreq->oflags, cred);
+       dput(dentry);
        if (IS_ERR(filp)) {
                put_unused_fd(fd);
                return PTR_ERR(filp);
@@ -361,9 +364,15 @@ xfs_fssetdm_by_handle(
        if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
+       error = mnt_want_write_file(parfilp);
+       if (error)
+               return error;
+
        dentry = xfs_handlereq_to_dentry(parfilp, &dmhreq.hreq);
-       if (IS_ERR(dentry))
+       if (IS_ERR(dentry)) {
+               mnt_drop_write_file(parfilp);
                return PTR_ERR(dentry);
+       }
 
        if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) {
                error = -XFS_ERROR(EPERM);
@@ -379,6 +388,7 @@ xfs_fssetdm_by_handle(
                                 fsd.fsd_dmstate);
 
  out:
+       mnt_drop_write_file(parfilp);
        dput(dentry);
        return error;
 }
@@ -631,7 +641,11 @@ xfs_ioc_space(
        if (ioflags & IO_INVIS)
                attr_flags |= XFS_ATTR_DMI;
 
+       error = mnt_want_write_file(filp);
+       if (error)
+               return error;
        error = xfs_change_file_space(ip, cmd, bf, filp->f_pos, attr_flags);
+       mnt_drop_write_file(filp);
        return -error;
 }
 
@@ -1160,6 +1174,7 @@ xfs_ioc_fssetxattr(
 {
        struct fsxattr          fa;
        unsigned int            mask;
+       int error;
 
        if (copy_from_user(&fa, arg, sizeof(fa)))
                return -EFAULT;
@@ -1168,7 +1183,12 @@ xfs_ioc_fssetxattr(
        if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
                mask |= FSX_NONBLOCK;
 
-       return -xfs_ioctl_setattr(ip, &fa, mask);
+       error = mnt_want_write_file(filp);
+       if (error)
+               return error;
+       error = xfs_ioctl_setattr(ip, &fa, mask);
+       mnt_drop_write_file(filp);
+       return -error;
 }
 
 STATIC int
@@ -1193,6 +1213,7 @@ xfs_ioc_setxflags(
        struct fsxattr          fa;
        unsigned int            flags;
        unsigned int            mask;
+       int error;
 
        if (copy_from_user(&flags, arg, sizeof(flags)))
                return -EFAULT;
@@ -1207,7 +1228,12 @@ xfs_ioc_setxflags(
                mask |= FSX_NONBLOCK;
        fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
 
-       return -xfs_ioctl_setattr(ip, &fa, mask);
+       error = mnt_want_write_file(filp);
+       if (error)
+               return error;
+       error = xfs_ioctl_setattr(ip, &fa, mask);
+       mnt_drop_write_file(filp);
+       return -error;
 }
 
 STATIC int
@@ -1382,8 +1408,13 @@ xfs_file_ioctl(
                if (copy_from_user(&dmi, arg, sizeof(dmi)))
                        return -XFS_ERROR(EFAULT);
 
+               error = mnt_want_write_file(filp);
+               if (error)
+                       return error;
+
                error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask,
                                dmi.fsd_dmstate);
+               mnt_drop_write_file(filp);
                return -error;
        }
 
@@ -1431,7 +1462,11 @@ xfs_file_ioctl(
 
                if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t)))
                        return -XFS_ERROR(EFAULT);
+               error = mnt_want_write_file(filp);
+               if (error)
+                       return error;
                error = xfs_swapext(&sxp);
+               mnt_drop_write_file(filp);
                return -error;
        }
 
@@ -1460,9 +1495,14 @@ xfs_file_ioctl(
                if (copy_from_user(&inout, arg, sizeof(inout)))
                        return -XFS_ERROR(EFAULT);
 
+               error = mnt_want_write_file(filp);
+               if (error)
+                       return error;
+
                /* input parameter is passed in resblks field of structure */
                in = inout.resblks;
                error = xfs_reserve_blocks(mp, &in, &inout);
+               mnt_drop_write_file(filp);
                if (error)
                        return -error;
 
@@ -1493,7 +1533,11 @@ xfs_file_ioctl(
                if (copy_from_user(&in, arg, sizeof(in)))
                        return -XFS_ERROR(EFAULT);
 
+               error = mnt_want_write_file(filp);
+               if (error)
+                       return error;
                error = xfs_growfs_data(mp, &in);
+               mnt_drop_write_file(filp);
                return -error;
        }
 
@@ -1503,7 +1547,11 @@ xfs_file_ioctl(
                if (copy_from_user(&in, arg, sizeof(in)))
                        return -XFS_ERROR(EFAULT);
 
+               error = mnt_want_write_file(filp);
+               if (error)
+                       return error;
                error = xfs_growfs_log(mp, &in);
+               mnt_drop_write_file(filp);
                return -error;
        }
 
@@ -1513,7 +1561,11 @@ xfs_file_ioctl(
                if (copy_from_user(&in, arg, sizeof(in)))
                        return -XFS_ERROR(EFAULT);
 
+               error = mnt_want_write_file(filp);
+               if (error)
+                       return error;
                error = xfs_growfs_rt(mp, &in);
+               mnt_drop_write_file(filp);
                return -error;
        }