Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xenbus: limit when state is forced to closed

If a driver probe() fails then leave the xenstore state alone. There is no
reason to modify it as the failure may be due to transient resource
allocation issues and hence a subsequent probe() may succeed.

If the driver supports re-binding then only force state to closed during
remove() only in the case when the toolstack may need to clean up. This can
be detected by checking whether the state in xenstore has been set to
closing prior to device removal.

NOTE: Re-bind support is indicated by new boolean in struct xenbus_driver,
which defaults to false. Subsequent patches will add support to
some backend drivers.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>

authored by

Paul Durrant and committed by
Juergen Gross
672b7763 c534374e

+11 -2
+10 -2
drivers/xen/xenbus/xenbus_probe.c
··· 255 255 module_put(drv->driver.owner); 256 256 fail: 257 257 xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); 258 - xenbus_switch_state(dev, XenbusStateClosed); 259 258 return err; 260 259 } 261 260 EXPORT_SYMBOL_GPL(xenbus_dev_probe); ··· 275 276 276 277 free_otherend_details(dev); 277 278 278 - xenbus_switch_state(dev, XenbusStateClosed); 279 + /* 280 + * If the toolstack has forced the device state to closing then set 281 + * the state to closed now to allow it to be cleaned up. 282 + * Similarly, if the driver does not support re-bind, set the 283 + * closed. 284 + */ 285 + if (!drv->allow_rebind || 286 + xenbus_read_driver_state(dev->nodename) == XenbusStateClosing) 287 + xenbus_switch_state(dev, XenbusStateClosed); 288 + 279 289 return 0; 280 290 } 281 291 EXPORT_SYMBOL_GPL(xenbus_dev_remove);
+1
include/xen/xenbus.h
··· 93 93 struct xenbus_driver { 94 94 const char *name; /* defaults to ids[0].devicetype */ 95 95 const struct xenbus_device_id *ids; 96 + bool allow_rebind; /* avoid setting xenstore closed during remove */ 96 97 int (*probe)(struct xenbus_device *dev, 97 98 const struct xenbus_device_id *id); 98 99 void (*otherend_changed)(struct xenbus_device *dev,