From patchwork Thu May 19 15:22:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9127889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4064E60453 for ; Thu, 19 May 2016 15:49:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33C3F280BB for ; Thu, 19 May 2016 15:49:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28A70281CE; Thu, 19 May 2016 15:49:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6161280BB for ; Thu, 19 May 2016 15:49:31 +0000 (UTC) Received: from localhost ([::1]:51074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3QCY-000448-RZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 May 2016 11:49:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3Pmn-0005YV-MS for qemu-devel@nongnu.org; Thu, 19 May 2016 11:22:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3Pmm-0000VT-Ds for qemu-devel@nongnu.org; Thu, 19 May 2016 11:22:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56820) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3Pmd-0000Ly-Ej; Thu, 19 May 2016 11:22:43 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A7302640; Thu, 19 May 2016 15:22:43 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4JFMEBH025145; Thu, 19 May 2016 11:22:42 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 19 May 2016 17:22:06 +0200 Message-Id: <1463671329-22655-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1463671329-22655-1-git-send-email-kwolf@redhat.com> References: <1463671329-22655-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 19 May 2016 15:22:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 28/31] block: clarify error message for qmp-eject X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: John Snow If you use HMP's eject but the CDROM tray is locked, you may get a confusing error message informing you that the "tray isn't open." As this is the point of eject, we can do a little better and help clarify that the tray was locked and that it (might) open up later, so try again. It's not ideal, but it makes the semantics of the (legacy) eject command more understandable to end users when they try to use it. Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- blockdev.c | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/blockdev.c b/blockdev.c index b6fa210..40e4e6f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2281,16 +2281,29 @@ exit: block_job_txn_unref(block_job_txn); } +static int do_open_tray(const char *device, bool force, Error **errp); + void qmp_eject(const char *device, bool has_force, bool force, Error **errp) { Error *local_err = NULL; + int rc; + + if (!has_force) { + force = false; + } - qmp_blockdev_open_tray(device, has_force, force, &local_err); + rc = do_open_tray(device, force, &local_err); if (local_err) { error_propagate(errp, local_err); return; } + if (rc == EINPROGRESS) { + error_setg(errp, "Device '%s' is locked and force was not specified, " + "wait for tray to open and try again", device); + return; + } + qmp_x_blockdev_remove_medium(device, errp); } @@ -2318,35 +2331,36 @@ void qmp_block_passwd(bool has_device, const char *device, aio_context_release(aio_context); } -void qmp_blockdev_open_tray(const char *device, bool has_force, bool force, - Error **errp) +/** + * returns -errno on fatal error, +errno for non-fatal situations. + * errp will always be set when the return code is negative. + * May return +ENOSYS if the device has no tray, + * or +EINPROGRESS if the tray is locked and the guest has been notified. + */ +static int do_open_tray(const char *device, bool force, Error **errp) { BlockBackend *blk; bool locked; - if (!has_force) { - force = false; - } - blk = blk_by_name(device); if (!blk) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", device); - return; + return -ENODEV; } if (!blk_dev_has_removable_media(blk)) { error_setg(errp, "Device '%s' is not removable", device); - return; + return -ENOTSUP; } if (!blk_dev_has_tray(blk)) { /* Ignore this command on tray-less devices */ - return; + return ENOSYS; } if (blk_dev_is_tray_open(blk)) { - return; + return 0; } locked = blk_dev_is_medium_locked(blk); @@ -2357,6 +2371,21 @@ void qmp_blockdev_open_tray(const char *device, bool has_force, bool force, if (!locked || force) { blk_dev_change_media_cb(blk, false); } + + if (locked && !force) { + return EINPROGRESS; + } + + return 0; +} + +void qmp_blockdev_open_tray(const char *device, bool has_force, bool force, + Error **errp) +{ + if (!has_force) { + force = false; + } + do_open_tray(device, force, errp); } void qmp_blockdev_close_tray(const char *device, Error **errp)