[sheepdog] [PATCH 2/5] dog/vdi: enhance find_vdi_name to allow returning SD_RES_XXX
Ruoyu
liangry at ucweb.com
Thu Sep 4 15:44:09 CEST 2014
Current return value of the function find_vdi_name is quite simple. -1
stands for failure and 0 stands for success. It is not enough if caller
A expects it returns information of a VDI and caller B expects it
returns the VDI is existed or not.
So, it is better to enhance it to return SD_RES_XXX.
As a result, the error message printed inside the function should be
moved to the callers.
Signed-off-by: Ruoyu <liangry at ucweb.com>
---
dog/vdi.c | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/dog/vdi.c b/dog/vdi.c
index 2cce69c..be9cbe2 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -353,16 +353,12 @@ static int find_vdi_name(const char *vdiname, uint32_t snapid, const char *tag,
ret = dog_exec_req(&sd_nid, &hdr, buf);
if (ret < 0)
- return -1;
+ return SD_RES_EIO;
- if (rsp->result != SD_RES_SUCCESS) {
- sd_err("Cannot get VDI info for %s %d %s: %s", vdiname, snapid,
- tag, sd_strerror(rsp->result));
- return -1;
- }
- *vid = rsp->vdi.vdi_id;
+ if (rsp->result == SD_RES_SUCCESS)
+ *vid = rsp->vdi.vdi_id;
- return 0;
+ return rsp->result;
}
int read_vdi_obj(const char *vdiname, int snapid, const char *tag,
@@ -373,8 +369,9 @@ int read_vdi_obj(const char *vdiname, int snapid, const char *tag,
uint32_t vid;
ret = find_vdi_name(vdiname, snapid, tag, &vid);
- if (ret < 0) {
- sd_err("Failed to open VDI %s", vdiname);
+ if (ret != SD_RES_SUCCESS) {
+ sd_err("Failed to open VDI %s (snapshot id: %d snapshot tag: %s)"
+ ": %s", vdiname, snapid, tag, sd_strerror(ret));
return EXIT_FAILURE;
}
@@ -824,8 +821,9 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag)
int i = 0;
ret = find_vdi_name(vdiname, snap_id, snap_tag, &vid);
- if (ret < 0) {
- sd_err("Failed to open VDI %s", vdiname);
+ if (ret != SD_RES_SUCCESS) {
+ sd_err("Failed to open VDI %s (snapshot id: %d snapshot tag: %s)"
+ ": %s", vdiname, snap_id, snap_tag, sd_strerror(ret));
ret = EXIT_FAILURE;
goto out;
}
@@ -2439,8 +2437,10 @@ static int vdi_cache_flush(int argc, char **argv)
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid);
- if (ret < 0) {
- sd_err("Failed to open VDI %s", vdiname);
+ if (ret != SD_RES_SUCCESS) {
+ sd_err("Failed to open VDI %s (snapshot id: %d snapshot tag: %s)"
+ ": %s", vdiname, vdi_cmd_data.snapshot_id,
+ vdi_cmd_data.snapshot_tag, sd_strerror(ret));
ret = EXIT_FAILURE;
goto out;
}
@@ -2474,8 +2474,10 @@ static int vdi_cache_delete(int argc, char **argv)
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid);
- if (ret < 0) {
- sd_err("Failed to open VDI %s", vdiname);
+ if (ret != SD_RES_SUCCESS) {
+ sd_err("Failed to open VDI %s (snapshot id: %d snapshot tag: %s)"
+ ": %s", vdiname, vdi_cmd_data.snapshot_id,
+ vdi_cmd_data.snapshot_tag, sd_strerror(ret));
ret = EXIT_FAILURE;
goto out;
}
@@ -2563,8 +2565,10 @@ static int vdi_cache_purge(int argc, char **argv)
vdiname = argv[optind++];
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid);
- if (ret < 0) {
- sd_err("Failed to open VDI %s", vdiname);
+ if (ret != SD_RES_SUCCESS) {
+ sd_err("Failed to open VDI %s (snapshot id: %d snapshot tag: %s)"
+ ": %s", vdiname, vdi_cmd_data.snapshot_id,
+ vdi_cmd_data.snapshot_tag, sd_strerror(ret));
ret = EXIT_FAILURE;
goto out;
}
--
1.8.3.2
More information about the sheepdog
mailing list