delete created files when block_crypto_co_create_opts_luks fails
A message that is not in the archive (sent off-list or not yet received): [email protected]
Ping
Quoted 22 lines · Daniel Henrique Barboza
In this new interation, the following changes were made from the previous version [1]:
- moved the 'generic' code fromblock.ctofile-posix.c
- moved the file delete call fromqemu_imgto the error path ofblock_crypto_co_create_opts_luks[1] https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg06444.html
Daniel Henrique Barboza (3):
block: introducing 'bdrv_co_delete_file' interfaceblock.c: addingbdrv_delete_file
crypto.c: cleanup created file whenblock_crypto_co_create_opts_luks
failsblock.c | 82 +++++++++++++++++++++++++++++++++++++++ block/crypto.c | 31 +++++++++++++++ block/file-posix.c | 28 +++++++++++++ include/block/block.h | 3 ++ include/block/block_int.h | 6 +++ 5 files changed, 150 insertions(+)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Qemu-devel] [Qemu-block] [PATCH v3 1/3] block: introducing 'bdrv_co_delete_file' interface
It looks like this one has gone un-noticed for a little while.
Quoted 49 lines · Daniel Henrique Barboza
Adding to Block Drivers the capability of being able to clean up its created files can be useful in certain situations. For the LUKS driver, for instance, a failure in one of its authentication steps can leave files in the host that weren't there before.
This patch adds the '
bdrv_co_delete_file' interface to block drivers and add it to the 'file' driver infile-posix.c. The implementation is given by 'raw_co_delete_file'. The helper 'bdrv_path_is_regular_file' is being used only inraw_co_delete_fileat this moment, but it will be used inside LUKS in a later patch. Foreseeing this future use, let's put it inblock.cand make it public.Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>--- block.c | 11 +++++++++++ block/file-posix.c | 28 ++++++++++++++++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 6 ++++++ 4 files changed, 46 insertions(+)block.c +11
-0@@ -621,6 +621,17 @@ int get_tmp_filename(char *filename, int size)#endif } +/** +* Helper that checks if a given string represents a regular +* local file. +*/ +bool bdrv_path_is_regular_file (const char *path) +{ +struct stat st; + +return (stat (path, &st) ==0 ) &&S_ISREG (st.st_mode); +} +/* * Detect host devices. By convention, /dev/cdrom[N] is always * recognized as a host CDROM. block/file-posix.c +0
-0
block/file-posix.c static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, · line 2349
Quoted 8 lines
block/file-posix.c +5
-0@@ -2342,6 +2342,33 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,return raw_co_create (&options, errp); } +/** +* Co-routine function that erases a regular file. +*/ +static int coroutine_fn raw_co_delete_file(const char *filename, +Error **errp)
Do we need to mark functions that make no use of coroutines as coroutine_fn? I guess this way the interface is *allowed* to be a coroutine if other drivers need to make use of that.
block/file-posix.c static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, · line 2355
Quoted 6 lines
block/file-posix.c +6
-0+{ +int ret; + +/* Skip file: protocol prefix */ +strstart (filename,"file:" , &filename); +
This sticks out as fragile to me, but I guess that's exactly how create works, so... OK.
Quoted 47 lines
block/file-posix.c +17
-0+if (!bdrv_path_is_regular_file (filename)) { + ret = -ENOENT ; +error_setg_errno (errp, -ret,"%s is not a regular file" , filename); + goto done; + } + + ret =unlink (filename); +if (ret <0 ) { + ret = -errno; +error_setg_errno (errp, -ret,"Error when deleting file %s" , filename); + } + +done: +return ret; +} +/* * Find allocation range in @bs around offset @start. * May change underlying file descriptor's file offset. @@ -2867,6 +2894,7 @@ BlockDriver bdrv_file = { .bdrv_co_block_status = raw_co_block_status, .bdrv_co_invalidate_cache = raw_co_invalidate_cache, .bdrv_co_pwrite_zeroes = raw_co_pwrite_zeroes, + .bdrv_co_delete_file = raw_co_delete_file, .bdrv_co_preadv = raw_co_preadv, .bdrv_co_pwritev = raw_co_pwritev,include/block/block.h +1
-0@@ -363,6 +363,7 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base, Error **errp);void bdrv_unfreeze_backing_chain (BlockDriverState *bs,BlockDriverState *base); +bool bdrv_path_is_regular_file (const char *path); typedef struct BdrvCheckResult { int corruptions;include/block/block_int.h +0
-0@@ -309,6 +309,12 @@ struct BlockDriver {*/ int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs);
include/block/block_int.h struct BlockDriver { · line 320
Quoted 10 lines
include/block/block_int.h +6
-0+/* +* Delete a local created file. +*/ + int coroutine_fn (*bdrv_co_delete_file)(const char *filename, +Error **errp); +/* * Flushes all data that was already written to the OS all the way down to * the disk (for example file-posix.c calls fsync()).
Seems alright at a glance, if we want this interface.
Kevin, do we?
--js
Re: [Qemu-devel] [Qemu-block] [PATCH v3 1/3] block: introducing 'bdrv_co_delete_file' interface
Hi John,
Quoted 55 lines · John Snow
It looks like this one has gone un-noticed for a little while.
Quoted 52 lines · Daniel Henrique Barboza
Adding to Block Drivers the capability of being able to clean up its created files can be useful in certain situations. For the LUKS driver, for instance, a failure in one of its authentication steps can leave files in the host that weren't there before.
This patch adds the '
bdrv_co_delete_file' interface to block drivers and add it to the 'file' driver infile-posix.c. The implementation is given by 'raw_co_delete_file'. The helper 'bdrv_path_is_regular_file' is being used only inraw_co_delete_fileat this moment, but it will be used inside LUKS in a later patch. Foreseeing this future use, let's put it inblock.cand make it public.Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>--- block.c | 11 +++++++++++ block/file-posix.c | 28 ++++++++++++++++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 6 ++++++ 4 files changed, 46 insertions(+)block.c +11
-0@@ -621,6 +621,17 @@ int get_tmp_filename(char *filename, int size)#endif } +/** +* Helper that checks if a given string represents a regular +* local file. +*/ +bool bdrv_path_is_regular_file (const char *path) +{ +struct stat st; + +return (stat (path, &st) ==0 ) &&S_ISREG (st.st_mode); +} +/* * Detect host devices. By convention, /dev/cdrom[N] is always * recognized as a host CDROM. block/file-posix.c +0
-0@@ -2342,6 +2342,33 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,return raw_co_create (&options, errp); }
Quoted 8 lines
block/file-posix.c static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, · line 2349
Quoted 5 lines
block/file-posix.c +5
-0+/** +* Co-routine function that erases a regular file. +*/ +static int coroutine_fn raw_co_delete_file(const char *filename, +Error **errp)Do we need to mark functions that make no use of coroutines as
coroutine_fn? I guess this way the interface is *allowed* to be a coroutine if other drivers need to make use of that.
This function is used in a coroutine in patch 2. But to be honest, what I did here was to emulate the existing behavior of bdrv_create. Which is kind of lame if bdrv_create happens to have design problems or inconsistencies, but at least it's based on something that's already working.
Quoted 9 lines
block/file-posix.c static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, · line 2355
Quoted 7 lines
block/file-posix.c +6
-0+{ +int ret; + +/* Skip file: protocol prefix */ +strstart (filename,"file:" , &filename); +This sticks out as fragile to me, but I guess that's exactly how create works, so... OK.
Yep, create does the same thing.
Thanks,
DHB
Quoted 63 lines
Quoted 48 lines
block/file-posix.c +17
-0+if (!bdrv_path_is_regular_file (filename)) { + ret = -ENOENT ; +error_setg_errno (errp, -ret,"%s is not a regular file" , filename); + goto done; + } + + ret =unlink (filename); +if (ret <0 ) { + ret = -errno; +error_setg_errno (errp, -ret,"Error when deleting file %s" , filename); + } + +done: +return ret; +} +/* * Find allocation range in @bs around offset @start. * May change underlying file descriptor's file offset. @@ -2867,6 +2894,7 @@ BlockDriver bdrv_file = { .bdrv_co_block_status = raw_co_block_status, .bdrv_co_invalidate_cache = raw_co_invalidate_cache, .bdrv_co_pwrite_zeroes = raw_co_pwrite_zeroes, + .bdrv_co_delete_file = raw_co_delete_file, .bdrv_co_preadv = raw_co_preadv, .bdrv_co_pwritev = raw_co_pwritev,include/block/block.h +1
-0@@ -363,6 +363,7 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base, Error **errp);void bdrv_unfreeze_backing_chain (BlockDriverState *bs,BlockDriverState *base); +bool bdrv_path_is_regular_file (const char *path); typedef struct BdrvCheckResult { int corruptions;include/block/block_int.h +0
-0@@ -309,6 +309,12 @@ struct BlockDriver {*/ int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs);include/block/block_int.h struct BlockDriver { · line 320
Quoted 10 lines
include/block/block_int.h +6
-0+/* +* Delete a local created file. +*/ + int coroutine_fn (*bdrv_co_delete_file)(const char *filename, +Error **errp); +/* * Flushes all data that was already written to the OS all the way down to * the disk (for example file-posix.c calls fsync()). Seems alright at a glance, if we want this interface.
Kevin, do we?
--js