Skip to content

Commit 741634b

Browse files
committed
CLOUDSTACK-5691: Fix for attaching an uploaded volume to instance running
on hyperv. There were multiple issues here. Upload volume was actually failing because the post download check for vhd on the cifs share was unsuccessful. Also the agent code wasn't parsing the volume path correctly. Fixed it too.
1 parent 9313a35 commit 741634b

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ public string FullFileName
173173
{
174174
fileName += @"\" + this.path;
175175
}
176-
fileName = Utils.NormalizePath(fileName + @"\" + this.name);
176+
177+
fileName = Utils.NormalizePath(fileName);
178+
if (Directory.Exists(fileName))
179+
{
180+
fileName = Utils.NormalizePath(fileName + @"\" + this.name);
181+
}
177182
}
178183
else
179184
{
@@ -182,7 +187,7 @@ public string FullFileName
182187
throw new InvalidDataException(errMsg);
183188
}
184189

185-
if (this.format != null)
190+
if (!Path.HasExtension(fileName) && this.format != null)
186191
{
187192
fileName = fileName + "." + this.format.ToLowerInvariant();
188193
}

scripts/storage/secondary/createvolume.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ uncompress() {
111111
return 0
112112
}
113113

114+
isCifs() {
115+
#TO:DO incase of multiple zone where cifs and nfs exists,
116+
#then check if the template file is from cifs using df -P filename
117+
#Currently only cifs is supported in hyperv zone.
118+
mount | grep "type cifs" > /dev/null
119+
echo $?
120+
}
121+
114122
create_from_file() {
115123
local tmpltfs=$1
116124
local tmpltimg=$2
@@ -196,12 +204,15 @@ rollback_if_needed $tmpltfs $? "tar archives not supported\n"
196204

197205
if [ ${tmpltname%.vhd} != ${tmpltname} ]
198206
then
199-
if which vhd-util &>/dev/null
200-
then
201-
vhd-util check -n ${tmpltimg2} > /dev/null
202-
rollback_if_needed $tmpltfs $? "vhd check of $tmpltimg2 failed\n"
203-
vhd-util set -n ${tmpltimg2} -f "hidden" -v "0" > /dev/null
204-
rollback_if_needed $tmpltfs $? "vhd remove $tmpltimg2 hidden failed\n"
207+
if [ isCifs -ne 0 ] ;
208+
then
209+
if which vhd-util &>/dev/null
210+
then
211+
vhd-util check -n ${tmpltimg2} > /dev/null
212+
rollback_if_needed $tmpltfs $? "vhd check of $tmpltimg2 failed\n"
213+
vhd-util set -n ${tmpltimg2} -f "hidden" -v "0" > /dev/null
214+
rollback_if_needed $tmpltfs $? "vhd remove $tmpltimg2 hidden failed\n"
215+
fi
205216
fi
206217
fi
207218

server/src/com/cloud/api/ApiDBUtils.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,19 @@ public static HypervisorType getVolumeHyperType(long volumeId) {
958958
return _volumeDao.getHypervisorType(volumeId);
959959
}
960960

961-
public static HypervisorType getHypervisorTypeFromFormat(ImageFormat format){
962-
return _storageMgr.getHypervisorTypeFromFormat(format);
961+
public static HypervisorType getHypervisorTypeFromFormat(long dcId, ImageFormat format){
962+
HypervisorType type = _storageMgr.getHypervisorTypeFromFormat(format);
963+
if (format == ImageFormat.VHD) {
964+
// Xenserver and Hyperv both support vhd format. Additionally hyperv is only supported
965+
// in a dc/zone if there aren't any other hypervisor types present in the zone). If the
966+
// format type is VHD check is any xenserver clusters are present. If not, we assume it
967+
// is a hyperv zone and update the type.
968+
List<ClusterVO> xenClusters = _clusterDao.listByDcHyType(dcId, HypervisorType.XenServer.toString());
969+
if (xenClusters.isEmpty()) {
970+
type = HypervisorType.Hyperv;
971+
}
972+
}
973+
return type;
963974
}
964975

965976

server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public VolumeResponse newVolumeResponse(VolumeJoinVO volume) {
115115
volResponse.setCreated(volume.getCreatedOnStore());
116116

117117
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)
118-
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getFormat()).toString());
118+
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
119119
if (volume.getDownloadState() != Status.DOWNLOADED) {
120120
String volumeStatus = "Processing";
121121
if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
@@ -180,7 +180,7 @@ public VolumeResponse newVolumeResponse(VolumeJoinVO volume) {
180180
if (volume.getHypervisorType() != null) {
181181
volResponse.setHypervisor(volume.getHypervisorType().toString());
182182
} else {
183-
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getFormat()).toString());
183+
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
184184
}
185185
}
186186
Long poolId = volume.getPoolId();

0 commit comments

Comments
 (0)