diff options
author | Sachin Pandit <spandit@redhat.com> | 2015-02-03 05:01:38 +0530 |
---|---|---|
committer | Kaushal M <kaushal@redhat.com> | 2015-02-19 02:12:36 -0800 |
commit | f099a87fd36b600ccb8268937d3cd7ca84799f77 (patch) | |
tree | 0413803dcd6ab593d40fd8b12ecaaffbc8bf7638 /cli/src/cli-rpc-ops.c | |
parent | bdb5ca2339edc76b81d1ff996d695eecd849760f (diff) |
features/quota : Fix XML output for quota list command
Sample output:
---------------
Sample 1)
----------
[root@snapshot-28 glusterfs]# gluster volume quota vol1 list /dir1 /dir4 /dir5 --xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>0</opErrno>
<opErrstr/>
<volQuota>
<limit>
<path>/dir1</path>
<hard_limit>10.0MB</hard_limit>
<soft_limit>80%</soft_limit>
<used_space>0Bytes</used_space>
<avail_space>10.0MB</avail_space>
<hl_exceeded>No</hl_exceeded>
<sl_exceeded>No</sl_exceeded>
</limit>
<limit>
<path>/dir4</path>
<path>No such file or directory</path>
</limit>
<limit>
<path>/dir5</path>
<path>No such file or directory</path>
</limit>
</volQuota>
</cliOutput>
Sample 2)
---------
gluster volume quota vol1 list --xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<opRet>0</opRet>
<opErrno>0</opErrno>
<opErrstr/>
<volQuota/>
</cliOutput>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cliOutput>
<volQuota>
<limit>
<path>/dir</path>
<hard_limit>10.0MB</hard_limit>
<soft_limit>80%</soft_limit>
<used_space>0Bytes</used_space>
<avail_space>10.0MB</avail_space>
<hl_exceeded>No</hl_exceeded>
<sl_exceeded>No</sl_exceeded>
</limit>
<limit>
<path>/dir1</path>
<hard_limit>10.0MB</hard_limit>
<soft_limit>80%</soft_limit>
<used_space>0Bytes</used_space>
<avail_space>10.0MB</avail_space>
<hl_exceeded>No</hl_exceeded>
<sl_exceeded>No</sl_exceeded>
</limit>
</volQuota>
</cliOutput>
Change-Id: I8a8d83cff88f778e5ee01fbca07d9f94c412317a
BUG: 1185259
Signed-off-by: Sachin Pandit <spandit@redhat.com>
Reviewed-on: http://review.gluster.org/9481
Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'cli/src/cli-rpc-ops.c')
-rw-r--r-- | cli/src/cli-rpc-ops.c | 161 |
1 files changed, 126 insertions, 35 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 0238a8ff0e7..4e1c6873cee 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2410,7 +2410,8 @@ out: } static int -print_quota_list_output (char *mountdir, char *default_sl, char *path) +print_quota_list_output (cli_local_t *local, char *mountdir, + char *default_sl, char *path) { int64_t used_space = 0; int64_t avail = 0; @@ -2443,10 +2444,30 @@ print_quota_list_output (char *mountdir, char *default_sl, char *path) #if defined(ENOATTR) && (ENOATTR != ENODATA) case ENOATTR: #endif - cli_err ("%-40s %s", path, "Limit not set"); + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_quota_list_xml_error + (local, path, "Limit not set"); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed " + "to print xml output"); + goto out; + } + } else { + cli_err ("%-40s %s", path, strerror (errno)); + } break; default: - cli_err ("%-40s %s", path, strerror (errno)); + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_quota_list_xml_error + (local, path, strerror (errno)); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed " + "to print xml output"); + goto out; + } + } else { + cli_err ("%-40s %s", path, strerror (errno)); + } break; } @@ -2473,9 +2494,21 @@ print_quota_list_output (char *mountdir, char *default_sl, char *path) &used_space, sizeof (used_space)); if (ret < 0) { - cli_out ("%-40s %7s %9s %11s %7s %15s %20s", - path, hl_str, sl_final, - "N/A", "N/A", "N/A", "N/A"); + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_quota_xml_output (local, path, hl_str, + sl_final, "N/A", + "N/A", "N/A", "N/A"); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to " + "output in xml format for quota " + "list command"); + } + goto out; + } else { + cli_out ("%-40s %7s %9s %11s %7s %15s %20s", + path, hl_str, sl_final, + "N/A", "N/A", "N/A", "N/A"); + } } else { used_space = ntoh64 (used_space); @@ -2494,6 +2527,20 @@ print_quota_list_output (char *mountdir, char *default_sl, char *path) } avail_str = gf_uint64_2human_readable (avail); + + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_quota_xml_output (local, path, hl_str, + sl_final, used_str, + avail_str, sl ? "Yes" : "No", + hl ? "Yes" : "No"); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to " + "output in xml format for quota " + "list command"); + } + goto out; + } + if (used_str == NULL) { cli_out ("%-40s %7s %9s %11"PRIu64 "%9"PRIu64" %15s %18s", path, hl_str, @@ -2514,14 +2561,17 @@ out: } int -gf_cli_print_limit_list_from_dict (char *volname, dict_t *dict, - char *default_sl, int count, char *op_errstr) +gf_cli_print_limit_list_from_dict (cli_local_t *local, char *volname, + dict_t *dict, char *default_sl, int count, + int op_ret, int op_errno, char *op_errstr) { - int ret = -1; - int i = 0; - char key[1024] = {0,}; - char mountdir[PATH_MAX] = {0,}; - char *path = NULL; + int ret = -1; + int i = 0; + char key[1024] = {0,}; + char mountdir[PATH_MAX] = {0,}; + char *path = NULL; + gf_boolean_t xml_err_flag = _gf_false; + char err_str[NAME_MAX] = {0,}; if (!dict|| count <= 0) goto out; @@ -2530,8 +2580,14 @@ gf_cli_print_limit_list_from_dict (char *volname, dict_t *dict, * to list them */ if (!_limits_set_on_volume (volname)) { + snprintf (err_str, sizeof (err_str), "No quota configured on " + "volume %s", volname); + if (global_state->mode & GLUSTER_MODE_XML) { + xml_err_flag = _gf_true; + } else { + cli_out ("quota: %s", err_str); + } ret = 0; - cli_out ("quota: No quota configured on volume %s", volname); goto out; } @@ -2541,12 +2597,22 @@ gf_cli_print_limit_list_from_dict (char *volname, dict_t *dict, goto out; } - cli_out (" Path Hard-limit " - "Soft-limit Used Available Soft-limit exceeded?" - " Hard-limit exceeded?"); - cli_out ("--------------------------------------------------------" - "--------------------------------------------------------" - "-----------"); + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_xml_output_vol_quota_limit_list_begin + (local, op_ret, op_errno, op_errstr); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, + "Error outputting xml begin"); + goto out; + } + } else { + cli_out (" Path Hard-limit " + "Soft-limit Used Available Soft-limit exceeded?" + " Hard-limit exceeded?"); + cli_out ("-----------------------------------------------------" + "-----------------------------------------------------" + "-----------------"); + } while (count--) { snprintf (key, sizeof (key), "path%d", i++); @@ -2562,10 +2628,18 @@ gf_cli_print_limit_list_from_dict (char *volname, dict_t *dict, if (ret) goto out; GLUSTERD_GET_QUOTA_AUX_MOUNT_PATH (mountdir, volname, path); - ret = print_quota_list_output (mountdir, default_sl, path); - + ret = print_quota_list_output (local, mountdir, default_sl, + path); } + out: + if (xml_err_flag) { + ret = cli_xml_output_str ("volQuota", NULL, -1, 0, err_str); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Error outputting in xml " + "format"); + } + } return ret; } @@ -2657,6 +2731,20 @@ print_quota_list_from_quotad (call_frame_t *frame, dict_t *rsp_dict) hl = sl = _gf_true; } avail_str = gf_uint64_2human_readable (avail); + + if (global_state->mode & GLUSTER_MODE_XML) { + ret = cli_quota_xml_output (local, path, hl_str, + sl_final, used_str, + avail_str, sl ? "Yes" : "No", + hl ? "Yes" : "No"); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed in " + "printing xml output for quota list " + "command"); + } + goto out; + } + if (used_str == NULL) cli_out ("%-40s %7s %9s %11"PRIu64 "%9"PRIu64" %15s %20s", path, hl_str, @@ -2768,8 +2856,9 @@ out: } void -gf_cli_quota_list (char *volname, dict_t *dict, int count, char *op_errstr, - char *default_sl) +gf_cli_quota_list (cli_local_t *local, char *volname, dict_t *dict, + char *default_sl, int count, int op_ret, + int op_errno, char *op_errstr) { GF_VALIDATE_OR_GOTO ("cli", volname, out); @@ -2777,8 +2866,9 @@ gf_cli_quota_list (char *volname, dict_t *dict, int count, char *op_errstr, goto out; if (count > 0) - gf_cli_print_limit_list_from_dict (volname, dict, default_sl, - count, op_errstr); + gf_cli_print_limit_list_from_dict (local, volname, dict, + default_sl, count, op_ret, + op_errno, op_errstr); out: return; } @@ -2881,18 +2971,19 @@ gf_cli_quota_cbk (struct rpc_req *req, struct iovec *iov, gf_log (frame->this->name, GF_LOG_TRACE, "failed to get count"); if (type == GF_QUOTA_OPTION_TYPE_LIST) { + gf_cli_quota_list (local, volname, dict, default_sl, + entry_count, rsp.op_ret, + rsp.op_errno, rsp.op_errstr); + if (global_state->mode & GLUSTER_MODE_XML) { - ret = cli_xml_output_vol_quota_limit_list - (volname, limit_list, rsp.op_ret, - rsp.op_errno, rsp.op_errstr); - if (ret) - gf_log ("cli", GF_LOG_ERROR, - "Error outputting to xml"); + ret = cli_xml_output_vol_quota_limit_list_end (local); + if (ret < 0) { + ret = -1; + gf_log ("cli", GF_LOG_ERROR, "Error in printing" + " xml output"); + } goto out; } - - gf_cli_quota_list (volname, dict, entry_count, rsp.op_errstr, - default_sl); } xml_output: |