Skip to content

Commit 8d36a4d

Browse files
author
Mike Tutkowski
committed
CLOUDSTACK-4235
1 parent 941c12d commit 8d36a4d

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6522,13 +6522,31 @@ protected VDI handleSrAndVdiAttach(String iqn, String storageHostName,
65226522
vdir.nameLabel = iqn;
65236523
vdir.SR = sr;
65246524
vdir.type = Types.VdiType.USER;
6525-
vdir.virtualSize = sr.getPhysicalSize(conn) - sr.getPhysicalUtilisation(conn) - getMetadata(sr.getPhysicalSize(conn));
6525+
6526+
long totalSpace = sr.getPhysicalSize(conn);
6527+
long unavailableSpace = sr.getPhysicalUtilisation(conn);
6528+
6529+
vdir.virtualSize = totalSpace - unavailableSpace;
65266530

65276531
if (vdir.virtualSize < 0) {
6528-
throw new CloudRuntimeException("VDI virtual size cannot be less than 0.");
6532+
throw new CloudRuntimeException("VDI virtual size cannot be less than 0.");
65296533
}
65306534

6531-
vdi = VDI.create(conn, vdir);
6535+
long maxNumberOfTries = (totalSpace / unavailableSpace >= 1) ? (totalSpace / unavailableSpace) : 1;
6536+
long tryNumber = 0;
6537+
6538+
while (tryNumber <= maxNumberOfTries) {
6539+
try {
6540+
vdi = VDI.create(conn, vdir);
6541+
6542+
break;
6543+
}
6544+
catch (Exception ex) {
6545+
tryNumber++;
6546+
6547+
vdir.virtualSize -= unavailableSpace;
6548+
}
6549+
}
65326550
}
65336551
else {
65346552
vdi = sr.getVDIs(conn).iterator().next();

0 commit comments

Comments
 (0)