[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] libxl: fix cleanup of tap devices in libxl__device_destroy
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1343900058 -3600 # Node ID f345fbfa8f50975b5c327669ceaf68c1d098da8f # Parent 075da4778b0a1a84680ef0acd26fcd3b01adeee4 libxl: fix cleanup of tap devices in libxl__device_destroy We pass be_path to tapdisk_destroy but we've already deleted it so it fails to read tapdisk-params. However it appears that we need to destroy the tap device after tearing down xenstore, to avoid the leak reported by Greg Wettstein in <201207312141.q6VLfJje012656@xxxxxxxxxxxxxxxxx>. So read the tapdisk-params in the cleanup transaction, before the remove, and pass that down to destroy_tapdisk instead. tapdisk-params may of course be NULL if the device isn't a tap device. There is no need to tear down the tap device from libxl__initiate_device_remove since this ultimately calls libxl__device_destroy. Propagate and log errors from libxl__device_destroy_tapdisk. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- This patch depends on Ian Jacksons "libxl: unify libxl__device_destroy and device_hotplug_done" and my "libxl: const correctness for libxl__xs_path_cleanup" diff -r 075da4778b0a -r f345fbfa8f50 tools/libxl/libxl_blktap2.c --- a/tools/libxl/libxl_blktap2.c Thu Aug 02 10:22:28 2012 +0100 +++ b/tools/libxl/libxl_blktap2.c Thu Aug 02 10:34:18 2012 +0100 @@ -51,28 +51,36 @@ char *libxl__blktap_devpath(libxl__gc *g } -void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path) +int libxl__device_destroy_tapdisk(libxl__gc *gc, char *params) { - char *path, *params, *type, *disk; + char *type, *disk; int err; tap_list_t tap; - path = libxl__sprintf(gc, "%s/tapdisk-params", be_path); - if (!path) return; - - params = libxl__xs_read(gc, XBT_NULL, path); - if (!params) return; - type = params; disk = strchr(params, ':'); - if (!disk) return; + if (!disk) { + LOG(ERROR, "Unable to parse params %s", params); + return ERROR_INVAL; + } *disk++ = '\0'; err = tap_ctl_find(type, disk, &tap); - if (err < 0) return; + if (err < 0) { + /* returns -errno */ + LOGEV(ERROR, -err, "Unable to find type %s disk %s", type, disk); + return ERROR_FAIL; + } - tap_ctl_destroy(tap.id, tap.minor); + err = tap_ctl_destroy(tap.id, tap.minor); + if (err < 0) { + LOGEV(ERROR, -err, "Failed to destroy tap device id %d minor %d", + tap.id, tap.minor); + return ERROR_FAIL; + } + + return 0; } /* diff -r 075da4778b0a -r f345fbfa8f50 tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Thu Aug 02 10:22:28 2012 +0100 +++ b/tools/libxl/libxl_device.c Thu Aug 02 10:34:18 2012 +0100 @@ -522,8 +522,10 @@ DEFINE_DEVICES_ADD(nic) int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) { - char *be_path = libxl__device_backend_path(gc, dev); + const char *be_path = libxl__device_backend_path(gc, dev); const char *fe_path = libxl__device_frontend_path(gc, dev); + const char *tapdisk_path = GCSPRINTF("%s/%s", be_path, "tapdisk-params"); + char *tapdisk_params; xs_transaction_t t = 0; int rc; @@ -531,6 +533,9 @@ int libxl__device_destroy(libxl__gc *gc, rc = libxl__xs_transaction_start(gc, &t); if (rc) goto out; + /* May not exist if this is not a tap device */ + tapdisk_params = libxl__xs_read(gc, t, tapdisk_path); + libxl__xs_path_cleanup(gc, t, fe_path); libxl__xs_path_cleanup(gc, t, be_path); @@ -539,7 +544,8 @@ int libxl__device_destroy(libxl__gc *gc, if (rc < 0) goto out; } - libxl__device_destroy_tapdisk(gc, be_path); + if (tapdisk_params) + rc = libxl__device_destroy_tapdisk(gc, tapdisk_params); out: return rc; @@ -789,8 +795,6 @@ void libxl__initiate_device_remove(libxl if (rc < 0) goto out; } - libxl__device_destroy_tapdisk(gc, be_path); - rc = libxl__ev_devstate_wait(gc, &aodev->backend_ds, device_backend_callback, state_path, XenbusStateClosed, diff -r 075da4778b0a -r f345fbfa8f50 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Thu Aug 02 10:22:28 2012 +0100 +++ b/tools/libxl/libxl_internal.h Thu Aug 02 10:34:18 2012 +0100 @@ -1344,8 +1344,9 @@ _hidden char *libxl__blktap_devpath(libx /* libxl__device_destroy_tapdisk: * Destroys any tapdisk process associated with the backend represented * by be_path. + * Always logs on failure. */ -_hidden void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path); +_hidden int libxl__device_destroy_tapdisk(libxl__gc *gc, char *params); _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid, libxl_device_disk *disk, diff -r 075da4778b0a -r f345fbfa8f50 tools/libxl/libxl_noblktap2.c --- a/tools/libxl/libxl_noblktap2.c Thu Aug 02 10:22:28 2012 +0100 +++ b/tools/libxl/libxl_noblktap2.c Thu Aug 02 10:34:18 2012 +0100 @@ -28,8 +28,9 @@ char *libxl__blktap_devpath(libxl__gc *g return NULL; } -void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path) +int libxl__device_destroy_tapdisk(libxl__gc *gc, char *params) { + return 0; } /* _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |