Re: [PATCH] Btrfs: change how we mount subvolumes
Hi, When I made snapshot listing, I thought 'subvol' parameter is not enough as G.Baroncelli wrote. I think nice feature too. (I tried to expand subvol parameter feature, by iterating dentry search(lookup_one_len) but I cannot treat dentries correctly yet. :) But, is 'subvol=name' not prohibited yet? When I specified 'subvol=name', mount command simply mounts filesystem root without error. Josef Bacik wrote: > This work is in preperation for being able to set a different root as the > default mounting root. > > There is currently a problem with how we mount subvolumes. We cannot > currently > mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of > the > default subvolume. So say you take a snapshot of the default subvolume and > call > it snap1, and then take a snapshot of snap1 and call it snap2, so now you have > > / > /snap1 > /snap1/snap2 > > as your available volumes. Currently you can only mount / and /snap1, you > cannot mount /snap1/snap2. To fix this problem instead of passing > subvol= > you must pass in subvol=, where is the tree id that gets spit > out via the subvolume listing you get from the subvolume listing patches > (btrfsctl -l). This allows us to mount /, /snap1 and /snap1/snap2 as the root > volume. > > In addition to the above, we also now read the default dir item in the tree > root > to get the root key that it points to. For now this just points at what has > always been the default subvolme, but later on I plan to change it to point at > whatever root you want to be the new default root, so you can just set the > default mount and not have to mount with -o subvol=. I tested this > out > with the above scenario and it worked perfectly. Thanks, > > Signed-off-by: Josef Bacik > --- > fs/btrfs/ctree.h |2 +- > fs/btrfs/export.c |4 +- > fs/btrfs/inode.c | 10 ++- > fs/btrfs/relocation.c |2 +- > fs/btrfs/super.c | 167 +++- > fs/btrfs/tree-log.c |2 +- > 6 files changed, 133 insertions(+), 54 deletions(-) > > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h > index 444b3e9..464f688 100644 > --- a/fs/btrfs/ctree.h > +++ b/fs/btrfs/ctree.h > @@ -2318,7 +2318,7 @@ int btrfs_init_cachep(void); > void btrfs_destroy_cachep(void); > long btrfs_ioctl_trans_end(struct file *file); > struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, > - struct btrfs_root *root); > + struct btrfs_root *root, int *was_new); > int btrfs_commit_write(struct file *file, struct page *page, > unsigned from, unsigned to); > struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, > diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c > index ba5c3fd..951ef09 100644 > --- a/fs/btrfs/export.c > +++ b/fs/btrfs/export.c > @@ -95,7 +95,7 @@ static struct dentry *btrfs_get_dentry(struct super_block > *sb, u64 objectid, > btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY); > key.offset = 0; > > - inode = btrfs_iget(sb, &key, root); > + inode = btrfs_iget(sb, &key, root, NULL); > if (IS_ERR(inode)) { > err = PTR_ERR(inode); > goto fail; > @@ -223,7 +223,7 @@ static struct dentry *btrfs_get_parent(struct dentry > *child) > > key.type = BTRFS_INODE_ITEM_KEY; > key.offset = 0; > - dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root)); > + dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root, > NULL)); > if (!IS_ERR(dentry)) > dentry->d_op = &btrfs_dentry_operations; > return dentry; > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > index b3ad168..b383e53 100644 > --- a/fs/btrfs/inode.c > +++ b/fs/btrfs/inode.c > @@ -2131,7 +2131,7 @@ void btrfs_orphan_cleanup(struct btrfs_root *root) > found_key.objectid = found_key.offset; > found_key.type = BTRFS_INODE_ITEM_KEY; > found_key.offset = 0; > - inode = btrfs_iget(root->fs_info->sb, &found_key, root); > + inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); > if (IS_ERR(inode)) > break; > > @@ -3609,7 +3609,7 @@ static struct inode *btrfs_iget_locked(struct > super_block *s, > * Returns in *is_new if the inode was read from disk > */ > struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, > - struct btrfs_root *root) > + struct btrfs_root *root, int *new) > { > struct inode *inode; > > @@ -3624,6 +3624,8 @@ struct inode *btrfs_iget(struct super_block *s, struct > btrfs_key *location, > > inode_tree_add(inode); > unlock_new_inode(inode); > + if (new) > + *new = 1; > } > > return inode; > @@ -3676,7 +3678,7 @@ struct inode *btrfs_lookup_dentry(struct
Re: [PATCH] Btrfs: change how we mount subvolumes
Hi Josef On Friday 04 December 2009, Josef Bacik wrote: > This work is in preperation for being able to set a different root as the > default mounting root. > > There is currently a problem with how we mount subvolumes. We cannot currently > mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the > default subvolume. So say you take a snapshot of the default subvolume and call > it snap1, and then take a snapshot of snap1 and call it snap2, so now you have > > / > /snap1 > /snap1/snap2 > > as your available volumes. Currently you can only mount / and /snap1, you > cannot mount /snap1/snap2. To fix this problem instead of passing subvol= > you must pass in subvol=, where is the tree id that gets spit > out via the subvolume listing you get from the subvolume listing patches > (btrfsctl -l). This allows us to mount /, /snap1 and /snap1/snap2 as the root > volume. > Nice feature. But only for clarification purpose I have to correct you: the only limit of the "subvol=" mount option is that the "volume name" or "snapshot name" have to be under the root of the "btrfs" filesystem (or if you prefer under the root of the "." volume). So: - a subvolume created under / may be mounted using the subvol= mount option - a subvolume created under a directory *can't* be mounted using the subvol= mount option - a subvolume created under a directory and moved under "/" *may* be mounted using the subvol= mount option - a snapshot of a subvolume created under / may be mounted using the subvol= option And so... (As side note: a subvol may be renamed/moved with a simple "mv" command.) In fact the "subvol=" mount option related code, search in the root of the btrfs a subvolume/snapshot named as required, then mount it. Doesn't matter if it is a snapshot of a subvolume or where it is originally created. In any case I like your idea. BR G.Baroncelli -- gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) Key fingerprint = 4769 7E51 5293 D36C 814E C054 BF04 F161 3DC5 0512 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] Btrfs: change how we mount subvolumes
This work is in preperation for being able to set a different root as the default mounting root. There is currently a problem with how we mount subvolumes. We cannot currently mount a subvolume of a subvolume, you can only mount subvolumes/snapshots of the default subvolume. So say you take a snapshot of the default subvolume and call it snap1, and then take a snapshot of snap1 and call it snap2, so now you have / /snap1 /snap1/snap2 as your available volumes. Currently you can only mount / and /snap1, you cannot mount /snap1/snap2. To fix this problem instead of passing subvol= you must pass in subvol=, where is the tree id that gets spit out via the subvolume listing you get from the subvolume listing patches (btrfsctl -l). This allows us to mount /, /snap1 and /snap1/snap2 as the root volume. In addition to the above, we also now read the default dir item in the tree root to get the root key that it points to. For now this just points at what has always been the default subvolme, but later on I plan to change it to point at whatever root you want to be the new default root, so you can just set the default mount and not have to mount with -o subvol=. I tested this out with the above scenario and it worked perfectly. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/ctree.h |2 +- fs/btrfs/export.c |4 +- fs/btrfs/inode.c | 10 ++- fs/btrfs/relocation.c |2 +- fs/btrfs/super.c | 167 +++- fs/btrfs/tree-log.c |2 +- 6 files changed, 133 insertions(+), 54 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 444b3e9..464f688 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2318,7 +2318,7 @@ int btrfs_init_cachep(void); void btrfs_destroy_cachep(void); long btrfs_ioctl_trans_end(struct file *file); struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, -struct btrfs_root *root); +struct btrfs_root *root, int *was_new); int btrfs_commit_write(struct file *file, struct page *page, unsigned from, unsigned to); struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c index ba5c3fd..951ef09 100644 --- a/fs/btrfs/export.c +++ b/fs/btrfs/export.c @@ -95,7 +95,7 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid, btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY); key.offset = 0; - inode = btrfs_iget(sb, &key, root); + inode = btrfs_iget(sb, &key, root, NULL); if (IS_ERR(inode)) { err = PTR_ERR(inode); goto fail; @@ -223,7 +223,7 @@ static struct dentry *btrfs_get_parent(struct dentry *child) key.type = BTRFS_INODE_ITEM_KEY; key.offset = 0; - dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root)); + dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root, NULL)); if (!IS_ERR(dentry)) dentry->d_op = &btrfs_dentry_operations; return dentry; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b3ad168..b383e53 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2131,7 +2131,7 @@ void btrfs_orphan_cleanup(struct btrfs_root *root) found_key.objectid = found_key.offset; found_key.type = BTRFS_INODE_ITEM_KEY; found_key.offset = 0; - inode = btrfs_iget(root->fs_info->sb, &found_key, root); + inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); if (IS_ERR(inode)) break; @@ -3609,7 +3609,7 @@ static struct inode *btrfs_iget_locked(struct super_block *s, * Returns in *is_new if the inode was read from disk */ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, -struct btrfs_root *root) +struct btrfs_root *root, int *new) { struct inode *inode; @@ -3624,6 +3624,8 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, inode_tree_add(inode); unlock_new_inode(inode); + if (new) + *new = 1; } return inode; @@ -3676,7 +3678,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) return NULL; if (location.type == BTRFS_INODE_ITEM_KEY) { - inode = btrfs_iget(dir->i_sb, &location, root); + inode = btrfs_iget(dir->i_sb, &location, root, NULL); return inode; } @@ -3691,7 +3693,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) else inode = new_simple_dir(dir->i_sb, &location, sub_root); } else { - inode = btrfs_iget(dir->i_sb, &location, sub_root); +