linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
	linux-btrfs@vger.kernel.org, mpdesouza@suse.com
Subject: [PATCH 5/5] btrfs: ioctl: Call btrfs_vol_uevent on subvolume deletion
Date: Wed, 23 Oct 2019 23:36:36 -0300	[thread overview]
Message-ID: <20191024023636.21124-6-marcos.souza.org@gmail.com> (raw)
In-Reply-To: <20191024023636.21124-1-marcos.souza.org@gmail.com>

From: Marcos Paulo de Souza <mpdesouza@suse.com>

Since the function btrfs_ioctl_snap_destroy is used for deleting both
subvolumes and snapshots it was needed call btrfs_is_snapshot,
which checks a giver btrfs_root and returns true if it's a snapshot.
The current code is interested in subvolumes only.

btrfs_vol_uevent will export two environment variables to udev:
BTRFS_VOL_NAME: containing the name of the subvolume deleted
BTRFS_VOL_DEL: will signalize that a volume is being deleted

One can create a udev rule and check for BTRFS_VOL_DEL being set,
these values one could detect whenever a subvolume is deleted, and
take any action based on the subvolume name contained in BTRFS_VOL_NAME.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 fs/btrfs/ioctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index c538d3648195..173f2a258508 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2869,6 +2869,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 {
 	struct dentry *parent = file->f_path.dentry;
 	struct btrfs_fs_info *fs_info = btrfs_sb(parent->d_sb);
+	struct block_device *bdev = fs_info->fs_devices->latest_bdev;
 	struct dentry *dentry;
 	struct inode *dir = d_inode(parent);
 	struct inode *inode;
@@ -2962,6 +2963,10 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
 	err = btrfs_delete_subvolume(dir, dentry);
 	inode_unlock(inode);
 	if (!err) {
+		/* send uevent only to subvolume deletion */
+		if (!btrfs_is_snapshot(dest))
+			btrfs_vol_uevent(bdev, false, vol_args->name);
+
 		fsnotify_rmdir(dir, dentry);
 		d_delete(dentry);
 	}
-- 
2.23.0


  parent reply	other threads:[~2019-10-24  2:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24  2:36 [PATCH 0/5] btrfs: send uevent on subvolume add/remove Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 1/5] btrfs: sysfs: Add envp argument to btrfs_kobject_uevent Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 2/5] btrfs: ioctl: Introduce btrfs_vol_uevent Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 3/5] btrfs: ioctl: Call btrfs_vol_uevent on subvol creation Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 4/5] btrfs: ctree.h: Add btrfs_is_snapshot function Marcos Paulo de Souza
2019-10-25 10:02   ` Filipe Manana
2019-10-24  2:36 ` Marcos Paulo de Souza [this message]
2019-10-25 12:00   ` [PATCH 5/5] btrfs: ioctl: Call btrfs_vol_uevent on subvolume deletion Graham Cobb
2019-10-25 15:44     ` Marcos Paulo de Souza
2019-11-18 20:50 ` [PATCH 0/5] btrfs: send uevent on subvolume add/remove David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191024023636.21124-6-marcos.souza.org@gmail.com \
    --to=marcos.souza.org@gmail.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpdesouza@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).