Skip to contentSkip to conversation

New event API

RFC PATCH Superseded Ian Jackson 6 participants 52 messages Oct 28, 2011 – Nov 29, 2011 Licenses and spdx stuff

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover New event API

This is a revised RFC version of my event handling API proposal.

It consists of 10 rather uninteresting preparatory, stylistic and bugfix patches, plus 3 with some meat in:

  02/13  libxenstore: Provide xs_check_watch
  12/13  libxl: New API for providing OS events to libxl
  13/13  libxl: New event generation API

This series contains an implementation of almost everything, and builds apart from the lack of libxl_event_free, but it has not been executed at all.

So at this stage a very detailed code review, particularly of 12 and 13 is probably not appropriate. However, this is hopefully a near-final version of the external and internal interfaces so it would be worth looking at those.

#1 lore raw

RFC PATCH v2 1/13 libxl: Make libxl__xs_* more const-correct

Paths and values which are not modified by these functions should be declared as "const char *" not "char *".

---
 tools/libxl/libxl_internal.h |    9 +++++----
 tools/libxl/libxl_xshelp.c   |    9 +++++----
 2 files changed, 10 insertions(+), 8 deletions(-)
tools/libxl/libxl_internal.h +5 -4
index 2e26ac6..31adbc8 100644
@@ -181,18 +181,19 @@ _hidden char *libxl__dirname(libxl__gc *gc, const char *s);
 _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length);
 
 _hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
-                    char *dir, char **kvs);
+                             const char *dir, char **kvs);
 _hidden int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
-                   char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
+               const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
    /* Each fn returns 0 on success.
     * On error: returns -1, sets errno (no logging) */
 
 _hidden char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid);
    /* On error: logs, returns NULL, sets errno. */
 
-_hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path);
+_hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t,
+                             const char *path);
 _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
-                                   char *path, unsigned int *nb);
+                                   const char *path, unsigned int *nb);
    /* On error: returns NULL, sets errno (no logging) */
 
 /* from xl_dom */
tools/libxl/libxl_xshelp.c +5 -4
index e41f962..56a7c7b 100644
@@ -49,7 +49,7 @@ char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length)
 }
 
 int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
-                    char *dir, char *kvs[])
+                     const char *dir, char *kvs[])
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *path;
@@ -69,7 +69,7 @@ int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
 }
 
 int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
-                   char *path, const char *fmt, ...)
+                    const char *path, const char *fmt, ...)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *s;
@@ -87,7 +87,7 @@ int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
     return 0;
 }
 
-char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path)
+char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, const char *path)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *ptr;
@@ -113,7 +113,8 @@ char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid)
     return s;
 }
 
-char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsigned int *nb)
+char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
+                           const char *path, unsigned int *nb)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char **ret = NULL;
Signature · 1 line
1.7.2.5
#2 lore raw

RFC PATCH v2 2/13 libxenstore: Provide xs_check_watch

Event-driven programs want to wait until the xs_fileno triggers for reading, and then repeatedly call xs_check_watch.

Also xs_read_watch exposes a useless "num" out parameter, which should always (if things aren't going hideously wrong) be at least 2 and which the caller shouldn't be interested in. So xs_check_watch doesn't have one of those.

---
 tools/xenstore/xs.c |   89 ++++++++++++++++++++++++++++++++++++++++++++-------
 tools/xenstore/xs.h |   16 +++++++++
 2 files changed, 93 insertions(+), 12 deletions(-)
tools/xenstore/xs.c +77 -12
index c72ea83..96e4b7a 100644
@@ -132,7 +132,20 @@ struct xs_handle {
 
 #endif
 
-static int read_message(struct xs_handle *h);
+static int read_message(struct xs_handle *h, int nonblocking);
+
+static void setnonblock(int fd, int nonblock) {
+	int flags = fcntl(fd, F_GETFL);
+	if (flags == -1)
+		return;
+
+	if (nonblock)
+		flags |= O_NONBLOCK;
+	else
+		flags &= ~O_NONBLOCK;
+
+	fcntl(fd, F_SETFL, flags);
+}
 
 int xs_fileno(struct xs_handle *h)
 {
@@ -327,8 +340,16 @@ void xs_close(struct xs_handle* xsh)
 		xs_daemon_close(xsh);
 }
 
-static bool read_all(int fd, void *data, unsigned int len)
+static bool read_all(int fd, void *data, unsigned int len, int nonblocking)
+	/* With nonblocking, either reads either everything requested,
+	 * or nothing. */
 {
+	if (!len)
+		return true;
+
+	if (nonblocking)
+		setnonblock(fd, 1);
+
 	while (len) {
 		int done;
 
@@ -336,18 +357,31 @@ static bool read_all(int fd, void *data, unsigned int len)
 		if (done < 0) {
 			if (errno == EINTR)
 				continue;
-			return false;
+			goto out_false;
 		}
 		if (done == 0) {
 			/* It closed fd on us?  EBADF is appropriate. */
 			errno = EBADF;
-			return false;
+			goto out_false;
 		}
 		data += done;
 		len -= done;
+
+		if (nonblocking) {
+			setnonblock(fd, 0);
+			nonblocking = 0;
+		}
 	}
 
 	return true;
+
+out_false:
+	if (nonblocking) {
+		int e = errno;
+		setnonblock(fd, 0);
+		errno = e;
+	}
+	return false;
 }
 
 #ifdef XSTEST
@@ -376,7 +410,7 @@ static void *read_reply(
 	read_from_thread = read_thread_exists(h);
 
 	/* Read from comms channel ourselves if there is no reader thread. */
-	if (!read_from_thread && (read_message(h) == -1))
+	if (!read_from_thread && (read_message(h, 0) == -1))
 		return NULL;
 
 	mutex_lock(&h->reply_mutex);
@@ -695,7 +729,8 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)
  * Returns array of two pointers: path and token, or NULL.
  * Call free() after use.
  */
-char **xs_read_watch(struct xs_handle *h, unsigned int *num)
+static char **read_watch_internal(struct xs_handle *h, unsigned int *num,
+				  int nonblocking)
 {
 	struct xs_stored_msg *msg;
 	char **ret, *strings, c = 0;
@@ -709,14 +744,20 @@ char **xs_read_watch(struct xs_handle *h, unsigned int *num)
 	 * we haven't called xs_watch.	Presumably the application
 	 * will do so later; in the meantime we just block.
 	 */
-	while (list_empty(&h->watch_list) && h->fd != -1)
+	while (list_empty(&h->watch_list) && h->fd != -1) {
+		if (nonblocking) {
+			mutex_unlock(&h->watch_mutex);
+			errno = EAGAIN;
+			return 0;
+		}
 		condvar_wait(&h->watch_condvar, &h->watch_mutex);
+	}
 #else /* !defined(USE_PTHREAD) */
 	/* Read from comms channel ourselves if there are no threads
 	 * and therefore no reader thread. */
 
 	assert(!read_thread_exists(h)); /* not threadsafe but worth a check */
-	if ((read_message(h) == -1))
+	if ((read_message(h, nonblocking) == -1))
 		return NULL;
 
 #endif /* !defined(USE_PTHREAD) */
@@ -762,6 +803,24 @@ char **xs_read_watch(struct xs_handle *h, unsigned int *num)
 	return ret;
 }
 
+char **xs_check_watch(struct xs_handle *h)
+{
+	unsigned int num;
+	char **ret;
+	ret = read_watch_internal(h, &num, 1);
+	if (ret) assert(num >= 2);
+	return ret;
+}
+
+/* Find out what node change was on (will block if nothing pending).
+ * Returns array of two pointers: path and token, or NULL.
+ * Call free() after use.
+ */
+char **xs_read_watch(struct xs_handle *h, unsigned int *num)
+{
+	return read_watch_internal(h, num, 0);
+}
+
 /* Remove a watch on a node.
  * Returns false on failure (no watch on that node).
  */
@@ -942,11 +1001,17 @@ char *xs_debug_command(struct xs_handle *h, const char *cmd,
 			ARRAY_SIZE(iov), NULL);
 }
 
-static int read_message(struct xs_handle *h)
+static int read_message(struct xs_handle *h, int nonblocking)
 {
 	/* IMPORTANT: It is forbidden to call this function without
 	 * acquiring the request lock and checking that h->read_thr_exists
 	 * is false.  See "Lock discipline" in struct xs_handle, above. */
+
+	/* If nonblocking==1, this function will always read either
+	 * nothing, returning -1 and setting errno==EAGAIN, or we read
+	 * whole amount requested.  Ie as soon as we have the start of
+	 * the message we block until we get all of it.
+	 */
          
 	struct xs_stored_msg *msg = NULL;
 	char *body = NULL;
@@ -958,7 +1023,7 @@ static int read_message(struct xs_handle *h)
 	if (msg == NULL)
 		goto error;
 	cleanup_push(free, msg);
-	if (!read_all(h->fd, &msg->hdr, sizeof(msg->hdr))) { /* Cancellation point */
+	if (!read_all(h->fd, &msg->hdr, sizeof(msg->hdr), nonblocking)) { /* Cancellation point */
 		saved_errno = errno;
 		goto error_freemsg;
 	}
@@ -968,7 +1033,7 @@ static int read_message(struct xs_handle *h)
 	if (body == NULL)
 		goto error_freemsg;
 	cleanup_push(free, body);
-	if (!read_all(h->fd, body, msg->hdr.len)) { /* Cancellation point */
+	if (!read_all(h->fd, body, msg->hdr.len, 0)) { /* Cancellation point */
 		saved_errno = errno;
 		goto error_freebody;
 	}
@@ -1023,7 +1088,7 @@ static void *read_thread(void *arg)
 	struct xs_handle *h = arg;
 	int fd;
 
-	while (read_message(h) != -1)
+	while (read_message(h, 0) != -1)
 		continue;
 
 	/* An error return from read_message leaves the socket in an undefined
tools/xenstore/xs.h +16 -0
index 1cbe255..63f535d 100644
@@ -135,6 +135,22 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token);
 /* Return the FD to poll on to see if a watch has fired. */
 int xs_fileno(struct xs_handle *h);
 
+/* Check for node changes.  On success, returns a non-NULL pointer ret
+ * such that ret[0] and ret[1] are valid C strings, namely the
+ * triggering path (see docs/misc/xenstore.txt) and the token (from
+ * xs_watch).  On error return value is NULL setting errno.
+ * 
+ * Callers should, after xs_fileno has become readable, repeatedly
+ * call xs_check_watch until it returns NULL and sets errno to EAGAIN.
+ * (If the fd became readable, xs_check_watch is allowed to make it no
+ * longer show up as readable even if future calls to xs_check_watch
+ * will return more watch events.)
+ *
+ * After the caller is finished with the returned information it
+ * should be freed all in one go with free(ret).
+ */
+char **xs_check_watch(struct xs_handle *h);
+
 /* Find out what node change was on (will block if nothing pending).
  * Returns array containing the path and token. Use XS_WATCH_* to access these
  * elements. Call free() after use.
Signature · 1 line
1.7.2.5
#3 lore raw

RFC PATCH v2 3/13 libxl: Provide a version of bsd's queue.h as _libxl_list.h

We would like some linked list macros which are (a) well known to be sane and (b) typesafe. BSD's queue.h meets these criteria.

We also provide some simple perlery to arrange to add the libxl_ namespace prefix to the macros. This will allow us to #include _libxl_list.h in our public header file without clashing with anyone else who is also using another version of queue.h.

---
 COPYING                              |    8 +
 tools/libxl/Makefile                 |   10 +-
 tools/libxl/bsd-sys-queue-h-seddery  |   70 +++
 tools/libxl/external/README          |   13 +
 tools/libxl/external/bsd-queue.3     | 1044 ++++++++++++++++++++++++++++++++++
 tools/libxl/external/bsd-sys-queue.h |  637 +++++++++++++++++++++
 6 files changed, 1779 insertions(+), 3 deletions(-)
 create mode 100755 tools/libxl/bsd-sys-queue-h-seddery
 create mode 100644 tools/libxl/external/README
 create mode 100644 tools/libxl/external/bsd-queue.3
 create mode 100644 tools/libxl/external/bsd-sys-queue.h
COPYING +8 -0
index 07535ad..524542d 100644
@@ -18,6 +18,14 @@ GPLv2. See the FSF's definition of GPL compatibility:
 And how this applies to a range of open source licenses:
  http://www.gnu.org/licenses/license-list.html
 
+Additionally, the documentation file tools/libxl/external/bsd-queue.3
+has the 4-clause BSD licence.  It is present in the Xen source tree
+for reference purposes for people developing Xen.  It is not installed
+by "make install" and is bundled in the source only for convenience of
+distribution.  We do not intend that we or Xen users or distributors
+should make any reference to "features or use" of that manpage.
+
+
 Licensing Exceptions (the relaxed BSD-style license)
 ----------------------------------------------------
 
tools/libxl/Makefile +7 -3
index 51e5132..f23661a 100644
@@ -42,7 +42,7 @@ LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
 
-AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
+AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h
 AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c
 LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \
 	libxlu_disk_l.o libxlu_disk.o
@@ -55,7 +55,7 @@ $(XL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 $(XL_OBJS): CFLAGS += $(CFLAGS_libxenlight)
 
 testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight)
-testidl.c: libxl_types.idl gentest.py libxl.h
+testidl.c: libxl_types.idl gentest.py libxl.h $(AUTOINCS)
 	$(PYTHON) gentest.py libxl_types.idl testidl.c.new
 	mv testidl.c.new testidl.c
 
@@ -63,7 +63,7 @@ testidl.c: libxl_types.idl gentest.py libxl.h
 all: $(CLIENTS) libxenlight.so libxenlight.a libxlutil.so libxlutil.a \
 	$(AUTOSRCS) $(AUTOINCS)
 
-$(LIBXLU_OBJS): $(AUTOINCS)
+$(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS): $(AUTOINCS)
 
 %.c %.h: %.y
 	@rm -f $*.[ch]
@@ -81,6 +81,10 @@ _libxl_paths.h: genpath
 	rm -f [email protected]
 	$(call move-if-changed,[email protected],$@)
 
+_libxl_list.h: bsd-sys-queue-h-seddery external/bsd-sys-queue.h
+	perl ./$^ --prefix=libxl >[email protected]
+	$(call move-if-changed,[email protected],$@)
+
 libxl_paths.c: _libxl_paths.h
 
 libxl.h: _libxl_types.h
tools/libxl/bsd-sys-queue-h-seddery new file +70 -0

70 lines not on this page · raw message

tools/libxl/external/README new file +13 -0
new file mode 100644
index 0000000..f3a3ac4
@@ -0,0 +1,13 @@
+WARNING - DO NOT EDIT THINGS IN THIS DIRECTORY (apart from this README)
+-----------------------------------------------------------------------
+
+These files were obtained elsewhere and should only be updated by
+copying new versions from the source location, as documented below:
+
+bsd-sys-queue.h
+bsd-queue.3
+
+  Obtained from the FreeBSD SVN using the following commands:
+    svn co -r 221843 svn://svn.freebsd.org/base/head/sys/sys/
+    svn co -r 221843 svn://svn.freebsd.org/base/head/share/man/man3
+
tools/libxl/external/bsd-queue.3 new file +1044 -0

1,044 lines not on this page · raw message

tools/libxl/external/bsd-sys-queue.h new file +637 -0

637 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#4 lore raw

RFC PATCH v2 4/13 libxl: idl: support new "c_only" type attribute

This provides for fields in libxl datatypes which are only present in the C version of structures. This is useful, for example, when a libxl datatype wants to contain fields which are used by libxl internally and which are only present in the structure to avoid additional memory allocation inconvenience.

---
 tools/libxl/gentest.py    |    2 ++
 tools/libxl/libxltypes.py |    4 +++-
 2 files changed, 5 insertions(+), 1 deletions(-)
tools/libxl/gentest.py +2 -0
index 6697ac5..ed5358d 100644
@@ -56,6 +56,8 @@ def gen_rand_init(ty, v, indent = "    ", parent = None):
         s += "%s = rand() %% 2;\n" % v
     elif ty.typename in ["char *"]:
         s += "%s = rand_str();\n" % v
+    elif ty.c_only:
+        pass
     elif ty.typename in handcoded:
         raise Exception("Gen for handcoded %s" % ty.typename)
     else:
tools/libxl/libxltypes.py +3 -1
index 05cba88..83a9426 100644
@@ -33,6 +33,8 @@ class Type(object):
         if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE]:
             raise ValueError
 
+        self.c_only = kwargs.setdefault('c_only', False)
+
         if typename is None: # Anonymous type
             self.typename = None
             self.rawname = None
@@ -50,7 +52,7 @@ class Type(object):
 
         self.autogenerate_destructor = kwargs.setdefault('autogenerate_destructor', True)
 
-        if self.typename is not None:
+        if self.typename is not None and not self.c_only:
             self.json_fn = kwargs.setdefault('json_fn', self.typename + "_gen_json")
         else:
             self.json_fn = kwargs.setdefault('json_fn', None)
Signature · 1 line
1.7.2.5
#5 lore raw

RFC PATCH v2 5/13 libxl: idl: Provide struct and union tags

Instead of generating:

   typedef struct {
     ...
   } libxl_foo;

Produce:

   typedef struct libxl_foo {
     ...
   } libxl_foo;

This makes it possible to refer to libxl idl-generated structs and unions, as incomplete types, before they have been defined.

---
 tools/libxl/gentypes.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/libxl/gentypes.py +1 -1
index e82b706..c4efbf3 100644
@@ -56,7 +56,7 @@ def libxl_C_type_define(ty, indent = ""):
         if ty.typename is None:
             s += "%s {\n" % ty.kind
         else:
-            s += "typedef %s {\n" % ty.kind
+            s += "typedef %s %s {\n" % (ty.kind, ty.typename)
 
         for f in ty.fields:
             if f.comment is not None:
Signature · 1 line
1.7.2.5
#6 lore raw

RFC PATCH v2 6/13 libxl: permit declaration after statement

GCC and C99 allow declarations to be mixed with code. This is a good idea because:

* It allows variables to be more often initialised as they are declared, thus reducing the occurrence of uninitialised variable errors.

* Certain alloca-like constructs (arrays allocated at runtime on the stack) can more often be written without a spurious { } block. Such blocks are confusing to read.

* It makes it easier to write and use macros which declare and initialise formulaic variables and do other function setup code, because there is no need to worry that such macros might be incompatible with each other or have strict ordering constraints.

---
 tools/libxl/Makefile |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tools/libxl/Makefile +2 -1
index f23661a..a3727ab 100644
@@ -11,7 +11,8 @@ MINOR = 0
 XLUMAJOR = 1.0
 XLUMINOR = 0
 
-CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations
+CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \
+	-Wno-declaration-after-statement
 CFLAGS += -I. -fPIC
 
 ifeq ($(CONFIG_Linux),y)
Signature · 1 line
1.7.2.5
#7 lore raw

RFC PATCH v2 7/13 libxl: internal convenience macros

Provide some macros which are useful shorthands for use within libxl:
* GC_INIT to initialise a gc from a ctx and GC_FREE to free it
* CTX(gc) to give you back the ctx
* LIBXL_TAILQ_INSERT_SORTED for inserting things into sorted lists

These will be used by later patches.

---
 tools/libxl/libxl_internal.h |   48 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +48 -0
index 31adbc8..8649788 100644
@@ -555,6 +555,54 @@ _hidden void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj);
 
 _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s);
 
+
+/*
+ * Convenience macros.
+ */
+
+
+/*
+ * All of these assume (or define)
+ *    libxl__gc *gc;
+ * as a local variable.
+ */
+
+#define GC_INIT(ctx)  libxl__gc gc[1] = { LIBXL_INIT_GC(ctx) }
+#define GC_FREE       libxl__free_all(gc)
+#define CTX           libxl__gc_owner(gc)
+
+
+/*
+ * Inserts "elm_new" into the sorted list "head".
+ *
+ * "elm_search" must be a loop search variable of the same type as
+ * "elm_new".  "new_after_search_p" must be an expression which is
+ * true iff the element "elm_new" sorts after the element
+ * "elm_search".
+ *
+ * "search_body" can be empty, or some declaration(s) and statement(s)
+ * needed for "new_after_search_p".
+ */
+#define LIBXL_TAILQ_INSERT_SORTED(head, entry, elm_new, elm_search,     \
+                                  search_body, new_after_search_p)      \
+    do {                                                                \
+        for ((elm_search) = LIBXL_TAILQ_FIRST((head));                  \
+             (elm_search);                                              \
+             (elm_search) = LIBXL_TAILQ_NEXT((elm_search), entry)) {    \
+            search_body;                                                \
+            if (!(new_after_search_p))                                  \
+                break;                                                  \
+        }                                                               \
+        /* now elm_search is either the element before which we want    \
+         * to place elm_new, or NULL meaning we want to put elm_new at  \
+         * the end */                                                   \
+        if ((elm_search))                                               \
+            LIBXL_TAILQ_INSERT_BEFORE((elm_search), (elm_new), entry);  \
+        else                                                            \
+            LIBXL_TAILQ_INSERT_TAIL((head), (elm_new), entry);          \
+    } while(0)
+
+
 #endif
 
 /*
Signature · 1 line
1.7.2.5
#8 lore raw

RFC PATCH v2 8/13 libxl: Rationalise #includes

libxl_internal.h now #includes libxl.h and various system headers.

This
1. makes the order of header inclusion more predictable
2. explicitly allows libxl_internal.h to use objects defined in libxl.h
3. removes the need for individual files to include these headers

Also
- remove some unnecessary #includes of libxl_utils.h, flexarray.h, etc. in some libxl*.c files,
- include libxl_osdeps.h at the top of libxl_internal.h
- add missing includes of libxl_osdeps.h to a couple of files
- change libxl.h to libxl_internal.h in a couple of files

---
 tools/libxl/libxl.c            |    3 ---
 tools/libxl/libxl_blktap2.c    |    1 -
 tools/libxl/libxl_bootloader.c |    4 ----
 tools/libxl/libxl_cpuid.c      |    4 ----
 tools/libxl/libxl_create.c     |    4 +---
 tools/libxl/libxl_device.c     |    2 --
 tools/libxl/libxl_dm.c         |    4 +---
 tools/libxl/libxl_dom.c        |    1 -
 tools/libxl/libxl_exec.c       |    1 -
 tools/libxl/libxl_flask.c      |    3 ++-
 tools/libxl/libxl_internal.c   |    4 ----
 tools/libxl/libxl_internal.h   |    5 +++++
 tools/libxl/libxl_json.c       |    4 ++--
 tools/libxl/libxl_noblktap2.c  |    2 --
 tools/libxl/libxl_nocpuid.c    |    2 +-
 tools/libxl/libxl_paths.c      |    2 +-
 tools/libxl/libxl_pci.c        |    5 -----
 tools/libxl/libxl_qmp.c        |    2 ++
 tools/libxl/libxl_utils.c      |    1 -
 tools/libxl/libxl_uuid.c       |    4 ++++
 tools/libxl/libxl_xshelp.c     |    1 -
 21 files changed, 19 insertions(+), 40 deletions(-)
tools/libxl/libxl.c +0 -3
index 064fbc4..5d448af 100644
@@ -31,10 +31,7 @@
 #include <inttypes.h>
 #include <assert.h>
 
-#include "libxl.h"
-#include "libxl_utils.h"
 #include "libxl_internal.h"
-#include "flexarray.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 #define BACKEND_STRING_SIZE 5
tools/libxl/libxl_blktap2.c +0 -1
index c8d9148..acf4110 100644
@@ -12,7 +12,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
 #include "libxl_osdeps.h"
 #include "libxl_internal.h"
 
tools/libxl/libxl_bootloader.c +0 -4
index 1e735a8..396aac6 100644
@@ -14,7 +14,6 @@
 
 #include "libxl_osdeps.h"
 
-#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <termios.h>
@@ -22,11 +21,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
-#include "flexarray.h"
-
 #define XENCONSOLED_BUF_SIZE 16
 #define BOOTLOADER_BUF_SIZE 1024
 
tools/libxl/libxl_cpuid.c +0 -4
index 12cc0b1..f65a898 100644
@@ -10,10 +10,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include <string.h>
-
-#include "libxl.h"
-#include "libxl_osdeps.h"
 #include "libxl_internal.h"
 
 void libxl_cpuid_destroy(libxl_cpuid_policy_list *p_cpuid_list)
tools/libxl/libxl_create.c +1 -3
index 68d0fc3..70705af 100644
@@ -26,10 +26,8 @@
 #include <xc_dom.h>
 #include <xenguest.h>
 #include <assert.h>
-#include "libxl.h"
-#include "libxl_utils.h"
+
 #include "libxl_internal.h"
-#include "flexarray.h"
 
 void libxl_domain_config_destroy(libxl_domain_config *d_config)
 {
tools/libxl/libxl_device.c +0 -2
index 88cd990..8b5fc4a 100644
@@ -24,8 +24,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-
-#include "libxl.h"
 #include "libxl_internal.h"
 
 static const char *string_of_kinds[] = {
tools/libxl/libxl_dm.c +1 -3
index d6ad85b..e18bac7 100644
@@ -24,10 +24,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <assert.h>
-#include "libxl_utils.h"
+
 #include "libxl_internal.h"
-#include "libxl.h"
-#include "flexarray.h"
 
 static const char *libxl_tapif_script(libxl__gc *gc)
 {
tools/libxl/libxl_dom.c +0 -1
index 718281a..430b3d0 100644
@@ -32,7 +32,6 @@
 
 #include <xen/hvm/hvm_info_table.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
tools/libxl/libxl_exec.c +0 -1
index d6199d4..e981679 100644
@@ -28,7 +28,6 @@
 #include <signal.h> /* for SIGKILL */
 #include <fcntl.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 static int call_waitpid(pid_t (*waitpid_cb)(pid_t, int *, int), pid_t pid, int *status, int options)
tools/libxl/libxl_flask.c +2 -1
index c8d0594..6b548dd 100644
@@ -7,13 +7,14 @@
  *  as published by the Free Software Foundation.
  */
 
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <xenctrl.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 int libxl_flask_context_to_sid(libxl_ctx *ctx, char *buf, size_t len,
tools/libxl/libxl_internal.c +0 -4
index 3993d8e..dd31f25 100644
@@ -16,8 +16,6 @@
 #include "libxl_osdeps.h"
 
 #include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -25,9 +23,7 @@
 #include <sys/mman.h>
 #include <unistd.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
-#include "libxl_utils.h"
 
 int libxl__error_set(libxl__gc *gc, int code)
 {
tools/libxl/libxl_internal.h +5 -0
index 8649788..6d9da2c 100644
@@ -17,14 +17,19 @@
 #ifndef LIBXL_INTERNAL_H
 #define LIBXL_INTERNAL_H
 
+#include "libxl_osdeps.h"
+
 #include <stdint.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <xs.h>
 #include <xenctrl.h>
 #include "xentoollog.h"
 
+#include "libxl.h"
+
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
 #define _hidden __attribute__((visibility("hidden")))
 #define _protected __attribute__((visibility("protected")))
tools/libxl/libxl_json.c +2 -2
index 11f65fc..a4208f3 100644
@@ -12,13 +12,13 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <assert.h>
-#include <string.h>
 
 #include <yajl/yajl_parse.h>
 #include <yajl/yajl_gen.h>
 
-#include <libxl.h>
 #include "libxl_internal.h"
 
 /* #define DEBUG_ANSWER */
tools/libxl/libxl_noblktap2.c +0 -2
index 704d03f..3307551 100644
@@ -12,8 +12,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
-#include "libxl_osdeps.h"
 #include "libxl_internal.h"
 
 int libxl__blktap_enabled(libxl__gc *gc)
tools/libxl/libxl_nocpuid.c +1 -1
index d63757f..2e9490c 100644
@@ -10,7 +10,7 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
+#include "libxl_internal.h"
 
 void libxl_cpuid_destroy(libxl_cpuid_policy_list *p_cpuid_list)
 {
tools/libxl/libxl_paths.c +1 -1
index 64f662d..fa80056 100644
@@ -12,7 +12,7 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
+#include "libxl_internal.h"
 #include "_libxl_paths.h"
 
 const char *libxl_sbindir_path(void)
tools/libxl/libxl_pci.c +0 -5
index 33dd060..9eac108 100644
@@ -17,7 +17,6 @@
 #include "libxl_osdeps.h"
 
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -27,15 +26,11 @@
 #include <sys/stat.h>
 #include <signal.h>
 #include <unistd.h> /* for write, unlink and close */
-#include <stdint.h>
 #include <inttypes.h>
 #include <dirent.h>
 #include <assert.h>
 
-#include "libxl.h"
-#include "libxl_utils.h"
 #include "libxl_internal.h"
-#include "flexarray.h"
 
 #define PCI_BDF                "%04x:%02x:%02x.%01x"
 #define PCI_BDF_SHORT          "%02x:%02x.%01x"
tools/libxl/libxl_qmp.c +2 -0
index 618f20f..0eefe4d 100644
@@ -18,6 +18,8 @@
  * Specification, see in the QEMU repository.
  */
 
+#include "libxl_osdeps.h"
+
 #include <unistd.h>
 #include <sys/un.h>
 #include <sys/queue.h>
tools/libxl/libxl_utils.c +0 -1
index dce9d8b..7ea2d2c 100644
@@ -28,7 +28,6 @@
 #include <unistd.h>
 #include <assert.h>
 
-#include "libxl_utils.h"
 #include "libxl_internal.h"
 
 struct schedid_name {
tools/libxl/libxl_uuid.c +4 -0
index e837228..80ab789 100644
@@ -12,8 +12,12 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <libxl_uuid.h>
 
+#include "libxl_internal.h"
+
 #if defined(__linux__)
 
 int libxl_uuid_is_nil(libxl_uuid *uuid)
tools/libxl/libxl_xshelp.c +0 -1
index 56a7c7b..f85e867 100644
@@ -21,7 +21,6 @@
 #include <stdarg.h>
 #include <inttypes.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length)
Signature · 1 line
1.7.2.5
#9 lore raw

RFC PATCH v2 9/13 libxl: introduce lock in libxl_ctx

This lock will be used to protect data structures which will be hung off the libxl_ctx in subsequent patches.

---
 tools/libxl/libxl.c          |    3 +++
 tools/libxl/libxl_internal.h |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +3 -0
index 5d448af..a3c9807 100644
@@ -40,6 +40,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
 {
     libxl_ctx *ctx;
     struct stat stat_buf;
+    const pthread_mutex_t mutex_value = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
     if (version != LIBXL_VERSION)
         return ERROR_VERSION;
@@ -53,6 +54,8 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
     memset(ctx, 0, sizeof(libxl_ctx));
     ctx->lg = lg;
 
+    memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));
+
     if ( stat(XENSTORE_PID_FILE, &stat_buf) != 0 ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Is xenstore daemon running?\n"
                      "failed to stat %s", XENSTORE_PID_FILE);
tools/libxl/libxl_internal.h +16 -0
index 6d9da2c..79a9de4 100644
@@ -23,6 +23,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 
 #include <xs.h>
 #include <xenctrl.h>
@@ -95,6 +96,9 @@ struct libxl__ctx {
     xc_interface *xch;
     struct xs_handle *xsh;
 
+    pthread_mutex_t lock; /* protects data structures hanging off the ctx */
+      /* always use MUTEX_LOCK and MUTEX_UNLOCK to manipulate this */
+
     /* for callers who reap children willy-nilly; caller must only
      * set this after libxl_init and before any other call - or
      * may leave them untouched */
@@ -577,6 +581,18 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s);
 #define CTX           libxl__gc_owner(gc)
 
 
+#define MUTEX_LOCK do {                                 \
+        int mutex_r = pthread_mutex_lock(&CTX->lock);   \
+        assert(!mutex_r);                               \
+    } while(0)
+
+#define MUTEX_UNLOCK do {                               \
+        int mutex_r = pthread_mutex_unlock(&CTX->lock); \
+        assert(!mutex_r);                               \
+    } while(0)
+        
+
+
 /*
  * Inserts "elm_new" into the sorted list "head".
  *
Signature · 1 line
1.7.2.5
#10 lore raw

RFC PATCH v2 10/13 libxl: make libxl__[v]log const-correct

---
 tools/libxl/libxl_internal.c |    4 ++--
 tools/libxl/libxl_internal.h |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl_internal.c +2 -2
index dd31f25..df2b7f8 100644
@@ -179,7 +179,7 @@ char *libxl__dirname(libxl__gc *gc, const char *s)
 
 void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
              const char *file, int line, const char *func,
-             char *fmt, va_list ap)
+             const char *fmt, va_list ap)
 {
     char *enomem = "[out of memory formatting log message]";
     char *base = NULL;
@@ -206,7 +206,7 @@ void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
 
 void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
             const char *file, int line, const char *func,
-            char *fmt, ...)
+            const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
tools/libxl/libxl_internal.h +2 -2
index 79a9de4..fe64d34 100644
@@ -80,13 +80,13 @@
 _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
              const char *file /* may be 0 */, int line /* ignored if !file */,
              const char *func /* may be 0 */,
-             char *fmt, va_list al)
+             const char *fmt, va_list al)
      __attribute__((format(printf,7,0)));
 
 _hidden void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
             const char *file /* may be 0 */, int line /* ignored if !file */,
             const char *func /* may be 0 */,
-            char *fmt, ...)
+            const char *fmt, ...)
      __attribute__((format(printf,7,8)));
 
      /* these functions preserve errno (saving and restoring) */
Signature · 1 line
1.7.2.5
#11 lore raw

RFC PATCH v2 11/13 libxl: make libxl__free_all idempotent

---
 tools/libxl/libxl_internal.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.c +2 -0
index df2b7f8..62e7fba 100644
@@ -72,6 +72,8 @@ void libxl__free_all(libxl__gc *gc)
         free(ptr);
     }
     free(gc->alloc_ptrs);
+    gc->alloc_ptrs = 0;
+    gc->alloc_maxsize = 0;
 }
 
 void *libxl__zalloc(libxl__gc *gc, int bytes)
Signature · 1 line
1.7.2.5
#12 lore raw

RFC PATCH v2 12/13 libxl: New API for providing OS events to libxl

We provide a new set of functions and related structures
libxl_osevent_*
which are to be used by event-driven applications to receive information from libxl about which fds libxl is interested in, and what timeouts libxl is waiting for, and to pass back to libxl information about which fds are readable/writeable etc., and which timeouts have occurred. Ie, low-level events.

In this patch, this new machinery is still all unused. Callers will appear in the next patch in the series, which introduces a new API for applications to receive high-level events about actual domains etc.

---
 tools/libxl/Makefile         |    2 +-
 tools/libxl/libxl.c          |   25 ++
 tools/libxl/libxl.h          |    6 +
 tools/libxl/libxl_event.c    |  704 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_event.h    |  185 +++++++++++
 tools/libxl/libxl_internal.h |  212 +++++++++++++-
 6 files changed, 1131 insertions(+), 3 deletions(-)
 create mode 100644 tools/libxl/libxl_event.c
 create mode 100644 tools/libxl/libxl_event.h
tools/libxl/Makefile +1 -1
index a3727ab..0680812 100644
@@ -38,7 +38,7 @@ LIBXL_LIBS += -lyajl
 LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
 			libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \
 			libxl_internal.o libxl_utils.o libxl_uuid.o libxl_json.o \
-			libxl_qmp.o $(LIBXL_OBJS-y)
+			libxl_qmp.o libxl_event.o $(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
tools/libxl/libxl.c +25 -0
index a3c9807..4d619ab 100644
@@ -56,6 +56,16 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
 
     memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));
 
+    ctx->osevent_hooks = 0;
+
+    ctx->fd_beforepolled = 0;
+    LIBXL_LIST_INIT(&ctx->efds);
+    LIBXL_TAILQ_INIT(&ctx->etimes);
+
+    ctx->watch_slots = 0;
+    LIBXL_SLIST_INIT(&ctx->watch_freeslots);
+    libxl__ev_fd_init(&ctx->watch_efd);
+
     if ( stat(XENSTORE_PID_FILE, &stat_buf) != 0 ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Is xenstore daemon running?\n"
                      "failed to stat %s", XENSTORE_PID_FILE);
@@ -85,10 +95,25 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
 
 int libxl_ctx_free(libxl_ctx *ctx)
 {
+    int i;
+    GC_INIT(ctx);
+
     if (!ctx) return 0;
+
+    for (i = 0; i < ctx->watch_nslots; i++)
+        assert(!libxl__watch_slot_contents(gc, i));
+    libxl__ev_fd_deregister(gc, &ctx->watch_efd);
+
+    assert(LIBXL_LIST_EMPTY(&ctx->efds));
+    assert(LIBXL_TAILQ_EMPTY(&ctx->etimes));
+
     if (ctx->xch) xc_interface_close(ctx->xch);
     libxl_version_info_destroy(&ctx->version_info);
     if (ctx->xsh) xs_daemon_close(ctx->xsh);
+
+    free(ctx->fd_beforepolled);
+    free(ctx->watch_slots);
+
     return 0;
 }
 
tools/libxl/libxl.h +6 -0
index 5d28ff9..da06ed2 100644
@@ -137,6 +137,7 @@
 #include <xen/sysctl.h>
 
 #include <libxl_uuid.h>
+#include <_libxl_list.h>
 
 typedef uint8_t libxl_mac[6];
 #define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
@@ -221,6 +222,9 @@ enum {
     ERROR_INVAL = -6,
     ERROR_BADFAIL = -7,
     ERROR_GUEST_TIMEDOUT = -8,
+    ERROR_NOT_READY = -9,
+    ERROR_OSEVENT_REG_FAIL = -10,
+    ERROR_BUFFERFULL = -11,
 };
 
 #define LIBXL_VERSION 0
@@ -539,6 +543,8 @@ const char *libxl_xen_script_dir_path(void);
 const char *libxl_lock_dir_path(void);
 const char *libxl_run_dir_path(void);
 
+#include <libxl_event.h>
+
 #endif /* LIBXL_H */
 
 /*
tools/libxl/libxl_event.c new file +704 -0

704 lines not on this page · raw message

tools/libxl/libxl_event.h new file +185 -0

185 lines not on this page · raw message

tools/libxl/libxl_internal.h +210 -2

252 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#13 lore raw

RFC PATCH v2 13/13 libxl: New event generation API

Replace the existing API for retrieving high-level events (events about domains, etc.) from libxl with a new one.

This changes the definition and semantics of the `libxl_event' structure, and replaces the calls for obtaining information about domain death and disk eject events.

This is an incompatible change, sorry. The alternative was to try to provide both the previous horrid API and the new one, and would also involve never using the name `libxl_event' for the new interface.

---
 tools/libxl/libxl.c          |  306 +++++++++++++++++++++++++++++------------
 tools/libxl/libxl.h          |   55 ++-------
 tools/libxl/libxl_event.c    |  182 +++++++++++++++++++++++---
 tools/libxl/libxl_event.h    |  172 +++++++++++++++++++++++
 tools/libxl/libxl_internal.c |    6 +
 tools/libxl/libxl_internal.h |   66 +++++++++
 tools/libxl/libxl_types.idl  |   35 ++++-
 tools/libxl/xl_cmdimpl.c     |  261 +++++++++++++++++++++---------------
 8 files changed, 815 insertions(+), 268 deletions(-)
tools/libxl/libxl.c +216 -90
index 4d619ab..701763e 100644
@@ -58,6 +58,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
 
     ctx->osevent_hooks = 0;
 
+    ctx->fd_polls = 0;
     ctx->fd_beforepolled = 0;
     LIBXL_LIST_INIT(&ctx->efds);
     LIBXL_TAILQ_INIT(&ctx->etimes);
@@ -66,6 +67,9 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
     LIBXL_SLIST_INIT(&ctx->watch_freeslots);
     libxl__ev_fd_init(&ctx->watch_efd);
 
+    LIBXL_TAILQ_INIT(&ctx->death_list);
+    libxl__ev_xswatch_init(&ctx->death_watch);
+
     if ( stat(XENSTORE_PID_FILE, &stat_buf) != 0 ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Is xenstore daemon running?\n"
                      "failed to stat %s", XENSTORE_PID_FILE);
@@ -93,6 +97,13 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
     return 0;
 }
 
+static void free_disable_deaths(libxl__gc *gc,
+                                struct libxl__evgen_domain_death_list *l) {
+    libxl_evgen_domain_death *death;
+    while ((death = LIBXL_TAILQ_FIRST(l)))
+        libxl__evdisable_domain_death(gc, death);
+}
+
 int libxl_ctx_free(libxl_ctx *ctx)
 {
     int i;
@@ -100,6 +111,9 @@ int libxl_ctx_free(libxl_ctx *ctx)
 
     if (!ctx) return 0;
 
+    free_disable_deaths(gc, &CTX->death_list);
+    free_disable_deaths(gc, &CTX->death_reported);
+
     for (i = 0; i < ctx->watch_nslots; i++)
         assert(!libxl__watch_slot_contents(gc, i));
     libxl__ev_fd_deregister(gc, &ctx->watch_efd);
@@ -111,6 +125,7 @@ int libxl_ctx_free(libxl_ctx *ctx)
     libxl_version_info_destroy(&ctx->version_info);
     if (ctx->xsh) xs_daemon_close(ctx->xsh);
 
+    free(ctx->fd_polls);
     free(ctx->fd_beforepolled);
     free(ctx->watch_slots);
 
@@ -610,117 +625,175 @@ int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, int req)
     return 0;
 }
 
-int libxl_get_wait_fd(libxl_ctx *ctx, int *fd)
-{
-    *fd = xs_fileno(ctx->xsh);
-    return 0;
-}
+static void domain_death_xswatch_callback(libxl__gc *gc, libxl__ev_xswatch *w,
+                                        const char *wpath, const char *epath) {
+    libxl_evgen_domain_death *evg;
+    uint32_t domid;
+    int rc;
 
-int libxl_wait_for_domain_death(libxl_ctx *ctx, uint32_t domid, libxl_waiter *waiter)
-{
-    waiter->path = strdup("@releaseDomain");
-    if (asprintf(&(waiter->token), "%d", LIBXL_EVENT_TYPE_DOMAIN_DEATH) < 0)
-        return -1;
-    if (!xs_watch(ctx->xsh, waiter->path, waiter->token))
-        return -1;
-    return 0;
-}
+    MUTEX_LOCK;
 
-int libxl_wait_for_disk_ejects(libxl_ctx *ctx, uint32_t guest_domid, libxl_device_disk *disks, int num_disks, libxl_waiter *waiter)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    int i, rc = -1;
-    uint32_t domid = libxl_get_stubdom_id(ctx, guest_domid);
+    evg = LIBXL_TAILQ_FIRST(&CTX->death_list);
+    if (!evg) goto out;
 
-    if (!domid)
-        domid = guest_domid;
+    domid = evg->domid;
 
-    for (i = 0; i < num_disks; i++) {
-        if (asprintf(&(waiter[i].path), "%s/device/vbd/%d/eject",
-                     libxl__xs_get_dompath(&gc, domid),
-                     libxl__device_disk_dev_number(disks[i].vdev,
-                                                   NULL, NULL)) < 0)
-            goto out;
-        if (asprintf(&(waiter[i].token), "%d", LIBXL_EVENT_TYPE_DISK_EJECT) < 0)
+    for (;;) {
+        int nentries = LIBXL_TAILQ_NEXT(evg, entry) ? 200 : 1;
+        xc_domaininfo_t domaininfos[nentries];
+        const xc_domaininfo_t *got = domaininfos, *gotend;
+
+        rc = xc_domain_getinfolist(CTX->xch, domid, nentries, domaininfos);
+        if (rc == -1) {
+            LIBXL__EVENT_DISASTER(gc, "xc_domain_getinfolist failed while"
+                                  " processing @releaseDomain watch event",
+                                  errno, 0);
             goto out;
-        xs_watch(ctx->xsh, waiter[i].path, waiter[i].token);
+        }
+        gotend = &domaininfos[rc];
+
+        for (;;) {
+            if (!evg)
+                goto all_reported;
+
+            if (!rc || got->domain > evg->domid) {
+                /* ie, the list doesn't contain evg->domid any more so
+                 * the domain has been destroyed */
+                libxl_evgen_domain_death *evg_next;
+
+                libxl_event *ev = NEW_EVENT(gc, DOMAIN_DESTROY, evg->domid);
+                if (!ev) goto out;
+
+                libxl__event_occurred(gc, ev);
+
+                evg->death_reported = 1;
+                evg_next = LIBXL_TAILQ_NEXT(evg, entry);
+                LIBXL_TAILQ_REMOVE(&CTX->death_list, evg, entry);
+                LIBXL_TAILQ_INSERT_HEAD(&CTX->death_reported, evg, entry);
+                evg = evg_next;
+
+                continue;
+            }
+            
+            if (got == gotend)
+                break;
+
+            if (got->domain < evg->domid) {
+                got++;
+                continue;
+            }
+
+            assert(evg->domid == got->domain);
+
+            if (!evg->shutdown_reported &&
+                (got->flags & XEN_DOMINF_shutdown)) {
+                libxl_event *ev = NEW_EVENT(gc, DOMAIN_SHUTDOWN, got->domain);
+                if (!ev) goto out;
+                
+                ev->u.domain_shutdown.shutdown_reason =
+                    (got->flags >> XEN_DOMINF_shutdownshift) &
+                    XEN_DOMINF_shutdownmask;
+                libxl__event_occurred(gc, ev);
+
+                evg->shutdown_reported = 1;
+            }
+            evg = LIBXL_TAILQ_NEXT(evg, entry);
+        }
+
+        assert(rc); /* rc==0 results in us eating all evgs and quitting */
+        domid = gotend[-1].domain;
     }
-    rc = 0;
-out:
-    libxl__free_all(&gc);
-    return rc;
+ all_reported:
+ out:
+
+    MUTEX_UNLOCK;
 }
 
-int libxl_get_event(libxl_ctx *ctx, libxl_event *event)
-{
-    unsigned int num;
-    char **events = xs_read_watch(ctx->xsh, &num);
-    if (num != 2) {
-        free(events);
-        return ERROR_FAIL;
+int libxl_evenable_domain_death(libxl_ctx *ctx, uint32_t domid,
+                libxl_ev_user user, libxl_evgen_domain_death **evgen_out) {
+    GC_INIT(ctx);
+    libxl_evgen_domain_death *evg, *evg_search;
+    int rc;
+    
+    MUTEX_LOCK;
+
+    evg = malloc(sizeof(*evg));  if (!evg) { rc = ERROR_NOMEM; goto out; }
+    memset(evg, 0, sizeof(*evg));
+    evg->domid = domid;
+    evg->user = user;
+
+    LIBXL_TAILQ_INSERT_SORTED(&ctx->death_list, entry, evg, evg_search, ,
+                              evg->domid > evg_search->domid);
+
+    if (!libxl__ev_xswatch_isregistered(&ctx->death_watch)) {
+        rc = libxl__ev_xswatch_register(gc, &ctx->death_watch,
+                        domain_death_xswatch_callback, "@releaseDomain");
+        if (rc) { libxl__evdisable_domain_death(gc, evg); goto out; }
     }
-    event->path = strdup(events[XS_WATCH_PATH]);
-    event->token = strdup(events[XS_WATCH_TOKEN]);
-    event->type = atoi(event->token);
-    free(events);
-    return 0;
-}
 
-int libxl_stop_waiting(libxl_ctx *ctx, libxl_waiter *waiter)
-{
-    if (!xs_unwatch(ctx->xsh, waiter->path, waiter->token))
-        return ERROR_FAIL;
-    else
-        return 0;
-}
+    rc = 0;
 
-int libxl_free_event(libxl_event *event)
-{
-    free(event->path);
-    free(event->token);
-    return 0;
-}
+ out:
+    MUTEX_UNLOCK;
+    return rc;
+};
 
-int libxl_free_waiter(libxl_waiter *waiter)
-{
-    free(waiter->path);
-    free(waiter->token);
-    return 0;
-}
+void libxl__evdisable_domain_death(libxl__gc *gc,
+                                   libxl_evgen_domain_death *evg) {
+    MUTEX_LOCK;
 
-int libxl_event_get_domain_death_info(libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_dominfo *info)
-{
-    if (libxl_domain_info(ctx, info, domid) < 0)
-        return 0;
+    if (!evg->death_reported)
+        LIBXL_TAILQ_REMOVE(&CTX->death_list, evg, entry);
+    else
+        LIBXL_TAILQ_REMOVE(&CTX->death_reported, evg, entry);
 
-    if (info->running || (!info->shutdown && !info->dying))
-        return ERROR_INVAL;
+    free(evg);
+
+    if (!LIBXL_TAILQ_FIRST(&CTX->death_list) &&
+        libxl__ev_xswatch_isregistered(&CTX->death_watch))
+        libxl__ev_xswatch_deregister(gc, &CTX->death_watch);
 
-    return 1;
+    MUTEX_UNLOCK;
 }
 
-int libxl_event_get_disk_eject_info(libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *path;
+void libxl_evdisable_domain_death(libxl_ctx *ctx,
+                                  libxl_evgen_domain_death *evg) {
+    GC_INIT(ctx);
+    libxl__evdisable_domain_death(gc, evg);
+    GC_FREE;
+}
+
+static void disk_eject_xswatch_callback(libxl__gc *gc, libxl__ev_xswatch *watch,
+                                        const char *wpath, const char *epath) {
+    libxl_evgen_domain_death *evg = (void*)watch;
+    int rc;
     char *backend;
     char *value;
     char backend_type[BACKEND_STRING_SIZE+1];
 
-    value = libxl__xs_read(&gc, XBT_NULL, event->path);
+    value = libxl__xs_read(gc, XBT_NULL, wpath);
 
-    if (!value || strcmp(value,  "eject")) {
-        libxl__free_all(&gc);
-        return 0;
+    if (!value || strcmp(value,  "eject"))
+        return;
+
+    rc = libxl__xs_write(gc, XBT_NULL, wpath, "");
+    if (rc) {
+        LIBXL__EVENT_DISASTER(gc, "xs_write failed acknowledging eject",
+                              errno, LIBXL_EVENT_TYPE_DISK_EJECT);
+        return;
     }
 
-    path = strdup(event->path);
-    path[strlen(path) - 6] = '\0';
-    backend = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend", path));
+    libxl_event *ev = NEW_EVENT(gc, DISK_EJECT, evg->domid);
+    libxl_device_disk *disk = &ev->u.disk_eject.disk;
+    
+    backend = libxl__xs_read(gc, XBT_NULL,
+                             libxl__sprintf(gc, "%.*s/backend",
+                                            (int)strlen(wpath)-6, wpath));
 
     sscanf(backend,
-            "/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE) "[a-z]/%*d/%*d",
-            &disk->backend_domid, backend_type);
+            "/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE)
+           "[a-z]/%*d/%*d",
+           &disk->backend_domid, backend_type);
     if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
         disk->backend = LIBXL_DISK_BACKEND_TAP;
     } else if (!strcmp(backend_type, "qdisk")) {
@@ -729,19 +802,72 @@ int libxl_event_get_disk_eject_info(libxl_ctx *ctx, uint32_t domid, libxl_event
         disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
     }
 
-    disk->pdev_path = strdup("");
+    disk->pdev_path = strdup(""); /* xxx fixme malloc failure */
     disk->format = LIBXL_DISK_FORMAT_EMPTY;
     /* this value is returned to the user: do not free right away */
-    disk->vdev = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/dev", backend), NULL);
+    disk->vdev = xs_read(CTX->xsh, XBT_NULL,
+                         libxl__sprintf(gc, "%s/dev", backend), NULL);
     disk->removable = 1;
     disk->readwrite = 0;
     disk->is_cdrom = 1;
 
-    free(path);
-    libxl__free_all(&gc);
-    return 1;
+    libxl__event_occurred(gc, ev);
 }
 
+int libxl_evenable_disk_eject(libxl_ctx *ctx, uint32_t guest_domid,
+                              const char *vdev, libxl_ev_user user,
+                              libxl_evgen_disk_eject **evgen_out) {
+    GC_INIT(ctx);
+    int rc;
+    char *path;
+    libxl_evgen_disk_eject *evg = NULL;
+
+    evg = malloc(sizeof(*evg));  if (!evg) { rc = ERROR_NOMEM; goto out; }
+    memset(evg, 0, sizeof(*evg));
+    evg->user = user;
+
+    evg->vdev = strdup(vdev);
+    if (!evg->vdev) { rc = ERROR_NOMEM; goto out; }
+
+    uint32_t domid = libxl_get_stubdom_id(ctx, guest_domid);
+    evg->domid = domid;
+
+    if (!domid)
+        domid = guest_domid;
+
+    path = libxl__sprintf(gc, "%s/device/vbd/%d/eject",
+                 libxl__xs_get_dompath(gc, domid),
+                 libxl__device_disk_dev_number(vdev, NULL, NULL));
+    if (!path) { rc = ERROR_NOMEM; goto out; }
+
+    rc = libxl__ev_xswatch_register(gc, &evg->watch,
+                                    disk_eject_xswatch_callback, path);
+    if (rc) goto out;
+
+    GC_FREE;
+    return 0;
+
+ out:
+    if (evg)
+        libxl__evdisable_disk_eject(gc, evg);
+    GC_FREE;
+    return rc;
+}
+
+void libxl__evdisable_disk_eject(libxl__gc *gc, libxl_evgen_disk_eject *evg) {
+    if (libxl__ev_xswatch_isregistered(&evg->watch))
+        libxl__ev_xswatch_deregister(gc, &evg->watch);
+
+    free(evg->vdev);
+    free(evg);
+}
+
+void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) {
+    GC_INIT(ctx);
+    libxl__evdisable_disk_eject(gc, evg);
+    GC_FREE;
+}    
+
 int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
tools/libxl/libxl.h +9 -46

79 lines not on this page · raw message

tools/libxl/libxl_event.c +166 -16

229 lines not on this page · raw message

tools/libxl/libxl_event.h +172 -0

178 lines not on this page · raw message

tools/libxl/libxl_internal.c +6 -0
index 62e7fba..202ba89 100644
@@ -74,6 +74,12 @@ void libxl__free_all(libxl__gc *gc)
     free(gc->alloc_ptrs);
     gc->alloc_ptrs = 0;
     gc->alloc_maxsize = 0;
+
+    libxl_event *ev, *ev_tmp;
+    LIBXL_TAILQ_FOREACH_SAFE(ev, &gc->occurred_for_callback, link, ev_tmp) {
+        LIBXL_TAILQ_REMOVE(&gc->occurred_for_callback, ev, link);
+        CTX->event_hooks->event_occurs(CTX->event_hooks_user, ev);
+    }
 }
 
 void *libxl__zalloc(libxl__gc *gc, int bytes)
tools/libxl/libxl_internal.h +66 -0

108 lines not on this page · raw message

tools/libxl/libxl_types.idl +30 -5
index 93fb8cd..53c07ee 100644
@@ -75,11 +75,6 @@ libxl_action_on_shutdown = Enumeration("action_on_shutdown", [
     (6, "COREDUMP_RESTART"),
     ])
 
-libxl_event_type = Enumeration("event_type", [
-    (1, "DOMAIN_DEATH"),
-    (2, "DISK_EJECT"),
-    ])
-
 libxl_button = Enumeration("button", [
     (1, "POWER"),
     (2, "SLEEP"),
@@ -374,3 +369,33 @@ libxl_sched_credit = Struct("sched_credit", [
     ("weight", integer),
     ("cap", integer),
     ], destructor_fn=None)
+
+libxl_event_type = Enumeration("event_type", [
+    (1, "DOMAIN_SHUTDOWN"),
+    (2, "DOMAIN_DESTROY"),
+    (3, "DISK_EJECT"),
+    ])
+
+libxl_ev_user = Number("libxl_ev_user")
+
+libxl_ev_link = Builtin("ev_link", passby=PASS_BY_REFERENCE, c_only=True)
+
+libxl_event = Struct("event",[
+    ("link",     libxl_ev_link,0,
+     "for use by libxl; caller may use this once the event has been"
+     " returned by libxl_event_{check,wait}"),
+    ("domid",    libxl_domid),
+    ("domuuid",  libxl_uuid),
+    ("for_user", libxl_ev_user),
+    ("type",     libxl_event_type),
+    ("u", KeyedUnion(None, libxl_event_type, "type",
+          [("domain_shutdown", Struct(None, [
+                                             ("shutdown_reason", uint8),
+                                      ])),
+           ("domain_destroy", Struct(None, [])),
+           ("disk_eject", Struct(None, [
+                                        ("vdev", string),
+                                        ("disk", libxl_device_disk),
+                                 ])),
+           ]))])
+
tools/libxl/xl_cmdimpl.c +150 -111

333 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#14 lore raw

Re: [PATCH RFC v2 13/13] libxl: New event generation API

I've not looked at this yet but CCing a few potential users of this interface. I've trimmed it to just the public header changes for their benefit, I'm sure they can find the full thing in the archive if they are interested in the gorey details.

Quoted 110 lines · Ian Jackson

Replace the existing API for retrieving high-level events (events about domains, etc.) from libxl with a new one.

This changes the definition and semantics of the `libxl_event' structure, and replaces the calls for obtaining information about domain death and disk eject events.

This is an incompatible change, sorry. The alternative was to try to provide both the previous horrid API and the new one, and would also involve never using the name `libxl_event' for the new interface.

---
 tools/libxl/libxl.c          |  306 +++++++++++++++++++++++++++++------------
 tools/libxl/libxl.h          |   55 ++-------
 tools/libxl/libxl_event.c    |  182 +++++++++++++++++++++++---
 tools/libxl/libxl_event.h    |  172 +++++++++++++++++++++++
 tools/libxl/libxl_internal.c |    6 +
 tools/libxl/libxl_internal.h |   66 +++++++++
 tools/libxl/libxl_types.idl  |   35 ++++-
 tools/libxl/xl_cmdimpl.c     |  261 +++++++++++++++++++++---------------
 8 files changed, 815 insertions(+), 268 deletions(-)
tools/libxl/libxl.h +9 -46
index da06ed2..4759c18 100644
@@ -53,7 +53,10 @@
  *    A public function may be called from within libxl; the call
  *    context initialisation macros will make sure that the internal
  *    caller's context is reused (eg, so that the same xenstore
- *    transaction is used).
+ *    transaction is used).  But in-libxl callers of libxl public
+ *    functions should note that any libxl public function may cause
+ *    recursively reentry into libxl via the application's event
+ *    callback hook.
  *
  *    Public functions have names like libxl_foobar.
  *
@@ -152,6 +155,8 @@ void libxl_key_value_list_destroy(libxl_key_value_list *kvl);
 
 typedef uint32_t libxl_hwcap[8];
 
+typedef uint64_t libxl_ev_user;
+
 typedef struct {
     uint32_t size;          /* number of bytes in map */
     uint8_t *map;
@@ -200,6 +205,9 @@ typedef struct {
     int v;
 } libxl_enum_string_table;
 
+struct libxl_event;
+typedef LIBXL_TAILQ_ENTRY(struct libxl_event) libxl_ev_link;
+
 typedef struct libxl__ctx libxl_ctx;
 
 #include "_libxl_types.h"
@@ -295,51 +303,6 @@ int libxl_run_bootloader(libxl_ctx *ctx,
 
   /* 0 means ERROR_ENOMEM, which we have logged */
 
-/* events handling */
-
-typedef struct {
-    /* event type */
-    libxl_event_type type;
-    /* data for internal use of the library */
-    char *path;
-    char *token;
-} libxl_event;
-
-typedef struct {
-    char *path;
-    char *token;
-} libxl_waiter;
-
-
-int libxl_get_wait_fd(libxl_ctx *ctx, int *fd);
-/* waiter is allocated by the caller */
-int libxl_wait_for_domain_death(libxl_ctx *ctx, uint32_t domid, libxl_waiter *waiter);
-/* waiter is a preallocated array of num_disks libxl_waiter elements */
-int libxl_wait_for_disk_ejects(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disks, int num_disks, libxl_waiter *waiter);
-int libxl_get_event(libxl_ctx *ctx, libxl_event *event);
-int libxl_stop_waiting(libxl_ctx *ctx, libxl_waiter *waiter);
-int libxl_free_event(libxl_event *event);
-int libxl_free_waiter(libxl_waiter *waiter);
-
-/*
- * Returns:
- *  - 0 if the domain is dead but there is no cleanup to be done. e.g
- *    because someone else has already done it.
- *  - 1 if the domain is dead and there is cleanup to be done.
- *
- * Can return error if the domain exists and is still running.
- *
- * *info will contain valid domain state iff 1 is returned. In
- * particular if 1 is returned then info->shutdown_reason is
- * guaranteed to be valid since by definition the domain is
- * (shutdown||dying))
- */
-int libxl_event_get_domain_death_info(libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_dominfo *info);
-
-/*
- * Returns true and fills *disk if the caller should eject the disk
- */
-int libxl_event_get_disk_eject_info(libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);
 
 int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
                         const char *old_name, const char *new_name);

[...]

Quoted 200 lines
tools/libxl/libxl_event.h +172 -0
index 48c6277..c52addc 100644
@@ -18,6 +18,178 @@
 
 #include <libxl.h>
 
+/*======================================================================*/
+
+/*
+ * Domain event handling - getting Xen events from libxl
+ */
+
+#define LIBXL_EVENTMASK_ALL (~(unsigned long)0)
+
+typedef int libxl_event_predicate(const libxl_event*, void *user);
+  /* Return value is 0 if the event is unwanted or non-0 if it is.
+   * Predicates are not allowed to fail.
+   */
+
+int libxl_event_check(libxl_ctx *ctx, libxl_event **event_r,
+                      unsigned long typemask,
+                      libxl_event_predicate *predicate, void *predicate_user);
+  /* Searches for an event, already-happened, which matches typemask
+   * and predicate.  predicate==0 matches any event.
+   * libxl_event_check returns the event, which must then later be
+   * freed by the caller using libxl_event_free.
+   *
+   * Returns ERROR_NOT_READY if no such event has happened.
+   */
+
+int libxl_event_wait(libxl_ctx *ctx, libxl_event **event_r,
+                     unsigned long typemask,
+                     libxl_event_predicate *predicate, void *predicate_user);
+  /* Like libxl_event_check but blocks if no suitable events are
+   * available, until some are.  Uses libxl_osevent_beforepoll/
+   * _afterpoll so may be inefficient if very many domains are being
+   * handled by a single program.
+   */
+
+int libxl_event_free(libxl_ctx *ctx, libxl_event *event);
+
+
+/* Alternatively or additionally, the application may also use this: */
+
+typedef struct libxl_event_hooks {
+    uint64_t event_occurs_mask;
+    void (*event_occurs)(void *user, const libxl_event *event);
+    void (*disaster)(void *user, libxl_event_type type,
+                     const char *msg, int errnoval);
+} libxl_event_hooks;
+
+void libxl_event_register_callbacks(libxl_ctx *ctx,
+                                    const libxl_event_hooks *hooks, void *user);
+  /*
+   * Arranges that libxl will henceforth call event_occurs for any
+   * events whose type is set in event_occurs_mask, rather than
+   * queueing the event for retrieval by libxl_event_check/wait.
+   * Events whose bit is clear in mask are not affected.
+   *
+   * event becomes owned by the application and must be freed, either
+   * by event_occurs or later.
+   *
+   * event_occurs may be NULL if mask is 0.
+   *
+   * libxl_event_register_callback also provides a way for libxl to
+   * report to the application that there was a problem reporting
+   * events; this can occur due to lack of host memory during event
+   * handling, or other wholly unrecoverable errors from system calls
+   * made by libxl.  This will not happen for frivolous reasons - only
+   * if the system, or the Xen components of it, are badly broken.
+   *
+   * msg and errnoval will describe the action that libxl was trying
+   * to do, and type specifies the type of libxl events which may be
+   * missing.  type may be 0 in which case events of all types may be
+   * missing.
+   *
+   * disaster may be NULL.  If it is, or if _register_callbacks has
+   * not been called, errors of this kind are fatal to the entire
+   * application: libxl will print messages to its logs and to stderr
+   * and call exit(-1).
+   *
+   * If disaster returns, it may be the case that some or all future
+   * libxl calls will return errors; likewise it may be the case that
+   * no more events (of the specified type, if applicable) can be
+   * produced.  An application which supplies a disaster function
+   * should normally react either by exiting, or by (when it has
+   * returned to its main event loop) shutting down libxl with
+   * libxl_ctx_free and perhaps trying to restart it with
+   * libxl_ctx_init.
+   *
+   * In any case before calling disaster, libxl will have logged a
+   * message with level XTL_CRITICAL.
+   *
+   * Reentrancy: it IS permitted to call libxl from within
+   * event_occurs.  It is NOT permitted to call libxl from within
+   * disaster.
+   *
+   * libxl_event_register_callbacks may be called as many times, with
+   * different parameters, as the application likes; the most recent
+   * call determines the libxl behaviour.  However it is NOT safe to
+   * call _register_callbacks concurrently with, or reentrantly from,
+   * any other libxl function.
+   *
+   * Calls to _register_callbacks do not affect events which have
+   * already occurred.
+   */
+
+
+/*
+ * Events are only generated if they have been requested.
+ * The following functions request the generation of specific events.
+ *
+ * Each set of functions for controlling event generation has this form:
+ *
+ *   typedef struct libxl__evgen_FOO libxl__evgen_FOO;
+ *   int libxl_evenable_FOO(libxl_ctx *ctx, FURTHER PARAMETERS,
+ *                          libxl_ev_user user, libxl__evgen_FOO **evgen_out);
+ *   void libxl_evdisable_FOO(libxl_ctx *ctx, libxl__evgen_FOO *evgen);
+ *
+ * The evenable function arranges that the events (as described in the
+ * doc comment for the individual function) will start to be generated
+ * by libxl.  On success, *evgen_out is set to a non-null pointer to
+ * an opaque struct.
+ *
+ * The user value is returned in the generated events and may be
+ * used by the caller for whatever it likes.  The type ev_user is
+ * guaranteed to be an unsigned integer type which is at least
+ * as big as uint64_t and is also guaranteed to be big enough to
+ * contain any intptr_t value.
+ *
+ * If it becomes desirable to stop generation of the relevant events,
+ * or to reclaim the resources in libxl associated with the evgen
+ * structure, the same evgen value should be passed to the evdisable
+ * function.  However, note that events which occurred prior to the
+ * evdisable call may still be returned.
+ *
+ * The caller may enable identical events more than once.  If they do
+ * so, each actual occurrence will generate several events to be
+ * returned by libxl_event_check, with the appropriate user value(s).
+ * Aside from this, each occurrence of each event is returned by
+ * libxl_event_check exactly once.
+ *
+ * An evgen is associated with the libxl_ctx used for its creation.
+ * After libxl_ctx_free, all corresponding evgen handles become
+ * invalid and must no longer be passed to evdisable.
+ *
+ * Events enabled with evenable prior to a fork and libxl_ctx_postfork
+ * are no longer generated after the fork/postfork; however the evgen
+ * structures are still valid and must be passed to evdisable if the
+ * memory they use should not be leaked.
+ *
+ * Applications should ensure that they eventually retrieve every
+ * event using libxl_event_check or libxl_event_wait, since events
+ * which occur but are not retreived by the application will be queued
+ * inside libxl indefinitely.  libxl_event_check/_wait may be O(n)
+ * where n is the number of queued events which do not match the
+ * criteria specified in the arguments to check/wait.
+ */
+
+typedef struct libxl__evgen_domain_death libxl_evgen_domain_death;
+int libxl_evenable_domain_death(libxl_ctx *ctx, uint32_t domid,
+                         libxl_ev_user, libxl_evgen_domain_death **evgen_out);
+void libxl_evdisable_domain_death(libxl_ctx *ctx, libxl_evgen_domain_death*);
+  /* Arranges for the generation of DOMAIN_SHUTDOWN and DOMAIN_DESTROY
+   * events.  A domain which is destroyed before it shuts down
+   * may generate only a DESTROY event.
+   */
+
+typedef struct libxl__evgen_disk_eject libxl_evgen_disk_eject;
+int libxl_evenable_disk_eject(libxl_ctx *ctx, uint32_t domid, const char *vdev,
+                        libxl_ev_user, libxl_evgen_disk_eject **evgen_out);
+void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject*);
+  /* Arranges for the generation of DISK_EJECT events.  A copy of the
+   * string *vdev will be made for libxl's internal use, and a pointer
+   * to this (or some other) copy will be returned as the vdev
+   * member of event.u.
+   */
+
 
 /*======================================================================*/
 
tools/libxl/libxl_internal.c +6 -0
index 62e7fba..202ba89 100644
@@ -74,6 +74,12 @@ void libxl__free_all(libxl__gc *gc)
     free(gc->alloc_ptrs);
     gc->alloc_ptrs = 0;
     gc->alloc_maxsize = 0;
+
+    libxl_event *ev, *ev_tmp;
+    LIBXL_TAILQ_FOREACH_SAFE(ev, &gc->occurred_for_callback, link, ev_tmp) {
+        LIBXL_TAILQ_REMOVE(&gc->occurred_for_callback, ev, link);
+        CTX->event_hooks->event_occurs(CTX->event_hooks_user, ev);
+    }
 }
 
 void *libxl__zalloc(libxl__gc *gc, int bytes)

[...]

Quoted 50 lines
tools/libxl/libxl_types.idl +30 -5
index 93fb8cd..53c07ee 100644
@@ -75,11 +75,6 @@ libxl_action_on_shutdown = Enumeration("action_on_shutdown", [
     (6, "COREDUMP_RESTART"),
     ])
 
-libxl_event_type = Enumeration("event_type", [
-    (1, "DOMAIN_DEATH"),
-    (2, "DISK_EJECT"),
-    ])
-
 libxl_button = Enumeration("button", [
     (1, "POWER"),
     (2, "SLEEP"),
@@ -374,3 +369,33 @@ libxl_sched_credit = Struct("sched_credit", [
     ("weight", integer),
     ("cap", integer),
     ], destructor_fn=None)
+
+libxl_event_type = Enumeration("event_type", [
+    (1, "DOMAIN_SHUTDOWN"),
+    (2, "DOMAIN_DESTROY"),
+    (3, "DISK_EJECT"),
+    ])
+
+libxl_ev_user = Number("libxl_ev_user")
+
+libxl_ev_link = Builtin("ev_link", passby=PASS_BY_REFERENCE, c_only=True)
+
+libxl_event = Struct("event",[
+    ("link",     libxl_ev_link,0,
+     "for use by libxl; caller may use this once the event has been"
+     " returned by libxl_event_{check,wait}"),
+    ("domid",    libxl_domid),
+    ("domuuid",  libxl_uuid),
+    ("for_user", libxl_ev_user),
+    ("type",     libxl_event_type),
+    ("u", KeyedUnion(None, libxl_event_type, "type",
+          [("domain_shutdown", Struct(None, [
+                                             ("shutdown_reason", uint8),
+                                      ])),
+           ("domain_destroy", Struct(None, [])),
+           ("disk_eject", Struct(None, [
+                                        ("vdev", string),
+                                        ("disk", libxl_device_disk),
+                                 ])),
+           ]))])
+
#15 lore raw

Re: [PATCH RFC v2 12/13] libxl: New API for providing OS events to libxl

In reply to Ian Jackson

Jon/Dave/Jim,

I CC'd you the API bits from 13/13 (as potential users of it) without realising that there was some here too. Once again I've trimmed this to just the public headers, see the archives if you want the underlying bits.

Comments on the suitability for your usecases etc gratefully received.

Ian.

Quoted 23 lines · Ian Jackson

We provide a new set of functions and related structures
libxl_osevent_*
which are to be used by event-driven applications to receive information from libxl about which fds libxl is interested in, and what timeouts libxl is waiting for, and to pass back to libxl information about which fds are readable/writeable etc., and which timeouts have occurred. Ie, low-level events.

In this patch, this new machinery is still all unused. Callers will appear in the next patch in the series, which introduces a new API for applications to receive high-level events about actual domains etc.

---
 tools/libxl/Makefile         |    2 +-
 tools/libxl/libxl.c          |   25 ++
 tools/libxl/libxl.h          |    6 +
 tools/libxl/libxl_event.c    |  704 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_event.h    |  185 +++++++++++
 tools/libxl/libxl_internal.h |  212 +++++++++++++-
 6 files changed, 1131 insertions(+), 3 deletions(-)
 create mode 100644 tools/libxl/libxl_event.c
 create mode 100644 tools/libxl/libxl_event.h

[...]

Quoted 223 lines
tools/libxl/libxl.h +6 -0
index 5d28ff9..da06ed2 100644
@@ -137,6 +137,7 @@
 #include <xen/sysctl.h>
 
 #include <libxl_uuid.h>
+#include <_libxl_list.h>
 
 typedef uint8_t libxl_mac[6];
 #define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
@@ -221,6 +222,9 @@ enum {
     ERROR_INVAL = -6,
     ERROR_BADFAIL = -7,
     ERROR_GUEST_TIMEDOUT = -8,
+    ERROR_NOT_READY = -9,
+    ERROR_OSEVENT_REG_FAIL = -10,
+    ERROR_BUFFERFULL = -11,
 };
 
 #define LIBXL_VERSION 0
@@ -539,6 +543,8 @@ const char *libxl_xen_script_dir_path(void);
 const char *libxl_lock_dir_path(void);
 const char *libxl_run_dir_path(void);
 
+#include <libxl_event.h>
+
 #endif /* LIBXL_H */
 
 /*
[...]
tools/libxl/libxl_event.h new file +185 -0
new file mode 100644
index 0000000..48c6277
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2011      Citrix Ltd.
+ * Author Ian Jackson <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#ifndef LIBXL_EVENT_H
+#define LIBXL_EVENT_H
+
+#include <libxl.h>
+
+
+/*======================================================================*/
+
+/*
+ * OS event handling - passing low-level OS events to libxl
+ *
+ * Event-driven programs must use these facilities to allow libxl
+ * to become aware of readability/writeability of file descriptors
+ * and the occurrence of timeouts.
+ *
+ * There are two approaches available.  The first is appropriate for
+ * simple programs handling reasonably small numbers of domains:
+ *
+ *   for (;;) {
+ *      libxl_osevent_beforepoll(...)
+ *      poll();
+ *      libxl_osevent_afterpoll(...);
+ *      for (;;) {
+ *        r=libxl_event_check(...);
+ *        if (r==LIBXL_NOT_READY) break;
+ *        if (r) handle failure;
+ *        do something with the event;
+ *      }
+ *   }
+ *
+ * The second approach uses libxl_osevent_register_hooks and is
+ * suitable for programs which are already using a callback-based
+ * event library.
+ *
+ * An application may freely mix the two styles of interaction.
+ */
+
+struct pollfd;
+
+int libxl_osevent_beforepoll(libxl_ctx *ctx, int *nfds_io,
+                             struct pollfd *fds, int *timeout_upd,
+                             struct timeval now);
+  /* The caller should provide beforepoll with some space for libxl's
+   * fds, and tell libxl how much space is available by setting *nfds_io.
+   * fds points to the start of this space (and fds may be a pointer into
+   * a larger array, for example, if the application has some fds of
+   * its own that it is interested in).
+   *
+   * On return *nfds_io will in any case have been updated by libxl
+   * according to how many fds libxl wants to poll on.
+   *
+   * If the space was sufficient, libxl fills in fds[0..<new
+   * *nfds_io>] suitably for poll(2), updates *timeout_upd if needed,
+   * and returns ok.
+   *
+   * If space was insufficient, fds[0..<old *nfds_io>] is undefined on
+   * return; *nfds_io on return will be greater than the value on
+   * entry; *timeout_upd may or may not have been updated; and
+   * libxl_osevent_beforepoll returns ERROR_BUFERFULL.  In this case
+   * the application needs to make more space (enough space for
+   * *nfds_io struct pollfd) and then call beforepoll again, before
+   * entering poll(2).  Typically this will involve calling realloc.
+   *
+   * The application may call beforepoll with fds==NULL and
+   * *nfds_io==0 in order to find out how much space is needed.
+   *
+   * *timeout_upd is as for poll(2): it's in milliseconds, and
+   * negative values mean no timeout (infinity).
+   * libxl_osevent_beforepoll will only reduce the timeout, naturally.
+   */
+void libxl_osevent_afterpoll(libxl_ctx *ctx, int nfds, const struct pollfd *fds,
+                             struct timeval now);
+  /* nfds and fds[0..nfds] must be from the most recent call to
+   * _beforepoll, as modified by poll.
+   *
+   * This function actually performs all of the IO and other actions,
+   * and generates events (libxl_event), which are implied by either
+   * (a) the time of day or (b) both (i) the returned information from
+   * _beforepoll, and (ii) the results from poll specified in
+   * fds[0..nfds-1].  Generated events can then be retrieved by
+   * libxl_event_check.
+   */
+
+
+typedef struct libxl_osevent_hooks {
+  int (*fd_register)(void *user, int fd, void **for_app_registration_out,
+                     short events, void *for_libxl);
+  int (*fd_modify)(void *user, int fd, void **for_app_registration_update,
+                   short events);
+  void (*fd_deregister)(void *user, int fd, void *for_app_registration);
+  int (*timeout_register)(void *user, void **for_app_registration_out,
+                          struct timeval abs, void *for_libxl);
+  int (*timeout_modify)(void *user, void **for_app_registration_update,
+                         struct timeval abs);
+  void (*timeout_deregister)(void *user, void *for_app_registration_io);
+} libxl_osevent_hooks;
+
+void libxl_osevent_register_hooks(libxl_ctx *ctx,
+                                  const libxl_osevent_hooks *hooks,
+                                  void *user);
+  /* The application which calls register_fd_hooks promises to
+   * maintain a register of fds and timeouts that libxl is interested
+   * in, and make calls into libxl (libxl_osevent_occurred_*)
+   * when those fd events and timeouts occur.  This is more efficient
+   * than _beforepoll/_afterpoll if there are many fds (which can
+   * happen if the same libxl application is managing many domains).
+   *
+   * For an fd event, events is as for poll().  register or modify may
+   * be called with events==0, in which case it must still work
+   * normally, just not generate any events.
+   *
+   * For a timeout event, milliseconds is as for poll().
+   * Specifically, negative values of milliseconds mean NO TIMEOUT.
+   * This is used by libxl to temporarily disable a timeout.
+   *
+   * If the register or modify hook succeeds it may update
+   * *for_app_registration_out/_update and must then return 0.
+   * On entry to register, *for_app_registration_out is always NULL.
+   *
+   * A registration or modification hook may fail, in which case it
+   * must leave the registration state of the fd or timeout unchanged.
+   * It may then either return ERROR_OSEVENT_REG_FAIL or any positive
+   * int.  The value returned will be passed up through libxl and
+   * eventually returned back to the application.  When register
+   * fails, any value stored into *for_registration_out is ignored by
+   * libxl; when modify fails, any changed value stored into
+   * *for_registration_update is honoured by libxl and will be passed
+   * to future modify or deregister calls.
+   *
+   * libxl will only attempt to register one callback for any one fd.
+   * libxl will remember the value stored in *for_app_registration_io
+   * by a successful call to register or modify and pass it into
+   * subsequent calls to modify or deregister.
+   *
+   * register_fd_hooks may be called only once for each libxl_ctx.
+   * libxl may make calls to register/modify/deregister from within
+   * any libxl function (indeed, it will usually call register from
+   * register_event_hooks).  Conversely, the application MUST NOT make
+   * the event occurrence calls (libxl_osevent_occurred_*) into libxl
+   * reentrantly from within libxl (for example, from within the
+   * register/modify functions).
+   *
+   * The value *hooks is not copied and must outlast the libxl_ctx.
+   */
+
+/* It is NOT legal to call _occurred_ reentrantly within any libxl
+ * function.  Specifically it is NOT legal to call it from within
+ * a register callback.  Conversely, libxl MAY call register/deregister
+ * from within libxl_event_registered_call_*.
+ */
+
+void libxl_osevent_occurred_fd(libxl_ctx *ctx, void *for_libxl,
+                               int fd, short events, short revents);
+
+void libxl_osevent_occurred_timeout(libxl_ctx *ctx, void *for_libxl);
+  /* Implicitly, on entry to this function the timeout has been
+   * deregistered.  If _occurred_timeout is called, libxl will not
+   * call timeout_deregister; if it wants to requeue the timeout it
+   * will call timeout_register again.
+   */
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
#16 lore raw

Re: [PATCH RFC v2 12/13] libxl: New API for providing OS events to libxl

In reply to Ian Jackson
Quoted 12 lines · Ian Jackson

+ * There are two approaches available. The first is appropriate for
+ * simple programs handling reasonably small numbers of domains:
+ *
+ * for (;;) {

+ *      libxl_osevent_beforepoll(...)
+ *      poll();
+ *      libxl_osevent_afterpoll(...);
+ *      for (;;) {
+ *        r=libxl_event_check(...);
+ *        if (r==LIBXL_NOT_READY) break;
+ *        if (r) handle failure;
+ *        do something with the event;
Quoted 2 lines

+ * }
+ * }

It is good that you included an example here but it doesn't follow the CODING_STYLE

#17 lore raw

Re: [PATCH RFC v2 12/13] libxl: New API for providing OS events to libxl

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 12/13] libxl: New API for providing OS events to libxl"):

Quoted 16 lines · Ian Jackson
Quoted 12 lines

+ * There are two approaches available. The first is appropriate for
+ * simple programs handling reasonably small numbers of domains:
+ *
+ * for (;;) {

+ *      libxl_osevent_beforepoll(...)
+ *      poll();
+ *      libxl_osevent_afterpoll(...);
+ *      for (;;) {
+ *        r=libxl_event_check(...);
+ *        if (r==LIBXL_NOT_READY) break;
+ *        if (r) handle failure;
+ *        do something with the event;
Quoted 2 lines

+ * }
+ * }

Quoted 2 lines

It is good that you included an example here but it doesn't follow the CODING_STYLE

I guess you mean the inner indent level being 2 and the missing spaces near "r=". Fixed.

Ian.

Acked-by on v2 11/13
#18 lore raw

Re: [PATCH RFC v2 11/13] libxl: make libxl__free_all idempotent

In reply to Ian Jackson
Quoted 1 line · Ian Jackson
Quoted 17 lines
---
 tools/libxl/libxl_internal.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.c +2 -0
index df2b7f8..62e7fba 100644
@@ -72,6 +72,8 @@ void libxl__free_all(libxl__gc *gc)
         free(ptr);
     }
     free(gc->alloc_ptrs);
+    gc->alloc_ptrs = 0;
+    gc->alloc_maxsize = 0;
 }
 
 void *libxl__zalloc(libxl__gc *gc, int bytes)
Acked-by on v2 10/13
#19 lore raw

Re: [PATCH RFC v2 10/13] libxl: make libxl__[v]log const-correct

In reply to Ian Jackson
Quoted 1 line · Ian Jackson
Quoted 47 lines
---
 tools/libxl/libxl_internal.c |    4 ++--
 tools/libxl/libxl_internal.h |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl_internal.c +2 -2
index dd31f25..df2b7f8 100644
@@ -179,7 +179,7 @@ char *libxl__dirname(libxl__gc *gc, const char *s)
 
 void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
              const char *file, int line, const char *func,
-             char *fmt, va_list ap)
+             const char *fmt, va_list ap)
 {
     char *enomem = "[out of memory formatting log message]";
     char *base = NULL;
@@ -206,7 +206,7 @@ void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
 
 void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
             const char *file, int line, const char *func,
-            char *fmt, ...)
+            const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
tools/libxl/libxl_internal.h +2 -2
index 79a9de4..fe64d34 100644
@@ -80,13 +80,13 @@
 _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
              const char *file /* may be 0 */, int line /* ignored if !file */,
              const char *func /* may be 0 */,
-             char *fmt, va_list al)
+             const char *fmt, va_list al)
      __attribute__((format(printf,7,0)));
 
 _hidden void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
             const char *file /* may be 0 */, int line /* ignored if !file */,
             const char *func /* may be 0 */,
-            char *fmt, ...)
+            const char *fmt, ...)
      __attribute__((format(printf,7,8)));
 
      /* these functions preserve errno (saving and restoring) */
#20 lore raw

Re: [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx

In reply to Ian Jackson
Quoted 22 lines · Ian Jackson

This lock will be used to protect data structures which will be hung off the libxl_ctx in subsequent patches.

---
 tools/libxl/libxl.c          |    3 +++
 tools/libxl/libxl_internal.h |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +1 -0
index 5d448af..a3c9807 100644
@@ -40,6 +40,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
 {
     libxl_ctx *ctx;
     struct stat stat_buf;
+    const pthread_mutex_t mutex_value = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
     if (version != LIBXL_VERSION)
         return ERROR_VERSION;

tools/libxl/libxl.c int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg) · line 57

Quoted 4 lines
tools/libxl/libxl.c +1 -0
@@ -53,6 +54,8 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, xentoollog_logger * lg)
     memset(ctx, 0, sizeof(libxl_ctx));
     ctx->lg = lg;
 
+    memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));

Is this subtly different to

       ctx->lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

in some way I'm missing?

Quoted 17 lines
tools/libxl/libxl.c +1 -0
+
     if ( stat(XENSTORE_PID_FILE, &stat_buf) != 0 ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Is xenstore daemon running?\n"
                      "failed to stat %s", XENSTORE_PID_FILE);
tools/libxl/libxl_internal.h +1 -0
index 6d9da2c..79a9de4 100644
@@ -23,6 +23,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 
 #include <xs.h>
 #include <xenctrl.h>

tools/libxl/libxl_internal.h struct libxl__ctx { · line 100

Quoted 5 lines
tools/libxl/libxl_internal.h +2 -0
@@ -95,6 +96,9 @@ struct libxl__ctx {
     xc_interface *xch;
     struct xs_handle *xsh;
 
+    pthread_mutex_t lock; /* protects data structures hanging off the ctx */
+      /* always use MUTEX_LOCK and MUTEX_UNLOCK to manipulate this */

MUTEX is something of an implementation detail (although I admit we are unlikely to use anything else), perhaps CTX_(UN)LOCK?

Perhaps give the variable a less obvious name to help discourage direct use?

tools/libxl/libxl_internal.h _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s); · line 586

Quoted 11 lines
tools/libxl/libxl_internal.h +4 -0
+
     /* for callers who reap children willy-nilly; caller must only
      * set this after libxl_init and before any other call - or
      * may leave them untouched */
@@ -577,6 +581,18 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s);
 #define CTX           libxl__gc_owner(gc)
 
 
+#define MUTEX_LOCK do {                                 \
+        int mutex_r = pthread_mutex_lock(&CTX->lock);   \
+        assert(!mutex_r);                               \

This assert is to catch EINVAL ("the mutex has not been properly initialized") rather than EDEADLK ("the mutex is already locked by the calling thread") since we asked for a non-error-checking recursive lock?

Since it is OK to take this lock recursively then it might be as well to say so explicitly?

This is the first lock in libxl so I guess there isn't much of a locking hierarchy yet. Are there any particular considerations which a caller must make wrt its own locking?

Quoted 12 lines
tools/libxl/libxl_internal.h +9 -0
+    } while(0)
+
+#define MUTEX_UNLOCK do {                               \
+        int mutex_r = pthread_mutex_unlock(&CTX->lock); \
+        assert(!mutex_r);                               \
+    } while(0)
+        
+
+
 /*
  * Inserts "elm_new" into the sorted list "head".
  *
#21 lore raw

Re: [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx"):

Quoted 2 lines · Ian Jackson
Quoted 1 line

+ const pthread_mutex_t mutex_value = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

...

Quoted 5 lines
Quoted 1 line

+ memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));

Is this subtly different to

       ctx->lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

in some way I'm missing?

Yes. PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is formally valid only as an initialiser, not necessarily as an expression. I'm not sure that relevant GCC extensions mean the two are always equivalent.

Ian.

#22 lore raw

Re: [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx

Quoted 6 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx"):

Quoted 2 lines · Ian Jackson
Quoted 1 line

+ const pthread_mutex_t mutex_value = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

...

Quoted 2 lines
Quoted 1 line

+ memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));

Quoted 7 lines
Quoted 3 lines

Is this subtly different to

       ctx->lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

in some way I'm missing?

Yes. PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is formally valid only as an initialiser, not necessarily as an expression. I'm not sure that relevant GCC extensions mean the two are always equivalent.

OK, thanks.

I just had a read of pthread_mutex(3) and I'm surprised how many hoops one has to jump through to use pthread_mutex_init(). Well, I say surprised...

Ian.

#23 lore raw

Re: [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx

In reply to Ian Campbell

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx"):

Quoted 6 lines · Ian Jackson
Quoted 1 line

+ memcpy(&ctx->lock, &mutex_value, sizeof(ctx->lock));

Is this subtly different to

       ctx->lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;

in some way I'm missing?

I have added a comment about this. (In my own tree; I'll repost the series shortly.)

Quoted 5 lines

tools/libxl/libxl_internal.h struct libxl__ctx { · line 100

Quoted 2 lines
tools/libxl/libxl_internal.h +2 -0
+    pthread_mutex_t lock; /* protects data structures hanging off the ctx */
+      /* always use MUTEX_LOCK and MUTEX_UNLOCK to manipulate this */

MUTEX is something of an implementation detail (although I admit we are unlikely to use anything else), perhaps CTX_(UN)LOCK?

Renamed.

Quoted 2 lines

Perhaps give the variable a less obvious name to help discourage direct use?

I think the comment right next to it ought to be sufficient.

Quoted 7 lines

tools/libxl/libxl_internal.h _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s); · line 586

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+#define MUTEX_LOCK do {                                 \
+        int mutex_r = pthread_mutex_lock(&CTX->lock);   \
+        assert(!mutex_r);                               \

This assert is to catch EINVAL ("the mutex has not been properly initialized") rather than EDEADLK ("the mutex is already locked by the calling thread") since we asked for a non-error-checking recursive lock?

Yes.

Quoted 6 lines

Since it is OK to take this lock recursively then it might be as well to say so explicitly?

This is the first lock in libxl so I guess there isn't much of a locking hierarchy yet. Are there any particular considerations which a caller must make wrt its own locking?

I have added a comment explaining this. No requirements are imposed on libxl's caller. (Other than the reentrancy ones on callbacks.)

Ian.

#24 lore raw

Re: [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx

Ian Jackson writes ("Re: [Xen-devel] [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx"):

Quoted 10 lines

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 09/13] libxl: introduce lock in libxl_ctx"):

Quoted 6 lines

Since it is OK to take this lock recursively then it might be as well to say so explicitly?

This is the first lock in libxl so I guess there isn't much of a locking hierarchy yet. Are there any particular considerations which a caller must make wrt its own locking?

I have added a comment explaining this. No requirements are imposed on libxl's caller. (Other than the reentrancy ones on callbacks.)

In fact this turns out not to be true. I will document the restrictions. Good question BTW.

Ian.

Acked-by on v2 8/13
#25 lore raw

Re: [PATCH RFC v2 08/13] libxl: Rationalise #includes

In reply to Ian Jackson
Quoted 7 lines · Ian Jackson

libxl_internal.h now #includes libxl.h and various system headers.

This
1. makes the order of header inclusion more predictable
2. explicitly allows libxl_internal.h to use objects defined in libxl.h
3. removes the need for individual files to include these headers

Quoted 8 lines

Also
- remove some unnecessary #includes of libxl_utils.h, flexarray.h, etc. in some libxl*.c files,
- include libxl_osdeps.h at the top of libxl_internal.h
- add missing includes of libxl_osdeps.h to a couple of files
- change libxl.h to libxl_internal.h in a couple of files

Quoted 375 lines
---
 tools/libxl/libxl.c            |    3 ---
 tools/libxl/libxl_blktap2.c    |    1 -
 tools/libxl/libxl_bootloader.c |    4 ----
 tools/libxl/libxl_cpuid.c      |    4 ----
 tools/libxl/libxl_create.c     |    4 +---
 tools/libxl/libxl_device.c     |    2 --
 tools/libxl/libxl_dm.c         |    4 +---
 tools/libxl/libxl_dom.c        |    1 -
 tools/libxl/libxl_exec.c       |    1 -
 tools/libxl/libxl_flask.c      |    3 ++-
 tools/libxl/libxl_internal.c   |    4 ----
 tools/libxl/libxl_internal.h   |    5 +++++
 tools/libxl/libxl_json.c       |    4 ++--
 tools/libxl/libxl_noblktap2.c  |    2 --
 tools/libxl/libxl_nocpuid.c    |    2 +-
 tools/libxl/libxl_paths.c      |    2 +-
 tools/libxl/libxl_pci.c        |    5 -----
 tools/libxl/libxl_qmp.c        |    2 ++
 tools/libxl/libxl_utils.c      |    1 -
 tools/libxl/libxl_uuid.c       |    4 ++++
 tools/libxl/libxl_xshelp.c     |    1 -
 21 files changed, 19 insertions(+), 40 deletions(-)
tools/libxl/libxl.c +0 -3
index 064fbc4..5d448af 100644
@@ -31,10 +31,7 @@
 #include <inttypes.h>
 #include <assert.h>
 
-#include "libxl.h"
-#include "libxl_utils.h"
 #include "libxl_internal.h"
-#include "flexarray.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 #define BACKEND_STRING_SIZE 5
tools/libxl/libxl_blktap2.c +0 -1
index c8d9148..acf4110 100644
@@ -12,7 +12,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
 #include "libxl_osdeps.h"
 #include "libxl_internal.h"
 
tools/libxl/libxl_bootloader.c +0 -4
index 1e735a8..396aac6 100644
@@ -14,7 +14,6 @@
 
 #include "libxl_osdeps.h"
 
-#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <termios.h>
@@ -22,11 +21,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
-#include "flexarray.h"
-
 #define XENCONSOLED_BUF_SIZE 16
 #define BOOTLOADER_BUF_SIZE 1024
 
tools/libxl/libxl_cpuid.c +0 -4
index 12cc0b1..f65a898 100644
@@ -10,10 +10,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include <string.h>
-
-#include "libxl.h"
-#include "libxl_osdeps.h"
 #include "libxl_internal.h"
 
 void libxl_cpuid_destroy(libxl_cpuid_policy_list *p_cpuid_list)
tools/libxl/libxl_create.c +1 -3
index 68d0fc3..70705af 100644
@@ -26,10 +26,8 @@
 #include <xc_dom.h>
 #include <xenguest.h>
 #include <assert.h>
-#include "libxl.h"
-#include "libxl_utils.h"
+
 #include "libxl_internal.h"
-#include "flexarray.h"
 
 void libxl_domain_config_destroy(libxl_domain_config *d_config)
 {
tools/libxl/libxl_device.c +0 -2
index 88cd990..8b5fc4a 100644
@@ -24,8 +24,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-
-#include "libxl.h"
 #include "libxl_internal.h"
 
 static const char *string_of_kinds[] = {
tools/libxl/libxl_dm.c +1 -3
index d6ad85b..e18bac7 100644
@@ -24,10 +24,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <assert.h>
-#include "libxl_utils.h"
+
 #include "libxl_internal.h"
-#include "libxl.h"
-#include "flexarray.h"
 
 static const char *libxl_tapif_script(libxl__gc *gc)
 {
tools/libxl/libxl_dom.c +0 -1
index 718281a..430b3d0 100644
@@ -32,7 +32,6 @@
 
 #include <xen/hvm/hvm_info_table.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid)
tools/libxl/libxl_exec.c +0 -1
index d6199d4..e981679 100644
@@ -28,7 +28,6 @@
 #include <signal.h> /* for SIGKILL */
 #include <fcntl.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 static int call_waitpid(pid_t (*waitpid_cb)(pid_t, int *, int), pid_t pid, int *status, int options)
tools/libxl/libxl_flask.c +2 -1
index c8d0594..6b548dd 100644
@@ -7,13 +7,14 @@
  *  as published by the Free Software Foundation.
  */
 
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <xenctrl.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 int libxl_flask_context_to_sid(libxl_ctx *ctx, char *buf, size_t len,
tools/libxl/libxl_internal.c +0 -4
index 3993d8e..dd31f25 100644
@@ -16,8 +16,6 @@
 #include "libxl_osdeps.h"
 
 #include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -25,9 +23,7 @@
 #include <sys/mman.h>
 #include <unistd.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
-#include "libxl_utils.h"
 
 int libxl__error_set(libxl__gc *gc, int code)
 {
tools/libxl/libxl_internal.h +5 -0
index 8649788..6d9da2c 100644
@@ -17,14 +17,19 @@
 #ifndef LIBXL_INTERNAL_H
 #define LIBXL_INTERNAL_H
 
+#include "libxl_osdeps.h"
+
 #include <stdint.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <xs.h>
 #include <xenctrl.h>
 #include "xentoollog.h"
 
+#include "libxl.h"
+
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
 #define _hidden __attribute__((visibility("hidden")))
 #define _protected __attribute__((visibility("protected")))
tools/libxl/libxl_json.c +2 -2
index 11f65fc..a4208f3 100644
@@ -12,13 +12,13 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <assert.h>
-#include <string.h>
 
 #include <yajl/yajl_parse.h>
 #include <yajl/yajl_gen.h>
 
-#include <libxl.h>
 #include "libxl_internal.h"
 
 /* #define DEBUG_ANSWER */
tools/libxl/libxl_noblktap2.c +0 -2
index 704d03f..3307551 100644
@@ -12,8 +12,6 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
-#include "libxl_osdeps.h"
 #include "libxl_internal.h"
 
 int libxl__blktap_enabled(libxl__gc *gc)
tools/libxl/libxl_nocpuid.c +1 -1
index d63757f..2e9490c 100644
@@ -10,7 +10,7 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
+#include "libxl_internal.h"
 
 void libxl_cpuid_destroy(libxl_cpuid_policy_list *p_cpuid_list)
 {
tools/libxl/libxl_paths.c +1 -1
index 64f662d..fa80056 100644
@@ -12,7 +12,7 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
+#include "libxl_internal.h"
 #include "_libxl_paths.h"
 
 const char *libxl_sbindir_path(void)
tools/libxl/libxl_pci.c +0 -5
index 33dd060..9eac108 100644
@@ -17,7 +17,6 @@
 #include "libxl_osdeps.h"
 
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -27,15 +26,11 @@
 #include <sys/stat.h>
 #include <signal.h>
 #include <unistd.h> /* for write, unlink and close */
-#include <stdint.h>
 #include <inttypes.h>
 #include <dirent.h>
 #include <assert.h>
 
-#include "libxl.h"
-#include "libxl_utils.h"
 #include "libxl_internal.h"
-#include "flexarray.h"
 
 #define PCI_BDF                "%04x:%02x:%02x.%01x"
 #define PCI_BDF_SHORT          "%02x:%02x.%01x"
tools/libxl/libxl_qmp.c +2 -0
index 618f20f..0eefe4d 100644
@@ -18,6 +18,8 @@
  * Specification, see in the QEMU repository.
  */
 
+#include "libxl_osdeps.h"
+
 #include <unistd.h>
 #include <sys/un.h>
 #include <sys/queue.h>
tools/libxl/libxl_utils.c +0 -1
index dce9d8b..7ea2d2c 100644
@@ -28,7 +28,6 @@
 #include <unistd.h>
 #include <assert.h>
 
-#include "libxl_utils.h"
 #include "libxl_internal.h"
 
 struct schedid_name {
tools/libxl/libxl_uuid.c +4 -0
index e837228..80ab789 100644
@@ -12,8 +12,12 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <libxl_uuid.h>
 
+#include "libxl_internal.h"
+
 #if defined(__linux__)
 
 int libxl_uuid_is_nil(libxl_uuid *uuid)
tools/libxl/libxl_xshelp.c +0 -2
index 56a7c7b..f85e867 100644
@@ -21,7 +21,6 @@
 #include <stdarg.h>
 #include <inttypes.h>
 
-#include "libxl.h"
 #include "libxl_internal.h"
 
 char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length)
--

1.7.2.5

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Acked-by on v2 7/13
#26 lore raw

Re: [PATCH RFC v2 07/13] libxl: internal convenience macros

In reply to Ian Jackson
Quoted 23 lines · Ian Jackson

Provide some macros which are useful shorthands for use within libxl:
* GC_INIT to initialise a gc from a ctx and GC_FREE to free it
* CTX(gc) to give you back the ctx
* LIBXL_TAILQ_INSERT_SORTED for inserting things into sorted lists

These will be used by later patches.

---
 tools/libxl/libxl_internal.h |   48 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +3 -0
index 31adbc8..8649788 100644
@@ -555,6 +555,54 @@ _hidden void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj);
 
 _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s);
 
+
+/*
+ * Convenience macros.

tools/libxl/libxl_internal.h _hidden void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj); · line 570

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+ */
+
+
+/*
+ * All of these assume (or define)
+ *    libxl__gc *gc;
+ * as a local variable.
+ */
+
+#define GC_INIT(ctx)  libxl__gc gc[1] = { LIBXL_INIT_GC(ctx) }

Tricksy, I like it ;-)

Is there a massive conversion patch somewhere downseries?

Quoted 38 lines
tools/libxl/libxl_internal.h +35 -0
+#define GC_FREE       libxl__free_all(gc)
+#define CTX           libxl__gc_owner(gc)
+
+
+/*
+ * Inserts "elm_new" into the sorted list "head".
+ *
+ * "elm_search" must be a loop search variable of the same type as
+ * "elm_new".  "new_after_search_p" must be an expression which is
+ * true iff the element "elm_new" sorts after the element
+ * "elm_search".
+ *
+ * "search_body" can be empty, or some declaration(s) and statement(s)
+ * needed for "new_after_search_p".
+ */
+#define LIBXL_TAILQ_INSERT_SORTED(head, entry, elm_new, elm_search,     \
+                                  search_body, new_after_search_p)      \
+    do {                                                                \
+        for ((elm_search) = LIBXL_TAILQ_FIRST((head));                  \
+             (elm_search);                                              \
+             (elm_search) = LIBXL_TAILQ_NEXT((elm_search), entry)) {    \
+            search_body;                                                \
+            if (!(new_after_search_p))                                  \
+                break;                                                  \
+        }                                                               \
+        /* now elm_search is either the element before which we want    \
+         * to place elm_new, or NULL meaning we want to put elm_new at  \
+         * the end */                                                   \
+        if ((elm_search))                                               \
+            LIBXL_TAILQ_INSERT_BEFORE((elm_search), (elm_new), entry);  \
+        else                                                            \
+            LIBXL_TAILQ_INSERT_TAIL((head), (elm_new), entry);          \
+    } while(0)
+
+
 #endif
 
 /*
#27 lore raw

Re: [PATCH RFC v2 07/13] libxl: internal convenience macros

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 07/13] libxl: internal convenience macros"):

Quoted 2 lines · Ian Jackson
Quoted 1 line

+#define GC_INIT(ctx) libxl__gc gc[1] = { LIBXL_INIT_GC(ctx) }

...

Quoted 1 line

Is there a massive conversion patch somewhere downseries?

Not yet. I decided I didn't want to put that on the critical path for my event handling series, and also of course I didn't want a large style cleanup patch at the end of my series to keep getting conflicts.

However this is something I have my eye on.

Ian.

#28 lore raw

Re: [PATCH RFC v2 07/13] libxl: internal convenience macros

Quoted 11 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 07/13] libxl: internal convenience macros"):

Quoted 2 lines · Ian Jackson
Quoted 1 line

+#define GC_INIT(ctx) libxl__gc gc[1] = { LIBXL_INIT_GC(ctx) }

...

Quoted 1 line

Is there a massive conversion patch somewhere downseries?

Not yet. I decided I didn't want to put that on the critical path for my event handling series, and also of course I didn't want a large style cleanup patch at the end of my series to keep getting conflicts.

However this is something I have my eye on.

Great, thanks.

Ian.

#29 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

In reply to Ian Jackson
Quoted 11 lines · Ian Jackson

GCC and C99 allow declarations to be mixed with code. This is a good idea because:

* It allows variables to be more often initialised as they are declared, thus reducing the occurrence of uninitialised variable errors.

* Certain alloca-like constructs (arrays allocated at runtime on the stack) can more often be written without a spurious { } block. Such blocks are confusing to read.

Quoted 6 lines

* It makes it easier to write and use macros which declare and initialise formulaic variables and do other function setup code, because there is no need to worry that such macros might be incompatible with each other or have strict ordering constraints.

I suspect there isn't much scope for abuse of this capability but would a few words of guidance in CODING_STYLE make sense?

Quoted 18 lines
---
 tools/libxl/Makefile |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tools/libxl/Makefile +2 -1
index f23661a..a3727ab 100644
@@ -11,7 +11,8 @@ MINOR = 0
 XLUMAJOR = 1.0
 XLUMINOR = 0
 
-CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations
+CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \
+	-Wno-declaration-after-statement
 CFLAGS += -I. -fPIC
 
 ifeq ($(CONFIG_Linux),y)
#30 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 2 lines

I suspect there isn't much scope for abuse of this capability but would a few words of guidance in CODING_STYLE make sense?

I don't think there's anything I feel needs saying. If you think people are likely to abuse it in a particular way then do say :-).

Otherwise we can wait and see what results and add stuff to CODING_STYLE as necessary ?

Ian.

#31 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Quoted 9 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 2 lines

I suspect there isn't much scope for abuse of this capability but would a few words of guidance in CODING_STYLE make sense?

I don't think there's anything I feel needs saying. If you think people are likely to abuse it in a particular way then do say :-).

Otherwise we can wait and see what results and add stuff to CODING_STYLE as necessary ?

Yes, lets do that.

#32 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Quoted 5 lines · Ian Campbell
Quoted 4 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 2 lines

I suspect there isn't much scope for abuse of this capability but would a few words of guidance in CODING_STYLE make sense?

Quoted 8 lines
Quoted 5 lines

I don't think there's anything I feel needs saying. If you think people are likely to abuse it in a particular way then do say :-).

Otherwise we can wait and see what results and add stuff to CODING_STYLE as necessary ?

Yes, lets do that.

I think it would make sense to add to the CODING_STYLE that variable declarations shouldn't be mixed with code, unless part of a macro or an alloca-like construct.
Basically the coding style should stay the same that is now.

#33 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 3 lines

I think it would make sense to add to the CODING_STYLE that variable declarations shouldn't be mixed with code, unless part of a macro or an alloca-like construct.

I think this is a silly rule. In my proposed commit message I advanced three reasons for allowing declaration after statement:

Quoted 4 lines
Quoted 4 lines

* It allows variables to be more often initialised as they are declared, thus reducing the occurrence of uninitialised variable errors.

Quoted 8 lines
Quoted 8 lines

* Certain alloca-like constructs (arrays allocated at runtime on the stack) can more often be written without a spurious { } block. Such blocks are confusing to read.

* It makes it easier to write and use macros which declare and initialise formulaic variables and do other function setup code, because there is no need to worry that such macros might be incompatible with each other or have strict ordering constraints.

Of these the first two improvements would be banned by your proposed coding style rule.

I don't understand what the harm is in allowing declarations, with initialisation, freely mixed with code.

Ian.

#34 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Quoted 21 lines · Ian Jackson

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 3 lines

I think it would make sense to add to the CODING_STYLE that variable declarations shouldn't be mixed with code, unless part of a macro or an alloca-like construct.

I think this is a silly rule. In my proposed commit message I advanced three reasons for allowing declaration after statement:

Quoted 4 lines
Quoted 4 lines

* It allows variables to be more often initialised as they are declared, thus reducing the occurrence of uninitialised variable errors.

Quoted 8 lines
Quoted 8 lines

* Certain alloca-like constructs (arrays allocated at runtime on the stack) can more often be written without a spurious { } block. Such blocks are confusing to read.

* It makes it easier to write and use macros which declare and initialise formulaic variables and do other function setup code, because there is no need to worry that such macros might be incompatible with each other or have strict ordering constraints.

Quoted 5 lines

Of these the first two improvements would be banned by your proposed coding style rule.

I don't understand what the harm is in allowing declarations, with initialisation, freely mixed with code.

Variable declarations should either be at the top of the function or immediately before / as part of the block which uses them. e.g. this is unhelpful:

void a_func(void)

{
	/* a bunch of code; */

	int bar;

	/* a bunch more code not using bar */

	bar = get_me_a_bar();

	/* use bar lots */
}

Ian.

#35 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Quoted 3 lines · Ian Campbell

Variable declarations should either be at the top of the function or immediately before / as part of the block which uses them. e.g. this is unhelpful:

This isn't an objection to the patch BTW, I'm happy with your reasoning...

Quoted 21 lines

void a_func(void)

{
	/* a bunch of code; */

	int bar;

	/* a bunch more code not using bar */

	bar = get_me_a_bar();

	/* use bar lots */
}

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#36 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

In reply to Ian Campbell

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 3 lines

Variable declarations should either be at the top of the function or immediately before / as part of the block which uses them. e.g. this is unhelpful:

I agree..

Quoted 12 lines

void a_func(void)

{
	/* a bunch of code; */

	int bar;

	/* a bunch more code not using bar */

	bar = get_me_a_bar();

	/* use bar lots */
}

Yes, but would anyone really write that ? I think the argument is about this:

/* a bunch of code; */

int bar = get_me_a_bar();

/* use bar lots */

I think this is fine and I think Stefano objects.

How about:

Declarations of automatic variables should either be at the start of the relevant function (or block), or as late as reasonable; in the latter case they should be initialised in the declaration if possible.

Ian.

#37 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

In reply to Ian Jackson
Quoted 16 lines · Ian Jackson

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 3 lines

I think it would make sense to add to the CODING_STYLE that variable declarations shouldn't be mixed with code, unless part of a macro or an alloca-like construct.

I think this is a silly rule. In my proposed commit message I advanced three reasons for allowing declaration after statement:

Quoted 8 lines
Quoted 8 lines

* It allows variables to be more often initialised as they are declared, thus reducing the occurrence of uninitialised variable errors.

* Certain alloca-like constructs (arrays allocated at runtime on the stack) can more often be written without a spurious { } block. Such blocks are confusing to read.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

* It makes it easier to write and use macros which declare and initialise formulaic variables and do other function setup code, because there is no need to worry that such macros might be incompatible with each other or have strict ordering constraints.

Of these the first two improvements would be banned by your proposed coding style rule.

Only the first would be banned, I am OK with making an exception for alloca constructs and macros.

Quoted 2 lines

I don't understand what the harm is in allowing declarations, with initialisation, freely mixed with code.

It makes the code harder to read;
it makes it more difficult to rearrange local variables in the future; it makes it more difficult to see how much stack your function is using; it makes it more difficult to realize if you can reduce the amount of local variables you are using.

And it violates the current coding style.

I think that declaring variables at the beginning of the function is a good programming practice in any language.

The three most important C codebases in the Xen project are: Linux, Qemu and Xen. None of these allow mixing declarations and code, for a good reason. I don't think libxl should have a different code style in this regard, it would just be confusing.

#38 lore raw

Re: [PATCH RFC v2 06/13] libxl: permit declaration after statement

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH RFC v2 06/13] libxl: permit declaration after statement"):

Quoted 6 lines · Ian Jackson
Quoted 2 lines

I don't understand what the harm is in allowing declarations, with initialisation, freely mixed with code.

It makes the code harder to read;

Naturally I disagree, but this is a matter of subjective taste as far as I can tell, unless you have something specific to point to.

Quoted 1 line

it makes it more difficult to rearrange local variables in the future;

I'm not sure what you mean by "rearrange local variables". The style where variables are declared only at the top of the file tends to result in long lists of local variables in declaration statements at the top of functions. Those long lists make editing the function somewhat more complex.

Declaring variables in the same statement as they are initialised naturally makes "rearranging" them trivial.

Quoted 1 line

it makes it more difficult to see how much stack your function is using;

This is not relevant in libxl unless the objects are truly huge (in which case they shouldn't be on the stack at all).

Quoted 2 lines

it makes it more difficult to realize if you can reduce the amount of local variables you are using.

There is no benefit in trying to "reduce the amount of local variables" in userland C code compiled with a reasonable optimising compiler. The compiler will be able to do the same liveness analysis either way.

Quoted 1 line

And it violates the current coding style.

This is not an argument against changing the coding style.

Quoted 2 lines

I think that declaring variables at the beginning of the function is a good programming practice in any language.

I think that initialising variables at the time they are declared, where reasonable, is good programming practice in any language.

Quoted 4 lines

The three most important C codebases in the Xen project are: Linux, Qemu and Xen. None of these allow mixing declarations and code, for a good reason. I don't think libxl should have a different code style in this regard, it would just be confusing.

I don't see this as a particularly relevant consideration. There are lots of other ways our coding style differs from (say) Linux. Any competent C programmer will be familiar with both styles.

Ian.

Acked-by on v2 5/13
#39 lore raw

Re: [PATCH RFC v2 05/13] libxl: idl: Provide struct and union tags

In reply to Ian Jackson
Quoted 8 lines · Ian Jackson

Instead of generating:

   typedef struct {
     ...
   } libxl_foo;

Produce:

Quoted 8 lines
   typedef struct libxl_foo {
     ...
   } libxl_foo;

This makes it possible to refer to libxl idl-generated structs and unions, as incomplete types, before they have been defined.

Quoted 17 lines
---
 tools/libxl/gentypes.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/libxl/gentypes.py +1 -1
index e82b706..c4efbf3 100644
@@ -56,7 +56,7 @@ def libxl_C_type_define(ty, indent = ""):
         if ty.typename is None:
             s += "%s {\n" % ty.kind
         else:
-            s += "typedef %s {\n" % ty.kind
+            s += "typedef %s %s {\n" % (ty.kind, ty.typename)
 
         for f in ty.fields:
             if f.comment is not None:
Acked-by on v2 4/13
#40 lore raw

Re: [PATCH RFC v2 04/13] libxl: idl: support new "c_only" type attribute

In reply to Ian Jackson
Quoted 7 lines · Ian Jackson

This provides for fields in libxl datatypes which are only present in the C version of structures. This is useful, for example, when a libxl datatype wants to contain fields which are used by libxl internally and which are only present in the structure to avoid additional memory allocation inconvenience.

Quoted 40 lines
---
 tools/libxl/gentest.py    |    2 ++
 tools/libxl/libxltypes.py |    4 +++-
 2 files changed, 5 insertions(+), 1 deletions(-)
tools/libxl/gentest.py +2 -0
index 6697ac5..ed5358d 100644
@@ -56,6 +56,8 @@ def gen_rand_init(ty, v, indent = "    ", parent = None):
         s += "%s = rand() %% 2;\n" % v
     elif ty.typename in ["char *"]:
         s += "%s = rand_str();\n" % v
+    elif ty.c_only:
+        pass
     elif ty.typename in handcoded:
         raise Exception("Gen for handcoded %s" % ty.typename)
     else:
tools/libxl/libxltypes.py +3 -1
index 05cba88..83a9426 100644
@@ -33,6 +33,8 @@ class Type(object):
         if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE]:
             raise ValueError
 
+        self.c_only = kwargs.setdefault('c_only', False)
+
         if typename is None: # Anonymous type
             self.typename = None
             self.rawname = None
@@ -50,7 +52,7 @@ class Type(object):
 
         self.autogenerate_destructor = kwargs.setdefault('autogenerate_destructor', True)
 
-        if self.typename is not None:
+        if self.typename is not None and not self.c_only:
             self.json_fn = kwargs.setdefault('json_fn', self.typename + "_gen_json")
         else:
             self.json_fn = kwargs.setdefault('json_fn', None)
Acked-by Tested-by Roger Pau Monne on v2 3/13
#41 lore raw

Re: [PATCH RFC v2 03/13] libxl: Provide a version of bsd's queue.h as _libxl_list.h

In reply to Ian Jackson

COPYING GPLv2. See the FSF's definition of GPL compatibility: · line 26

Quoted 10 lines · Ian Jackson
COPYING +6 -0
@@ -18,6 +18,14 @@ GPLv2. See the FSF's definition of GPL compatibility:
 And how this applies to a range of open source licenses:
  http://www.gnu.org/licenses/license-list.html
 
+Additionally, the documentation file tools/libxl/external/bsd-queue.3
+has the 4-clause BSD licence.  It is present in the Xen source tree
+for reference purposes for people developing Xen.  It is not installed
+by "make install" and is bundled in the source only for convenience of
+distribution.  We do not intend that we or Xen users or distributors
+should make any reference to "features or use" of that manpage.

Anil pointed to the OpenBSD version of this page which has that clause removed. It would simplify things to use their version (of the header too for consistency)? We are probably not comfortable with just rescinding the clause ourselves?

Otherwise I'm happy with this, so:

Also Roger previously supplied a

Quoted 1 line
(quoted diff) +1 -0
+[...]
#42 lore raw

Re: [PATCH RFC v2 03/13] libxl: Provide a version of bsd's queue.h as _libxl_list.h

Quoted 5 lines · Ian Campbell
Quoted 4 lines · Ian Jackson
(quoted diff) +0 -0
@@ -18,6 +18,14 @@ GPLv2. See the FSF's definition of GPL compatibility:

And how this applies to a range of open source licenses:
http://www.gnu.org/licenses/license-list.html

Quoted 11 lines

COPYING GPLv2. See the FSF's definition of GPL compatibility: · line 26

Quoted 6 lines
COPYING +6 -0
+Additionally, the documentation file tools/libxl/external/bsd-queue.3
+has the 4-clause BSD licence.  It is present in the Xen source tree
+for reference purposes for people developing Xen.  It is not installed
+by "make install" and is bundled in the source only for convenience of
+distribution.  We do not intend that we or Xen users or distributors
+should make any reference to "features or use" of that manpage.

Anil pointed to the OpenBSD version of this page which has that clause removed. It would simplify things to use their version (of the header too for consistency)? We are probably not comfortable with just rescinding the clause ourselves?

If you rescind it yourself, you'll need to go through the FreeBSD CVS history to make sure that there were no other contributors other than Berkeley. OpenBSD already did that in 2002 (and subsequent patches take on the new license, so it doesn't matter).

-anil

#43 lore raw

Re: [PATCH RFC v2 03/13] libxl: Provide a version of bsd's queue.h as _libxl_list.h

Quoted 19 lines · Anil Madhavapeddy
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Ian Jackson
(quoted diff) +0 -0
@@ -18,6 +18,14 @@ GPLv2. See the FSF's definition of GPL compatibility:

And how this applies to a range of open source licenses:
http://www.gnu.org/licenses/license-list.html

Quoted 11 lines

COPYING GPLv2. See the FSF's definition of GPL compatibility: · line 26

Quoted 6 lines
COPYING +6 -0
+Additionally, the documentation file tools/libxl/external/bsd-queue.3
+has the 4-clause BSD licence.  It is present in the Xen source tree
+for reference purposes for people developing Xen.  It is not installed
+by "make install" and is bundled in the source only for convenience of
+distribution.  We do not intend that we or Xen users or distributors
+should make any reference to "features or use" of that manpage.

Anil pointed to the OpenBSD version of this page which has that clause removed. It would simplify things to use their version (of the header too for consistency)? We are probably not comfortable with just rescinding the clause ourselves?

Quoted 3 lines

If you rescind it yourself, you'll need to go through the FreeBSD CVS history
to make sure that there were no other contributors other than Berkeley. OpenBSD already did that in 2002 (and subsequent patches take on the new license, so it doesn't matter).

According to cvs history both NetBSD and OpenBSD did that in 2003. Now it's just about to compare whose content matches most with FreeBSD's implementation. :)

Christoph

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#44 lore raw

Re: [PATCH RFC v2 02/13] libxenstore: Provide xs_check_watch

In reply to Ian Jackson

tools/xenstore/xs.c static bool read_all(int fd, void *data, unsigned int len) · line 383

Quoted 7 lines · Ian Jackson
tools/xenstore/xs.c +7 -0
+
+out_false:
+	if (nonblocking) {
+		int e = errno;
+		setnonblock(fd, 0);
+		errno = e;
+	}

Since setnonblock cannot itself return an error should it always preserve errno on behalf of the caller?

Ian.

#45 lore raw

Re: [PATCH RFC v2 02/13] libxenstore: Provide xs_check_watch

Ian Campbell writes ("Re: [Xen-devel] [PATCH RFC v2 02/13] libxenstore: Provide xs_check_watch"):

Quoted 2 lines

Since setnonblock cannot itself return an error should it always preserve errno on behalf of the caller?

Good idea.

Ian.

Acked-by on v2 1/13
#46 lore raw

Re: [PATCH RFC v2 01/13] libxl: Make libxl__xs_* more const-correct

In reply to Ian Jackson
Quoted 4 lines · Ian Jackson

Paths and values which are not modified by these functions should be declared as "const char *" not "char *".

Obviously correct, (assuming it compiles, which is a safe assumption I think ;-))):

Quoted 74 lines
---
 tools/libxl/libxl_internal.h |    9 +++++----
 tools/libxl/libxl_xshelp.c   |    9 +++++----
 2 files changed, 10 insertions(+), 8 deletions(-)
tools/libxl/libxl_internal.h +5 -4
index 2e26ac6..31adbc8 100644
@@ -181,18 +181,19 @@ _hidden char *libxl__dirname(libxl__gc *gc, const char *s);
 _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length);
 
 _hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
-                    char *dir, char **kvs);
+                             const char *dir, char **kvs);
 _hidden int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
-                   char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
+               const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
    /* Each fn returns 0 on success.
     * On error: returns -1, sets errno (no logging) */
 
 _hidden char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid);
    /* On error: logs, returns NULL, sets errno. */
 
-_hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path);
+_hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t,
+                             const char *path);
 _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
-                                   char *path, unsigned int *nb);
+                                   const char *path, unsigned int *nb);
    /* On error: returns NULL, sets errno (no logging) */
 
 /* from xl_dom */
tools/libxl/libxl_xshelp.c +5 -4
index e41f962..56a7c7b 100644
@@ -49,7 +49,7 @@ char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length)
 }
 
 int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
-                    char *dir, char *kvs[])
+                     const char *dir, char *kvs[])
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *path;
@@ -69,7 +69,7 @@ int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
 }
 
 int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
-                   char *path, const char *fmt, ...)
+                    const char *path, const char *fmt, ...)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *s;
@@ -87,7 +87,7 @@ int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
     return 0;
 }
 
-char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path)
+char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, const char *path)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *ptr;
@@ -113,7 +113,8 @@ char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid)
     return s;
 }
 
-char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsigned int *nb)
+char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
+                           const char *path, unsigned int *nb)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char **ret = NULL;
#47 lore raw
In reply to Ian Jackson
Quoted 13 lines · Ian Jackson

This is a revised RFC version of my event handling API proposal.

It consists of 10 rather uninteresting preparatory, stylistic and bugfix patches, plus 3 with some meat in:

  02/13  libxenstore: Provide xs_check_watch
  12/13  libxl: New API for providing OS events to libxl
  13/13  libxl: New event generation API

This series contains an implementation of almost everything, and builds apart from the lack of libxl_event_free, but it has not been executed at all.

Quoted 4 lines

So at this stage a very detailed code review, particularly of 12 and 13 is probably not appropriate. However, this is hopefully a near-final version of the external and internal interfaces so it would be worth looking at those.

I reviewed all but #12 and #13 so far and I think they can mostly go in now, at least in principal. I acked the majority with that in mind.

I suppose the ones which introduce new facilities should/could wait for the actual users (which I presume are in #12 and #13) which I guess was your intent but I think #1, #3, #5, #8, #10 and #11 would be obviously fine right now.

#3 is a bit borderline wrt having a user but I think you wanted libxl_qmp.c to use it so bashing it in now makes sense?

Ian.

#48 lore raw

I'm sorry to ask such a noobish question... I'm trying to import this patches into my source tree, but mimport seems to be unable to correctly sort them (maybe because they seem to be in git format). What's the best way to import them directly from my mailbox?

Thanks, Roger.

#49 lore raw

Roger Pau Monné writes ("Re: [Xen-devel] [PATCH RFC v2 00/13] New event API"):

Quoted 4 lines

I'm sorry to ask such a noobish question... I'm trying to import this patches into my source tree, but mimport seems to be unable to correctly sort them (maybe because they seem to be in git format). What's the best way to import them directly from my mailbox?

I'm afraid I don't know. With my upstream hat on, for applying patches, I have an absolutely hideous script. (Below but don't read it if you want to keep your lunch.) With my contributor hat on I almost always use git.

Ian.

#!/bin/bash
set -e

file=$1

perl -pe <$file >$file.mangled '

        BEGIN { $nl=""; }
        if (m/^\S/ || m/^$/) {
                if (defined $subj) {
                        die "$subj ?" if $subj =~ m/rfc/i;
                        $subj =~ s/\[xen-devel\]//i;
                        $subj =~ s/\[patch[ 0-9a-z,]*\]//i;
                        $subj =~ s/\s+/ /g;
                        $subj =~ s/^\s+//; $subj =~ s/\s+$//;
                        print "Subject: $subj\n";
                        $subj= undef;
                        $nl= "\n";
                }
        }
        if (m/^subject:\s+/i) {
                $subj= $'\'';
        } elsif (defined $subj) {
                $subj .= $_;
        }
        if (m/^$/) {
                print $nl;
                $nl= "";
        }
        $_="" if defined $subj;
        if ($last =~ m/^signed-off-by/i && !m/^signed-off-by/i) {
                print <<END or die $!;

END
#Acked-by: Ian Jackson <[email protected]> #
#Acked-by: Ian Campbell <[email protected]>

        }
        $last= $_;

'

formail -s hg import - < $file.mangled

#50 lore raw

2011/11/22 Ian Jackson <[email protected]>:

Quoted 4 lines

I'm afraid I don't know.  With my upstream hat on, for applying patches, I have an absolutely hideous script.  (Below but don't read it if you want to keep your lunch.)  With my contributor hat on I almost always use git.

Thanks for the script, I will try to import this series later this week if I can get my hands on an unused virtualization server (right now all my available servers are busy). Shouldn't we agree on having only one repository format? Either git or mercurial is fine for me, but it will avoid this kind of situations.

Regards, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#51 lore raw

Roger Pau Monné writes ("Re: [Xen-devel] [PATCH RFC v2 00/13] New event API"):

Quoted 11 lines

2011/11/22 Ian Jackson <[email protected]>:

Quoted 4 lines

I'm afraid I don't know.  With my upstream hat on, for applying patches, I have an absolutely hideous script.  (Below but don't read it if you want to keep your lunch.)  With my contributor hat on I almost always use git.

Thanks for the script, I will try to import this series later this week if I can get my hands on an unused virtualization server (right now all my available servers are busy). Shouldn't we agree on having only one repository format? Either git or mercurial is fine for me, but it will avoid this kind of situations.

Well, with my contributor hat on you can pry my git out of my cold dead fingers.

With my upstream hat on, I'm happy to accept patches generated by any reasonable vcs (or none). But I don't think we have a consensus to change xen-unstable to git.

Ian.