mirror of https://github.com/xemu-project/xemu.git
block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_apply_auto_read_only() need to hold a reader lock for the graph because it calls bdrv_can_set_read_only(), which indirectly accesses the parents list of a node. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-ID: <20230929145157.45443-19-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
277f2007ce
commit
018f9dea9c
4
block.c
4
block.c
|
@ -320,8 +320,6 @@ int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
IO_CODE();
|
IO_CODE();
|
||||||
|
|
||||||
assume_graph_lock(); /* FIXME */
|
|
||||||
|
|
||||||
if (!(bs->open_flags & BDRV_O_RDWR)) {
|
if (!(bs->open_flags & BDRV_O_RDWR)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1908,7 +1906,9 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
|
||||||
|
|
||||||
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, ro)) {
|
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, ro)) {
|
||||||
if (!ro && bdrv_is_whitelisted(drv, true)) {
|
if (!ro && bdrv_is_whitelisted(drv, true)) {
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
ret = bdrv_apply_auto_read_only(bs, NULL, NULL);
|
ret = bdrv_apply_auto_read_only(bs, NULL, NULL);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
} else {
|
} else {
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,9 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* No write support yet */
|
/* No write support yet */
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,9 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
uint32_t offsets_size, max_compressed_block_size = 1, i;
|
uint32_t offsets_size, max_compressed_block_size = 1, i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -696,8 +696,10 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
const char *protocol_delimiter;
|
const char *protocol_delimiter;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
ret = bdrv_apply_auto_read_only(bs, "curl driver does not support writes",
|
ret = bdrv_apply_auto_read_only(bs, "curl driver does not support writes",
|
||||||
errp);
|
errp);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,7 +452,9 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
ret = bdrv_apply_auto_read_only(bs, NULL, errp);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -863,11 +863,13 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
|
||||||
if (ret == -EACCES || ret == -EROFS) {
|
if (ret == -EACCES || ret == -EROFS) {
|
||||||
/* Try to degrade to read-only, but if it doesn't work, still use the
|
/* Try to degrade to read-only, but if it doesn't work, still use the
|
||||||
* normal error message. */
|
* normal error message. */
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
if (bdrv_apply_auto_read_only(bs, NULL, NULL) == 0) {
|
if (bdrv_apply_auto_read_only(bs, NULL, NULL) == 0) {
|
||||||
open_flags = (open_flags & ~O_RDWR) | O_RDONLY;
|
open_flags = (open_flags & ~O_RDWR) | O_RDONLY;
|
||||||
s->fd = glfs_open(s->glfs, gconf->path, open_flags);
|
s->fd = glfs_open(s->glfs, gconf->path, open_flags);
|
||||||
ret = s->fd ? 0 : -errno;
|
ret = s->fd ? 0 : -errno;
|
||||||
}
|
}
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
s->supports_seek_data = qemu_gluster_test_seek(s->fd);
|
s->supports_seek_data = qemu_gluster_test_seek(s->fd);
|
||||||
|
|
|
@ -1925,7 +1925,9 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
/* Check the write protect flag of the LUN if we want to write */
|
/* Check the write protect flag of the LUN if we want to write */
|
||||||
if (iscsilun->type == TYPE_DISK && (flags & BDRV_O_RDWR) &&
|
if (iscsilun->type == TYPE_DISK && (flags & BDRV_O_RDWR) &&
|
||||||
iscsilun->write_protected) {
|
iscsilun->write_protected) {
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
ret = bdrv_apply_auto_read_only(bs, "LUN is write protected", errp);
|
ret = bdrv_apply_auto_read_only(bs, "LUN is write protected", errp);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,8 @@ static bool nbd_client_will_reconnect(BDRVNBDState *s)
|
||||||
* Return failure if the server's advertised options are incompatible with the
|
* Return failure if the server's advertised options are incompatible with the
|
||||||
* client's needs.
|
* client's needs.
|
||||||
*/
|
*/
|
||||||
static int nbd_handle_updated_info(BlockDriverState *bs, Error **errp)
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
|
nbd_handle_updated_info(BlockDriverState *bs, Error **errp)
|
||||||
{
|
{
|
||||||
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
|
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
@ -1168,7 +1168,9 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
/* If we are using an rbd snapshot, we must be r/o, otherwise
|
/* If we are using an rbd snapshot, we must be r/o, otherwise
|
||||||
* leave as-is */
|
* leave as-is */
|
||||||
if (s->snap != NULL) {
|
if (s->snap != NULL) {
|
||||||
|
bdrv_graph_rdlock_main_loop();
|
||||||
r = bdrv_apply_auto_read_only(bs, "rbd snapshots are read-only", errp);
|
r = bdrv_apply_auto_read_only(bs, "rbd snapshots are read-only", errp);
|
||||||
|
bdrv_graph_rdunlock_main_loop();
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
goto failed_post_open;
|
goto failed_post_open;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,8 +163,10 @@ bdrv_is_allocated_above(BlockDriverState *bs, BlockDriverState *base,
|
||||||
int coroutine_fn GRAPH_RDLOCK
|
int coroutine_fn GRAPH_RDLOCK
|
||||||
bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes);
|
bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes);
|
||||||
|
|
||||||
int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
|
int GRAPH_RDLOCK
|
||||||
|
bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
|
|
||||||
bool bdrv_is_read_only(BlockDriverState *bs);
|
bool bdrv_is_read_only(BlockDriverState *bs);
|
||||||
bool bdrv_is_writable(BlockDriverState *bs);
|
bool bdrv_is_writable(BlockDriverState *bs);
|
||||||
bool bdrv_is_sg(BlockDriverState *bs);
|
bool bdrv_is_sg(BlockDriverState *bs);
|
||||||
|
|
Loading…
Reference in New Issue