From: yacui <[email protected]>

Comments:
This patch is primarily made to support adding a floppy using the
-drive -global syntax. and the number of floppies is limited to 2.
The 3 places being changed are:
1 the add_drive function
2 a global counter of fdc_unit
3 the part of making qemu command for the floppy, now the primary
  method has been substituted by the "-drive -global" instead of
  the conventional "-fda method"

Signed-off-by: yacui <[email protected]>
---
 client/tests/kvm/kvm_vm.py |   49 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 67aa276..20a0125 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -301,7 +301,9 @@ class VM(object):
         def add_drive(help, filename, index=None, format=None, cache=None,
                       werror=None, serial=None, snapshot=False, boot=False,
                       imgfmt="raw", aio=None, media="disk", ide_bus=None,
-                      ide_unit=None, vdisk=None, pci_addr=None):
+                      ide_unit=None, vdisk=None, pci_addr=None,
+                      fdc_unit=None,readonly=False):
+
             free_pci_addr = get_free_pci_addr(pci_addr)
 
             dev = {"virtio" : "virtio-blk-pci",
@@ -315,6 +317,8 @@ class VM(object):
                     vdisk += 1
                 blkdev_id ="virtio-disk%s" % vdisk
                 id = "virtio-disk%s" % vdisk
+            elif format == "floppy":
+                id ="fdc0-0-%s" % fdc_unit
             blkdev_id = "drive-%s" % id
 
             # -drive part
@@ -327,18 +331,19 @@ class VM(object):
             else:
                 if format: cmd += ",if=%s" % format
 
-            cmd += ",media=%s" % media
+            if media:
+                cmd += ",media=%s" % media
             if cache: cmd += ",cache=%s" % cache
             if werror: cmd += ",werror=%s" % werror
             if serial: cmd += ",serial='%s'" % serial
             if snapshot: cmd += ",snapshot=on"
             if boot: cmd += ",boot=on"
-            if media == "cdrom": cmd += ",readonly=on"
+            if media == "cdrom" or readonly : cmd += ",readonly=on"
             cmd += ",format=%s" % imgfmt
             if ",aio=" in help and aio : cmd += ",aio=%s" % aio
 
             # -device part
-            if has_option(help, "device"):
+            if has_option(help, "device") and format != "floppy" :
                 cmd += " -device %s" % dev[format]
                 if format == "ide":
                     cmd += ",bus=%s" % ide_bus
@@ -348,6 +353,11 @@ class VM(object):
                 cmd += ",drive=%s" % blkdev_id
                 cmd += ",id=%s" % id
 
+            # -global part
+            drivelist = ['driveA','driveB']
+            if has_option(help,"global") and format == "floppy" :
+                cmd += " -global isa-fdc.%s=drive-%s" \
+                        % (drivelist[fdc_unit] , id)
             return cmd
 
         def add_nic(help, vlan, model=None, mac=None, netdev_id=None,
@@ -556,6 +566,7 @@ class VM(object):
         # global counters
         ide_bus = 0
         ide_unit = 0
+        fdc_unit = 0
         vdisk = 0
         self.pci_addr_list = [0, 1, 2]
 
@@ -722,13 +733,29 @@ class VM(object):
             if "2.6.32" not in commands.getoutput("uname -r"):
                 qemu_cmd += " -soundhw %s" % soundhw
 
-
-        # We may want to add {floppy_otps} parameter for -fda
-        # {fat:floppy:}/path/. However vvfat is not usually recommended.
-        floppy = params.get("floppy")
-        if floppy:
-            floppy = kvm_utils.get_path(root_dir, floppy)
-            qemu_cmd += add_floppy(help, floppy)
+        # We may want to add the floppy using the "-drive -global " format
+        # and the current script allow the nums of the floppies to be 2
+        # Readonly floppy is supported by adding the parameter 
+        # of floppy_readonly
+        floppies = params.get("floppy")
+        floppies_readonly = params.get("floppy_readonly")
+        if floppies:
+            floppy_list = floppies.split()
+            fl_readonly_list = floppies_readonly.split()
+            for index in range(len(fl_readonly_list)):
+                 fl_readonly_list[index] = eval(fl_readonly_list[index])
+            if len(floppy_list) > 2 :
+                raise error.TestError("Only the maximum of 2 floppies"
+                                      " can be supported here")
+            for (floppy,fl_readonly) in zip(floppy_list,fl_readonly_list):
+                floppy = kvm_utils.get_path(root_dir, floppy)
+                if has_option(help,"global"):
+                    qemu_cmd += add_drive(help,floppy,None,"floppy",
+                                      media=None,fdc_unit=fdc_unit,
+                                      readonly=fl_readonly)
+                else:
+                    qemu_cmd += add_floppy(help, floppy)
+                fdc_unit ^= 1
 
         usbdevice = params.get("usbdevice")
         if usbdevice:
-- 
1.7.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to