Revision af5db30c lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
1034 1034
        data.append(info)
1035 1035
    return data
1036 1036

  
1037
  def _GenerateKVMBlockDevicesOptions(self, instance, block_devices, kvmhelp):
1038

  
1039
    hvp = instance.hvparams
1040
    boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
1041

  
1042
    # whether this is an older KVM version that uses the boot=on flag
1043
    # on devices
1044
    needs_boot_flag = self._BOOT_RE.search(kvmhelp)
1045

  
1046
    dev_opts = []
1047
    disk_type = hvp[constants.HV_DISK_TYPE]
1048
    if disk_type == constants.HT_DISK_PARAVIRTUAL:
1049
      if_val = ",if=%s" % self._VIRTIO
1050
    else:
1051
      if_val = ",if=%s" % disk_type
1052
    # Cache mode
1053
    disk_cache = hvp[constants.HV_DISK_CACHE]
1054
    if instance.disk_template in constants.DTS_EXT_MIRROR:
1055
      if disk_cache != "none":
1056
        # TODO: make this a hard error, instead of a silent overwrite
1057
        logging.warning("KVM: overriding disk_cache setting '%s' with 'none'"
1058
                        " to prevent shared storage corruption on migration",
1059
                        disk_cache)
1060
      cache_val = ",cache=none"
1061
    elif disk_cache != constants.HT_CACHE_DEFAULT:
1062
      cache_val = ",cache=%s" % disk_cache
1063
    else:
1064
      cache_val = ""
1065
    for cfdev, dev_path, device in block_devices:
1066
      if cfdev.mode != constants.DISK_RDWR:
1067
        raise errors.HypervisorError("Instance has read-only disks which"
1068
                                     " are not supported by KVM")
1069
      # TODO: handle FD_LOOP and FD_BLKTAP (?)
1070
      boot_val = ""
1071
      if boot_disk:
1072
        dev_opts.extend(["-boot", "c"])
1073
        boot_disk = False
1074
        if needs_boot_flag and disk_type != constants.HT_DISK_IDE:
1075
          boot_val = ",boot=on"
1076

  
1077
      access_mode = cfdev.params.get(constants.LDP_ACCESS,
1078
                                     constants.DISK_KERNELSPACE)
1079
      if access_mode == constants.DISK_USERSPACE:
1080
        drive_uri = device.GetUserspaceAccessUri(constants.HT_KVM)
1081
      else:
1082
        drive_uri = dev_path
1083

  
1084
      drive_val = "file=%s,format=raw%s%s%s" % \
1085
                  (drive_uri, if_val, boot_val, cache_val)
1086

  
1087
      dev_opts.extend(["-drive", drive_val])
1088

  
1089
    return dev_opts
1090

  
1037 1091
  def _GenerateKVMRuntime(self, instance, block_devices, startup_paused,
1038 1092
                          kvmhelp):
1039 1093
    """Generate KVM information to start an instance.
......
1102 1156

  
1103 1157
    kernel_path = hvp[constants.HV_KERNEL_PATH]
1104 1158
    if kernel_path:
1105
      boot_disk = boot_cdrom = boot_floppy = boot_network = False
1159
      boot_cdrom = boot_floppy = boot_network = False
1106 1160
    else:
1107
      boot_disk = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_DISK
1108 1161
      boot_cdrom = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_CDROM
1109 1162
      boot_floppy = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_FLOPPY
1110 1163
      boot_network = hvp[constants.HV_BOOT_ORDER] == constants.HT_BO_NETWORK
......
1120 1173
    needs_boot_flag = self._BOOT_RE.search(kvmhelp)
1121 1174

  
1122 1175
    disk_type = hvp[constants.HV_DISK_TYPE]
1123
    if disk_type == constants.HT_DISK_PARAVIRTUAL:
1124
      if_val = ",if=virtio"
1125
    else:
1126
      if_val = ",if=%s" % disk_type
1127
    # Cache mode
1128
    disk_cache = hvp[constants.HV_DISK_CACHE]
1129
    if instance.disk_template in constants.DTS_EXT_MIRROR:
1130
      if disk_cache != "none":
1131
        # TODO: make this a hard error, instead of a silent overwrite
1132
        logging.warning("KVM: overriding disk_cache setting '%s' with 'none'"
1133
                        " to prevent shared storage corruption on migration",
1134
                        disk_cache)
1135
      cache_val = ",cache=none"
1136
    elif disk_cache != constants.HT_CACHE_DEFAULT:
1137
      cache_val = ",cache=%s" % disk_cache
1138
    else:
1139
      cache_val = ""
1140
    for cfdev, dev_path, device in block_devices:
1141
      if cfdev.mode != constants.DISK_RDWR:
1142
        raise errors.HypervisorError("Instance has read-only disks which"
1143
                                     " are not supported by KVM")
1144
      # TODO: handle FD_LOOP and FD_BLKTAP (?)
1145
      boot_val = ""
1146
      if boot_disk:
1147
        kvm_cmd.extend(["-boot", "c"])
1148
        boot_disk = False
1149
        if needs_boot_flag and disk_type != constants.HT_DISK_IDE:
1150
          boot_val = ",boot=on"
1151

  
1152
      access_mode = cfdev.params.get(constants.LDP_ACCESS,
1153
                                     constants.DISK_KERNELSPACE)
1154
      if access_mode == constants.DISK_USERSPACE:
1155
        drive_uri = device.GetUserspaceAccessUri(constants.HT_KVM)
1156
      else:
1157
        drive_uri = dev_path
1158

  
1159
      drive_val = "file=%s,format=raw%s%s%s" % (drive_uri, if_val,
1160
                                                boot_val, cache_val)
1161
      kvm_cmd.extend(["-drive", drive_val])
1162 1176

  
1163 1177
    #Now we can specify a different device type for CDROM devices.
1164 1178
    cdrom_disk_type = hvp[constants.HV_KVM_CDROM_DISK_TYPE]
......
1422 1436
    if hvp[constants.HV_KVM_EXTRA]:
1423 1437
      kvm_cmd.extend(hvp[constants.HV_KVM_EXTRA].split(" "))
1424 1438

  
1439
    bdev_opts = self._GenerateKVMBlockDevicesOptions(instance,
1440
                                                     block_devices,
1441
                                                     kvmhelp)
1442
    kvm_cmd.extend(bdev_opts)
1425 1443
    # Save the current instance nics, but defer their expansion as parameters,
1426 1444
    # as we'll need to generate executable temp files for them.
1427 1445
    kvm_nics = instance.nics

Also available in: Unified diff