Hi,

I am currently implementing both pre-copy cloning and post-copy cloning.

Problem: Facing a problem with device deletion and addition (related to
pre-copy cloning)

When the cloning process completes, we will end up having two VM with same
IP and MAC address. In order to change the IP and MAC of new VM (i.e., new
clone), we delete existing nic device and hot plug a new device (with a new
MAC address). We restrict VMs to use only DHCP address. As a result, with a
new MAC address, VM gets a new IP. For disk consistency, we create live
snapshots.

Source PM:
(Source VM -- From which a new clone is created)
$ /usr/local/bin/qemu-system-x86_64 -name VM3 -m 1024 -enable-kvm -smp 2
-drive
file=/root/kvm/VM3.img,if=none,id=drive-virtio-disk0,format=raw,cache=none
-device virtio-blk-pci,drive=drive-virtio-disk0,id=virtio-disk0 -netdev
tap,id=hostnet0,script=/usr/bin/qemu-ifup,downscript=/usr/bin/qemu-ifdown
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:cf:eb:91
-device virtio-balloon-pci,id=balloon0 -boot c -vnc 127.0.0.1:2 -vga cirrus
-monitor stdio

Destination PM:
(new VM -- cloned from Source VM)
/usr/local/bin/qemu-system-x86_64 -name VM3 -m 1024 -enable-kvm -smp 2
-drive
file=/root/kvm/VM3.img,if=none,id=drive-virtio-disk0,format=raw,cache=none
-device virtio-blk-pci,drive=drive-virtio-disk0,id=virtio-disk0 -netdev
tap,id=hostnet0,script=/usr/bin/qemu-ifup,downscript=/usr/bin/qemu-ifdown
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:cf:eb:91
-device virtio-balloon-pci,id=balloon0 -boot c -vnc 127.0.0.1:2 -vga cirrus
-monitor stdio -incoming tcp:0:4444

At destination, before performing vm_start(), we delete virtio-net-pci and
try to add a new virtio-net-pci. However, we are getting the following
error

*"qemu-system-x86_64: Property 'virtio-net-pci.netdev' can't take value
'hostnet0', it's in use" *

qemu-1.7.0/migration.c    2014-03-10 15:05:33.000000000 +0530
+++ migration.c    2014-03-17 02:33:48.000000000 +0530

 static void process_incoming_migration_co(void *opaque)
 {
     QEMUFile *f = opaque;
@@ -115,8 +120,26 @@
     /* Make sure all file formats flush their mutable metadata */
     bdrv_invalidate_cache_all();

+
     if (autostart) {
+        //CENDHU_START
+        char *device_name;
+        char *netdev_name;
+        char *info;
+        char driver[] = "virtio-net-pci";
+        char mac[] = "52:54:00:cf:eb:92";
+        Error *err = NULL;
+
+        get_info_network(&device_name, &netdev_name, &info); //assuming
only one nic
+        qmp_set_link(device_name, false, &err);
          vm_start();
+        qmp_device_del(device_name, &err);
+
+        net_device_add(device_name, netdev_name, driver, mac);
+        qmp_set_link(device_name, true, &err);
+        free(device_name);
+        free(netdev_name);
+        free(info);
     } else {
         runstate_set(RUN_STATE_PAUSED);
     }


qemu-1.7.0/qdev-monitor.c    2013-11-28 03:45:55.000000000 +0530
+++ qdev-monitor.c    2014-03-17 02:05:49.000000000 +0530
@@ -25,6 +25,14 @@
+int net_device_add(char *device_name, char *netdev_name, char *driver,
char *mac)
+{
+    QemuOpts *opts;
+    DeviceState *dev;
+    Error *err = NULL;
+    opts = qemu_opts_create(qemu_find_opts("device"), device_name, 0,
&err);
+    if(opts == NULL)
+        return -1;
+    qemu_opt_set_manual(opts, "driver", driver);
+    qemu_opt_set_manual(opts, "netdev", netdev_name);
+    qemu_opt_set_manual(opts, "mac", mac);
+    dev = qdev_device_add(opts);
+    if (!dev) {
+        //qemu_opts_del(opts);
+        return -1;
+    }
+}


qmp_device_del(net0, &err) successfully delete virtio-net-pci device.

when we try to add a virtio-net-pci device with a new MAC address, i.e,
net_device_add(net0, hostnet0, virtio-net-pci,52:54:00:cf:eb:92);, we get


*"qemu-system-x86_64: Property 'virtio-net-pci.netdev' can't take value
'hostnet0', it's in use"*
When we tried from qemu monitor, we were able to delete and add device
successfully.

(qemu) info network
net0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:cf:eb:91
 \ hostnet0:
index=0,type=tap,ifname=tap0,script=/usr/bin/qemu-ifup,downscript=/usr/bin/qemu-ifdown
(qemu) device_del net0
(qemu) info network
hostnet0:
index=0,type=tap,ifname=tap0,script=/usr/bin/qemu-ifup,downscript=/usr/bin/qemu-ifdown
(qemu) device_add
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:cf:eb:92
(qemu) info network
net0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:cf:eb:92
 \ hostnet0:
index=0,type=tap,ifname=tap0,script=/usr/bin/qemu-ifup,downscript=/usr/bin/qemu-ifdown

Any idea?

Thanks
Cendhu

Reply via email to