virtio-net.c (3abad4a221e050d43fa8540677b285057642baaf) virtio-net.c (0e9a65c5b168b993b845ec2acb2568328c2353da)
1/*
2 * Virtio Network Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *

--- 3079 unchanged lines hidden (view full) ---

3088 assert(type != NULL);
3089
3090 g_free(n->netclient_name);
3091 g_free(n->netclient_type);
3092 n->netclient_name = g_strdup(name);
3093 n->netclient_type = g_strdup(type);
3094}
3095
1/*
2 * Virtio Network Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *

--- 3079 unchanged lines hidden (view full) ---

3088 assert(type != NULL);
3089
3090 g_free(n->netclient_name);
3091 g_free(n->netclient_type);
3092 n->netclient_name = g_strdup(name);
3093 n->netclient_type = g_strdup(type);
3094}
3095
3096static bool failover_unplug_primary(VirtIONet *n)
3096static bool failover_unplug_primary(VirtIONet *n, DeviceState *dev)
3097{
3098 HotplugHandler *hotplug_ctrl;
3099 PCIDevice *pci_dev;
3100 Error *err = NULL;
3101
3097{
3098 HotplugHandler *hotplug_ctrl;
3099 PCIDevice *pci_dev;
3100 Error *err = NULL;
3101
3102 hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
3102 hotplug_ctrl = qdev_get_hotplug_handler(dev);
3103 if (hotplug_ctrl) {
3103 if (hotplug_ctrl) {
3104 pci_dev = PCI_DEVICE(n->primary_dev);
3104 pci_dev = PCI_DEVICE(dev);
3105 pci_dev->partially_hotplugged = true;
3105 pci_dev->partially_hotplugged = true;
3106 hotplug_handler_unplug_request(hotplug_ctrl, n->primary_dev, &err);
3106 hotplug_handler_unplug_request(hotplug_ctrl, dev, &err);
3107 if (err) {
3108 error_report_err(err);
3109 return false;
3110 }
3111 } else {
3112 return false;
3113 }
3114 return true;
3115}
3116
3107 if (err) {
3108 error_report_err(err);
3109 return false;
3110 }
3111 } else {
3112 return false;
3113 }
3114 return true;
3115}
3116
3117static bool failover_replug_primary(VirtIONet *n, Error **errp)
3117static bool failover_replug_primary(VirtIONet *n, DeviceState *dev,
3118 Error **errp)
3118{
3119 Error *err = NULL;
3120 HotplugHandler *hotplug_ctrl;
3119{
3120 Error *err = NULL;
3121 HotplugHandler *hotplug_ctrl;
3121 PCIDevice *pdev = PCI_DEVICE(n->primary_dev);
3122 PCIDevice *pdev = PCI_DEVICE(dev);
3122 BusState *primary_bus;
3123
3124 if (!pdev->partially_hotplugged) {
3125 return true;
3126 }
3123 BusState *primary_bus;
3124
3125 if (!pdev->partially_hotplugged) {
3126 return true;
3127 }
3127 primary_bus = n->primary_dev->parent_bus;
3128 primary_bus = dev->parent_bus;
3128 if (!primary_bus) {
3129 error_setg(errp, "virtio_net: couldn't find primary bus");
3130 return false;
3131 }
3129 if (!primary_bus) {
3130 error_setg(errp, "virtio_net: couldn't find primary bus");
3131 return false;
3132 }
3132 qdev_set_parent_bus(n->primary_dev, primary_bus, &error_abort);
3133 qdev_set_parent_bus(dev, primary_bus, &error_abort);
3133 qatomic_set(&n->failover_primary_hidden, false);
3134 qatomic_set(&n->failover_primary_hidden, false);
3134 hotplug_ctrl = qdev_get_hotplug_handler(n->primary_dev);
3135 hotplug_ctrl = qdev_get_hotplug_handler(dev);
3135 if (hotplug_ctrl) {
3136 if (hotplug_ctrl) {
3136 hotplug_handler_pre_plug(hotplug_ctrl, n->primary_dev, &err);
3137 hotplug_handler_pre_plug(hotplug_ctrl, dev, &err);
3137 if (err) {
3138 goto out;
3139 }
3138 if (err) {
3139 goto out;
3140 }
3140 hotplug_handler_plug(hotplug_ctrl, n->primary_dev, &err);
3141 hotplug_handler_plug(hotplug_ctrl, dev, &err);
3141 }
3142
3143out:
3144 error_propagate(errp, err);
3145 return !err;
3146}
3147
3148static void virtio_net_handle_migration_primary(VirtIONet *n,

--- 7 unchanged lines hidden (view full) ---

3156 if (!n->primary_dev) {
3157 n->primary_dev = failover_find_primary_device(n);
3158 if (!n->primary_dev) {
3159 return;
3160 }
3161 }
3162
3163 if (migration_in_setup(s) && !should_be_hidden) {
3142 }
3143
3144out:
3145 error_propagate(errp, err);
3146 return !err;
3147}
3148
3149static void virtio_net_handle_migration_primary(VirtIONet *n,

--- 7 unchanged lines hidden (view full) ---

3157 if (!n->primary_dev) {
3158 n->primary_dev = failover_find_primary_device(n);
3159 if (!n->primary_dev) {
3160 return;
3161 }
3162 }
3163
3164 if (migration_in_setup(s) && !should_be_hidden) {
3164 if (failover_unplug_primary(n)) {
3165 if (failover_unplug_primary(n, n->primary_dev)) {
3165 vmstate_unregister(VMSTATE_IF(n->primary_dev),
3166 qdev_get_vmsd(n->primary_dev),
3167 n->primary_dev);
3168 qapi_event_send_unplug_primary(n->primary_dev->id);
3169 qatomic_set(&n->failover_primary_hidden, true);
3170 } else {
3171 warn_report("couldn't unplug primary device");
3172 }
3173 } else if (migration_has_failed(s)) {
3174 /* We already unplugged the device let's plug it back */
3166 vmstate_unregister(VMSTATE_IF(n->primary_dev),
3167 qdev_get_vmsd(n->primary_dev),
3168 n->primary_dev);
3169 qapi_event_send_unplug_primary(n->primary_dev->id);
3170 qatomic_set(&n->failover_primary_hidden, true);
3171 } else {
3172 warn_report("couldn't unplug primary device");
3173 }
3174 } else if (migration_has_failed(s)) {
3175 /* We already unplugged the device let's plug it back */
3175 if (!failover_replug_primary(n, &err)) {
3176 if (!failover_replug_primary(n, n->primary_dev, &err)) {
3176 if (err) {
3177 error_report_err(err);
3178 }
3179 }
3180 }
3181}
3182
3183static void virtio_net_migration_state_notifier(Notifier *notifier, void *data)

--- 378 unchanged lines hidden ---
3177 if (err) {
3178 error_report_err(err);
3179 }
3180 }
3181 }
3182}
3183
3184static void virtio_net_migration_state_notifier(Notifier *notifier, void *data)

--- 378 unchanged lines hidden ---