Skip to contentSkip to conversation

] Btrfs: fix destroy snapshot to get the right parent dentry

PATCH In review Rui Miguel Silva 2 participants 3 messages Nov 3, 2009 – Nov 4, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ] Btrfs: fix destroy snapshot to get the right parent dentry

In snapshot destroy the dentry used for parent was the snapshot dentry itself. Remove d_invalidate since always return EBUSY, making possible to remove a snapshot using the btrfsctl -D option.

---
 fs/btrfs/ioctl.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/ioctl.c +2 -5
index cdbb054..fe6ac9a 100644
@@ -741,7 +741,7 @@ out:
 static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 					     void __user *arg)
 {
-	struct dentry *parent = fdentry(file);
+	struct dentry *parent = file->f_path.dentry->d_parent;
 	struct dentry *dentry;
 	struct inode *dir = parent->d_inode;
 	struct inode *inode;
@@ -793,9 +793,6 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 	dest = BTRFS_I(inode)->root;
 
 	mutex_lock(&inode->i_mutex);
-	err = d_invalidate(dentry);
-	if (err)
-		goto out_unlock;
 
 	down_write(&root->fs_info->subvol_sem);
 
@@ -827,7 +824,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 	inode->i_flags |= S_DEAD;
 out_up_write:
 	up_write(&root->fs_info->subvol_sem);
-out_unlock:
+
 	mutex_unlock(&inode->i_mutex);
 	if (!err) {
 		shrink_dcache_sb(root->fs_info->sb);
Signature · 1 line
1.6.5.1
#1 lore raw

On Wed, Nov 4, 2009 at 12:10 AM, Rui Miguel Silva <[email protected]> wr= ote:

Quoted 1 line

In snapshot destroy the dentry used for parent was the snapshot dentr=

y

Quoted 1 line

itself. Remove d_invalidate since always return EBUSY, making possibl=

e

Quoted 2 lines

to remove a snapshot using the btrfsctl -D option.

This is not correct. The snapshot destroy ioctl receives two parameters= =2E
The first one provides directory that the snapshot is in, the second on= e
provides the name of snapshot..

The usage of 'btrfsctl -D' is:
btrfsctl -D [name of snapshot] [directory that holds the snapshot]

Yan, Zheng

Quoted 11 lines

---
=A0fs/btrfs/ioctl.c | =A0 =A07 ++-----
=A01 files changed, 2 insertions(+), 5 deletions(-)

fs/btrfs/ioctl.c +0 -0
index cdbb054..fe6ac9a 100644
@@ -741,7 +741,7 @@ out:
 =A0static noinline int btrfs_ioctl_snap_destroy(struct file *file,
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 void __user *arg)

Quoted 3 lines

=A0{
- =A0 =A0 =A0 struct dentry *parent =3D fdentry(file);
+ =A0 =A0 =A0 struct dentry *parent =3D file->f_path.dentry->d_parent=

;

fs/btrfs/ioctl.c static noinline int btrfs_ioctl_snap_destroy(stru=

Quoted 4 lines

=A0 =A0 =A0 =A0struct dentry *dentry;
=A0 =A0 =A0 =A0struct inode *dir =3D parent->d_inode; =A0 =A0 =A0 =A0struct inode *inode;

fs/btrfs/ioctl.c +0 -0
@@ -793,9 +793,6 @@ static noinline int btrfs_ioctl_snap_destroy(stru=

ct file *file,

fs/btrfs/ioctl.c static noinline int btrfs_ioctl_snap_destroy(stru=

Quoted 10 lines
fs/btrfs/ioctl.c +0 -3
 =A0 =A0 =A0 =A0dest =3D BTRFS_I(inode)->root;
 
 =A0 =A0 =A0 =A0mutex_lock(&inode->i_mutex);
- =A0 =A0 =A0 err =3D d_invalidate(dentry);
- =A0 =A0 =A0 if (err)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_unlock;
 
 =A0 =A0 =A0 =A0down_write(&root->fs_info->subvol_sem);
 
@@ -827,7 +824,7 @@ static noinline int btrfs_ioctl_snap_destroy(stru=

ct file *file,

Quoted 8 lines
fs/btrfs/ioctl.c +0 -0
 =A0 =A0 =A0 =A0inode->i_flags |=3D S_DEAD;

=A0out_up_write:
=A0 =A0 =A0 =A0up_write(&root->fs_info->subvol_sem);

fs/btrfs/ioctl.c +1 -1
-out_unlock:
+

=A0 =A0 =A0 =A0mutex_unlock(&inode->i_mutex);
=A0 =A0 =A0 =A0if (!err) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0shrink_dcache_sb(root->fs_info->sb);

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 6 lines · Zheng
Quoted 4 lines · Rui Miguel Silva

In snapshot destroy the dentry used for parent was the snapshot dentry itself. Remove d_invalidate since always return EBUSY, making possible to remove a snapshot using the btrfsctl -D option.

Quoted 9 lines

This is not correct. The snapshot destroy ioctl receives two parameters. The first one provides directory that the snapshot is in, the second one provides the name of snapshot..

The usage of 'btrfsctl -D' is:
btrfsctl -D [name of snapshot] [directory that holds the snapshot]

Yan, Zheng

Hi,
thanks for the explanation. I just saw the usage output: " [-D dir .]" "-D: delete snapshot" and I didn't understand it like the usage that you explained above. I understood it like this: btrfsctl -D relative/path/to/snapshot comparing to the -s option "-s snap_name dir: creates a new snapshot of dir" which is more clear.

That makes the patch completely wrong. Once again many thanks.

Cheers,
-- Rui

Quoted 30 lines
Quoted 30 lines
---
 fs/btrfs/ioctl.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/ioctl.c +1 -4
index cdbb054..fe6ac9a 100644
@@ -741,7 +741,7 @@ out:
 static noinline int btrfs_ioctl_snap_destroy(struct file *file,
                                            void __user *arg)
 {
-       struct dentry *parent = fdentry(file);
+       struct dentry *parent = file->f_path.dentry->d_parent;
       struct dentry *dentry;
       struct inode *dir = parent->d_inode;
       struct inode *inode;
@@ -793,9 +793,6 @@ static noinline int btrfs_ioctl_snap_destroy(struct  
 file *file,
       dest = BTRFS_I(inode)->root;
 
       mutex_lock(&inode->i_mutex);
-       err = d_invalidate(dentry);
-       if (err)
-               goto out_unlock;
 
       down_write(&root->fs_info->subvol_sem);
Quoted 10 lines
Quoted 10 lines
fs/btrfs/ioctl.c +1 -1
@@ -827,7 +824,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct  
 file *file,
       inode->i_flags |= S_DEAD;
 out_up_write:
       up_write(&root->fs_info->subvol_sem);
-out_unlock:
+
       mutex_unlock(&inode->i_mutex);
       if (!err) {
               shrink_dcache_sb(root->fs_info->sb);

--