Skip to contentSkip to conversation

libxl: call hotplug scripts from libxl

PATCH In review Roger Pau Monne 3 participants 14 messages May 10, 2012 – May 14, 2012 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

v4 cover libxl: call hotplug scripts from libxl

This series removes the use of udev rules to call hotplug scripts when using libxl. Scripts are directly called from the toolstack at the necessary points, making use of the new event library and it's fork support.

They should be applied after IanJ v8 "libxl: subprocess handling" and IanC "libxl/xend: name tap devices vifX.Y-emu".

This version (v4) introduces many changes, and makes proper use of the event library. It entangles device addition with domain creation, following IanJ changes to domain creation, and also introduces AO operations to domain destruction and specifically to device teardown.

Many changes are introduced, and also a lot of code motion, since libxl_device_{disk,nic}_add are now mere wrappers arround their respective libxl__device_{disk,nic}_add counterparts, which can be called within an already running AO operation, and perform all the work.

#1 lore raw

PATCH v4 1/4 libxl: pass env vars to libxl__exec

Add another parameter to libxl__exec call that contains the environment variables to use when performing the execvp call.

Changes since v3:

* Use CTX instead of defining libxl_ctx *ctx.

* Error checking on setenv.

* Better comment on header for libxl__exec function.

* Added some const-correctness.

---
 tools/libxl/libxl.c            |    2 +-
 tools/libxl/libxl_bootloader.c |    4 ++--
 tools/libxl/libxl_dm.c         |    2 +-
 tools/libxl/libxl_exec.c       |   20 ++++++++++++++++++--
 tools/libxl/libxl_internal.h   |   20 ++++++++++++++++++--
 5 files changed, 40 insertions(+), 8 deletions(-)
tools/libxl/libxl.c +1 -1
index 8f63941..79d7708 100644
@@ -1251,7 +1251,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
         args[2] = "-autopass";
     }
 
-    libxl__exec(autopass_fd, -1, -1, args[0], args);
+    libxl__exec(gc, autopass_fd, -1, -1, args[0], args, NULL);
     abort();
 
  x_fail:
tools/libxl/libxl_bootloader.c +2 -2
index fb1302b..0021a7b 100644
@@ -359,6 +359,7 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
     libxl__bootloader_state *bl = CONTAINER_OF(op, *bl, openpty);
     STATE_AO_GC(bl->ao);
     int rc, r;
+    char *const env[] = { "TERM", "vt100", NULL };
 
     if (bl->openpty.rc) {
         rc = bl->openpty.rc;
@@ -452,8 +453,7 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
         /* child */
         r = login_tty(libxl__carefd_fd(bl->ptys[0].slave));
         if (r) { LOGE(ERROR, "login_tty failed"); exit(-1); }
-        setenv("TERM", "vt100", 1);
-        libxl__exec(-1, -1, -1, bl->args[0], (char**)bl->args);
+        libxl__exec(gc, -1, -1, -1, bl->args[0], (char **) bl->args, env);
         exit(-1);
     }
 
tools/libxl/libxl_dm.c +1 -1
index b2bae68..5de3aef 100644
@@ -1006,7 +1006,7 @@ retry_transaction:
         goto out_close;
     if (!rc) { /* inner child */
         setsid();
-        libxl__exec(null, logfile_w, logfile_w, dm, args);
+        libxl__exec(gc, null, logfile_w, logfile_w, dm, args, NULL);
     }
 
     rc = 0;
tools/libxl/libxl_exec.c +18 -2
index b46b893..fba4cb4 100644
@@ -66,8 +66,8 @@ static void check_open_fds(const char *what)
     if (badness) abort();
 }
 
-void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0,
-                char **args)
+void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd, int stderrfd,
+                 const char *arg0, char *const args[], char *const env[])
      /* call this in the child */
 {
     if (stdinfd != -1)
@@ -90,8 +90,24 @@ void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0,
     /* in case our caller set it to IGN.  subprocesses are entitled
      * to assume they got DFL. */
 
+    if (env != NULL) {
+        for (int i = 0; env[i] != NULL && env[i+1] != NULL; i += 2) {
+            if (setenv(env[i], env[i+1], 1) < 0) {
+                switch (errno) {
+                case EINVAL:
+                    LOGEV(ERROR, errno, "invalid env variables (%s = %s)",
+                                        env[i], env[i+1]);
+                    break;
+                case ENOMEM:
+                    libxl__alloc_failed(CTX, __func__, 0, 0);
+                }
+                goto out;
+            }
+        }
+    }
     execvp(arg0, args);
 
+out:
     fprintf(stderr, "libxl: cannot execute %s: %s\n", arg0, strerror(errno));
     _exit(-1);
 }
tools/libxl/libxl_internal.h +18 -2
index 8a90622..9ab76f8 100644
@@ -1138,8 +1138,24 @@ _hidden int libxl__wait_for_offspring(libxl__gc *gc,
 
  /* low-level stuff, for synchronous subprocesses etc. */
 
-_hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
-               const char *arg0, char **args); // logs errors, never returns
+/*
+ * env should be passed using the following format,
+ *
+ * env[0]: name of env variable
+ * env[1]: value of env variable
+ * env[n]: ...
+ *
+ * So it efectively becomes something like:
+ * export env[n]=env[n+1]
+ * (where n%2 = 0)
+ *
+ * The last entry of the array always has to be NULL.
+ *
+ * Logs errors, never returns.
+ */
+_hidden  void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd,
+                          int stderrfd, const char *arg0, char *const args[],
+                          char *const env[]);
 
 /* from xl_create */
 _hidden int libxl__domain_make(libxl__gc *gc,
Signature · 1 line
1.7.7.5 (Apple Git-26)
#2 lore raw

Re: [PATCH v4 1/4] libxl: pass env vars to libxl__exec

Roger Pau Monne writes ("[Xen-devel] [PATCH v4 1/4] libxl: pass env vars to libxl__exec"):

tools/libxl/libxl_exec.c void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0, · line 104

Quoted 10 lines
tools/libxl/libxl_exec.c +10 -0
+            if (setenv(env[i], env[i+1], 1) < 0) {
+                switch (errno) {
+                case EINVAL:
+                    LOGEV(ERROR, errno, "invalid env variables (%s = %s)",
+                                        env[i], env[i+1]);
+                    break;
+                case ENOMEM:
+                    libxl__alloc_failed(CTX, __func__, 0, 0);
+                }
+                goto out;

This silently exits if errno isn't one of the expected values.

TBH I'm not sure you need to bother switching on errno here. Whatever the errno is we're going to log a message and exit nonzero, so you might as well simply LOGEV even in the ENOMEM case.

Ian.

#3 lore raw

PATCH v4 2/4 libxl: add libxl__xs_path_cleanup

In reply to Roger Pau Monne

Add a function which behaves like "xenstore-rm -t", and which will be used to
clean xenstore after unplug since we will be no longer executing xen-hotplug-cleanup script, that used to do that for us.

Changes since v3:

* Better error checking and function description.

Changes since v2:

* Moved the function to libxl_xshelp.c and added the prototype to libxl_internal.h.

---
 tools/libxl/libxl_internal.h |    7 +++++++
 tools/libxl/libxl_xshelp.c   |   30 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +7 -0
index 9ab76f8..fc2024d 100644
@@ -494,6 +494,13 @@ _hidden bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
 
 _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
 
+/*
+ * This is a recursive delete, from top to bottom. What this function does
+ * is remove empty folders that contained the deleted entry.
+ *
+ * It mimics xenstore-rm -t behaviour.
+ */
+_hidden int libxl__xs_path_cleanup(libxl__gc *gc, char *user_path);
 
 /*
  * Event generation functions provided by the libxl event core to the
tools/libxl/libxl_xshelp.c +30 -0
index 3ea8d08..7339236 100644
@@ -135,6 +135,36 @@ char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)
     return s;
 }
 
+int libxl__xs_path_cleanup(libxl__gc *gc, char *user_path)
+{
+    unsigned int nb = 0;
+    char *path, *last;
+
+    if (!user_path) {
+        LOGE(ERROR, "null path provided");
+        return ERROR_FAIL;
+    }
+
+    path = libxl__strdup(gc, user_path);
+    xs_rm(CTX->xsh, XBT_NULL, path);
+
+    for (last = strrchr(path, '/'); last != NULL; last = strrchr(path, '/')) {
+        *last = '\0';
+
+        if (!strlen(path)) break;
+
+        if (!libxl__xs_directory(gc, XBT_NULL, path, &nb)) {
+            LOG(DEBUG, "failed to read directory contents of %s", path);
+            return ERROR_FAIL;
+        }
+
+        if (nb == 0) {
+            xs_rm(CTX->xsh, XBT_NULL, path);
+        }
+    }
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
Signature · 1 line
1.7.7.5 (Apple Git-26)
#4 lore raw

Re: [PATCH v4 2/4] libxl: add libxl__xs_path_cleanup

Roger Pau Monne writes ("[Xen-devel] [PATCH v4 2/4] libxl: add libxl__xs_path_cleanup"):

Quoted 4 lines

Add a function which behaves like "xenstore-rm -t", and which will be used to
clean xenstore after unplug since we will be no longer executing xen-hotplug-cleanup script, that used to do that for us.

I still think this needs to run in a transaction.

Otherwise, if another xenstore user adds an entry to one of the directories we think is empty, we will unwittingly remove that entry.

And in general it may be necessary to use the caller's transaction. So I would make libxl__xs_path_cleanup always require a non-null transaction to be passed in by the caller.

Ian.

#5 lore raw

PATCH v4 3/4 libxl: call hotplug scripts from libxl for vbd

In reply to Roger Pau Monne

This is a rather big change, that adds the necessary machinery to perform hotplug script calling from libxl for Linux. This patch launches the necessary scripts to attach and detach PHY and TAP backend types (Qemu doesn't use hotplug scripts).

Here's a list of the major changes introduced:

* libxl_device_disk_add makes use of the new event library and takes the optional parameter libxl_asyncop_how, to choose how the operation has to be issued (sync or async).

* Disk addition waits for backend to switch to state 2 (XenbusInitWait) and then launches the hotplug script.

* Created and internal function (libxl__device_disk_add), that can be called within an already running AO, and that will plug the requested disk and execute the callback afterward. libxl_device_disk_add is a user of this newly created function.

* libxl__devices_destroy no longer calls libxl__device_destroy, and instead calls libxl__initiate_device_remove, so we can disconnect the device and execute the necessary hotplug scripts instead of just deleting the backend entries. So libxl__devices_destroy now uses the event library, and so does libxl_domain_destroy, that has been converted to an AO operation function

* The internal API for hotplug scripts has been added, which consists of one function; libxl__device_hotplug that takes the device and a struct with the necessary info about the action to execute.

* Linux hotplug scripts are called by setting the necessary env variables to emulate udev rules, so there's no need to change them (although a rework to pass this as parameters insted of env variables would be suitable, so both NetBSD and Linux hotplug scripts take the same parameters).

* Added a check in xen-hotplug-common.sh, so scripts are only executed from udev when using xend. xl adds a disable_udev=1 to xenstore libxl local directory and with the modification of the udev rules every call from udev gets UDEV_CALL passed, that points to disable_udev. If UDEV_CALL is passed and points to a value, the hotplug script is not executed.

Changes since v3 (changes based on IanJ review):

* Store disable_udev in libxl/disable_udev, which now is not device dependant, but backend domain dependant.

* Added a global callback to device addition/destruction, that is now called when we have finished all the oprtations and handles the call to ao_complete if no other operations are pending.

* Unified both device creation/destruction flows, so now all of them use the same data structure and callbacks.

* Used the event interface in a proper way, and merged disk addition with the new async flow of the domain creation.

* Make use of the new functions LOG, LOGE, GCNEW_ARRAY...

* Passed NULL as ao_how in Python bindings.

Changes since v1:

* Replaced the hotplug snippet that prevents execution from udev when necessary, and now we set the env var from udev rules instead of libxl.

* Replaced the libxl_device_disk_add "if" with a "switch".

* Removed libxl__xs_path_cleanup (replaced with xs_rm).

* Fixed several spelling mistakes.

---
 docs/man/xl.conf.pod.5                    |    8 +
 tools/examples/xl.conf                    |    5 +
 tools/hotplug/Linux/xen-backend.rules     |    6 +-
 tools/hotplug/Linux/xen-hotplug-common.sh |    6 +
 tools/libxl/Makefile                      |    3 +-
 tools/libxl/libxl.c                       |  351 +++++++--------------
 tools/libxl/libxl.h                       |    7 +-
 tools/libxl/libxl_create.c                |  102 ++++++-
 tools/libxl/libxl_device.c                |  497 +++++++++++++++++++++++++----
 tools/libxl/libxl_dm.c                    |  136 +++++----
 tools/libxl/libxl_dom.c                   |  170 ++++++++++
 tools/libxl/libxl_hotplug.c               |   84 +++++
 tools/libxl/libxl_internal.h              |  170 ++++++++++-
 tools/libxl/libxl_linux.c                 |  126 ++++++++
 tools/libxl/libxl_types.idl               |    1 +
 tools/libxl/xl.c                          |    4 +
 tools/libxl/xl.h                          |    1 +
 tools/libxl/xl_cmdimpl.c                  |   15 +-
 tools/python/xen/lowlevel/xl/xl.c         |    2 +-
 19 files changed, 1291 insertions(+), 403 deletions(-)
 create mode 100644 tools/libxl/libxl_hotplug.c
docs/man/xl.conf.pod.5 +8 -0
index 8bd45ea..72825a0 100644
@@ -55,6 +55,14 @@ default.
 
 Default: C<1>
 
+=item B<run_hotplug_scripts=BOOLEAN>
+
+If disabled hotplug scripts will be called from udev, as it used to
+be in the previous releases. With the default option, hotplug scripts
+will be launched by xl directly.
+
+Default: C<1>
+
 =item B<lockfile="PATH">
 
 Sets the path to the lock file used by xl to serialise certain
tools/examples/xl.conf +5 -0
index 56d3b3b..75b00e0 100644
@@ -12,3 +12,8 @@
 
 # default output format used by "xl list -l"
 #output_format="json"
+
+# default option to run hotplug scripts from xl
+# if disabled the old behaviour will be used, and hotplug scripts will be
+# launched by udev.
+#run_hotplug_scripts=1
tools/hotplug/Linux/xen-backend.rules +3 -3
index 405387f..d55ff11 100644
@@ -1,11 +1,11 @@
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}"
-SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
+SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
 SUBSYSTEM=="xen", KERNEL=="blktap[0-9]*", NAME="xen/%k", MODE="0600"
 SUBSYSTEM=="blktap2", KERNEL=="blktap[0-9]*", NAME="xen/blktap-2/%k", MODE="0600"
tools/hotplug/Linux/xen-hotplug-common.sh +6 -0
index 8f6557d..6443a63 100644
@@ -15,6 +15,12 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ] && \
+   `xenstore-read "libxl/disable_udev" >/dev/null 2>&1`; then
+    exit 0
+fi
 
 dir=$(dirname "$0")
 . "$dir/hotplugpath.sh"
tools/libxl/Makefile +2 -1
index 5d9227e..9abadff 100644
@@ -66,7 +66,8 @@ 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_aoutils.o \
-			libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
+			libxl_qmp.o libxl_event.o libxl_fork.o libxl_hotplug.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) -include $(XEN_ROOT)/tools/config.h
tools/libxl/libxl.c +108 -243

449 lines not on this page · raw message

tools/libxl/libxl.h +5 -2
index 0ff4a83..0ab1531 100644
@@ -530,7 +530,8 @@ int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid);
-int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid);
+int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
+                         const libxl_asyncop_how *ao_how);
 int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid);
 
 /* get max. number of cpus supported by hypervisor */
@@ -660,7 +661,9 @@ void libxl_vminfo_list_free(libxl_vminfo *list, int nr);
  */
 
 /* Disks */
-int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
+int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
+                          libxl_device_disk *disk,
+                          const libxl_asyncop_how *ao_how);
 int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
                              libxl_device_disk *disk,
                              const libxl_asyncop_how *ao_how);
tools/libxl/libxl_create.c +95 -7

153 lines not on this page · raw message

tools/libxl/libxl_device.c +427 -70

585 lines not on this page · raw message

tools/libxl/libxl_dm.c +75 -61

207 lines not on this page · raw message

tools/libxl/libxl_dom.c +170 -0

176 lines not on this page · raw message

tools/libxl/libxl_hotplug.c new file +84 -0

84 lines not on this page · raw message

tools/libxl/libxl_internal.h +162 -8

224 lines not on this page · raw message

tools/libxl/libxl_linux.c +126 -0

129 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index 551e367..b1351de 100644
@@ -220,6 +220,7 @@ libxl_domain_create_info = Struct("domain_create_info",[
     ("xsdata",       libxl_key_value_list),
     ("platformdata", libxl_key_value_list),
     ("poolid",       uint32),
+    ("run_hotplug_scripts",libxl_defbool),
     ], dir=DIR_IN)
 
 MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
tools/libxl/xl.c +4 -0
index d4db1f8..d992c32 100644
@@ -35,6 +35,7 @@
 xentoollog_logger_stdiostream *logger;
 int dryrun_only;
 int autoballoon = 1;
+libxl_defbool run_hotplug_scripts;
 char *lockfile;
 char *default_vifscript = NULL;
 char *default_bridge = NULL;
@@ -66,6 +67,9 @@ static void parse_global_config(const char *configfile,
     if (!xlu_cfg_get_long (config, "autoballoon", &l, 0))
         autoballoon = l;
 
+    libxl_defbool_setdefault(&run_hotplug_scripts, true);
+    xlu_cfg_get_defbool(config, "run_hotplug_scripts", &run_hotplug_scripts, 0);
+
     if (!xlu_cfg_get_string (config, "lockfile", &buf, 0))
         lockfile = strdup(buf);
     else {
tools/libxl/xl.h +1 -0
index 2b6714a..43d727a 100644
@@ -109,6 +109,7 @@ void postfork(void);
 
 /* global options */
 extern int autoballoon;
+extern libxl_defbool run_hotplug_scripts;
 extern int dryrun_only;
 extern char *lockfile;
 extern char *default_vifscript;
tools/libxl/xl_cmdimpl.c +8 -7
index 8908581..3f1bbf6 100644
@@ -562,6 +562,7 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    c_info->run_hotplug_scripts = run_hotplug_scripts;
     c_info->type = LIBXL_DOMAIN_TYPE_PV;
     if (!xlu_cfg_get_string (config, "builder", &buf, 0) &&
         !strncmp(buf, "hvm", strlen(buf)))
@@ -1333,7 +1334,7 @@ static int handle_domain_death(libxl_ctx *ctx, uint32_t domid,
         /* fall-through */
     case LIBXL_ACTION_ON_SHUTDOWN_DESTROY:
         LOG("Domain %d needs to be cleaned up: destroying the domain", domid);
-        libxl_domain_destroy(ctx, domid);
+        libxl_domain_destroy(ctx, domid, 0);
         break;
 
     case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY:
@@ -1899,7 +1900,7 @@ start:
 error_out:
     release_lock();
     if (libxl_domid_valid_guest(domid))
-        libxl_domain_destroy(ctx, domid);
+        libxl_domain_destroy(ctx, domid, 0);
 
 out:
     if (logfile != 2)
@@ -2386,7 +2387,7 @@ static void destroy_domain(const char *p)
         fprintf(stderr, "Cannot destroy privileged domain 0.\n\n");
         exit(-1);
     }
-    rc = libxl_domain_destroy(ctx, domid);
+    rc = libxl_domain_destroy(ctx, domid, 0);
     if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n",rc); exit(-1); }
 }
 
@@ -2660,7 +2661,7 @@ static int save_domain(const char *p, const char *filename, int checkpoint,
     if (checkpoint)
         libxl_domain_unpause(ctx, domid);
     else
-        libxl_domain_destroy(ctx, domid);
+        libxl_domain_destroy(ctx, domid, 0);
 
     exit(0);
 }
@@ -2892,7 +2893,7 @@ static void migrate_domain(const char *domain_spec, const char *rune,
     }
 
     fprintf(stderr, "migration sender: Target reports successful startup.\n");
-    libxl_domain_destroy(ctx, domid); /* bang! */
+    libxl_domain_destroy(ctx, domid, 0); /* bang! */
     fprintf(stderr, "Migration successful.\n");
     exit(0);
 
@@ -3010,7 +3011,7 @@ static void migrate_receive(int debug, int daemonize, int monitor)
     if (rc) {
         fprintf(stderr, "migration target: Failure, destroying our copy.\n");
 
-        rc2 = libxl_domain_destroy(ctx, domid);
+        rc2 = libxl_domain_destroy(ctx, domid, 0);
         if (rc2) {
             fprintf(stderr, "migration target: Failed to destroy our copy"
                     " (code %d).\n", rc2);
@@ -5077,7 +5078,7 @@ int main_blockattach(int argc, char **argv)
         return 0;
     }
 
-    if (libxl_device_disk_add(ctx, fe_domid, &disk)) {
+    if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) {
         fprintf(stderr, "libxl_device_disk_add failed.\n");
     }
     return 0;
tools/python/xen/lowlevel/xl/xl.c +1 -1
index c4f7c52..ce7a2b2 100644
@@ -447,7 +447,7 @@ static PyObject *pyxl_domain_destroy(XlObject *self, PyObject *args)
     int domid;
     if ( !PyArg_ParseTuple(args, "i", &domid) )
         return NULL;
-    if ( libxl_domain_destroy(self->ctx, domid) ) {
+    if ( libxl_domain_destroy(self->ctx, domid, NULL) ) {
         PyErr_SetString(xl_error_obj, "cannot destroy domain");
         return NULL;
     }
Signature · 1 line
1.7.7.5 (Apple Git-26)
#6 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

Roger Pau Monne writes ("[Xen-devel] [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd"):

Quoted 4 lines

This is a rather big change, that adds the necessary machinery to perform hotplug script calling from libxl for Linux. This patch launches the necessary scripts to attach and detach PHY and TAP backend types (Qemu doesn't use hotplug scripts).

Thanks.

tools/hotplug/Linux/xen-backend.rules line 2

Quoted 4 lines
tools/hotplug/Linux/xen-backend.rules +2 -2
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"

Wouldn't it be better to have an env var set by libxl to mean "_not_ called from udev?". That would mean that if the udev rules weren't updated for some reason it would all still work. On many setups these are config files which may require the user to merge changes, etc., so this is a real concern.

tools/hotplug/Linux/xen-hotplug-common.sh line 21

Quoted 4 lines
tools/hotplug/Linux/xen-hotplug-common.sh +4 -0
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ] && \
+   `xenstore-read "libxl/disable_udev" >/dev/null 2>&1`; then

This reads something from xenstore and executes it as a shell command! (Also it will go wrong if the value read is empty eg becaue the key doesn't exist.)

Also didn't I say that in xenstore we normally record booleans as decimal integers, "0" for false and "1" for true ?

tools/libxl/libxl.c void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) { · line 1063

Quoted 11 lines
tools/libxl/libxl.c +2 -8
-}    
+}
 
-int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)
-{
-    GC_INIT(ctx);
-    char *dom_path;
-    char *vm_path;
-    char *pid;
-    int rc, dm_present;
+/* Callback for domain destruction */

The rest of this is very very difficult to review because of the amount of code motion, variable renaming, and so forth.

Do you think it would be possible to reorganise things so that the diff is as minimal as possible ? Techniques you will probably find useful include:

* Declare some convenience variables such as

      uint32_t const domid = dis->domid;

This is best done near the top of each function along with the new function prototype etc., so it doesn't introduce a mid-function patch hunk. This will avoid irrelevant noise in the diff caused by the movement of state into the operation state struct.

* Declare callback functions at the top of the file so that they can appear after the point where they are referenced, and write all the code in the order in which it actually occurs. This is useful anyway, but it probably means that the code won't need to move because it's probably already in that order. If it isn't you may need to move it about separately.

* In general, avoid moving any code if at all possible in the main patch. If you need to move code, do it in a pre- or post-patch.

* Only take the opportunity to make unrelated changes (eg, changing from libxl__sprintf to GCSPRINTF) if you have to make another change to the very same line of code.

* If any code motion is needed, split it out into a pre-patch which contains only code motion.

* Be prepared to leave wrinkles in the code style or layout and fix them up in a later patch.

* If it is necessary to switch a variable from a "struct foo" to a "struct foo*", split out a separate pre-patch which changes it to a "struct foo[1]". This separate patch will then obviously have no functional change and wiull simply contain a lot of removing of "&" etc. The actual patch with the meat can leave all those references unchanged.

* Likewise if you want to change something from a "struct foo*" to a "struct foo" you can do the reverse: in your main patch change it to "struct foo[1]" instead. Then, you can add a post-patch to fix that up by changing "struct foo[1]" to "struct foo" which again will have no functional change.

You will see me applying these techniques in my recent child process series; I can point you at specific commits etc. if you want more hints.

Of course this may not be feasible. If for some parts of the code this approach is not feasible, and the result is always going to look like a rewrite, mention in the commit message that such-and-such function(s) or parts of code have essentially been rewritten.

Thanks,
Ian.

#7 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

Quoted 8 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd"):

Quoted 4 lines

This is a rather big change, that adds the necessary machinery to perform hotplug script calling from libxl for Linux. This patch launches the necessary scripts to attach and detach PHY and TAP backend types (Qemu doesn't use hotplug scripts).

Thanks.

Quoted 10 lines

tools/hotplug/Linux/xen-backend.rules line 2

Quoted 4 lines
tools/hotplug/Linux/xen-backend.rules +2 -2
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"

Wouldn't it be better to have an env var set by libxl to mean "_not_ called from udev?". That would mean that if the udev rules weren't updated for some reason it would all still work. On many setups these are config files which may require the user to merge changes, etc., so this is a real concern.

Since the 4.2 release already implies updating udev rules (due to the change from tap* to *emu), I think it's better to set the var on udev, that way when udev is dropped we won't need to perform any change to libxl.

Quoted 9 lines

tools/hotplug/Linux/xen-hotplug-common.sh

Quoted 5 lines
tools/hotplug/Linux/xen-hotplug-common.sh +4 -0
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ]&&  \
+   `xenstore-read "libxl/disable_udev">/dev/null 2>&1`; then

This reads something from xenstore and executes it as a shell command! (Also it will go wrong if the value read is empty eg becaue the key doesn't exist.)

Are you sure about this? This command never returns anything, because it is redirected to /dev/null, so we only evaluate if it is able to read libxl/disable_udev. If libxl/disable_udev exists this test is passed.

Quoted 7 lines

Also didn't I say that in xenstore we normally record booleans as decimal integers, "0" for false and "1" for true ?

Quoted 3 lines
(quoted diff) +1 -1
-}
+}
Quoted 11 lines

tools/libxl/libxl.c void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) { · line 1063

Quoted 8 lines
tools/libxl/libxl.c +1 -7
-int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)
-{
-    GC_INIT(ctx);
-    char *dom_path;
-    char *vm_path;
-    char *pid;
-    int rc, dm_present;
+/* Callback for domain destruction */

The rest of this is very very difficult to review because of the amount of code motion, variable renaming, and so forth.

Yes, will try to do so. I'm currently moving the changes to mach tip and also splitting them.

Quoted 56 lines

Do you think it would be possible to reorganise things so that the diff is as minimal as possible ? Techniques you will probably find useful include:

* Declare some convenience variables such as
uint32_t const domid = dis->domid;
This is best done near the top of each function along with the new function prototype etc., so it doesn't introduce a mid-function patch hunk. This will avoid irrelevant noise in the diff caused by the movement of state into the operation state struct.

* Declare callback functions at the top of the file so that they can appear after the point where they are referenced, and write all the code in the order in which it actually occurs. This is useful anyway, but it probably means that the code won't need to move because it's probably already in that order. If it isn't you may need to move it about separately.

* In general, avoid moving any code if at all possible in the main patch. If you need to move code, do it in a pre- or post-patch.

* Only take the opportunity to make unrelated changes (eg, changing from libxl__sprintf to GCSPRINTF) if you have to make another change to the very same line of code.

* If any code motion is needed, split it out into a pre-patch which contains only code motion.

* Be prepared to leave wrinkles in the code style or layout and fix them up in a later patch.

* If it is necessary to switch a variable from a "struct foo" to a "struct foo*", split out a separate pre-patch which changes it to a "struct foo[1]". This separate patch will then obviously have no functional change and wiull simply contain a lot of removing of "&" etc. The actual patch with the meat can leave all those references unchanged.

* Likewise if you want to change something from a "struct foo*" to a "struct foo" you can do the reverse: in your main patch change it to "struct foo[1]" instead. Then, you can add a post-patch to fix that up by changing "struct foo[1]" to "struct foo" which again will have no functional change.

You will see me applying these techniques in my recent child process series; I can point you at specific commits etc. if you want more hints.

Of course this may not be feasible. If for some parts of the code this approach is not feasible, and the result is always going to look like a rewrite, mention in the commit message that such-and-such function(s) or parts of code have essentially been rewritten.

Thanks,
Ian.

#8 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

Quoted 9 lines · Roger Pau Monne
Quoted 8 lines

tools/hotplug/Linux/xen-hotplug-common.sh

Quoted 4 lines
tools/hotplug/Linux/xen-hotplug-common.sh +4 -0
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ]&&  \
+   `xenstore-read "libxl/disable_udev">/dev/null 2>&1`; then

This reads something from xenstore and executes it as a shell command! (Also it will go wrong if the value read is empty eg becaue the key doesn't exist.)

Quoted 3 lines

Are you sure about this? This command never returns anything, because it is redirected to /dev/null, so we only evaluate if it is able to read libxl/disable_udev. If libxl/disable_udev exists this test is passed.

You don't need the backticks for that though. With the backticks it will execute whatever happens to be in the key -- I guess it's something quite benign right now or you'd have seen errors.

Ian.

#9 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

Quoted 8 lines · Ian Campbell
Quoted 7 lines · Roger Pau Monne
Quoted 7 lines

tools/hotplug/Linux/xen-hotplug-common.sh

Quoted 4 lines
tools/hotplug/Linux/xen-hotplug-common.sh +4 -0
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ]&&   \
+   `xenstore-read "libxl/disable_udev">/dev/null 2>&1`; then

This reads something from xenstore and executes it as a shell command! (Also it will go wrong if the value read is empty eg becaue the key doesn't exist.)

Quoted 7 lines
Quoted 3 lines

Are you sure about this? This command never returns anything, because it is redirected to /dev/null, so we only evaluate if it is able to read libxl/disable_udev. If libxl/disable_udev exists this test is passed.

You don't need the backticks for that though. With the backticks it will execute whatever happens to be in the key -- I guess it's something quite benign right now or you'd have seen errors.

Yes, it's not the first time that I've made that mistake. Since it never returns anything I guess that's why I never saw any errors.

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

#10 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

In reply to Ian Campbell

Ian Campbell writes ("Re: [Xen-devel] [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd"):

Quoted 8 lines · Roger Pau Monne
Quoted 3 lines

Are you sure about this? This command never returns anything, because it is redirected to /dev/null, so we only evaluate if it is able to read libxl/disable_udev. If libxl/disable_udev exists this test is passed.

You don't need the backticks for that though. With the backticks it will execute whatever happens to be in the key -- I guess it's something quite benign right now or you'd have seen errors.

In fact Roger was right on the narrow point: because the >/dev/null is inside the backticks, the backticks never see any output and it's equivalent to false or true. I'm pleased that it's not just me that read it the way you did at first :-).

But you are of course right in that it's a silly construction. If the output is not wanted, `` should not be used.

Ian.

#11 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

Quoted 5 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd"):

Quoted 4 lines · Roger Pau Monne
Quoted 3 lines

Are you sure about this? This command never returns anything, because it is redirected to /dev/null, so we only evaluate if it is able to read libxl/disable_udev. If libxl/disable_udev exists this test is passed.

Quoted 8 lines
Quoted 3 lines

You don't need the backticks for that though. With the backticks it will execute whatever happens to be in the key -- I guess it's something quite benign right now or you'd have seen errors.

In fact Roger was right on the narrow point: because the>/dev/null is inside the backticks, the backticks never see any output and it's equivalent to false or true. I'm pleased that it's not just me that read it the way you did at first :-).

The fact that it works is just a question of "luck", but the construction is definitely wrong. I always forget that you don't need to use the ` when testing in the conditional for the execution of a command. Sorry about that.

Quoted 4 lines

But you are of course right in that it's a silly construction. If the output is not wanted, `` should not be used.

Ian.

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

#12 lore raw

Re: [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd

In reply to Roger Pau Monne

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v4 3/4] libxl: call hotplug scripts from libxl for vbd"):

Quoted 10 lines
Quoted 5 lines · Ian Jackson

Wouldn't it be better to have an env var set by libxl to mean "_not_ called from udev?". That would mean that if the udev rules weren't updated for some reason it would all still work. On many setups these are config files which may require the user to merge changes, etc., so this is a real concern.

Since the 4.2 release already implies updating udev rules (due to the change from tap* to *emu), I think it's better to set the var on udev, that way when udev is dropped we won't need to perform any change to libxl.

Ah. (The change to libxl is not an essential one so we won't "need" to make it, but OK.)

Quoted 10 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+if [ -n "${UDEV_CALL}" ]&&  \
+   `xenstore-read "libxl/disable_udev">/dev/null 2>&1`; then

This reads something from xenstore and executes it as a shell command! (Also it will go wrong if the value read is empty eg becaue the key doesn't exist.)

Are you sure about this? This command never returns anything, because it is redirected to /dev/null, so we only evaluate if it is able to read libxl/disable_udev. If libxl/disable_udev exists this test is passed.

Uh, so it does. Why are you using `` at all then ? This is a very odd construction.

Thanks,
Ian.

#13 lore raw

PATCH v4 4/4 libxl: call hotplug scripts from libxl for vif

In reply to Roger Pau Monne

As the previous change already introduces most of needed machinery to call hotplug scripts from libxl, this only adds the necessary bits to call this scripts for vif interfaces also.

libxl_device_nic_add has been changed to make use of the new event functionality, and the necessary vif hotplug code has been added. No changes where needed in the teardown part, since it uses exactly the same code introduced for vbd.

Network devices are added after the domain model has launched, since we need the tap inteface to be present when the hotplug script is executed.

PV nic devices are set to LIBXL_NIC_TYPE_VIF, since the default value is LIBXL_NIC_TYPE_IOEMU regardless of the guest type.

Changes since v3:

* Entangle network device addition with the new AO domain creation, assute that network interfaces are always added after device model creation. Make sure the same happens for stubdomain network interfaces.

* Make use of the new functions LOG, LOGE, GCNEW_ARRAY...

* Remove disable_xl_vif_scripts, since now it's a global option that affects both vifs and disks hotplug scripts.

* Added proper handling of IOEMU type of nics, we need to execute two different hotplug scripts. Now both scripts are chained, and one is executed after the other has finished (we call the next script from the callback of the previous one). Previously we used to launch both scripts simultaneously.

Changes since v2:

* Added fancy functions to fetch tap and vif names, now the prefix of the tap device has been saved in a constant, called TAP_DEVICE_PREFIX.

* Wait for timeout before nuking frontend xenstore entries.

* Changed disable_vif_scripts to disable_xl_vif_scripts, it's easier to understand.

* Default nic type set by libxl__device_nic_setdefault is VIF now (was IOEMU).

* Save nic type and udev script exection inside /libxl/devices/<domid>/nic/<devid>/ instead of saving it in the backend path.

Changes since v1:

* Propagated changes from previous patch (disable_udev and libxl_device_nic_add switch).

* Modified udev rules to add the new env variable.

* Added support for named interfaces.

---
 tools/hotplug/Linux/xen-backend.rules |    6 +-
 tools/libxl/libxl.c                   |  122 ++++---------------------------
 tools/libxl/libxl.h                   |    3 +-
 tools/libxl/libxl_create.c            |   78 ++++++++++++++++++--
 tools/libxl/libxl_device.c            |  122 +++++++++++++++++++++++++++++++
 tools/libxl/libxl_dm.c                |   64 +++++++++++++++-
 tools/libxl/libxl_internal.h          |    9 ++
 tools/libxl/libxl_linux.c             |  130 ++++++++++++++++++++++++++++++++-
 tools/libxl/xl_cmdimpl.c              |    2 +-
 9 files changed, 412 insertions(+), 124 deletions(-)
tools/hotplug/Linux/xen-backend.rules +3 -3
index d55ff11..c591a3f 100644
@@ -2,8 +2,8 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scr
 SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
-SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ENV{UDEV_CALL}="1", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ENV{UDEV_CALL}="1", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}"
 SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
@@ -13,4 +13,4 @@ KERNEL=="blktap-control", NAME="xen/blktap-2/control", MODE="0600"
 KERNEL=="gntdev", NAME="xen/%k", MODE="0600"
 KERNEL=="pci_iomul", NAME="xen/%k", MODE="0600"
 KERNEL=="tapdev[a-z]*", NAME="xen/blktap-2/tapdev%m", MODE="0600"
-SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
+SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
tools/libxl/libxl.c +14 -108

137 lines not on this page · raw message

tools/libxl/libxl.h +2 -1
index 0ab1531..6689baf 100644
@@ -688,7 +688,8 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
 int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
 
 /* Network Interfaces */
-int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
+int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
+                         const libxl_asyncop_how *ao_how);
 int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
                             libxl_device_nic *nic,
                             const libxl_asyncop_how *ao_how);
tools/libxl/libxl_create.c +71 -7

96 lines not on this page · raw message

tools/libxl/libxl_device.c +122 -0

134 lines not on this page · raw message

tools/libxl/libxl_dm.c +61 -3

85 lines not on this page · raw message

tools/libxl/libxl_internal.h +9 -0
index faeb965..91eba63 100644
@@ -782,6 +782,9 @@ _hidden int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
 _hidden char *libxl__device_disk_string_of_backend(libxl_disk_backend backend);
 _hidden char *libxl__device_disk_string_of_format(libxl_disk_format format);
 _hidden int libxl__device_disk_set_backend(libxl__gc*, libxl_device_disk*);
+_hidden int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_nic *nic,
+                                   libxl__device *device);
 _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
                                     libxl_device_disk *disk,
                                     libxl__device *device);
@@ -965,6 +968,7 @@ struct libxl__ao_device {
     libxl__device_callback *callback;
     /* private for implementation */
     int rc;
+    int vif_executed;
     libxl__ev_time ev;
     libxl__ev_child child;
     libxl__ev_devstate ds;
@@ -974,6 +978,9 @@ struct libxl__ao_device {
 _hidden int libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
                                    libxl_device_disk *disk,
                                    libxl__ao_device *aorm);
+_hidden int libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
+                                  libxl_device_nic *nic,
+                                  libxl__ao_device *aorm);
 
 /*
  *----- spawn -----
@@ -1147,6 +1154,8 @@ struct libxl__dm_spawn_state {
     libxl_domain_config *guest_config;
     libxl__domain_build_state *build_state; /* relates to guest_domid */
     libxl__dm_spawn_cb *callback;
+    libxl__ao_device *devices;
+    int num_devices;
 };
 
 _hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*);
tools/libxl/libxl_linux.c +129 -1

167 lines not on this page · raw message

tools/libxl/xl_cmdimpl.c +1 -1
index 3f1bbf6..162bb82 100644
@@ -4967,7 +4967,7 @@ int main_networkattach(int argc, char **argv)
         return 0;
     }
 
-    if (libxl_device_nic_add(ctx, domid, &nic)) {
+    if (libxl_device_nic_add(ctx, domid, &nic, 0)) {
         fprintf(stderr, "libxl_device_nic_add failed.\n");
         return 1;
     }
Signature · 1 line
1.7.7.5 (Apple Git-26)