Btrfs: return EPERM when deleting a default subvolume
authorGuangyu Sun <guangyu.sun@oracle.com>
Tue, 11 Mar 2014 18:24:18 +0000 (11:24 -0700)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 00:15:27 +0000 (17:15 -0700)
The error message is confusing:

 # btrfs sub delete /mnt/mysub/
 Delete subvolume '/mnt/mysub'
 ERROR: cannot delete '/mnt/mysub' - Directory not empty

The error message does not make sense to me: It's not about deleting a
directory but it's a subvolume, and it doesn't matter if the subvolume is
empty or not.

Maybe EPERM or is more appropriate in this case, combined with an explanatory
kernel log message. (e.g. "subvolume with ID 123 cannot be deleted because
it is configured as default subvolume.")

Reported-by: Koen De Wit <koen.de.wit@oracle.com>
Signed-off-by: Guangyu Sun <guangyu.sun@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/ioctl.c

index 3ad5c10d3704bc4f621398b2c5f726ee9746471a..10c18a6582cc7e30706aa3765dfde70fe42e7dee 100644 (file)
@@ -1858,7 +1858,9 @@ static noinline int may_destroy_subvol(struct btrfs_root *root)
        if (di && !IS_ERR(di)) {
                btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
                if (key.objectid == root->root_key.objectid) {
-                       ret = -ENOTEMPTY;
+                       ret = -EPERM;
+                       btrfs_err(root->fs_info, "deleting default subvolume "
+                                 "%llu is not allowed", key.objectid);
                        goto out;
                }
                btrfs_release_path(path);