Skip to contentSkip to conversation

block: Move read-only check during truncation earlier

PATCH Applied Eric Blake 3 participants 3 messages Jun 9, 2021 Block layer

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 block: Move read-only check during truncation earlier

No need to start a tracked request that will always fail. The choice to check read-only after bdrv_inc_in_flight() predates 1bc5f09f2e (block: Use tracked request for truncate), but waiting for serializing requests can make the effect more noticeable.

---
 block/io.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/io.c +5 -5
index 323854d06337..1a05f320d35e 100644
@@ -3390,6 +3390,11 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
         return old_size;
     }
 
+    if (bdrv_is_read_only(bs)) {
+        error_setg(errp, "Image is read-only");
+        return -EACCES;
+    }
+
     if (offset > old_size) {
         new_bytes = offset - old_size;
     } else {
@@ -3406,11 +3411,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
     if (new_bytes) {
         bdrv_make_request_serialising(&req, 1);
     }
-    if (bdrv_is_read_only(bs)) {
-        error_setg(errp, "Image is read-only");
-        ret = -EACCES;
-        goto out;
-    }
     ret = bdrv_co_write_req_prepare(child, offset - new_bytes, new_bytes, &req,
                                     0);
     if (ret < 0) {
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric Blake

No need to start a tracked request that will always fail. The choice to check read-only after bdrv_inc_in_flight() predates 1bc5f09f2e (block: Use tracked request for truncate), but waiting for serializing requests can make the effect more noticeable.

Signature · 2 lines
Best regards,
Vladimir
Applied
#2 lore raw
In reply to Eric Blake

Am 09.06.2021 um 18:30 hat Eric Blake geschrieben:

Quoted 6 lines

No need to start a tracked request that will always fail. The choice to check read-only after bdrv_inc_in_flight() predates 1bc5f09f2e (block: Use tracked request for truncate), but waiting for serializing requests can make the effect more noticeable.

Thanks, applied to the block branch.

Kevin