qcow2: don't leave partially initialized file on image creation
v2 cover qcow2: don't leave partially initialized file on image creation
Use the bdrv_co_delete_file interface to delete the underlying file if qcow2 initilization fails (e.g due to bad encryption secret)
This gives the qcow2 the same treatment as to luks.
V2: added a patch to fix a memory leak.
Maxim Levitsky (2):
crypto: luks: fix tiny memory leak
block: qcow2: remove the created file on initialization error
block/crypto.c | 1 + block/qcow2.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
Signature · 1 line
2.26.2
PATCH v2 1/2 crypto: luks: fix tiny memory leak
In the case when underlying block device doesn't support the bdrv_co_delete_file interface, an 'Error' wasn't freed.
--- block/crypto.c | 1 + 1 file changed, 1 insertion(+)
block/crypto.c +1 -0
@@ -736,6 +736,7 @@ fail:if ((r_del <0 ) && (r_del != -ENOTSUP )) {error_report_err (local_delete_err); } +error_free (local_delete_err); }bdrv_unref (bs);
Signature · 1 line
2.26.2
Re: [PATCH v2 1/2] crypto: luks: fix tiny memory leak
Quoted 13 lines · Maxim Levitsky
In the case when underlying block device doesn't support the
bdrv_co_delete_fileinterface, an 'Error' wasn't freed.Signed-off-by Maxim Levitsky <[email protected]>--- block/crypto.c | 1 + 1 file changed, 1 insertion(+)block/crypto.c +0
-0
block/crypto.c fail: · line 740
Quoted 5 lines
block/crypto.c +1
-0@@ -736,6 +736,7 @@ fail:if ((r_del <0 ) && (r_del != -ENOTSUP )) {error_report_err (local_delete_err); } +error_free (local_delete_err); }
error_report_err() already calls error_free().
Berto
Re: [PATCH v2 1/2] crypto: luks: fix tiny memory leak
Quoted 9 lines · Alberto Garcia
Quoted 8 lines · Maxim Levitsky
In the case when underlying block device doesn't support the
bdrv_co_delete_fileinterface, an 'Error' wasn't freed.Signed-off-by Maxim Levitsky <[email protected]>--- block/crypto.c | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
block/crypto.c fail: · line 740
Quoted 10 lines
block/crypto.c +1
-0@@ -736,6 +736,7 @@ fail:if ((r_del <0 ) && (r_del != -ENOTSUP )) {error_report_err (local_delete_err); } +error_free (local_delete_err); }
error_report_err()already callserror_free().
Thanks. I didn't knew this.
Will send V3 soon.
Best regards,
Maxim Levitsky
Quoted 3 lines
Berto
PATCH v2 2/2 block: qcow2: remove the created file on initialization error
In reply to Maxim LevitskyIf the qcow initialization fails after we created the storage file, we should remove it to avoid leaving stale files around.
We already do this for luks raw images.
--- block/qcow2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
block/qcow2.c +12 -0
@@ -3834,6 +3834,18 @@ 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); + } +error_free (local_delete_err); goto finish; }
Signature · 1 line
2.26.2