[2/5] btrfs: ioctl: Introduce btrfs_vol_uevent
diff mbox series

Message ID 20191024023636.21124-3-marcos.souza.org@gmail.com
State New
Headers show
Series
  • btrfs: send uevent on subvolume add/remove
Related show

Commit Message

Marcos Paulo de Souza Oct. 24, 2019, 2:36 a.m. UTC
From: Marcos Paulo de Souza <mpdesouza@suse.com>

This new function will be used to send uevents when a subvolume is created
or removed. Two environment variables are being exported:

BTRFS_VOL_NAME: contains the name of the volume being added/removed
BTRFS_VOL_{ADD|DEL}: will signalize whether a subvolume is created/deleted

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

Patch
diff mbox series

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index de730e56d3f5..174cbe71d6be 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -940,6 +940,33 @@  static inline int btrfs_may_create(struct inode *dir, struct dentry *child)
 	return inode_permission(dir, MAY_WRITE | MAY_EXEC);
 }
 
+static inline int btrfs_vol_uevent(struct block_device *bdev, bool vol_added,
+				const char *name)
+{
+	char *envp[3];
+	int ret = -ENOMEM;
+
+	envp[0] = kasprintf(GFP_KERNEL, "BTRFS_VOL_NAME=%s", name);
+	if (!envp[0])
+		return ret;
+
+	envp[1] = kasprintf(GFP_KERNEL, "BTRFS_VOL_%s=1",
+			vol_added ? "NEW" : "DEL");
+	if (!envp[1])
+		goto free;
+
+	envp[2] = NULL;
+
+	btrfs_kobject_uevent(bdev, KOBJ_CHANGE, envp);
+
+	ret = 0;
+
+	kfree(envp[1]);
+free:
+	kfree(envp[0]);
+	return ret;
+}
+
 /*
  * Create a new subvolume below @parent.  This is largely modeled after
  * sys_mkdirat and vfs_mkdir, but we only do a single component lookup