[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC PATCH 3/4] xl: introduce facility to run function with per-domain lock held



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/xl/xl.h       |  1 +
 tools/xl/xl_utils.c | 19 +++++++++++++++++++
 tools/xl/xl_utils.h |  3 +++
 3 files changed, 23 insertions(+)

diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index 93ec4d7e4c..8d667ff444 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -292,6 +292,7 @@ extern void printf_info_sexp(int domid, libxl_domain_config 
*d_config, FILE *fh)
 
 #define XL_GLOBAL_CONFIG XEN_CONFIG_DIR "/xl.conf"
 #define XL_LOCK_FILE XEN_LOCK_DIR "/xl"
+#define XL_DOMAIN_LOCK_FILE_FMT XEN_LOCK_DIR "/xl-%u"
 
 #endif /* XL_H */
 
diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c
index e7038ec324..bb32ba0a1f 100644
--- a/tools/xl/xl_utils.c
+++ b/tools/xl/xl_utils.c
@@ -27,6 +27,25 @@
 #include "xl.h"
 #include "xl_utils.h"
 
+int with_lock(uint32_t domid, domain_fn fn, void *arg)
+{
+    char filename[sizeof(XL_DOMAIN_LOCK_FILE_FMT)+15];
+    int fd_lock = -1;
+    int rc;
+
+    snprintf(filename, sizeof(filename), XL_DOMAIN_LOCK_FILE_FMT, domid);
+
+    rc = acquire_lock(filename, &fd_lock);
+    if (rc) goto out;
+
+    rc = fn(arg);
+
+    release_lock(filename, &fd_lock);
+
+out:
+    return rc;
+}
+
 void dolog(const char *file, int line, const char *func, char *fmt, ...)
 {
     va_list ap;
diff --git a/tools/xl/xl_utils.h b/tools/xl/xl_utils.h
index 18280d7e84..5e0d502fa6 100644
--- a/tools/xl/xl_utils.h
+++ b/tools/xl/xl_utils.h
@@ -149,6 +149,9 @@ int do_daemonize(char *name, const char *pidfile);
 
 int acquire_lock(const char *lockfile, int *fd_lock);
 int release_lock(const char *lockfile, int *fd_lock);
+
+typedef int (*domain_fn)(void *arg);
+int with_lock(uint32_t domid, domain_fn fn, void *arg);
 #endif /* XL_UTILS_H */
 
 /*
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.