[Devel] [PATCH RH9 5/5] dm-qcow2: Move qcow2_get_img_name() and qcow2_get_img_fd() out of mutex

Kirill Tkhai ktkhai at virtuozzo.com
Thu Nov 25 19:05:57 MSK 2021


Now it is protected by target ref, so we move them out.
This allows to avoid long hang in case of this functions
are called in parallel with backup.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-qcow2-cmd.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index c64ea325e52e..bb541e4707cf 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -315,24 +315,28 @@ int qcow2_message(struct dm_target *ti, unsigned int argc, char **argv,
 	if (argc < 1)
 		goto out;
 
-	ret = mutex_lock_killable(&tgt->ctl_mutex);
-	if (ret)
-		goto out;
-
-	if (!strcmp(argv[0], "get_errors")) {
-		ret = qcow2_get_errors(tgt, result, maxlen);
-	} else if (!strcmp(argv[0], "get_img_fd")) {
+	if (!strcmp(argv[0], "get_img_fd")) {
 		if (argc != 2 || kstrtou32(argv[1], 10, &val)) {
 			ret = -EINVAL;
-			goto unlock;
+			goto out;
 		}
 		ret = qcow2_get_img_fd(tgt, val, result, maxlen);
+		goto out;
 	} else if (!strcmp(argv[0], "get_img_name")) {
 		if (argc != 2 || kstrtou32(argv[1], 10, &val)) {
 			ret = -EINVAL;
-			goto unlock;
+			goto out;
 		}
 		ret = qcow2_get_img_name(tgt, val, result, maxlen);
+		goto out;
+	}
+
+	ret = mutex_lock_killable(&tgt->ctl_mutex);
+	if (ret)
+		goto out;
+
+	if (!strcmp(argv[0], "get_errors")) {
+		ret = qcow2_get_errors(tgt, result, maxlen);
 	} else if (!tgt->service_operations_allowed) {
 		ret = -EBUSY; /* Suspended */
 		/* Service operations goes below: */
@@ -343,7 +347,7 @@ int qcow2_message(struct dm_target *ti, unsigned int argc, char **argv,
 	} else {
 		ret = -ENOTTY;
 	}
-unlock:
+
 	mutex_unlock(&tgt->ctl_mutex);
 out:
 	return ret;




More information about the Devel mailing list