[Devel] [PATCH RH8 41/61] ploop: Cache header

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 14 18:58:17 MSK 2021


We want to have generic code for parsing delta mapping,
but for top delta we also need to to get base parameters
from header. Cache them, so the rest code will be modular.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c    |   27 +++++++++++++++------------
 drivers/md/dm-ploop-target.c |    1 -
 drivers/md/dm-ploop.h        |    5 +++++
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 21eadbb69746..e21eb98fcd2b 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -279,6 +279,9 @@ int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 	if (le32_to_cpu(m_hdr->m_Sectors) != 1 << cluster_log)
 		goto out;
 
+	memcpy(ploop->m_Sig, m_hdr->m_Sig, sizeof(ploop->m_Sig));
+	ploop->m_Type = le32_to_cpu(m_hdr->m_Type);
+	ploop->m_Sectors = le32_to_cpu(m_hdr->m_Sectors);
 	ploop->nr_bat_entries = le32_to_cpu(m_hdr->m_Size);
 
 	/* Header and BAT-occupied clusters at start of file */
@@ -305,20 +308,14 @@ static int ploop_delta_check_header(struct ploop *ploop, struct page *page,
 		       unsigned int *nr_pages, unsigned int *last_page_len)
 {
 	unsigned int bytes, delta_nr_be, offset_clusters, bat_clusters, cluster_log;
-	struct ploop_pvd_header *d_hdr, *hdr;
-	struct md_page *md;
+	struct ploop_pvd_header *d_hdr;
 	int ret = -EPROTO;
 
-	md = md_page_find(ploop, 0);
-	if (!md)
-		return -ENXIO;
-
-	hdr = kmap(md->page);
 	d_hdr = kmap(page);
 
-	if (memcmp(d_hdr->m_Sig, hdr->m_Sig, sizeof(d_hdr->m_Sig)) ||
-	    d_hdr->m_Sectors != hdr->m_Sectors ||
-	    d_hdr->m_Type != hdr->m_Type)
+	if (memcmp(d_hdr->m_Sig, ploop->m_Sig, sizeof(d_hdr->m_Sig)) ||
+	    d_hdr->m_Sectors != ploop->m_Sectors ||
+	    d_hdr->m_Type != ploop->m_Type)
 		goto out;
 
 	delta_nr_be = le32_to_cpu(d_hdr->m_Size);
@@ -336,7 +333,6 @@ static int ploop_delta_check_header(struct ploop *ploop, struct page *page,
 	*last_page_len = bytes ? : PAGE_SIZE;
 	ret = 0;
 out:
-	kunmap(md->page);
 	kunmap(page);
 	return ret;
 }
@@ -454,8 +450,15 @@ static void apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas
 
 	write_lock_irq(&ploop->bat_rwlock);
 	ploop_for_each_md_page(ploop, md, node) {
-		init_bat_entries_iter(ploop, md->id, &i, &end);
 		bat_entries = kmap_atomic(md->page);
+
+		if (is_top_level && md->id == 0) {
+			/* bat_entries before PLOOP_MAP_OFFSET is hdr */
+			memcpy(bat_entries, hdr, sizeof(struct ploop_pvd_header));
+		}
+
+		init_bat_entries_iter(ploop, md->id, &i, &end);
+
 		for (; i <= end; i++) {
 			clu = page_clu_idx_to_bat_clu(md->id, i);
 			if (clu >= size_in_clus) {
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 020b05dbfb0f..307463fab633 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -185,7 +185,6 @@ static struct file * get_delta_file(int fd)
 static int check_top_delta(struct ploop *ploop, struct file *file)
 {
 	struct page *page = NULL;
-	u32 i, nr, *bat_entries;
 	int ret;
 
 	/* Prealloc a page to read hdr */
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index a8abd89164a1..c3cc2127a8d2 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -158,6 +158,11 @@ struct ploop {
 	u8 nr_deltas;
 	unsigned int nr_bat_entries;
 	unsigned int cluster_log; /* In sectors */
+
+	u8 m_Sig[16]; /* Signature */
+	u32 m_Type; /* Disk type */
+	u32 m_Sectors; /* Sectors per clu */
+
 	/*
 	 * Absolute values from start of file. BAT-related clusters
 	 * are also included, and their bits must be zeroed.




More information about the Devel mailing list