aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2013-06-17 13:14:46 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2013-06-17 13:14:46 -0500
commit21a885a7e2a0f532f7653a2607efddbd83504430 (patch)
tree6c633a6174cda24a78cece7a2b157cb108ad42bb
parent128dc2d1e4cb98ddbe9c0df2e0c914dc00925dac (diff)
parentdbfbc6373441e436ac6e2bcf7a8acb284225aa21 (diff)
Merge remote-tracking branch 'luiz/queue/qmp' into staging
# By Luiz Capitulino # Via Luiz Capitulino * luiz/queue/qmp: qerror: drop QERR_OPEN_FILE_FAILED macro block: bdrv_reopen_prepare(): don't use QERR_OPEN_FILE_FAILED savevm: qmp_xen_save_devices_state(): use error_setg_file_open() dump: qmp_dump_guest_memory(): use error_setg_file_open() cpus: use error_setg_file_open() blockdev: use error_setg_file_open() block: mirror_complete(): use error_setg_file_open() rng-random: use error_setg_file_open() error: add error_setg_file_open() helper Message-id: 1371484631-29510-1-git-send-email-lcapitulino@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--backends/rng-random.c3
-rw-r--r--block.c4
-rw-r--r--block/mirror.c2
-rw-r--r--blockdev.c11
-rw-r--r--cpus.c4
-rw-r--r--dump.c2
-rw-r--r--include/qapi/error.h5
-rw-r--r--include/qapi/qmp/qerror.h3
-rw-r--r--savevm.c2
-rw-r--r--util/error.c5
10 files changed, 25 insertions, 16 deletions
diff --git a/backends/rng-random.c b/backends/rng-random.c
index 830360c780..68dfc8a9c6 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -78,9 +78,8 @@ static void rng_random_opened(RngBackend *b, Error **errp)
"filename", "a valid filename");
} else {
s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK);
-
if (s->fd == -1) {
- error_set(errp, QERR_OPEN_FILE_FAILED, s->filename);
+ error_setg_file_open(errp, errno, s->filename);
}
}
}
diff --git a/block.c b/block.c
index 79ad33d0f9..b88ad2fa04 100644
--- a/block.c
+++ b/block.c
@@ -1291,8 +1291,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
if (local_err != NULL) {
error_propagate(errp, local_err);
} else {
- error_set(errp, QERR_OPEN_FILE_FAILED,
- reopen_state->bs->filename);
+ error_setg(errp, "failed while preparing to reopen image '%s'",
+ reopen_state->bs->filename);
}
goto error;
}
diff --git a/block/mirror.c b/block/mirror.c
index 8b07dec314..1ae724f705 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -512,7 +512,7 @@ static void mirror_complete(BlockJob *job, Error **errp)
char backing_filename[PATH_MAX];
bdrv_get_full_backing_filename(s->target, backing_filename,
sizeof(backing_filename));
- error_set(errp, QERR_OPEN_FILE_FAILED, backing_filename);
+ error_setg_file_open(errp, -ret, backing_filename);
return;
}
if (!s->synced) {
diff --git a/blockdev.c b/blockdev.c
index 9937311aac..5975dde5d0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -899,7 +899,7 @@ static void external_snapshot_prepare(BlkTransactionStates *common,
ret = bdrv_open(states->new_bs, new_image_file, NULL,
flags | BDRV_O_NO_BACKING, drv);
if (ret != 0) {
- error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+ error_setg_file_open(errp, -ret, new_image_file);
}
}
@@ -1062,8 +1062,11 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
int bdrv_flags, BlockDriver *drv,
const char *password, Error **errp)
{
- if (bdrv_open(bs, filename, NULL, bdrv_flags, drv) < 0) {
- error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+ int ret;
+
+ ret = bdrv_open(bs, filename, NULL, bdrv_flags, drv);
+ if (ret < 0) {
+ error_setg_file_open(errp, -ret, filename);
return;
}
@@ -1483,7 +1486,7 @@ void qmp_drive_mirror(const char *device, const char *target,
if (ret < 0) {
bdrv_delete(target_bs);
- error_set(errp, QERR_OPEN_FILE_FAILED, target);
+ error_setg_file_open(errp, -ret, target);
return;
}
diff --git a/cpus.c b/cpus.c
index c232265cd2..c8bc8ad8b5 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1278,7 +1278,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char *filename,
f = fopen(filename, "wb");
if (!f) {
- error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+ error_setg_file_open(errp, errno, filename);
return;
}
@@ -1308,7 +1308,7 @@ void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
f = fopen(filename, "wb");
if (!f) {
- error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+ error_setg_file_open(errp, errno, filename);
return;
}
diff --git a/dump.c b/dump.c
index 44a1339c8a..c812cfaf2d 100644
--- a/dump.c
+++ b/dump.c
@@ -853,7 +853,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
if (strstart(file, "file:", &p)) {
fd = qemu_open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
if (fd < 0) {
- error_set(errp, QERR_OPEN_FILE_FAILED, p);
+ error_setg_file_open(errp, errno, p);
return;
}
}
diff --git a/include/qapi/error.h b/include/qapi/error.h
index 5cd2f0c302..ffd1cea477 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -45,6 +45,11 @@ void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char
error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__)
/**
+ * Helper for open() errors
+ */
+void error_setg_file_open(Error **errp, int os_errno, const char *filename);
+
+/**
* Returns true if an indirect pointer to an error is pointing to a valid
* error object.
*/
diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
index 6c0a18dfc4..c30c2f6d7a 100644
--- a/include/qapi/qmp/qerror.h
+++ b/include/qapi/qmp/qerror.h
@@ -177,9 +177,6 @@ void assert_no_error(Error *err);
#define QERR_NOT_SUPPORTED \
ERROR_CLASS_GENERIC_ERROR, "Not supported"
-#define QERR_OPEN_FILE_FAILED \
- ERROR_CLASS_GENERIC_ERROR, "Could not open '%s'"
-
#define QERR_PERMISSION_DENIED \
ERROR_CLASS_GENERIC_ERROR, "Insufficient permission to perform this operation"
diff --git a/savevm.c b/savevm.c
index 2ce439f7f4..ff5ece651a 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2410,7 +2410,7 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)
f = qemu_fopen(filename, "wb");
if (!f) {
- error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+ error_setg_file_open(errp, errno, filename);
goto the_end;
}
ret = qemu_save_device_state(f);
diff --git a/util/error.c b/util/error.c
index 519f6b6ce0..53b04354ae 100644
--- a/util/error.c
+++ b/util/error.c
@@ -71,6 +71,11 @@ void error_set_errno(Error **errp, int os_errno, ErrorClass err_class,
*errp = err;
}
+void error_setg_file_open(Error **errp, int os_errno, const char *filename)
+{
+ error_setg_errno(errp, os_errno, "Could not open '%s'", filename);
+}
+
Error *error_copy(const Error *err)
{
Error *err_new;