From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QodEl-0001it-Tb for qemu-devel@nongnu.org; Wed, 03 Aug 2011 11:20:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QodEh-0006wX-VE for qemu-devel@nongnu.org; Wed, 03 Aug 2011 11:19:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QodEh-0006vF-JS for qemu-devel@nongnu.org; Wed, 03 Aug 2011 11:19:55 -0400 From: Luiz Capitulino Date: Wed, 3 Aug 2011 12:19:21 -0300 Message-Id: <1312384765-721-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1312384765-721-1-git-send-email-lcapitulino@redhat.com> References: <1312384765-721-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PATCH 1/5] block: Introduce get_iostatus() device model operation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, armbru@redhat.com It returns the status of the last executed I/O operation, which can be: o OK (success) o ENOSPC (no space) o FAILED (other kinds of failures such as EIO) We make a distiction between ENOSPC and other kinds of failures because QMP clients can use ENOSPC to implement a feature where the VM is started with a small disk and space is allocated on demand. Signed-off-by: Luiz Capitulino --- block.c | 19 +++++++++++++++++++ block.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index d391836..c86e144 100644 --- a/block.c +++ b/block.c @@ -28,6 +28,7 @@ #include "block_int.h" #include "module.h" #include "qemu-objects.h" +#include "sysemu.h" #ifdef CONFIG_BSD #include @@ -790,6 +791,14 @@ int bdrv_dev_is_medium_locked(BlockDriverState *bs) return 0; } +BlockDevIOStatus bdrv_dev_iostatus(BlockDriverState *bs) +{ + if (bs->dev_ops && bs->dev_ops->get_iostatus) { + return bs->dev_ops->get_iostatus(bs->dev_opaque); + } + return BDRV_IOS_INVAL; +} + /* * Run consistency checks on an image * @@ -1724,6 +1733,16 @@ void bdrv_mon_event(const BlockDriverState *bdrv, qobject_decref(data); } +BlockDevIOStatus bdrv_iostatus_from_error(int error) +{ + if (!error) { + return BDRV_IOS_OK; + } else { + return (abs(error) == ENOSPC) ? BDRV_IOS_ENOSPC : + BDRV_IOS_FAILED; + } +} + static void bdrv_print_dict(QObject *obj, void *opaque) { QDict *bs_dict; diff --git a/block.h b/block.h index 1157eed..27413ae 100644 --- a/block.h +++ b/block.h @@ -27,6 +27,10 @@ typedef struct QEMUSnapshotInfo { uint64_t vm_clock_nsec; /* VM clock relative to boot */ } QEMUSnapshotInfo; +typedef enum { + BDRV_IOS_INVAL, BDRV_IOS_OK, BDRV_IOS_FAILED, BDRV_IOS_ENOSPC +} BlockDevIOStatus; + /* Callbacks for block device models */ typedef struct BlockDevOps { /* @@ -51,6 +55,11 @@ typedef struct BlockDevOps { * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); + /* + * Returns the status of the last I/O operation. Likely to be useful + * only when the VM is stopped. + */ + BlockDevIOStatus (*get_iostatus)(void *opaque); } BlockDevOps; #define BDRV_O_RDWR 0x0002 @@ -78,6 +87,7 @@ typedef enum { void bdrv_mon_event(const BlockDriverState *bdrv, BlockMonEventAction action, int is_read); +BlockDevIOStatus bdrv_iostatus_from_error(int error); void bdrv_info_print(Monitor *mon, const QObject *data); void bdrv_info(Monitor *mon, QObject **ret_data); void bdrv_stats_print(Monitor *mon, const QObject *data); @@ -107,6 +117,7 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, int bdrv_dev_has_removable_media(BlockDriverState *bs); bool bdrv_dev_is_medium_ejected(BlockDriverState *bs); int bdrv_dev_is_medium_locked(BlockDriverState *bs); +BlockDevIOStatus bdrv_dev_iostatus(BlockDriverState *bs); int bdrv_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num, -- 1.7.6.396.ge0613