New event API
v5 cover New event API
Yet another version of my event handling API series I'm afraid. This addresses all comments so far.
Many of the earlier parts of the series have been acked and are reposted for completeness. Hopefully we will be able to apply these early parts 01-13 soon:
01/18 libxl: Make libxl__xs_* more const-correct
02/18 libxenstore: Provide xs_check_watch
03/18 libxl: Provide a version of bsd's queue.h as _libxl_list.h 04/18 libxl: idl: support new "private" type attribute 05/18 libxl: idl: Provide struct and union tags
06/18 libxl: permit declaration after statement
07/18 libxl: internal convenience macros
08/18 libxl: Rationalise #includes
09/18 libxl: introduce lock in libxl_ctx
10/18 libxl: make libxl__[v]log const-correct
11/18 libxl: make libxl__free_all idempotent
* 12/18 libxl: libxl_ctx_free should free the ctx
13/18 libxl: Use GC_INIT and GC_FREE everywhere
Of these 12/18 is new but I think obviously correct. After that's acked, and test passes and patch backlog permitting, I intend to apply those.
And here are the remaining patches, including the meat, which are still undergoing review:
14/18 libxl: make LIBXL_INIT_GC a statement, not an initialiser 15/18 xenstore: New function xs_path_is_subpath 16/18 libxl: rename libxl__free_all
17/18 libxl: New API for providing OS events to libxl 18/18 libxl: New event generation API
PATCH v5 1/18 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
@@ -172,18 +172,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) */ _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
tools/libxl/libxl_xshelp.c +5 -4
@@ -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
PATCH v5 2/18 libxenstore: Provide xs_check_watch
In reply to Ian JacksonEvent-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/Makefile | 2 +- tools/xenstore/xs.c | 89 ++++++++++++++++++++++++++++++++++++++++------ tools/xenstore/xs.h | 16 ++++++++ 3 files changed, 94 insertions(+), 13 deletions(-)
tools/xenstore/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT=$(CURDIR)/../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 3.0 -MINOR = 0 +MINOR = 1 CFLAGS += -Werror CFLAGS += -I.
tools/xenstore/xs.c +77 -12
176 lines not on this page · raw message
tools/xenstore/xs.h +16 -0
@@ -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
PATCH v5 3/18 libxl: Provide a version of bsd's queue.h as _libxl_list.h
In reply to Ian JacksonWe 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.
(A note on copyright: The FreeBSD files we are adding have an [L]GPL-compatible licence, so there is no need to change our COPYING. Although FreeBSD's queue.3 still contains the advertising clause, this has been withdrawn by UCB as recorded in the FreeBSD COPYRIGHT file, which is included in tools/libxl/external/ for reference.)
--- tools/libxl/Makefile | 12 +- tools/libxl/bsd-sys-queue-h-seddery | 70 +++ tools/libxl/external/README | 14 + tools/libxl/external/bsd-COPYRIGHT | 126 ++++ tools/libxl/external/bsd-queue.3 | 1044 ++++++++++++++++++++++++++++++++++ tools/libxl/external/bsd-sys-queue.h | 637 +++++++++++++++++++++ 6 files changed, 1899 insertions(+), 4 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-COPYRIGHT create mode 100644 tools/libxl/external/bsd-queue.3 create mode 100644 tools/libxl/external/bsd-sys-queue.h
tools/libxl/Makefile +8 -4
@@ -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
@@ -143,7 +147,7 @@ install: all ln -sf libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(LIBDIR)/libxlutil.so.$(XLUMAJOR) ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so $(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR) - $(INSTALL_DATA) libxl.h libxl_json.h _libxl_types.h _libxl_types_json.h libxl_utils.h libxl_uuid.h $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_DATA) libxl.h libxl_json.h _libxl_types.h _libxl_types_json.h _libxl_list.h libxl_utils.h libxl_uuid.h $(DESTDIR)$(INCLUDEDIR) $(INSTALL_DATA) bash-completion $(DESTDIR)$(BASH_COMPLETION_DIR)/xl.sh .PHONY: clean
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 +14 -0
@@ -0,0 +1,14 @@ +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-COPYRIGHT +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 + svn cat -r 221843 http://svn.freebsd.org/base/head/COPYRIGHT >tools/libxl/external/bsd-COPYRIGHT
tools/libxl/external/bsd-COPYRIGHT new file +126 -0
126 lines not on this page · raw message
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
PATCH v5 4/18 libxl: idl: support new "private" type attribute
In reply to Ian JacksonThis provides for fields in libxl datatypes which are only present in the C version of structures and are used only by libxl itself. This is useful 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 +++- tools/python/genwrap.py | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletions(-)
tools/libxl/gentest.py +2 -0
@@ -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.private: + pass elif ty.typename in handcoded: raise Exception("Gen for handcoded %s" % ty.typename) else:
tools/libxl/libxltypes.py +3 -1
@@ -33,6 +33,8 @@ class Type(object): if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE]: raise ValueError + self.private = kwargs.setdefault('private', False) + if typename is None: # Anonymous type self.typename = None self.rawname = None
@@ -50,7 +52,7 @@ class Type(object): self.autogenerate_dispose_fn = kwargs.setdefault('autogenerate_dispose_fn', True) - if self.typename is not None: + if self.typename is not None and not self.private: self.json_fn = kwargs.setdefault('json_fn', self.typename + "_gen_json") else: self.json_fn = kwargs.setdefault('json_fn', None)
tools/python/genwrap.py +6 -0
@@ -129,6 +129,8 @@ static PyObject *Py%(rawname)s_new(PyTypeObject *type, PyObject *args, PyObject l.append('static PyGetSetDef Py%s_getset[] = {'%ty.rawname) for f in ty.fields: + if f.type.private: + continue l.append(' { .name = "%s", '%f.name) if ty.marshal_out(): l.append(' .get = (getter)py_%s_%s_get, '%(ty.rawname, f.name))
@@ -295,9 +297,13 @@ _hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask); """ % tuple((' '.join(sys.argv),) + (os.path.split(decls)[-1:]),)) for ty in types: + if ty.private: + continue if isinstance(ty, libxltypes.Aggregate): f.write('/* Attribute get/set functions for %s */\n'%ty.typename) for a in ty.fields: + if a.type.private: + continue if ty.marshal_out(): f.write(py_attrib_get(ty,a)) if ty.marshal_in():
Signature · 1 line
1.7.2.5
PATCH v5 5/18 libxl: idl: Provide struct and union tags
In reply to Ian JacksonInstead 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
@@ -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
PATCH v5 6/18 libxl: permit declaration after statement
In reply to Ian JacksonGCC 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
@@ -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
PATCH v5 7/18 libxl: internal convenience macros
In reply to Ian JacksonProvide 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
@@ -646,6 +646,54 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s); _hidden libxl_device_model_versionlibxl__device_model_version_running (libxl__gc *gc,uint32_t domid); + +/* +* 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
PATCH v5 8/18 libxl: Rationalise #includes
In reply to Ian Jacksonlibxl_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 | 1 - 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 | 3 ++- 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(+), 38 deletions(-)
tools/libxl/libxl.c +0 -3
@@ -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
@@ -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
@@ -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 4096#define BOOTLOADER_TIMEOUT 1
tools/libxl/libxl_cpuid.c +0 -4
@@ -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_dispose (libxl_cpuid_policy_list *p_cpuid_list)
tools/libxl/libxl_create.c +1 -3
@@ -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_dispose (libxl_domain_config *d_config) {
tools/libxl/libxl_device.c +0 -1
@@ -24,7 +24,6 @@#include <unistd.h> #include <fcntl.h> -#include "libxl.h" #include "libxl_internal.h" char *libxl__device_frontend_path (libxl__gc *gc,libxl__device *device)
tools/libxl/libxl_dm.c +1 -3
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 -1
@@ -12,6 +12,8 @@* GNU Lesser General Public License for more details. */ +#include "libxl_osdeps.h" +#include <assert.h> #include <string.h> #include <math.h>
@@ -19,7 +21,6 @@#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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v5 9/18 libxl: introduce lock in libxl_ctx
In reply to Ian JacksonThis lock will be used to protect data structures which will be hung off the libxl_ctx in subsequent patches.
--- tools/libxl/libxl.c | 6 ++++++ tools/libxl/libxl_internal.h | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +6 -0
@@ -41,6 +41,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version, {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 ;
@@ -54,6 +55,11 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,memset (ctx,0 ,sizeof (libxl_ctx)); ctx->lg = lg; +/* This somewhat convoluted approach is needed because +* PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is defined to be valid +* only as an initialiser, not as an expression. */ +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 +27 -0
@@ -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,18 @@ struct libxl__ctx {xc_interface *xch;struct xs_handle *xsh; +pthread_mutex_t lock;/* protects data structures hanging off the ctx */ +/* Always use CTX_LOCK and CTX_UNLOCK to manipulate this. +* +* You may acquire this mutex recursively if it is convenient to +* do so. You may not acquire this lock at the same time as any +* other lock. If you need to call application code outside +* libxl (ie, a callback) with this lock held then it is +* necessaray to impose restrictions on the caller to maintain a +* proper lock hierarchy, and these restrictions must then be +* documented in the libxl public interface. +*/ +/* 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 */
@@ -668,6 +681,20 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);#define CTX libxl__gc_owner(gc) +/* Locking functions. See comment for "lock" member of libxl__ctx. */ + +#define CTX_LOCK do { \ + int mutex_r = pthread_mutex_lock(&CTX->lock); \ + assert(!mutex_r); \ + } while(0) + +#define CTX_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
PATCH v5 10/18 libxl: make libxl__[v]log const-correct
In reply to Ian Jackson--- 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
@@ -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
@@ -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
PATCH v5 11/18 libxl: make libxl__free_all idempotent
In reply to Ian Jackson--- tools/libxl/libxl_internal.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.c +2 -0
@@ -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
PATCH v5 12/18 libxl: libxl_ctx_free should free the ctx
In reply to Ian Jackson--- tools/libxl/libxl.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +1 -0
@@ -93,6 +93,7 @@ int libxl_ctx_free(libxl_ctx *ctx)if (ctx->xch)xc_interface_close (ctx->xch);libxl_version_info_dispose (&ctx->version_info);if (ctx->xsh)xs_daemon_close (ctx->xsh); +free (ctx);return 0 ; }
Signature · 1 line
1.7.2.5
Re: [PATCH 12/18] libxl: libxl_ctx_free should free the ctx
Quoted 1 line · Ian Jackson
Signed-off-by Ian Jackson <[email protected]>
I introduced this error when I switch things from libxl_ctx_init to libxl_ctx_alloc, sorry. By way of making up for it:
Quoted 16 lines
--- tools/libxl/libxl.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)tools/libxl/libxl.c +1
-0@@ -93,6 +93,7 @@ int libxl_ctx_free(libxl_ctx *ctx)if (ctx->xch)xc_interface_close (ctx->xch);libxl_version_info_dispose (&ctx->version_info);if (ctx->xsh)xs_daemon_close (ctx->xsh); +free (ctx);return 0 ; }
PATCH v5 13/18 libxl: Use GC_INIT and GC_FREE everywhere
In reply to Ian JacksonReplace
libxl__gc gc = LIBXL_INIT_GC(ctx);
...
libxl__free_all(&gc);
with
GC_INIT(ctx);
...
GC_FREE;throughout with a couple of perl runes.
We must then adjust uses of the resulting gc for pointerness, which is mostly just replacing all occurrences of "&gc" with "gc". Also a couple of unusual uses of LIBXL_INIT_GC needed to be fixed up by hand.
Here are those runes:
perl -i -pe 's/\Q libxl__gc gc = LIBXL_INIT_GC(ctx);/ GC_INIT(ctx);/' tools/libxl/*.c
perl -i -pe 's/\Q libxl__free_all(&gc);/ GC_FREE;/' tools/libxl/*.c
--- tools/libxl/libxl.c | 590 ++++++++++++++++++++-------------------- tools/libxl/libxl_bootloader.c | 14 +- tools/libxl/libxl_create.c | 12 +- tools/libxl/libxl_dom.c | 16 +- tools/libxl/libxl_pci.c | 34 ++-- tools/libxl/libxl_qmp.c | 32 +- tools/libxl/libxl_utils.c | 36 ++-- 7 files changed, 367 insertions(+), 367 deletions(-)
tools/libxl/libxl.c +295 -295
@@ -233,19 +233,19 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,int libxl_domain_rename (libxl_ctx *ctx,uint32_t domid,const char *old_name,const char *new_name) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc; - rc =libxl__domain_rename (&gc, domid, old_name, new_name,XBT_NULL ); -libxl__free_all (&gc); + rc =libxl__domain_rename (gc, domid, old_name, new_name,XBT_NULL ); +GC_FREE ;return rc; }int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc =0 ; -if (LIBXL__DOMAIN_IS_TYPE (&gc, domid,HVM )) { +if (LIBXL__DOMAIN_IS_TYPE (gc, domid,HVM )) {LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Called domain_resume on " "non-cooperative hvm domain %u" , domid); rc =ERROR_NI ;
@@ -265,7 +265,7 @@ int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid) rc =ERROR_FAIL ; } out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -278,7 +278,7 @@ out:int libxl_domain_preserve (libxl_ctx *ctx,uint32_t domid,libxl_domain_create_info *info,const char *name_suffix,libxl_uuid new_uuid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);struct xs_permissions roperm[2 ];xs_transaction_t t;char *preserved_name;
@@ -288,27 +288,27 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid,int rc; - preserved_name =libxl__sprintf (&gc,"%s%s" , info->name, name_suffix); + preserved_name =libxl__sprintf (gc,"%s%s" , info->name, name_suffix);if (!preserved_name) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_NOMEM ; } - uuid_string =libxl__uuid2string (&gc, new_uuid); + uuid_string =libxl__uuid2string (gc, new_uuid);if (!uuid_string) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_NOMEM ; } - dom_path =libxl__xs_get_dompath (&gc, domid); + dom_path =libxl__xs_get_dompath (gc, domid);if (!dom_path) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; } - vm_path =libxl__sprintf (&gc,"/vm/%s" , uuid_string); + vm_path =libxl__sprintf (gc,"/vm/%s" , uuid_string);if (!vm_path) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }
@@ -324,20 +324,20 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid,xs_mkdir (ctx->xsh, t, vm_path);xs_set_permissions (ctx->xsh, t, vm_path, roperm,ARRAY_SIZE (roperm)); -xs_write (ctx->xsh, t,libxl__sprintf (&gc,"%s/vm" , dom_path), vm_path,strlen (vm_path)); - rc =libxl__domain_rename (&gc, domid, info->name, preserved_name, t); +xs_write (ctx->xsh, t,libxl__sprintf (gc,"%s/vm" , dom_path), vm_path,strlen (vm_path)); + rc =libxl__domain_rename (gc, domid, info->name, preserved_name, t);if (rc) { -libxl__free_all (&gc); +GC_FREE ;return rc; } -xs_write (ctx->xsh, t,libxl__sprintf (&gc,"%s/uuid" , vm_path), uuid_string,strlen (uuid_string)); +xs_write (ctx->xsh, t,libxl__sprintf (gc,"%s/uuid" , vm_path), uuid_string,strlen (uuid_string));if (!xs_transaction_end (ctx->xsh, t,0 ))if (errno ==EAGAIN ) goto retry_transaction; -libxl__free_all (&gc); +GC_FREE ;return 0 ; }
@@ -479,16 +479,16 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm)int libxl_domain_suspend (libxl_ctx *ctx,libxl_domain_suspend_info *info,uint32_t domid,int fd) { -libxl__gc gc =LIBXL_INIT_GC (ctx); -libxl_domain_type type =libxl__domain_type (&gc, domid); +GC_INIT (ctx); +libxl_domain_type type =libxl__domain_type (gc, domid);int live = info !=NULL && info->flags &XL_SUSPEND_LIVE ;int debug = info !=NULL && info->flags &XL_SUSPEND_DEBUG ;int rc =0 ; - rc =libxl__domain_suspend_common (&gc, domid, fd, type, live, debug); + rc =libxl__domain_suspend_common (gc, domid, fd, type, live, debug);if (!rc && type ==LIBXL_DOMAIN_TYPE_HVM ) - rc =libxl__domain_save_device_model (&gc, domid, fd); -libxl__free_all (&gc); + rc =libxl__domain_save_device_model (gc, domid, fd); +GC_FREE ;return rc; }
@@ -518,17 +518,17 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,int libxl_domain_unpause (libxl_ctx *ctx,uint32_t domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *path;char *state;int ret, rc =0 ; -if (LIBXL__DOMAIN_IS_TYPE (&gc, domid,HVM )) { - path =libxl__sprintf (&gc,"/local/domain/0/device-model/%d/state" , domid); - state =libxl__xs_read (&gc,XBT_NULL , path); +if (LIBXL__DOMAIN_IS_TYPE (gc, domid,HVM )) { + path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/state" , domid); + state =libxl__xs_read (gc,XBT_NULL , path);if (state !=NULL && !strcmp (state,"paused" )) { -libxl__xs_write (&gc,XBT_NULL ,libxl__sprintf (&gc,"/local/domain/0/device-model/%d/command" , domid),"continue" ); -libxl__wait_for_device_model (&gc, domid,"running" , +libxl__xs_write (gc,XBT_NULL ,libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , domid),"continue" ); +libxl__wait_for_device_model (gc, domid,"running" ,NULL ,NULL ,NULL ); } }
@@ -537,7 +537,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"unpausing domain %d" , domid); rc =ERROR_FAIL ; } -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -551,42 +551,42 @@ static char *req_table[] = {int libxl_domain_shutdown (libxl_ctx *ctx,uint32_t domid,int req) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *shutdown_path;char *dom_path;if (req >ARRAY_SIZE (req_table)) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_INVAL ; } - dom_path =libxl__xs_get_dompath (&gc, domid); + dom_path =libxl__xs_get_dompath (gc, domid);if (!dom_path) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; } -if (LIBXL__DOMAIN_IS_TYPE (&gc, domid,HVM )) { +if (LIBXL__DOMAIN_IS_TYPE (gc, domid,HVM )) {unsigned long pvdriver =0 ;int ret; ret =xc_get_hvm_param (ctx->xch, domid,HVM_PARAM_CALLBACK_IRQ , &pvdriver);if (ret<0 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting HVM callback IRQ" ); -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }if (!pvdriver) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"HVM domain without PV drivers:" " graceful shutdown not possible, use destroy" ); -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; } } - shutdown_path =libxl__sprintf (&gc,"%s/control/shutdown" , dom_path); + shutdown_path =libxl__sprintf (gc,"%s/control/shutdown" , dom_path);xs_write (ctx->xsh,XBT_NULL , shutdown_path, req_table[req],strlen (req_table[req])); -libxl__free_all (&gc); +GC_FREE ;return 0 ; }
@@ -608,7 +608,7 @@ int libxl_wait_for_domain_death(libxl_ctx *ctx, uint32_t domid, libxl_waiter *waint 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); +GC_INIT (ctx);int i, rc =-1 ;uint32_t domid =libxl_get_stubdom_id (ctx, guest_domid);
@@ -617,7 +617,7 @@ int libxl_wait_for_disk_ejects(libxl_ctx *ctx, uint32_t guest_domid, libxl_devicfor (i =0 ; i < num_disks; i++) {if (asprintf (&(waiter[i].path),"%s/device/vbd/%d/eject" , -libxl__xs_get_dompath (&gc, domid), +libxl__xs_get_dompath (gc, domid),libxl__device_disk_dev_number (disks[i].vdev,NULL ,NULL )) <0 ) goto out;
@@ -627,7 +627,7 @@ int libxl_wait_for_disk_ejects(libxl_ctx *ctx, uint32_t guest_domid, libxl_devic } rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -681,22 +681,22 @@ int libxl_event_get_domain_death_info(libxl_ctx *ctx, uint32_t domid, libxl_evenint 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); +GC_INIT (ctx);char *path;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 , event->path);if (!value ||strcmp (value,"eject" )) { -libxl__free_all (&gc); +GC_FREE ;return 0 ; } path =strdup (event->path); path[strlen (path) -6 ] ='\0' ; - backend =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/backend" , path)); + backend =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/backend" , path)); sscanf(backend, "/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE) "[a-z]/%*d/%*d",
@@ -712,19 +712,19 @@ int libxl_event_get_disk_eject_info(libxl_ctx *ctx, uint32_t domid, libxl_event disk->pdev_path =strdup ("" ); 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); +GC_FREE ;return 1 ; }int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid,int force) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl_dominfo dominfo;char *dom_path;char *vm_path;
@@ -741,40 +741,40 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force)return rc; } -switch (libxl__domain_type (&gc, domid)) { +switch (libxl__domain_type (gc, domid)) {case LIBXL_DOMAIN_TYPE_HVM : dm_present =1 ;break ;case LIBXL_DOMAIN_TYPE_PV : - pid =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"/local/domain/%d/image/device-model-pid" , domid)); + pid =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"/local/domain/%d/image/device-model-pid" , domid)); dm_present = (pid !=NULL );break ;default :abort (); } - dom_path =libxl__xs_get_dompath (&gc, domid); + dom_path =libxl__xs_get_dompath (gc, domid);if (!dom_path) { rc =ERROR_FAIL ; goto out; } -if (libxl__device_pci_destroy_all (&gc, domid) <0 ) +if (libxl__device_pci_destroy_all (gc, domid) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"pci shutdown failed for domid %d" , domid); rc =xc_domain_pause (ctx->xch, domid);if (rc <0 ) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"xc_domain_pause failed for %d" , domid); }if (dm_present) { -if (libxl__destroy_device_model (&gc, domid) <0 ) +if (libxl__destroy_device_model (gc, domid) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl__destroy_device_model failed for %d" , domid); -libxl__qmp_cleanup (&gc, domid); +libxl__qmp_cleanup (gc, domid); } -if (libxl__devices_destroy (&gc, domid, force) <0 ) +if (libxl__devices_destroy (gc, domid, force) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl_devices_dispose failed for %d" , domid); - vm_path =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/vm" , dom_path)); + vm_path =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/vm" , dom_path));if (vm_path)if (!xs_rm (ctx->xsh,XBT_NULL , vm_path))LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xs_rm failed for %s" , vm_path);
@@ -782,9 +782,9 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force)if (!xs_rm (ctx->xsh,XBT_NULL , dom_path))LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xs_rm failed for %s" , dom_path); -xs_rm (ctx->xsh,XBT_NULL ,libxl__xs_libxl_path (&gc, domid)); +xs_rm (ctx->xsh,XBT_NULL ,libxl__xs_libxl_path (gc, domid)); -libxl__userdata_destroyall (&gc, domid); +libxl__userdata_destroyall (gc, domid); rc =xc_domain_destroy (ctx->xch, domid);if (rc <0 ) {
@@ -794,16 +794,16 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force) } rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_console_exec (libxl_ctx *ctx,uint32_t domid,int cons_num,libxl_console_type type) { -libxl__gc gc =LIBXL_INIT_GC (ctx); -char *p =libxl__sprintf (&gc,"%s/xenconsole" ,libxl_private_bindir_path ()); -char *domid_s =libxl__sprintf (&gc,"%d" , domid); -char *cons_num_s =libxl__sprintf (&gc,"%d" , cons_num); +GC_INIT (ctx); +char *p =libxl__sprintf (gc,"%s/xenconsole" ,libxl_private_bindir_path ()); +char *domid_s =libxl__sprintf (gc,"%d" , domid); +char *cons_num_s =libxl__sprintf (gc,"%d" , cons_num);char *cons_type_s;switch (type) {
@@ -820,20 +820,20 @@ int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num, libxl_consoexecl (p, p, domid_s,"--num" , cons_num_s,"--type" , cons_type_s, (void *)NULL ); out: -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }int libxl_primary_console_exec (libxl_ctx *ctx,uint32_t domid_vm) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);uint32_t stubdomid =libxl_get_stubdom_id (ctx, domid_vm);int rc;if (stubdomid) rc =libxl_console_exec (ctx, stubdomid,STUBDOM_CONSOLE_SERIAL ,LIBXL_CONSOLE_TYPE_PV );else { -switch (libxl__domain_type (&gc, domid_vm)) { +switch (libxl__domain_type (gc, domid_vm)) {case LIBXL_DOMAIN_TYPE_HVM : rc =libxl_console_exec (ctx, domid_vm,0 ,LIBXL_CONSOLE_TYPE_SERIAL );break ;
@@ -844,13 +844,13 @@ int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm)abort (); } } -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_vncviewer_exec (libxl_ctx *ctx,uint32_t domid,int autopass) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);const char *vnc_port;const char *vnc_listen =NULL , *vnc_pass =NULL ;int port =0 , autopass_fd =-1 ;
@@ -861,19 +861,19 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass) NULL, }; - vnc_port =libxl__xs_read (&gc,XBT_NULL , -libxl__sprintf (&gc, + vnc_port =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"/local/domain/%d/console/vnc-port" , domid));if ( vnc_port ) port =atoi (vnc_port) -5900 ; - vnc_listen =libxl__xs_read (&gc,XBT_NULL , -libxl__sprintf (&gc, + vnc_listen =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"/local/domain/%d/console/vnc-listen" , domid));if ( autopass ) - vnc_pass =libxl__xs_read (&gc,XBT_NULL , -libxl__sprintf (&gc, + vnc_pass =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"/local/domain/%d/console/vnc-pass" , domid));if (NULL == vnc_listen )
@@ -882,7 +882,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)if ( (vnc_bin =getenv ("VNCVIEWER" )) ) args[0 ] = vnc_bin; - args[1 ] =libxl__sprintf (&gc,"%s:%d" , vnc_listen, port); + args[1 ] =libxl__sprintf (gc,"%s:%d" , vnc_listen, port);if ( vnc_pass ) {char tmpname[] ="/tmp/vncautopass.XXXXXX" ;
@@ -917,7 +917,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)abort (); x_fail: -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }
@@ -971,17 +971,17 @@ static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,int libxl_device_disk_add (libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);flexarray_t *front;flexarray_t *back;char *dev;libxl__device device;int major, minor, rc; - rc =libxl__device_disk_set_backend (&gc, disk); + rc =libxl__device_disk_set_backend (gc, disk);if (rc) goto out; - rc =libxl__device_disk_set_backend (&gc, disk); + rc =libxl__device_disk_set_backend (gc, disk);if (rc) goto out; front =flexarray_make (16 ,1 );
@@ -1002,7 +1002,7 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *dis goto out_free; } - rc =libxl__device_from_disk (&gc, domid, disk, &device); + rc =libxl__device_from_disk (gc, domid, disk, &device);if (rc !=0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Invalid or unsupported" " virtual disk identifier %s" , disk->vdev);
@@ -1015,7 +1015,7 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *dis do_backend_phy:libxl__device_physdisk_major_minor (dev, &major, &minor);flexarray_append (back,"physical-device" ); -flexarray_append (back,libxl__sprintf (&gc,"%x:%x" , major, minor)); +flexarray_append (back,libxl__sprintf (gc,"%x:%x" , major, minor));flexarray_append (back,"params" );flexarray_append (back, dev);
@@ -1023,13 +1023,13 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disassert (device.backend_kind ==LIBXL__DEVICE_KIND_VBD );break ;case LIBXL_DISK_BACKEND_TAP : - dev =libxl__blktap_devpath (&gc, disk->pdev_path, disk->format); + dev =libxl__blktap_devpath (gc, disk->pdev_path, disk->format);if (!dev) { rc =ERROR_FAIL ; goto out_free; }flexarray_append (back,"tapdisk-params" ); -flexarray_append (back,libxl__sprintf (&gc,"%s:%s" , +flexarray_append (back,libxl__sprintf (gc,"%s:%s" ,libxl__device_disk_string_of_format (disk->format), disk->pdev_path));
@@ -1037,7 +1037,7 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *dis goto do_backend_phy;case LIBXL_DISK_BACKEND_QDISK :flexarray_append (back,"params" ); -flexarray_append (back,libxl__sprintf (&gc,"%s:%s" , +flexarray_append (back,libxl__sprintf (gc,"%s:%s" ,libxl__device_disk_string_of_format (disk->format), disk->pdev_path));assert (device.backend_kind ==LIBXL__DEVICE_KIND_QDISK );break ;
@@ -1048,15 +1048,15 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *dis }flexarray_append (back,"frontend-id" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" , domid)); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid));flexarray_append (back,"online" );flexarray_append (back,"1" );flexarray_append (back,"removable" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" , (disk->removable) ?1 :0 )); +flexarray_append (back,libxl__sprintf (gc,"%d" , (disk->removable) ?1 :0 ));flexarray_append (back,"bootable" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 ));flexarray_append (back,"state" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 ));flexarray_append (back,"dev" );flexarray_append (back, disk->vdev);flexarray_append (back,"type" );
@@ -1067,17 +1067,17 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disflexarray_append (back, disk->is_cdrom ?"cdrom" :"disk" );flexarray_append (front,"backend-id" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" , disk->backend_domid)); +flexarray_append (front,libxl__sprintf (gc,"%d" , disk->backend_domid));flexarray_append (front,"state" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (front,libxl__sprintf (gc,"%d" ,1 ));flexarray_append (front,"virtual-device" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" , device.devid)); +flexarray_append (front,libxl__sprintf (gc,"%d" , device.devid));flexarray_append (front,"device-type" );flexarray_append (front, disk->is_cdrom ?"cdrom" :"disk" ); -libxl__device_generic_add (&gc, &device, -libxl__xs_kvs_of_flexarray (&gc, back, back->count), -libxl__xs_kvs_of_flexarray (&gc, front, front->count)); +libxl__device_generic_add (gc, &device, +libxl__xs_kvs_of_flexarray (gc, back, back->count), +libxl__xs_kvs_of_flexarray (gc, front, front->count)); rc =0 ;
@@ -1085,39 +1085,39 @@ out_free:flexarray_free (back);flexarray_free (front); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_disk_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_disk (&gc, domid, disk, &device); + rc =libxl__device_from_disk (gc, domid, disk, &device);if (rc !=0 ) goto out; - rc =libxl__device_remove (&gc, &device,1 ); + rc =libxl__device_remove (gc, &device,1 ); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_disk_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_disk (&gc, domid, disk, &device); + rc =libxl__device_from_disk (gc, domid, disk, &device);if (rc !=0 ) goto out; - rc =libxl__device_destroy (&gc, &device); + rc =libxl__device_destroy (gc, &device); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -1169,27 +1169,27 @@ static void libxl__device_disk_from_xs_be(libxl__gc *gc,int libxl_devid_to_device_disk (libxl_ctx *ctx,uint32_t domid,int devid,libxl_device_disk *disk) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *dompath, *path;int rc =ERROR_FAIL ;libxl_device_disk_init (ctx, disk); - dompath =libxl__xs_get_dompath (&gc, domid); + dompath =libxl__xs_get_dompath (gc, domid);if (!dompath) { goto out; } - path =libxl__xs_read (&gc,XBT_NULL , -libxl__sprintf (&gc,"%s/device/vbd/%d/backend" , + path =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"%s/device/vbd/%d/backend" , dompath, devid));if (!path) goto out; -libxl__device_disk_from_xs_be (&gc, path, disk); +libxl__device_disk_from_xs_be (gc, path, disk); rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -1229,22 +1229,22 @@ static int libxl__append_disk_list_of_type(libxl__gc *gc,libxl_device_disk *libxl_device_disk_list (libxl_ctx *ctx,uint32_t domid,int *num) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl_device_disk *disks =NULL ;int rc; *num =0 ; - rc =libxl__append_disk_list_of_type (&gc, domid,"vbd" , &disks, num); + rc =libxl__append_disk_list_of_type (gc, domid,"vbd" , &disks, num);if (rc) goto out_err; - rc =libxl__append_disk_list_of_type (&gc, domid,"tap" , &disks, num); + rc =libxl__append_disk_list_of_type (gc, domid,"tap" , &disks, num);if (rc) goto out_err; - rc =libxl__append_disk_list_of_type (&gc, domid,"qdisk" , &disks, num); + rc =libxl__append_disk_list_of_type (gc, domid,"qdisk" , &disks, num);if (rc) goto out_err; -libxl__free_all (&gc); +GC_FREE ;return disks; out_err:
@@ -1260,35 +1260,35 @@ out_err:int libxl_device_disk_getinfo (libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk,libxl_diskinfo *diskinfo) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *dompath, *diskpath;char *val; - dompath =libxl__xs_get_dompath (&gc, domid); + dompath =libxl__xs_get_dompath (gc, domid); diskinfo->devid =libxl__device_disk_dev_number (disk->vdev,NULL ,NULL );/* tap devices entries in xenstore are written as vbd devices. */ - diskpath =libxl__sprintf (&gc,"%s/device/vbd/%d" , dompath, diskinfo->devid); + diskpath =libxl__sprintf (gc,"%s/device/vbd/%d" , dompath, diskinfo->devid); diskinfo->backend =xs_read (ctx->xsh,XBT_NULL , -libxl__sprintf (&gc,"%s/backend" , diskpath),NULL ); +libxl__sprintf (gc,"%s/backend" , diskpath),NULL );if (!diskinfo->backend) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; } - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/backend-id" , diskpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/backend-id" , diskpath)); diskinfo->backend_id = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/state" , diskpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/state" , diskpath)); diskinfo->state = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/event-channel" , diskpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/event-channel" , diskpath)); diskinfo->evtch = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/ring-ref" , diskpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/ring-ref" , diskpath)); diskinfo->rref = val ?strtoul (val,NULL ,10 ) :-1 ; diskinfo->frontend =xs_read (ctx->xsh,XBT_NULL , -libxl__sprintf (&gc,"%s/frontend" , diskinfo->backend),NULL ); - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/frontend-id" , diskinfo->backend)); +libxl__sprintf (gc,"%s/frontend" , diskinfo->backend),NULL ); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/frontend-id" , diskinfo->backend)); diskinfo->frontend_id = val ?strtoul (val,NULL ,10 ) :-1 ; -libxl__free_all (&gc); +GC_FREE ;return 0 ; }
@@ -1332,12 +1332,12 @@ out:char *libxl_device_disk_local_attach (libxl_ctx *ctx,libxl_device_disk *disk) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *dev =NULL ;char *ret =NULL ;int rc; - rc =libxl__device_disk_set_backend (&gc, disk); + rc =libxl__device_disk_set_backend (gc, disk);if (rc) goto out;switch (disk->backend) {
@@ -1356,7 +1356,7 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk) dev = disk->pdev_path;break ;case LIBXL_DISK_FORMAT_VHD : - dev =libxl__blktap_devpath (&gc, disk->pdev_path, + dev =libxl__blktap_devpath (gc, disk->pdev_path, disk->format);break ;case LIBXL_DISK_FORMAT_QCOW :
@@ -1387,7 +1387,7 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk) out:if (dev !=NULL ) ret =strdup (dev); -libxl__free_all (&gc); +GC_FREE ;return ret; }
@@ -1449,7 +1449,7 @@ static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,int libxl_device_nic_add (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);flexarray_t *front;flexarray_t *back;libxl__device device;
@@ -1468,59 +1468,59 @@ int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic) }if (nic->devid ==-1 ) { -if (!(dompath =libxl__xs_get_dompath (&gc, domid))) { +if (!(dompath =libxl__xs_get_dompath (gc, domid))) { rc =ERROR_FAIL ; goto out_free; } -if (!(l =libxl__xs_directory (&gc,XBT_NULL , -libxl__sprintf (&gc,"%s/device/vif" , dompath), &nb))) { +if (!(l =libxl__xs_directory (gc,XBT_NULL , +libxl__sprintf (gc,"%s/device/vif" , dompath), &nb))) { nic->devid =0 ; }else { nic->devid =strtoul (l[nb -1 ],NULL ,10 ) +1 ; } } - rc =libxl__device_from_nic (&gc, domid, nic, &device); + rc =libxl__device_from_nic (gc, domid, nic, &device);if ( rc !=0 ) goto out_free;flexarray_append (back,"frontend-id" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" , domid)); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid));flexarray_append (back,"online" );flexarray_append (back,"1" );flexarray_append (back,"state" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 ));if (nic->script) {flexarray_append (back,"script" );flexarray_append (back, nic->script[0 ]=='/' ? nic->script - :libxl__sprintf (&gc,"%s/%s" , + :libxl__sprintf (gc,"%s/%s" ,libxl_xen_script_dir_path (), nic->script)); }flexarray_append (back,"mac" ); -flexarray_append (back,libxl__sprintf (&gc, +flexarray_append (back,libxl__sprintf (gc,LIBXL_MAC_FMT ,LIBXL_MAC_BYTES (nic->mac)));if (nic->ip) {flexarray_append (back,"ip" ); -flexarray_append (back,libxl__strdup (&gc, nic->ip)); +flexarray_append (back,libxl__strdup (gc, nic->ip)); }flexarray_append (back,"bridge" ); -flexarray_append (back,libxl__strdup (&gc, nic->bridge)); +flexarray_append (back,libxl__strdup (gc, nic->bridge));flexarray_append (back,"handle" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" , nic->devid)); +flexarray_append (back,libxl__sprintf (gc,"%d" , nic->devid));flexarray_append (front,"backend-id" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" , nic->backend_domid)); +flexarray_append (front,libxl__sprintf (gc,"%d" , nic->backend_domid));flexarray_append (front,"state" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (front,libxl__sprintf (gc,"%d" ,1 ));flexarray_append (front,"handle" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" , nic->devid)); +flexarray_append (front,libxl__sprintf (gc,"%d" , nic->devid));flexarray_append (front,"mac" ); -flexarray_append (front,libxl__sprintf (&gc, +flexarray_append (front,libxl__sprintf (gc,LIBXL_MAC_FMT ,LIBXL_MAC_BYTES (nic->mac))); -libxl__device_generic_add (&gc, &device, -libxl__xs_kvs_of_flexarray (&gc, back, back->count), -libxl__xs_kvs_of_flexarray (&gc, front, front->count)); +libxl__device_generic_add (gc, &device, +libxl__xs_kvs_of_flexarray (gc, back, back->count), +libxl__xs_kvs_of_flexarray (gc, front, front->count));/* FIXME: wait for plug */ rc =0 ;
@@ -1528,39 +1528,39 @@ out_free:flexarray_free (back);flexarray_free (front); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_nic_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_nic (&gc, domid, nic, &device); + rc =libxl__device_from_nic (gc, domid, nic, &device);if (rc !=0 ) goto out; - rc =libxl__device_remove (&gc, &device,1 ); + rc =libxl__device_remove (gc, &device,1 ); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_nic_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_nic (&gc, domid, nic, &device); + rc =libxl__device_from_nic (gc, domid, nic, &device);if (rc !=0 ) goto out; - rc =libxl__device_destroy (&gc, &device); + rc =libxl__device_destroy (gc, &device); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -1608,26 +1608,26 @@ static void libxl__device_nic_from_xs_be(libxl__gc *gc,int libxl_devid_to_device_nic (libxl_ctx *ctx,uint32_t domid,int devid,libxl_device_nic *nic) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *dompath, *path;int rc =ERROR_FAIL ;memset (nic,0 ,sizeof (libxl_device_nic)); - dompath =libxl__xs_get_dompath (&gc, domid); + dompath =libxl__xs_get_dompath (gc, domid);if (!dompath) goto out; - path =libxl__xs_read (&gc,XBT_NULL , -libxl__sprintf (&gc,"%s/device/vif/%d/backend" , + path =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"%s/device/vif/%d/backend" , dompath, devid));if (!path) goto out; -libxl__device_nic_from_xs_be (&gc, path, nic); +libxl__device_nic_from_xs_be (gc, path, nic); rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -1666,16 +1666,16 @@ static int libxl__append_nic_list_of_type(libxl__gc *gc,libxl_device_nic *libxl_device_nic_list (libxl_ctx *ctx,uint32_t domid,int *num) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl_device_nic *nics =NULL ;int rc; *num =0 ; - rc =libxl__append_nic_list_of_type (&gc, domid,"vif" , &nics, num); + rc =libxl__append_nic_list_of_type (gc, domid,"vif" , &nics, num);if (rc) goto out_err; -libxl__free_all (&gc); +GC_FREE ;return nics; out_err:
@@ -1691,36 +1691,36 @@ out_err:int libxl_device_nic_getinfo (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic,libxl_nicinfo *nicinfo) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *dompath, *nicpath;char *val; - dompath =libxl__xs_get_dompath (&gc, domid); + dompath =libxl__xs_get_dompath (gc, domid); nicinfo->devid = nic->devid; - nicpath =libxl__sprintf (&gc,"%s/device/vif/%d" , dompath, nicinfo->devid); + nicpath =libxl__sprintf (gc,"%s/device/vif/%d" , dompath, nicinfo->devid); nicinfo->backend =xs_read (ctx->xsh,XBT_NULL , -libxl__sprintf (&gc,"%s/backend" , nicpath),NULL ); +libxl__sprintf (gc,"%s/backend" , nicpath),NULL );if (!nicinfo->backend) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; } - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/backend-id" , nicpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/backend-id" , nicpath)); nicinfo->backend_id = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/state" , nicpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/state" , nicpath)); nicinfo->state = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/event-channel" , nicpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/event-channel" , nicpath)); nicinfo->evtch = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/tx-ring-ref" , nicpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/tx-ring-ref" , nicpath)); nicinfo->rref_tx = val ?strtoul (val,NULL ,10 ) :-1 ; - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/rx-ring-ref" , nicpath)); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/rx-ring-ref" , nicpath)); nicinfo->rref_rx = val ?strtoul (val,NULL ,10 ) :-1 ; nicinfo->frontend =xs_read (ctx->xsh,XBT_NULL , -libxl__sprintf (&gc,"%s/frontend" , nicinfo->backend),NULL ); - val =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/frontend-id" , nicinfo->backend)); +libxl__sprintf (gc,"%s/frontend" , nicinfo->backend),NULL ); + val =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/frontend-id" , nicinfo->backend)); nicinfo->frontend_id = val ?strtoul (val,NULL ,10 ) :-1 ; -libxl__free_all (&gc); +GC_FREE ;return 0 ; }
@@ -1826,7 +1826,7 @@ static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,int libxl_device_vkb_add (libxl_ctx *ctx,uint32_t domid,libxl_device_vkb *vkb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);flexarray_t *front;flexarray_t *back;libxl__device device;
@@ -1843,64 +1843,64 @@ int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb) goto out_free; } - rc =libxl__device_from_vkb (&gc, domid, vkb, &device); + rc =libxl__device_from_vkb (gc, domid, vkb, &device);if (rc !=0 ) goto out_free;flexarray_append (back,"frontend-id" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" , domid)); +flexarray_append (back,libxl__sprintf (gc,"%d" , domid));flexarray_append (back,"online" );flexarray_append (back,"1" );flexarray_append (back,"state" ); -flexarray_append (back,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (back,libxl__sprintf (gc,"%d" ,1 ));flexarray_append (back,"domain" ); -flexarray_append (back,libxl__domid_to_name (&gc, domid)); +flexarray_append (back,libxl__domid_to_name (gc, domid));flexarray_append (front,"backend-id" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" , vkb->backend_domid)); +flexarray_append (front,libxl__sprintf (gc,"%d" , vkb->backend_domid));flexarray_append (front,"state" ); -flexarray_append (front,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append (front,libxl__sprintf (gc,"%d" ,1 )); -libxl__device_generic_add (&gc, &device, -libxl__xs_kvs_of_flexarray (&gc, back, back->count), -libxl__xs_kvs_of_flexarray (&gc, front, front->count)); +libxl__device_generic_add (gc, &device, +libxl__xs_kvs_of_flexarray (gc, back, back->count), +libxl__xs_kvs_of_flexarray (gc, front, front->count)); rc =0 ; out_free:flexarray_free (back);flexarray_free (front); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_vkb_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_vkb *vkb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_vkb (&gc, domid, vkb, &device); + rc =libxl__device_from_vkb (gc, domid, vkb, &device);if (rc !=0 ) goto out; - rc =libxl__device_remove (&gc, &device,1 ); + rc =libxl__device_remove (gc, &device,1 ); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_vkb_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_vkb *vkb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_vkb (&gc, domid, vkb, &device); + rc =libxl__device_from_vkb (gc, domid, vkb, &device);if (rc !=0 ) goto out; - rc =libxl__device_destroy (&gc, &device); + rc =libxl__device_destroy (gc, &device); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -1936,7 +1936,7 @@ static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid,int libxl_device_vfb_add (libxl_ctx *ctx,uint32_t domid,libxl_device_vfb *vfb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);flexarray_t *front;flexarray_t *back;libxl__device device;
@@ -1953,20 +1953,20 @@ int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb) goto out_free; } - rc =libxl__device_from_vfb (&gc, domid, vfb, &device); + rc =libxl__device_from_vfb (gc, domid, vfb, &device);if (rc !=0 ) goto out_free; -flexarray_append_pair (back,"frontend-id" ,libxl__sprintf (&gc,"%d" , domid)); +flexarray_append_pair (back,"frontend-id" ,libxl__sprintf (gc,"%d" , domid));flexarray_append_pair (back,"online" ,"1" ); -flexarray_append_pair (back,"state" ,libxl__sprintf (&gc,"%d" ,1 )); -flexarray_append_pair (back,"domain" ,libxl__domid_to_name (&gc, domid)); -flexarray_append_pair (back,"vnc" ,libxl__sprintf (&gc,"%d" , vfb->vnc)); +flexarray_append_pair (back,"state" ,libxl__sprintf (gc,"%d" ,1 )); +flexarray_append_pair (back,"domain" ,libxl__domid_to_name (gc, domid)); +flexarray_append_pair (back,"vnc" ,libxl__sprintf (gc,"%d" , vfb->vnc));flexarray_append_pair (back,"vnclisten" , vfb->vnclisten);flexarray_append_pair (back,"vncpasswd" , vfb->vncpasswd); -flexarray_append_pair (back,"vncdisplay" ,libxl__sprintf (&gc,"%d" , vfb->vncdisplay)); -flexarray_append_pair (back,"vncunused" ,libxl__sprintf (&gc,"%d" , vfb->vncunused)); -flexarray_append_pair (back,"sdl" ,libxl__sprintf (&gc,"%d" , vfb->sdl)); -flexarray_append_pair (back,"opengl" ,libxl__sprintf (&gc,"%d" , vfb->opengl)); +flexarray_append_pair (back,"vncdisplay" ,libxl__sprintf (gc,"%d" , vfb->vncdisplay)); +flexarray_append_pair (back,"vncunused" ,libxl__sprintf (gc,"%d" , vfb->vncunused)); +flexarray_append_pair (back,"sdl" ,libxl__sprintf (gc,"%d" , vfb->sdl)); +flexarray_append_pair (back,"opengl" ,libxl__sprintf (gc,"%d" , vfb->opengl));if (vfb->xauthority) {flexarray_append_pair (back,"xauthority" , vfb->xauthority); }
@@ -1974,50 +1974,50 @@ int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb)flexarray_append_pair (back,"display" , vfb->display); } -flexarray_append_pair (front,"backend-id" ,libxl__sprintf (&gc,"%d" , vfb->backend_domid)); -flexarray_append_pair (front,"state" ,libxl__sprintf (&gc,"%d" ,1 )); +flexarray_append_pair (front,"backend-id" ,libxl__sprintf (gc,"%d" , vfb->backend_domid)); +flexarray_append_pair (front,"state" ,libxl__sprintf (gc,"%d" ,1 )); -libxl__device_generic_add (&gc, &device, -libxl__xs_kvs_of_flexarray (&gc, back, back->count), -libxl__xs_kvs_of_flexarray (&gc, front, front->count)); +libxl__device_generic_add (gc, &device, +libxl__xs_kvs_of_flexarray (gc, back, back->count), +libxl__xs_kvs_of_flexarray (gc, front, front->count)); rc =0 ; out_free:flexarray_free (front);flexarray_free (back); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_vfb_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_vfb *vfb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_vfb (&gc, domid, vfb, &device); + rc =libxl__device_from_vfb (gc, domid, vfb, &device);if (rc !=0 ) goto out; - rc =libxl__device_remove (&gc, &device,1 ); + rc =libxl__device_remove (gc, &device,1 ); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_vfb_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_vfb *vfb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl__device device;int rc; - rc =libxl__device_from_vfb (&gc, domid, vfb, &device); + rc =libxl__device_from_vfb (gc, domid, vfb, &device);if (rc !=0 ) goto out; - rc =libxl__device_destroy (&gc, &device); + rc =libxl__device_destroy (gc, &device); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -2025,13 +2025,13 @@ out:int libxl_domain_setmaxmem (libxl_ctx *ctx,uint32_t domid,uint32_t max_memkb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *mem, *endptr;uint32_t memorykb; -char *dompath =libxl__xs_get_dompath (&gc, domid); +char *dompath =libxl__xs_get_dompath (gc, domid);int rc =1 ; - mem =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/memory/target" , dompath)); + mem =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/memory/target" , dompath));if (!mem) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"cannot get memory info from %s/memory/target\n" , dompath); goto out;
@@ -2056,7 +2056,7 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb) rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -2164,12 +2164,12 @@ retry:int libxl_set_memory_target (libxl_ctx *ctx,uint32_t domid,int32_t target_memkb,int relative,int enforce) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc =1 , abort =0 ;uint32_t memorykb =0 , videoram =0 ;uint32_t current_target_memkb =0 , new_target_memkb =0 ;char *memmax, *endptr, *videoram_s =NULL , *target =NULL ; -char *dompath =libxl__xs_get_dompath (&gc, domid); +char *dompath =libxl__xs_get_dompath (gc, domid);xc_domaininfo_t info;libxl_dominfo ptr;char *uuid;
@@ -2178,11 +2178,11 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, retry_transaction: t =xs_transaction_start (ctx->xsh); - target =libxl__xs_read (&gc, t,libxl__sprintf (&gc, + target =libxl__xs_read (gc, t,libxl__sprintf (gc,"%s/memory/target" , dompath));if (!target && !domid) {xs_transaction_end (ctx->xsh, t,1 ); - rc =libxl__fill_dom0_memory_info (&gc, ¤t_target_memkb); + rc =libxl__fill_dom0_memory_info (gc, ¤t_target_memkb);if (rc <0 ) { abort =1 ; goto out;
@@ -2204,7 +2204,7 @@ retry_transaction: goto out; } } - memmax =libxl__xs_read (&gc, t,libxl__sprintf (&gc, + memmax =libxl__xs_read (gc, t,libxl__sprintf (gc,"%s/memory/static-max" , dompath));if (!memmax) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
@@ -2244,7 +2244,7 @@ retry_transaction: abort =1 ; goto out; } - videoram_s =libxl__xs_read (&gc, t,libxl__sprintf (&gc, + videoram_s =libxl__xs_read (gc, t,libxl__sprintf (gc,"%s/memory/videoram" , dompath)); videoram = videoram_s ?atoi (videoram_s) :0 ;
@@ -2273,7 +2273,7 @@ retry_transaction: goto out; } -libxl__xs_write (&gc, t,libxl__sprintf (&gc,"%s/memory/target" , +libxl__xs_write (gc, t,libxl__sprintf (gc,"%s/memory/target" , dompath),"%" PRIu32, new_target_memkb); rc =xc_domain_getinfolist (ctx->xch, domid,1 , &info);if (rc !=1 || info.domain != domid) {
@@ -2281,8 +2281,8 @@ retry_transaction: goto out; }xcinfo2xlinfo (&info, &ptr); - uuid =libxl__uuid2string (&gc, ptr.uuid); -libxl__xs_write (&gc, t,libxl__sprintf (&gc,"/vm/%s/memory" , uuid), + uuid =libxl__uuid2string (gc, ptr.uuid); +libxl__xs_write (gc, t,libxl__sprintf (gc,"/vm/%s/memory" , uuid),"%" PRIu32, new_target_memkb /1024 ); out:
@@ -2290,22 +2290,22 @@ out:if (errno ==EAGAIN ) goto retry_transaction; -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_get_memory_target (libxl_ctx *ctx,uint32_t domid,uint32_t *out_target) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc =1 ;char *target =NULL , *endptr =NULL ; -char *dompath =libxl__xs_get_dompath (&gc, domid); +char *dompath =libxl__xs_get_dompath (gc, domid);uint32_t target_memkb; - target =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc, + target =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/memory/target" , dompath));if (!target && !domid) { - rc =libxl__fill_dom0_memory_info (&gc, &target_memkb); + rc =libxl__fill_dom0_memory_info (gc, &target_memkb);if (rc <0 ) goto out; }else if (!target) {
@@ -2326,14 +2326,14 @@ int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t *out_target rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_domain_need_memory (libxl_ctx *ctx,libxl_domain_build_info *b_info,libxl_device_model_info *dm_info,uint32_t *need_memkb) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc =ERROR_INVAL ; *need_memkb = b_info->target_memkb;switch (b_info->type) {
@@ -2352,7 +2352,7 @@ int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info, *need_memkb += (2 *1024 ) - (*need_memkb % (2 *1024 )); rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -2362,12 +2362,12 @@ int libxl_get_free_memory(libxl_ctx *ctx, uint32_t *memkb)int rc =0 ;libxl_physinfo info;uint32_t freemem_slack; -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx); rc =libxl_get_physinfo (ctx, &info);if (rc <0 ) goto out; - rc =libxl__get_free_memory_slack (&gc, &freemem_slack); + rc =libxl__get_free_memory_slack (gc, &freemem_slack);if (rc <0 ) goto out;
@@ -2377,7 +2377,7 @@ int libxl_get_free_memory(libxl_ctx *ctx, uint32_t *memkb) *memkb =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -2387,9 +2387,9 @@ int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint32_tint rc =0 ;libxl_physinfo info;uint32_t freemem_slack; -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx); - rc =libxl__get_free_memory_slack (&gc, &freemem_slack); + rc =libxl__get_free_memory_slack (gc, &freemem_slack);if (rc <0 ) goto out;while (wait_secs >0 ) {
@@ -2406,7 +2406,7 @@ int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint32_t rc =ERROR_NOMEM ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -2632,7 +2632,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,int libxl_set_vcpuonline (libxl_ctx *ctx,uint32_t domid,libxl_cpumap *cpumap) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl_dominfo info;char *dompath;xs_transaction_t t;
@@ -2642,14 +2642,14 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap)LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"getting domain info list" ); goto out; } -if (!(dompath =libxl__xs_get_dompath (&gc, domid))) +if (!(dompath =libxl__xs_get_dompath (gc, domid))) goto out; retry_transaction: t =xs_transaction_start (ctx->xsh);for (i =0 ; i <= info.vcpu_max_id; i++) -libxl__xs_write (&gc, t, -libxl__sprintf (&gc,"%s/cpu/%u/availability" , dompath, i), +libxl__xs_write (gc, t, +libxl__sprintf (gc,"%s/cpu/%u/availability" , dompath, i),"%s" ,libxl_cpumap_test (cpumap, i) ?"online" :"offline" );if (!xs_transaction_end (ctx->xsh, t,0 )) {if (errno ==EAGAIN )
@@ -2657,7 +2657,7 @@ retry_transaction: }else rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -2777,12 +2777,12 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, char *trigger_name, uint3int libxl_send_sysrq (libxl_ctx *ctx,uint32_t domid,char sysrq) { -libxl__gc gc =LIBXL_INIT_GC (ctx); -char *dompath =libxl__xs_get_dompath (&gc, domid); +GC_INIT (ctx); +char *dompath =libxl__xs_get_dompath (gc, domid); -libxl__xs_write (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/control/sysrq" , dompath),"%c" , sysrq); +libxl__xs_write (gc,XBT_NULL ,libxl__sprintf (gc,"%s/control/sysrq" , dompath),"%c" , sysrq); -libxl__free_all (&gc); +GC_FREE ;return 0 ; }
@@ -2869,15 +2869,15 @@ void libxl_xen_console_read_finish(libxl_ctx *ctx,uint32_t libxl_vm_get_start_time (libxl_ctx *ctx,uint32_t domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); -char *dompath =libxl__xs_get_dompath (&gc, domid); +GC_INIT (ctx); +char *dompath =libxl__xs_get_dompath (gc, domid);char *vm_path, *start_time;uint32_t ret; vm_path =libxl__xs_read ( - &gc,XBT_NULL ,libxl__sprintf (&gc,"%s/vm" , dompath)); + gc,XBT_NULL ,libxl__sprintf (gc,"%s/vm" , dompath)); start_time =libxl__xs_read ( - &gc,XBT_NULL ,libxl__sprintf (&gc,"%s/start_time" , vm_path)); + gc,XBT_NULL ,libxl__sprintf (gc,"%s/start_time" , vm_path));if (start_time ==NULL ) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR ,-1 ,"Can't get start time of domain '%d'" , domid);
@@ -2885,7 +2885,7 @@ uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid) }else { ret =strtoul (start_time,NULL ,10 ); } -libxl__free_all (&gc); +GC_FREE ;return ret; }
@@ -3038,15 +3038,15 @@ int libxl_create_cpupool(libxl_ctx *ctx, const char *name, int schedid, libxl_cpumap cpumap, libxl_uuid *uuid, uint32_t *poolid) { - libxl__gc gc = LIBXL_INIT_GC(ctx); +GC_INIT (ctx );int rc;int i;xs_transaction_t t;char *uuid_string; - uuid_string =libxl__uuid2string (&gc, *uuid); + uuid_string =libxl__uuid2string (gc, *uuid);if (!uuid_string) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_NOMEM ; }
@@ -3054,7 +3054,7 @@ int libxl_create_cpupool(libxl_ctx *ctx, const char *name, int schedid,if (rc) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"Could not create cpupool" ); -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }
@@ -3065,7 +3065,7 @@ int libxl_create_cpupool(libxl_ctx *ctx, const char *name, int schedid,LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"Error moving cpu to cpupool" );libxl_cpupool_destroy (ctx, *poolid); -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; } }
@@ -3073,16 +3073,16 @@ int libxl_create_cpupool(libxl_ctx *ctx, const char *name, int schedid,for (;;) { t =xs_transaction_start (ctx->xsh); -xs_mkdir (ctx->xsh, t,libxl__sprintf (&gc,"/local/pool/%d" , *poolid)); -libxl__xs_write (&gc, t, -libxl__sprintf (&gc,"/local/pool/%d/uuid" , *poolid), +xs_mkdir (ctx->xsh, t,libxl__sprintf (gc,"/local/pool/%d" , *poolid)); +libxl__xs_write (gc, t, +libxl__sprintf (gc,"/local/pool/%d/uuid" , *poolid),"%s" , uuid_string); -libxl__xs_write (&gc, t, -libxl__sprintf (&gc,"/local/pool/%d/name" , *poolid), +libxl__xs_write (gc, t, +libxl__sprintf (gc,"/local/pool/%d/name" , *poolid),"%s" , name);if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN )) { -libxl__free_all (&gc); +GC_FREE ;return 0 ; } }
@@ -3090,7 +3090,7 @@ int libxl_create_cpupool(libxl_ctx *ctx, const char *name, int schedid,int libxl_cpupool_destroy (libxl_ctx *ctx,uint32_t poolid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc, i;xc_cpupoolinfo_t *info;xs_transaction_t t;
@@ -3098,7 +3098,7 @@ int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid) info =xc_cpupool_getinfo (ctx->xch, poolid);if (info ==NULL ) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_NOMEM ; }
@@ -3132,7 +3132,7 @@ int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid)for (;;) { t =xs_transaction_start (ctx->xsh); -xs_rm (ctx->xsh,XBT_NULL ,libxl__sprintf (&gc,"/local/pool/%d" , poolid)); +xs_rm (ctx->xsh,XBT_NULL ,libxl__sprintf (gc,"/local/pool/%d" , poolid));if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN ))break ;
@@ -3144,21 +3144,21 @@ out1:libxl_cpumap_dispose (&cpumap); out:xc_cpupool_infofree (ctx->xch, info); -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_cpupool_rename (libxl_ctx *ctx,const char *name,uint32_t poolid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);xs_transaction_t t;xc_cpupoolinfo_t *info;int rc; info =xc_cpupool_getinfo (ctx->xch, poolid);if (info ==NULL ) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_NOMEM ; }
@@ -3171,8 +3171,8 @@ int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid)for (;;) { t =xs_transaction_start (ctx->xsh); -libxl__xs_write (&gc, t, -libxl__sprintf (&gc,"/local/pool/%d/name" , poolid), +libxl__xs_write (gc, t, +libxl__sprintf (gc,"/local/pool/%d/name" , poolid),"%s" , name);if (xs_transaction_end (ctx->xsh, t,0 ))
@@ -3187,7 +3187,7 @@ int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid) out:xc_cpupool_infofree (ctx->xch, info); -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -3294,16 +3294,16 @@ out:int libxl_cpupool_movedomain (libxl_ctx *ctx,uint32_t poolid,uint32_t domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc;char *dom_path;char *vm_path;char *poolname;xs_transaction_t t; - dom_path =libxl__xs_get_dompath (&gc, domid); + dom_path =libxl__xs_get_dompath (gc, domid);if (!dom_path) { -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }
@@ -3311,26 +3311,26 @@ int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)if (rc) {LIBXL__LOG_ERRNOVAL (ctx,LIBXL__LOG_ERROR , rc,"Error moving domain to cpupool" ); -libxl__free_all (&gc); +GC_FREE ;return ERROR_FAIL ; }for (;;) { t =xs_transaction_start (ctx->xsh); - poolname =libxl__cpupoolid_to_name (&gc, poolid); - vm_path =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/vm" , dom_path)); + poolname =libxl__cpupoolid_to_name (gc, poolid); + vm_path =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/vm" , dom_path));if (!vm_path)break ; -libxl__xs_write (&gc, t,libxl__sprintf (&gc,"%s/pool_name" , vm_path), +libxl__xs_write (gc, t,libxl__sprintf (gc,"%s/pool_name" , vm_path),"%s" , poolname);if (xs_transaction_end (ctx->xsh, t,0 ) || (errno !=EAGAIN ))break ; } -libxl__free_all (&gc); +GC_FREE ;return 0 ; }
tools/libxl/libxl_bootloader.c +7 -7
@@ -328,7 +328,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,libxl_device_disk *disk, uint32_t domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx );int ret, rc =0 ;char *fifo =NULL ;char *diskpath =NULL ;
@@ -388,7 +388,7 @@ int libxl_run_bootloader(libxl_ctx *ctx, goto out_close; } - args =make_bootloader_args (&gc, info, domid, fifo, diskpath); + args =make_bootloader_args (gc, info, domid, fifo, diskpath);if (args ==NULL ) { rc =ERROR_NOMEM ; goto out_close;
@@ -411,8 +411,8 @@ int libxl_run_bootloader(libxl_ctx *ctx, goto out_close; } - dom_console_xs_path =libxl__sprintf (&gc,"%s/console/tty" ,libxl__xs_get_dompath (&gc, domid)); -libxl__xs_write (&gc,XBT_NULL , dom_console_xs_path,"%s" , dom_console_slave_tty_path); + dom_console_xs_path =libxl__sprintf (gc,"%s/console/tty" ,libxl__xs_get_dompath (gc, domid)); +libxl__xs_write (gc,XBT_NULL , dom_console_xs_path,"%s" , dom_console_slave_tty_path); pid =fork_exec_bootloader (&bootloader_fd, info->u.pv.bootloader, args);if (pid <0 ) {
@@ -435,7 +435,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,fcntl (fifo_fd,F_SETFL ,O_NDELAY ); - blout =bootloader_interact (&gc, xenconsoled_fd, bootloader_fd, fifo_fd); + blout =bootloader_interact (gc, xenconsoled_fd, bootloader_fd, fifo_fd);if (blout ==NULL ) { goto out_close; }
@@ -445,7 +445,7 @@ int libxl_run_bootloader(libxl_ctx *ctx, goto out_close; } -parse_bootloader_result (&gc, info, blout); +parse_bootloader_result (gc, info, blout); rc =0 ; out_close:
@@ -472,7 +472,7 @@ out_close:free (args); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
tools/libxl/libxl_create.c +6 -6
@@ -670,20 +670,20 @@ error_out:int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc; - rc =do_domain_create (&gc, d_config, cb, priv, domid,-1 ); -libxl__free_all (&gc); + rc =do_domain_create (gc, d_config, cb, priv, domid,-1 ); +GC_FREE ;return rc; }int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid,int restore_fd) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc; - rc =do_domain_create (&gc, d_config, cb, priv, domid, restore_fd); -libxl__free_all (&gc); + rc =do_domain_create (gc, d_config, cb, priv, domid, restore_fd); +GC_FREE ;return rc; }
tools/libxl/libxl_dom.c +8 -8
@@ -730,7 +730,7 @@ int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid,const char *userdata_userid, const uint8_t *data, int datalen) { - libxl__gc gc = LIBXL_INIT_GC(ctx); +GC_INIT (ctx );const char *filename;const char *newfilename;int e, rc;
@@ -738,18 +738,18 @@ int libxl_userdata_store(libxl_ctx *ctx, uint32_t domid,FILE *f =NULL ;size_t rs; - filename =userdata_path (&gc, domid, userdata_userid,"d" ); + filename =userdata_path (gc, domid, userdata_userid,"d" );if (!filename) { rc =ERROR_NOMEM ; goto out; }if (!datalen) { - rc =userdata_delete (&gc, filename); + rc =userdata_delete (gc, filename); goto out; } - newfilename =userdata_path (&gc, domid, userdata_userid,"n" ); + newfilename =userdata_path (gc, domid, userdata_userid,"n" );if (!newfilename) { rc =ERROR_NOMEM ; goto out;
@@ -791,7 +791,7 @@ err:LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"cannot write %s for %s" , newfilename, filename); out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -799,13 +799,13 @@ int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,const char *userdata_userid, uint8_t **data_r, int *datalen_r) { - libxl__gc gc = LIBXL_INIT_GC(ctx); +GC_INIT (ctx );const char *filename;int e, rc;int datalen =0 ;void *data =0 ; - filename =userdata_path (&gc, domid, userdata_userid,"d" ); + filename =userdata_path (gc, domid, userdata_userid,"d" );if (!filename) { rc =ERROR_NOMEM ; goto out;
@@ -827,7 +827,7 @@ int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,if (datalen_r) *datalen_r = datalen; rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
tools/libxl/libxl_pci.c +17 -17
@@ -483,7 +483,7 @@ static int is_assigned(libxl_device_pci *assigned, int num_assigned,libxl_device_pci *libxl_device_pci_list_assignable (libxl_ctx *ctx,int *num) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);libxl_device_pci *pcidevs =NULL , *new, *assigned;struct dirent *de;DIR *dir;
@@ -491,7 +491,7 @@ libxl_device_pci *libxl_device_pci_list_assignable(libxl_ctx *ctx, int *num) *num =0 ; - rc =get_all_assigned_devices (&gc, &assigned, &num_assigned); + rc =get_all_assigned_devices (gc, &assigned, &num_assigned);if ( rc ) goto out;
@@ -528,7 +528,7 @@ libxl_device_pci *libxl_device_pci_list_assignable(libxl_ctx *ctx, int *num) out_closedir:closedir (dir); out: -libxl__free_all (&gc); +GC_FREE ;return pcidevs; }
@@ -782,10 +782,10 @@ static int libxl__device_pci_reset(libxl__gc *gc, unsigned int domain, unsignedint libxl_device_pci_add (libxl_ctx *ctx,uint32_t domid,libxl_device_pci *pcidev) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc; - rc =libxl__device_pci_add (&gc, domid, pcidev,0 ); -libxl__free_all (&gc); + rc =libxl__device_pci_add (gc, domid, pcidev,0 ); +GC_FREE ;return rc; }
@@ -1057,24 +1057,24 @@ out:int libxl_device_pci_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_pci *pcidev) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc; - rc =libxl__device_pci_remove_common (&gc, domid, pcidev,0 ); + rc =libxl__device_pci_remove_common (gc, domid, pcidev,0 ); -libxl__free_all (&gc); +GC_FREE ;return rc; }int libxl_device_pci_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_pci *pcidev) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);int rc; - rc =libxl__device_pci_remove_common (&gc, domid, pcidev,1 ); + rc =libxl__device_pci_remove_common (gc, domid, pcidev,1 ); -libxl__free_all (&gc); +GC_FREE ;return rc; }
@@ -1115,15 +1115,15 @@ static void libxl__device_pci_from_xs_be(libxl__gc *gc,libxl_device_pci *libxl_device_pci_list (libxl_ctx *ctx,uint32_t domid,int *num) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *be_path, *num_devs;int n, i;libxl_device_pci *pcidevs =NULL ; *num =0 ; - be_path =libxl__sprintf (&gc,"%s/backend/pci/%d/0" ,libxl__xs_get_dompath (&gc,0 ), domid); - num_devs =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/num_devs" , be_path)); + be_path =libxl__sprintf (gc,"%s/backend/pci/%d/0" ,libxl__xs_get_dompath (gc,0 ), domid); + num_devs =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/num_devs" , be_path));if (!num_devs) goto out;
@@ -1131,11 +1131,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num pcidevs =calloc (n,sizeof (libxl_device_pci));for (i =0 ; i < n; i++) -libxl__device_pci_from_xs_be (&gc, be_path, pcidevs + i, i); +libxl__device_pci_from_xs_be (gc, be_path, pcidevs + i, i); *num = n; out: -libxl__free_all (&gc); +GC_FREE ;return pcidevs; }
tools/libxl/libxl_qmp.c +16 -16
@@ -94,7 +94,7 @@ static int store_serial_port_info(libxl__qmp_handler *qmp,const char *chardev, int port) { - libxl__gc gc = LIBXL_INIT_GC(qmp->ctx); + GC_INIT(qmp->ctx);char *path =NULL ;int ret =0 ;
@@ -102,12 +102,12 @@ static int store_serial_port_info(libxl__qmp_handler *qmp,return 0 ; } - path =libxl__xs_get_dompath (&gc, qmp->domid); - path =libxl__sprintf (&gc,"%s/serial/%d/tty" , path, port); + path =libxl__xs_get_dompath (gc, qmp->domid); + path =libxl__sprintf (gc,"%s/serial/%d/tty" , path, port); - ret =libxl__xs_write (&gc,XBT_NULL , path,"%s" , chardev +4 ); + ret =libxl__xs_write (gc,XBT_NULL , path,"%s" , chardev +4 ); -libxl__free_all (&gc); +GC_FREE ;return ret; }
@@ -521,7 +521,7 @@ static int qmp_synchronous_send(libxl__qmp_handler *qmp, const char *cmd, {int id =0 ;int ret =0 ; -libxl__gc gc =LIBXL_INIT_GC (qmp->ctx); +GC_INIT (qmp->ctx);qmp_request_context context = { .rc =0 }; id =qmp_send (qmp, cmd, args, callback, opaque, &context);
@@ -531,7 +531,7 @@ static int qmp_synchronous_send(libxl__qmp_handler *qmp, const char *cmd, qmp->wait_for_id = id;while (qmp->wait_for_id == id) { -if ((ret =qmp_next (&gc, qmp)) <0 ) { +if ((ret =qmp_next (gc, qmp)) <0 ) {break ; } }
@@ -540,7 +540,7 @@ static int qmp_synchronous_send(libxl__qmp_handler *qmp, const char *cmd, ret = context.rc; } -libxl__free_all (&gc); +GC_FREE ;return ret; }
@@ -559,15 +559,15 @@ libxl__qmp_handler *libxl__qmp_initialize(libxl_ctx *ctx, uint32_t domid)int ret =0 ;libxl__qmp_handler *qmp =NULL ;char *qmp_socket; -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx); qmp =qmp_init_handler (ctx, domid); - qmp_socket =libxl__sprintf (&gc,"%s/qmp-libxl-%d" , + qmp_socket =libxl__sprintf (gc,"%s/qmp-libxl-%d" ,libxl_run_dir_path (), domid);if ((ret =qmp_open (qmp, qmp_socket,QMP_SOCKET_CONNECT_TIMEOUT )) <0 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"Connection error" ); -libxl__free_all (&gc); +GC_FREE ;qmp_free_handler (qmp);return NULL ; }
@@ -576,12 +576,12 @@ libxl__qmp_handler *libxl__qmp_initialize(libxl_ctx *ctx, uint32_t domid)/* Wait for the response to qmp_capabilities */ while (!qmp->connected) { -if ((ret =qmp_next (&gc, qmp)) <0 ) { +if ((ret =qmp_next (gc, qmp)) <0 ) {break ; } } -libxl__free_all (&gc); +GC_FREE ;if (!qmp->connected) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Failed to connect to QMP" );libxl__qmp_close (qmp);
@@ -626,9 +626,9 @@ static int pci_add_callback(libxl__qmp_handler *qmp, {libxl_device_pci *pcidev = opaque;const libxl__json_object *bus =NULL ; -libxl__gc gc =LIBXL_INIT_GC (qmp->ctx); +GC_INIT (qmp->ctx);int i, j, rc =-1 ; -char *asked_id =libxl__sprintf (&gc,PCI_PT_QDEV_ID , +char *asked_id =libxl__sprintf (gc,PCI_PT_QDEV_ID , pcidev->bus, pcidev->dev, pcidev->func);for (i =0 ; (bus =libxl__json_array_get (response, i)); i++) {
@@ -665,7 +665,7 @@ static int pci_add_callback(libxl__qmp_handler *qmp, out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
tools/libxl/libxl_utils.c +18 -18
@@ -186,29 +186,29 @@ char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid)int libxl_get_stubdom_id (libxl_ctx *ctx,int guest_domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char * stubdom_id_s;int ret; - stubdom_id_s =libxl__xs_read (&gc,XBT_NULL , -libxl__sprintf (&gc,"%s/image/device-model-domid" , -libxl__xs_get_dompath (&gc, guest_domid))); + stubdom_id_s =libxl__xs_read (gc,XBT_NULL , +libxl__sprintf (gc,"%s/image/device-model-domid" , +libxl__xs_get_dompath (gc, guest_domid)));if (stubdom_id_s) ret =atoi (stubdom_id_s);else ret =0 ; -libxl__free_all (&gc); +GC_FREE ;return ret; }int libxl_is_stubdom (libxl_ctx *ctx,uint32_t domid,uint32_t *target_domid) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);char *target, *endptr;uint32_t value;int ret =0 ; - target =libxl__xs_read (&gc,XBT_NULL ,libxl__sprintf (&gc,"%s/target" ,libxl__xs_get_dompath (&gc, domid))); + target =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/target" ,libxl__xs_get_dompath (gc, domid)));if (!target) goto out; value =strtol (target, &endptr,10 );
@@ -218,7 +218,7 @@ int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid) *target_domid = value; ret =1 ; out: -libxl__free_all (&gc); +GC_FREE ;return ret; }
@@ -240,27 +240,27 @@ static int logrename(libxl__gc *gc, const char *old, const char *new)int libxl_create_logfile (libxl_ctx *ctx,char *name,char **full_name) { -libxl__gc gc =LIBXL_INIT_GC (ctx); +GC_INIT (ctx);struct stat stat_buf;char *logfile, *logfile_new;int i, rc; - logfile =libxl__sprintf (&gc,"/var/log/xen/%s.log" , name); + logfile =libxl__sprintf (gc,"/var/log/xen/%s.log" , name);if (stat (logfile, &stat_buf) ==0 ) {/* file exists, rotate */ - logfile =libxl__sprintf (&gc,"/var/log/xen/%s.log.10" , name); + logfile =libxl__sprintf (gc,"/var/log/xen/%s.log.10" , name);unlink (logfile);for (i =9 ; i >0 ; i--) { - logfile =libxl__sprintf (&gc,"/var/log/xen/%s.log.%d" , name, i); - logfile_new =libxl__sprintf (&gc,"/var/log/xen/%s.log.%d" , name, i +1 ); - rc =logrename (&gc, logfile, logfile_new); + logfile =libxl__sprintf (gc,"/var/log/xen/%s.log.%d" , name, i); + logfile_new =libxl__sprintf (gc,"/var/log/xen/%s.log.%d" , name, i +1 ); + rc =logrename (gc, logfile, logfile_new);if (rc) goto out; } - logfile =libxl__sprintf (&gc,"/var/log/xen/%s.log" , name); - logfile_new =libxl__sprintf (&gc,"/var/log/xen/%s.log.1" , name); + logfile =libxl__sprintf (gc,"/var/log/xen/%s.log" , name); + logfile_new =libxl__sprintf (gc,"/var/log/xen/%s.log.1" , name); - rc =logrename (&gc, logfile, logfile_new); + rc =logrename (gc, logfile, logfile_new);if (rc) goto out; }else {
@@ -272,7 +272,7 @@ int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name) *full_name =strdup (logfile); rc =0 ; out: -libxl__free_all (&gc); +GC_FREE ;return rc; }
Signature · 1 line
1.7.2.5
PATCH v5 14/18 libxl: make LIBXL_INIT_GC a statement, not an initialiser
In reply to Ian JacksonPreviously LIBXL_INIT_GC was an initialiser, which you were expected to use like this:
libxl__gc gc = LIBXL_INIT_GC(ctx);
But we are going to want to put things in the gc which are to be initialised using other macros. That means that LIBXL_INIT_GC has to become a statement too. So instead, we make it so that it's used like this:
libxl_gc gc;
LIBXL_INIT_GC(gc,ctx);In fact there is only one caller now, GC_INIT, which uses this trick:
libxl_gc gc[1];
LIBXL_INIT_GC(gc[0],ctx);--- tools/libxl/libxl_internal.h | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
tools/libxl/libxl_internal.h +7 -2
@@ -145,7 +145,12 @@ typedef struct {libxl_ctx *owner; } libxl__gc; -#define LIBXL_INIT_GC (ctx) (libxl__gc){ .alloc_maxsize = 0, .alloc_ptrs = 0, .owner = ctx } +#define LIBXL_INIT_GC (gc,ctx) do{ \ + (gc).alloc_maxsize = 0; \ + (gc).alloc_ptrs = 0; \ + (gc).owner = (ctx); \ + } while(0) +static inline libxl_ctx *libxl__gc_owner (libxl__gc *gc) {return gc->owner;
@@ -676,7 +681,7 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);* as a local variable. */ -#define GC_INIT (ctx) libxl__gc gc[1] = { LIBXL_INIT_GC(ctx) } +#define GC_INIT (ctx) libxl__gc gc[1]; LIBXL_INIT_GC(gc[0],ctx)#define GC_FREE libxl__free_all(gc)#define CTX libxl__gc_owner(gc)
Signature · 1 line
1.7.2.5
PATCH v5 15/18 xenstore: New function xs_path_is_subpath
In reply to Ian JacksonThis utility function compares two paths, textually and reports whether one is a subpath (a child path) of the other.
--- tools/xenstore/xs.c | 17 +++++++++++++++++ tools/xenstore/xs.h | 7 +++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
tools/xenstore/xs.c +17 -0
@@ -950,6 +950,23 @@ char *xs_get_domain_path(struct xs_handle *h, unsigned int domid)return xs_single (h,XBT_NULL ,XS_GET_DOMAIN_PATH , domid_str,NULL ); } +bool xs_path_is_subpath (const char *parent,const char *child) +{ +size_t childlen =strlen (child); +size_t parentlen =strlen (parent); + +if (childlen < parentlen) +return false; + +if (memcmp (child, parent, parentlen)) +return false; + +if (childlen > parentlen && child[parentlen] !='/' ) +return false; + +return true; +} +bool xs_is_domain_introduced (struct xs_handle *h,unsigned int domid) {char *domain =single_with_domid (h,XS_IS_DOMAIN_INTRODUCED , domid);
tools/xenstore/xs.h +7 -0
@@ -207,6 +207,13 @@ bool xs_release_domain(struct xs_handle *h, unsigned int domid);*/ char *xs_get_domain_path (struct xs_handle *h,unsigned int domid); +/* Returns true if child is either equal to parent, or a node underneath +* parent; or false otherwise. Done by string comparison, so relative and +* absolute pathnames never in a parent/child relationship by this +* definition. Cannot fail. +*/ +bool xs_path_is_subpath (const char *parent,const char *child); +/* Return whether the domain specified has been introduced to xenstored. */ bool xs_is_domain_introduced (struct xs_handle *h,unsigned int domid);
Signature · 1 line
1.7.2.5
Re: [PATCH 15/18] xenstore: New function xs_path_is_subpath
Quoted 20 lines · Ian Jackson
This utility function compares two paths, textually and reports whether one is a subpath (a child path) of the other.
Signed-off-by Ian Jackson <[email protected]>--- tools/xenstore/xs.c | 17 +++++++++++++++++ tools/xenstore/xs.h | 7 +++++++ 2 files changed, 24 insertions(+), 0 deletions(-)tools/xenstore/xs.c +3
-0@@ -950,6 +950,23 @@ char *xs_get_domain_path(struct xs_handle *h, unsigned int domid)return xs_single (h,XBT_NULL ,XS_GET_DOMAIN_PATH , domid_str,NULL ); } +bool xs_path_is_subpath (const char *parent,const char *child) +{ +size_t childlen =strlen (child);
tools/xenstore/xs.c char *xs_get_domain_path(struct xs_handle *h, unsigned int domid) · line 965
Quoted 10 lines
tools/xenstore/xs.c +10
-0+size_t parentlen =strlen (parent); + +if (childlen < parentlen) +return false; + +if (memcmp (child, parent, parentlen)) +return false; + +if (childlen > parentlen && child[parentlen] !='/' ) +return false;
It took me a second to figure that this last statement was preventing false positives from sibling directories where one is a substring of the other. Worth a comment?
Doesn't the correctness of this depend on whether parent has a trailing slash or not though?
parent = "foo" len = 3 child = "foo/bar" => child[3] == '/' => GOOD parent = "foo/" len = 4 child = "foo/bar => child[4] == 'b' => BAD.
Does adding
if parent[parentlen] == '/' parentlen--;
beforehand help?
Quoted 25 lines
tools/xenstore/xs.c +4
-0+ +return true; +} +bool xs_is_domain_introduced (struct xs_handle *h,unsigned int domid) {char *domain =single_with_domid (h,XS_IS_DOMAIN_INTRODUCED , domid);tools/xenstore/xs.h +7
-0@@ -207,6 +207,13 @@ bool xs_release_domain(struct xs_handle *h, unsigned int domid);*/ char *xs_get_domain_path (struct xs_handle *h,unsigned int domid); +/* Returns true if child is either equal to parent, or a node underneath +* parent; or false otherwise. Done by string comparison, so relative and +* absolute pathnames never in a parent/child relationship by this +* definition. Cannot fail. +*/ +bool xs_path_is_subpath (const char *parent,const char *child); +/* Return whether the domain specified has been introduced to xenstored. */ bool xs_is_domain_introduced (struct xs_handle *h,unsigned int domid);
Re: [PATCH 15/18] xenstore: New function xs_path_is_subpath
Ian Campbell writes ("Re: [Xen-devel] [PATCH 15/18] xenstore: New function xs_path_is_subpath"):
Quoted 7 lines · Ian Jackson
tools/xenstore/xs.c char *xs_get_domain_path(struct xs_handle *h, unsigned int domid) · line 965
Quoted 2 lines
tools/xenstore/xs.c +2
-0+if (childlen > parentlen && child[parentlen] !='/' ) +return false;It took me a second to figure that this last statement was preventing false positives from sibling directories where one is a substring of the other. Worth a comment?
Probably, yes.
Quoted 2 lines
Doesn't the correctness of this depend on whether parent has a trailing slash or not though?
We don't allow trailing slashes. They don't work in xenstore operations. However, there is one exception: "/". If parent is "/" the algorithm is wrong.
So docs/misc/xenstore.txt needs updating to clarify the former and my new function needs the latter fixing.
These are the perils of taking code that was correct in situ and making a general function out of it, I guess ...
Ian.
PATCH v5 16/18 libxl: rename libxl__free_all
In reply to Ian Jacksonlibxl__free_all is going to gain some extra functionality, which will mean that the name is no longer accurate. Rename it to libxl__gc_cleanup.
--- tools/libxl/libxl.h | 2 +- tools/libxl/libxl_internal.c | 2 +- tools/libxl/libxl_internal.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl.h +1 -1
@@ -119,7 +119,7 @@* * No temporary objects allocated from the pool may be explicitly freed. * Therefore public functions which initialize a libxl__gc MUST call -* libxl__free_all() before returning. +* libxl__gc_cleanup() before returning. */ #ifndef LIBXL_H #define LIBXL_H
tools/libxl/libxl_internal.c +1 -1
@@ -61,7 +61,7 @@ int libxl__ptr_add(libxl__gc *gc, void *ptr)return 0 ; } -void libxl__free_all (libxl__gc *gc) +void libxl__gc_cleanup (libxl__gc *gc) {void *ptr;int i;
tools/libxl/libxl_internal.h +2 -2
@@ -171,7 +171,7 @@ static inline libxl_ctx *libxl__gc_owner(libxl__gc *gc)/* register @ptr in @gc for free on exit from outermost libxl callframe. */ _hidden int libxl__ptr_add(libxl__gc *gc, void *ptr);/* if this is the outermost libxl callframe then free all pointers in @gc */ -_hidden void libxl__free_all(libxl__gc *gc); +_hidden void libxl__gc_cleanup(libxl__gc *gc);/* allocate and zero @bytes. (similar to a gc'd malloc(3)+memzero()) */ _hidden void *libxl__zalloc(libxl__gc *gc, int bytes);/* allocate and zero memory for an array of @nmemb members of @size each.
@@ -682,7 +682,7 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);*/ #define GC_INIT (ctx) libxl__gc gc[1]; LIBXL_INIT_GC(gc[0],ctx) -#define GC_FREE libxl__free_all(gc) +#define GC_FREE libxl__gc_cleanup(gc)#define CTX libxl__gc_owner(gc)
Signature · 1 line
1.7.2.5
Re: [PATCH 16/18] libxl: rename libxl__free_all
Quoted 5 lines · Ian Jackson
libxl__free_allis going to gain some extra functionality, which will mean that the name is no longer accurate. Rename it tolibxl__gc_cleanup.Signed-off-by Ian Jackson <[email protected]>
PATCH v5 17/18 libxl: New API for providing OS events to libxl
In reply to Ian JacksonWe 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 | 30 ++ tools/libxl/libxl.h | 6 + tools/libxl/libxl_event.c | 736 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_event.h | 200 ++++++++++++ tools/libxl/libxl_internal.h | 219 ++++++++++++- 6 files changed, 1189 insertions(+), 4 deletions(-) create mode 100644 tools/libxl/libxl_event.c create mode 100644 tools/libxl/libxl_event.h
tools/libxl/Makefile +1 -1
@@ -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 +30 -0
@@ -60,6 +60,16 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,* only as an initialiser, not as an expression. */ 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 );
@@ -90,9 +100,29 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,int libxl_ctx_free (libxl_ctx *ctx) {if (!ctx)return 0 ; + +int i; +GC_INIT (ctx); + +/* Deregister all libxl__ev_KINDs: */ + +for (i =0 ; i < ctx->watch_nslots; i++) +assert (!libxl__watch_slot_contents (gc, i)); +libxl__ev_fd_deregister (gc, &ctx->watch_efd); + +/* Now there should be no more events requested from the application: */ + +assert (LIBXL_LIST_EMPTY (&ctx->efds)); +assert (LIBXL_TAILQ_EMPTY (&ctx->etimes)); +if (ctx->xch)xc_interface_close (ctx->xch);libxl_version_info_dispose (&ctx->version_info);if (ctx->xsh)xs_daemon_close (ctx->xsh); + +free (ctx->fd_beforepolled); +free (ctx->watch_slots); + +GC_FREE ;free (ctx);return 0 ; }
tools/libxl/libxl.h +6 -0
@@ -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"
@@ -222,6 +223,9 @@ enum {ERROR_BADFAIL =-7 ,ERROR_GUEST_TIMEDOUT =-8 ,ERROR_TIMEDOUT =-9 , +ERROR_NOT_READY =-10 , +ERROR_OSEVENT_REG_FAIL =-11 , + ERROR_BUFFERFULL = -12, };#define LIBXL_VERSION 0
@@ -635,6 +639,8 @@ const char *libxl_lock_dir_path(void);const char *libxl_run_dir_path (void );const char *libxl_xenpaging_dir_path (void ); +#include <libxl_event.h> +#endif /* LIBXL_H */ /*
tools/libxl/libxl_event.c new file +736 -0
736 lines not on this page · raw message
tools/libxl/libxl_event.h new file +200 -0
200 lines not on this page · raw message
tools/libxl/libxl_internal.h +216 -3
261 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v5 18/18 libxl: New event generation API
In reply to Ian JacksonReplace 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 | 329 +++++++++++++++++++++++++++++++----------- tools/libxl/libxl.h | 55 ++------ tools/libxl/libxl_event.c | 200 +++++++++++++++++++++++--- tools/libxl/libxl_event.h | 182 +++++++++++++++++++++++- tools/libxl/libxl_internal.c | 6 + tools/libxl/libxl_internal.h | 87 +++++++++++- tools/libxl/libxl_types.idl | 35 ++++- tools/libxl/xl_cmdimpl.c | 270 ++++++++++++++++++++--------------- 8 files changed, 885 insertions(+), 279 deletions(-)
tools/libxl/libxl.c +241 -88
@@ -60,8 +60,11 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,* only as an initialiser, not as an expression. */ memcpy (&ctx->lock, &mutex_value,sizeof (ctx->lock)); +LIBXL_TAILQ_INIT (&ctx->occurred); + ctx->osevent_hooks =0 ; + ctx->fd_polls =0 ; ctx->fd_beforepolled =0 ;LIBXL_LIST_INIT (&ctx->efds);LIBXL_TAILQ_INIT (&ctx->etimes);
@@ -70,6 +73,9 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,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 );
@@ -97,6 +103,20 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,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); +} + +static void discard_events (struct libxl__event_list *l) { +/* doesn't bother unlinking from the list, so l is corrupt on return */ +libxl_event *ev; + LIBXL_TAILQ_FOREACH(ev, l, link) +libxl_event_free (0 , ev); +} +int libxl_ctx_free (libxl_ctx *ctx) {if (!ctx)return 0 ;
@@ -106,6 +126,13 @@ int libxl_ctx_free(libxl_ctx *ctx)/* Deregister all libxl__ev_KINDs: */ +free_disable_deaths (gc, &CTX ->death_list); +free_disable_deaths (gc, &CTX ->death_reported); + +libxl_evgen_disk_eject *eject; +while ((eject =LIBXL_LIST_FIRST (&CTX ->disk_eject_evgens))) +libxl__evdisable_disk_eject (gc, eject); +for (i =0 ; i < ctx->watch_nslots; i++)assert (!libxl__watch_slot_contents (gc, i));libxl__ev_fd_deregister (gc, &ctx->watch_efd);
@@ -119,9 +146,16 @@ int libxl_ctx_free(libxl_ctx *ctx)libxl_version_info_dispose (&ctx->version_info);if (ctx->xsh)xs_daemon_close (ctx->xsh); +free (ctx->fd_polls);free (ctx->fd_beforepolled);free (ctx->watch_slots); +discard_events (&ctx->occurred); +discard_events (&gc->occurred_for_callback); +/* There shouldn't be any of the latter - they would have had to +* have been generated during libxl_ctx_free - but throwing them +* away is more friendly than asserting. */ +GC_FREE ;free (ctx);return 0 ;
@@ -620,117 +654,173 @@ 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 ; -} +CTX_LOCK ; -int libxl_wait_for_disk_ejects (libxl_ctx *ctx,uint32_t guest_domid,libxl_device_disk *disks,int num_disks,libxl_waiter *waiter) -{ -GC_INIT (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: -GC_FREE ; -return rc; + all_reported: + out: + +CTX_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; + +CTX_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: +CTX_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) { +CTX_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); -return 1 ; +if (!LIBXL_TAILQ_FIRST (&CTX ->death_list) && +libxl__ev_xswatch_isregistered (&CTX ->death_watch)) +libxl__ev_xswatch_deregister (gc, &CTX ->death_watch); + +CTX_UNLOCK ; } -int libxl_event_get_disk_eject_info (libxl_ctx *ctx,uint32_t domid,libxl_event *event,libxl_device_disk *disk) -{ +void libxl_evdisable_domain_death (libxl_ctx *ctx, +libxl_evgen_domain_death *evg) {GC_INIT (ctx); -char *path; +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_disk_eject *evg = (void *)watch;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" )) { -GC_FREE ; -return 0 ; +if (!value ||strcmp (value,"eject" )) +return ; + +if (libxl__xs_write (gc,XBT_NULL , wpath,"" )) { +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" )) {
@@ -739,19 +829,82 @@ 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__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); +CTX_LOCK ; +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->domid = guest_domid; +LIBXL_LIST_INSERT_HEAD (&CTX ->disk_eject_evgens, evg, entry); + + evg->vdev =strdup (vdev); +if (!evg->vdev) { rc =ERROR_NOMEM ; goto out; } + +uint32_t domid =libxl_get_stubdom_id (ctx, guest_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; + +CTX_UNLOCK ;GC_FREE ; -return 1 ; +return 0 ; + + out: +if (evg) +libxl__evdisable_disk_eject (gc, evg); +CTX_UNLOCK ; +GC_FREE ; +return rc; +} + +void libxl__evdisable_disk_eject (libxl__gc *gc,libxl_evgen_disk_eject *evg) { +CTX_LOCK ; + +LIBXL_LIST_REMOVE (evg, entry); + +if (libxl__ev_xswatch_isregistered (&evg->watch)) +libxl__ev_xswatch_deregister (gc, &evg->watch); + +free (evg->vdev); +free (evg); + +CTX_UNLOCK ; } +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) {GC_INIT (ctx);
tools/libxl/libxl.h +9 -46
79 lines not on this page · raw message
tools/libxl/libxl_event.c +183 -17
254 lines not on this page · raw message
tools/libxl/libxl_event.h +178 -4
200 lines not on this page · raw message
tools/libxl/libxl_internal.c +6 -0
@@ -74,6 +74,12 @@ void libxl__gc_cleanup(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 +81 -6
154 lines not on this page · raw message
tools/libxl/libxl_types.idl +30 -5
@@ -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"),
@@ -381,3 +376,33 @@ libxl_sched_credit = Struct("sched_credit", [ ("weight", integer), ("cap", integer), ], dispose_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, private=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 +157 -113
354 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Ian Jackson writes ("[PATCH v5 00/18] New event API"):
Quoted 14 lines
Yet another version of my event handling API series I'm afraid. This addresses all comments so far.
Many of the earlier parts of the series have been acked and are reposted for completeness. Hopefully we will be able to apply these early parts 01-13 soon:
01/18 libxl: Make libxl__xs_* more const-correct 02/18 libxenstore: Providexs_check_watch
03/18 libxl: Provide a version of bsd'squeue.has_libxl_list.h04/18 libxl: idl: support new "private" type attribute 05/18 libxl: idl: Provide struct and union tags
06/18 libxl: permit declaration after statement
07/18 libxl: internal convenience macros
08/18 libxl: Rationalise #includes
Quoted 8 lines
09/18 libxl: introduce lock in
libxl_ctx
10/18 libxl: make libxl__[v]log const-correct
11/18 libxl: makelibxl__free_allidempotent
* 12/18 libxl:libxl_ctx_freeshould free the ctx
13/18 libxl: UseGC_INITandGC_FREEeverywhere
Of these 12/18 is new but I think obviously correct. After that's acked, and test passes and patch backlog permitting, I intend to apply those.
I have applied 01-13, the uncontroversial preamble, all of which had been acked. Hopefully this will reduce the overhang (and reduce the patchbombs too...)
I'm aware there are other tools patches outstanding too.
Ian.