[PATCH 2/5] btrfs: ioctl: Introduce btrfs_vol_uevent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Marcos Paulo de Souza <mpdesouza@xxxxxxxx>

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@xxxxxxxx>
---
 fs/btrfs/ioctl.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

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
-- 
2.23.0




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux