From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Kevin Wolf <kwolf@redhat.com>
Cc: mreitz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 07/17] blockdev: Move parsing of 'media' option to drive_init
Date: Fri, 20 Sep 2013 16:28:19 +0200 [thread overview]
Message-ID: <20130920142819.GD6794@irqsave.net> (raw)
In-Reply-To: <1379678070-14346-8-git-send-email-kwolf@redhat.com>
Le Friday 20 Sep 2013 à 13:54:20 (+0200), Kevin Wolf a écrit :
> This moves as much as possible of the processing of the 'media' option
> to drive_init so that it can only be accessed using legacy functions,
> but never with anything blockdev-add related.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> blockdev.c | 73 ++++++++++++++++++++++++++++++++++++++++++--------------------
> 1 file changed, 50 insertions(+), 23 deletions(-)
>
> diff --git a/blockdev.c b/blockdev.c
> index 3a1444c..5b25d7f 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -302,16 +302,18 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)
> return true;
> }
>
> +typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
> +
> /* Takes the ownership of bs_opts */
> static DriveInfo *blockdev_init(QDict *bs_opts,
> - BlockInterfaceType block_default_type)
> + BlockInterfaceType block_default_type,
> + DriveMediaType media)
> {
> const char *buf;
> const char *file = NULL;
> const char *serial;
> const char *mediastr = "";
> BlockInterfaceType type;
> - enum { MEDIA_DISK, MEDIA_CDROM } media;
> int bus_id, unit_id;
> int cyls, heads, secs, translation;
> int max_devs;
> @@ -332,7 +334,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
> BlockDriver *drv = NULL;
>
> translation = BIOS_ATA_TRANSLATION_AUTO;
> - media = MEDIA_DISK;
>
> /* Check common options by copying from bs_opts to opts, all other options
> * stay in bs_opts for processing by bdrv_open(). */
> @@ -419,19 +420,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
> }
> }
>
> - if ((buf = qemu_opt_get(opts, "media")) != NULL) {
> - if (!strcmp(buf, "disk")) {
> - media = MEDIA_DISK;
> - } else if (!strcmp(buf, "cdrom")) {
> - if (cyls || secs || heads) {
> - error_report("CHS can't be set with media=%s", buf);
> - return NULL;
> - }
> - media = MEDIA_CDROM;
> - } else {
> - error_report("'%s' invalid media", buf);
> - return NULL;
> - }
> + if (media == MEDIA_CDROM) {
> + if (cyls || secs || heads) {
> + error_report("CHS can't be set with media=cdrom");
> + return NULL;
> + }
> }
>
> if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
> @@ -752,11 +745,27 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
> }
> }
>
> +QemuOptsList qemu_legacy_drive_opts = {
> + .name = "drive",
> + .head = QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts.head),
> + .desc = {
> + {
> + .name = "media",
> + .type = QEMU_OPT_STRING,
> + .help = "media type (disk, cdrom)",
> + },
> + { /* end of list */ }
> + },
> +};
> +
> DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
> {
> const char *value;
> - DriveInfo *dinfo;
> + DriveInfo *dinfo = NULL;
> QDict *bs_opts;
> + QemuOpts *legacy_opts;
> + DriveMediaType media = MEDIA_DISK;
> + Error *local_err = NULL;
>
> /* Change legacy command line options into QMP ones */
> qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
> @@ -809,8 +818,29 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
> bs_opts = qdict_new();
> qemu_opts_to_qdict(all_opts, bs_opts);
>
> + legacy_opts = qemu_opts_create_nofail(&qemu_legacy_drive_opts);
> + qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err);
> + if (error_is_set(&local_err)) {
> + qerror_report_err(local_err);
> + error_free(local_err);
> + goto fail;
> + }
> +
> + /* Media type */
> + value = qemu_opt_get(legacy_opts, "media");
> + if (value) {
> + if (!strcmp(value, "disk")) {
> + media = MEDIA_DISK;
> + } else if (!strcmp(value, "cdrom")) {
> + media = MEDIA_CDROM;
> + } else {
> + error_report("'%s' invalid media", value);
> + goto fail;
> + }
> + }
> +
> /* Actual block device init: Functionality shared with blockdev-add */
> - dinfo = blockdev_init(bs_opts, block_default_type);
> + dinfo = blockdev_init(bs_opts, block_default_type, media);
> if (dinfo == NULL) {
> goto fail;
> }
> @@ -820,6 +850,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
> dinfo->opts = all_opts;
>
> fail:
> + qemu_opts_del(legacy_opts);
> return dinfo;
> }
>
> @@ -2112,7 +2143,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
>
> qdict_flatten(qdict);
>
> - dinfo = blockdev_init(qdict, IF_NONE);
> + dinfo = blockdev_init(qdict, IF_NONE, MEDIA_DISK);
> if (!dinfo) {
> error_setg(errp, "Could not open image");
> goto fail;
> @@ -2181,10 +2212,6 @@ QemuOptsList qemu_common_drive_opts = {
> .type = QEMU_OPT_STRING,
> .help = "chs translation (auto, lba. none)",
> },{
> - .name = "media",
> - .type = QEMU_OPT_STRING,
> - .help = "media type (disk, cdrom)",
> - },{
> .name = "snapshot",
> .type = QEMU_OPT_BOOL,
> .help = "enable/disable snapshot mode",
> --
> 1.8.1.4
>
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
next prev parent reply other threads:[~2013-09-20 14:28 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-20 11:54 [Qemu-devel] [PATCH 00/17] blockdev-add QMP command Kevin Wolf
2013-09-20 11:54 ` [Qemu-devel] [PATCH 01/17] qapi-types/visit.py: Pass whole expr dict for structs Kevin Wolf
2013-09-20 13:32 ` Max Reitz
2013-09-20 14:51 ` Eric Blake
2013-09-20 11:54 ` [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance " Kevin Wolf
2013-09-20 13:33 ` Max Reitz
2013-09-20 14:19 ` Kevin Wolf
2013-09-20 14:58 ` Eric Blake
2013-09-20 11:54 ` [Qemu-devel] [PATCH 03/17] blockdev: Introduce DriveInfo.enable_auto_del Kevin Wolf
2013-09-20 15:03 ` Eric Blake
2013-09-20 15:12 ` Kevin Wolf
2013-09-20 15:25 ` Eric Blake
2013-09-30 5:05 ` Wenchao Xia
2013-09-20 11:54 ` [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command Kevin Wolf
2013-09-20 13:34 ` Max Reitz
2013-09-20 14:57 ` Kevin Wolf
2013-09-20 14:01 ` Benoît Canet
2013-09-24 10:41 ` Paolo Bonzini
2013-09-24 11:10 ` Kevin Wolf
2013-09-20 15:22 ` Eric Blake
2013-09-20 15:34 ` Kevin Wolf
2013-09-24 5:18 ` Fam Zheng
2013-09-24 8:01 ` Kevin Wolf
2013-09-24 10:39 ` Paolo Bonzini
2013-09-20 11:54 ` [Qemu-devel] [PATCH 05/17] blockdev: Separate ID generation from DriveInfo creation Kevin Wolf
2013-09-23 9:01 ` Max Reitz
2013-09-23 15:45 ` Eric Blake
2013-09-30 5:24 ` Wenchao Xia
2013-09-20 11:54 ` [Qemu-devel] [PATCH 06/17] blockdev: Pass QDict to blockdev_init() Kevin Wolf
2013-09-20 14:11 ` Benoît Canet
2013-09-25 6:25 ` Fam Zheng
2013-09-20 11:54 ` [Qemu-devel] [PATCH 07/17] blockdev: Move parsing of 'media' option to drive_init Kevin Wolf
2013-09-20 14:28 ` Benoît Canet [this message]
2013-09-20 11:54 ` [Qemu-devel] [PATCH 08/17] blockdev: Move parsing of 'if' " Kevin Wolf
2013-09-20 14:47 ` Max Reitz
2013-09-20 15:04 ` Kevin Wolf
2013-09-20 14:50 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 09/17] blockdev: Moving parsing of geometry options " Kevin Wolf
2013-09-20 15:04 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 10/17] blockdev: Move parsing of 'boot' option " Kevin Wolf
2013-09-20 15:05 ` Benoît Canet
2013-09-20 11:54 ` [Qemu-devel] [PATCH 11/17] blockdev: Move bus/unit/index processing " Kevin Wolf
2013-09-23 9:03 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 12/17] blockdev: Move virtio-blk device creation " Kevin Wolf
2013-09-23 9:04 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 13/17] blockdev: Remove IF_* check for read-only blockdev_init Kevin Wolf
2013-09-23 8:00 ` Max Reitz
2013-09-23 8:08 ` Kevin Wolf
2013-09-20 11:54 ` [Qemu-devel] [PATCH 14/17] qemu-iotests: Check autodel behaviour for device_del Kevin Wolf
2013-09-23 9:06 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 15/17] blockdev: Remove 'media' parameter from blockdev_init() Kevin Wolf
2013-09-23 9:06 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 16/17] blockdev: Don't disable COR automatically with blockdev-add Kevin Wolf
2013-09-23 9:07 ` Max Reitz
2013-09-20 11:54 ` [Qemu-devel] [PATCH 17/17] blockdev: blockdev_init() error conversion Kevin Wolf
2013-09-23 9:08 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130920142819.GD6794@irqsave.net \
--to=benoit.canet@irqsave.net \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.