Btrfs: prevent loops in the directory tree when creating snapshots

For a directory tree:

/mnt/subvolA/subvolB

btrfsctl -s /mnt/subvolA/subvolB /mnt

Will create a directory loop with subvolA under subvolB.  This
commit uses the forward refs for each subvol and snapshot to error out
before creating the loop.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
Chris Mason
2008-11-17 21:14:24 -05:00
parent 0660b5af3f
commit ea9e8b11bd
4 changed files with 73 additions and 1 deletions

View File

@@ -300,6 +300,22 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
return ret;
}
int btrfs_find_root_ref(struct btrfs_root *tree_root,
struct btrfs_path *path,
u64 root_id, u64 ref_id)
{
struct btrfs_key key;
int ret;
key.objectid = root_id;
key.type = BTRFS_ROOT_REF_KEY;
key.offset = ref_id;
ret = btrfs_search_slot(NULL, tree_root, &key, path, 0, 0);
return ret;
}
/*
* add a btrfs_root_ref item. type is either BTRFS_ROOT_REF_KEY
* or BTRFS_ROOT_BACKREF_KEY.