Skip to contentSkip to conversation

qcow2: cleanup created file when qcow2_co_create

PATCH In review Maxim Levitsky 2 participants 5 messages Jul 16, 2020 – Oct 11, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qcow2: cleanup created file when qcow2_co_create

This is basically the same thing as commit
'crypto.c: cleanup created file when block_crypto_co_create_opts_luks fails' does but for qcow2 files to ensure that we don't leave qcow2 files when creation fails.

---
 block/qcow2.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/qcow2.c +11 -0
index fadf3422f8..8b848924b5 100644
@@ -3794,6 +3794,17 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
     /* Create the qcow2 image (format layer) */
     ret = qcow2_co_create(create_options, errp);
     if (ret < 0) {
+
+        Error *local_delete_err = NULL;
+        int r_del = bdrv_co_delete_file(bs, &local_delete_err);
+        /*
+         * ENOTSUP will happen if the block driver doesn't support
+         * the 'bdrv_co_delete_file' interface. This is a predictable
+         * scenario and shouldn't be reported back to the user.
+         */
+        if ((r_del < 0) && (r_del != -ENOTSUP)) {
+            error_report_err(local_delete_err);
+        }
         goto finish;
     }
 
Signature · 1 line
2.26.2
#1 lore raw
Quoted 22 lines · Maxim Levitsky

This is basically the same thing as commit
'crypto.c: cleanup created file when block_crypto_co_create_opts_luks fails' does but for qcow2 files to ensure that we don't leave qcow2 files when creation fails.

---
 block/qcow2.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/qcow2.c +4 -0
index fadf3422f8..8b848924b5 100644
@@ -3794,6 +3794,17 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
     /* Create the qcow2 image (format layer) */
     ret = qcow2_co_create(create_options, errp);
     if (ret < 0) {
+
+        Error *local_delete_err = NULL;
+        int r_del = bdrv_co_delete_file(bs, &local_delete_err);
+        /*

block/qcow2.c static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, · line 3810

Quoted 10 lines
block/qcow2.c +7 -0
+         * ENOTSUP will happen if the block driver doesn't support
+         * the 'bdrv_co_delete_file' interface. This is a predictable
+         * scenario and shouldn't be reported back to the user.
+         */
+        if ((r_del < 0) && (r_del != -ENOTSUP)) {
+            error_report_err(local_delete_err);
+        }
         goto finish;
     }
 

Any update on this? Do you think we can add this to 5.1 or is it too late? Best regards,
Maxim Levitsky

#2 lore raw
In reply to Maxim Levitsky
Quoted 6 lines · Maxim Levitsky

This is basically the same thing as commit
'crypto.c: cleanup created file when block_crypto_co_create_opts_luks fails' does but for qcow2 files to ensure that we don't leave qcow2 files when creation fails.

Very kind ping on this patch.

Best regards,
Maxim levitsky

Quoted 26 lines
---
 block/qcow2.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/qcow2.c +11 -0
index fadf3422f8..8b848924b5 100644
@@ -3794,6 +3794,17 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
     /* Create the qcow2 image (format layer) */
     ret = qcow2_co_create(create_options, errp);
     if (ret < 0) {
+
+        Error *local_delete_err = NULL;
+        int r_del = bdrv_co_delete_file(bs, &local_delete_err);
+        /*
+         * ENOTSUP will happen if the block driver doesn't support
+         * the 'bdrv_co_delete_file' interface. This is a predictable
+         * scenario and shouldn't be reported back to the user.
+         */
+        if ((r_del < 0) && (r_del != -ENOTSUP)) {
+            error_report_err(local_delete_err);
+        }
         goto finish;
     }
 
#3 lore raw
In reply to Maxim Levitsky

block/qcow2.c static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, · line 3807

Quoted 12 lines · Maxim Levitsky
     if (ret < 0) {
block/qcow2.c +11 -0
+
+        Error *local_delete_err = NULL;
+        int r_del = bdrv_co_delete_file(bs, &local_delete_err);
+        /*
+         * ENOTSUP will happen if the block driver doesn't support
+         * the 'bdrv_co_delete_file' interface. This is a predictable
+         * scenario and shouldn't be reported back to the user.
+         */
+        if ((r_del < 0) && (r_del != -ENOTSUP)) {
+            error_report_err(local_delete_err);
+        }

I think you're leaking the error on ENOTSUP.

Berto

#4 lore raw
Quoted 14 lines · Alberto Garcia

block/qcow2.c static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, · line 3807

Quoted 12 lines · Maxim Levitsky
     if (ret < 0) {
block/qcow2.c +11 -0
+
+        Error *local_delete_err = NULL;
+        int r_del = bdrv_co_delete_file(bs, &local_delete_err);
+        /*
+         * ENOTSUP will happen if the block driver doesn't support
+         * the 'bdrv_co_delete_file' interface. This is a predictable
+         * scenario and shouldn't be reported back to the user.
+         */
+        if ((r_del < 0) && (r_del != -ENOTSUP)) {
+            error_report_err(local_delete_err);
+        }
Quoted 1 line

I think you're leaking the error on ENOTSUP.

Indeed, just like in the original code from where I copy&pasta'ed this from. I'll send a patch to fix this and update the patch as well.

Thanks,
Best regards,
Maxim Levitsky

Quoted 3 lines

Berto