[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 29 of 29 RFC] libxl: delegate plug/unplug of disk and nic devices to xldeviced
# HG changeset patch # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> # Date 1328189192 -3600 # Node ID 7de94a26474f869177ce16b59b61421bf342f820 # Parent 35164add2785b8606c0e9b771206d83862afd2c6 libxl: delegate plug/unplug of disk and nic devices to xldeviced Change the calls to libxl_device_<type>_<action> to libxl_device_<type>_hotplug_<action> for disk and nic device types. Alsoe enables hotplug script calling from libxl itself, by disabling some udev rules and removing the commented code in libxl__device_hotplug. Bootloading is handled attaching the requested device to Dom0 (xvda), and executing pygrub against that device (/dev/xvda). This should be fixed in future versions, since xvda might already be in use. Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> diff -r 35164add2785 -r 7de94a26474f tools/hotplug/Linux/xen-backend.rules --- a/tools/hotplug/Linux/xen-backend.rules Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/hotplug/Linux/xen-backend.rules Thu Feb 02 14:26:32 2012 +0100 @@ -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*", RUN+="/etc/xen/scripts/blktap $env{ACTION}" +# SUBSYSTEM=="xen-backend", KERNEL=="vbd*", 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-*", 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", 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" diff -r 35164add2785 -r 7de94a26474f tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/libxl/libxl.c Thu Feb 02 14:26:32 2012 +0100 @@ -1714,12 +1714,12 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u ret = 0; - libxl_device_disk_remove(ctx, domid, disks + i); - libxl_device_disk_add(ctx, domid, disk); + libxl_device_disk_hotplug_remove(ctx, domid, disks + i); + libxl_device_disk_hotplug_add(ctx, domid, disk); stubdomid = libxl_get_stubdom_id(ctx, domid); if (stubdomid) { - libxl_device_disk_remove(ctx, stubdomid, disks + i); - libxl_device_disk_add(ctx, stubdomid, disk); + libxl_device_disk_hotplug_remove(ctx, stubdomid, disks + i); + libxl_device_disk_hotplug_add(ctx, stubdomid, disk); } out: for (i = 0; i < num; i++) @@ -1735,52 +1735,13 @@ char * libxl_device_disk_local_attach(li char *ret = NULL; int rc; - rc = libxl__device_disk_set_backend(gc, disk); - if (rc) goto out; - - switch (disk->backend) { - case LIBXL_DISK_BACKEND_PHY: - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s", - disk->pdev_path); - dev = disk->pdev_path; - break; - case LIBXL_DISK_BACKEND_TAP: - switch (disk->format) { - case LIBXL_DISK_FORMAT_RAW: - /* optimise away the early tapdisk attach in this case */ - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching" - " tap disk %s directly (ie without using blktap)", - disk->pdev_path); - dev = disk->pdev_path; - break; - case LIBXL_DISK_FORMAT_VHD: - dev = libxl__blktap_devpath(gc, disk->pdev_path, - disk->format); - break; - case LIBXL_DISK_FORMAT_QCOW: - case LIBXL_DISK_FORMAT_QCOW2: - abort(); /* prevented by libxl__device_disk_set_backend */ - default: - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "unrecognized disk format: %d", disk->format); - break; - } - break; - case LIBXL_DISK_BACKEND_QDISK: - if (disk->format != LIBXL_DISK_FORMAT_RAW) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot locally" - " attach a qdisk image if the format is not raw"); - break; - } - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching qdisk %s\n", - disk->pdev_path); - dev = disk->pdev_path; - break; - default: - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend " - "type: %d", disk->backend); - break; + rc = libxl_device_disk_hotplug_add(ctx, 0, disk); + if (rc < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to attach disk %s to Dom0", + disk->pdev_path); + goto out; } + dev = libxl__sprintf(gc, "/dev/%s", disk->vdev); out: if (dev != NULL) @@ -1791,14 +1752,17 @@ char * libxl_device_disk_local_attach(li int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk) { - /* Nothing to do for PHYSTYPE_PHY. */ - - /* - * For other device types assume that the blktap2 process is - * needed by the soon to be started domain and do nothing. - */ - - return 0; + GC_INIT(ctx); + int rc; + + rc = libxl_device_disk_hotplug_destroy(ctx, 0, disk); + if (rc < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to attach disk %s to Dom0", + disk->pdev_path); + } + + GC_FREE; + return rc; } /******************************************************************************/ diff -r 35164add2785 -r 7de94a26474f tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/libxl/libxl_create.c Thu Feb 02 14:26:32 2012 +0100 @@ -500,12 +500,11 @@ static int do_domain_create(libxl__gc *g goto error_out; } - +#if 0 for (i = 0; i < d_config->num_disks; i++) { - ret = libxl__device_disk_set_backend(gc, &d_config->disks[i]); - if (ret) goto error_out; + d_config->disks[i].backend = LIBXL_DISK_BACKEND_PHY; } - +#endif if ( restore_fd < 0 ) { ret = libxl_run_bootloader(ctx, &d_config->b_info, d_config->num_disks > 0 ? &d_config->disks[0] : NULL, domid); if (ret) { @@ -534,7 +533,7 @@ static int do_domain_create(libxl__gc *g store_libxl_entry(gc, domid, dm_info); for (i = 0; i < d_config->num_disks; i++) { - ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]); + ret = libxl_device_disk_hotplug_add(ctx, domid, &d_config->disks[i]); if (ret) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot add disk %d to domain: %d", i, ret); @@ -543,7 +542,7 @@ static int do_domain_create(libxl__gc *g } } for (i = 0; i < d_config->num_vifs; i++) { - ret = libxl_device_nic_add(ctx, domid, &d_config->vifs[i]); + ret = libxl_device_nic_hotplug_add(ctx, domid, &d_config->vifs[i]); if (ret) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot add nic %d to domain: %d", i, ret); diff -r 35164add2785 -r 7de94a26474f tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/libxl/libxl_device.c Thu Feb 02 14:26:32 2012 +0100 @@ -805,7 +805,20 @@ int libxl__devices_destroy(libxl__gc *gc dev.kind = kind; dev.devid = atoi(devs[j]); - libxl__device_destroy(gc, &dev); + switch(dev.kind) { + case LIBXL__DEVICE_KIND_VIF: + case LIBXL__DEVICE_KIND_VBD: + case LIBXL__DEVICE_KIND_QDISK: + libxl__device_hotplug_disconnect(gc, &dev, + HOTPLUG_DEVICE_FORCE_DISCONNECT); + break; + case LIBXL__DEVICE_KIND_PCI: + case LIBXL__DEVICE_KIND_VFB: + case LIBXL__DEVICE_KIND_VKBD: + case LIBXL__DEVICE_KIND_CONSOLE: + libxl__device_destroy(gc, &dev); + break; + } } } } diff -r 35164add2785 -r 7de94a26474f tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/libxl/libxl_dm.c Thu Feb 02 14:26:32 2012 +0100 @@ -674,12 +674,12 @@ retry_transaction: goto retry_transaction; for (i = 0; i < num_disks; i++) { - ret = libxl_device_disk_add(ctx, domid, &disks[i]); + ret = libxl_device_disk_hotplug_add(ctx, domid, &disks[i]); if (ret) goto out_free; } for (i = 0; i < num_vifs; i++) { - ret = libxl_device_nic_add(ctx, domid, &vifs[i]); + ret = libxl_device_nic_hotplug_add(ctx, domid, &vifs[i]); if (ret) goto out_free; } diff -r 35164add2785 -r 7de94a26474f tools/libxl/libxl_linux.c --- a/tools/libxl/libxl_linux.c Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/libxl/libxl_linux.c Thu Feb 02 14:26:32 2012 +0100 @@ -27,7 +27,7 @@ int libxl__try_phy_backend(mode_t st_mod } /* Hotplug scripts helpers */ -#if 0 + static char **get_hotplug_env(libxl__gc *gc, libxl__device *dev) { libxl_ctx *ctx = libxl__gc_owner(gc); @@ -175,12 +175,12 @@ out: free(args); return rc; } -#endif /* 0 */ + int libxl__device_hotplug(libxl__gc *gc, libxl__device *dev, libxl__hotplug_action action) { int rc = 0; -#if 0 + switch (dev->backend_kind) { case LIBXL__DEVICE_KIND_VIF: rc = libxl__hotplug_nic(gc, dev, action); @@ -192,6 +192,6 @@ int libxl__device_hotplug(libxl__gc *gc, rc = 0; break; } -#endif /* 0 */ + return rc; } diff -r 35164add2785 -r 7de94a26474f tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Feb 02 14:25:12 2012 +0100 +++ b/tools/libxl/xl_cmdimpl.c Thu Feb 02 14:26:32 2012 +0100 @@ -4574,7 +4574,7 @@ int main_networkattach(int argc, char ** return 1; } } - if (libxl_device_nic_add(ctx, domid, &nic)) { + if (libxl_device_nic_hotplug_add(ctx, domid, &nic)) { fprintf(stderr, "libxl_device_nic_add failed.\n"); return 1; } @@ -4684,7 +4684,7 @@ int main_blockattach(int argc, char **ar return 0; } - if (libxl_device_disk_add(ctx, fe_domid, &disk)) { + if (libxl_device_disk_hotplug_add(ctx, fe_domid, &disk)) { fprintf(stderr, "libxl_device_disk_add failed.\n"); } return 0; @@ -4742,7 +4742,7 @@ int main_blockdetach(int argc, char **ar fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); return 1; } - if (libxl_device_disk_remove(ctx, domid, &disk)) { + if (libxl_device_disk_hotplug_remove(ctx, domid, &disk) < 0) { fprintf(stderr, "libxl_device_disk_remove failed.\n"); } return 0; _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |