libxl: add support for hotplug script calling from libxl
PATCH v5 1/1 libxl: add support for hotplug script calling from libxl
Previously acked patches from the series.
PATCH v5 1/1 libxl: add support for image files for NetBSD
# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1317386335 -7200
# Node ID c8de7762b28386a8867b305660673c11eb5cf512 # Parent 8e129474fc0ac87623ba814ea865326d45cb8436
libxl: add support for image files for NetBSD
Created a helper function to detect if the OS is capable of using image files as phy backends. Create two OS specific files, and changed the Makefile to choose the correct one at compile time.
tools/libxl/Makefile +9 -0
@@ -33,6 +33,15 @@ endif LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o +ifeq ($(CONFIG_NetBSD),y) +LIBXL_OBJS-y += libxl_netbsd.o +else ifeq ($(CONFIG_Linux),y) +LIBXL_OBJS-y += libxl_linux.o +else +$(error Your Operating System is not supported by libxenlight, \ +please check libxl_linux.c and libxl_netbsd.c to see how to get it ported) +endif + LIBXL_LIBS += -lyajl LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
tools/libxl/libxl_device.c +7 -8
@@ -137,15 +137,14 @@ static int disk_try_backend(disk_try_bac a->disk->format == LIBXL_DISK_FORMAT_EMPTY)) { goto bad_format; } -if (a->disk->format !=LIBXL_DISK_FORMAT_EMPTY && - !S_ISBLK (a->stab.st_mode)) { -LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Disk vdev=%s, backend phy" -" unsuitable as phys path not a block device" , - a->disk->vdev); -return 0 ; - } -return backend; +if (libxl__try_phy_backend (a->stab.st_mode)) +return backend; + +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Disk vdev=%s, backend phy" +" unsuitable as phys path not a block device" , + a->disk->vdev); +return 0 ;case LIBXL_DISK_BACKEND_TAP :if (!libxl__blktap_enabled (a->gc)) {
tools/libxl/libxl_internal.h +9 -0
@@ -271,6 +271,15 @@ _hidden int libxl__device_destroy(libxl_ _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +/* +* libxl__try_phy_backend - Check if there's support for the passed +* type of file using the PHY backend +* st_mode: mode_t of the file, as returned by stat function +* +* Returns 0 on success, and < 0 on error. +*/ +_hidden int libxl__try_phy_backend(mode_t st_mode); +/* from libxl_pci */ _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting);
tools/libxl/libxl_linux.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2011 +* Author Roger Pau Monne <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ + +#include <sys/stat.h> + +#include "libxl_internal.h" + +int libxl__try_phy_backend (mode_t st_mode) +{ +if (!S_ISBLK (st_mode)) { +return 0 ; + } + +return 1 ; +}
tools/libxl/libxl_netbsd.c new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2011 +* Author Roger Pau Monne <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ + +#include <sys/stat.h> + +#include "libxl_internal.h" + +int libxl__try_phy_backend (mode_t st_mode) +{ +if (S_ISREG (st_mode) ||S_ISBLK (st_mode)) +return 1 ; + +return 0 ; +}
PATCH v5 1/1 libxl: introduce libxl__wait_for_device_state
In reply to Roger Pau Monne# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1323971745 -3600
# Node ID 492fa4832e68f6493e5f61b72e598c164572eb41 # Parent e428efb092ffdaab1eeee5c304fd5f3b824ad958
libxl: introduce libxl__wait_for_device_state
This is a generic function, that waits for xs watches to reach a certain state and then executes the passed helper function. Removed wait_for_dev_destroy and used this new function instead. This function will also be used by future patches that need to wait for the initialization of devices before executing hotplug scripts.
tools/libxl/libxl_device.c +30 -12
@@ -369,7 +369,9 @@ int libxl__device_disk_dev_number(const* Returns 0 if a device is removed, ERROR_* if an error * or timeout occurred. */ -static int wait_for_dev_destroy (libxl__gc *gc,struct timeval *tv) +int libxl__wait_for_device_state (libxl__gc *gc,struct timeval *tv, +XenbusState state, +libxl__device_state_handler handler) {libxl_ctx *ctx =libxl__gc_owner (gc);int nfds, rc;
@@ -394,17 +396,14 @@ start:default : l1 =xs_read_watch (ctx->xsh, &n);if (l1 !=NULL ) { -char *state =libxl__xs_read (gc,XBT_NULL , +char *sstate =libxl__xs_read (gc,XBT_NULL , l1[XS_WATCH_PATH ]); -if (!state ||atoi (state) ==6 ) { -xs_unwatch (ctx->xsh, l1[0 ], l1[1 ]); -xs_rm (ctx->xsh,XBT_NULL , l1[XS_WATCH_TOKEN ]); -LIBXL__LOG (ctx,LIBXL__LOG_DEBUG , -"Destroyed device backend at %s" , - l1[XS_WATCH_TOKEN ]); - rc =0 ; +if (!sstate ||atoi (sstate) == state) { +/* Call handler function if present */ +if (handler) + rc =handler (gc, l1, sstate); }else { -/* State is not "disconnected", continue waiting... */ +/* State is different than expected, continue waiting... */ goto start; }free (l1);
@@ -417,6 +416,23 @@ start: }/* +* Handler function for device destruction to be passed to +* libxl__wait_for_device_state +*/ +static int destroy_device (libxl__gc *gc,char **l1,char *state) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); + +xs_unwatch (ctx->xsh, l1[0 ], l1[1 ]); +xs_rm (ctx->xsh,XBT_NULL , l1[XS_WATCH_TOKEN ]); +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG , +"Destroyed device backend at %s" , + l1[XS_WATCH_TOKEN ]); + +return 0 ; +} + +/* * Returns 0 (device already destroyed) or 1 (caller must * wait_for_dev_destroy) on success, ERROR_* on fail. */
@@ -457,7 +473,8 @@ retry_transaction:struct timeval tv; tv.tv_sec =LIBXL_DESTROY_TIMEOUT ; tv.tv_usec =0 ; - rc =wait_for_dev_destroy (gc, &tv); + rc =libxl__wait_for_device_state (gc, &tv, XenbusStateClosed, + destroy_device);if (rc <0 )/* an error or timeout occurred, clear watches */ xs_unwatch (ctx->xsh, state_path, be_path);xs_rm (ctx->xsh,XBT_NULL ,libxl__device_frontend_path (gc, dev));
@@ -565,7 +582,8 @@ int libxl__devices_destroy(libxl__gc *gc tv.tv_sec =LIBXL_DESTROY_TIMEOUT ; tv.tv_usec =0 ;while (n_watches >0 ) { -if (wait_for_dev_destroy (gc, &tv) <0 ) { +if (libxl__wait_for_device_state (gc, &tv, XenbusStateClosed, + destroy_device) <0 ) {/* function returned ERROR_* */ break ; }else {
tools/libxl/libxl_internal.h +28 -0
@@ -24,11 +24,14 @@#include <stdlib.h> #include <string.h> #include <pthread.h> +#include <sys/time.h> #include <xs.h> #include <xenctrl.h> #include "xentoollog.h" +#include <xen/io/xenbus.h> +#include "libxl.h" #if __GNUC__ >3 || (__GNUC__ ==3 && __GNUC_MINOR__ >=1 )
@@ -271,6 +274,31 @@ _hidden int libxl__device_destroy(libxl_ _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +/* Handler for the libxl__wait_for_device_state callback */ +/* +* libxl__device_state_handler - Handler for the libxl__wait_for_device_state +* gc: allocation pool +* l1: array containing the path and token +* state: string that contains the state of the device +* +* Returns 0 on success, and < 0 on error. +*/ +typedef int libxl__device_state_handler (libxl__gc *gc,char **l1,char *state); + +/* +* libxl__wait_for_device_state - waits a given time for a device to +* reach a given state +* gc: allocation pool +* tv: timeval struct containing the maximum time to wait +* state: state to wait for (check xen/io/xenbus.h) +* handler: callback function to execute when state is reached +* +* Returns 0 on success, and < 0 on error. +*/ +_hidden int libxl__wait_for_device_state(libxl__gc *gc, struct timeval *tv, +XenbusState state, +libxl__device_state_handler handler); +/* * libxl__try_phy_backend - Check if there's support for the passed * type of file using the PHY backend
PATCH v5 1/1 hotplug: remove debug messages from NetBSD hotplug scripts
In reply to Roger Pau Monne# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1323971746 -3600
# Node ID 75e1660cd4c350105e45f15b2ecbcdd564f2a290 # Parent f56b12b7e8d6979844639a88bb1c5118e498e096
hotplug: remove debug messages from NetBSD hotplug scripts
Remove unecessary debug messages from NetBSD hotplug scripts, left error messages only.
tools/hotplug/NetBSD/block +0 -4
@@ -69,14 +69,12 @@ 1) if [ "$status" = "free" ] && \ vnconfig /dev/${disk}d $xparams >/dev/null; then device=/dev/${disk}d - echo vnconfig /dev/${disk}d $xparams break fi done if [ x$device = x ] ; then error "no available vnd device" fi - echo xenstore-write $xpath/vnd $device xenstore-write $xpath/vnd $device ;; phy)
@@ -84,9 +82,7 @@ 1) ;; esac physical_device=$(stat -f '%r' "$device") - echo xenstore-write $xpath/physical-device $physical_device xenstore-write $xpath/physical-device $physical_device - echo xenstore-write $xpath/hotplug-status connected xenstore-write $xpath/hotplug-status connected exit 0 ;;
tools/hotplug/NetBSD/vif-bridge +0 -3
@@ -24,12 +24,9 @@ 1) xfid=$(xenstore-read "$xpath/frontend-id") xhandle=$(xenstore-read "$xpath/handle") iface=$(xenstore-read "$xpath/vifname") - echo ifconfig $iface up ifconfig $iface up brconfig $xbridge add $iface - echo brconfig $xbridge add $iface xenstore-write $xpath/hotplug-status connected - echo xenstore-write $xpath/hotplug-status connected exit 0 ;; *)
tools/hotplug/NetBSD/vif-ip +0 -2
@@ -24,10 +24,8 @@ 1) xfid=$(xenstore-read "$xpath/frontend-id") xhandle=$(xenstore-read "$xpath/handle") iface=$(xenstore-read "$xpath/vifname") - echo ifconfig $iface $xip up ifconfig $iface $xip up xenstore-write $xpath/hotplug-status connected - echo xenstore-write $xpath/hotplug-status connected exit 0 ;; *)
PATCH v5 1/1 libxl: fix incorrect log message in libxl_domain_destroy
In reply to Roger Pau Monne# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1323971746 -3600
# Node ID f2274ad5e46301dcc4f3f24a06b1c5e394c61f55 # Parent 27003c971acf4064b60de68de9e4caec588b5b7d
libxl: fix incorrect log message in libxl_domain_destroy
Fix a log message that was referring to libxl_devices_dispose instead of libxl__devices_destroy.
tools/libxl/libxl.c +2 -1
@@ -773,7 +773,8 @@ int libxl_domain_destroy(libxl_ctx *ctx,libxl__qmp_cleanup (gc, domid); }if (libxl__devices_destroy (gc, domid, force) <0 ) -LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl_devices_dispose failed for %d" , domid); +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"libxl__devices_destroy failed for %d" , domid); vm_path =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/vm" , dom_path));if (vm_path)
PATCH v5 1/1 libxl: remove force parameter from libxl_domain_destroy
In reply to Roger Pau Monne# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1323971746 -3600
# Node ID 1ab9421bf75c620fabb8d02c921a877a323c1a03 # Parent e25ad5cc0963ca0a6d2b8efe2772afa77b4835c4
libxl: remove force parameter from libxl_domain_destroy
Since a destroy is considered a forced shutdown, there's no point in passing a force parameter. All the occurences of this function have been replaced with the proper syntax.
tools/libxl/libxl.c +2 -2
@@ -723,7 +723,7 @@ int libxl_event_get_disk_eject_info(libxreturn 1 ; } -int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid,int force) +int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid) {GC_INIT (ctx);libxl_dominfo dominfo;
@@ -772,7 +772,7 @@ int libxl_domain_destroy(libxl_ctx *ctx,libxl__qmp_cleanup (gc, domid); } -if (libxl__devices_destroy (gc, domid, force) <0 ) +if (libxl__devices_destroy (gc, domid,1 ) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl__devices_destroy failed for %d" , domid);
tools/libxl/libxl.h +1 -1
@@ -269,7 +269,7 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd);int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid);int libxl_domain_shutdown (libxl_ctx *ctx,uint32_t domid,int req); -int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid,int force); +int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid);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 */
tools/libxl/libxl_create.c +1 -1
@@ -662,7 +662,7 @@ static int do_domain_create(libxl__gc *g error_out:if (domid) -libxl_domain_destroy (ctx, domid,0 ); +libxl_domain_destroy (ctx, domid);return ret; }
tools/libxl/libxl_dm.c +1 -1
@@ -917,7 +917,7 @@ int libxl__destroy_device_model(libxl__g goto out; }LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Device model is a stubdom, domid=%d" , stubdomid); - ret =libxl_domain_destroy (ctx, stubdomid,0 ); + ret =libxl_domain_destroy (ctx, stubdomid);if (ret) goto out; }else {
tools/libxl/xl_cmdimpl.c +6 -6
@@ -1283,7 +1283,7 @@ static int handle_domain_death(libxl_ctx/* 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,0 ); +libxl_domain_destroy (ctx, domid);break ;case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY :
@@ -1786,7 +1786,7 @@ start: error_out:release_lock ();if (libxl_domid_valid_guest (domid)) -libxl_domain_destroy (ctx, domid,0 ); +libxl_domain_destroy (ctx, domid); out:if (logfile !=2 )
@@ -2256,7 +2256,7 @@ static void destroy_domain(const char *pfprintf (stderr,"Cannot destroy privileged domain 0.\n\n" );exit (-1 ); } - rc =libxl_domain_destroy (ctx, domid,0 ); + rc =libxl_domain_destroy (ctx, domid);if (rc) {fprintf (stderr,"destroy failed (rc=%d)\n" ,rc);exit (-1 ); } }
@@ -2502,7 +2502,7 @@ static int save_domain(const char *p, coif (checkpoint)libxl_domain_unpause (ctx, domid);else -libxl_domain_destroy (ctx, domid,0 ); +libxl_domain_destroy (ctx, domid);exit (0 ); }
@@ -2735,7 +2735,7 @@ static void migrate_domain(const char *d }fprintf (stderr,"migration sender: Target reports successful startup.\n" ); -libxl_domain_destroy (ctx, domid,1 );/* bang! */ +libxl_domain_destroy (ctx, domid);/* bang! */ fprintf (stderr,"Migration successful.\n" );exit (0 );
@@ -2852,7 +2852,7 @@ static void migrate_receive(int debug, iif (rc) {fprintf (stderr,"migration target: Failure, destroying our copy.\n" ); - rc2 =libxl_domain_destroy (ctx, domid,1 ); + rc2 =libxl_domain_destroy (ctx, domid);if (rc2) {fprintf (stderr,"migration target: Failed to destroy our copy" " (code %d).\n" , rc2);
tools/python/xen/lowlevel/xl/xl.c +3 -3
@@ -437,10 +437,10 @@ static PyObject *pyxl_domain_shutdown(Xlstatic PyObject *pyxl_domain_destroy (XlObject *self,PyObject *args) { -int domid, force =1 ; -if ( !PyArg_ParseTuple (args,"i|i" , &domid, &force) ) +int domid; +if ( !PyArg_ParseTuple (args,"i" , &domid) )return NULL ; -if (libxl_domain_destroy (self->ctx, domid, force) ) { +if (libxl_domain_destroy (self->ctx, domid) ) {PyErr_SetString (xl_error_obj,"cannot destroy domain" );return NULL ; }
PATCH v5 1/1 libxl: remove force parameter from libxl__devices_destroy
In reply to Roger Pau Monne# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1323971746 -3600
# Node ID 5cb746278dd800860267939f6208abeb3239dc9c # Parent 1ab9421bf75c620fabb8d02c921a877a323c1a03
libxl: remove force parameter from libxl__devices_destroy
Remove the force flag, and always use forced destruction.
tools/libxl/libxl.c +1 -1
@@ -772,7 +772,7 @@ int libxl_domain_destroy(libxl_ctx *ctx,libxl__qmp_cleanup (gc, domid); } -if (libxl__devices_destroy (gc, domid,1 ) <0 ) +if (libxl__devices_destroy (gc, domid) <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl__devices_destroy failed for %d" , domid);
tools/libxl/libxl_device.c +4 -41
70 lines not on this page · raw message
tools/libxl/libxl_internal.h +1 -1
@@ -271,7 +271,7 @@ _hidden int libxl__parse_backend_path(li libxl__device *dev); _hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev, int wait); _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev); -_hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force); +_hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);/* Handler for the libxl__wait_for_device_state callback */
Ian Jackson
AppliedRoger Pau Monne writes ("[Xen-devel] [PATCH 0 of 6 ACKED v5] libxl: add support for hotplug script calling from libxl"):
Quoted 1 line
Previously acked patches from the series.
Applied all six, thanks.
Ian.