static void backend_create_netif(struct backend_info *be);
static int register_csum_offload_watch(struct backend_info *be);
static void unregister_csum_offload_watch(struct backend_info *be);
+static void unregister_hotplug_status_watch(struct backend_info *be);
static int netback_remove(struct xenbus_device *dev)
{
netback_remove_accelerators(be, dev);
unregister_csum_offload_watch(be);
+ unregister_hotplug_status_watch(be);
if (be->netif) {
kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
+ xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
netif_disconnect(be->netif);
be->netif = NULL;
}
if (be->netif) {
unregister_csum_offload_watch(be);
+ xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
netif_disconnect(be->netif);
be->netif = NULL;
}
return 0;
}
+static void unregister_hotplug_status_watch(struct backend_info *be)
+{
+ if (be->have_hotplug_status_watch) {
+ unregister_xenbus_watch(&be->hotplug_status_watch);
+ kfree(be->hotplug_status_watch.node);
+ }
+ be->have_hotplug_status_watch = 0;
+}
+
+static void hotplug_status_changed(struct xenbus_watch *watch,
+ const char **vec,
+ unsigned int vec_size)
+{
+ struct backend_info *be = container_of(watch,
+ struct backend_info,
+ hotplug_status_watch);
+ char *str;
+ unsigned int len;
+
+ str = xenbus_read(XBT_NIL, be->dev->nodename, "hotplug-status", &len);
+ if ( IS_ERR(str) )
+ return;
+ if ( len == sizeof("connected")-1 && !memcmp(str, "connected", len) ) {
+ xenbus_switch_state(be->dev, XenbusStateConnected);
+ /* Not interested in this watch anymore. */
+ unregister_hotplug_status_watch(be);
+ }
+ kfree(str);
+}
+
static void connect(struct backend_info *be)
{
int err;
&be->netif->credit_usec);
be->netif->remaining_credit = be->netif->credit_bytes;
- xenbus_switch_state(dev, XenbusStateConnected);
+ unregister_hotplug_status_watch(be);
+ err = xenbus_watch_path2(dev, dev->nodename, "hotplug-status",
+ &be->hotplug_status_watch,
+ hotplug_status_changed);
+ if (err) {
+ /* Switch now, since we can't do a watch. */
+ xenbus_switch_state(dev, XenbusStateConnected);
+ } else {
+ be->have_hotplug_status_watch = 1;
+ }
netif_wake_queue(be->netif->dev);
}