Skip to contentSkip to conversation

xl: Add "xl rename" command

PATCH In review Yang Hongyang 3 participants 4 messages May 7, 2010 – May 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 xl: Add "xl rename" command

Hi Keir, Stefano,

It's based on my previous 2 patchs: Add "xl domid" command / Add "xl domname" command

==========================================================

Add "xl rename" command, a clone of "xm rename".

tools/libxl/xl_cmdimpl.c +45 -0
diff -r 357eab43f7ee -r 636a21458395 tools/libxl/xl_cmdimpl.c
@@ -1227,6 +1227,9 @@
     } else if (!strcmp(command, "domname")) {
         printf("Usage: xl domname <DomainId>\n\n");
         printf("Convert a domain id to domain name.\n");
+    } else if (!strcmp(command, "rename")) {
+        printf("Usage: xl rename <Domain> <NewDomainName>\n\n");
+        printf("Rename a domain.\n");
     }
 }
 
@@ -3024,3 +3027,45 @@
 
     exit(0);
 }
+
+int main_rename(int argc, char **argv)
+{
+    int opt;
+    char *dom;
+    char *new_name;
+    xs_transaction_t t;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("rename");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    dom = argv[optind++];
+    if (!dom || !argv[optind]) {
+        fprintf(stderr, "'xl rename' requires 2 arguments.\n\n");
+        help("rename");
+        exit(1);
+    }
+
+    find_domain(dom);
+    new_name = argv[optind];
+
+retry_transaction:
+    t = xs_transaction_start(ctx.xsh);
+    if (libxl_domain_rename(&ctx, domid, common_domname, new_name, t)) {
+        fprintf(stderr, "Can't rename domain '%s'.\n", dom);
+        exit(1);
+    }
+
+    if (!xs_transaction_end(ctx.xsh, t, 0))
+        if (errno == EAGAIN)
+            goto retry_transaction;
+
+    exit(0);
+}
tools/libxl/xl_cmdimpl.h +1 -0
diff -r 357eab43f7ee -r 636a21458395 tools/libxl/xl_cmdimpl.h
@@ -37,5 +37,6 @@
 int main_sched_credit(int argc, char **argv);
 int main_domid(int argc, char **argv);
 int main_domname(int argc, char **argv);
+int main_rename(int argc, char **argv);
 
 void help(char *command);
tools/libxl/xl_cmdtable.c +1 -0
diff -r 357eab43f7ee -r 636a21458395 tools/libxl/xl_cmdtable.c
@@ -38,6 +38,7 @@
     { "sched-credit", &main_sched_credit, "get/set credit scheduler parameters" },
     { "domid", &main_domid, "convert a domain name to domain id"},
     { "domname", &main_domname, "convert a domain id to domain name"},
+    { "rename", &main_rename, "rename a domain"},
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 2 lines
Regards
Yang Hongyang
#1 lore raw
Quoted 59 lines · Yang Hongyang

Hi Keir, Stefano,

It's based on my previous 2 patchs: Add "xl domid" command / Add "xl domname" command

==========================================================

Add "xl rename" command, a clone of "xm rename".

diff -r 357eab43f7ee -r 636a21458395 tools/libxl/xl_cmdimpl.c

tools/libxl/xl_cmdimpl.c +35 -0
@@ -1227,6 +1227,9 @@
     } else if (!strcmp(command, "domname")) {
         printf("Usage: xl domname <DomainId>\n\n");
         printf("Convert a domain id to domain name.\n");
+    } else if (!strcmp(command, "rename")) {
+        printf("Usage: xl rename <Domain> <NewDomainName>\n\n");
+        printf("Rename a domain.\n");
     }
 }
 
@@ -3024,3 +3027,45 @@
 
     exit(0);
 }
+
+int main_rename(int argc, char **argv)
+{
+    int opt;
+    char *dom;
+    char *new_name;
+    xs_transaction_t t;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("rename");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    dom = argv[optind++];
+    if (!dom || !argv[optind]) {
+        fprintf(stderr, "'xl rename' requires 2 arguments.\n\n");
+        help("rename");
+        exit(1);
+    }
+
+    find_domain(dom);
+    new_name = argv[optind];
+
+retry_transaction:
+    t = xs_transaction_start(ctx.xsh);
+    if (libxl_domain_rename(&ctx, domid, common_domname, new_name, t)) {

tools/libxl/xl_cmdimpl.c line 3071

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +10 -0
+        fprintf(stderr, "Can't rename domain '%s'.\n", dom);
+        exit(1);
+    }
+
+    if (!xs_transaction_end(ctx.xsh, t, 0))
+        if (errno == EAGAIN)
+            goto retry_transaction;
+
+    exit(0);
+}

There is no need to explicitly handle the transaction here, just pass 0 to libxl_domain_rename.
In the near future libxl_domain_rename won't take a transaction anymore (libxl clients shouldn't know about xenstore).

#2 lore raw
Quoted 68 lines · On Friday 07 May 2010 17:45:25 Stefano Stabellini wrote:
Quoted 67 lines · Yang Hongyang

Hi Keir, Stefano,

It's based on my previous 2 patchs: Add "xl domid" command / Add "xl domname" command

==========================================================

Add "xl rename" command, a clone of "xm rename".

diff -r 357eab43f7ee -r 636a21458395 tools/libxl/xl_cmdimpl.c

tools/libxl/xl_cmdimpl.c +42 -0
@@ -1227,6 +1227,9 @@
     } else if (!strcmp(command, "domname")) {
         printf("Usage: xl domname <DomainId>\n\n");
         printf("Convert a domain id to domain name.\n");
+    } else if (!strcmp(command, "rename")) {
+        printf("Usage: xl rename <Domain> <NewDomainName>\n\n");
+        printf("Rename a domain.\n");
     }
 }
 
@@ -3024,3 +3027,45 @@
 
     exit(0);
 }
+
+int main_rename(int argc, char **argv)
+{
+    int opt;
+    char *dom;
+    char *new_name;
+    xs_transaction_t t;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("rename");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    dom = argv[optind++];
+    if (!dom || !argv[optind]) {
+        fprintf(stderr, "'xl rename' requires 2 arguments.\n\n");
+        help("rename");
+        exit(1);
+    }
+
+    find_domain(dom);
+    new_name = argv[optind];
+
+retry_transaction:
+    t = xs_transaction_start(ctx.xsh);
+    if (libxl_domain_rename(&ctx, domid, common_domname, new_name, t)) {
+        fprintf(stderr, "Can't rename domain '%s'.\n", dom);
+        exit(1);
+    }
+
+    if (!xs_transaction_end(ctx.xsh, t, 0))
+        if (errno == EAGAIN)
+            goto retry_transaction;
Quoted 8 lines

tools/libxl/xl_cmdimpl.c line 3046

Quoted 3 lines
tools/libxl/xl_cmdimpl.c +3 -0
+
+    exit(0);
+}

There is no need to explicitly handle the transaction here, just pass 0 to libxl_domain_rename.
In the near future libxl_domain_rename won't take a transaction anymore (libxl clients shouldn't know about xenstore).

Setting the domain name must be already implemented somewhere used by xl create.

I think, with these new commands there are some refactorings possible resulting in less fragmented code.

Christoph

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Andrew Bowd, Thomas M. McCoy, Giuliano Meroni
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#3 lore raw
In reply to Stefano Stabellini

Hi Stefano,

Quoted 67 lines · Stefano Stabellini
Quoted 66 lines · Yang Hongyang

Hi Keir, Stefano,

It's based on my previous 2 patchs: Add "xl domid" command / Add "xl domname" command

==========================================================

Add "xl rename" command, a clone of "xm rename".

diff -r 357eab43f7ee -r 636a21458395 tools/libxl/xl_cmdimpl.c

tools/libxl/xl_cmdimpl.c +42 -0
@@ -1227,6 +1227,9 @@
     } else if (!strcmp(command, "domname")) {
         printf("Usage: xl domname <DomainId>\n\n");
         printf("Convert a domain id to domain name.\n");
+    } else if (!strcmp(command, "rename")) {
+        printf("Usage: xl rename <Domain> <NewDomainName>\n\n");
+        printf("Rename a domain.\n");
     }
 }
 
@@ -3024,3 +3027,45 @@
 
     exit(0);
 }
+
+int main_rename(int argc, char **argv)
+{
+    int opt;
+    char *dom;
+    char *new_name;
+    xs_transaction_t t;
+
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("rename");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    dom = argv[optind++];
+    if (!dom || !argv[optind]) {
+        fprintf(stderr, "'xl rename' requires 2 arguments.\n\n");
+        help("rename");
+        exit(1);
+    }
+
+    find_domain(dom);
+    new_name = argv[optind];
+
+retry_transaction:
+    t = xs_transaction_start(ctx.xsh);
+    if (libxl_domain_rename(&ctx, domid, common_domname, new_name, t)) {
+        fprintf(stderr, "Can't rename domain '%s'.\n", dom);
+        exit(1);
+    }
+
+    if (!xs_transaction_end(ctx.xsh, t, 0))
+        if (errno == EAGAIN)
+            goto retry_transaction;
Quoted 10 lines

tools/libxl/xl_cmdimpl.c line 3046

Quoted 3 lines
tools/libxl/xl_cmdimpl.c +3 -0
+
+    exit(0);
+}

There is no need to explicitly handle the transaction here, just pass 0 to libxl_domain_rename.
In the near future libxl_domain_rename won't take a transaction anymore (libxl clients shouldn't know about xenstore).

I will send a patch to fix it.

Quoted 2 lines
Signature · 2 lines
Regards
Yang Hongyang