[RHEL8,COMMIT] ploop: Refactor and rename ploop_setup_pb()

Submitted by Konstantin Khorenko on Oct. 25, 2019, 4:15 p.m.

Details

Message ID 201910251615.x9PGFGSO005293@finist_co8.work.ct
State New
Series "ploop: Refactor and rename ploop_setup_pb()"
Headers show

Commit Message

Konstantin Khorenko Oct. 25, 2019, 4:15 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.3
------>
commit 46090acf477e8fe0fe497ceb90be883526843767
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Fri Oct 25 19:15:16 2019 +0300

    ploop: Refactor and rename ploop_setup_pb()
    
    It will be able to fail after next patch.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c | 56 ++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 25 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index c45c2106c387..230ded562312 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -1281,6 +1281,23 @@  static void process_set_push_backup(struct ploop *ploop, struct ploop_cmd *cmd)
 		ploop_free_pb(pb);
 }
 
+static void ploop_pb_timer(struct timer_list *timer)
+{
+	struct push_backup *pb = from_timer(pb, timer, deadline_timer);
+	u64 deadline, now = get_jiffies_64();
+	struct ploop *ploop = pb->ploop;
+	unsigned long flags;
+
+	spin_lock_irqsave(&ploop->pb_lock, flags);
+	deadline = pb->deadline_jiffies;
+	spin_unlock_irqrestore(&ploop->pb_lock, flags);
+
+	if (unlikely(time_before64(now, deadline)))
+		mod_timer(timer, deadline - now + 1);
+	else
+		queue_work(ploop->wq, &ploop->worker);
+}
+
 static struct push_backup *ploop_alloc_pb(struct ploop *ploop, char *uuid)
 {
 	struct push_backup *pb;
@@ -1291,17 +1308,21 @@  static struct push_backup *ploop_alloc_pb(struct ploop *ploop, char *uuid)
 	if (!pb)
 		return NULL;
 	snprintf(pb->uuid, sizeof(pb->uuid), "%s", uuid);
+	pb->ploop = ploop;
 	init_waitqueue_head(&pb->wq);
 	INIT_LIST_HEAD(&pb->pending);
 	pb->rb_root = RB_ROOT;
 
+	pb->deadline_jiffies = S64_MAX;
+	timer_setup(&pb->deadline_timer, ploop_pb_timer, 0);
+
 	size = DIV_ROUND_UP(ploop->nr_bat_entries, 8);
 	size = round_up(size, sizeof(unsigned long));
 	map = kvzalloc(size, GFP_KERNEL);
 	if (!map)
 		goto out_pb;
-
 	pb->ppb_map = map;
+	pb->alive = true;
 	return pb;
 out_pb:
 	kfree(pb);
@@ -1315,24 +1336,7 @@  void ploop_free_pb(struct push_backup *pb)
 	kfree(pb);
 }
 
-static void ploop_pb_timer(struct timer_list *timer)
-{
-	struct push_backup *pb = from_timer(pb, timer, deadline_timer);
-	u64 deadline, now = get_jiffies_64();
-	struct ploop *ploop = pb->ploop;
-	unsigned long flags;
-
-	spin_lock_irqsave(&ploop->pb_lock, flags);
-	deadline = pb->deadline_jiffies;
-	spin_unlock_irqrestore(&ploop->pb_lock, flags);
-
-	if (unlikely(time_before64(now, deadline)))
-		mod_timer(timer, deadline - now + 1);
-	else
-		queue_work(ploop->wq, &ploop->worker);
-}
-
-static void ploop_setup_pb(struct ploop *ploop, struct push_backup *pb)
+static int ploop_setup_pb_map(struct ploop *ploop, struct push_backup *pb)
 {
 	unsigned int i, nr_bat_entries = ploop->nr_bat_entries;
 
@@ -1341,11 +1345,7 @@  static void ploop_setup_pb(struct ploop *ploop, struct push_backup *pb)
 	for (i = round_down(nr_bat_entries, 8); i < nr_bat_entries; i++)
 		set_bit(i, pb->ppb_map);
 
-	pb->deadline_jiffies = S64_MAX;
-	timer_setup(&pb->deadline_timer, ploop_pb_timer, 0);
-
-	pb->ploop = ploop;
-	pb->alive = true;
+	return 0;
 }
 
 static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
@@ -1354,6 +1354,7 @@  static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
 	struct ploop_cmd cmd = { {0} };
 	struct push_backup *pb;
 	char *p = uuid;
+	int ret;
 
 	cmd.type = PLOOP_CMD_SET_PUSH_BACKUP;
 	cmd.ploop = ploop;
@@ -1381,7 +1382,9 @@  static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
 	pb = ploop_alloc_pb(ploop, uuid);
 	if (!pb)
 		return -ENOMEM;
-	ploop_setup_pb(ploop, pb);
+	ret = ploop_setup_pb_map(ploop, pb);
+	if (ret)
+		goto err_free;
 
 	/* Assign pb in work, to make it visible w/o locks (in work) */
 	cmd.set_push_backup.pb = pb;
@@ -1390,6 +1393,9 @@  static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
 	wait_for_completion(&cmd.comp);
 	ploop->maintaince = true;
 	return 0;
+err_free:
+	ploop_free_pb(pb);
+	return ret;
 }
 
 static int ploop_push_backup_stop(struct ploop *ploop, char *uuid,