btrfs: cleanup 64bit/32bit divs, provably bounded values
[linux-2.6-block.git] / fs / btrfs / ioctl.c
index 4399f0c3a4ce1c6a08cfa81f2720f27a7138eea7..4a5524c2713a4f127ddb41c91f15829673dc9848 100644 (file)
@@ -617,7 +617,7 @@ fail:
        return ret;
 }
 
-static void btrfs_wait_nocow_write(struct btrfs_root *root)
+static void btrfs_wait_for_no_snapshoting_writes(struct btrfs_root *root)
 {
        s64 writers;
        DEFINE_WAIT(wait);
@@ -649,7 +649,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
 
        atomic_inc(&root->will_be_snapshoted);
        smp_mb__after_atomic();
-       btrfs_wait_nocow_write(root);
+       btrfs_wait_for_no_snapshoting_writes(root);
 
        ret = btrfs_start_delalloc_inodes(root, 0);
        if (ret)
@@ -717,35 +717,6 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
        if (ret)
                goto fail;
 
-       /*
-        * If orphan cleanup did remove any orphans, it means the tree was
-        * modified and therefore the commit root is not the same as the
-        * current root anymore. This is a problem, because send uses the
-        * commit root and therefore can see inode items that don't exist
-        * in the current root anymore, and for example make calls to
-        * btrfs_iget, which will do tree lookups based on the current root
-        * and not on the commit root. Those lookups will fail, returning a
-        * -ESTALE error, and making send fail with that error. So make sure
-        * a send does not see any orphans we have just removed, and that it
-        * will see the same inodes regardless of whether a transaction
-        * commit happened before it started (meaning that the commit root
-        * will be the same as the current root) or not.
-        */
-       if (readonly && pending_snapshot->snap->node !=
-           pending_snapshot->snap->commit_root) {
-               trans = btrfs_join_transaction(pending_snapshot->snap);
-               if (IS_ERR(trans) && PTR_ERR(trans) != -ENOENT) {
-                       ret = PTR_ERR(trans);
-                       goto fail;
-               }
-               if (!IS_ERR(trans)) {
-                       ret = btrfs_commit_transaction(trans,
-                                                      pending_snapshot->snap);
-                       if (ret)
-                               goto fail;
-               }
-       }
-
        inode = btrfs_lookup_dentry(dentry->d_parent->d_inode, dentry);
        if (IS_ERR(inode)) {
                ret = PTR_ERR(inode);
@@ -761,7 +732,8 @@ fail:
 free:
        kfree(pending_snapshot);
 out:
-       atomic_dec(&root->will_be_snapshoted);
+       if (atomic_dec_and_test(&root->will_be_snapshoted))
+               wake_up_atomic_t(&root->will_be_snapshoted);
        return ret;
 }
 
@@ -1592,7 +1564,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
                goto out_free;
        }
 
-       do_div(new_size, root->sectorsize);
+       new_size = div_u64(new_size, root->sectorsize);
        new_size *= root->sectorsize;
 
        printk_in_rcu(KERN_INFO "BTRFS: new size for %s is %llu\n",
@@ -3067,7 +3039,7 @@ out:
 static int check_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
                     u64 disko)
 {
-       struct seq_list tree_mod_seq_elem = {};
+       struct seq_list tree_mod_seq_elem = SEQ_LIST_INIT(tree_mod_seq_elem);
        struct ulist *roots;
        struct ulist_iterator uiter;
        struct ulist_node *root_node = NULL;
@@ -5296,7 +5268,7 @@ long btrfs_ioctl(struct file *file, unsigned int
                ret = btrfs_start_delalloc_roots(root->fs_info, 0, -1);
                if (ret)
                        return ret;
-               ret = btrfs_sync_fs(file->f_dentry->d_sb, 1);
+               ret = btrfs_sync_fs(file_inode(file)->i_sb, 1);
                /*
                 * The transaction thread may want to do more work,
                 * namely it pokes the cleaner ktread that will start