btrfs: Deprecate userspace transaction ioctls
[sfrench/cifs-2.6.git] / fs / btrfs / ioctl.c
index fa1b78cf25f68083de3db86ead690a41563316ce..4cfc3d4c0a3720ca1564eb14cb063db26bc017e1 100644 (file)
@@ -156,37 +156,6 @@ void btrfs_update_iflags(struct inode *inode)
                      new_fl);
 }
 
-/*
- * Inherit flags from the parent inode.
- *
- * Currently only the compression flags and the cow flags are inherited.
- */
-void btrfs_inherit_iflags(struct inode *inode, struct inode *dir)
-{
-       unsigned int flags;
-
-       if (!dir)
-               return;
-
-       flags = BTRFS_I(dir)->flags;
-
-       if (flags & BTRFS_INODE_NOCOMPRESS) {
-               BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
-               BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS;
-       } else if (flags & BTRFS_INODE_COMPRESS) {
-               BTRFS_I(inode)->flags &= ~BTRFS_INODE_NOCOMPRESS;
-               BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
-       }
-
-       if (flags & BTRFS_INODE_NODATACOW) {
-               BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
-               if (S_ISREG(inode->i_mode))
-                       BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
-       }
-
-       btrfs_update_iflags(inode);
-}
-
 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
 {
        struct btrfs_inode *ip = BTRFS_I(file_inode(file));
@@ -1304,20 +1273,19 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                extent_thresh = SZ_256K;
 
        /*
-        * if we were not given a file, allocate a readahead
-        * context
+        * If we were not given a file, allocate a readahead context. As
+        * readahead is just an optimization, defrag will work without it so
+        * we don't error out.
         */
        if (!file) {
-               ra = kzalloc(sizeof(*ra), GFP_NOFS);
-               if (!ra)
-                       return -ENOMEM;
-               file_ra_state_init(ra, inode->i_mapping);
+               ra = kzalloc(sizeof(*ra), GFP_KERNEL);
+               if (ra)
+                       file_ra_state_init(ra, inode->i_mapping);
        } else {
                ra = &file->f_ra;
        }
 
-       pages = kmalloc_array(max_cluster, sizeof(struct page *),
-                       GFP_NOFS);
+       pages = kmalloc_array(max_cluster, sizeof(struct page *), GFP_KERNEL);
        if (!pages) {
                ret = -ENOMEM;
                goto out_ra;
@@ -1395,8 +1363,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 
                if (i + cluster > ra_index) {
                        ra_index = max(i, ra_index);
-                       btrfs_force_ra(inode->i_mapping, ra, file, ra_index,
-                                      cluster);
+                       if (ra)
+                               btrfs_force_ra(inode->i_mapping, ra, file,
+                                               ra_index, cluster);
                        ra_index += cluster;
                }
 
@@ -1600,8 +1569,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
                goto out_free;
        }
 
-       new_size = div_u64(new_size, fs_info->sectorsize);
-       new_size *= fs_info->sectorsize;
+       new_size = round_down(new_size, fs_info->sectorsize);
 
        btrfs_info_in_rcu(fs_info, "new size for %s is %llu",
                          rcu_str_deref(device->name), new_size);
@@ -3999,11 +3967,22 @@ static long btrfs_ioctl_trans_start(struct file *file)
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct btrfs_trans_handle *trans;
        int ret;
+       static bool warned = false;
 
        ret = -EPERM;
        if (!capable(CAP_SYS_ADMIN))
                goto out;
 
+       if (!warned) {
+               btrfs_warn(fs_info,
+                       "Userspace transaction mechanism is considered "
+                       "deprecated and slated to be removed in 4.17. "
+                       "If you have a valid use case please "
+                       "speak up on the mailing list");
+               WARN_ON(1);
+               warned = true;
+       }
+
        ret = -EINPROGRESS;
        if (file->private_data)
                goto out;