libxl: add support for FreeBSD block hotplug scripts
v2 cover libxl: add support for FreeBSD block hotplug scripts
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
The current blkback implementation in FreeBSD HEAD doesn't yet know about hotplug scripts, I plan to commit the FreeBSD side once this series is reviewed.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 2/7 libxl: introduce an OS-specific function to get the physical-device
Linux and NetBSD will return the device major and minor numbers encoded in hex and separated by a ":". FreeBSD on the other hand returns the path to the block device or image file.
---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
--- tools/libxl/libxl.c | 9 +++++---- tools/libxl/libxl_freebsd.c | 6 ++++++ tools/libxl/libxl_internal.h | 6 ++++++ tools/libxl/libxl_linux.c | 10 ++++++++++ tools/libxl/libxl_netbsd.c | 10 ++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-)
tools/libxl/libxl.c +5 -4
@@ -2515,10 +2515,11 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,*/ if (!disk->script && disk->backend_domid ==LIBXL_TOOLSTACK_DOMID ) { -int major, minor; -if (!libxl__device_physdisk_major_minor (dev, &major, &minor)) -flexarray_append_pair (back,"physical-device" , -GCSPRINTF ("%x:%x" , major, minor)); +char *physdev; + + physdev =libxl__get_physical_device (dev); +if (physdev !=NULL ) +flexarray_append_pair (back,"physical-device" , physdev); }assert (device->backend_kind ==LIBXL__DEVICE_KIND_VBD );
tools/libxl/libxl_freebsd.c +6 -0
@@ -143,3 +143,9 @@ int libxl__pci_topology_init(libxl__gc *gc, {return ERROR_NI ; } + +char *libxl__get_physical_device (char *dev) +{ + +return dev; +}
tools/libxl/libxl_internal.h +6 -0
@@ -1346,6 +1346,12 @@ void libxl__domaindeathcheck_stop(libxl__gc *gc, libxl__domaindeathcheck *dc);*/ _hidden int libxl__try_phy_backend(mode_t st_mode); +/* +* Fetch the "physical-device" backend xenstore field for a local disk +* device. The implementation of this function is OS-specific. +*/ +_hidden char *libxl__get_physical_device(char *dev); + _hidden char *libxl__devid_to_localdev(libxl__gc *gc, int devid);
tools/libxl/libxl_linux.c +10 -0
@@ -347,3 +347,13 @@ int libxl__pci_topology_init(libxl__gc *gc,return err; } + +char *libxl__get_physical_device (char *dev) +{ +int major, minor; + +if (libxl__device_physdisk_major_minor (dev, &major, &minor)) +return NULL ; + +return GCSPRINTF ("%x:%x" , major, minor); +}
tools/libxl/libxl_netbsd.c +10 -0
@@ -100,3 +100,13 @@ int libxl__pci_topology_init(libxl__gc *gc, {return ERROR_NI ; } + +char *libxl__get_physical_device (char *dev) +{ +int major, minor; + +if (libxl__device_physdisk_major_minor (dev, &major, &minor)) +return NULL ; + +return GCSPRINTF ("%x:%x" , major, minor); +}
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 1/7 blkif: document how FreeBSD uses the physical-device backend node
In reply to Roger Pau MonneFreeBSD blkback uses the physical-device xenstore node in order to fetch the path to the underlying backing storage (either a block device or raw image). This node is set by the hotplug scripts.
---
Cc: Ian Campbell <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Tim Deegan <[email protected]>
--- xen/include/public/io/blkif.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
xen/include/public/io/blkif.h +10 -6
@@ -89,14 +89,18 @@* Values: string * * A free formatted string providing sufficient information for the -* backend driver to open the backing device. (e.g. the path to the -* file or block device representing the backing store.) +* hotplug script to attach the device and provide a suitable +* handler (ie: a block device) for blkback to use. * -* physical-device -* Values: "MAJOR:MINOR" +* physical-device: +* Values: OS specific * -* MAJOR and MINOR are the major number and minor number of the -* backing device respectively. +* A free formatted string that contains the OS specific path to the +* backing device for this blkback instance. +* +* Linux and NetBSD encode the block device major and minor numbers using +* the following printf format: "%x:%x", while FreeBSD places the path to +* the file or device in the filesystem. * * type * Values: "file", "phy", "tap"
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 3/7 hotplug/FreeBSD: add block hotplug script
In reply to Roger Pau MonneThis is the default hotplug script for block devices. Its only job is to copy the "params" blkback xenstore node to "physical-device".
---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
--- tools/hotplug/FreeBSD/Makefile | 2 +- tools/hotplug/FreeBSD/block | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tools/hotplug/FreeBSD/block
tools/hotplug/FreeBSD/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk # Xen script dir and scripts to go there. -XEN_SCRIPTS = vif-bridge +XEN_SCRIPTS = vif-bridge block XEN_SCRIPT_DATA =
tools/hotplug/FreeBSD/block new file +25 -0
@@ -0,0 +1,25 @@ +#!/bin/sh -e +# +# FreeBSD hotplug script for attaching disks +# +# Parameters: +# $1: xenstore backend path of the vbd +# $2: action, either "add" or "remove" +# +# Environment variables: +# None +# + +path=$1 +action=$2 +params=$(xenstore-read "$path/params") + +case $action in +add) + xenstore-write $path/physical-device $params + exit 0 + ;; +*) + exit 0 + ;; +esac
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 4/7 libxl/FreeBSD: add support for disk hotplug scripts
In reply to Roger Pau MonneAllow FreeBSD to execute hotplug scripts when attaching disk devices.
---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
--- tools/libxl/libxl_freebsd.c | 114 ++++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 31 deletions(-)
tools/libxl/libxl_freebsd.c +83 -31
@@ -59,14 +59,36 @@ static int libxl__hotplug_env_nic(libxl__gc *gc, libxl__device *dev, char ***envreturn 0 ; } -static int libxl__hotplug_nic (libxl__gc *gc,libxl__device *dev,char ***args, -libxl__device_action action) +static int libxl__hotplug_nic (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action, +int num_exec) { +libxl_nic_type nictype;char *be_path =libxl__device_backend_path (gc, dev);char *script; -int nr =0 , rc =0 , arraysize =4 ; +int nr =0 , rc; -assert (dev->backend_kind ==LIBXL__DEVICE_KIND_VIF ); + rc =libxl__nic_type (gc, dev, &nictype); +if (rc) { +LOG (ERROR ,"error when fetching nic type" ); + rc =ERROR_FAIL ; + goto out; + } + +/* +* For PV domains only one pass is needed (because there's no emulated +* interface). For HVM domains two passes are needed in order to add +* both the PV and the tap interfaces to the bridge. +*/ +if (nictype ==LIBXL_NIC_TYPE_VIF && num_exec !=0 ) { + rc =0 ; + goto out; + } + + rc =libxl__hotplug_env_nic (gc, dev, env, num_exec); +if (rc) + goto out; script =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/%s" , be_path,"script" ));
@@ -76,53 +98,83 @@ static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, char ***args, goto out; } +const int arraysize =4 ;GCNEW_ARRAY (*args, arraysize); (*args)[nr++] = script; (*args)[nr++] = be_path; - (*args)[nr++] =GCSPRINTF ("%s" , action ==LIBXL__DEVICE_ACTION_ADD ? -"add" :"remove" ); + (*args)[nr++] = (char *)libxl__device_action_to_string (action); (*args)[nr++] =NULL ;assert (nr == arraysize); + rc =1 ; + out:return rc; } +static int libxl__hotplug_disk (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +char *be_path =libxl__device_backend_path (gc, dev); +char *script; +int nr =0 , rc; + + script =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path,"script" )); +if (!script) { +LOGEV (ERROR , errno,"unable to read script from %s" , be_path); + rc =ERROR_FAIL ; + goto error; + } + +const int arraysize =4 ; +GCNEW_ARRAY (*args, arraysize); + (*args)[nr++] = script; + (*args)[nr++] = be_path; + (*args)[nr++] = (char *)libxl__device_action_to_string (action); + (*args)[nr++] =NULL ; +assert (nr == arraysize); + + rc =1 ; + +error: +return rc; +} +int libxl__get_hotplug_script_info (libxl__gc *gc,libxl__device *dev,char ***args,char ***env,libxl__device_action action,int num_exec) { -libxl_nic_type nictype;int rc; -if (dev->backend_kind !=LIBXL__DEVICE_KIND_VIF || num_exec ==2 ) -return 0 ; - - rc =libxl__nic_type (gc, dev, &nictype); -if (rc) { -LOG (ERROR ,"error when fetching nic type" ); - rc =ERROR_FAIL ; - goto out; - } - -/* -* For PV domains only one pass is needed (because there's no emulated -* interface). For HVM domains two passes are needed in order to add -* both the PV and the tap interfaces to the bridge. -*/ -if (nictype ==LIBXL_NIC_TYPE_VIF && num_exec !=0 ) { +switch (dev->backend_kind) { +case LIBXL__DEVICE_KIND_VBD : +if (num_exec !=0 ) { + rc =0 ; + goto out; + } + rc =libxl__hotplug_disk (gc, dev, args, env, action); +break ; +case LIBXL__DEVICE_KIND_VIF : +/* +* If domain has a stubdom we don't have to execute hotplug scripts +* for emulated interfaces +*/ +if ((num_exec >1 ) || + (libxl_get_stubdom_id (CTX , dev->domid) && num_exec)) { + rc =0 ; + goto out; + } + rc =libxl__hotplug_nic (gc, dev, args, env, action, num_exec); +break ; +default : +/* No need to execute any hotplug scripts */ rc =0 ; - goto out; +break ; } - rc =libxl__hotplug_env_nic (gc, dev, env, num_exec); -if (rc) - goto out; - - rc =libxl__hotplug_nic (gc, dev, args, action); -if (!rc) rc =1 ; - out:return rc; }
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 5/7 libxl: properly use vdev vs local device
In reply to Roger Pau MonneThe current code in libxl assumed that vdev is equal to local device, but this is only true for Linux systems. In other OSes the local device can use a nomenclature completely different from the virtual device one.
Move the current libxl__devid_to_localdev Linux implementation out of the OS-specific file and rename it to libxl__devid_to_vdev, and then make sure local_device_attach_cb return the local device in the diskpath field.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
--- tools/libxl/libxl.c | 12 ++++------ tools/libxl/libxl_device.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_linux.c | 49 +------------------------------------ 4 files changed, 64 insertions(+), 55 deletions(-)
tools/libxl/libxl.c +5 -7
@@ -3071,7 +3071,7 @@ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user, GCSPRINTF("%s/device/vbd/%d/backend", dompath, devid)) == NULL) {if (errno ==ENOENT ) -return libxl__devid_to_localdev (gc, devid); +return libxl__devid_to_vdev (gc, devid);else return NULL ; }
@@ -3137,7 +3137,7 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao);libxl__disk_local_state *dls =CONTAINER_OF (aodev, *dls, aodev); -char *dev =NULL , *be_path =NULL ; +char *be_path =NULL ;int rc;libxl__device device;libxl_device_disk *disk = &dls->disk;
@@ -3151,9 +3151,6 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev) goto out; } - dev =GCSPRINTF ("/dev/%s" , disk->vdev); -LOG (DEBUG ,"locally attaching disk %s" , dev); - rc =libxl__device_from_disk (gc,LIBXL_TOOLSTACK_DOMID , disk, &device);if (rc <0 ) goto out;
@@ -3162,8 +3159,9 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)if (rc <0 ) goto out; -if (dev !=NULL ) - dls->diskpath =libxl__strdup (gc, dev); + dls->diskpath =GCSPRINTF ("/dev/%s" , +libxl__devid_to_localdev (gc, device.devid)); +LOG (DEBUG ,"locally attached disk %s" , dls->diskpath); dls->callback (egc, dls,0 );return ;
tools/libxl/libxl_device.c +57 -0
63 lines not on this page · raw message
tools/libxl/libxl_internal.h +1 -0
@@ -1156,6 +1156,7 @@ _hidden int libxl__device_disk_set_backend(libxl__gc*, libxl_device_disk*); _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor); _hidden int libxl__device_disk_dev_number(const char *virtpath,int *pdisk,int *ppartition); +_hidden char *libxl__devid_to_vdev(libxl__gc *gc, int devid); _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid, libxl__device_console *console,
tools/libxl/libxl_linux.c +1 -48
57 lines not on this page · raw message
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 6/7 libxl: add a FreeBSD implementation of libxl__devid_to_localdev
In reply to Roger Pau MonneThis code is extracted from the FreeBSD blkfront implementation.
--- tools/libxl/libxl_freebsd.c | 54 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-)
tools/libxl/libxl_freebsd.c +52 -2
@@ -27,8 +27,58 @@ int libxl__try_phy_backend(mode_t st_mode)char *libxl__devid_to_localdev (libxl__gc *gc,int devid) { -/* TODO */ -return NULL ; +/* This translation table has been copied from the FreeBSD blkfront code. */ +const static struct vdev_info { +int major; +int shift; +int base; +const char *name; + } info[] = { + {3 ,6 ,0 ,"ada" },/* ide0 */ + {22 ,6 ,2 ,"ada" },/* ide1 */ + {33 ,6 ,4 ,"ada" },/* ide2 */ + {34 ,6 ,6 ,"ada" },/* ide3 */ + {56 ,6 ,8 ,"ada" },/* ide4 */ + {57 ,6 ,10 ,"ada" },/* ide5 */ + {88 ,6 ,12 ,"ada" },/* ide6 */ + {89 ,6 ,14 ,"ada" },/* ide7 */ + {90 ,6 ,16 ,"ada" },/* ide8 */ + {91 ,6 ,18 ,"ada" },/* ide9 */ + + {8 ,4 ,0 ,"da" },/* scsi disk0 */ + {65 ,4 ,16 ,"da" },/* scsi disk1 */ + {66 ,4 ,32 ,"da" },/* scsi disk2 */ + {67 ,4 ,48 ,"da" },/* scsi disk3 */ + {68 ,4 ,64 ,"da" },/* scsi disk4 */ + {69 ,4 ,80 ,"da" },/* scsi disk5 */ + {70 ,4 ,96 ,"da" },/* scsi disk6 */ + {71 ,4 ,112 ,"da" },/* scsi disk7 */ + {128 ,4 ,128 ,"da" },/* scsi disk8 */ + {129 ,4 ,144 ,"da" },/* scsi disk9 */ + {130 ,4 ,160 ,"da" },/* scsi disk10 */ + {131 ,4 ,176 ,"da" },/* scsi disk11 */ + {132 ,4 ,192 ,"da" },/* scsi disk12 */ + {133 ,4 ,208 ,"da" },/* scsi disk13 */ + {134 ,4 ,224 ,"da" },/* scsi disk14 */ + {135 ,4 ,240 ,"da" },/* scsi disk15 */ + + {202 ,4 ,0 ,"xbd" },/* xbd */ + + {0 ,0 ,0 ,NULL }, + }; +int major = devid >>8 ; +int minor = devid &0xff ; +int i; + +if (devid & (1 <<28 )) +return GCSPRINTF ("%s%d" ,"xbd" , (devid & ((1 <<28 ) -1 )) >>8 ); + +for (i =0 ; info[i].major; i++) +if (info[i].major == major) +return GCSPRINTF ("%s%d" , info[i].name, + info[i].base + (minor >> info[i].shift)); + +return GCSPRINTF ("%s%d" ,"xbd" , minor >>4 ); }/* Hotplug scripts caller functions */
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v2 7/7 libxl: fix error message in local_device_attach_cb
In reply to Roger Pau MonneThe fields that are printed might not be set in the case of a failure, which generates a segmentation fault.
---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
--- tools/libxl/libxl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
tools/libxl/libxl.c +1 -4
@@ -3144,10 +3144,7 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev) rc = aodev->rc;if (rc) { -LOGE (ERROR ,"unable to %s %s with id %u" , -libxl__device_action_to_string (aodev->action), -libxl__device_kind_to_string (aodev->dev->kind), - aodev->dev->devid); +LOGE (ERROR ,"unable locally attach device: %s" , disk->pdev_path); goto out; }
Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 5 lines · Roger Pau Monne
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
Just to catch me up here -- is this an incompatible thing that FreeBSD *already* does, or something you're adding with this series?
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
El 29/2/16 a les 13:15, George Dunlap ha escrit:
Quoted 9 lines · Roger Pau Monne
Quoted 5 lines
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
Just to catch me up here -- is this an incompatible thing that FreeBSD *already* does, or something you're adding with this series?
I assume you mean the usage of the "physical-device" node, right? In which case, this is something that I'm adding with this series (and some FreeBSD kernel changes, of course). Current FreeBSD code doesn't use physical-device at all.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 8 lines · Roger Pau Monné
El 29/2/16 a les 13:15, George Dunlap ha escrit:
Quoted 7 lines · Roger Pau Monne
Quoted 5 lines
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
Quoted 7 lines
Quoted 2 lines
Just to catch me up here -- is this an incompatible thing that FreeBSD *already* does, or something you're adding with this series?
I assume you mean the usage of the "physical-device" node, right? In which case, this is something that I'm adding with this series (and some FreeBSD kernel changes, of course). Current FreeBSD code doesn't use physical-device at all.
So there are cases where libxl could use the actual path to the resulting device (if available) as well. Rather than overloading physical-device, what about making a new node, with a path, that can be used by all of them?
I submitted such a patch here:
As part of a series allowing HVM domains to use hotplug scripts.
Thoughts?
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
El 29/2/16 a les 15:26, George Dunlap ha escrit:
Quoted 22 lines · Roger Pau Monné
Quoted 8 lines
El 29/2/16 a les 13:15, George Dunlap ha escrit:
Quoted 7 lines · Roger Pau Monne
Quoted 5 lines
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
Quoted 7 lines
Quoted 2 lines
Just to catch me up here -- is this an incompatible thing that FreeBSD *already* does, or something you're adding with this series?
I assume you mean the usage of the "physical-device" node, right? In which case, this is something that I'm adding with this series (and some FreeBSD kernel changes, of course). Current FreeBSD code doesn't use physical-device at all.
So there are cases where libxl could use the actual path to the resulting device (if available) as well. Rather than overloading physical-device, what about making a new node, with a path, that can be used by all of them?
Quoted 7 lines
I submitted such a patch here:
As part of a series allowing HVM domains to use hotplug scripts.
Thoughts?
TBH, I thought we were planning to use local attach to deal with both HVM guests with hotplug scripts and HVM guests using disks on driver domains. The solution you propose only solves the first part (hotplug scripts), but for disks coming from driver domains we would still need to use local-attach, so I would be in favour of always using local attach.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 29 lines · Roger Pau Monné
El 29/2/16 a les 15:26, George Dunlap ha escrit:
Quoted 28 lines · Roger Pau Monné
Quoted 8 lines
El 29/2/16 a les 13:15, George Dunlap ha escrit:
Quoted 7 lines · Roger Pau Monne
Quoted 5 lines
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
Quoted 7 lines
Quoted 2 lines
Just to catch me up here -- is this an incompatible thing that FreeBSD *already* does, or something you're adding with this series?
I assume you mean the usage of the "physical-device" node, right? In which case, this is something that I'm adding with this series (and some FreeBSD kernel changes, of course). Current FreeBSD code doesn't use physical-device at all.
So there are cases where libxl could use the actual path to the resulting device (if available) as well. Rather than overloading physical-device, what about making a new node, with a path, that can be used by all of them?
I submitted such a patch here:
As part of a series allowing HVM domains to use hotplug scripts.
Quoted 7 lines
Quoted 1 line
Thoughts?
TBH, I thought we were planning to use local attach to deal with both HVM guests with hotplug scripts and HVM guests using disks on driver domains. The solution you propose only solves the first part (hotplug scripts), but for disks coming from driver domains we would still need to use local-attach, so I would be in favour of always using local attach.
So the bootloader path basically has a feature where it says, "If you can find a local path, just use it; otherwise do local attach". This seems like a sensible path to take, as it avoids going through the whole process of doing a local attach / detach when the disk is already available. It seems like doing the same thing for qemu, and for disks with hotplug scripts, makes a lot of sense.
Additionally, I doubt I'm going to have time to do anything wrt local attach before 4.7; this (with the appropriate libxl additions) could allow HVM guests for non-driver domains to have full parity with PV guests in a relatively simple way.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 1/7] blkif: document how FreeBSD uses the physical-device backend node
In reply to Roger Pau MonneQuoted 30 lines · Roger Pau Monne
FreeBSD blkback uses the physical-device xenstore node in order to fetch the path to the underlying backing storage (either a block device or raw image). This node is set by the hotplug scripts.
Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Ian Campbell <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Tim Deegan <[email protected]>--- xen/include/public/io/blkif.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)xen/include/public/io/blkif.h +3
-4@@ -89,14 +89,18 @@* Values: string * * A free formatted string providing sufficient information for the -* backend driver to open the backing device. (e.g. the path to the -* file or block device representing the backing store.) +* hotplug script to attach the device and provide a suitable +* handler (ie: a block device) for blkback to use. * -* physical-device -* Values: "MAJOR:MINOR" +* physical-device:
xen/include/public/io/blkif.h line 103
Quoted 10 lines
xen/include/public/io/blkif.h +7
-2+* Values: OS specific * -* MAJOR and MINOR are the major number and minor number of the -* backing device respectively. +* A free formatted string that contains the OS specific path to the +* backing device for this blkback instance. +* +* Linux and NetBSD encode the block device major and minor numbers using +* the following printf format: "%x:%x", while FreeBSD places the path to +* the file or device in the filesystem.
I think this is a sensible approach FWIW.
Wei.
Quoted 11 lines
xen/include/public/io/blkif.h +0
-0* * type * Values: "file", "phy", "tap" Signature · 7 lines
2.5.4 (Apple Git-61) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 2/7] libxl: introduce an OS-specific function to get the physical-device
In reply to Roger Pau MonneQuoted 5 lines · Roger Pau Monne
Linux and NetBSD will return the device major and minor numbers encoded in hex and separated by a ":". FreeBSD on the other hand returns the path to the block device or image file.
Signed-off-by Roger Pau Monné <[email protected]>
The code looks sensible.
The acceptance of the patch depends on whether we come to agreement to use the node as proposed in patch #1.
Quoted 37 lines
---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>--- tools/libxl/libxl.c | 9 +++++---- tools/libxl/libxl_freebsd.c | 6 ++++++ tools/libxl/libxl_internal.h | 6 ++++++ tools/libxl/libxl_linux.c | 10 ++++++++++ tools/libxl/libxl_netbsd.c | 10 ++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-)tools/libxl/libxl.c +5
-4@@ -2515,10 +2515,11 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,*/ if (!disk->script && disk->backend_domid ==LIBXL_TOOLSTACK_DOMID ) { -int major, minor; -if (!libxl__device_physdisk_major_minor (dev, &major, &minor)) -flexarray_append_pair (back,"physical-device" , -GCSPRINTF ("%x:%x" , major, minor)); +char *physdev; + + physdev =libxl__get_physical_device (dev); +if (physdev !=NULL ) +flexarray_append_pair (back,"physical-device" , physdev); }assert (device->backend_kind ==LIBXL__DEVICE_KIND_VBD );tools/libxl/libxl_freebsd.c +0
-0
tools/libxl/libxl_freebsd.c int libxl__pci_topology_init(libxl__gc *gc, · line 149
Quoted 7 lines
tools/libxl/libxl_freebsd.c +4
-0@@ -143,3 +143,9 @@ int libxl__pci_topology_init(libxl__gc *gc, {return ERROR_NI ; } + +char *libxl__get_physical_device (char *dev) +{ +
No need to have this extra blank line.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 3/7] hotplug/FreeBSD: add block hotplug script
In reply to Roger Pau MonneQuoted 4 lines · Roger Pau Monne
This is the default hotplug script for block devices. Its only job is to copy the "params" blkback xenstore node to "physical-device".
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 4/7] libxl/FreeBSD: add support for disk hotplug scripts
In reply to Roger Pau MonneQuoted 11 lines · Roger Pau Monne
Allow FreeBSD to execute hotplug scripts when attaching disk devices.
Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>--- tools/libxl/libxl_freebsd.c | 114 ++++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 31 deletions(-)
It's better to either break the refactoring to another patch or explicitly say there is refactoring in this patch.
Quoted 20 lines
tools/libxl/libxl_freebsd.c +20
-0+static int libxl__hotplug_disk (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +char *be_path =libxl__device_backend_path (gc, dev); +char *script; +int nr =0 , rc; + + script =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path,"script" )); +if (!script) { +LOGEV (ERROR , errno,"unable to read script from %s" , be_path); + rc =ERROR_FAIL ; + goto error; + } + +const int arraysize =4 ; +GCNEW_ARRAY (*args, arraysize); + (*args)[nr++] = script; + (*args)[nr++] = be_path;
tools/libxl/libxl_freebsd.c static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, char ***args, · line 144
Quoted 10 lines
tools/libxl/libxl_freebsd.c +10
-0+ (*args)[nr++] = (char *)libxl__device_action_to_string (action); + (*args)[nr++] =NULL ; +assert (nr == arraysize); + + rc =1 ; + +error: +return rc; +} +
The code looks fine.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 6/7] libxl: add a FreeBSD implementation of libxl__devid_to_localdev
In reply to Roger Pau MonneQuoted 3 lines · Roger Pau Monne
This code is extracted from the FreeBSD blkfront implementation.
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 5/7] libxl: properly use vdev vs local device
In reply to Roger Pau MonneQuoted 9 lines · Roger Pau Monne
The current code in libxl assumed that vdev is equal to local device, but this is only true for Linux systems. In other OSes the local device can use a nomenclature completely different from the virtual device one.
Move the current
libxl__devid_to_localdevLinux implementation out of the OS-specific file and rename it tolibxl__devid_to_vdev, and then make surelocal_device_attach_cbreturn the local device in the diskpath field.Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 7/7] libxl: fix error message in local_device_attach_cb
In reply to Roger Pau MonneQuoted 3 lines · Roger Pau Monne
The fields that are printed might not be set in the case of a failure, which generates a segmentation fault.
Right, I can see how this can fail.
In device_addrm_aocomplete we check if aodev is set. But I think that's a bit overkill for local attach.
Quoted 1 line
Signed-off-by Roger Pau Monné <[email protected]>
Quoted 27 lines
---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>--- tools/libxl/libxl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)tools/libxl/libxl.c +1
-4@@ -3144,10 +3144,7 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev) rc = aodev->rc;if (rc) { -LOGE (ERROR ,"unable to %s %s with id %u" , -libxl__device_action_to_string (aodev->action), -libxl__device_kind_to_string (aodev->dev->kind), - aodev->dev->devid); +LOGE (ERROR ,"unable locally attach device: %s" , disk->pdev_path); goto out; }Signature · 1 line
2.5.4 (Apple Git-61)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
El 29/2/16 a les 17:45, George Dunlap ha escrit:
Quoted 45 lines · Roger Pau Monné
Quoted 29 lines
El 29/2/16 a les 15:26, George Dunlap ha escrit:
Quoted 28 lines · Roger Pau Monné
Quoted 8 lines
El 29/2/16 a les 13:15, George Dunlap ha escrit:
Quoted 7 lines · Roger Pau Monne
Quoted 5 lines
This series enables using hotplug scripts with the FreeBSD blkback implementation. Since FreeBSD blkback can use both block devices and regular RAW files as disks, the physical-device xenstore backend node is now OS-specific, Linux and NetBSD will encode the device major and minor numbers there, while FreeBSD simply puts an absolute path to a disk image.
Quoted 7 lines
Quoted 2 lines
Just to catch me up here -- is this an incompatible thing that FreeBSD *already* does, or something you're adding with this series?
I assume you mean the usage of the "physical-device" node, right? In which case, this is something that I'm adding with this series (and some FreeBSD kernel changes, of course). Current FreeBSD code doesn't use physical-device at all.
So there are cases where libxl could use the actual path to the resulting device (if available) as well. Rather than overloading physical-device, what about making a new node, with a path, that can be used by all of them?
I submitted such a patch here:
As part of a series allowing HVM domains to use hotplug scripts.
Quoted 7 lines
Quoted 1 line
Thoughts?
TBH, I thought we were planning to use local attach to deal with both HVM guests with hotplug scripts and HVM guests using disks on driver domains. The solution you propose only solves the first part (hotplug scripts), but for disks coming from driver domains we would still need to use local-attach, so I would be in favour of always using local attach.
So the bootloader path basically has a feature where it says, "If you can find a local path, just use it; otherwise do local attach". This seems like a sensible path to take, as it avoids going through the whole process of doing a local attach / detach when the disk is already available. It seems like doing the same thing for qemu, and for disks with hotplug scripts, makes a lot of sense.
Quoted 4 lines
Additionally, I doubt I'm going to have time to do anything wrt local attach before 4.7; this (with the appropriate libxl additions) could allow HVM guests for non-driver domains to have full parity with PV guests in a relatively simple way.
Right, I'm not opposed to this. I can s/physical-device/physical-device-path/ in my series, but I would like to have a confirmation that this is the way we are going to proceed forward.
In fact, there's a user on the FreeBSD-Xen ML that's interested in working on hotplug script support for HVM guests, and I've told him that the right way to solve this would be to perform a local-attach and use the resulting device as the disk that's passed to QEMU.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 1/7] blkif: document how FreeBSD uses the physical-device backend node
In reply to Roger Pau MonneRoger Pau Monne writes ("[PATCH v2 1/7] blkif: document how FreeBSD uses the physical-device backend node"):
Quoted 3 lines
FreeBSD blkback uses the physical-device xenstore node in order to fetch the path to the underlying backing storage (either a block device or raw image). This node is set by the hotplug scripts.
I think it is undesirable that the interface to hotplug scripts would be platform-specific.
I would prefer it if hotplug scripts always produced a path, and libxl were responsible for converting it into a major/minor if required. (libxl already has to have platform-specific code to drive its driver domain's blkback).
This would be a change to the hotplug script protocol but I think it can be done in a backward-compatible way.
What do you think ?
(This is related to the conversation you and George had on irc.)
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel