From: Keir Fraser Date: Wed, 19 May 2010 11:48:32 +0000 (+0100) Subject: libxl: Add tmem support commands X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12118 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5c898a05f448738985cc0eefa0ae7389e26349a4;p=xen.git libxl: Add tmem support commands Signed-off-by: Yang Hongyang --- diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 7da3695ff8..948e845d5a 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2840,3 +2840,111 @@ uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid) return strtoul(start_time, NULL, 10); } +char *libxl_tmem_list(struct libxl_ctx *ctx, uint32_t domid, int use_long) +{ + int rc; + char _buf[32768]; + + rc = xc_tmem_control(ctx->xch, -1, TMEMC_LIST, domid, 32768, use_long, + 0, _buf); + if (rc < 0) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, + "Can not get tmem list"); + return NULL; + } + + return strdup(_buf); +} + +int libxl_tmem_freeze(struct libxl_ctx *ctx, uint32_t domid) +{ + int rc; + + rc = xc_tmem_control(ctx->xch, -1, TMEMC_FREEZE, domid, 0, 0, + 0, NULL); + if (rc < 0) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, + "Can not freeze tmem pools"); + return -1; + } + + return rc; +} + +int libxl_tmem_destroy(struct libxl_ctx *ctx, uint32_t domid) +{ + int rc; + + rc = xc_tmem_control(ctx->xch, -1, TMEMC_DESTROY, domid, 0, 0, + 0, NULL); + if (rc < 0) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, + "Can not destroy tmem pools"); + return -1; + } + + return rc; +} + +int libxl_tmem_thaw(struct libxl_ctx *ctx, uint32_t domid) +{ + int rc; + + rc = xc_tmem_control(ctx->xch, -1, TMEMC_THAW, domid, 0, 0, + 0, NULL); + if (rc < 0) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, + "Can not thaw tmem pools"); + return -1; + } + + return rc; +} + +static int32_t tmem_setop_from_string(char *set_name) +{ + if (!strcmp(set_name, "weight")) + return TMEMC_SET_WEIGHT; + else if (!strcmp(set_name, "cap")) + return TMEMC_SET_CAP; + else if (!strcmp(set_name, "compress")) + return TMEMC_SET_COMPRESS; + else + return -1; +} + +int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set) +{ + int rc; + int32_t subop = tmem_setop_from_string(name); + + if (subop == -1) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, -1, + "Invalid set, valid sets are "); + return -1; + } + rc = xc_tmem_control(ctx->xch, -1, subop, domid, set, 0, 0, NULL); + if (rc < 0) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, + "Can not set tmem %s", name); + return -1; + } + + return rc; +} + +int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, + char* uuid, int auth) +{ + int rc; + + rc = xc_tmem_auth(ctx->xch, domid, uuid, auth); + if (rc < 0) { + XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, + "Can not set tmem shared auth"); + return -1; + } + + return rc; +} + diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 9764671525..a3f949bab8 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -513,5 +513,13 @@ int libxl_send_trigger(struct libxl_ctx *ctx, uint32_t domid, int libxl_send_sysrq(struct libxl_ctx *ctx, uint32_t domid, char sysrq); uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid); +char *libxl_tmem_list(struct libxl_ctx *ctx, uint32_t domid, int use_long); +int libxl_tmem_freeze(struct libxl_ctx *ctx, uint32_t domid); +int libxl_tmem_destroy(struct libxl_ctx *ctx, uint32_t domid); +int libxl_tmem_thaw(struct libxl_ctx *ctx, uint32_t domid); +int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name, + uint32_t set); +int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, char* uuid, + int auth); #endif /* LIBXL_H */ diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index b1fe305882..e9fa1e2a5f 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -3731,3 +3731,279 @@ int main_uptime(int argc, char **argv) exit(0); } + +int main_tmem_list(int argc, char **argv) +{ + char *dom = NULL; + char *buf = NULL; + int use_long = 0; + int all = 0; + int opt; + + while ((opt = getopt(argc, argv, "alh")) != -1) { + switch (opt) { + case 'l': + use_long = 1; + break; + case 'a': + all = 1; + break; + case 'h': + help("tmem-list"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + dom = argv[optind]; + if (!dom && all == 0) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + help("tmem-list"); + exit(1); + } + + if (all) + domid = -1; + else + find_domain(dom); + + buf = libxl_tmem_list(&ctx, domid, use_long); + if (buf == NULL) + exit(-1); + + printf("%s\n", buf); + free(buf); + exit(0); +} + +int main_tmem_freeze(int argc, char **argv) +{ + char *dom = NULL; + int all = 0; + int opt; + + while ((opt = getopt(argc, argv, "ah")) != -1) { + switch (opt) { + case 'a': + all = 1; + break; + case 'h': + help("tmem-freeze"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + dom = argv[optind]; + if (!dom && all == 0) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + help("tmem-freeze"); + exit(1); + } + + if (all) + domid = -1; + else + find_domain(dom); + + libxl_tmem_freeze(&ctx, domid); + exit(0); +} + +int main_tmem_destroy(int argc, char **argv) +{ + char *dom = NULL; + int all = 0; + int opt; + + while ((opt = getopt(argc, argv, "ah")) != -1) { + switch (opt) { + case 'a': + all = 1; + break; + case 'h': + help("tmem-destroy"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + dom = argv[optind]; + if (!dom && all == 0) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + help("tmem-destroy"); + exit(1); + } + + if (all) + domid = -1; + else + find_domain(dom); + + libxl_tmem_destroy(&ctx, domid); + exit(0); +} + +int main_tmem_thaw(int argc, char **argv) +{ + char *dom = NULL; + int all = 0; + int opt; + + while ((opt = getopt(argc, argv, "ah")) != -1) { + switch (opt) { + case 'a': + all = 1; + break; + case 'h': + help("tmem-thaw"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + dom = argv[optind]; + if (!dom && all == 0) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + help("tmem-thaw"); + exit(1); + } + + if (all) + domid = -1; + else + find_domain(dom); + + libxl_tmem_thaw(&ctx, domid); + exit(0); +} + +int main_tmem_set(int argc, char **argv) +{ + char *dom = NULL; + uint32_t weight = 0, cap = 0, compress = 0; + int opt_w = 0, opt_c = 0, opt_p = 0; + int all = 0; + int opt; + + while ((opt = getopt(argc, argv, "aw:c:p:h")) != -1) { + switch (opt) { + case 'a': + all = 1; + break; + case 'w': + weight = strtol(optarg, NULL, 10); + opt_w = 1; + break; + case 'c': + cap = strtol(optarg, NULL, 10); + opt_c = 1; + break; + case 'p': + compress = strtol(optarg, NULL, 10); + opt_p = 1; + break; + case 'h': + help("tmem-set"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + dom = argv[optind]; + if (!dom && all == 0) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + help("tmem-set"); + exit(1); + } + + if (all) + domid = -1; + else + find_domain(dom); + + if (!opt_w && !opt_c && !opt_p) { + fprintf(stderr, "No set value specified.\n\n"); + help("tmem-set"); + exit(1); + } + + if (opt_w) + libxl_tmem_set(&ctx, domid, "weight", weight); + if (opt_c) + libxl_tmem_set(&ctx, domid, "cap", cap); + if (opt_p) + libxl_tmem_set(&ctx, domid, "compress", compress); + + exit(0); +} + +int main_tmem_shared_auth(int argc, char **argv) +{ + char *autharg = NULL; + char *endptr = NULL; + char *dom = NULL; + char *uuid = NULL; + int auth = -1; + int all = 0; + int opt; + + while ((opt = getopt(argc, argv, "au:A:h")) != -1) { + switch (opt) { + case 'a': + all = 1; + break; + case 'u': + uuid = optarg; + break; + case 'A': + autharg = optarg; + break; + case 'h': + help("tmem-shared-auth"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + dom = argv[optind]; + if (!dom && all == 0) { + fprintf(stderr, "You must specify -a or a domain id.\n\n"); + help("tmem-shared-auth"); + exit(1); + } + + if (all) + domid = -1; + else + find_domain(dom); + + if (uuid == NULL || autharg == NULL) { + fprintf(stderr, "No uuid or auth specified.\n\n"); + help("tmem-shared-auth"); + exit(1); + } + + auth = strtol(autharg, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, "Invalid auth, valid auth are <0|1>.\n\n"); + exit(1); + } + + libxl_tmem_shared_auth(&ctx, domid, uuid, auth); + + exit(0); +} + diff --git a/tools/libxl/xl_cmdimpl.h b/tools/libxl/xl_cmdimpl.h index 2654efb589..ebbf740fe4 100644 --- a/tools/libxl/xl_cmdimpl.h +++ b/tools/libxl/xl_cmdimpl.h @@ -52,6 +52,12 @@ int main_blockattach(int argc, char **argv); int main_blocklist(int argc, char **argv); int main_blockdetach(int argc, char **argv); int main_uptime(int argc, char **argv); +int main_tmem_list(int argc, char **argv); +int main_tmem_freeze(int argc, char **argv); +int main_tmem_destroy(int argc, char **argv); +int main_tmem_thaw(int argc, char **argv); +int main_tmem_set(int argc, char **argv); +int main_tmem_shared_auth(int argc, char **argv); void help(char *command); diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index 82cf2ca722..b1f87468e8 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -228,6 +228,48 @@ struct cmd_spec cmd_table[] = { "Print uptime for all/some domains", "[-s] [Domain]", }, + { "tmem-list", + &main_tmem_list, + "List tmem pools", + "[-l] [|-a]", + " -l List tmem stats", + }, + { "tmem-freeze", + &main_tmem_freeze, + "Freeze tmem pools", + "[|-a]", + " -a Freeze all tmem", + }, + { "tmem-destroy", + &main_tmem_destroy, + "Destroy tmem pools", + "[|-a]", + " -a Destroy all tmem", + }, + { "tmem-thaw", + &main_tmem_thaw, + "Thaw tmem pools", + "[|-a]", + " -a Thaw all tmem", + }, + { "tmem-set", + &main_tmem_set, + "Change tmem settings", + "[|-a] [-w[=WEIGHT]|-c[=CAP]|-p[=COMPRESS]]", + " -a Operate on all tmem\n" + " -w WEIGHT Weight (int)\n" + " -c CAP Cap (int)\n" + " -p COMPRESS Compress (int)", + }, + { "tmem-shared-auth", + &main_tmem_shared_auth, + "De/authenticate shared tmem pool", + "[|-a] [-u[=UUID] [-A[=AUTH]", + " -a Authenticate for all tmem pools\n" + " -u UUID Specify uuid\n" + " (abcdef01-2345-6789-1234-567890abcdef)\n" + " -A AUTH 0=auth,1=deauth", + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);