Revision ece1057c lib/hypervisor/hv_kvm.py
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
1021 | 1021 |
data.append(info) |
1022 | 1022 |
return data |
1023 | 1023 |
|
1024 |
def _GenerateKVMBlockDevicesOptions(self, instance, block_devices, kvmhelp): |
|
1025 |
|
|
1026 |
hvp = instance.hvparams |
|
1027 |
boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK |
|
1028 |
|
|
1029 |
# whether this is an older KVM version that uses the boot=on flag |
|
1030 |
# on devices |
|
1031 |
needs_boot_flag = self._BOOT_RE.search(kvmhelp) |
|
1032 |
|
|
1033 |
dev_opts = [] |
|
1034 |
disk_type = hvp[constants.HV_DISK_TYPE] |
|
1035 |
if disk_type == constants.HT_DISK_PARAVIRTUAL: |
|
1036 |
if_val = ",if=%s" % self._VIRTIO |
|
1037 |
else: |
|
1038 |
if_val = ",if=%s" % disk_type |
|
1039 |
# Cache mode |
|
1040 |
disk_cache = hvp[constants.HV_DISK_CACHE] |
|
1041 |
if instance.disk_template in constants.DTS_EXT_MIRROR: |
|
1042 |
if disk_cache != "none": |
|
1043 |
# TODO: make this a hard error, instead of a silent overwrite |
|
1044 |
logging.warning("KVM: overriding disk_cache setting '%s' with 'none'" |
|
1045 |
" to prevent shared storage corruption on migration", |
|
1046 |
disk_cache) |
|
1047 |
cache_val = ",cache=none" |
|
1048 |
elif disk_cache != constants.HT_CACHE_DEFAULT: |
|
1049 |
cache_val = ",cache=%s" % disk_cache |
|
1050 |
else: |
|
1051 |
cache_val = "" |
|
1052 |
for cfdev, dev_path in block_devices: |
|
1053 |
if cfdev.mode != constants.DISK_RDWR: |
|
1054 |
raise errors.HypervisorError("Instance has read-only disks which" |
|
1055 |
" are not supported by KVM") |
|
1056 |
# TODO: handle FD_LOOP and FD_BLKTAP (?) |
|
1057 |
boot_val = "" |
|
1058 |
if boot_disk: |
|
1059 |
dev_opts.extend(["-boot", "c"]) |
|
1060 |
boot_disk = False |
|
1061 |
if needs_boot_flag and disk_type != constants.HT_DISK_IDE: |
|
1062 |
boot_val = ",boot=on" |
|
1063 |
drive_val = "file=%s,format=raw%s%s%s" % \ |
|
1064 |
(dev_path, if_val, boot_val, cache_val) |
|
1065 |
|
|
1066 |
dev_opts.extend(["-drive", drive_val]) |
|
1067 |
|
|
1068 |
return dev_opts |
|
1069 |
|
|
1024 | 1070 |
def _GenerateKVMRuntime(self, instance, block_devices, startup_paused, |
1025 | 1071 |
kvmhelp): |
1026 | 1072 |
"""Generate KVM information to start an instance. |
... | ... | |
1089 | 1135 |
|
1090 | 1136 |
kernel_path = hvp[constants.HV_KERNEL_PATH] |
1091 | 1137 |
if kernel_path: |
1092 |
boot_disk = boot_cdrom = boot_floppy = boot_network = False
|
|
1138 |
boot_cdrom = boot_floppy = boot_network = False |
|
1093 | 1139 |
else: |
1094 |
boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK |
|
1095 | 1140 |
boot_cdrom = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_CDROM |
1096 | 1141 |
boot_floppy = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_FLOPPY |
1097 | 1142 |
boot_network = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_NETWORK |
... | ... | |
1107 | 1152 |
needs_boot_flag = self._BOOT_RE.search(kvmhelp) |
1108 | 1153 |
|
1109 | 1154 |
disk_type = hvp[constants.HV_DISK_TYPE] |
1110 |
if disk_type == constants.HT_DISK_PARAVIRTUAL: |
|
1111 |
if_val = ",if=virtio" |
|
1112 |
else: |
|
1113 |
if_val = ",if=%s" % disk_type |
|
1114 |
# Cache mode |
|
1115 |
disk_cache = hvp[constants.HV_DISK_CACHE] |
|
1116 |
if instance.disk_template in constants.DTS_EXT_MIRROR: |
|
1117 |
if disk_cache != "none": |
|
1118 |
# TODO: make this a hard error, instead of a silent overwrite |
|
1119 |
logging.warning("KVM: overriding disk_cache setting '%s' with 'none'" |
|
1120 |
" to prevent shared storage corruption on migration", |
|
1121 |
disk_cache) |
|
1122 |
cache_val = ",cache=none" |
|
1123 |
elif disk_cache != constants.HT_CACHE_DEFAULT: |
|
1124 |
cache_val = ",cache=%s" % disk_cache |
|
1125 |
else: |
|
1126 |
cache_val = "" |
|
1127 |
for cfdev, dev_path in block_devices: |
|
1128 |
if cfdev.mode != constants.DISK_RDWR: |
|
1129 |
raise errors.HypervisorError("Instance has read-only disks which" |
|
1130 |
" are not supported by KVM") |
|
1131 |
# TODO: handle FD_LOOP and FD_BLKTAP (?) |
|
1132 |
boot_val = "" |
|
1133 |
if boot_disk: |
|
1134 |
kvm_cmd.extend(["-boot", "c"]) |
|
1135 |
boot_disk = False |
|
1136 |
if needs_boot_flag and disk_type != constants.HT_DISK_IDE: |
|
1137 |
boot_val = ",boot=on" |
|
1138 |
|
|
1139 |
drive_val = "file=%s,format=raw%s%s%s" % (dev_path, if_val, boot_val, |
|
1140 |
cache_val) |
|
1141 |
kvm_cmd.extend(["-drive", drive_val]) |
|
1142 | 1155 |
|
1143 | 1156 |
#Now we can specify a different device type for CDROM devices. |
1144 | 1157 |
cdrom_disk_type = hvp[constants.HV_KVM_CDROM_DISK_TYPE] |
... | ... | |
1390 | 1403 |
if hvp[constants.HV_KVM_EXTRA]: |
1391 | 1404 |
kvm_cmd.extend(hvp[constants.HV_KVM_EXTRA].split(" ")) |
1392 | 1405 |
|
1406 |
bdev_opts = self._GenerateKVMBlockDevicesOptions(instance, |
|
1407 |
block_devices, |
|
1408 |
kvmhelp) |
|
1409 |
kvm_cmd.extend(bdev_opts) |
|
1393 | 1410 |
# Save the current instance nics, but defer their expansion as parameters, |
1394 | 1411 |
# as we'll need to generate executable temp files for them. |
1395 | 1412 |
kvm_nics = instance.nics |
Also available in: Unified diff