Patchwork [09/13] block: update return value from bdrv_snapshot_create

login
register
mail settings
Submitter Pavel Hrdina
Date Jan. 9, 2013, 3:18 p.m.
Message ID <6558e79e437c68e1c939ed19cc9a5b0062c0394f.1357741229.git.phrdina@redhat.com>
Download mbox | patch
Permalink /patch/210754/
State New
Headers show

Comments

Pavel Hrdina - Jan. 9, 2013, 3:18 p.m.
If we provide error message, we should also provide a return code.
In some cases we could not care about any error message and the return
code is enough for as.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 block.c                | 4 ++--
 block/qcow2-snapshot.c | 4 ++--
 block/rbd.c            | 8 ++++----
 block/sheepdog.c       | 4 ++--
 qemu-img.c             | 7 ++++---
 5 files changed, 14 insertions(+), 13 deletions(-)

Patch

diff --git a/block.c b/block.c
index 10e5d3e..44f43bd 100644
--- a/block.c
+++ b/block.c
@@ -3139,7 +3139,7 @@  int bdrv_snapshot_create(BlockDriverState *bs,
     if (!drv) {
         error_setg(errp, "Device '%s' has no medium.",
                    bdrv_get_device_name(bs));
-        return -ENOMEDIUM;
+        return -1;
     }
     if (drv->bdrv_snapshot_create) {
         return drv->bdrv_snapshot_create(bs, sn_info, errp);
@@ -3150,7 +3150,7 @@  int bdrv_snapshot_create(BlockDriverState *bs,
 
     error_setg(errp, "Snapshot is not supported for '%s'.",
                bdrv_get_format_name(bs));
-    return -ENOTSUP;
+    return -1;
 }
 
 int bdrv_snapshot_goto(BlockDriverState *bs,
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 529e9ee..313c7cd 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -334,7 +334,7 @@  int qcow2_snapshot_create(BlockDriverState *bs,
     /* Check that the ID is unique */
     if (find_snapshot_by_id(bs, sn_info->id_str) >= 0) {
         error_setg(errp, "Parameter 'name' has to be unique ID.");
-        return -EEXIST;
+        return -1;
     }
 
     /* Populate sn with passed data */
@@ -423,7 +423,7 @@  fail:
     g_free(sn->name);
     g_free(l1_table);
 
-    return ret;
+    return -1;
 }
 
 /* copy the snapshot 'snapshot_name' into the current disk image */
diff --git a/block/rbd.c b/block/rbd.c
index 1066159..03f04c4 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -823,7 +823,7 @@  static int qemu_rbd_snap_create(BlockDriverState *bs,
 
     if (sn_info->name[0] == '\0') {
         error_setg(errp, "Parameter 'name' cannot be empty.");
-        return -EINVAL; /* we need a name for rbd snapshots */
+        return -1; /* we need a name for rbd snapshots */
     }
 
     /*
@@ -833,19 +833,19 @@  static int qemu_rbd_snap_create(BlockDriverState *bs,
     if (sn_info->id_str[0] != '\0' &&
         strcmp(sn_info->id_str, sn_info->name) != 0) {
         error_setg(errp, "ID and name have to be equal.");
-        return -EINVAL;
+        return -1;
     }
 
     if (strlen(sn_info->name) >= sizeof(sn_info->id_str)) {
         error_setg(errp, "Parameter 'name' has to be shorter that 127 chars.");
-        return -ERANGE;
+        return -1;
     }
 
     r = rbd_snap_create(s->image, sn_info->name);
     if (r < 0) {
         error_setg(errp, "Failed to create snapshot.");
         error_report("failed to create snap: %s", strerror(-r));
-        return r;
+        return -1;
     }
 
     return 0;
diff --git a/block/sheepdog.c b/block/sheepdog.c
index aacde64..5c6adf7 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1753,7 +1753,7 @@  static int sd_snapshot_create(BlockDriverState *bs,
     if (s->is_snapshot) {
         error_setg(errp, "You can't create a snapshot '%s' of a VDI snapshot.",
                    sn_info->name);
-        return -EINVAL;
+        return -1;
     }
 
     dprintf("%s %s\n", sn_info->name, sn_info->id_str);
@@ -1805,7 +1805,7 @@  static int sd_snapshot_create(BlockDriverState *bs,
 
 cleanup:
     closesocket(fd);
-    return ret;
+    return ret < 0 ? -1 : 0;
 }
 
 static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
diff --git a/qemu-img.c b/qemu-img.c
index c283bf6..06dd484 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1498,6 +1498,7 @@  static int img_snapshot(int argc, char **argv)
     int c, ret = 0, bdrv_oflags;
     int action = 0;
     qemu_timeval tv;
+    Error *local_err;
 
     bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;
     /* Parse commandline parameters */
@@ -1571,10 +1572,10 @@  static int img_snapshot(int argc, char **argv)
         sn.date_sec = tv.tv_sec;
         sn.date_nsec = tv.tv_usec * 1000;
 
-        ret = bdrv_snapshot_create(bs, &sn, NULL);
+        local_err = NULL;
+        ret = bdrv_snapshot_create(bs, &sn, &local_err);
         if (ret) {
-            error_report("Could not create snapshot '%s': %d (%s)",
-                snapshot_name, ret, strerror(-ret));
+            qemu_img_handle_error(local_err);
         }
         break;