[RHEL8,COMMIT] ploop: Add ploop_delta type

Submitted by Konstantin Khorenko on Dec. 10, 2019, 3:12 p.m.

Details

Message ID 201912101512.xBAFC3g0023692@finist_co8.work.ct
State New
Series "ploop: Add ploop_delta type"
Headers show

Commit Message

Konstantin Khorenko Dec. 10, 2019, 3:12 p.m.
The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.2.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.2.6
------>
commit dacd373c1d2e9d52ce0fa1298eb6a72b7297402c
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Tue Dec 10 18:12:03 2019 +0300

    ploop: Add ploop_delta type
    
    Introduce a structure to store delta. Next patches will
    make delta consists of more information than just only
    file pointer.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c    | 25 +++++++++++++------------
 drivers/md/dm-ploop-map.c    |  2 +-
 drivers/md/dm-ploop-target.c |  2 +-
 drivers/md/dm-ploop.h        | 10 +++++++---
 4 files changed, 22 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 86e6804037ba..651f8a78972d 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -540,7 +540,7 @@  static void process_add_delta_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 	swap(ploop->deltas, cmd->add_delta.deltas);
 	ploop->nr_deltas++;
 	write_unlock_irq(&ploop->bat_rwlock);
-	get_file(ploop->deltas[level]);
+	get_file(ploop->deltas[level].file);
 	cmd->retval = 0;
 out:
 	complete(&cmd->comp); /* Last touch of cmd memory */
@@ -566,7 +566,7 @@  int ploop_add_delta(struct ploop *ploop, const char *arg)
 {
 	unsigned int level = ploop->nr_deltas;
 	struct ploop_cmd cmd = { {0} };
-	struct file **deltas;
+	struct ploop_delta *deltas;
 	bool is_raw = false;
 	unsigned int size;
 	struct file *file;
@@ -596,7 +596,7 @@  int ploop_add_delta(struct ploop *ploop, const char *arg)
 		goto out;
 	size = level * sizeof(*deltas);
 	memcpy(deltas, ploop->deltas, size);
-	deltas[level] = file;
+	deltas[level].file = file;
 	/*
 	 * BAT update in general is driven by the kwork
 	 * (see comment in process_one_deferred_bio()),
@@ -721,7 +721,7 @@  static void process_merge_latest_snapshot_cmd(struct ploop *ploop,
 	if (cmd->retval == 0 && !cmd->merge.do_repeat) {
 		/* Delta merged. Release delta's file */
 		write_lock_irq(&ploop->bat_rwlock);
-		file = ploop->deltas[--ploop->nr_deltas];
+		file = ploop->deltas[--ploop->nr_deltas].file;
 		write_unlock_irq(&ploop->bat_rwlock);
 		ploop_inflight_bios_ref_switch(ploop);
 		fput(file);
@@ -801,11 +801,11 @@  static void process_notify_delta_merged(struct ploop *ploop,
 			bat_levels[i]--;
 	}
 
-	file = ploop->deltas[level];
+	file = ploop->deltas[level].file;
 	/* Renumber deltas above @level */
 	for (i = level + 1; i < ploop->nr_deltas; i++)
 		ploop->deltas[i - 1] = ploop->deltas[i];
-	ploop->deltas[--ploop->nr_deltas] = NULL;
+	ploop->deltas[--ploop->nr_deltas].file = NULL;
 	write_unlock_irq(&ploop->bat_rwlock);
 
 	ploop_inflight_bios_ref_switch(ploop);
@@ -860,7 +860,7 @@  static int ploop_delta_clusters_merged(struct ploop *ploop, u8 level,
 	int ret;
 
 	/* Reread BAT of deltas[@level + 1] (or [@level - 1]) */
-	file = ploop->deltas[level + forward ? 1 : -1];
+	file = ploop->deltas[level + forward ? 1 : -1].file;
 
 	ret = ploop_read_delta_metadata(ploop, file, &d_hdr);
 	if (ret)
@@ -921,7 +921,7 @@  static int ploop_get_delta_name_cmd(struct ploop *ploop, u8 level,
 	 * for uniformity.
 	 */
 	read_lock_irq(&ploop->bat_rwlock);
-	file = get_file(ploop->deltas[level]);
+	file = get_file(ploop->deltas[level].file);
 	read_unlock_irq(&ploop->bat_rwlock);
 
 	p = file_path(file, result, maxlen);
@@ -1024,13 +1024,13 @@  static int ploop_switch_top_delta(struct ploop *ploop, int new_ro_fd,
 	if (ret)
 		goto fput;
 	ret = -ENOMEM;
-	size = (ploop->nr_deltas + 1) * sizeof(struct file *);
+	size = (ploop->nr_deltas + 1) * sizeof(struct ploop_delta);
 	cmd.switch_top_delta.deltas = kmalloc(size, GFP_NOIO);
 	if (!cmd.switch_top_delta.deltas)
 		goto put_dev;
-	size -= sizeof(struct file *);
+	size -= sizeof(struct ploop_delta);
 	memcpy(cmd.switch_top_delta.deltas, ploop->deltas, size);
-	cmd.switch_top_delta.deltas[ploop->nr_deltas] = file;
+	cmd.switch_top_delta.deltas[ploop->nr_deltas].file = file;
 
 	init_completion(&cmd.comp);
 	ploop_queue_deferred_cmd(ploop, &cmd);
@@ -1074,7 +1074,8 @@  static void process_flip_upper_deltas(struct ploop *ploop, struct ploop_cmd *cmd
 		}
 	}
 	swap(ploop->origin_dev, cmd->flip_upper_deltas.origin_dev);
-	swap(ploop->deltas[level], cmd->flip_upper_deltas.file);
+	/* FIXME */
+	swap(ploop->deltas[level].file, cmd->flip_upper_deltas.file);
 	write_unlock_irq(&ploop->bat_rwlock);
 	/* Device is suspended, but anyway... */
 	ploop_inflight_bios_ref_switch(ploop);
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 05febca61c09..8af8fa836278 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -913,7 +913,7 @@  static void submit_delta_read(struct ploop *ploop, unsigned int level,
 	iter.iov_offset = offset;
 
 	pos = (bio->bi_iter.bi_sector << SECTOR_SHIFT);
-	file = ploop->deltas[level];
+	file = ploop->deltas[level].file;
 
 	piocb->iocb.ki_pos = pos;
 	piocb->iocb.ki_filp = file;
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 2e11c4b9c27c..24f69cc35c5b 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -63,7 +63,7 @@  static void ploop_destroy(struct ploop *ploop)
 		percpu_ref_exit(&ploop->inflight_bios_ref[i]);
 	/* Nobody uses it after destroy_workqueue() */
 	while (ploop->nr_deltas-- > 0)
-		fput(ploop->deltas[ploop->nr_deltas]);
+		fput(ploop->deltas[ploop->nr_deltas].file);
 	WARN_ON(!RB_EMPTY_ROOT(&ploop->exclusive_bios_rbtree));
 	WARN_ON(!RB_EMPTY_ROOT(&ploop->inflight_bios_rbtree));
 	kfree(ploop->deltas);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 5c488bfd5e7c..4934959eb7a5 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -31,6 +31,10 @@  struct ploop_pvd_header {
 };
 #pragma pack(pop)
 
+struct ploop_delta {
+	struct file *file;
+};
+
 struct ploop_cmd {
 #define PLOOP_CMD_RESIZE		1
 #define PLOOP_CMD_ADD_DELTA		2
@@ -63,7 +67,7 @@  struct ploop_cmd {
 		} resize;
 		struct {
 			struct file *file;
-			struct file **deltas;
+			struct ploop_delta *deltas;
 			void *hdr; /* hdr and bat_entries consequentially */
 			unsigned int raw_clusters;
 			bool is_raw;
@@ -81,7 +85,7 @@  struct ploop_cmd {
 		} notify_delta_merged;
 		struct {
 			struct dm_dev *origin_dev;
-			struct file **deltas;
+			struct ploop_delta *deltas;
 		} switch_top_delta;
 		struct {
 			u8 level;
@@ -158,7 +162,7 @@  struct ploop {
 	struct ploop_pvd_header *hdr;
 	unsigned int *bat_entries;
 	u8 *bat_levels;
-	struct file **deltas;
+	struct ploop_delta *deltas;
 	u8 nr_deltas;
 	unsigned int nr_bat_entries;
 	unsigned int cluster_log; /* In sectors */