Skip to content

Commit e0242d5

Browse files
authored
xenserver: check and eject patch vbd for systemvms (#4525)
XenServer 7.1 has an file descriptor/tapdisk iso-caching issue where new systemvm.iso are not recognised and inside the VR/ssvm/cpvm file IO error is seen. This was only reproducible with XS7.1 (intermittently), the fix was to check and eject the systemvm.iso (old/stale/cached), then insert the new systemvm.iso and then eject it. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 74982c5 commit e0242d5

File tree

3 files changed

+56
-37
lines changed

3 files changed

+56
-37
lines changed

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,33 +1063,46 @@ protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolea
10631063
}
10641064
}
10651065

1066-
public VBD createPatchVbd(final Connection conn, final String vmName, final VM vm) throws XmlRpcException, XenAPIException {
1066+
public SR findPatchIsoSR(final Connection conn) throws XmlRpcException, XenAPIException {
1067+
Set<SR> srs = SR.getByNameLabel(conn, "XenServer Tools");
1068+
if (srs.size() != 1) {
1069+
s_logger.debug("Failed to find SR by name 'XenServer Tools', will try to find 'XCP-ng Tools' SR");
1070+
srs = SR.getByNameLabel(conn, "XCP-ng Tools");
1071+
}
1072+
if (srs.size() != 1) {
1073+
s_logger.debug("Failed to find SR by name 'XenServer Tools' or 'XCP-ng Tools', will try to find 'Citrix Hypervisor' SR");
1074+
srs = SR.getByNameLabel(conn, "Citrix Hypervisor Tools");
1075+
}
1076+
if (srs.size() != 1) {
1077+
throw new CloudRuntimeException("There are " + srs.size() + " SRs with name XenServer Tools or XCP-ng Tools or Citrix Hypervisor Tools");
1078+
}
1079+
final SR sr = srs.iterator().next();
1080+
sr.scan(conn);
1081+
return sr;
1082+
}
10671083

1068-
if (_host.getSystemvmisouuid() == null) {
1069-
Set<SR> srs = SR.getByNameLabel(conn, "XenServer Tools");
1070-
if (srs.size() != 1) {
1071-
s_logger.debug("Failed to find SR by name 'XenServer Tools', will try to find 'XCP-ng Tools' SR");
1072-
srs = SR.getByNameLabel(conn, "XCP-ng Tools");
1073-
}
1074-
if (srs.size() != 1) {
1075-
s_logger.debug("Failed to find SR by name 'XenServer Tools' or 'XCP-ng Tools', will try to find 'Citrix Hypervisor' SR");
1076-
srs = SR.getByNameLabel(conn, "Citrix Hypervisor Tools");
1077-
}
1078-
if (srs.size() != 1) {
1079-
throw new CloudRuntimeException("There are " + srs.size() + " SRs with name XenServer Tools or XCP-ng Tools or Citrix Hypervisor Tools");
1084+
public VDI findPatchIsoVDI(final Connection conn, final SR sr) throws XmlRpcException, XenAPIException {
1085+
if (sr == null) {
1086+
return null;
1087+
}
1088+
final SR.Record srr = sr.getRecord(conn);
1089+
for (final VDI vdi : srr.VDIs) {
1090+
final VDI.Record vdir = vdi.getRecord(conn);
1091+
if (vdir.nameLabel.contains("systemvm.iso")) {
1092+
return vdi;
10801093
}
1081-
final SR sr = srs.iterator().next();
1082-
sr.scan(conn);
1094+
}
1095+
return null;
1096+
}
10831097

1084-
final SR.Record srr = sr.getRecord(conn);
1098+
public VBD createPatchVbd(final Connection conn, final String vmName, final VM vm) throws XmlRpcException, XenAPIException {
10851099

1100+
if (_host.getSystemvmisouuid() == null) {
1101+
final SR sr = findPatchIsoSR(conn);
10861102
if (_host.getSystemvmisouuid() == null) {
1087-
for (final VDI vdi : srr.VDIs) {
1088-
final VDI.Record vdir = vdi.getRecord(conn);
1089-
if (vdir.nameLabel.contains("systemvm.iso")) {
1090-
_host.setSystemvmisouuid(vdir.uuid);
1091-
break;
1092-
}
1103+
final VDI vdi = findPatchIsoVDI(conn, sr);
1104+
if (vdi != null) {
1105+
_host.setSystemvmisouuid(vdi.getRecord(conn).uuid);
10931106
}
10941107
}
10951108
if (_host.getSystemvmisouuid() == null) {
@@ -1489,24 +1502,33 @@ protected String deleteSnapshotBackup(final Connection conn, final Long dcId, fi
14891502
return result;
14901503
}
14911504

1492-
public void destroyPatchVbd(final Connection conn, final String vmName) throws XmlRpcException, XenAPIException {
1493-
try {
1494-
if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) {
1495-
return;
1496-
}
1497-
final Set<VM> vms = VM.getByNameLabel(conn, vmName);
1498-
for (final VM vm : vms) {
1505+
public void destroyPatchVbd(final Connection conn, final Set<VM> vms) throws XmlRpcException, XenAPIException {
1506+
final SR sr = findPatchIsoSR(conn);
1507+
final VDI patchVDI = findPatchIsoVDI(conn, sr);
1508+
for (final VM vm : vms) {
1509+
final String vmName = vm.getNameLabel(conn);
1510+
try {
1511+
if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) {
1512+
return;
1513+
}
14991514
final Set<VBD> vbds = vm.getVBDs(conn);
15001515
for (final VBD vbd : vbds) {
1501-
if (vbd.getType(conn) == Types.VbdType.CD) {
1502-
vbd.eject(conn);
1516+
if (Types.VbdType.CD.equals(vbd.getType(conn))) {
1517+
if (!vbd.getEmpty(conn)) {
1518+
vbd.eject(conn);
1519+
}
1520+
// Workaround for any file descriptor caching issue
1521+
if (patchVDI != null) {
1522+
vbd.insert(conn, patchVDI);
1523+
vbd.eject(conn);
1524+
}
15031525
vbd.destroy(conn);
15041526
break;
15051527
}
15061528
}
1529+
} catch (final Exception e) {
1530+
s_logger.debug("Cannot destroy CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
15071531
}
1508-
} catch (final Exception e) {
1509-
s_logger.debug("Cannot destory CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
15101532
}
15111533
}
15121534

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixReadyCommandWrapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public Answer execute(final ReadyCommand command, final CitrixResourceBase citri
5454
try {
5555
final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
5656
final Set<VM> vms = host.getResidentVMs(conn);
57-
for (final VM vm : vms) {
58-
citrixResourceBase.destroyPatchVbd(conn, vm.getNameLabel(conn));
59-
}
57+
citrixResourceBase.destroyPatchVbd(conn, vms);
6058
} catch (final Exception e) {
6159
}
6260
try {

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupCommandWrapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri
7777

7878
}
7979

80-
8180
final boolean r = citrixResourceBase.launchHeartBeat(conn);
8281
if (!r) {
8382
return null;

0 commit comments

Comments
 (0)