fix(xo-server#_migrateVmWithStorageMotion): don't migrate VM VDIs to default SR (#5577)

See xoa-support#3248
See xoa-support#3355
This commit is contained in:
Rajaa.BARHTAOUI
2021-02-25 10:35:14 +01:00
committed by GitHub
parent 171ec54781
commit 8cb524080c
2 changed files with 30 additions and 4 deletions

View File

@@ -454,7 +454,7 @@ export async function migrate({ vm, host, sr, mapVdisSrs, mapVifsNetworks, migra
if (mapVdisSrs) {
mapVdisSrsXapi = {}
forEach(mapVdisSrs, (srId, vdiId) => {
const vdiXapiId = this.getObject(vdiId, ['VDI', 'VDI-snapshot'])._xapiId
const vdiXapiId = this.getObject(vdiId, 'VDI')._xapiId
mapVdisSrsXapi[vdiXapiId] = this.getObject(srId, 'SR')._xapiId
return permissions.push([srId, 'administrate'])
})

View File

@@ -1106,7 +1106,7 @@ export default class Xapi extends XapiBase {
{
migrationNetwork = find(host.$PIFs, pif => pif.management).$network, // TODO: handle not found
sr,
mapVdisSrs,
mapVdisSrs = {},
mapVifsNetworks,
force = false,
}
@@ -1122,14 +1122,40 @@ export default class Xapi extends XapiBase {
return defaultSr.$ref
})
const hostPbds = new Set(host.PBDs)
const connectedSrs = new Map()
const isSrConnected = sr => {
let isConnected = connectedSrs.get(sr.$ref)
if (isConnected === undefined) {
isConnected = sr.PBDs.some(ref => hostPbds.has(ref))
connectedSrs.set(sr.$ref, isConnected)
}
return isConnected
}
// VDIs/SRs mapping
// For VDI:
// - If SR was explicitly passed: use it
// - Else if VDI SR is reachable from the destination host: use it
// - Else: use the migration main SR or the pool's default SR (error if none of them is defined)
// For VDI-snapshot:
// - If VDI-snapshot is an orphan snapshot: same logic as a VDI
// - Else: don't add it to the map (VDI -> SR). It will be managed by the XAPI (snapshot will be migrated to the same SR as its parent active VDI)
const vdis = {}
const vbds = flatMap(vm.$snapshots, '$VBDs').concat(vm.$VBDs)
for (const vbd of vbds) {
const vdi = vbd.$VDI
if (vbd.type === 'Disk') {
const vdi = vbd.$VDI
// Ignore VDI snapshots which have a parent
if (vdi.$snapshot_of !== undefined) {
continue
}
vdis[vdi.$ref] =
mapVdisSrs && mapVdisSrs[vdi.$id] ? hostXapi.getObject(mapVdisSrs[vdi.$id]).$ref : getDefaultSrRef()
mapVdisSrs[vdi.$id] !== undefined
? hostXapi.getObject(mapVdisSrs[vdi.$id]).$ref
: isSrConnected(vdi.$SR)
? vdi.$SR.$ref
: getDefaultSrRef()
}
}