(ext) Pass disk geometry in kvm command
authorDimitris Aragiorgis <dimara@grnet.gr>
Tue, 3 Dec 2013 09:32:21 +0000 (11:32 +0200)
committerDimitris Aragiorgis <dimara@grnet.gr>
Thu, 27 Mar 2014 08:00:58 +0000 (10:00 +0200)
Currently we allow this feature only for ext templates that
allow arbitrary params per disk. If both 'heads' and 'secs'
params are given then 'cyls' is calculated from the disk size.

TODO: export these params in IDISK_PARAMS since the can be
useful for every disk.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>

lib/hypervisor/hv_kvm.py

index 30f0f05..50123ce 100644 (file)
@@ -1296,6 +1296,20 @@ class KVMHypervisor(hv_base.BaseHypervisor):
           dev_val += ",bus=pci.0,addr=%s" % hex(cfdev.pci)
         dev_opts.extend(["-device", dev_val])
 
+      # TODO: export disk geometry in IDISK_PARAMS
+      heads = cfdev.params.get('heads', None)
+      secs = cfdev.params.get('secs', None)
+      if heads and secs:
+        nr_sectors = cfdev.size * 1024 * 1024 / 512
+        cyls = nr_sectors / (int(heads) * int(secs))
+        if cyls > 16383:
+          cyls = 16383
+        elif cyls < 2:
+          cyls = 2
+        if cyls and heads and secs:
+          drive_val += (",cyls=%d,heads=%d,secs=%d" %
+                        (cyls, int(heads), int(secs)))
+
       dev_opts.extend(["-drive", drive_val])
 
     return dev_opts