* [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames
@ 2014-03-06 22:25 Max Reitz
2014-03-06 22:25 ` [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev Max Reitz
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
As some kind of follow-up to the "block: Strip 'file:' prefix from
filenames" series, this series does the same thing for other protocol
drivers.
All protocol drivers which implement bdrv_probe() may rely on them being
selected based on that function returning success alone. However, they
may have been chosen through a protocol prefix as well. Thus, if they
currently do not implement bdrv_parse_filename(), they may be unaware of
that possible prefix and therefore fail to interpret such filenames
(and, in fact, all of those are unaware).
This series makes these drivers strip their respective prefix through
bdrv_parse_filename() and in bdrv_create(), if implemented.
The following protocol drivers are not touched by this series since they
already implement bdrv_parse_filename() and are thus very likely aware
of the prefix:
- vvfat, nbd, blkdebug, blkverify, ssh, curl
The following protocol drivers are not touched by this series since they
do not implement bdrv_probe() and therefore always receive a prefixed
filename (unless they are selected through QMP options) which makes them
pretty much guaranteed to handle these prefixes correctly:
- nfs, sheepdog, rbd, quorum, gluster, iscsi
Thus, only drivers implementing bdrv_probe() and not implementing
bdrv_parse_filename() have been touched.
Please note that this series does not strip the prefix in bdrv_probe().
This is due to the driver being selected anyway later on through the
protocol prefix, even though bdrv_probe() returned 0. More importantly,
according to a comment in bdrv_find_protocol() in block.c about why
bdrv_probe() occurs before the protocol prefix is interpreted, it seems
actually more desirable not to strip the prefix in bdrv_probe() (since
it may in fact not be a prefix but rather some obscure device naming
schema).
Max Reitz (5):
block/raw-posix: bdrv_parse_filename() for hdev
block/raw-posix: bdrv_parse_filename() for floppy
block/raw-posix: bdrv_parse_filename() for cdrom
block/raw-posix: Strip protocol prefix on creation
block/raw-win32: bdrv_parse_filename() for hdev
block/raw-posix.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
block/raw-win32.c | 10 ++++++++++
2 files changed, 62 insertions(+)
--
1.9.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev
2014-03-06 22:25 [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames Max Reitz
@ 2014-03-06 22:25 ` Max Reitz
2014-03-06 22:38 ` Benoît Canet
2014-03-06 22:25 ` [Qemu-devel] [PATCH 2/5] block/raw-posix: bdrv_parse_filename() for floppy Max Reitz
` (3 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
The "host_device" protocol driver should strip the "host_device:" prefix
from filenames if present.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-posix.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index e6b4c1f..ab32ff9 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1561,6 +1561,15 @@ static int check_hdev_writable(BDRVRawState *s)
return 0;
}
+static void hdev_parse_filename(const char *filename, QDict *options,
+ Error **errp)
+{
+ /* The prefix is optional, just as for "file". */
+ strstart(filename, "host_device:", &filename);
+
+ qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+}
+
static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
@@ -1805,6 +1814,7 @@ static BlockDriver bdrv_host_device = {
.instance_size = sizeof(BDRVRawState),
.bdrv_needs_filename = true,
.bdrv_probe_device = hdev_probe_device,
+ .bdrv_parse_filename = hdev_parse_filename,
.bdrv_file_open = hdev_open,
.bdrv_close = raw_close,
.bdrv_reopen_prepare = raw_reopen_prepare,
--
1.9.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 2/5] block/raw-posix: bdrv_parse_filename() for floppy
2014-03-06 22:25 [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames Max Reitz
2014-03-06 22:25 ` [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev Max Reitz
@ 2014-03-06 22:25 ` Max Reitz
2014-03-06 22:38 ` Benoît Canet
2014-03-06 22:25 ` [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom Max Reitz
` (2 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
The "host_floppy" protocol driver should strip the "host_floppy:" prefix
from filenames if present.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-posix.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index ab32ff9..4b8c183 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1844,6 +1844,15 @@ static BlockDriver bdrv_host_device = {
};
#ifdef __linux__
+static void floppy_parse_filename(const char *filename, QDict *options,
+ Error **errp)
+{
+ /* The prefix is optional, just as for "file". */
+ strstart(filename, "host_floppy:", &filename);
+
+ qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+}
+
static int floppy_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
@@ -1949,6 +1958,7 @@ static BlockDriver bdrv_host_floppy = {
.instance_size = sizeof(BDRVRawState),
.bdrv_needs_filename = true,
.bdrv_probe_device = floppy_probe_device,
+ .bdrv_parse_filename = floppy_parse_filename,
.bdrv_file_open = floppy_open,
.bdrv_close = raw_close,
.bdrv_reopen_prepare = raw_reopen_prepare,
--
1.9.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom
2014-03-06 22:25 [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames Max Reitz
2014-03-06 22:25 ` [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev Max Reitz
2014-03-06 22:25 ` [Qemu-devel] [PATCH 2/5] block/raw-posix: bdrv_parse_filename() for floppy Max Reitz
@ 2014-03-06 22:25 ` Max Reitz
2014-03-06 22:37 ` Benoît Canet
2014-03-06 22:25 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
2014-03-06 22:27 ` Max Reitz
4 siblings, 1 reply; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
The "host_cdrom" protocol drivers should strip the "host_cdrom:" prefix
from filenames if present.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-posix.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 4b8c183..6c9b8f2 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1984,6 +1984,15 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_eject = floppy_eject,
};
+static void cdrom_parse_filename(const char *filename, QDict *options,
+ Error **errp)
+{
+ /* The prefix is optional, just as for "file". */
+ strstart(filename, "host_cdrom:", &filename);
+
+ qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+}
+
static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
@@ -2070,6 +2079,7 @@ static BlockDriver bdrv_host_cdrom = {
.instance_size = sizeof(BDRVRawState),
.bdrv_needs_filename = true,
.bdrv_probe_device = cdrom_probe_device,
+ .bdrv_parse_filename = cdrom_parse_filename,
.bdrv_file_open = cdrom_open,
.bdrv_close = raw_close,
.bdrv_reopen_prepare = raw_reopen_prepare,
@@ -2101,6 +2111,15 @@ static BlockDriver bdrv_host_cdrom = {
#endif /* __linux__ */
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
+static void cdrom_parse_filename(const char *filename, QDict *options,
+ Error **errp)
+{
+ /* The prefix is optional, just as for "file". */
+ strstart(filename, "host_cdrom:", &filename);
+
+ qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+}
+
static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
@@ -2200,6 +2219,7 @@ static BlockDriver bdrv_host_cdrom = {
.instance_size = sizeof(BDRVRawState),
.bdrv_needs_filename = true,
.bdrv_probe_device = cdrom_probe_device,
+ .bdrv_parse_filename = cdrom_parse_filename,
.bdrv_file_open = cdrom_open,
.bdrv_close = raw_close,
.bdrv_reopen_prepare = raw_reopen_prepare,
--
1.9.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation
2014-03-06 22:25 [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames Max Reitz
` (2 preceding siblings ...)
2014-03-06 22:25 ` [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom Max Reitz
@ 2014-03-06 22:25 ` Max Reitz
2014-03-06 22:45 ` Benoît Canet
2014-03-06 23:58 ` Eric Blake
2014-03-06 22:27 ` Max Reitz
4 siblings, 2 replies; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:25 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
The hdev_create() implementation in block/raw-posix.c is used by the
"host_device", "host_cdrom" and "host_floppy" protocol block drivers
together. Thus, it any of the associated prefixes may occur and exactly
one should be stripped, if it does (thus,
"host_device:host_cdrom:/dev/cdrom" is not shortened to "/dev/cdrom").
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-posix.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6c9b8f2..598d736 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1776,6 +1776,18 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
int ret = 0;
struct stat stat_buf;
int64_t total_size = 0;
+ bool has_prefix;
+
+ /* This function is used by all three protocol block drivers and therefore
+ * any of these three prefixes may be given.
+ * The return value has to be stored somewhere, otherwise this is an error
+ * due to -Werror=unused-value. */
+ has_prefix =
+ strstart(filename, "host_device:", &filename) ||
+ strstart(filename, "host_cdrom:" , &filename) ||
+ strstart(filename, "host_floppy:", &filename);
+
+ (void)has_prefix;
/* Read out options */
while (options && options->name) {
--
1.9.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation
2014-03-06 22:25 [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames Max Reitz
` (3 preceding siblings ...)
2014-03-06 22:25 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
@ 2014-03-06 22:27 ` Max Reitz
2014-03-06 22:27 ` [Qemu-devel] [PATCH 5/5] block/raw-win32: bdrv_parse_filename() for hdev Max Reitz
2014-03-06 22:37 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
4 siblings, 2 replies; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:27 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
The hdev_create() implementation in block/raw-posix.c is used by the
"host_device", "host_cdrom" and "host_floppy" protocol block drivers
together. Thus, it any of the associated prefixes may occur and exactly
one should be stripped, if it does (thus,
"host_device:host_cdrom:/dev/cdrom" is not shortened to "/dev/cdrom").
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-posix.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6c9b8f2..598d736 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1776,6 +1776,18 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
int ret = 0;
struct stat stat_buf;
int64_t total_size = 0;
+ bool has_prefix;
+
+ /* This function is used by all three protocol block drivers and therefore
+ * any of these three prefixes may be given.
+ * The return value has to be stored somewhere, otherwise this is an error
+ * due to -Werror=unused-value. */
+ has_prefix =
+ strstart(filename, "host_device:", &filename) ||
+ strstart(filename, "host_cdrom:" , &filename) ||
+ strstart(filename, "host_floppy:", &filename);
+
+ (void)has_prefix;
/* Read out options */
while (options && options->name) {
--
1.9.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 5/5] block/raw-win32: bdrv_parse_filename() for hdev
2014-03-06 22:27 ` Max Reitz
@ 2014-03-06 22:27 ` Max Reitz
2014-03-06 22:47 ` Benoît Canet
2014-03-06 22:37 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
1 sibling, 1 reply; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:27 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi, Max Reitz
The "host_device" protocol driver should strip the "host_device:" prefix
from filenames if present.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-win32.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 9954748..48cb2c2 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -593,6 +593,15 @@ static int hdev_probe_device(const char *filename)
return 0;
}
+static void hdev_parse_filename(const char *filename, QDict *options,
+ Error **errp)
+{
+ /* The prefix is optional, just as for "file". */
+ strstart(filename, "host_device:", &filename);
+
+ qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
+}
+
static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
Error **errp)
{
@@ -663,6 +672,7 @@ static BlockDriver bdrv_host_device = {
.protocol_name = "host_device",
.instance_size = sizeof(BDRVRawState),
.bdrv_needs_filename = true,
+ .bdrv_parse_filename = hdev_parse_filename,
.bdrv_probe_device = hdev_probe_device,
.bdrv_file_open = hdev_open,
.bdrv_close = raw_close,
--
1.9.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom
2014-03-06 22:25 ` [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom Max Reitz
@ 2014-03-06 22:37 ` Benoît Canet
2014-03-06 22:39 ` Max Reitz
0 siblings, 1 reply; 15+ messages in thread
From: Benoît Canet @ 2014-03-06 22:37 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, Benoît Canet, qemu-devel, Stefan Hajnoczi
The Thursday 06 Mar 2014 à 23:25:37 (+0100), Max Reitz wrote :
> The "host_cdrom" protocol drivers should strip the "host_cdrom:" prefix
> from filenames if present.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-posix.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 4b8c183..6c9b8f2 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1984,6 +1984,15 @@ static BlockDriver bdrv_host_floppy = {
> .bdrv_eject = floppy_eject,
> };
>
> +static void cdrom_parse_filename(const char *filename, QDict *options,
> + Error **errp)
> +{
> + /* The prefix is optional, just as for "file". */
> + strstart(filename, "host_cdrom:", &filename);
> +
> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
> +}
> +
> static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
> Error **errp)
> {
> @@ -2070,6 +2079,7 @@ static BlockDriver bdrv_host_cdrom = {
> .instance_size = sizeof(BDRVRawState),
> .bdrv_needs_filename = true,
> .bdrv_probe_device = cdrom_probe_device,
> + .bdrv_parse_filename = cdrom_parse_filename,
> .bdrv_file_open = cdrom_open,
> .bdrv_close = raw_close,
> .bdrv_reopen_prepare = raw_reopen_prepare,
> @@ -2101,6 +2111,15 @@ static BlockDriver bdrv_host_cdrom = {
> #endif /* __linux__ */
>
> #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
> +static void cdrom_parse_filename(const char *filename, QDict *options,
> + Error **errp)
> +{
> + /* The prefix is optional, just as for "file". */
> + strstart(filename, "host_cdrom:", &filename);
> +
> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
> +}
> +
The cdrom_probe_device and cdrom_open function actually differs and are not
duplicated whereas these two instances of cdrom_parse_filename are pretty much
the same.
Why not putting a merged version on the top of the file and guarded by
#if defined(__linux__) || defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
?
> static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
> Error **errp)
> {
> @@ -2200,6 +2219,7 @@ static BlockDriver bdrv_host_cdrom = {
> .instance_size = sizeof(BDRVRawState),
> .bdrv_needs_filename = true,
> .bdrv_probe_device = cdrom_probe_device,
> + .bdrv_parse_filename = cdrom_parse_filename,
> .bdrv_file_open = cdrom_open,
> .bdrv_close = raw_close,
> .bdrv_reopen_prepare = raw_reopen_prepare,
> --
> 1.9.0
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation
2014-03-06 22:27 ` Max Reitz
2014-03-06 22:27 ` [Qemu-devel] [PATCH 5/5] block/raw-win32: bdrv_parse_filename() for hdev Max Reitz
@ 2014-03-06 22:37 ` Max Reitz
1 sibling, 0 replies; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:37 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi
Sorry for the duplicate 4/5 and the wrong in-reply-to for 5/5, but I
deduced from the send-email output that 4/5 failed to send (and 5/5
wasn't even attempted) and forgot --no-thread for the resend of 4 and 5.
Max
On 06.03.2014 23:27, Max Reitz wrote:
> The hdev_create() implementation in block/raw-posix.c is used by the
> "host_device", "host_cdrom" and "host_floppy" protocol block drivers
> together. Thus, it any of the associated prefixes may occur and exactly
> one should be stripped, if it does (thus,
> "host_device:host_cdrom:/dev/cdrom" is not shortened to "/dev/cdrom").
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-posix.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 6c9b8f2..598d736 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1776,6 +1776,18 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
> int ret = 0;
> struct stat stat_buf;
> int64_t total_size = 0;
> + bool has_prefix;
> +
> + /* This function is used by all three protocol block drivers and therefore
> + * any of these three prefixes may be given.
> + * The return value has to be stored somewhere, otherwise this is an error
> + * due to -Werror=unused-value. */
> + has_prefix =
> + strstart(filename, "host_device:", &filename) ||
> + strstart(filename, "host_cdrom:" , &filename) ||
> + strstart(filename, "host_floppy:", &filename);
> +
> + (void)has_prefix;
>
> /* Read out options */
> while (options && options->name) {
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev
2014-03-06 22:25 ` [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev Max Reitz
@ 2014-03-06 22:38 ` Benoît Canet
0 siblings, 0 replies; 15+ messages in thread
From: Benoît Canet @ 2014-03-06 22:38 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, Benoît Canet, qemu-devel, Stefan Hajnoczi
The Thursday 06 Mar 2014 à 23:25:35 (+0100), Max Reitz wrote :
> The "host_device" protocol driver should strip the "host_device:" prefix
> from filenames if present.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-posix.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index e6b4c1f..ab32ff9 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1561,6 +1561,15 @@ static int check_hdev_writable(BDRVRawState *s)
> return 0;
> }
>
> +static void hdev_parse_filename(const char *filename, QDict *options,
> + Error **errp)
> +{
> + /* The prefix is optional, just as for "file". */
> + strstart(filename, "host_device:", &filename);
> +
> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
> +}
> +
> static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
> Error **errp)
> {
> @@ -1805,6 +1814,7 @@ static BlockDriver bdrv_host_device = {
> .instance_size = sizeof(BDRVRawState),
> .bdrv_needs_filename = true,
> .bdrv_probe_device = hdev_probe_device,
> + .bdrv_parse_filename = hdev_parse_filename,
> .bdrv_file_open = hdev_open,
> .bdrv_close = raw_close,
> .bdrv_reopen_prepare = raw_reopen_prepare,
> --
> 1.9.0
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 2/5] block/raw-posix: bdrv_parse_filename() for floppy
2014-03-06 22:25 ` [Qemu-devel] [PATCH 2/5] block/raw-posix: bdrv_parse_filename() for floppy Max Reitz
@ 2014-03-06 22:38 ` Benoît Canet
0 siblings, 0 replies; 15+ messages in thread
From: Benoît Canet @ 2014-03-06 22:38 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, Benoît Canet, qemu-devel, Stefan Hajnoczi
The Thursday 06 Mar 2014 à 23:25:36 (+0100), Max Reitz wrote :
> The "host_floppy" protocol driver should strip the "host_floppy:" prefix
> from filenames if present.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-posix.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index ab32ff9..4b8c183 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1844,6 +1844,15 @@ static BlockDriver bdrv_host_device = {
> };
>
> #ifdef __linux__
> +static void floppy_parse_filename(const char *filename, QDict *options,
> + Error **errp)
> +{
> + /* The prefix is optional, just as for "file". */
> + strstart(filename, "host_floppy:", &filename);
> +
> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
> +}
> +
> static int floppy_open(BlockDriverState *bs, QDict *options, int flags,
> Error **errp)
> {
> @@ -1949,6 +1958,7 @@ static BlockDriver bdrv_host_floppy = {
> .instance_size = sizeof(BDRVRawState),
> .bdrv_needs_filename = true,
> .bdrv_probe_device = floppy_probe_device,
> + .bdrv_parse_filename = floppy_parse_filename,
> .bdrv_file_open = floppy_open,
> .bdrv_close = raw_close,
> .bdrv_reopen_prepare = raw_reopen_prepare,
> --
> 1.9.0
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom
2014-03-06 22:37 ` Benoît Canet
@ 2014-03-06 22:39 ` Max Reitz
0 siblings, 0 replies; 15+ messages in thread
From: Max Reitz @ 2014-03-06 22:39 UTC (permalink / raw)
To: Benoît Canet; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi
On 06.03.2014 23:37, Benoît Canet wrote:
> The Thursday 06 Mar 2014 à 23:25:37 (+0100), Max Reitz wrote :
>> The "host_cdrom" protocol drivers should strip the "host_cdrom:" prefix
>> from filenames if present.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>> block/raw-posix.c | 20 ++++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>>
>> diff --git a/block/raw-posix.c b/block/raw-posix.c
>> index 4b8c183..6c9b8f2 100644
>> --- a/block/raw-posix.c
>> +++ b/block/raw-posix.c
>> @@ -1984,6 +1984,15 @@ static BlockDriver bdrv_host_floppy = {
>> .bdrv_eject = floppy_eject,
>> };
>>
>> +static void cdrom_parse_filename(const char *filename, QDict *options,
>> + Error **errp)
>> +{
>> + /* The prefix is optional, just as for "file". */
>> + strstart(filename, "host_cdrom:", &filename);
>> +
>> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
>> +}
>> +
>> static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
>> Error **errp)
>> {
>> @@ -2070,6 +2079,7 @@ static BlockDriver bdrv_host_cdrom = {
>> .instance_size = sizeof(BDRVRawState),
>> .bdrv_needs_filename = true,
>> .bdrv_probe_device = cdrom_probe_device,
>> + .bdrv_parse_filename = cdrom_parse_filename,
>> .bdrv_file_open = cdrom_open,
>> .bdrv_close = raw_close,
>> .bdrv_reopen_prepare = raw_reopen_prepare,
>> @@ -2101,6 +2111,15 @@ static BlockDriver bdrv_host_cdrom = {
>> #endif /* __linux__ */
>>
>> #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
>> +static void cdrom_parse_filename(const char *filename, QDict *options,
>> + Error **errp)
>> +{
>> + /* The prefix is optional, just as for "file". */
>> + strstart(filename, "host_cdrom:", &filename);
>> +
>> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
>> +}
>> +
> The cdrom_probe_device and cdrom_open function actually differs and are not
> duplicated whereas these two instances of cdrom_parse_filename are pretty much
> the same.
> Why not putting a merged version on the top of the file and guarded by
> #if defined(__linux__) || defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
> ?
I didn't want to since the #ifdef linux began before the floppy driver
and ended after the Linux CD-ROM driver, so I'd have to split it up. But
since you're suggesting it now, I'll do it. ;-)
Max
>> static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
>> Error **errp)
>> {
>> @@ -2200,6 +2219,7 @@ static BlockDriver bdrv_host_cdrom = {
>> .instance_size = sizeof(BDRVRawState),
>> .bdrv_needs_filename = true,
>> .bdrv_probe_device = cdrom_probe_device,
>> + .bdrv_parse_filename = cdrom_parse_filename,
>> .bdrv_file_open = cdrom_open,
>> .bdrv_close = raw_close,
>> .bdrv_reopen_prepare = raw_reopen_prepare,
>> --
>> 1.9.0
>>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation
2014-03-06 22:25 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
@ 2014-03-06 22:45 ` Benoît Canet
2014-03-06 23:58 ` Eric Blake
1 sibling, 0 replies; 15+ messages in thread
From: Benoît Canet @ 2014-03-06 22:45 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, Benoît Canet, qemu-devel, Stefan Hajnoczi
The Thursday 06 Mar 2014 à 23:25:38 (+0100), Max Reitz wrote :
> The hdev_create() implementation in block/raw-posix.c is used by the
> "host_device", "host_cdrom" and "host_floppy" protocol block drivers
> together. Thus, it any of the associated prefixes may occur and exactly
> one should be stripped, if it does (thus,
> "host_device:host_cdrom:/dev/cdrom" is not shortened to "/dev/cdrom").
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-posix.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 6c9b8f2..598d736 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1776,6 +1776,18 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
> int ret = 0;
> struct stat stat_buf;
> int64_t total_size = 0;
> + bool has_prefix;
> +
> + /* This function is used by all three protocol block drivers and therefore
> + * any of these three prefixes may be given.
> + * The return value has to be stored somewhere, otherwise this is an error
> + * due to -Werror=unused-value. */
> + has_prefix =
> + strstart(filename, "host_device:", &filename) ||
> + strstart(filename, "host_cdrom:" , &filename) ||
> + strstart(filename, "host_floppy:", &filename);
> +
> + (void)has_prefix;
>
> /* Read out options */
> while (options && options->name) {
> --
> 1.9.0
>
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 5/5] block/raw-win32: bdrv_parse_filename() for hdev
2014-03-06 22:27 ` [Qemu-devel] [PATCH 5/5] block/raw-win32: bdrv_parse_filename() for hdev Max Reitz
@ 2014-03-06 22:47 ` Benoît Canet
0 siblings, 0 replies; 15+ messages in thread
From: Benoît Canet @ 2014-03-06 22:47 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, Benoît Canet, qemu-devel, Stefan Hajnoczi
The Thursday 06 Mar 2014 à 23:27:41 (+0100), Max Reitz wrote :
> The "host_device" protocol driver should strip the "host_device:" prefix
> from filenames if present.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-win32.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/block/raw-win32.c b/block/raw-win32.c
> index 9954748..48cb2c2 100644
> --- a/block/raw-win32.c
> +++ b/block/raw-win32.c
> @@ -593,6 +593,15 @@ static int hdev_probe_device(const char *filename)
> return 0;
> }
>
> +static void hdev_parse_filename(const char *filename, QDict *options,
> + Error **errp)
> +{
> + /* The prefix is optional, just as for "file". */
> + strstart(filename, "host_device:", &filename);
> +
> + qdict_put_obj(options, "filename", QOBJECT(qstring_from_str(filename)));
> +}
> +
> static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
> Error **errp)
> {
> @@ -663,6 +672,7 @@ static BlockDriver bdrv_host_device = {
> .protocol_name = "host_device",
> .instance_size = sizeof(BDRVRawState),
> .bdrv_needs_filename = true,
> + .bdrv_parse_filename = hdev_parse_filename,
> .bdrv_probe_device = hdev_probe_device,
> .bdrv_file_open = hdev_open,
> .bdrv_close = raw_close,
> --
> 1.9.0
>
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation
2014-03-06 22:25 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
2014-03-06 22:45 ` Benoît Canet
@ 2014-03-06 23:58 ` Eric Blake
1 sibling, 0 replies; 15+ messages in thread
From: Eric Blake @ 2014-03-06 23:58 UTC (permalink / raw)
To: Max Reitz, qemu-devel; +Cc: Kevin Wolf, Benoît Canet, Stefan Hajnoczi
[-- Attachment #1: Type: text/plain, Size: 640 bytes --]
On 03/06/2014 03:25 PM, Max Reitz wrote:
> The hdev_create() implementation in block/raw-posix.c is used by the
> "host_device", "host_cdrom" and "host_floppy" protocol block drivers
> together. Thus, it any of the associated prefixes may occur and exactly
s/it //
> one should be stripped, if it does (thus,
> "host_device:host_cdrom:/dev/cdrom" is not shortened to "/dev/cdrom").
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/raw-posix.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-03-06 23:58 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-06 22:25 [Qemu-devel] [PATCH 0/5] block: Strip protocol prefixes from filenames Max Reitz
2014-03-06 22:25 ` [Qemu-devel] [PATCH 1/5] block/raw-posix: bdrv_parse_filename() for hdev Max Reitz
2014-03-06 22:38 ` Benoît Canet
2014-03-06 22:25 ` [Qemu-devel] [PATCH 2/5] block/raw-posix: bdrv_parse_filename() for floppy Max Reitz
2014-03-06 22:38 ` Benoît Canet
2014-03-06 22:25 ` [Qemu-devel] [PATCH 3/5] block/raw-posix: bdrv_parse_filename() for cdrom Max Reitz
2014-03-06 22:37 ` Benoît Canet
2014-03-06 22:39 ` Max Reitz
2014-03-06 22:25 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
2014-03-06 22:45 ` Benoît Canet
2014-03-06 23:58 ` Eric Blake
2014-03-06 22:27 ` Max Reitz
2014-03-06 22:27 ` [Qemu-devel] [PATCH 5/5] block/raw-win32: bdrv_parse_filename() for hdev Max Reitz
2014-03-06 22:47 ` Benoît Canet
2014-03-06 22:37 ` [Qemu-devel] [PATCH 4/5] block/raw-posix: Strip protocol prefix on creation Max Reitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).