Revision f44c88c7

b/lib/hypervisor/hv_kvm.py
115 115
  }
116 116

  
117 117

  
118
def _GenerateDeviceKVMId(dev_type, dev):
118
def _GenerateDeviceKVMId(dev_type, dev, idx=None):
119 119
  """Helper function to generate a unique device name used by KVM
120 120

  
121 121
  QEMU monitor commands use names to identify devices. Here we use their pci
......
130 130

  
131 131
  """
132 132

  
133
  if not dev.pci:
134
    raise errors.HotplugError("Hotplug is not supported for %s with UUID %s" %
135
                              (dev_type, dev.uuid))
133
  # proper device id - available in latest Ganeti versions
134
  if dev.pci and dev.uuid:
135
    return "%s-%s-pci-%d" % (dev_type.lower(), dev.uuid.split("-")[0], dev.pci)
136 136

  
137
  return "%s-%s-pci-%d" % (dev_type.lower(), dev.uuid.split("-")[0], dev.pci)
137
  # dummy device id - returned only to _GenerateKVMBlockDevicesOptions
138
  # This enables -device option for paravirtual disk_type
139
  if idx is not None:
140
    return "%s-%d" % (dev_type.lower(), idx)
141

  
142
  raise errors.HotplugError("Hotplug is not supported for devices"
143
                            " without UUID or PCI info")
138 144

  
139 145

  
140 146
def _UpdatePCISlots(dev, pci_reservations):
......
1261 1267
      cache_val = ",cache=%s" % disk_cache
1262 1268
    else:
1263 1269
      cache_val = ""
1264
    for cfdev, link_name in kvm_disks:
1270
    for idx, (cfdev, link_name) in enumerate(kvm_disks):
1265 1271
      if cfdev.mode != constants.DISK_RDWR:
1266 1272
        raise errors.HypervisorError("Instance has read-only disks which"
1267 1273
                                     " are not supported by KVM")
......
1273 1279
        if needs_boot_flag and disk_type != constants.HT_DISK_IDE:
1274 1280
          boot_val = ",boot=on"
1275 1281
      drive_val = "file=%s,format=raw%s%s%s" % \
1276
                  (dev_path, if_val, boot_val, cache_val)
1282
                  (link_name, if_val, boot_val, cache_val)
1277 1283

  
1278 1284
      if device_driver:
1279 1285
        # kvm_disks are the 4th entry of runtime file that did not exist in
1280 1286
        # the past. That means that cfdev should always have pci slot and
1281 1287
        # _GenerateDeviceKVMId() will not raise a exception.
1282
        kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_DISK, cfdev)
1288
        kvm_devid = _GenerateDeviceKVMId(constants.HOTPLUG_TARGET_DISK,
1289
                                         cfdev, idx)
1283 1290
        drive_val += (",id=%s" % kvm_devid)
1284
        drive_val += (",bus=0,unit=%d" % cfdev.pci)
1291
        if cfdev.pci:
1292
          drive_val += (",bus=0,unit=%d" % cfdev.pci)
1285 1293
        dev_val = ("%s,drive=%s,id=%s" %
1286 1294
                   (device_driver, kvm_devid, kvm_devid))
1287
        dev_val += ",bus=pci.0,addr=%s" % hex(cfdev.pci)
1295
        if cfdev.pci:
1296
          dev_val += ",bus=pci.0,addr=%s" % hex(cfdev.pci)
1288 1297
        dev_opts.extend(["-device", dev_val])
1289 1298

  
1290 1299
      dev_opts.extend(["-drive", drive_val])

Also available in: Unified diff