libxl: Add tmem support commands
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 19 May 2010 11:48:32 +0000 (12:48 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 19 May 2010 11:48:32 +0000 (12:48 +0100)
Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdimpl.h
tools/libxl/xl_cmdtable.c

index 7da3695ff8d41f7108029e04512614627b937c7b..948e845d5a579f55c73fe018bc453130b53063a5 100644 (file)
@@ -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 <weight|cap|compress>");
+        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;
+}
+
index 976467152556f1fbae488f33dbc3fd0c3920ba74..a3f949bab8c6300205aa0c9dabfd4a0f07450551 100644 (file)
@@ -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 */
 
index b1fe3058826b0e366c320a28a9b589b708bbbb8f..e9fa1e2a5f940396446319e58c74ed16a250cf0c 100644 (file)
@@ -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);
+}
+
index 2654efb589ccecc2922157e2c94accc3b5c78521..ebbf740fe44ca0745330ab6c4ac86724ff5be787 100644 (file)
@@ -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);
 
index 82cf2ca722809fb646939b9e4de0a264fb83a401..b1f87468e828b5b573a8e6f14f11b8cd708436f3 100644 (file)
@@ -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] [<Domain>|-a]",
+      "  -l                             List tmem stats",
+    },
+    { "tmem-freeze",
+      &main_tmem_freeze,
+      "Freeze tmem pools",
+      "[<Domain>|-a]",
+      "  -a                             Freeze all tmem",
+    },
+    { "tmem-destroy",
+      &main_tmem_destroy,
+      "Destroy tmem pools",
+      "[<Domain>|-a]",
+      "  -a                             Destroy all tmem",
+    },
+    { "tmem-thaw",
+      &main_tmem_thaw,
+      "Thaw tmem pools",
+      "[<Domain>|-a]",
+      "  -a                             Thaw all tmem",
+    },
+    { "tmem-set",
+      &main_tmem_set,
+      "Change tmem settings",
+      "[<Domain>|-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",
+      "[<Domain>|-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);