From patchwork Wed Jan 4 17:38:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 134308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6E645B6FAA for ; Thu, 5 Jan 2012 04:40:57 +1100 (EST) Received: from localhost ([::1]:36112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiUpZ-0000Jq-TD for incoming@patchwork.ozlabs.org; Wed, 04 Jan 2012 12:40:53 -0500 Received: from eggs.gnu.org ([140.186.70.92]:59352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiUpR-0000JV-Qr for qemu-devel@nongnu.org; Wed, 04 Jan 2012 12:40:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RiUpQ-0002Vf-E4 for qemu-devel@nongnu.org; Wed, 04 Jan 2012 12:40:45 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:44915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiUpQ-0002VT-03 for qemu-devel@nongnu.org; Wed, 04 Jan 2012 12:40:44 -0500 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Jan 2012 17:40:43 -0000 Received: from d06nrmr1806.portsmouth.uk.ibm.com ([9.149.39.193]) by e06smtp11.uk.ibm.com ([192.168.101.141]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Jan 2012 17:40:40 -0000 Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q04HedHQ2842698 for ; Wed, 4 Jan 2012 17:40:39 GMT Received: from d06av11.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q04HedLn020430 for ; Wed, 4 Jan 2012 10:40:39 -0700 Received: from localhost (sig-9-145-145-29.de.ibm.com [9.145.145.29]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q04Hecm9020427; Wed, 4 Jan 2012 10:40:39 -0700 From: Stefan Hajnoczi To: Date: Wed, 4 Jan 2012 17:38:23 +0000 Message-Id: <1325698703-15370-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1325698703-15370-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1325698703-15370-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12010417-5024-0000-0000-000001429DBB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.107 Cc: Stefan Hajnoczi , Luiz Capitulino Subject: [Qemu-devel] [PATCH 3/3] block: use proper qerrors in qmp_block_resize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Let's report specific errors so that management tools and users can identify the problem. Two new qerrors are needed: * QERR_DEVICE_HAS_NO_MEDIUM for ENOMEDIUM * QERR_DEVICE_IS_READ_ONLY for EACCES Signed-off-by: Stefan Hajnoczi --- blockdev.c | 26 ++++++++++++++++++-------- qerror.c | 8 ++++++++ qerror.h | 6 ++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index c832782..8c2c8cc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -841,11 +841,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) return 0; } -/* - * XXX: replace the QERR_UNDEFINED_ERROR errors with real values once the - * existing QERR_ macro mess is cleaned up. A good example for better - * error reports can be found in the qemu-img resize code. - */ void qmp_block_resize(const char *device, int64_t size, Error **errp) { BlockDriverState *bs; @@ -857,12 +852,27 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp) } if (size < 0) { - error_set(errp, QERR_UNDEFINED_ERROR); + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size"); return; } - if (bdrv_truncate(bs, size)) { + switch (bdrv_truncate(bs, size)) { + case 0: + break; + case -ENOMEDIUM: + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + break; + case -ENOTSUP: + error_set(errp, QERR_UNSUPPORTED); + break; + case -EACCES: + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device); + break; + case -EBUSY: + error_set(errp, QERR_DEVICE_IN_USE, device); + break; + default: error_set(errp, QERR_UNDEFINED_ERROR); - return; + break; } } diff --git a/qerror.c b/qerror.c index 2979b3e..3d95383 100644 --- a/qerror.c +++ b/qerror.c @@ -80,6 +80,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Migration is disabled when using feature '%(feature)' in device '%(device)'", }, { + .error_fmt = QERR_DEVICE_HAS_NO_MEDIUM, + .desc = "Device '%(device)' has no medium", + }, + { .error_fmt = QERR_DEVICE_INIT_FAILED, .desc = "Device '%(device)' could not be initialized", }, @@ -88,6 +92,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' is in use", }, { + .error_fmt = QERR_DEVICE_IS_READ_ONLY, + .desc = "Device '%(device)' is read only", + }, + { .error_fmt = QERR_DEVICE_LOCKED, .desc = "Device '%(device)' is locked", }, diff --git a/qerror.h b/qerror.h index c34674e..a693d49 100644 --- a/qerror.h +++ b/qerror.h @@ -81,12 +81,18 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_DEVICE_FEATURE_BLOCKS_MIGRATION \ "{ 'class': 'DeviceFeatureBlocksMigration', 'data': { 'device': %s, 'feature': %s } }" +#define QERR_DEVICE_HAS_NO_MEDIUM \ + "{ 'class': 'DeviceHasNoMedium', 'data', { 'name': %s } }" + #define QERR_DEVICE_INIT_FAILED \ "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }" #define QERR_DEVICE_IN_USE \ "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }" +#define QERR_DEVICE_IS_READ_ONLY \ + "{ 'class': 'DeviceIsReadOnly', 'data': { 'device': %s } }" + #define QERR_DEVICE_LOCKED \ "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"