[Nbd] [PATCH v2] nbd: Issue a uevent when disconnecting
- To: Markus Pargmann <mpa@...1897...>, nbd-general <nbd-general@lists.sourceforge.net>, lkml <linux-kernel@...25...>
- Subject: [Nbd] [PATCH v2] nbd: Issue a uevent when disconnecting
- From: Wouter Verhelst <w@...112...>
- Date: Tue, 2 Feb 2016 16:27:00 +0100
- Message-id: <20160202152700.GA7562@...3...>
- In-reply-to: <1453566230-5786-1-git-send-email-w@...112...>
- References: <1453566230-5786-1-git-send-email-w@...112...>
There already is a uevent by default when closing a device upon connect
of the device. However, the same isn't true on disconnect.
This makes it hard for userspace to keep track of whether a device is
connected, since we are notified when the connection is created, but not
when it is removed again.
Explicitly issue a "change" uevent to remedy.
[v2: incorporate feedback from udev maintainer and make sure that we
issue a uevent upon connect as well as disconnect, rather than connect
only]
Signed-off-by: Wouter Verhelst <w@...112...>
---
drivers/block/nbd.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index e4c5cc1..04d9563 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -417,6 +417,8 @@ static int nbd_thread_recv(struct nbd_device *nbd)
spin_unlock_irqrestore(&nbd->tasks_lock, flags);
ret = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
+ kobject_uevent(&disk_to_dev(nbd->disk)->kobj, KOBJ_CHANGE);
+
if (ret) {
dev_err(disk_to_dev(nbd->disk), "device_create_file failed!\n");
@@ -438,6 +440,7 @@ static int nbd_thread_recv(struct nbd_device *nbd)
}
device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
+ kobject_uevent(&disk_to_dev(nbd->disk)->kobj, KOBJ_CHANGE);
spin_lock_irqsave(&nbd->tasks_lock, flags);
nbd->task_recv = NULL;
--
2.7.0
Reply to: