[RHEL8,COMMIT] cbt: Change errno values for new ioctl

Submitted by Konstantin Khorenko on Oct. 25, 2019, 2:43 p.m.

Details

Message ID 201910251443.x9PEhC5J005199@finist_co8.work.ct
State New
Series "cbt: Change errno values for new ioctl"
Headers show

Commit Message

Konstantin Khorenko Oct. 25, 2019, 2:43 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 5d46a2bbb3d1cbfc2e1f8acdbf4f7873a829176f
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Fri Oct 25 17:43:12 2019 +0300

    cbt: Change errno values for new ioctl
    
    To differ the situations, when there is no cbt tracking
    and there is no cbt snapshot: return -ENOENT and -ENODEV
    respectively).
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 block/blk-cbt.c | 74 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 38 insertions(+), 36 deletions(-)

Patch hide | download patch | download mbox

diff --git a/block/blk-cbt.c b/block/blk-cbt.c
index 32949219e5b7..f5205a8b7387 100644
--- a/block/blk-cbt.c
+++ b/block/blk-cbt.c
@@ -337,12 +337,10 @@  static int blk_cbt_snp_create(struct request_queue *q, __u8 *uuid,
 	__u64 to_addr;
 	int ret;
 
-	if (copy_from_user(&to_addr, &arg->addr, sizeof(to_addr)))
+	if (copy_from_user(&to_addr, &arg->addr, sizeof(to_addr)) ||
+	    (unsigned long)to_addr != to_addr)
 		return -EFAULT;
 
-	if ((unsigned long)to_addr != to_addr)
-		return -EINVAL;
-
 	mutex_lock(&cbt_mutex);
 	cbt = q->cbt;
 
@@ -414,35 +412,34 @@  static int blk_cbt_snp_drop(struct request_queue *q, __u8 *uuid)
 	struct cbt_info *cbt;
 	unsigned long npages;
 	struct page **map;
+	int ret;
 
 	mutex_lock(&cbt_mutex);
 	cbt = q->cbt;
 
-	if (!cbt) {
-		mutex_unlock(&cbt_mutex);
-		return -ENOENT;
-	}
+	ret = -ENOENT;
+	if (!cbt)
+		goto out;
 
 	BUG_ON(!cbt->map);
 	BUG_ON(!cbt->block_max);
 
-	if (!uuid || memcmp(uuid, cbt->uuid, sizeof(cbt->uuid))) {
-		mutex_unlock(&cbt_mutex);
-		return -EINVAL;
-	}
+	ret = -EINVAL;
+	if (!uuid || memcmp(uuid, cbt->uuid, sizeof(cbt->uuid)))
+		goto out;
 
+	ret = -ENODEV;
 	map = cbt->snp_map;
-	if (!map) {
-		mutex_unlock(&cbt_mutex);
-		return -ENOENT;
-	}
+	if (!map)
+		goto out;
 	cbt->snp_map = NULL;
-
 	npages = NR_PAGES(cbt->snp_block_max);
 	cbt->snp_block_max = 0;
+	ret = 0;
+out:
 	mutex_unlock(&cbt_mutex);
-
-	free_map(map, npages);
+	if (ret == 0)
+		free_map(map, npages);
 	return 0;
 }
 
@@ -465,26 +462,30 @@  static int blk_cbt_snp_merge_back(struct request_queue *q, __u8 *uuid)
 	blkcnt_t block_max;
 	struct page **map;
 	unsigned long i;
+	int ret;
 
 	mutex_lock(&cbt_mutex);
 	cbt = q->cbt;
 
-	if (!cbt) {
-		mutex_unlock(&cbt_mutex);
-		return -ENOENT;
-	}
+	ret = -ENOENT;
+	if (!cbt)
+		goto out;
 
 	BUG_ON(!cbt->map);
 	BUG_ON(!cbt->block_max);
 
+	ret = -EINVAL;
+	if (!uuid || memcmp(uuid, cbt->uuid, sizeof(cbt->uuid)))
+		goto out;
+
 	map = cbt->snp_map;
 	block_max = cbt->snp_block_max;
-
-	if (!map || !uuid || memcmp(uuid, cbt->uuid, sizeof(cbt->uuid)) ||
-	    block_max != cbt->block_max) {
-		mutex_unlock(&cbt_mutex);
-		return -EINVAL;
-	}
+	ret = -ENODEV;
+	if (!map)
+		goto out;
+	ret = -ESTALE;
+	if (block_max != cbt->block_max)
+		goto out;
 
 	for (i = 0; i < NR_PAGES(cbt->block_max); i++) {
 		struct page *page_main = cbt->map[i];
@@ -497,11 +498,10 @@  static int blk_cbt_snp_merge_back(struct request_queue *q, __u8 *uuid)
 			continue;
 
 		if (!page_main) {
-			int ret = cbt_page_alloc(&cbt, i, 0);
-			if (ret) {
-				mutex_unlock(&cbt_mutex);
-				return ret;
-			}
+			ret = -ENOMEM;
+			if (cbt_page_alloc(&cbt, i, 0))
+				goto out;
+
 			page_main = cbt->map[i];
 			BUG_ON(page_main == NULL);
 			BUG_ON(page_main == CBT_PAGE_MISSED);
@@ -514,9 +514,11 @@  static int blk_cbt_snp_merge_back(struct request_queue *q, __u8 *uuid)
 
 	cbt->snp_map = NULL;
 	cbt->snp_block_max = 0;
+	ret = 0;
+out:
 	mutex_unlock(&cbt_mutex);
-
-	free_map(map, NR_PAGES(block_max));
+	if (ret == 0)
+		free_map(map, NR_PAGES(block_max));
 	return 0;
 }