[Devel] [PATCH rh7 20/38] ploop: expose open_count to sysfs

Andrey Smetanin asmetanin at virtuozzo.com
Fri May 15 09:48:21 PDT 2015


The patch shows number of opened instances of ploop-device (plo->open_count)
in /sys/block/ploopN/pstate/open_count. This will allow userspace to decide
whether a ploop-device is used by someone (e.g. backup) by scanning the
open_count for all ploop-devices.

https://jira.sw.ru/browse/PSBM-24754

Signed-off-by: Maxim Patlasov <MPatlasov at parallels.com>
---
 drivers/block/ploop/sysfs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index 5c31826..3ef53ac 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -383,6 +383,11 @@ static u32 show_event(struct ploop_device * plo)
 	return ret;
 }
 
+static u32 show_open_count(struct ploop_device * plo)
+{
+	return atomic_read(&plo->open_count);
+}
+
 static ssize_t print_cookie(struct ploop_device * plo, char * page)
 {
 	return sprintf(page, "%s\n", plo->cookie);
@@ -466,6 +471,7 @@ static struct attribute *state_attributes[] = {
 	_A(top),
 	_A(event),
 	_A3(cookie),
+	_A(open_count),
 	NULL
 };
 
-- 
1.9.3




More information about the Devel mailing list