From 258cd4e261de3b3f4470ba390b16c73101c802ce Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 3 Aug 2012 09:54:09 +0100 Subject: libxl: fix device counting race in libxl__devices_destroy Don't have a fixed number of devices in the aodevs array, and instead size it depending on the devices present in xenstore. Somewhat formalise the multiple device addition/removal machinery to make this clearer and easier to do. As a side-effect we fix a few "lost thread of control" bug which would occur if there were no devices of a particular kind. (Various if statements which checked for there being no devices have become redundant, but are retained to avoid making the patch bigger.) Specifically: * Users of libxl__ao_devices are no longer expected to know in advance how many device operations they are going to do. Instead they can initiate them one at a time, between bracketing calls to "begin" and "prepared". * The array of aodevs used for this is dynamically sized; to support this it's an array of pointers rather than of structs. * Users of libxl__ao_devices are presented with a more opaque interface. They are are no longer expected to, themselves, - look into the array of aodevs (this is now private) - know that the individual addition/removal completions are handled by libxl__ao_devices_callback (this callback function is now a private function for the multidev machinery) - ever deal with populating the contents of an aodevs * The doc comments relating to some of the members of libxl__ao_device are clarified. (And the member `aodevs' is moved to put it with the other members with the same status.) * The multidev machinery allocates an aodev to represent the operation of preparing all of the other operations. See the comment in libxl__multidev_begin. A wrinkle is that the functions are called "multidev" but the structs are called "libxl__ao_devices" and "aodevs". I have given these functions this name to distinguish them from "libxl__ao_device" and "aodev" and so forth by more than just the use of the plural "s" suffix. In the next patch we will rename the structs. Signed-off-by: Roger Pau Monne Signed-off-by: Ian Jackson Acked-by: Ian Campbell Committed-by: Ian Campbell --- tools/libxl/libxl_dm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools/libxl/libxl_dm.c') diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index f2e9572bfa..177642b497 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -856,10 +856,10 @@ retry_transaction: if (errno == EAGAIN) goto retry_transaction; - sdss->aodevs.size = dm_config->num_disks; + libxl__multidev_begin(ao, &sdss->aodevs); sdss->aodevs.callback = spawn_stub_launch_dm; - libxl__prepare_ao_devices(ao, &sdss->aodevs); libxl__add_disks(egc, ao, dm_domid, 0, dm_config, &sdss->aodevs); + libxl__multidev_prepared(egc, &sdss->aodevs, 0); free(args); return; @@ -982,10 +982,10 @@ static void spawn_stubdom_pvqemu_cb(libxl__egc *egc, if (rc) goto out; if (d_config->num_nics > 0) { - sdss->aodevs.size = d_config->num_nics; + libxl__multidev_begin(ao, &sdss->aodevs); sdss->aodevs.callback = stubdom_pvqemu_cb; - libxl__prepare_ao_devices(ao, &sdss->aodevs); libxl__add_nics(egc, ao, dm_domid, 0, d_config, &sdss->aodevs); + libxl__multidev_prepared(egc, &sdss->aodevs, 0); return; } -- cgit v1.2.3