Skip to content

Commit

Permalink
fix(backups): disable CBT when CBT is unusable (#8313)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp authored Mar 3, 2025
1 parent 39613ff commit 2a2c966
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
38 changes: 37 additions & 1 deletion @xen-orchestra/xapi/vdi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ class Vdi {
return Buffer.from(encoded, 'base64')
}

/**
* will disable CBT on the VDI, all its ancestor and will purge
* snapshots of type cbt_metadata of this chain
*
* @param {OpaqueRef} vdiRef
*/
async disableCbtOnChain(vdiRef) {
const smConfig = await this.getField('VDI', vdiRef, 'sm_config')
if (smConfig['vhd-parent']) {
const parentRef = await this.call('VDI.get_by_uuid', smConfig['vhd-parent'])
await this.VDI_disableCbtOnChain(parentRef)
}
const snapshotRefs = await this.getField('VDI', vdiRef, 'snapshots')
for (const snapshotRef of snapshotRefs) {
const type = await this.getField('VDI', snapshotRef, 'type')
if (type === 'cbt_metadata') {
try {
await this.VDI_destroy(snapshotRef)
} catch (err) {
warn('couldn t destroy snapshot', { err, vdiRef, snapshotRef })
}
}
/**
* xapi can't disable CBT on a snapshot OPERATION_NOT_ALLOWED(VDI is a snapshot)
*/
}
try {
await this.callAsync('VDI.disable_cbt', vdiRef)
} catch (err) {
warn('couldn t disable cbt on disk', { err, vdiRef })
}
}

async disconnectFromControlDomain(vdiRef) {
let vbdRefs
try {
Expand Down Expand Up @@ -206,11 +239,12 @@ class Vdi {
vdi: ref,
}

const [cbt_enabled, size, uuid, vdiName] = await Promise.all([
const [cbt_enabled, size, snapshotOf, uuid, vdiName] = await Promise.all([
this.getField('VDI', ref, 'cbt_enabled').catch(() => {
/* on XS < 7.3 cbt is not supported */
}),
this.getField('VDI', ref, 'virtual_size'),
this.getField('VDI', ref, 'snapshot_of'),
this.getField('VDI', ref, 'uuid'),
this.getField('VDI', ref, 'name_label'),
])
Expand Down Expand Up @@ -275,8 +309,10 @@ class Vdi {
// a CBT export can only work if we have a NBD client and changed blocks
if (changedBlocks === undefined || nbdClient === undefined) {
if (baseParentType === 'cbt_metadata') {
await this.VDI_disableCbtOnChain(snapshotOf)
const e = new Error(`can't create a stream from a metadata VDI, fall back to a base `)
e.code = 'VDI_CANT_DO_DELTA'
// CBT is not usable: reset it
throw e
}

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

- **XO6**:
- [Pool/Network]: Display networks and host internal networks information in side panel (PR [#8286](https://github.com/vatesfr/xen-orchestra/pull/8286))

- [Changed Block Tracking] Disabling CBT now cleanup the full disk and snapshot chains (PR [#8313](https://github.com/vatesfr/xen-orchestra/pull/8313))
> Users must be able to say: “Nice enhancement, I'm eager to test it”
### Bug fixes
Expand Down
7 changes: 5 additions & 2 deletions packages/xo-server/src/api/vdi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ export const set = defer(async function ($defer, params) {
await xapi.resizeVdi(ref, size)
}
if ('cbt' in params) {
const method = params.cbt ? 'VDI.enable_cbt' : 'VDI.disable_cbt'
await xapi.callAsync(method, ref)
if (params.cbt) {
await xapi.callAsync('VDI.enable_cbt', ref)
} else {
await xapi.VDI_disableCbtOnChain(ref)
}
}

// Other fields.
Expand Down

0 comments on commit 2a2c966

Please sign in to comment.