Skip to contentSkip to conversation

xl: Add 'xl tmem-*' commands

PATCH New Yang Hongyang 1 participant 7 messages May 19, 2010

lore
Share & tools
lore
#0 lore raw

cover xl: Add 'xl tmem-*' commands

Add tmem-* commands, did some simple tests.

[PATCH 1/6]xl: Add 'xl tmem-list' command [PATCH 2/6]xl: Add 'xl tmem-freeze' command [PATCH 3/6]xl: Add 'xl tmem-destroy' command [PATCH 4/6]xl: Add 'xl tmem-thaw' command [PATCH 5/6]xl: Add 'xl tmem-set' command [PATCH 6/6]xl: Add 'xl tmem-shared-auth' command

Signature · 2 lines
Regards
Yang Hongyang
#1 lore raw

PATCH 1/6 xl: Add 'xl tmem-list' command

Add 'xl tmem-list' command

tools/libxl/libxl.c +15 -0
diff -r baccadfd9418 tools/libxl/libxl.c
@@ -2825,3 +2825,18 @@
     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);
+}
tools/libxl/libxl.h +2 -0
diff -r baccadfd9418 tools/libxl/libxl.h
@@ -513,5 +513,7 @@
 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);
+
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +46 -0

49 lines not on this page · raw message

tools/libxl/xl_cmdimpl.h +1 -0
diff -r baccadfd9418 tools/libxl/xl_cmdimpl.h
@@ -52,6 +52,7 @@
 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);
 
 void help(char *command);
 
tools/libxl/xl_cmdtable.c +6 -0
diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
@@ -224,6 +224,12 @@
       "Print uptime for all/some domains",
       "[-s] [Domain]",
     },
+    { "tmem-list",
+      &main_tmem_list,
+      "List tmem pools",
+      "[-l] [<Domain>|-a]",
+      "  -l                             List tmem stats",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#2 lore raw

PATCH 2/6 xl: Add 'xl tmem-freeze' command

In reply to Yang Hongyang

Add 'xl tmem-freeze' command

tools/libxl/libxl.c +15 -0
diff -r 540720cb1f64 tools/libxl/libxl.c
@@ -2840,3 +2840,18 @@
 
     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;
+}
tools/libxl/libxl.h +1 -0
diff -r 540720cb1f64 tools/libxl/libxl.h
@@ -514,6 +514,7 @@
 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);
 
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +37 -0
diff -r 540720cb1f64 tools/libxl/xl_cmdimpl.c
@@ -3713,3 +3713,40 @@
     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);
+}
+
tools/libxl/xl_cmdimpl.h +1 -0
diff -r 540720cb1f64 tools/libxl/xl_cmdimpl.h
@@ -53,6 +53,7 @@
 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);
 
 void help(char *command);
 
tools/libxl/xl_cmdtable.c +6 -0
diff -r 540720cb1f64 tools/libxl/xl_cmdtable.c
@@ -230,6 +230,12 @@
       "[-l] [<Domain>|-a]",
       "  -l                             List tmem stats",
     },
+    { "tmem-freeze",
+      &main_tmem_freeze,
+      "Freeze tmem pools",
+      "[<Domain>|-a]",
+      "  -a                             Freeze all tmem",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#3 lore raw

PATCH 3/6 xl: Add 'xl tmem-destroy' command

In reply to Yang Hongyang

Add 'xl tmem-destroy' command

tools/libxl/libxl.c +15 -0
diff -r 6b8ccb78dffe tools/libxl/libxl.c
@@ -2855,3 +2855,18 @@
 
     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;
+}
tools/libxl/libxl.h +1 -1
diff -r 6b8ccb78dffe tools/libxl/libxl.h
@@ -515,6 +515,6 @@
 
 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);
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +36 -0
diff -r 6b8ccb78dffe tools/libxl/xl_cmdimpl.c
@@ -3750,3 +3750,39 @@
     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);
+}
+
tools/libxl/xl_cmdimpl.h +1 -0
diff -r 6b8ccb78dffe tools/libxl/xl_cmdimpl.h
@@ -54,6 +54,7 @@
 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);
 
 void help(char *command);
 
tools/libxl/xl_cmdtable.c +6 -0
diff -r 6b8ccb78dffe tools/libxl/xl_cmdtable.c
@@ -236,6 +236,12 @@
       "[<Domain>|-a]",
       "  -a                             Freeze all tmem",
     },
+    { "tmem-destroy",
+      &main_tmem_destroy,
+      "Destroy tmem pools",
+      "[<Domain>|-a]",
+      "  -a                             Destroy all tmem",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#4 lore raw

PATCH 4/6 xl: Add 'xl tmem-thaw' command

In reply to Yang Hongyang

Add 'xl tmem-thaw' command

tools/libxl/libxl.c +15 -0
diff -r 6997a436e0ed tools/libxl/libxl.c
@@ -2870,3 +2870,18 @@
 
     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;
+}
tools/libxl/libxl.h +1 -0
diff -r 6997a436e0ed tools/libxl/libxl.h
@@ -516,5 +516,6 @@
 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);
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +36 -0
diff -r 6997a436e0ed tools/libxl/xl_cmdimpl.c
@@ -3786,3 +3786,39 @@
     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);
+}
+
tools/libxl/xl_cmdimpl.h +1 -0
diff -r 6997a436e0ed tools/libxl/xl_cmdimpl.h
@@ -55,6 +55,7 @@
 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);
 
 void help(char *command);
 
tools/libxl/xl_cmdtable.c +6 -0
diff -r 6997a436e0ed tools/libxl/xl_cmdtable.c
@@ -242,6 +242,12 @@
       "[<Domain>|-a]",
       "  -a                             Destroy all tmem",
     },
+    { "tmem-thaw",
+      &main_tmem_thaw,
+      "Thaw tmem pools",
+      "[<Domain>|-a]",
+      "  -a                             Thaw all tmem",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#5 lore raw

PATCH 5/6 xl: Add 'xl tmem-set' command

In reply to Yang Hongyang

Add 'xl tmem-set' command

tools/libxl/libxl.c +32 -0
diff -r f5c579127b26 tools/libxl/libxl.c
@@ -2885,3 +2885,35 @@
 
     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;
+}
tools/libxl/libxl.h +2 -0
diff -r f5c579127b26 tools/libxl/libxl.h
@@ -517,5 +517,7 @@
 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);
 #endif /* LIBXL_H */
 
tools/libxl/xl_cmdimpl.c +61 -0

64 lines not on this page · raw message

tools/libxl/xl_cmdimpl.h +1 -0
diff -r f5c579127b26 tools/libxl/xl_cmdimpl.h
@@ -56,6 +56,7 @@
 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);
 
 void help(char *command);
 
tools/libxl/xl_cmdtable.c +9 -0
diff -r f5c579127b26 tools/libxl/xl_cmdtable.c
@@ -248,6 +248,15 @@
       "[<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)",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#6 lore raw

PATCH 6/6 xl: Add 'xl tmem-shared-auth' command

In reply to Yang Hongyang

Add 'xl tmem-shared-auth' command

tools/libxl/libxl.c +16 -0
diff -r d432ff60f69d tools/libxl/libxl.c
@@ -2917,3 +2917,19 @@
 
     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;
+}
+
tools/libxl/libxl.h +2 -0
diff -r d432ff60f69d tools/libxl/libxl.h
@@ -519,5 +519,7 @@
 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 */
 
tools/libxl/xl_cmdimpl.c +60 -0

63 lines not on this page · raw message

tools/libxl/xl_cmdimpl.h +1 -0
diff -r d432ff60f69d tools/libxl/xl_cmdimpl.h
@@ -57,6 +57,7 @@
 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);
 
tools/libxl/xl_cmdtable.c +9 -0
diff -r d432ff60f69d tools/libxl/xl_cmdtable.c
@@ -257,6 +257,15 @@
       "  -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);
Signature · 2 lines
Regards
Yang Hongyang