block: Ensure non-protocol drivers can only be selected explicitly
cover block: Ensure non-protocol drivers can only be selected explicitly
Block drivers can be selected by either protocol syntax:
<protocol>:<filename>[:options]
or explicitly:
driver=<driver>[,option=<opt1>...]
For the protocol syntax to work, drivers should set the protocol_name field of the BlockDriver structure and provide bdrv_file_open and bdrv_parse_filename implementations.
Conversely, block drivers that do not support the protocol syntax should instead implement bdrv_open and not have a protocol_name field.
Some drivers do not currently adhere to this and errors arise when trying to select them using the protocol syntax. For instance:
$ qemu-img info replication:foo qemu-img: block.c:2401: bdrv_open_inherit: \ Assertion `!!(flags & BDRV_O_PROTOCOL) == !!drv->bdrv_file_open' failed. Aborted (core dumped)
This patch-set ensures that the following drivers are meeting the above criteria:
- blkreplay
- quorum
- replication
- throttle
Aside from that, documentation was added to make the above more explicit.
Fabiano Rosas (5):
block/replication: Remove protocol_name field block/quorum: Remove protocol-related fields block/throttle: Remove protocol-related fields block/blkreplay: Remove protocol-related fields include/block/block_int: Document protocol related functions
block/blkreplay.c | 3 +-- block/quorum.c | 3 +-- block/replication.c | 1 - block/throttle.c | 3 +-- include/block/block_int.h | 6 ++++++ replication.h | 1 - 6 files changed, 9 insertions(+), 8 deletions(-)
--
2.13.6
PATCH 1/5 block/replication: Remove protocol_name field
The replication driver is only selected explicitly (via driver=replication,mode=primary,...) so it is not a protocol driver.
This patch removes the protocol_name field from the brdv_replication structure so that attempts to invoke this driver using protocol syntax (i.e. replication:<filename:options:...>) will fail gracefully:
$ qemu-img info replication:foo qemu-img: Could not open 'replication:': Unknown protocol 'replication'
--- block/replication.c | 1 - replication.h | 1 - 2 files changed, 2 deletions(-)
block/replication.c +0 -1
@@ -703,7 +703,6 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)BlockDriver bdrv_replication = { .format_name ="replication" , - .protocol_name ="replication" , .instance_size =sizeof (BDRVReplicationState), .bdrv_open = replication_open,
replication.h +0 -1
@@ -67,7 +67,6 @@ typedef struct ReplicationState ReplicationState;* * BlockDriver bdrv_replication = { * .format_name = "replication", -* .protocol_name = "replication", * .instance_size = sizeof(BDRVReplicationState), * * .bdrv_open = replication_open,
Signature · 1 line
2.13.6
PATCH 2/5 block/quorum: Remove protocol-related fields
In reply to Fabiano RosasThe quorum driver is not a protocol so it should implement bdrv_open instead of bdrv_file_open and not provide a protocol_name.
Attempts to invoke this driver using protocol syntax (i.e. quorum:<filename:options:...>) will now fail gracefully:
$ qemu-img info quorum:foo qemu-img: Could not open 'quorum:foo': Unknown protocol 'quorum'
--- block/quorum.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/quorum.c +1 -2
@@ -1098,11 +1098,10 @@ static void quorum_refresh_filename(BlockDriverState *bs, QDict *options)static BlockDriver bdrv_quorum = { .format_name ="quorum" , - .protocol_name ="quorum" , .instance_size =sizeof (BDRVQuorumState), - .bdrv_file_open = quorum_open, + .bdrv_open = quorum_open, .bdrv_close = quorum_close, .bdrv_refresh_filename = quorum_refresh_filename,
Signature · 1 line
2.13.6
PATCH 3/5 block/throttle: Remove protocol-related fields
In reply to Fabiano RosasThe throttle driver is not a protocol so it should implement bdrv_open instead of bdrv_file_open and not provide a protocol_name.
Attempts to invoke this driver using protocol syntax (i.e. throttle:<filename:options:...>) will now fail gracefully:
$ qemu-img info throttle:foo qemu-img: Could not open 'throttle:foo': Unknown protocol 'throttle'
--- block/throttle.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/throttle.c +1 -2
@@ -215,10 +215,9 @@ static void coroutine_fn throttle_co_drain_end(BlockDriverState *bs)static BlockDriver bdrv_throttle = { .format_name ="throttle" , - .protocol_name ="throttle" , .instance_size =sizeof (ThrottleGroupMember), - .bdrv_file_open = throttle_open, + .bdrv_open = throttle_open, .bdrv_close = throttle_close, .bdrv_co_flush = throttle_co_flush,
Signature · 1 line
2.13.6
PATCH 4/5 block/blkreplay: Remove protocol-related fields
In reply to Fabiano RosasThe blkreplay driver is not a protocol so it should implement bdrv_open instead of bdrv_file_open and not provide a protocol_name.
Attempts to invoke this driver using protocol syntax (i.e. blkreplay:<filename:options:...>) will now fail gracefully:
$ qemu-img info blkreplay:foo qemu-img: Could not open 'blkreplay:foo': Unknown protocol 'blkreplay'
--- block/blkreplay.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/blkreplay.c +1 -2
@@ -129,10 +129,9 @@ static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)static BlockDriver bdrv_blkreplay = { .format_name ="blkreplay" , - .protocol_name ="blkreplay" , .instance_size =0 , - .bdrv_file_open = blkreplay_open, + .bdrv_open = blkreplay_open, .bdrv_close = blkreplay_close, .bdrv_child_perm = bdrv_filter_default_perms, .bdrv_getlength = blkreplay_getlength,
Signature · 1 line
2.13.6
PATCH 5/5 include/block/block_int: Document protocol related functions
In reply to Fabiano RosasClarify that for protocols the brdv_file_open function is used instead of bdrv_open and that protocol_name is expected to be set.
--- include/block/block_int.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/block/block_int.h +6 -0
@@ -126,6 +126,8 @@ struct BlockDriver {int (*bdrv_open)(BlockDriverState *bs,QDict *options,int flags,Error **errp); + +/* Protocol drivers should implement this instead of bdrv_open */ int (*bdrv_file_open)(BlockDriverState *bs,QDict *options,int flags,Error **errp);void (*bdrv_close)(BlockDriverState *bs);
@@ -247,6 +249,10 @@ struct BlockDriver {*/ int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); +/* +* Drivers that set this field should also provide a +* bdrv_file_open implementation +*/ const char *protocol_name;int (*bdrv_truncate)(BlockDriverState *bs,int64_t offset,PreallocMode prealloc,Error **errp);
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH 4/5] block/blkreplay: Remove protocol-related fields
In reply to Fabiano RosasQuoted 32 lines
From: Fabiano Rosas [mailto:[email protected]]
The blkreplay driver is not a protocol so it should implementbdrv_openinstead ofbdrv_file_openand not provide aprotocol_name.Attempts to invoke this driver using protocol syntax (i.e. blkreplay:<filename:options:...>) will now fail gracefully:
$ qemu-img info blkreplay:foo qemu-img: Could not open 'blkreplay:foo': Unknown protocol 'blkreplay'Signed-off-by Fabiano Rosas <[email protected]>--- block/blkreplay.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)block/blkreplay.c +1
-3@@ -129,10 +129,9 @@ static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)static BlockDriver bdrv_blkreplay = { .format_name ="blkreplay" , - .protocol_name ="blkreplay" , .instance_size =0 , - .bdrv_file_open = blkreplay_open, + .bdrv_open = blkreplay_open, .bdrv_close = blkreplay_close, .bdrv_child_perm = bdrv_filter_default_perms, .bdrv_getlength = blkreplay_getlength, --
Quoted 1 line
2.13.6
Pavel Dovgalyuk
Re: [Qemu-devel] [PATCH 1/5] block/replication: Remove protocol_name field
In reply to Fabiano RosasQuoted 2 lines · Fabiano Rosas
The replication driver is only selected explicitly (via driver=replication,mode=primary,...) so it is not a protocol driver.
That's not really the point. It isn't a protocol driver because it has a "file" child (opened in replication_open). All in all it's a filter driver.
Apart from that, having a protocol_name might still be OK even for non-protocol drivers; for instance, blkdebug and blkverify are both filter drivers, but since they implement bdrv_parse_filename() it's OK for them to specify protocol_name.
So your sentence is half correct. Because it can only be selected explicitly (for several reasons), giving a protocol_name doesn't make sense. (Independently of whether it is a protocol driver or not.)
But anyway:
Quoted 39 lines
This patch removes the
protocol_namefield from thebrdv_replicationstructure so that attempts to invoke this driver using protocol syntax (i.e. replication:<filename:options:...>) will fail gracefully:$ qemu-img info replication:foo qemu-img: Could not open 'replication:': Unknown protocol 'replication'Signed-off-by Fabiano Rosas <[email protected]>--- block/replication.c | 1 - replication.h | 1 - 2 files changed, 2 deletions(-)block/replication.c +0
-1@@ -703,7 +703,6 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp)BlockDriver bdrv_replication = { .format_name ="replication" , - .protocol_name ="replication" , .instance_size =sizeof (BDRVReplicationState), .bdrv_open = replication_open,replication.h +0
-1@@ -67,7 +67,6 @@ typedef struct ReplicationState ReplicationState;* * BlockDriver bdrv_replication = { * .format_name = "replication", -* .protocol_name = "replication", * .instance_size = sizeof(BDRVReplicationState), * * .bdrv_open = replication_open,
Re: [Qemu-devel] [PATCH 2/5] block/quorum: Remove protocol-related fields
In reply to Fabiano RosasQuoted 6 lines · Fabiano Rosas
The quorum driver is not a protocol so it should implement
bdrv_openinstead ofbdrv_file_openand not provide aprotocol_name.Attempts to invoke this driver using protocol syntax (i.e. quorum:<filename:options:...>) will now fail gracefully:
Quoted 7 lines
$ qemu-img info quorum:foo qemu-img: Could not open 'quorum:foo': Unknown protocol 'quorum'Signed-off-by Fabiano Rosas <[email protected]>--- block/quorum.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [Qemu-devel] [PATCH 3/5] block/throttle: Remove protocol-related fields
In reply to Fabiano RosasQuoted 6 lines · Fabiano Rosas
The throttle driver is not a protocol so it should implement
bdrv_openinstead ofbdrv_file_openand not provide aprotocol_name.Attempts to invoke this driver using protocol syntax (i.e. throttle:<filename:options:...>) will now fail gracefully:
Quoted 7 lines
$ qemu-img info throttle:foo qemu-img: Could not open 'throttle:foo': Unknown protocol 'throttle'Signed-off-by Fabiano Rosas <[email protected]>--- block/throttle.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [Qemu-devel] [PATCH 4/5] block/blkreplay: Remove protocol-related fields
In reply to Fabiano RosasQuoted 6 lines · Fabiano Rosas
The blkreplay driver is not a protocol so it should implement
bdrv_openinstead ofbdrv_file_openand not provide aprotocol_name.Attempts to invoke this driver using protocol syntax (i.e. blkreplay:<filename:options:...>) will now fail gracefully:
Quoted 7 lines
$ qemu-img info blkreplay:foo qemu-img: Could not open 'blkreplay:foo': Unknown protocol 'blkreplay'Signed-off-by Fabiano Rosas <[email protected]>--- block/blkreplay.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [Qemu-devel] [PATCH 5/5] include/block/block_int: Document protocol related functions
In reply to Fabiano RosasQuoted 22 lines · Fabiano Rosas
Clarify that for protocols the
brdv_file_openfunction is used instead ofbdrv_openand thatprotocol_nameis expected to be set.Signed-off-by Fabiano Rosas <[email protected]>--- include/block/block_int.h | 6 ++++++ 1 file changed, 6 insertions(+)include/block/block_int.h +2
-0@@ -126,6 +126,8 @@ struct BlockDriver {int (*bdrv_open)(BlockDriverState *bs,QDict *options,int flags,Error **errp); + +/* Protocol drivers should implement this instead of bdrv_open */ int (*bdrv_file_open)(BlockDriverState *bs,QDict *options,int flags,Error **errp);void (*bdrv_close)(BlockDriverState *bs);
include/block/block_int.h struct BlockDriver { · line 254
Quoted 6 lines
include/block/block_int.h +3
-0@@ -247,6 +249,10 @@ struct BlockDriver {*/ int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); +/* +* Drivers that set this field should also provide a +* bdrv_file_open implementation
Well... In a sense.
Drivers that implement this should be expected to be given only a filename and no other options. Therefore, they should generally implement .bdrv_parse_filename() so they can extract options from it (exception: gluster, which parses the whole filename in its .bdrv_file_open() implementation).
(Or maybe they can just accept a URL and don't need to extract options from it, like curl or file.)
So the stress lies on "Drivers setting this field must be able to work with just a plain filename with this prefix, and no other options." (Note that all of the drivers you removed this field from in this series violated this. They expect some other options and cannot work without.)
A driver doesn't need to be a protocol driver for this, and technically a protocol driver doesn't need to set this. Maybe we should rename it to "filename_prefix"...?
Max
Quoted 5 lines
include/block/block_int.h +1
-0+*/ const char *protocol_name;int (*bdrv_truncate)(BlockDriverState *bs,int64_t offset,PreallocMode prealloc,Error **errp);
Re: [Qemu-devel] [PATCH 5/5] include/block/block_int: Document protocol related functions
Quoted 3 lines · Max Reitz
A driver doesn't need to be a protocol driver for this, and technically a protocol driver doesn't need to set this. Maybe we should rename it to "
filename_prefix"...?
Yes, something that is closer to the filename string and farther from the notion of what defines a protocol would be good. I see "protocol prefix" mentioned in block.c, maybe that would be a good middle ground.
Cheers