[Devel] [PATCH RHEL8 COMMIT] ploop: Convert ctl_mutex into rwsem

Konstantin Khorenko khorenko at virtuozzo.com
Fri Oct 25 17:09:42 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.3
------>
commit 4560637ae8f166a3f0ab85f44a13055716b6ed5e
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri Oct 25 17:09:41 2019 +0300

    ploop: Convert ctl_mutex into rwsem
    
    Userspace push backup is multithreaded, and push_backup_read/write
    may be called in parallel. Use rwsem to allow that.
    
    Possible, in the future I'll avoid a lock here at all,
    if this looks better. I don't know yet.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c    | 25 ++++++++++++++++++++++---
 drivers/md/dm-ploop-target.c |  2 +-
 drivers/md/dm-ploop.h        |  2 +-
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index d329b5d62455..e3886c175b2e 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -1564,12 +1564,23 @@ void process_deferred_cmd(struct ploop *ploop, struct ploop_index_wb *piwb)
 	spin_lock_irq(&ploop->deferred_lock);
 }
 
+static bool msg_wants_down_read(const char *cmd)
+{
+	if (!strcmp(cmd, "get_delta_name") ||
+	    !strcmp(cmd, "push_backup_get_uuid") ||
+	    !strcmp(cmd, "push_backup_read") ||
+	    !strcmp(cmd, "push_backup_write"))
+		return true;
+
+	return false;
+}
+
 int ploop_message(struct dm_target *ti, unsigned int argc, char **argv,
 		  char *result, unsigned int maxlen)
 {
 	struct ploop *ploop = ti->private;
+	bool read, forward = true;
 	int ival, ret = -EPERM;
-	bool forward = true;
 	u64 val, val2;
 
 	if (!capable(CAP_SYS_ADMIN))
@@ -1579,7 +1590,12 @@ int ploop_message(struct dm_target *ti, unsigned int argc, char **argv,
 	if (argc < 1)
 		goto out;
 
-	mutex_lock(&ploop->ctl_mutex);
+	read = msg_wants_down_read(argv[0]);
+	if (read)
+		down_read(&ploop->ctl_rwsem);
+	else
+		down_write(&ploop->ctl_rwsem);
+
 	if (!strcmp(argv[0], "resize")) {
 		if (argc != 2 || kstrtou64(argv[1], 10, &val) < 0)
 			goto unlock;
@@ -1649,7 +1665,10 @@ int ploop_message(struct dm_target *ti, unsigned int argc, char **argv,
 	}
 
 unlock:
-	mutex_unlock(&ploop->ctl_mutex);
+	if (read)
+		up_read(&ploop->ctl_rwsem);
+	else
+		up_write(&ploop->ctl_rwsem);
 out:
 	return ret;
 }
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 999f78a05977..2e11c4b9c27c 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -112,7 +112,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	}
 
 	rwlock_init(&ploop->bat_rwlock);
-	mutex_init(&ploop->ctl_mutex);
+	init_rwsem(&ploop->ctl_rwsem);
 	spin_lock_init(&ploop->deferred_lock);
 	spin_lock_init(&ploop->pb_lock);
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index fc58e1081a78..ea5b7d41a6e1 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -203,7 +203,7 @@ struct ploop {
 	struct bio_list deferred_bios;
 	struct bio_list discard_bios;
 
-	struct mutex ctl_mutex;
+	struct rw_semaphore ctl_rwsem;
 	struct ploop_cmd *deferred_cmd;
 
 	/*



More information about the Devel mailing list