From: <ta...@us...> - 2014-01-31 01:31:20
|
Revision: 8835 http://sourceforge.net/p/gfarm/code/8835 Author: tatebe Date: 2014-01-31 01:31:17 +0000 (Fri, 31 Jan 2014) Log Message: ----------- output total Modified Paths: -------------- gfarm_v2/branches/2.5/gftool/gfusage/gfusage.c Modified: gfarm_v2/branches/2.5/gftool/gfusage/gfusage.c =================================================================== --- gfarm_v2/branches/2.5/gftool/gfusage/gfusage.c 2014-01-30 03:36:17 UTC (rev 8834) +++ gfarm_v2/branches/2.5/gftool/gfusage/gfusage.c 2014-01-31 01:31:17 UTC (rev 8835) @@ -21,6 +21,8 @@ static int opt_format_flags = 0; static int opt_humanize_number = 0; +static struct gfarm_quota_get_info total_qi; + static void usage(void) { @@ -47,65 +49,95 @@ } static gfarm_error_t -print_usage_common(const char *name, int opt_group) +print_usage(const char *name, struct gfarm_quota_get_info *qip) { - struct gfarm_quota_get_info qi; - gfarm_error_t e; - - if (opt_group) - e = gfm_client_quota_group_get(gfm_server, name, &qi); - else - e = gfm_client_quota_user_get(gfm_server, name, &qi); - if (e == GFARM_ERR_OPERATION_NOT_PERMITTED) /* not report here */ - return (e); - else if (e == GFARM_ERR_NO_SUCH_OBJECT) { /* not enabled */ - fprintf(stderr, "%s : quota is not enabled.\n", name); - return (e); - } else if (e != GFARM_ERR_NO_ERROR) { - fprintf(stderr, "%s: %s : %s\n", - program_name, name, gfarm_error_string(e)); - return (e); - } printf("%12s : ", name); if (opt_humanize_number) { - printf("%15s ", humanize(qi.space)); - printf("%11s ", humanize(qi.num)); - printf("%15s ", humanize(qi.phy_space)); - printf("%11s\n", humanize(qi.phy_num)); + printf("%15s ", humanize(qip->space)); + printf("%11s ", humanize(qip->num)); + printf("%15s ", humanize(qip->phy_space)); + printf("%11s\n", humanize(qip->phy_num)); } else printf("%15"GFARM_PRId64" %11"GFARM_PRId64 " %15"GFARM_PRId64" %11"GFARM_PRId64"\n", - qi.space, qi.num, qi.phy_space, qi.phy_num); - gfarm_quota_get_info_free(&qi); + qip->space, qip->num, qip->phy_space, qip->phy_num); return (GFARM_ERR_NO_ERROR); } -static void -print_header_user() +static gfarm_error_t +print_usage_total(void) { - printf(header_format, head_user, head_space, head_num, - head_phy_space, head_phy_num); + printf("-------------------------------------------"); + printf("---------------------------\n"); + return (print_usage("TOTAL", &total_qi)); } -static void -print_header_group() +static gfarm_error_t +quota_get(gfarm_error_t (*get)( + struct gfm_connection *, const char *, struct gfarm_quota_get_info *), + const char *name, struct gfarm_quota_get_info *qip) { - printf(header_format, head_group, head_space, head_num, - head_phy_space, head_phy_num); + gfarm_error_t e = get(gfm_server, name, qip); + + if (e == GFARM_ERR_OPERATION_NOT_PERMITTED) /* not report here */ + ; + else if (e == GFARM_ERR_NO_SUCH_OBJECT) /* not enabled */ + fprintf(stderr, "%s: quota is not enabled.\n", name); + else if (e != GFARM_ERR_NO_ERROR) + fprintf(stderr, "%s: %s: %s\n", + program_name, name, gfarm_error_string(e)); + return (e); } + static gfarm_error_t +print_usage_common(gfarm_error_t (*get)( + struct gfm_connection *, const char *, struct gfarm_quota_get_info *), + const char *name) +{ + gfarm_error_t e; + struct gfarm_quota_get_info qi; + + e = quota_get(get, name, &qi); + if (e != GFARM_ERR_NO_ERROR) + return (e); + e = print_usage(name, &qi); + if (e == GFARM_ERR_NO_ERROR) { + total_qi.space += qi.space; + total_qi.num += qi.num; + total_qi.phy_space += qi.phy_space; + total_qi.phy_num += qi.phy_num; + } + gfarm_quota_get_info_free(&qi); + return (e); +} + +static gfarm_error_t print_usage_user(const char *name) { - return (print_usage_common(name, 0)); + return (print_usage_common(gfm_client_quota_user_get, name)); } static gfarm_error_t print_usage_group(const char *name) { - return (print_usage_common(name, 1)); + return (print_usage_common(gfm_client_quota_group_get, name)); } +static void +print_header_user() +{ + printf(header_format, head_user, head_space, head_num, + head_phy_space, head_phy_num); +} + +static void +print_header_group() +{ + printf(header_format, head_group, head_space, head_num, + head_phy_space, head_phy_num); +} + static gfarm_error_t usage_user_one(const char *name) { @@ -151,7 +183,7 @@ free(users); if (success > 0) - return (GFARM_ERR_NO_ERROR); + return (print_usage_total()); else return (e_save); } @@ -187,7 +219,7 @@ free(groups); if (success > 0) - return (GFARM_ERR_NO_ERROR); + return (print_usage_total()); else return (e_save); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |