@@ -209,6 +209,8 @@ int main_psr_cat_show(int argc, char **argv);
#endif
int main_qemu_monitor_command(int argc, char **argv);
+int main_lock(int argc, char **argv);
+
void help(const char *command);
extern const char *common_domname;
@@ -591,6 +591,11 @@ struct cmd_spec cmd_table[] = {
"Issue a qemu monitor command to the device model of a domain",
"<Domain> <Command>",
},
+ { "lock",
+ &main_lock, 0, 0,
+ "Lock a domain, prevent other xl processes from manipulating it",
+ "<Domain>",
+ },
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
@@ -14,6 +14,7 @@
#include <limits.h>
#include <stdlib.h>
+#include <unistd.h>
#include <libxl.h>
#include <libxl_utils.h>
@@ -344,6 +345,42 @@ int main_config_update(int argc, char **argv)
return 0;
}
+struct lock_arg {
+ uint32_t domid;
+};
+
+static int lock_fn(void *p)
+{
+ struct lock_arg *arg = p;
+
+ fprintf(stderr, "Now I have the lock for %u\n", arg->domid);
+
+ sleep(10);
+
+ fprintf(stderr, "Done\n");
+
+ return 0;
+}
+
+int main_lock(int argc, char **argv)
+{
+ uint32_t domid;
+ struct lock_arg arg;
+ int rc;
+
+ domid = find_domain(argv[optind++]);
+
+ fprintf(stderr, "About to lock %u\n", domid);
+
+ arg.domid = domid;
+
+ rc = with_lock(domid, lock_fn, &arg);
+ fprintf(stderr, "with_lock returned, rc = %d\n", rc);
+ if (rc)
+ return EXIT_FAILURE;
+ return EXIT_SUCCESS;
+}
+
/*
* Local variables:
* mode: C
Signed-off-by: Wei Liu <wei.liu2@citrix.com> --- tools/xl/xl.h | 2 ++ tools/xl/xl_cmdtable.c | 5 +++++ tools/xl/xl_misc.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+)