mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 16:23:55 -06:00
block: Protect bs->file with graph_lock
Almost all functions that access bs->file already take the graph lock now. Add locking to the remaining users and finally annotate the struct field itself as protected by the graph lock. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20231027155333.420094-25-kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
a4b740db5e
commit
1f051dcbdf
15 changed files with 97 additions and 41 deletions
14
block/vmdk.c
14
block/vmdk.c
|
@ -300,7 +300,8 @@ static void vmdk_free_last_extent(BlockDriverState *bs)
|
|||
}
|
||||
|
||||
/* Return -ve errno, or 0 on success and write CID into *pcid. */
|
||||
static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid)
|
||||
static int GRAPH_RDLOCK
|
||||
vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid)
|
||||
{
|
||||
char *desc;
|
||||
uint32_t cid;
|
||||
|
@ -415,6 +416,9 @@ static int vmdk_reopen_prepare(BDRVReopenState *state,
|
|||
BDRVVmdkReopenState *rs;
|
||||
int i;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||
|
||||
assert(state != NULL);
|
||||
assert(state->bs != NULL);
|
||||
assert(state->opaque == NULL);
|
||||
|
@ -451,6 +455,9 @@ static void vmdk_reopen_commit(BDRVReopenState *state)
|
|||
BDRVVmdkReopenState *rs = state->opaque;
|
||||
int i;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||
|
||||
for (i = 0; i < s->num_extents; i++) {
|
||||
if (rs->extents_using_bs_file[i]) {
|
||||
s->extents[i].file = state->bs->file;
|
||||
|
@ -465,7 +472,7 @@ static void vmdk_reopen_abort(BDRVReopenState *state)
|
|||
vmdk_reopen_clean(state);
|
||||
}
|
||||
|
||||
static int vmdk_parent_open(BlockDriverState *bs)
|
||||
static int GRAPH_RDLOCK vmdk_parent_open(BlockDriverState *bs)
|
||||
{
|
||||
char *p_name;
|
||||
char *desc;
|
||||
|
@ -2547,7 +2554,10 @@ vmdk_co_do_create(int64_t size,
|
|||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
bdrv_graph_co_rdlock();
|
||||
ret = vmdk_read_cid(blk_bs(backing), 0, &parent_cid);
|
||||
bdrv_graph_co_rdunlock();
|
||||
blk_co_unref(backing);
|
||||
if (ret) {
|
||||
error_setg(errp, "Failed to read parent CID");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue