[Devel] [PATCH rh7] ploop: added into pvd header new close signatures

Andrey Smetanin asmetanin at virtuozzo.com
Tue Jun 2 01:10:34 PDT 2015


pvd header m_DiskInUse field extended to store additinal
SIGNATURE_DISK_CLOSED_V21 value(will be used by backup software).
Disk in use checks replaced by pvd_header_is_disk_in_use().

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

Signed-off-by: Andrey Smetanin <asmetanin at virtuozzo.com>

---
 drivers/block/ploop/fmt_ploop1.c   | 14 +++++++-------
 drivers/block/ploop/ploop1_image.h | 21 +++++++++++++++++++++
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 17ce27b..6e9897e 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -87,7 +87,7 @@ static int ploop1_stop(struct ploop_delta * delta)
 		vh->m_Flags = cpu_to_le32(vh->m_Flags);
 	}
 
-	vh->m_DiskInUse = 0;
+	pvd_header_set_disk_closed(vh);
 
 	err = delta->io.ops->sync_write(&delta->io, ph->dyn_page, 4096, 0, 0);
 	if (err)
@@ -146,7 +146,7 @@ ploop1_open(struct ploop_delta * delta)
 	ph->l1_off = le32_to_cpu(vh->m_FirstBlockOffset);
 
 	err = -EBUSY;
-	if (vh->m_DiskInUse)
+	if (pvd_header_is_disk_in_use(vh))
 		goto out_err;
 
 	err = -EINVAL;
@@ -166,7 +166,7 @@ ploop1_open(struct ploop_delta * delta)
 		goto out_err;
 
 	if (!(delta->flags & PLOOP_FMT_RDONLY)) {
-		vh->m_DiskInUse = cpu_to_le32(SIGNATURE_DISK_IN_USE);
+		pvd_header_set_disk_in_use(vh);
 		err = delta->io.ops->sync_write(&delta->io, ph->dyn_page, 4096, 0, 0);
 		if (err)
 			goto out_err;
@@ -275,7 +275,7 @@ ploop1_sync(struct ploop_delta * delta)
 		return err;
 
 	vh = (struct ploop_pvd_header *)page_address(ph->dyn_page);
-	vh->m_DiskInUse = cpu_to_le32(SIGNATURE_DISK_IN_USE);
+	pvd_header_set_disk_in_use(vh);
 
 	if (ph->alloc_head > (ph->l1_off >> delta->plo->cluster_log)) {
 		vh->m_Flags = le32_to_cpu(vh->m_Flags);
@@ -328,7 +328,7 @@ ploop1_complete_snapshot(struct ploop_delta * delta, struct ploop_snapdata * sd)
 		vh->m_Flags = cpu_to_le32(vh->m_Flags);
 	}
 
-	vh->m_DiskInUse = 0;
+	pvd_header_set_disk_closed(vh);
 
 	/*
 	 * NB: we don't call ploop_update_map_hdr() here because top
@@ -375,7 +375,7 @@ ploop1_prepare_merge(struct ploop_delta * delta, struct ploop_snapdata * sd)
 	if (err)
 		return err;
 
-	if (vh->m_DiskInUse)
+	if (pvd_header_is_disk_in_use(vh))
 		return -EBUSY;
 
 	ph->alloc_head = delta->io.ops->i_size_read(&delta->io) >>
@@ -412,7 +412,7 @@ ploop1_start_merge(struct ploop_delta * delta, struct ploop_snapdata * sd)
 		return err;
 
 	vh = (struct ploop_pvd_header *)page_address(ph->dyn_page);
-	vh->m_DiskInUse = cpu_to_le32(SIGNATURE_DISK_IN_USE);
+	pvd_header_set_disk_in_use(vh);
 
 	/* keep hdr in ph->dyn_page and in map_node in sync */
 	ploop_update_map_hdr(&delta->plo->map, (u8 *)vh, sizeof(*vh));
diff --git a/drivers/block/ploop/ploop1_image.h b/drivers/block/ploop/ploop1_image.h
index c4efe87..1db8cea 100644
--- a/drivers/block/ploop/ploop1_image.h
+++ b/drivers/block/ploop/ploop1_image.h
@@ -57,6 +57,12 @@ struct ploop_pvd_header
 /* Sign that the disk is in "using" state */
 #define SIGNATURE_DISK_IN_USE		0x746F6E59
 
+/* Disk was closed by software which conformed specification 2.0 */
+#define SIGNATURE_DISK_CLOSED_V20	0x0
+
+/* Disk disk was closed by software which conformed specification 2.1 */
+#define SIGNATURE_DISK_CLOSED_V21	0x312e3276
+
 /**
  * Compressed disk image flags
  */
@@ -354,6 +360,21 @@ generate_pvd_header(struct ploop_pvd_header *vh, __u64 bdsize, __u32 blocksize,
 	return SizeToFill;
 }
 
+static inline bool pvd_header_is_disk_in_use(struct ploop_pvd_header *vh)
+{
+	return (vh->m_DiskInUse == cpu_to_le32(SIGNATURE_DISK_IN_USE)) ?
+		true : false;
+}
+
+static inline void pvd_header_set_disk_in_use(struct ploop_pvd_header *vh)
+{
+	vh->m_DiskInUse = cpu_to_le32(SIGNATURE_DISK_IN_USE);
+}
+
+static inline void pvd_header_set_disk_closed(struct ploop_pvd_header *vh)
+{
+	vh->m_DiskInUse = cpu_to_le32(SIGNATURE_DISK_CLOSED_V20);
+}
 
 /* Translation of sector number to offset in image */
 
-- 
1.9.3




More information about the Devel mailing list