aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Campbell <Ian.Campbell@citrix.com>2015-06-01 06:30:24 -0400
committerDavid S. Miller <davem@davemloft.net>2015-06-01 15:03:04 -0400
commit31a418986a5852034d520a5bab546821ff1ccf3d (patch)
treef98e6736a2b8f13dde878f85e78dd747ecae160a
parentdc5e7a811d3e57f2b10a4c4c90b175ce498a097d (diff)
xen: netback: read hotplug script once at start of day.
When we come to tear things down in netback_remove() and generate the uevent it is possible that the xenstore directory has already been removed (details below). In such cases netback_uevent() won't be able to read the hotplug script and will write a xenstore error node. A recent change to the hypervisor exposed this race such that we now sometimes lose it (where apparently we didn't ever before). Instead read the hotplug script configuration during setup and use it for the lifetime of the backend device. The apparently more obvious fix of moving the transition to state=Closed in netback_remove() to after the uevent does not work because it is possible that we are already in state=Closed (in reaction to the guest having disconnected as it shutdown). Being already in Closed means the toolstack is at liberty to start tearing down the xenstore directories. In principal it might be possible to arrange to unregister the device sooner (e.g on transition to Closing) such that xenstore would still be there but this state machine is fragile and prone to anger... A modern Xen system only relies on the hotplug uevent for driver domains, when the backend is in the same domain as the toolstack it will run the necessary setup/teardown directly in the correct sequence wrt xenstore changes. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/xen-netback/xenbus.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index fee02414529e..968787abf78d 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -34,6 +34,8 @@ struct backend_info {
34 enum xenbus_state frontend_state; 34 enum xenbus_state frontend_state;
35 struct xenbus_watch hotplug_status_watch; 35 struct xenbus_watch hotplug_status_watch;
36 u8 have_hotplug_status_watch:1; 36 u8 have_hotplug_status_watch:1;
37
38 const char *hotplug_script;
37}; 39};
38 40
39static int connect_rings(struct backend_info *be, struct xenvif_queue *queue); 41static int connect_rings(struct backend_info *be, struct xenvif_queue *queue);
@@ -238,6 +240,7 @@ static int netback_remove(struct xenbus_device *dev)
238 xenvif_free(be->vif); 240 xenvif_free(be->vif);
239 be->vif = NULL; 241 be->vif = NULL;
240 } 242 }
243 kfree(be->hotplug_script);
241 kfree(be); 244 kfree(be);
242 dev_set_drvdata(&dev->dev, NULL); 245 dev_set_drvdata(&dev->dev, NULL);
243 return 0; 246 return 0;
@@ -255,6 +258,7 @@ static int netback_probe(struct xenbus_device *dev,
255 struct xenbus_transaction xbt; 258 struct xenbus_transaction xbt;
256 int err; 259 int err;
257 int sg; 260 int sg;
261 const char *script;
258 struct backend_info *be = kzalloc(sizeof(struct backend_info), 262 struct backend_info *be = kzalloc(sizeof(struct backend_info),
259 GFP_KERNEL); 263 GFP_KERNEL);
260 if (!be) { 264 if (!be) {
@@ -347,6 +351,15 @@ static int netback_probe(struct xenbus_device *dev,
347 if (err) 351 if (err)
348 pr_debug("Error writing multi-queue-max-queues\n"); 352 pr_debug("Error writing multi-queue-max-queues\n");
349 353
354 script = xenbus_read(XBT_NIL, dev->nodename, "script", NULL);
355 if (IS_ERR(script)) {
356 err = PTR_ERR(script);
357 xenbus_dev_fatal(dev, err, "reading script");
358 goto fail;
359 }
360
361 be->hotplug_script = script;
362
350 err = xenbus_switch_state(dev, XenbusStateInitWait); 363 err = xenbus_switch_state(dev, XenbusStateInitWait);
351 if (err) 364 if (err)
352 goto fail; 365 goto fail;
@@ -379,22 +392,14 @@ static int netback_uevent(struct xenbus_device *xdev,
379 struct kobj_uevent_env *env) 392 struct kobj_uevent_env *env)
380{ 393{
381 struct backend_info *be = dev_get_drvdata(&xdev->dev); 394 struct backend_info *be = dev_get_drvdata(&xdev->dev);
382 char *val;
383 395
384 val = xenbus_read(XBT_NIL, xdev->nodename, "script", NULL); 396 if (!be)
385 if (IS_ERR(val)) { 397 return 0;
386 int err = PTR_ERR(val); 398
387 xenbus_dev_fatal(xdev, err, "reading script"); 399 if (add_uevent_var(env, "script=%s", be->hotplug_script))
388 return err; 400 return -ENOMEM;
389 } else {
390 if (add_uevent_var(env, "script=%s", val)) {
391 kfree(val);
392 return -ENOMEM;
393 }
394 kfree(val);
395 }
396 401
397 if (!be || !be->vif) 402 if (!be->vif)
398 return 0; 403 return 0;
399 404
400 return add_uevent_var(env, "vif=%s", be->vif->dev->name); 405 return add_uevent_var(env, "vif=%s", be->vif->dev->name);