@@ -28,6 +28,7 @@
#include "block_int.h"
#include "module.h"
#include "qemu-objects.h"
+#include "sysemu.h"
#ifdef CONFIG_BSD
#include <sys/types.h>
@@ -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;
@@ -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,
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 <lcapitulino@redhat.com> --- block.c | 19 +++++++++++++++++++ block.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-)