Skip to content

Commit c874800

Browse files
authored
Adding a driver element with queues (#40)
* Adding a driver element with queues * Adding queues to hot plugged locations * Adding virtio model check
1 parent 70fd4a1 commit c874800

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,9 @@ private void VifHotPlug(final Connect conn, final String vmName, final String br
16381638
}
16391639

16401640
final Domain vm = getDomain(conn, vmName);
1641-
vm.attachDevice(getVifDriver(nicTO.getType()).plug(nicTO, "Other PV", "").toString());
1641+
InterfaceDef nic = getVifDriver(nicTO.getType()).plug(nicTO, "Other PV", "");
1642+
nic.setQueues(vm.getMaxVcpus());
1643+
vm.attachDevice(nic.toString());
16421644
}
16431645

16441646

@@ -2195,7 +2197,7 @@ public void createVifs(final VirtualMachineTO vmSpec, final LibvirtVMDef vm) thr
21952197
for (int i = 0; i < nics.length; i++) {
21962198
for (final NicTO nic : vmSpec.getNics()) {
21972199
if (nic.getDeviceId() == i) {
2198-
createVif(vm, nic, nicAdapter);
2200+
createVif(vm, nic, nicAdapter, vmSpec.getCpus());
21992201
}
22002202
}
22012203
}
@@ -2387,7 +2389,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
23872389

23882390
}
23892391

2390-
private void createVif(final LibvirtVMDef vm, final NicTO nic, final String nicAdapter) throws InternalErrorException, LibvirtException {
2392+
private void createVif(final LibvirtVMDef vm, final NicTO nic, final String nicAdapter, int queues) throws InternalErrorException, LibvirtException {
23912393

23922394
if (nic.getType().equals(TrafficType.Guest) && nic.getBroadcastType().equals(BroadcastDomainType.Vsp)) {
23932395
String vrIp = nic.getBroadcastUri().getPath().substring(1);
@@ -2399,7 +2401,9 @@ private void createVif(final LibvirtVMDef vm, final NicTO nic, final String nicA
23992401
}
24002402
}
24012403

2402-
vm.getDevices().addDevice(getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter));
2404+
InterfaceDef device = getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter);
2405+
device.setQueues(queues);
2406+
vm.getDevices().addDevice(device);
24032407
}
24042408

24052409
public boolean cleanupDisk(Map<String, String> volumeToDisconnect) {

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ enum HostNicType {
957957
private boolean _pxeDisable = false;
958958
private boolean _linkStateUp = true;
959959
private Integer _slot;
960+
private Integer queues = 0;
960961

961962
public void defBridgeNet(String brName, String targetBrName, String macAddr, NicModel model) {
962963
defBridgeNet(brName, targetBrName, macAddr, model, 0);
@@ -1096,6 +1097,14 @@ public boolean isLinkStateUp() {
10961097
return _linkStateUp;
10971098
}
10981099

1100+
public void setQueues(int queues) {
1101+
this.queues = queues;
1102+
}
1103+
1104+
public int getQueues() {
1105+
return this.queues;
1106+
}
1107+
10991108
@Override
11001109
public String toString() {
11011110
StringBuilder netBuilder = new StringBuilder();
@@ -1144,6 +1153,9 @@ public String toString() {
11441153
if (_slot != null) {
11451154
netBuilder.append(String.format("<address type='pci' domain='0x0000' bus='0x00' slot='0x%02x' function='0x0'/>\n", _slot));
11461155
}
1156+
if (_model == NicModel.VIRTIO && queues > 0) {
1157+
netBuilder.append(String.format("<driver queues='%d'/>\n", queues));
1158+
}
11471159
netBuilder.append("</interface>\n");
11481160
return netBuilder.toString();
11491161
}

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public Answer execute(final PlugNicCommand command, final LibvirtComputingResour
6262
}
6363
final VifDriver vifDriver = libvirtComputingResource.getVifDriver(nic.getType(), nic.getName());
6464
final InterfaceDef interfaceDef = vifDriver.plug(nic, "Other PV", "");
65+
interfaceDef.setQueues(vm.getMaxVcpus());
6566
vm.attachDevice(interfaceDef.toString());
6667

6768
return new PlugNicAnswer(command, true, "success");

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public Answer execute(final ReplugNicCommand command, final LibvirtComputingReso
6767
final VifDriver newVifDriver = libvirtComputingResource.getVifDriver(nic.getType(), nic.getName());
6868
final InterfaceDef interfaceDef = newVifDriver.plug(nic, "Other PV", oldPluggedNic.getModel().toString());
6969

70+
interfaceDef.setQueues(vm.getMaxVcpus());
7071
interfaceDef.setSlot(oldPluggedNic.getSlot());
7172
interfaceDef.setDevName(oldPluggedNic.getDevName());
7273
interfaceDef.setLinkStateUp(false);

plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,39 @@ public void testInterfaceDirectNet() {
6060
assertEquals(expected, ifDef.toString());
6161
}
6262

63+
public void testInterfaceDirectNetWithQueues() {
64+
LibvirtVMDef.InterfaceDef ifDef = new LibvirtVMDef.InterfaceDef();
65+
ifDef.defDirectNet("targetDeviceName", null, "00:11:22:aa:bb:dd", LibvirtVMDef.InterfaceDef.NicModel.VIRTIO, "private");
66+
ifDef.setQueues(4);
67+
68+
String expected =
69+
"<interface type='" + LibvirtVMDef.InterfaceDef.GuestNetType.DIRECT + "'>\n"
70+
+ "<source dev='targetDeviceName' mode='private'/>\n"
71+
+ "<mac address='00:11:22:aa:bb:dd'/>\n"
72+
+ "<model type='virtio'/>\n"
73+
+ "<link state='up'/>\n"
74+
+ "<driver queues='4'/>\n"
75+
+ "</interface>\n";
76+
77+
assertEquals(expected, ifDef.toString());
78+
}
79+
80+
public void testInterfaceDirectNetE1000WithQueuesShouldNotAddDriver() {
81+
LibvirtVMDef.InterfaceDef ifDef = new LibvirtVMDef.InterfaceDef();
82+
ifDef.defDirectNet("targetDeviceName", null, "00:11:22:aa:bb:dd", LibvirtVMDef.InterfaceDef.NicModel.E1000, "private");
83+
ifDef.setQueues(4);
84+
85+
String expected =
86+
"<interface type='" + LibvirtVMDef.InterfaceDef.GuestNetType.DIRECT + "'>\n"
87+
+ "<source dev='targetDeviceName' mode='private'/>\n"
88+
+ "<mac address='00:11:22:aa:bb:dd'/>\n"
89+
+ "<model type='e1000'/>\n"
90+
+ "<link state='up'/>\n"
91+
+ "</interface>\n";
92+
93+
assertEquals(expected, ifDef.toString());
94+
}
95+
6396
public void testInterfaceBridgeSlot() {
6497
LibvirtVMDef.InterfaceDef ifDef = new LibvirtVMDef.InterfaceDef();
6598
ifDef.defBridgeNet("targetDeviceName", null, "00:11:22:aa:bb:dd", LibvirtVMDef.InterfaceDef.NicModel.VIRTIO);

0 commit comments

Comments
 (0)