From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, amit.shah@redhat.com, aliguori@us.ibm.com,
armbru@redhat.com
Subject: [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert command
Date: Fri, 3 Jun 2011 16:03:59 -0300 [thread overview]
Message-ID: <1307127842-12102-8-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1307127842-12102-1-git-send-email-lcapitulino@redhat.com>
This command inserts a new media in an already opened tray. It's only
available in QMP.
Please, check the command's documentation (being introduced in this
commit) for a detailed description.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
blockdev.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
blockdev.h | 1 +
qmp-commands.hx | 32 ++++++++++++++++++++++++++++++++
3 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 943905d..14c8312 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -721,6 +721,58 @@ static int tray_close(const char *device)
return 0;
}
+static int media_insert(const char *device, const char *mediafile,
+ const char *format)
+{
+ BlockDriver *drv = NULL;
+ BlockDriverState *bs;
+ int bdrv_flags;
+
+ bs = bdrv_removable_find(device);
+ if (!bs) {
+ return -1;
+ }
+
+ if (bdrv_is_locked(bs)) {
+ qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
+ return -1;
+ }
+
+ if (bdrv_is_inserted(bs)) {
+ /* FIXME: will report undefined error in QMP */
+ return -1;
+ }
+
+ if (!bs->tray_open) {
+ /* FIXME: will report undefined error in QMP */
+ return 1;
+ }
+
+ if (format) {
+ drv = bdrv_find_whitelisted_format(format);
+ if (!drv) {
+ qerror_report(QERR_INVALID_BLOCK_FORMAT, format);
+ return -1;
+ }
+ }
+
+ bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
+ bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
+ if (bdrv_open(bs, mediafile, bdrv_flags, drv) < 0) {
+ qerror_report(QERR_OPEN_FILE_FAILED, mediafile);
+ return -1;
+ }
+
+ return 0;
+}
+
+int do_media_insert(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+ return media_insert(qdict_get_str(qdict, "device"),
+ qdict_get_str(qdict, "media"),
+ qdict_get_try_str(qdict, "format"));
+}
+
int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
return tray_close(qdict_get_str(qdict, "device"));
diff --git a/blockdev.h b/blockdev.h
index 975e91a..4dfd869 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -67,5 +67,6 @@ int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data);
int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data);
int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data);
int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_media_insert(Monitor *mon, const QDict *qdict, QObject **ret_data);
#endif
diff --git a/qmp-commands.hx b/qmp-commands.hx
index fdf9750..fe50593 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -480,6 +480,38 @@ Example:
EQMP
{
+ .name = "blockdev-media-insert",
+ .args_type = "device:B,media:F,format:s?",
+ .mhandler.cmd_new = do_media_insert,
+ },
+
+SQMP
+blockdev-media-insert
+---------------------
+
+Insert a new media in a removable drive. The tray must be empty and already
+opened. The tray is not automatically closed (please, see blockdev-tray-open
+and blockdev-tray-close commands).
+
+Arguments:
+
+- "device": device name (json-string)
+- "media": media file path (json-string)
+- "format": media file format (json-string, optional)
+
+Example:
+
+-> { "execute": "blockdev-media-insert",
+ "arguments": { "device": "ide1-cd0",
+ "media": "/srv/images/Fedora-12-x86_64-DVD.iso" } }
+<- { "return": {} }
+
+Note: If the media is encrypted, the command block_passwd has to be used to
+ set the media's password.
+
+EQMP
+
+ {
.name = "migrate",
.args_type = "detach:-d,blk:-b,inc:-i,uri:s",
.params = "[-d] [-b] [-i] uri",
--
1.7.4.4
next prev parent reply other threads:[~2011-06-03 19:04 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-03 19:03 [Qemu-devel] [RFC 00/10]: QMP/HMP: Introduce tray handling commands Luiz Capitulino
2011-06-03 19:03 ` [Qemu-devel] [RFC 01/10] block: bdrv_eject(): Add 'force' parameter Luiz Capitulino
2011-06-03 19:03 ` [Qemu-devel] [RFC 02/10] block: Rename bdrv_mon_event() Luiz Capitulino
2011-06-03 19:03 ` [Qemu-devel] [RFC 03/10] QMP: query-block: Add the 'tray-open' key Luiz Capitulino
2011-06-03 19:03 ` [Qemu-devel] [RFC 04/10] HMP: info block: Print " Luiz Capitulino
2011-06-06 13:19 ` Markus Armbruster
2011-06-06 14:46 ` Luiz Capitulino
2011-06-03 19:03 ` [Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command Luiz Capitulino
2011-06-06 11:40 ` Amit Shah
2011-06-06 14:38 ` Luiz Capitulino
2011-06-07 13:29 ` Amit Shah
2011-06-07 13:53 ` Luiz Capitulino
2011-06-06 13:35 ` Markus Armbruster
2011-06-03 19:03 ` [Qemu-devel] [RFC 06/10] QMP: Introduce the blockdev-tray-close command Luiz Capitulino
2011-06-03 19:03 ` Luiz Capitulino [this message]
2011-06-06 11:44 ` [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert command Amit Shah
2011-06-06 13:40 ` Markus Armbruster
2011-06-06 14:58 ` Luiz Capitulino
2011-06-03 19:04 ` [Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TRAY_CLOSE events Luiz Capitulino
2011-06-03 19:04 ` [Qemu-devel] [RFC 09/10] QMP/HMP: eject: Use blockdev-tray-open Luiz Capitulino
2011-06-03 19:04 ` [Qemu-devel] [RFC 10/10] QMP/HMP: change: Use QMP tray commands Luiz Capitulino
2011-06-06 11:48 ` Amit Shah
2011-06-06 14:45 ` Luiz Capitulino
2011-06-07 13:32 ` Amit Shah
2011-06-06 13:31 ` [Qemu-devel] [RFC 00/10]: QMP/HMP: Introduce tray handling commands Markus Armbruster
2011-06-06 14:56 ` Luiz Capitulino
2011-12-20 6:49 ` Osier Yang
2012-01-03 19:28 ` Luiz Capitulino
2012-01-11 7:34 ` Osier Yang
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=1307127842-12102-8-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=amit.shah@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 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).