Skip to contentSkip to conversation

libxl: prevent xl from running if xend is running.

PATCH Superseded Roger Pau Monne 2 participants 4 messages Apr 25, 2012 – May 14, 2012

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 libxl: prevent xl from running if xend is running.

Prevent xl from doing any operation if xend daemon is running. That prevents bugs that happened when xl and xend raced to close a domain.

Changes since v2:

* Allow to dry run even if xend is running.

* Refresh to apply to current tree.

Changes since v1:

* Add documentation to xl man page.

* Permit the execution of commands that don't modify anything.

* Indent error message.

---
 docs/man/xl.pod.1         |    6 ++
 tools/libxl/xl.c          |   22 +++++++-
 tools/libxl/xl.h          |    1 +
 tools/libxl/xl_cmdimpl.c  |    5 +-
 tools/libxl/xl_cmdtable.c |  132 ++++++++++++++++++++++----------------------
 5 files changed, 97 insertions(+), 69 deletions(-)
docs/man/xl.pod.1 +6 -0
index e5324fb..e829697 100644
@@ -75,6 +75,12 @@ Verbose.
 
 Dry run: do not actually execute the command.
 
+=item B<-f>
+
+Force execution: xl will refuse to run some commands if it detects that xend is
+also running, this option will force the execution of those commands, even
+though it is unsafe.
+
 =back
 
 =head1 DOMAIN SUBCOMMANDS
tools/libxl/xl.c +21 -1
index a6ffd25..51369fd 100644
@@ -32,8 +32,11 @@
 #include "libxlutil.h"
 #include "xl.h"
 
+#define XEND_LOCK { "/var/lock/subsys/xend", "/var/lock/xend" }
+
 xentoollog_logger_stdiostream *logger;
 int dryrun_only;
+int force_execution;
 int autoballoon = 1;
 char *lockfile;
 char *default_vifscript = NULL;
@@ -114,8 +117,9 @@ int main(int argc, char **argv)
     char *config_file;
     void *config_data = 0;
     int config_len = 0;
+    const char *locks[] = XEND_LOCK;
 
-    while ((opt = getopt(argc, argv, "+vN")) >= 0) {
+    while ((opt = getopt(argc, argv, "+vfN")) >= 0) {
         switch (opt) {
         case 'v':
             if (minmsglevel > 0) minmsglevel--;
@@ -123,6 +127,9 @@ int main(int argc, char **argv)
         case 'N':
             dryrun_only = 1;
             break;
+        case 'f':
+            force_execution = 1;
+            break;
         default:
             fprintf(stderr, "unknown global option\n");
             exit(2);
@@ -173,6 +180,19 @@ int main(int argc, char **argv)
             ret = 1;
             goto xit;
         }
+        if (cspec->modifies && !dryrun_only) {
+            for (int i = 0; i < sizeof(locks)/sizeof(locks[0]); i++) {
+                if (!access(locks[i], F_OK) && !force_execution) {
+                    fprintf(stderr,
+"xend is running, which prevents xl from working correctly.\n"
+"If you still want to force the execution of xl please use the -f\n"
+"option.\n"
+                            );
+                    ret = 1;
+                    goto xit;
+                }
+            }
+        }
         ret = cspec->cmd_impl(argc, argv);
     } else if (!strcmp(cmd, "help")) {
         help(argv[1]);
tools/libxl/xl.h +1 -0
index 7e258d5..8c0823f 100644
@@ -21,6 +21,7 @@ struct cmd_spec {
     char *cmd_name;
     int (*cmd_impl)(int argc, char **argv);
     int can_dryrun;
+    int modifies;
     char *cmd_desc;
     char *cmd_usage;
     char *cmd_option;
tools/libxl/xl_cmdimpl.c +3 -2
index 5703512..085ec80 100644
@@ -1905,7 +1905,7 @@ void help(const char *command)
     struct cmd_spec *cmd;
 
     if (!command || !strcmp(command, "help")) {
-        printf("Usage xl [-vN] <subcommand> [args]\n\n");
+        printf("Usage xl [-vfN] <subcommand> [args]\n\n");
         printf("xl full list of subcommands:\n\n");
         for (i = 0; i < cmdtable_len; i++) {
             printf(" %-19s ", cmd_table[i].cmd_name);
@@ -1916,7 +1916,8 @@ void help(const char *command)
     } else {
         cmd = cmdtable_lookup(command);
         if (cmd) {
-            printf("Usage: xl [-v%s] %s %s\n\n%s.\n\n",
+            printf("Usage: xl [-v%s%s] %s %s\n\n%s.\n\n",
+                   cmd->modifies ? "f" : "",
                    cmd->can_dryrun ? "N" : "",
                    cmd->cmd_name,
                    cmd->cmd_usage,
tools/libxl/xl_cmdtable.c +66 -66

439 lines not on this page · raw message

Signature · 1 line
1.7.7.5 (Apple Git-26)
Acked-by on v3 1/1
#1 lore raw

Roger Pau Monne writes ("[PATCH v3] libxl: prevent xl from running if xend is running."):

Quoted 2 lines

Prevent xl from doing any operation if xend daemon is running. That prevents bugs that happened when xl and xend raced to close a domain.

Acked-by on v3 1/1
#2 lore raw
In reply to Roger Pau Monne

Roger Pau Monne writes ("[Xen-devel] [PATCH v3] libxl: prevent xl from running if xend is running."):

Quoted 2 lines

Prevent xl from doing any operation if xend daemon is running. That prevents bugs that happened when xl and xend raced to close a domain.

Thanks,

I tried to apply this but I'm afraid it needs a refresh.

Ian.

#3 lore raw
Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v3] libxl: prevent xl from running if xend is running."):

Quoted 2 lines

Prevent xl from doing any operation if xend daemon is running. That prevents bugs that happened when xl and xend raced to close a domain.

Thanks,

I tried to apply this but I'm afraid it needs a refresh.

Ok, I've updated it and resend, but I'm afraid I've forgot to add the Ack, sorry about that.