[Devel] [PATCH rh7] ploop: push_backup: show uuid

Maxim Patlasov mpatlasov at virtuozzo.com
Wed May 11 17:36:54 PDT 2016


It's useful to be able to discover current uuid:

# cat /sys/block/ploopN/pstate/push_backup_uuid
00000000-0000-0000-0000-000000000000

For example, if ioctl(PLOOP_IOC_PUSH_BACKUP_STOP) fails with EINVAL,
the userspace may re-check if it used correct uuid.

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

Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
 drivers/block/ploop/dev.c         |    2 ++
 drivers/block/ploop/push_backup.c |   17 +++++++++++++++--
 drivers/block/ploop/push_backup.h |    1 +
 drivers/block/ploop/sysfs.c       |   18 ++++++++++++++++++
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index c4d2bc1..1e511d7 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -4553,7 +4553,9 @@ static int ploop_push_backup_init(struct ploop_device *plo, unsigned long arg)
 		goto pb_init_done;
 	}
 
+	mutex_lock(&plo->sysfs_mutex);
 	plo->pbd = pbd;
+	mutex_unlock(&plo->sysfs_mutex);
 
 	atomic_set(&plo->maintenance_cnt, 0);
 	plo->maintenance_type = PLOOP_MNTN_PUSH_BACKUP;
diff --git a/drivers/block/ploop/push_backup.c b/drivers/block/ploop/push_backup.c
index 50b776c..4f23925 100644
--- a/drivers/block/ploop/push_backup.c
+++ b/drivers/block/ploop/push_backup.c
@@ -43,6 +43,15 @@ int ploop_pb_check_uuid(struct ploop_pushbackup_desc *pbd, __u8 *uuid)
 	return 0;
 }
 
+int ploop_pb_get_uuid(struct ploop_pushbackup_desc *pbd, __u8 *uuid)
+{
+	if (!pbd)
+		return -1;
+
+	memcpy(uuid, pbd->cbt_uuid, sizeof(pbd->cbt_uuid));
+	return 0;
+}
+
 struct ploop_pushbackup_desc *ploop_pb_alloc(struct ploop_device *plo)
 {
 	struct ploop_pushbackup_desc *pbd;
@@ -253,8 +262,12 @@ void ploop_pb_fini(struct ploop_pushbackup_desc *pbd)
 	if (!RB_EMPTY_ROOT(&pbd->reported_tree))
 		printk("ploop_pb_fini: reported_tree is not empty!\n");
 
-	if (pbd->plo)
-		pbd->plo->pbd = NULL;
+	if (pbd->plo) {
+		struct ploop_device *plo = pbd->plo;
+		mutex_lock(&plo->sysfs_mutex);
+		plo->pbd = NULL;
+		mutex_unlock(&plo->sysfs_mutex);
+	}
 
 	ploop_pb_free_cbt_map(pbd);
 
diff --git a/drivers/block/ploop/push_backup.h b/drivers/block/ploop/push_backup.h
index cfb1138..1a8636a 100644
--- a/drivers/block/ploop/push_backup.h
+++ b/drivers/block/ploop/push_backup.h
@@ -6,6 +6,7 @@ void ploop_pb_fini(struct ploop_pushbackup_desc *pbd);
 int ploop_pb_copy_cbt_to_user(struct ploop_pushbackup_desc *pbd, char *user_addr);
 unsigned long ploop_pb_stop(struct ploop_pushbackup_desc *pbd);
 int ploop_pb_check_uuid(struct ploop_pushbackup_desc *pbd, __u8 *uuid);
+int ploop_pb_get_uuid(struct ploop_pushbackup_desc *pbd, __u8 *uuid);
 
 int ploop_pb_get_pending(struct ploop_pushbackup_desc *pbd,
 			 cluster_t *clu_p, cluster_t *len_p, unsigned n_done);
diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index 8b3e818..034713a 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -9,6 +9,7 @@
 #include <asm/uaccess.h>
 
 #include <linux/ploop/ploop.h>
+#include "push_backup.h"
 
 struct delta_sysfs_entry {
 	struct attribute attr;
@@ -401,6 +402,22 @@ static ssize_t print_cookie(struct ploop_device * plo, char * page)
 	return sprintf(page, "%s\n", plo->cookie);
 }
 
+static ssize_t print_push_backup_uuid(struct ploop_device * plo, char * page)
+{
+	__u8 uuid[16];
+	int err;
+
+	mutex_lock(&plo->sysfs_mutex);
+	err = ploop_pb_get_uuid(plo->pbd, uuid);
+	mutex_unlock(&plo->sysfs_mutex);
+
+	page[0] = '\0';
+	if (err)
+		return 0;
+
+	return snprintf(page, PAGE_SIZE, "%pUB\n", uuid);
+}
+
 #define _TUNE_U32(_name)				\
 static u32 show_##_name(struct ploop_device * plo)	\
 {							\
@@ -480,6 +497,7 @@ static struct attribute *state_attributes[] = {
 	_A(top),
 	_A(event),
 	_A3(cookie),
+	_A3(push_backup_uuid),
 	_A(open_count),
 	NULL
 };



More information about the Devel mailing list