block: handle -EBUSY in bdrv_commit_all()
Monitor operations that manipulate image files must not execute while a background job (like image streaming) is in progress. This prevents corruptions from happening when two pieces of code are manipulating the image file without knowledge of each other. The monitor "commit" command raises QERR_DEVICE_IN_USE when bdrv_commit() returns -EBUSY but "commit all" has no error handling. This is easy to fix, although note that we do not deliver a detailed error about which device was busy in the "commit all" case. Suggested-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
3cce16f44d
commit
e88774971c
8
block.c
8
block.c
@ -1244,13 +1244,17 @@ ro_cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_commit_all(void)
|
int bdrv_commit_all(void)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
|
|
||||||
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
||||||
bdrv_commit(bs);
|
int ret = bdrv_commit(bs);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BdrvTrackedRequest {
|
struct BdrvTrackedRequest {
|
||||||
|
2
block.h
2
block.h
@ -165,7 +165,7 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
|
|||||||
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
|
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
|
||||||
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
|
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
|
||||||
int bdrv_commit(BlockDriverState *bs);
|
int bdrv_commit(BlockDriverState *bs);
|
||||||
void bdrv_commit_all(void);
|
int bdrv_commit_all(void);
|
||||||
int bdrv_change_backing_file(BlockDriverState *bs,
|
int bdrv_change_backing_file(BlockDriverState *bs,
|
||||||
const char *backing_file, const char *backing_fmt);
|
const char *backing_file, const char *backing_fmt);
|
||||||
void bdrv_register(BlockDriver *bdrv);
|
void bdrv_register(BlockDriver *bdrv);
|
||||||
|
@ -627,12 +627,15 @@ void do_commit(Monitor *mon, const QDict *qdict)
|
|||||||
{
|
{
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!strcmp(device, "all")) {
|
if (!strcmp(device, "all")) {
|
||||||
bdrv_commit_all();
|
ret = bdrv_commit_all();
|
||||||
|
if (ret == -EBUSY) {
|
||||||
|
qerror_report(QERR_DEVICE_IN_USE, device);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int ret;
|
|
||||||
|
|
||||||
bs = bdrv_find(device);
|
bs = bdrv_find(device);
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
qerror_report(QERR_DEVICE_NOT_FOUND, device);
|
qerror_report(QERR_DEVICE_NOT_FOUND, device);
|
||||||
|
Loading…
Reference in New Issue
Block a user