[Devel] [PATCH RHEL8 COMMIT] ploop: Add timeout argument in push backup

Konstantin Khorenko khorenko at virtuozzo.com
Tue Oct 29 14:42:19 MSK 2019


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.4
------>
commit a226015f6512b70dff96c1da0176e09a35218bb7
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue Oct 29 14:42:17 2019 +0300

    ploop: Add timeout argument in push backup
    
    The timeout arg is in seconds, so this is 2147483647 seconds or 4085 years.
    This should be enough...
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c | 19 ++++++++++++-------
 drivers/md/dm-ploop-map.c |  4 ++--
 drivers/md/dm-ploop.h     |  2 +-
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 9dea07b276d7..8c94fcf4bb67 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -1302,7 +1302,8 @@ static void ploop_pb_timer(struct timer_list *timer)
 		queue_work(ploop->wq, &ploop->worker);
 }
 
-static struct push_backup *ploop_alloc_pb(struct ploop *ploop, char *uuid)
+static struct push_backup *ploop_alloc_pb(struct ploop *ploop,
+					  char *uuid, int timeout)
 {
 	struct push_backup *pb;
 	unsigned int size;
@@ -1318,6 +1319,7 @@ static struct push_backup *ploop_alloc_pb(struct ploop *ploop, char *uuid)
 	pb->rb_root = RB_ROOT;
 
 	pb->deadline_jiffies = S64_MAX;
+	pb->timeout_in_jiffies = timeout * HZ;
 	timer_setup(&pb->deadline_timer, ploop_pb_timer, 0);
 
 	size = DIV_ROUND_UP(ploop->nr_bat_entries, 8);
@@ -1363,7 +1365,7 @@ static int ploop_setup_pb_map(struct push_backup *pb, void __user *mask)
 }
 
 static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
-				   void __user *mask)
+				   void __user *mask, int timeout)
 {
 	struct ploop_cmd cmd = { {0} };
 	struct push_backup *pb;
@@ -1375,6 +1377,8 @@ static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
 
 	if (ploop->pb)
 		return -EEXIST;
+	if (timeout <= 0)
+		return -EINVAL;
 	/*
 	 * There is no a problem in case of not suspended for the device.
 	 * But this means userspace collects wrong backup. Warn it here.
@@ -1390,7 +1394,7 @@ static int ploop_push_backup_start(struct ploop *ploop, char *uuid,
 	}
 	if (p != uuid + sizeof(pb->uuid) - 1)
 		return -EINVAL;
-	pb = ploop_alloc_pb(ploop, uuid);
+	pb = ploop_alloc_pb(ploop, uuid, timeout);
 	if (!pb)
 		return -ENOMEM;
 	ret = ploop_setup_pb_map(pb, mask);
@@ -1528,7 +1532,7 @@ static int ploop_push_backup_write(struct ploop *ploop, char *uuid,
 
 	has_more = !RB_EMPTY_ROOT(&pb->rb_root);
 	if (has_more)
-		pb->deadline_jiffies = get_jiffies_64() + BACKUP_DEADLINE * HZ;
+		pb->deadline_jiffies = get_jiffies_64() + pb->timeout_in_jiffies;
 	else
 		pb->deadline_jiffies = S64_MAX;
 	spin_unlock_irq(&ploop->pb_lock);
@@ -1536,7 +1540,7 @@ static int ploop_push_backup_write(struct ploop *ploop, char *uuid,
 	if (!bio_list_empty(&bio_list)) {
 		defer_bio_list(ploop, &bio_list);
 		if (has_more)
-			mod_timer(&pb->deadline_timer, BACKUP_DEADLINE * HZ + 1);
+			mod_timer(&pb->deadline_timer, pb->timeout_in_jiffies + 1);
 	}
 
 	return 0;
@@ -1659,9 +1663,10 @@ int ploop_message(struct dm_target *ti, unsigned int argc, char **argv,
 			goto unlock;
 		ret = ploop_flip_upper_deltas(ploop, argv[1], argv[2]);
 	} else if (!strcmp(argv[0], "push_backup_start")) {
-		if (argc != 3 || kstrtou64(argv[2], 10, &val) < 0)
+		if (argc != 4 || kstrtou64(argv[2], 10, &val) < 0 ||
+				 kstrtos32(argv[3], 10, &ival) < 0)
 			goto unlock;
-		ret = ploop_push_backup_start(ploop, argv[1], (void *)val);
+		ret = ploop_push_backup_start(ploop, argv[1], (void *)val, ival);
 	} else if (!strcmp(argv[0], "push_backup_stop")) {
 		if (argc != 3 || kstrtos32(argv[2], 10, &ival) < 0)
 			goto unlock;
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 13cb5c9e2f04..9b7aa95054dc 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -986,7 +986,7 @@ static bool postpone_if_required_for_backup(struct ploop *ploop,
 	}
 
 	if (RB_EMPTY_ROOT(&pb->rb_root)) {
-		pb->deadline_jiffies = get_jiffies_64() + BACKUP_DEADLINE * HZ;
+		pb->deadline_jiffies = get_jiffies_64() + pb->timeout_in_jiffies;
 		queue_timer = true;
 	}
 
@@ -1000,7 +1000,7 @@ static bool postpone_if_required_for_backup(struct ploop *ploop,
 		wake_up_interruptible(&pb->wq);
 
 	if (queue_timer)
-		mod_timer(&pb->deadline_timer, BACKUP_DEADLINE * HZ + 1);
+		mod_timer(&pb->deadline_timer, pb->timeout_in_jiffies + 1);
 
 	return true;
 }
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index ea5b7d41a6e1..5c488bfd5e7c 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -107,7 +107,6 @@ struct ploop_cmd {
 
 #define BAT_LEVEL_TOP		U8_MAX
 #define CLEANUP_DELAY		20
-#define BACKUP_DEADLINE		42
 
 #define PLOOP_BIOS_HTABLE_BITS	8
 #define PLOOP_BIOS_HTABLE_SIZE	(1 << PLOOP_BIOS_HTABLE_BITS)
@@ -141,6 +140,7 @@ struct push_backup {
 
 	void *ppb_map;
 
+	u64 timeout_in_jiffies;
 	u64 deadline_jiffies;
 	struct timer_list deadline_timer;
 



More information about the Devel mailing list