Compare commits

..

6 Commits

Author SHA1 Message Date
Pierre Brunet
9c13ec98b3 fix: small issue for alias length/size 2026-07-23 09:23:27 +02:00
Pierre Brunet
c19acbeb74 fix: update type imports 2026-07-21 17:44:32 +02:00
Pierre Brunet
b2a6f26eb2 chore: update changelog 2026-07-21 17:41:14 +02:00
Pierre Brunet
38fec907c1 feat: refactor RemoteVhdDisk to use RemotePathDisk 2026-07-21 17:35:23 +02:00
Pierre Brunet
8f761a2398 fix: small typo issues in fs types 2026-07-21 17:34:45 +02:00
Pierre Brunet
3b2ab4fd92 feat: add DiskAlias class to handle generic aliases in remoteDisks 2026-07-21 17:34:07 +02:00
518 changed files with 6358 additions and 14697 deletions

View File

@@ -19,12 +19,12 @@
},
"main": "./index.mjs",
"dependencies": {
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/fs": "^4.9.2",
"@xen-orchestra/log": "^0.7.2",
"fuse-native": "^2.2.6",
"lru-cache": "^7.14.0",
"promise-toolbox": "^0.21.0",
"vhd-lib": "^4.16.1"
"vhd-lib": "^4.16.0"
},
"bin": {
"xo-fuse-vhd": "./cli.mjs"

View File

@@ -19,12 +19,6 @@ export class NbdDisk extends RandomAccessDisk {
/** @type {number} */
#blockSize
/** @type {number | undefined} */
#hasBlockCursor
/** @type {number | undefined} */
#hasBlockPreviousIndex
constructor(nbdInfos, blockSize, { dataMap } = {}) {
super()
this.#blockSize = blockSize
@@ -33,38 +27,11 @@ export class NbdDisk extends RandomAccessDisk {
}
#processDatamap(rawDataMap) {
const ranges = rawDataMap
.filter(({ type, length }) => type === 0 && length > 0)
return rawDataMap
.filter(({ type }) => type === 0)
.map(({ offset, length }) => ({ offset, length }))
.sort(({ offset: offset1 }, { offset: offset2 }) => offset1 - offset2)
// hasBlock()'s forward-only cursor is only correct if the extents are
// sorted AND disjoint: an earlier extent must never reach into a block
// after a later one, otherwise the cursor could skip it and wrongly report
// a block as empty, dropping data and corrupting the output.
// Touching extents (cur.offset === prevEnd) are merged
const merged = []
for (const range of ranges) {
const last = merged[merged.length - 1]
if (last !== undefined) {
const lastEnd = last.offset + last.length
if (range.offset < lastEnd) {
throw new Error(
`overlapping ranges in data map: [${last.offset}, ${lastEnd}) and [${range.offset}, ${range.offset + range.length})`
)
}
if (range.offset === lastEnd) {
// touching: extend the previous extent
last.length += range.length
continue
}
}
// gap (or first range): new extent
merged.push(range)
}
return merged
}
/**
* @param {number} index
* @returns {Promise<DiskBlock>}
@@ -150,34 +117,6 @@ export class NbdDisk extends RandomAccessDisk {
return [...indexes].sort((a, b) => a - b)
}
/**
* Counts the allocated blocks without materializing the index list.
*
* @returns {number}
*/
getBlockIndexesCount() {
if (!this.#dataMap) {
throw new Error("can't getBlockIndexesCount before init")
}
const blockSize = this.getBlockSize()
let count = 0
let lastCountedBlock = -1
for (const { offset, length } of this.#dataMap) {
const firstBlockIndex = Math.floor(offset / blockSize)
const lastBlockIndex = Math.floor((offset + length - 1) / blockSize)
const from = Math.max(firstBlockIndex, lastCountedBlock + 1)
if (lastBlockIndex >= from) {
count += lastBlockIndex - from + 1
lastCountedBlock = lastBlockIndex
}
}
return count
}
/**
* @param {number} index
* @returns {boolean}
@@ -186,32 +125,8 @@ export class NbdDisk extends RandomAccessDisk {
if (!this.#dataMap) {
throw new Error("can't hasBlock before init")
}
const blockSize = this.getBlockSize()
const blockStart = index * blockSize
const blockEnd = blockStart + blockSize
let startExtentIndex = 0
if (this.#hasBlockCursor !== undefined && index >= this.#hasBlockPreviousIndex) {
startExtentIndex = this.#hasBlockCursor
} else {
this.#hasBlockCursor = undefined
}
this.#hasBlockPreviousIndex = index
const dataMap = this.#dataMap
const l = dataMap.length
for (let i = startExtentIndex; i < l; i++) {
const { offset, length } = dataMap[i]
if (offset >= blockEnd) {
// extents are sorted: nothing from here on can overlap this block
break
}
if (offset + length > blockStart) {
this.#hasBlockCursor = i
return true
}
}
return false
const blockStart = index * this.getBlockSize()
const blockEnd = (index + 1) * this.getBlockSize()
return this.#dataMap.some(({ offset, length }) => offset + length > blockStart && offset < blockEnd)
}
}

View File

@@ -1,127 +0,0 @@
import { describe, it } from 'node:test'
import assert from 'node:assert'
import { NbdDisk } from './NbdDisk.mjs'
const KiB = 1024
const MiB = 1024 * KiB
const TiB = 1024 * 1024 * MiB
const SOURCE_BLOCK_SIZE = 2 * MiB // VHD_BLOCK_SIZE, the block size used when importing from VMware
const CLUSTER_SIZE = 64 * KiB // qcow2 cluster size
// hasBlock() only needs the dataMap (passed through the constructor) and the
// block size, so we can exercise it without a live NBD connection.
describe('NbdDisk.hasBlock', () => {
it('reports allocated and unallocated blocks correctly', () => {
const dataMap = [
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE }, // block 0
{ type: 0, offset: 5 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 5
]
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
assert.strictEqual(disk.hasBlock(0), true)
assert.strictEqual(disk.hasBlock(1), false)
assert.strictEqual(disk.hasBlock(4), false)
assert.strictEqual(disk.hasBlock(5), true)
assert.strictEqual(disk.hasBlock(6), false)
})
it('handles repeated and out-of-order queries with the resume cursor', () => {
const dataMap = [
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE }, // block 0
{ type: 0, offset: 5 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 5
]
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
// repeated indexes (the qcow2 path queries each 2MB block ~32 times as it
// walks 64KB clusters) must return a stable answer
assert.strictEqual(disk.hasBlock(5), true)
assert.strictEqual(disk.hasBlock(5), true)
assert.strictEqual(disk.hasBlock(6), false)
assert.strictEqual(disk.hasBlock(6), false)
// querying backwards must still be correct (falls back to a full scan)
assert.strictEqual(disk.hasBlock(0), true)
assert.strictEqual(disk.hasBlock(5), true)
})
it('invalidates the cursor on a backward miss (no stale skip)', () => {
const dataMap = [
{ type: 0, offset: 3 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 3
{ type: 0, offset: 10 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 10
]
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
assert.strictEqual(disk.hasBlock(10), true) // forward hit: cursor parks on the high extent
assert.strictEqual(disk.hasBlock(1), false) // backward miss: must invalidate the cursor
assert.strictEqual(disk.hasBlock(3), true) // lower extent must not be skipped
})
it('throws on overlapping ranges (would break the resume cursor)', () => {
const dataMap = [
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE },
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: SOURCE_BLOCK_SIZE }, // overlaps the previous range
]
assert.throws(() => new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap }), /overlapping ranges/)
})
it('merges touching ranges and drops zero-length / non type-0 entries', () => {
const dataMap = [
{ type: 0, offset: 2 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // [2, 3)
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE / 2 }, // [0, .5)
{ type: 0, offset: SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // [1, 2)
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: SOURCE_BLOCK_SIZE / 2 }, // [.5, 1), touches [0, .5)
{ type: 1, offset: 10 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // wrong type: ignored
{ type: 0, offset: 7 * SOURCE_BLOCK_SIZE, length: 0 }, // zero length: ignored
]
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
assert.strictEqual(disk.hasBlock(0), true)
assert.strictEqual(disk.hasBlock(1), true)
assert.strictEqual(disk.hasBlock(2), true)
assert.strictEqual(disk.hasBlock(3), false)
assert.strictEqual(disk.hasBlock(7), false) // zero-length range dropped
assert.strictEqual(disk.hasBlock(10), false) // non type-0 range dropped
})
})
describe('NbdDisk.getBlockIndexesCount', () => {
const cases = {
'aligned, disjoint blocks': [
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE }, // block 0
{ type: 0, offset: 5 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 5
],
'a range spanning several blocks': [
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: 3 * SOURCE_BLOCK_SIZE }, // blocks 0,1,2,3
],
'two disjoint extents sharing block 0 (needs dedup)': [
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE / 2 }, // [0, .5) => block 0
{ type: 0, offset: 3 * (SOURCE_BLOCK_SIZE / 4), length: SOURCE_BLOCK_SIZE }, // [.75, 1.75) => blocks 0,1
],
'touching sub-block fragments': [
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE / 2 },
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: SOURCE_BLOCK_SIZE / 2 },
{ type: 0, offset: SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE },
],
empty: [],
}
for (const [name, dataMap] of Object.entries(cases)) {
it(`matches getBlockIndexes().length: ${name}`, () => {
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
})
}
it('matches getBlockIndexes().length on the large sparse map', () => {
const virtualSize = Math.floor(3.5 * TiB)
const NB_RANGES = 113528
const dataMap = []
for (let i = 0; i < NB_RANGES; i++) {
dataMap.push({ type: 0, offset: Math.floor((i / NB_RANGES) * virtualSize), length: CLUSTER_SIZE })
}
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
})
})

View File

@@ -13,7 +13,7 @@
"url": "https://vates.fr"
},
"license": "ISC",
"version": "3.5.0",
"version": "3.4.0",
"engines": {
"node": ">=14.0"
},
@@ -22,10 +22,10 @@
"@vates/async-each": "^1.0.3",
"@vates/read-chunk": "^1.2.1",
"@xen-orchestra/async-map": "^0.1.3",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/disk-transform": "^1.3.1",
"@xen-orchestra/log": "^0.7.2",
"promise-toolbox": "^0.21.0",
"xen-api": "^4.8.0"
"xen-api": "^4.7.8"
},
"devDependencies": {
"tap": "^18.7.0",

View File

@@ -1,7 +1,7 @@
{
"name": "@vates/types",
"private": false,
"version": "1.30.1",
"version": "1.28.0",
"main": "./dist/index.mjs",
"exports": {
".": {
@@ -32,8 +32,7 @@
"devDependencies": {
"@eslint/js": "^9.19.0",
"typescript": "~5.6.3",
"typescript-eslint": "^8.61.0",
"@types/express": "^5.0.0"
"typescript-eslint": "^8.61.0"
},
"scripts": {
"build": "tsc",

View File

@@ -5,4 +5,3 @@ export * from './xo-app.mjs'
export * from './lib/xen-orchestra-xapi.mjs'
export * from './lib/xen-orchestra-acl.mjs'
export * from './lib/complex-matcher.mjs'
export * from './lib/rest-api.mjs'

View File

@@ -1,102 +0,0 @@
import type { NextFunction, Request, Response } from 'express'
import type { VatesTask } from './vates-task.mjs'
import type { XoApp } from '../xo-app.mjs'
export type SecurityName = '*' | 'token' | 'basic' | 'none'
export type FieldDefinition =
| {
type: 'string'
example?: string
optional?: boolean
}
| {
type: 'boolean'
example?: boolean
optional?: boolean
}
| {
type: 'number'
example?: number
optional?: boolean
}
| {
type: 'enum'
enum: string[]
example?: string
optional?: boolean
}
| {
type: 'object'
fields: Record<string, FieldDefinition>
optional?: boolean
}
| {
type: 'array'
items: FieldDefinition
example?: unknown[]
optional?: boolean
}
export type ParamFieldDefinition = Exclude<
FieldDefinition,
{ type: 'boolean' } | { type: 'object' } | { type: 'array' }
>
export type QueryFieldDefinition = Exclude<FieldDefinition, { type: 'object' } | { type: 'array' }>
type RestApi = object & { xoApp: XoApp }
export type CreateAction = <Result>(
callback: (task: VatesTask) => MaybePromise<Result>,
opts: {
sync?: boolean
statusCode?: number
taskProperties: { name: string; [key: string]: unknown }
}
) => Promise<Result | undefined>
export interface BaseRouteDefinition<Middleware> {
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
endpoint: string
description?: string
tags?: string[]
params?: Record<string, ParamFieldDefinition>
query?: Record<string, QueryFieldDefinition>
body?: Record<string, FieldDefinition>
responses?: Array<{
status: number
description: string
schema?: Record<string, FieldDefinition>
}>
middlewares?: Middleware[]
scope?: 'acl'
callback: (params: {
req: Request
res: Response
next: NextFunction
restApi: RestApi
createAction: CreateAction
}) => MaybePromise<unknown>
security?: SecurityName
}
export type MiddlewareDescriptor =
| { name: 'json' | 'urlencoded' | 'text' | 'raw'; options?: Record<string, unknown> }
| { name: 'acl'; acls: LooseAclEntry | LooseAclEntry[] }
type MaybePromise<T> = T | Promise<T>
/**
* Loosely-typed mirror of {@link https://github.com/vatesfr/xen-orchestra/blob/master/@xen-orchestra/rest-api/src/middlewares/acl.middleware.mts | AclEntry}
* from `@xen-orchestra/rest-api/src/middlewares/acl.middleware.mts`.
*/
export type LooseAclEntry = {
resource: string
action?: string | ((opts: { req: object; restApi: RestApi }) => string | undefined)
actions?: string[] | ((opts: { req: object; restApi: RestApi }) => string[])
objectId?: string | ((opts: { req: object; restApi: RestApi }) => string)
objectIds?: string[] | ((opts: { req: object; restApi: RestApi }) => string[])
object?: object | ((opts: { req: object; restApi: RestApi }) => MaybePromise<object> | undefined)
objects?: object[] | ((opts: { req: object; restApi: RestApi }) => MaybePromise<object[]> | undefined)
getObject?: (opts: { restApi: RestApi }) => (id: string) => MaybePromise<object>
}
export type PluginRestRouteDefinition = BaseRouteDefinition<MiddlewareDescriptor>

View File

@@ -1,24 +1,19 @@
import { Branded } from '../common.mjs'
import type { XoGroup, XoUser } from '../xo.mjs'
type XoAclBaseRole = {
id: Branded<'acl-v2-role'>
name: string
description?: string
privilegeIds: XoAclBasePrivilege['id'][]
}
type XoAclRegularRole = XoAclBaseRole & {
groupIds: XoGroup['id'][]
userIds: XoUser['id'][]
}
type XoAclTemplateRole = XoAclBaseRole & {
isTemplate: true
roleTemplateId: number
}
export type XoAclRole = XoAclRegularRole | XoAclTemplateRole
export type XoAclRole =
| {
id: Branded<'acl-v2-role'>
name: string
description?: string
}
| {
id: Branded<'acl-v2-role'>
name: string
description?: string
isTemplate: true
roleTemplateId: number
}
export type XoAclSupportedActionsByResource = {
[resource: string]: Record<string, unknown>

View File

@@ -233,36 +233,6 @@ export interface Xapi {
powerOnHost(hostId: XoHost['id']): Promise<void>
rebootHost(hostId: XoHost['id'], force?: boolean): Promise<void>
shutdownHost(hostId: XoHost['id'], opts?: { force?: boolean; bypassEvacuate?: boolean }): Promise<void>
SR_create(params: {
content_type?: XoSr['content_type']
// index signature, not `Record<string, string>`: tsoa emits an empty schema for `Record`
// (https://github.com/lukeautry/tsoa/pull/1858). device_config keys are driver-specific (SR_type).
device_config: {
chapuser?: string
chappassword?: string
device?: string
legacy_mode?: string
location?: string
nfsversion?: string
options?: string
password?: string
SCSIid?: string
server?: string
serverpath?: string
target?: string
targetIQN?: string
username?: string
} & {
[key: string]: string
}
host: XenApiHost['$ref']
name_description?: XoSr['name_description']
name_label: XoSr['name_label']
physical_size?: number
shared: boolean
sm_config?: { [key: string]: string }
type: XoSr['SR_type']
}): Promise<XenApiSr['$ref']>
SR_importVdi(
ref: XenApiSr['$ref'],
stream: Readable,
@@ -358,7 +328,6 @@ export interface Xapi {
vgpuType?: XoVgpuType['id']
gpuGroup?: XoGpuGroup['id']
copyHostBiosStrings?: boolean
highAvailability?: XoVm['high_availability']
hvmBootFirmware?: 'uefi' | 'bios'
secureBoot?: boolean
},
@@ -411,7 +380,7 @@ export interface Xapi {
): Promise<Readable & { length?: number }>
VDI_importContent(
vdiRef: XenApiVdi['$ref'],
stream: Readable | Buffer,
stream: Readable,
opts: { cancelToken?: unknown; format: SUPPORTED_VDI_FORMAT }
): Promise<void>
VIF_create(

View File

@@ -1,5 +1,6 @@
import { EventEmitter } from 'node:stream'
import type {
AnyXoBackupJob,
AnyXoJob,
AnyXoLog,
XapiXoRecord,
@@ -20,7 +21,6 @@ import type {
XoVmBackupArchive,
} from './xo.mjs'
import { VatesTask } from './lib/vates-task.mjs'
import type { PluginRestRouteDefinition } from './lib/rest-api.mjs'
import {
Xapi,
XapiHostStats,
@@ -195,7 +195,6 @@ export type XoApp = {
params?: any
}
) => () => void // eslint-disable-line @typescript-eslint/no-explicit-any
registerRestRoutes: (routes: PluginRestRouteDefinition[], base?: string) => () => void
authenticateUser: (
credentials: { token?: string; username?: string; password?: string },
userData?: { ip?: string },
@@ -234,11 +233,7 @@ export type XoApp = {
url: string
}): Promise<XoBackupRepository>
createUser(params: { name?: string; password?: string; [key: string]: unknown }): Promise<XoUser>
deleteAclV2GroupRole(
groupId: XoGroup['id'],
roleId: XoAclRole['id'],
opts?: { bypassAuthorization?: boolean }
): Promise<boolean>
deleteAclV2GroupRole(groupId: XoGroup['id'], roleId: XoAclRole['id']): Promise<boolean>
deleteAclV2Privilege(privilegeId: XoAclBasePrivilege['id'], options?: { force?: boolean }): Promise<boolean>
deleteAclV2Role(roleId: XoAclRole['id'], options?: { force?: boolean }): Promise<boolean>
deleteGroup(id: XoGroup['id']): Promise<void>
@@ -251,22 +246,10 @@ export type XoApp = {
getAclV2Privilege(id: XoAclBasePrivilege['id']): Promise<XoAclBasePrivilege>
getAclV2Privileges(): Promise<XoAclBasePrivilege[]>
getAclV2RolePrivileges(roleId: XoAclRole['id']): Promise<XoAclBasePrivilege[]>
getAclV2Role(id: XoAclRole['id'], opts?: { bypassAuthorization?: boolean }): Promise<XoAclRole>
deleteAclV2UserRole(
userId: XoUser['id'],
roleId: XoAclRole['id'],
opts?: { bypassAuthorization?: boolean }
): Promise<boolean>
getAclV2GroupRoles(
groupId: XoGroup['id'],
opts?: { bypassAuthorization?: boolean }
): Promise<Exclude<XoAclRole, { isTemplate: true }>[]>
getAclV2Role(id: XoAclRole['id']): Promise<XoAclRole>
deleteAclV2UserRole(userId: XoUser['id'], roleId: XoAclRole['id']): Promise<boolean>
getAclV2Roles(): Promise<XoAclRole[]>
getAclV2UserPrivileges(userId: XoUser['id']): Promise<XoAclBasePrivilege[]>
getAclV2UserRoles(
userId: XoUser['id'],
opts?: { bypassAuthorization?: boolean; fromGroup?: boolean; fromUser?: boolean }
): Promise<XoAclRole[]>
getAllGroups(): Promise<XoGroup[]>
getAllProxies(): Promise<XoProxy[]>
getAllJobs<T extends AnyXoJob['type']>(type: T): Promise<Extract<AnyXoJob, { type: T }>[]>
@@ -341,11 +324,8 @@ export type XoApp = {
readOnly?: XoServer['readOnly']
}
): Promise<XoServer>
rollingPoolReboot(pool: XoPool, opts?: { parentTask?: VatesTask; shutdownPinnedVms?: boolean }): Promise<void>
rollingPoolUpdate(
pool: XoPool,
opts?: { rebootVm?: boolean; parentTask?: VatesTask; shutdownPinnedVms?: boolean }
): Promise<void>
rollingPoolReboot(pool: XoPool, opts?: { parentTask?: VatesTask }): Promise<void>
rollingPoolUpdate(pool: XoPool, opts?: { rebootVm?: boolean; parentTask?: VatesTask }): Promise<void>
setVmResourceSet(vmId: XoVm['id'], resourceSetId: string | null, force?: boolean): Promise<void>
shareVmResourceSet(vmId: XoVm['id']): Promise<void>
removeUserFromGroup(userId: XoUser['id'], id: XoGroup['id']): Promise<void>

View File

@@ -76,7 +76,7 @@ type BaseXoVm = BaseXapiXo & {
expNestedHvm: boolean
isNestedVirtEnabled: boolean
hasVendorDevice: boolean
high_availability: 'best-effort' | 'restart' | ''
high_availability: string
installTime?: number | null
isFirmwareSupported: boolean
memory: {
@@ -222,7 +222,6 @@ export type XoGroup = {
provider?: string
providerGroupId?: string
users: XoUser['id'][]
aclRoleIds: XoAclRole['id'][]
}
export type XoHost = BaseXapiXo & {
@@ -614,7 +613,7 @@ export type XoSr = BaseXapiXo & {
VDIs: AnyXoVdi['id'][]
allocationStrategy?: 'thin' | 'thick' | 'unknown'
content_type: 'user' | 'iso' | 'disk'
content_type: string
current_operations: Record<string, STORAGE_OPERATIONS>
id: Branded<'SR'>
inMaintenanceMode: boolean
@@ -625,28 +624,7 @@ export type XoSr = BaseXapiXo & {
shared: boolean
size: number
sm_config: Record<string, string>
// SM drivers shipped with XCP-ng/XenServer
SR_type:
| 'cephfs'
| 'dummy'
| 'ext'
| 'file'
| 'glusterfs'
| 'hba'
| 'iso'
| 'largeblock'
| 'linstor'
| 'lvm'
| 'lvmofcoe'
| 'lvmohba'
| 'lvmoiscsi'
| 'moosefs'
| 'nfs'
| 'shm'
| 'smb'
| 'udev'
| 'xfs'
| 'zfs'
SR_type: string
tags: string[]
type: 'SR'
usage: number

View File

@@ -6,7 +6,7 @@
"main": "dist/index.mjs",
"name": "@xen-orchestra/acl",
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/acl",
"version": "1.5.0",
"version": "1.4.0",
"license": "AGPL-3.0-or-later",
"private": false,
"type": "module",
@@ -30,7 +30,7 @@
},
"devDependencies": {
"@eslint/js": "^9.19.0",
"@vates/types": "^1.30.1",
"@vates/types": "^1.28.0",
"rimraf": "^6.0.1",
"typescript": "~5.6",
"typescript-eslint": "^8.61.0"

View File

@@ -16,7 +16,6 @@ export default {
smart: true,
},
'restart-toolstack': true,
'scan-pifs': true,
shutdown: {
clean: true,
emergency: true,

View File

@@ -1,5 +1,4 @@
export default {
create: true,
delete: true,
forget: true,
import: {

View File

@@ -1,6 +1,6 @@
{
"name": "@xen-orchestra/backup-archive",
"version": "1.1.1",
"version": "1.0.4",
"description": "Helper to handle generic backup archives",
"license": "ISC",
"author": "",
@@ -21,24 +21,23 @@
"tar-stream": "^3.1.8",
"@types/tar-stream": "^3.1.4",
"tmp": "^0.2.1",
"@vates/types": "^1.30.1"
"@vates/types": "^1.28.0"
},
"dependencies": {
"@xen-orchestra/log": "^0.7.1",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/fs": "^4.9.2",
"@xen-orchestra/disk-transform": "^1.3.1",
"@vates/task": "0.7.0",
"golike-defer": "0.5.1",
"uuid": "^9.0.0",
"promise-toolbox": "^0.21.0",
"@vates/async-each": "^1.0.1",
"vhd-lib": "^4.16.1"
"vhd-lib": "^4.14.7"
},
"scripts": {
"build": "yarn run clean && tsc",
"dev": "tsc --watch",
"postversion": "npm publish --access public",
"test": "yarn run clean && tsc && node --test **/*.test.mjs",
"test-integration": "yarn run clean && tsc && node --test **/*.integ.mjs",
"clean": "rimraf dist/"
},

View File

@@ -10,11 +10,6 @@ export interface PartialBackupMetadata {
jobId: string
scheduleId: string
timestamp: number
// 'true' when written by code including the non-NBD qcow2 corruption fix and its force-full
// gate; its absence marks a potentially-corrupt older backup and makes the gate re-probe.
// Preserved (never stamped) across merges here.
// @todo remove this code and the logic associated on 2027 01 01
includeNonNbdQcow2Fix?: boolean
}
export const DEFAULT_MERGE_CONCURRENCY = 1
export const DEFAULT_REMOVE_CONCURRENCY = 4

View File

@@ -39,10 +39,6 @@ export class VmBackupDirectory implements VmBackupInterface {
#checkResult: (CheckResult & { orphans: string[]; linked: string[] }) | undefined = undefined
#uniqueLineages: Map<string, RemoteDiskLineage> | undefined = undefined
// Set by #checkCacheCount(): the on-disk cache did not match the archives found
// on disk, so clean() must regenerate it even when nothing was merged/removed.
#cacheOutOfSync = false
constructor(
handler: RemoteHandlerAbstract,
vmBackupPath: string,
@@ -187,7 +183,7 @@ export class VmBackupDirectory implements VmBackupInterface {
{ concurrency: 2 }
)
if (allMergedSizes.size > 0 || cacheNeedsRegen || this.#cacheOutOfSync) {
if (allMergedSizes.size > 0 || cacheNeedsRegen) {
await this.#regenerateCache()
}
@@ -218,8 +214,7 @@ export class VmBackupDirectory implements VmBackupInterface {
const existingCache = await this.#readCache(cachePath)
const actual = existingCache === undefined ? 0 : Object.keys(existingCache).length
const expected = this.backupArchives.size
this.#cacheOutOfSync = actual !== expected
if (this.#cacheOutOfSync) {
if (actual !== expected) {
this.opts.logWarn('unexpected number of entries in backup cache', { path: cachePath, actual, expected })
}
}

View File

@@ -13,14 +13,10 @@ import { MergeRemoteDisk } from '../dist/disks/MergeRemoteDisk.mjs'
import { VHDFOOTER, VHDHEADER } from './tests.fixtures.mjs'
import { VhdFile, Constants, VhdDirectory, VhdAbstract } from 'vhd-lib'
import { dirname, basename } from 'node:path'
import { promisify } from 'node:util'
import zlib from 'node:zlib'
import { rimraf } from 'rimraf'
const { beforeEach, afterEach, describe } = test
const gunzip = promisify(zlib.gunzip)
let tempDir, handler, jobId, vdiId, basePath, relativePath, vdiId2, basePath2, relativePath2
const rootPath = 'xo-vm-backups/VMUUID/'
@@ -832,28 +828,3 @@ test('it preserves VDI directory when handler.list() throws during lineage init'
const remaining = await handler.list(basePath)
assert.ok(remaining.includes('snapshot.vhd'), 'VHD must survive when handler.list() throws during lineage init')
})
test('it regenerates the cache when its entry count is out of sync, even with nothing to merge/remove', async () => {
// a referenced disk + its metadata, but no cache.json.gz on disk
await generateVhd(`${basePath}/diskA1.vhd`)
await handler.writeFile(
`${rootPath}/metadata.json`,
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/diskA1.vhd`] })
)
await assert.rejects(handler.readFile(`${rootPath}/cache.json.gz`), { code: 'ENOENT' })
const logged = []
// remove/merge both false: cacheNeedsRegen stays false and no merge happens,
// so only the cache-count mismatch can trigger the regeneration
await VmBackupDirectory.cleanVm(handler, rootPath, {
remove: false,
merge: false,
logInfo: () => {},
logWarn: message => logged.push(message),
})
assert.ok(logged.includes('unexpected number of entries in backup cache'), 'mismatch should be reported')
const cache = JSON.parse((await gunzip(await handler.readFile(`${rootPath}/cache.json.gz`))).toString())
assert.equal(Object.keys(cache).length, 1, 'cache should be regenerated to match the archives on disk')
})

View File

@@ -0,0 +1,260 @@
// @ts-check
/**
* @typedef {import('@xen-orchestra/disk-transform').FileAccessor} FileAccessor
*/
import { DiskAlias, AliasMissingError, AliasIsDirectoryError } from '@xen-orchestra/disk-transform'
import { normalize } from '@xen-orchestra/fs/path'
import { RemoteDisk } from './RemoteDisk.mjs'
/**
* A RemoteDisk backed by a single handler + path (possibly an alias to another path).
* Owns the alias-driven rename/unlink/clean/listAssociatedFiles logic so format-specific
* subclasses (RemoteVhdDisk, and later others) don't have to reimplement it.
*/
export class RemotePathDisk extends RemoteDisk {
/** @type {FileAccessor} */
#handler
/** @type {string} */
#path
/** @type {DiskAlias} */
#alias
/**
* @param {Object} params
* @param {FileAccessor} params.handler
* @param {string} params.path
* @param {string} params.extension - e.g. 'vhd', used to build the `*.alias.<extension>` suffix
*/
constructor({ handler, path, extension }) {
super()
this.#handler = handler
this.#path = path
this.#alias = new DiskAlias(extension)
}
/** @returns {FileAccessor} */
get handler() {
return this.#handler
}
/** @returns {string} */
get path() {
return this.#path
}
set path(newPath) {
this.#path = newPath
}
/** @returns {DiskAlias} */
get alias() {
return this.#alias
}
/**
* Abstract - true once the disk's format-specific state has been opened (e.g. after init()).
* @returns {boolean}
*/
get isOpen() {
throw new Error('isOpen must be implemented')
}
/**
* Abstract - throws if `target` isn't a valid, openable disk of this format.
* @param {string} target
* @returns {Promise<void>}
*/
async validateTarget(target) {
throw new Error('validateTarget must be implemented')
}
/**
* @returns {string}
*/
getPath() {
return this.path
}
/**
* @returns {string[]}
*/
getPaths() {
return [this.getPath()]
}
/**
* Rename alias/disk
* @param {string} newPath
*/
async rename(newPath) {
const { handler, alias } = this
if (alias.isAlias(newPath)) {
const dataPath = await alias.resolve(handler, this.path)
await handler.unlink(newPath)
await alias.create(handler, newPath, dataPath)
await handler.unlink(this.path)
this.path = newPath
} else {
try {
await handler.unlink(newPath)
} catch (err) {
if (err && typeof err === 'object' && 'code' in err && err.code === 'EISDIR') {
await handler.rmtree(newPath).catch(() => {})
}
}
await handler.rename(this.path, newPath)
this.path = newPath
}
}
/**
* Deletes alias/disk
* @param {Object} options
* @param {boolean} [options.force]
*/
async unlink({ force = false } = {}) {
const { handler, alias } = this
if (!this.isOpen) {
if (!force) {
throw new Error(`can't call unlink of a ${this.constructor.name} before init`)
}
await alias.unlink(handler, this.path)
return
}
await this.close()
if (alias.isAlias(this.path)) {
try {
await handler.unlink(await alias.resolve(handler, this.path))
} catch (err) {
if (err && typeof err === 'object' && 'code' in err && err.code === 'EISDIR') {
await handler.rmtree(await alias.resolve(handler, this.path)).catch(() => {})
}
}
}
try {
await handler.unlink(this.path)
} catch (err) {
if (err && typeof err === 'object' && 'code' in err && err.code === 'EISDIR') {
await handler.rmtree(this.path).catch(() => {})
}
}
}
/**
* Returns all file paths within dir that this disk claims.
* For a plain disk: [path]
* For an alias: [aliasPath, resolvedDataPath]
* If the alias target cannot be resolved, only the alias path is returned.
*
* @param {string} dir
* @returns {Promise<string[]>}
*/
async listAssociatedFiles(dir) {
const { handler, alias } = this
const prefix = normalize(dir.endsWith('/') ? dir : dir + '/')
const isInDir = /** @param {string} p */ p => p === dir || p.startsWith(prefix)
const files = []
if (isInDir(this.path)) {
files.push(this.path)
}
if (alias.isAlias(this.path)) {
try {
const resolved = await alias.resolve(handler, this.path)
if (isInDir(resolved)) {
files.push(resolved)
}
} catch {
// broken alias, no data file to claim
}
}
return files
}
/**
* Checks the integrity of this disk's alias reference.
* Only meaningful for alias files; no-op for plain disks.
* Returns the resolved target path when the alias is valid, undefined otherwise.
*
* @param {Object} [opts]
* @param {boolean} [opts.remove]
* @param {Function} [opts.logWarn]
* @param {Function} [opts.logInfo]
* @returns {Promise<string | undefined>}
*/
async clean({ remove = false, logWarn = () => {}, logInfo = () => {} } = {}) {
const { handler, alias } = this
if (!alias.isAlias(this.path)) {
return undefined
}
let target
try {
target = await alias.resolve(handler, this.path)
} catch (err) {
if (err instanceof AliasMissingError) {
logWarn('missing target of alias', { alias: this.path })
if (remove) {
logInfo('removing alias with missing target', { alias: this.path })
await handler.unlink(this.path)
}
return undefined
}
if (err instanceof AliasIsDirectoryError) {
logWarn('alias is a directory', { alias: this.path })
if (remove) {
logInfo('removing directory named as alias', { alias: this.path })
await alias.unlink(handler, this.path)
}
return undefined
}
logWarn('unhandled error while checking alias', { alias: this.path, err })
return undefined
}
if (target === '') {
logWarn('empty target for alias', { alias: this.path })
if (remove) {
logInfo('removing alias with empty target', { alias: this.path })
await handler.unlink(this.path)
}
return undefined
}
try {
await this.validateTarget(target)
return target
} catch (error) {
if (error?.invalidTargetName) {
logWarn('alias references an invalid target', { alias: this.path, target })
if (remove) {
logInfo('removing alias and invalid target', { alias: this.path, target })
await handler.unlink(target)
await handler.unlink(this.path)
}
return undefined
}
logWarn('missing or broken alias target', { alias: this.path, target, error })
if (remove) {
try {
await alias.unlink(handler, this.path)
} catch (err) {
if (err.code !== 'ENOENT') {
logWarn('error deleting broken alias', { alias: this.path, target, err })
}
}
}
return undefined
}
}
}

View File

@@ -5,31 +5,21 @@
* @typedef {import('vhd-lib/Vhd/VhdFile.js').VhdFile} VhdFile
* @typedef {import('vhd-lib/_createFooterHeader.js').VhdFooter} VhdFooter
* @typedef {import('@xen-orchestra/disk-transform').DiskBlock} DiskBlock
* @typedef {import('@xen-orchestra/fs').RemoteHandlerAbstract} RemoteHandlerAbstract
* @typedef {import('@xen-orchestra/disk-transform').FileAccessor} FileAccessor
* @typedef {import('./RemoteDisk.mjs').RemoteDisk} RemoteDisk
*
*/
import { openVhd, VhdAbstract, VhdDirectory } from 'vhd-lib'
import { RemoteDisk } from './RemoteDisk.mjs'
import { openVhd, VhdDirectory } from 'vhd-lib'
import { RemotePathDisk } from './RemotePathDisk.mjs'
import { DISK_TYPES } from 'vhd-lib/_constants.js'
import { isVhdAlias, resolveVhdAlias } from 'vhd-lib/aliases.js'
import { stringify } from 'uuid'
import { dirname, join } from 'node:path'
import { RemoteVhdDiskChain } from './RemoteVhdDiskChain.mjs'
import { normalize } from '@xen-orchestra/fs/path'
export class RemoteVhdDisk extends RemoteDisk {
/**
* @type {string}
*/
#path
/**
* @type {RemoteHandlerAbstract}
*/
#handler
export class RemoteVhdDisk extends RemotePathDisk {
/**
* @type {VhdFile | VhdDirectory | undefined}
*/
@@ -57,14 +47,19 @@ export class RemoteVhdDisk extends RemoteDisk {
/**
* @param {Object} params
* @param {RemoteHandlerAbstract} params.handler
* @param {FileAccessor} params.handler
* @param {string} params.path
*/
constructor({ handler, path }) {
super()
// @todo : ensure this is the full path from the root of the remote
this.#path = path
this.#handler = handler
super({ handler, path, extension: 'vhd' })
}
/**
* @returns {boolean}
*/
get isOpen() {
return this.#vhd !== undefined
}
/**
@@ -76,12 +71,12 @@ export class RemoteVhdDisk extends RemoteDisk {
async init(options = {}) {
if (this.#vhd === undefined) {
try {
const { value, dispose } = await openVhd(this.#handler, await resolveVhdAlias(this.#handler, this.#path), {
const { value, dispose } = await openVhd(this.handler, this.path, {
checkSecondFooter: !options.force,
})
this.#vhd = value
if ((await this.isDirectory()) && !isVhdAlias(this.#path)) {
if ((await this.isDirectory()) && !this.alias.isAlias(this.path)) {
this.#vhd = undefined
throw Object.assign(new Error("Can't init vhd directory without using alias"), { code: 'NOT_SUPPORTED' })
}
@@ -138,22 +133,6 @@ export class RemoteVhdDisk extends RemoteDisk {
return this.#blockSize
}
/**
* @returns {string}
*/
getPath() {
return this.#path
}
/**
* Returns the disk path in an array.
*
* @returns {string[]}
*/
getPaths() {
return [this.getPath()]
}
/**
* @returns {string}
*/
@@ -187,7 +166,7 @@ export class RemoteVhdDisk extends RemoteDisk {
}
const parentPath = this.#vhd.header.parentUnicodeName
return normalize(join(dirname(this.#path), parentPath))
return normalize(join(dirname(this.path), parentPath))
}
/**
@@ -236,13 +215,13 @@ export class RemoteVhdDisk extends RemoteDisk {
}
const parentPath = this.#vhd.header.parentUnicodeName
const fullParentPath = normalize(join(dirname(this.#path), parentPath))
const fullParentPath = normalize(join(dirname(this.path), parentPath))
if (!parentPath) {
throw new Error(`disk ${this.#path} doesn't have parents`)
throw new Error(`disk ${this.path} doesn't have parents`)
}
const parent = new RemoteVhdDisk({ handler: this.#handler, path: fullParentPath })
const parent = new RemoteVhdDisk({ handler: this.handler, path: fullParentPath })
return parent
}
/**
@@ -300,7 +279,7 @@ export class RemoteVhdDisk extends RemoteDisk {
(await childDisk.isDirectory())
) {
try {
await this.#handler.rename(childDisk.getBlockPath(index), this.getBlockPath(index))
await this.handler.rename(childDisk.getBlockPath(index), this.getBlockPath(index))
this.setAllocatedBlocks([index])
} catch (error) {
@@ -434,92 +413,7 @@ export class RemoteVhdDisk extends RemoteDisk {
}
/**
* Rename alias/disk
* @param {string} newPath
*/
async rename(newPath) {
if (isVhdAlias(newPath)) {
const dataPath = await resolveVhdAlias(this.#handler, this.#path)
await this.#handler.unlink(newPath)
await VhdAbstract.createAlias(this.#handler, newPath, dataPath)
await this.#handler.unlink(this.#path)
this.#path = newPath
} else {
try {
await this.#handler.unlink(newPath)
} catch (err) {
if (err && typeof err === 'object' && 'code' in err && err.code === 'EISDIR') {
await this.#handler.rmtree(newPath).catch(() => {})
}
}
await this.#handler.rename(this.#path, newPath)
this.#path = newPath
}
}
/**
* Deletes disk
* @param {Object} options
*/
async unlink({ force = false } = {}) {
if (this.#vhd === undefined) {
if (force) {
let resolved = this.#path
try {
resolved = await resolveVhdAlias(this.#handler, this.#path)
} catch (err) {
// broken vhd directory must be unlinkable
if (err.code !== 'EISDIR') {
throw err
}
// warn('Deleting directly a VhdDirectory', { this.#path, err })
}
try {
await this.#handler.unlink(resolved)
} catch (err) {
if (err.code === 'EISDIR') {
await this.#handler.rmtree(resolved)
} else {
throw err
}
}
// also delete the alias file
if (this.#path !== resolved) {
await this.#handler.unlink(this.#path)
}
} else {
throw new Error(`can't call unlink of a RemoteVhdDisk before init`)
}
} else {
await this.close()
if (isVhdAlias(this.#path)) {
try {
await this.#handler.unlink(await resolveVhdAlias(this.#handler, this.#path))
} catch (err) {
if (err && typeof err === 'object' && 'code' in err && err.code === 'EISDIR') {
await this.#handler.rmtree(await resolveVhdAlias(this.#handler, this.#path)).catch(() => {})
}
}
}
try {
await this.#handler.unlink(this.#path)
} catch (err) {
if (err && typeof err === 'object' && 'code' in err && err.code === 'EISDIR') {
await this.#handler.rmtree(this.#path).catch(() => {})
}
}
}
}
/**
* Check if the disk is a VHD directory.
* Checks if the disk is a VHD directory.
* @returns {Promise<boolean>}
*/
async isDirectory() {
@@ -531,116 +425,19 @@ export class RemoteVhdDisk extends RemoteDisk {
}
/**
* Returns all file paths within dir that this disk claims.
* For a plain VHD or VHD directory: [path]
* For a VHD alias: [aliasPath, resolvedDataPath]
* If the alias target cannot be resolved, only the alias path is returned.
*
* @param {string} dir
* @returns {Promise<string[]>}
* Throws if `target` isn't a valid, openable VHD.
* @param {string} target
* @returns {Promise<void>}
*/
async listAssociatedFiles(dir) {
const prefix = normalize(dir.endsWith('/') ? dir : dir + '/')
const isInDir = /** @param {string} p */ p => p === dir || p.startsWith(prefix)
const files = []
if (isInDir(this.#path)) {
files.push(this.#path)
async validateTarget(target) {
if (!this.alias.isAlias(target) && !target.endsWith('.vhd')) {
throw Object.assign(new Error(`${target} is not a vhd target`), { invalidTargetName: true })
}
if (isVhdAlias(this.#path)) {
try {
const resolved = await resolveVhdAlias(this.#handler, this.#path)
if (isInDir(resolved)) {
files.push(resolved)
}
} catch {
// broken alias, no data file to claim
}
}
return files
}
/**
* Checks the integrity of this disk's alias reference.
* Only meaningful for alias files (.alias.vhd); no-op for plain VHDs.
* Returns the resolved target path when the alias is valid, undefined otherwise.
*
* @param {Object} [opts]
* @param {boolean} [opts.remove]
* @param {Function} [opts.logWarn]
* @param {Function} [opts.logInfo]
* @returns {Promise<string | undefined>}
*/
async clean({ remove = false, logWarn = () => {}, logInfo = () => {} } = {}) {
if (!isVhdAlias(this.#path)) {
return undefined
}
let target
const { dispose } = await openVhd(this.handler, target)
try {
target = await resolveVhdAlias(this.#handler, this.#path)
} catch (err) {
if (err.code === 'ENOENT') {
logWarn('missing target of alias', { alias: this.#path })
if (remove) {
logInfo('removing alias with missing target', { alias: this.#path })
await this.#handler.unlink(this.#path)
}
return undefined
}
if (err.code === 'EISDIR') {
logWarn('alias is a vhd directory', { alias: this.#path })
if (remove) {
logInfo('removing vhd directory named as alias', { alias: this.#path })
await VhdAbstract.unlink(this.#handler, this.#path)
}
return undefined
}
logWarn('unhandled error while checking alias', { alias: this.#path, err })
return undefined
}
if (target === '') {
logWarn('empty target for alias', { alias: this.#path })
if (remove) {
logInfo('removing alias with empty target', { alias: this.#path })
await this.#handler.unlink(this.#path)
}
return undefined
}
if (!isVhdAlias(target) && !target.endsWith('.vhd')) {
logWarn('alias references non VHD target', { alias: this.#path, target })
if (remove) {
logInfo('removing alias and non VHD target', { alias: this.#path, target })
await this.#handler.unlink(target)
await this.#handler.unlink(this.#path)
}
return undefined
}
try {
const { dispose } = await openVhd(this.#handler, target)
try {
await dispose()
} catch (_) {
// errors during dispose should not trigger deletion
}
return target
} catch (error) {
logWarn('missing or broken alias target', { alias: this.#path, target, error })
if (remove) {
try {
await VhdAbstract.unlink(this.#handler, this.#path)
} catch (/** @type {any} */ err) {
if (err.code !== 'ENOENT') {
logWarn('error deleting broken alias', { alias: this.#path, target, err })
}
}
}
return undefined
await dispose()
} catch (_) {
// errors during dispose should not trigger deletion
}
}
}

View File

@@ -312,12 +312,4 @@ export class RemoteVhdDiskChain extends RemoteDisk {
async clean(opts = {}) {
throw new Error(`Can't clean a disk chain`)
}
/**
*
* @returns {RemoteVhdDisk|undefined}
*/
getRootDisk() {
return this.#disks[0]
}
}

View File

@@ -8,8 +8,8 @@
"dependencies": {
"@vates/async-each": "^1.0.3",
"@xen-orchestra/async-map": "^0.1.3",
"@xen-orchestra/backups": "^0.73.10",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/backups": "^0.73.7",
"@xen-orchestra/fs": "^4.9.2",
"filenamify": "^6.0.0",
"getopts": "^2.2.5",
"lodash": "^4.18.0",

View File

@@ -315,11 +315,6 @@ export class RemoteAdapter {
fn(cache)
await this._writeCache(path, cache)
} else {
const regenerated = await this.#getCacheableDataListVmBackups(dirname(path))
if (regenerated !== undefined) {
await this._writeCache(path, regenerated)
}
}
}
@@ -388,7 +383,8 @@ export class RemoteAdapter {
return
}
await this._writeCache(path, backups)
// detached async action, will not reject
this._writeCache(path, backups)
return backups
}
@@ -453,7 +449,7 @@ export class RemoteAdapter {
return path
}
async writeVhd(path, disk, { validator = noop, writeBlockConcurrency, uuid, parentUuid, parentPath } = {}) {
async writeVhd(path, disk, { validator = noop, writeBlockConcurrency } = {}) {
const handler = this._handler
if (this.useVhdDirectory()) {
@@ -465,19 +461,11 @@ export class RemoteAdapter {
concurrency: writeBlockConcurrency,
validator,
compression: 'brotli',
uuid,
parentUuid,
parentPath,
},
})
} else {
const stream = await toVhdStream(disk, { uuid, parentUuid, parentPath })
const size = await this.outputStream(path, stream, {
validator,
// no checksum for VHDs, because they will be invalidated by
// merges and chains
checksum: false,
})
const stream = await toVhdStream(disk)
const size = await this.outputStream(path, stream, { validator, checksum: false })
await validator(path)
return size
}

View File

@@ -1,8 +1,7 @@
import { strict as assert } from 'node:assert'
import test from 'node:test'
import { execFile } from 'node:child_process'
import { copyFile, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { Stream } from 'node:stream'
import { copyFile, mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { promisify } from 'node:util'
@@ -40,37 +39,6 @@ async function createLvmImage(imagePath, vgName, lvName) {
})
}
// xo-proxy answers this stream through Koa, which pipes only bodies passing `instanceof Stream`
// and JSON-serializes anything else: node-tar >= 7 returns a duck-typed (Minipass) stream, which
// silently turned a proxied file restore into a JSON dump of the tar object. Every format must
// resolve with a real node stream.
test('fetchPartitionFiles resolves with a node:stream for every format', async t => {
const tmp = await mkdtemp(join(tmpdir(), 'xo-flr-fetch-'))
t.after(() => rm(tmp, { recursive: true, force: true }))
await writeFile(join(tmp, 'file.txt'), 'hello')
const adapter = new RemoteAdapter({})
// at this point of a real restore the partition is already mounted
adapter.getPartition = Disposable.factory(async function* () {
yield tmp
})
for (const [format, magic] of [
['tgz', Buffer.from([0x1f, 0x8b])],
['zip', Buffer.from('PK')],
]) {
const stream = await adapter.fetchPartitionFiles('disk', 'partition', ['/file.txt'], format)
assert.ok(stream instanceof Stream, `${format}: expected a node:stream instance`)
const chunks = []
for await (const chunk of stream) {
chunks.push(chunk)
}
const archive = Buffer.concat(chunks)
assert.deepEqual(archive.subarray(0, magic.length), magic, `${format}: unexpected archive header`)
}
})
test('LVM file-restore against real losetup/dmsetup/lvm', { skip }, async t => {
const tmp = await mkdtemp(join(tmpdir(), 'xo-flr-'))
const adapter = new RemoteAdapter({})

View File

@@ -12,7 +12,6 @@ import { compose } from '@vates/compose'
import { createLogger } from '@xen-orchestra/log'
import { deduped } from '@vates/disposable/deduped.js'
import { randomBytes } from 'node:crypto'
import { Readable } from 'node:stream'
import { join, resolve } from 'node:path'
import { execFile } from 'child_process'
import { finished } from 'node:stream/promises'
@@ -298,15 +297,7 @@ export const fileRestoreMethods = {
// simultaneous reads. Those saturate the libuv threadpool and starve
// the underlying vhd/CIFS reads NTFS-3g depends on (FUSE-on-FUSE
// threadpool deadlock). Serializing keeps a worker free for them.
const pack = tar.c({ cwd: path, gzip: true, jobs: 1 }, paths.map(makeRelative))
// node-tar >= 7 returns a Minipass stream: it has `pipe()` but is not a `node:stream`
// instance. xo-proxy serves this stream through Koa, which pipes only bodies passing
// `instanceof Stream` and JSON-serializes anything else — so a file restore through a
// proxy answered a JSON dump of the tar object instead of the archive. Wrapping it in a
// real node stream also propagates tar errors to the consumer and aborts the tar job
// when the client disconnects.
outputStream = Readable.from(pack, { objectMode: false })
outputStream = tar.c({ cwd: path, gzip: true, jobs: 1 }, paths.map(makeRelative))
resolve(outputStream)
} else if (format === 'zip') {
const zip = new ZipFile()

View File

@@ -33,13 +33,6 @@ export const VM_UUID = 'xo:backup:vm'
// allows direction-agnostic discovery of common base VDIs (e.g. for failback/reverse replication)
export const CONTENT_KEY = 'xo:backup:contentKey'
// in `other_config` of a replicated VM and its VDIs
// set to the string 'true' on every write done by code that includes the non-NBD qcow2
// corruption fix (fix(disk-transform): erroneous DiskLargerBlock copy offset). Its absence
// on a qcow2 full means the replica may be silently corrupt and its chain must be re-based
// with a clean full. Named after the specific fix so future fixes get their own flag.
export const INCLUDE_NON_NBD_QCOW2_FIX = 'xo:backup:includeNonNbdQcow2Fix'
async function listVdiRefs(xapi, vmRef) {
return xapi.VM_getDisks(vmRef)
}
@@ -97,7 +90,6 @@ export function resetVmOtherConfig(xapi, vmRef) {
[DATETIME]: null,
[DELTA_CHAIN_LENGTH]: null,
[EXPORTED_SUCCESSFULLY]: null,
[INCLUDE_NON_NBD_QCOW2_FIX]: null,
[JOB_ID]: null,
[SCHEDULE_ID]: null,
[VM_UUID]: null,
@@ -128,10 +120,6 @@ export async function setVmOtherConfig(xapi, vmRef, { timestamp, jobId, schedule
xapi.setFieldEntries(type, ref, 'other_config', {
[REPLICATED_TO_SR_UUID]: srUuid,
[DATETIME]: formatDateTime(timestamp),
// stamped on every write: its presence marks the object as produced by code
// that includes the non-NBD qcow2 corruption fix, so a chain rooted in a pre-fix
// qcow2 full (missing this flag) can be detected and re-based with a clean full
[INCLUDE_NON_NBD_QCOW2_FIX]: 'true',
[JOB_ID]: jobId,
[SCHEDULE_ID]: scheduleId,
[VM_UUID]: vmUuid,

View File

@@ -1,13 +1,10 @@
import { asyncMap } from '@xen-orchestra/async-map'
import { createLogger } from '@xen-orchestra/log'
import { Task } from '@vates/task'
import { DIR_XO_POOL_METADATA_BACKUPS } from '../RemoteAdapter.mjs'
import { forkStreamUnpipe } from './_forkStreamUnpipe.mjs'
import { formatFilenameDate } from '../_filenameDate.mjs'
const { debug } = createLogger('xo:backups:PoolMetadataBackup')
export const PATH_DB_DUMP = '/pool/xmldbdump'
export class PoolMetadataBackup {
@@ -34,22 +31,7 @@ export class PoolMetadataBackup {
const poolDir = `${DIR_XO_POOL_METADATA_BACKUPS}/${schedule.id}/${pool.$id}`
const dir = `${poolDir}/${formatFilenameDate(timestamp)}`
const tasks = Object.values(pool.$xapi.objects.indexes.type.task ?? {})
const pendingTasks = tasks.filter(task => task.status === 'pending')
debug('pool tasks before export', {
total: tasks.length,
pending: pendingTasks.length,
oldestPendingCreated: pendingTasks.map(task => task.created).sort()[0],
})
const stream = (await this._exportPoolMetadata()).body
const startedAt = Date.now()
let bytes = 0
stream.once('data', () => debug('first byte received', { afterMs: Date.now() - startedAt }))
stream.on('data', chunk => (bytes += chunk.length))
stream.once('end', () => debug('stream ended', { bytes, durationMs: Date.now() - startedAt }))
stream.once('error', error => debug('stream errored', { error, bytes, durationMs: Date.now() - startedAt }))
const fileName = `${dir}/data`
const metadata = JSON.stringify(

View File

@@ -99,7 +99,6 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {
writer =>
writer.transfer({
deltaExport: forkDeltaExport(incrementalExport, writer.constructor.name),
includeNonNbdQcow2Fix: metadata.includeNonNbdQcow2Fix,
isVhdDifferencing,
timestamp: metadata.timestamp,
vm: metadata.vm,
@@ -107,6 +106,16 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {
}),
'writer.transfer()'
)
// this will update parent name with the needed alias
await this._callWriters(
writer =>
writer.updateUuidAndChain({
isVhdDifferencing,
timestamp: metadata.timestamp,
vdis: incrementalExport.vdis,
}),
'writer.updateUuidAndChain()'
)
await this._callWriters(writer => writer.cleanup(), 'writer.cleanup()')
// for healthcheck

View File

@@ -73,10 +73,6 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
writer =>
writer.transfer({
deltaExport: forkDeltaExport(deltaExport, writer.constructor.name),
// freshly exported from XAPI by code that has the fix and the force-full gate
// (writer.checkBaseVdis ran before this transfer), so the chain is verified/forced
// clean; the tip's flag lets the next run skip re-probing
includeNonNbdQcow2Fix: true,
isVhdDifferencing,
timestamp,
vm,
@@ -84,6 +80,15 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
}),
'writer.transfer()'
)
await this._callWriters(
writer =>
writer.updateUuidAndChain({
isVhdDifferencing,
timestamp,
vdis: deltaExport.vdis,
}),
'writer.updateUuidAndChain()'
)
if (isFull) {
await setVmDeltaChainLength(this._xapi, exportedVm.$ref, 0)

View File

@@ -22,7 +22,7 @@ export class AggregatedIncrementalRemoteWriter extends AbstractAggregatedRemoteW
}
// update the parameter with our best candidate
// that can be an empty map
baseUuidToSrcVdi.forEach((_, key) => {
baseUuidToSrcVdi.forEach(key => {
if (!selectedCopy.has(key)) {
baseUuidToSrcVdi.delete(key)
}
@@ -50,8 +50,13 @@ export class AggregatedIncrementalRemoteWriter extends AbstractAggregatedRemoteW
await Promise.all(this.writers.map(writer => writer.prepare({ isFull })))
}
// write only on the main writer
transfer(args) {
return this.mainWriter.transfer(args)
transfer({ isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
return this.mainWriter.transfer({ isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot })
}
// chain only on the main writer
updateUuidAndChain({ isVhdDifferencing, vdis }) {
return this.mainWriter.updateUuidAndChain({ isVhdDifferencing, vdis })
}
// remove the backups and remove the entries

View File

@@ -25,7 +25,7 @@ export class AggregatedIncrementalXapiWriter extends AbstractAggregatedXapiWrite
}
// update the parameter with our best candidate
// that can be an empty map
baseUuidToSrcVdi.forEach((_, key) => {
baseUuidToSrcVdi.forEach(key => {
if (!selectedCopy.has(key)) {
baseUuidToSrcVdi.delete(key)
}
@@ -59,6 +59,11 @@ export class AggregatedIncrementalXapiWriter extends AbstractAggregatedXapiWrite
return this.mainWriter.transfer(args)
}
// chain only on the main writer
updateUuidAndChain(args) {
return this.mainWriter.updateUuidAndChain(args)
}
// remove the backups and remove the entries
async cleanup() {
debug('cleanup')

View File

@@ -2,11 +2,11 @@ import assert from 'node:assert'
import mapValues from 'lodash/mapValues.js'
import { asyncEach } from '@vates/async-each'
import { asyncMap } from '@xen-orchestra/async-map'
import { chainVhd, openVhd } from 'vhd-lib'
import { createLogger } from '@xen-orchestra/log'
import { decorateClass } from '@vates/decorate-with'
import { defer } from 'golike-defer'
import { dirname, basename } from 'node:path'
import { relativeFromFile } from '@xen-orchestra/fs/path'
import { Task } from '@vates/task'
import { formatFilenameDate } from '../../_filenameDate.mjs'
@@ -16,18 +16,15 @@ import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
import { checkVhd } from './_checkVhd.mjs'
import { packUuid } from './_packUuid.mjs'
import { openDiskChain } from '@xen-orchestra/backup-archive/disks'
import { VDI_FORMAT_QCOW2 } from '@xen-orchestra/xapi'
import { diskHasData } from './_diskHasData.mjs'
import { Disposable } from 'promise-toolbox'
const { warn } = createLogger('xo:backups:DeltaBackupWriter')
export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrementalWriter) {
#parentVdiPaths
#parentUuids
#vhds
async checkBaseVdis(baseUuidToSrcVdi) {
this.#parentVdiPaths = {}
this.#parentUuids = {}
const { handler } = this._adapter
const adapter = this._adapter
@@ -35,7 +32,6 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
await asyncMap(baseUuidToSrcVdi, async ([baseUuid, srcVdiUuid]) => {
let parentDestPath
let parentUuid
const vhdDir = `${vdisDir}/${srcVdiUuid}`
try {
const vhds = await handler.list(vhdDir, {
@@ -51,7 +47,6 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
try {
if (await adapter.isMergeableParent(packedBaseUuid, path)) {
parentDestPath = path
parentUuid = packedBaseUuid
}
} catch (error) {
warn('checkBaseVdis', { error })
@@ -64,77 +59,11 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
if (parentDestPath === undefined) {
baseUuidToSrcVdi.delete(baseUuid)
} else {
try {
// A delta is only chained onto a qcow2 base when NBD is enabled; without NBD a qcow2
// export falls back to a full, so there is no suspect base to worry about.
if (this._settings.preferNbd && !(await this.#isBaseChainable(parentDestPath))) {
Task.warning('forcing a full: qcow2 base predates the non-NBD qcow2 fix and looks corrupt', {
parentDestPath,
})
baseUuidToSrcVdi.delete(baseUuid)
return
}
this.#parentVdiPaths[vhdDir] = parentDestPath
this.#parentUuids[vhdDir] = parentUuid
} catch (error) {
warn('checkBaseVdis: unexpected error, forcing a full', { error, parentDestPath })
baseUuidToSrcVdi.delete(baseUuid)
}
this.#parentVdiPaths[vhdDir] = parentDestPath
}
})
}
// Decide whether it is safe to chain a delta onto `parentDestPath` (the chain tip).
// A qcow2 full exported before the DiskLargerBlock 20260724 fix can be silently corrupt (block 0
// valid, following allocated blocks all zero); chaining a delta onto it would extend a
// broken chain, so we detect that case and let the caller fall back to a full.
async #isBaseChainable(parentDestPath) {
// parentDestPath is the chain tip = most-recent backup; its filename is stable under
// merges (merges rename the OLDER disks), so unlike the root it maps reliably to its
// metadata json.
const parentDate = basename(parentDestPath).replace(/\.(alias\.)?vhd$/, '')
let metadata
try {
metadata = await this._adapter.readVmBackupMetadata(`${this._vmBackupDir}/${parentDate}.json`)
} catch (error) {
warn('checkBaseVdis: cannot read parent metadata, will probe', { error, parentDestPath })
}
if (metadata?.includeNonNbdQcow2Fix === true) {
// written by code that has the fix and this gate, so its chain was already
// verified/forced clean — no disk open needed
// we can't have includeNonNbdQcow2Fix = false since it would have restarted a clean chain
return true
}
const isQcow2 =
metadata === undefined ||
Object.values(metadata.vdis ?? {}).some(vdi => vdi?.sm_config?.['image-format'] === VDI_FORMAT_QCOW2)
if (!isQcow2) {
// only qcow2 exports can carry this corruption
return true
}
return this.#baseHasData(parentDestPath)
}
// Probe the first data blocks of the chain root for the DiskLargerBlock corruption
// signature. Returns false only when enough allocated blocks past the first are all zero.
async #baseHasData(parentDestPath) {
const { handler } = this._adapter
// open the chain (with block allocation tables) and probe its root full. This only runs
// once per chain — afterwards the includeNonNbdQcow2Fix flag on the tip skips it — so
// reading the deltas' BATs here is negligible and lets us reuse the root disk directly.
const chain = await openDiskChain({ handler, path: parentDestPath })
try {
const root = chain.getRootDisk()
if (root === undefined) {
throw new Error(`can't resolve root of chain ${parentDestPath}`)
}
return await diskHasData(root)
} finally {
await chain.close()
}
}
async beforeBackup() {
await super.beforeBackup()
return this._cleanVm({ merge: true, remove: true })
@@ -197,6 +126,48 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
}
}
async updateUuidAndChain({ isVhdDifferencing, vdis }) {
assert.notStrictEqual(
this.#vhds,
undefined,
'_transfer must be called before updateUuidAndChain for incremental backups'
)
const parentVdiPaths = this.#parentVdiPaths
const { handler } = this._adapter
const vhds = this.#vhds
await asyncEach(Object.entries(vdis), async ([id, vdi]) => {
const isDifferencing = isVhdDifferencing[id]
const path = `${this._vmBackupDir}/${vhds[id]}`
if (isDifferencing) {
assert.notStrictEqual(
parentVdiPaths,
undefined,
'checkbasevdi must be called before updateUuidAndChain for incremental backups'
)
const parentPath = parentVdiPaths[dirname(path)]
// we are in a incremental backup
// we already computed the chain in checkBaseVdis
assert.notStrictEqual(parentPath, undefined, 'A differential VHD must have a parent')
// forbid any kind of loop
assert.ok(basename(parentPath) < basename(path), `vhd must be sorted to be chained`)
// re-chainVhd is mandatory
// since the parent may be a alias or not
// and the child may be the other
await chainVhd(handler, parentPath, handler, path)
}
// set the correct UUID in the VHD if needed
await Disposable.use(openVhd(handler, path), async vhd => {
if (!vhd.footer.uuid.equals(packUuid(vdi.uuid))) {
vhd.footer.uuid = packUuid(vdi.uuid)
await vhd.readBlockAllocationTable() // required by writeFooter()
await vhd.writeFooter()
}
})
})
}
async _deleteOldEntries() {
const adapter = this._adapter
const oldEntries = this._oldEntries
@@ -207,7 +178,7 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
}
}
async _transfer($defer, { includeNonNbdQcow2Fix, isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
async _transfer($defer, { isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
const adapter = this._adapter
const job = this._job
const scheduleId = this._schedule.id
@@ -215,8 +186,10 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
const jobId = job.id
const handler = adapter.handler
const filenameDate = formatFilenameDate(timestamp)
const vhds = mapValues(
const basename = formatFilenameDate(timestamp)
// update this.#vhds before eventually skipping transfer, so that
// updateUuidAndChain has all the mandatory data
const vhds = (this.#vhds = mapValues(
deltaExport.vdis,
vdi =>
`vdis/${jobId}/${
@@ -225,8 +198,8 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
// don't do delta for it
vdi.uuid
: vdi.$snapshot_of$uuid
}/${adapter.getVhdFileName(filenameDate)}`
)
}/${adapter.getVhdFileName(basename)}`
))
let metadataContent = await this._isAlreadyTransferred(timestamp)
if (metadataContent !== undefined) {
@@ -236,11 +209,6 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
}
metadataContent = {
// marks whether the disk data is known-good w.r.t. the non-NBD qcow2 corruption bug.
// A fresh XAPI export by fixed code passes `true`; the mirror runner propagates the
// source backup's value (copying corrupt source data must NOT become "fixed"). Its
// absence flags a potentially-corrupt older disk (used by cleanVm and the force-full gate).
includeNonNbdQcow2Fix,
isVhdDifferencing,
jobId,
mode: job.mode,
@@ -261,24 +229,12 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
Object.entries(deltaExport.disks),
async ([diskRef, disk]) => {
const path = `${this._vmBackupDir}/${vhds[diskRef]}`
const vdi = deltaExport.vdis[diskRef]
let parentUuid, parentPath
if (isVhdDifferencing[diskRef]) {
const parentDestPath = this.#parentVdiPaths[dirname(path)]
parentUuid = this.#parentUuids[dirname(path)]
assert.notStrictEqual(parentDestPath, undefined, 'A differential VHD must have a parent')
// forbid any kind of loop
assert.ok(basename(parentDestPath) < basename(path), `vhd must be sorted to be chained`)
parentPath = relativeFromFile(path, parentDestPath)
}
const transferred = await adapter.writeVhd(path, disk, {
// no checksum for VHDs, because they will be invalidated by
// merges and chains
checksum: false,
validator: tmpPath => checkVhd(handler, tmpPath),
writeBlockConcurrency: this._config.writeBlockConcurrency,
uuid: packUuid(vdi.uuid),
parentUuid,
parentPath,
})
size += transferred
},

View File

@@ -1,4 +1,3 @@
import assert from 'node:assert'
import humanFormat from 'human-format'
import { asyncMapSettled } from '@xen-orchestra/async-map'
@@ -21,7 +20,6 @@ import {
DATETIME,
VM_UUID,
CONTENT_KEY,
INCLUDE_NON_NBD_QCOW2_FIX,
resetVmOtherConfig,
} from '../../_otherConfig.mjs'
import { formatFilenameDate } from '../../_filenameDate.mjs'
@@ -29,9 +27,8 @@ import { XapiDiskSource } from '@xen-orchestra/xapi'
import { asyncEach } from '@vates/async-each'
import { createLogger } from '@xen-orchestra/log'
import { VM_POWER_STATE } from '@vates/types'
import { diskHasData } from './_diskHasData.mjs'
const { debug, warn } = createLogger('xo:backups:IncrementalXapiWriter')
const { debug } = createLogger('xo:backups:IncrementalXapiWriter')
export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWriter) {
// Map of source VDI UUID (COPY_OF) → validated active VDI on the target SR.
@@ -96,45 +93,6 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
)
}
if (target !== undefined) {
// A delta is only chained onto a qcow2 base when NBD is enabled; without NBD a qcow2
// export falls back to a full, so there is no suspect base.
if (this._settings.preferNbd) {
// Every copy written by fixed code carries the flag, so the marker on the most recent
// link is enough: if it is there, this chain was already verified (or re-based) by a
// run that had the fix, and older links need no re-check.
const suspect = target.other_config[INCLUDE_NON_NBD_QCOW2_FIX] !== 'true'
if (suspect) {
const chain = this.#diskReplicaSnapshots(target)
// probe the OLDEST link (least-masked view of the corruption — a later delta could
// have overwritten the corrupt blocks and hidden the damage on a more recent snapshot).
// Re-replicating a full is expensive, so only force one when it actually looks corrupt.
let base = target
assert.notStrictEqual(base.other_config[DATETIME], undefined)
for (const vdi of chain) {
const datetime = vdi.other_config[DATETIME]
assert.notStrictEqual(datetime, undefined)
if (datetime < base.other_config[DATETIME]) {
base = vdi
}
}
let chainable
try {
chainable = await this.#baseVdiHasData(base.$ref)
} catch (error) {
// can't read the base to decide → don't chain onto it
warn('checkBaseVdis: error probing replicated base, forcing a full', { error, baseVdi: base.uuid })
chainable = false
}
if (!chainable) {
Task.warning('forcing a full: replicated qcow2 chain predates the non-NBD qcow2 fix and looks corrupt', {
baseVdi: base.uuid,
})
// drop it so neither the snapshot nor the legacy fallback reuses it → full
baseUuidToSrcVdi.delete(baseUuid)
continue
}
}
}
snapshotCandidates.set(baseUuid, target)
}
}
@@ -175,42 +133,6 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
}
}
}
// All replica snapshots of a given disk share the same active target VDI ($snapshot_of). Return
// them (same job+vm) so the caller can inspect the whole chain: any link missing the fix marker
// makes the chain suspect, and the oldest link (by DATETIME) is the least-masked base to probe.
// Scoped by $snapshot_of, so history before a CR VM recreation (which resets it) is not included.
#diskReplicaSnapshots(target) {
const activeUuid = target.$snapshot_of?.uuid
const snapshots = []
for (const vdi of this._sr.$VDIs) {
if (
vdi?.managed &&
vdi?.is_a_snapshot &&
vdi.$snapshot_of?.uuid === activeUuid &&
vdi.other_config[JOB_ID] === this._job.id &&
vdi.other_config[VM_UUID] === this._vmUuid
) {
snapshots.push(vdi)
}
}
return snapshots
}
// Probe a replicated base VDI for the DiskLargerBlock corruption signature (block 0 valid,
// following allocated blocks all zero). Uses an export (not NBD): block flow is guaranteed
// to be in index order, so block 0 comes first and inspecting the first few blocks is enough.
// Returns false only when no allocated non-zero block is found among the first ones.
async #baseVdiHasData(vdiRef) {
const source = new XapiDiskSource({ xapi: this._sr.$xapi, vdiRef, preferNbd: false })
try {
await source.init()
return await diskHasData(source)
} finally {
await source.close()
}
}
/**
* 6.3+ snapshot-based validation: for each snapshot candidate, check whether
* the active VDI has diverged from the snapshot. Returns a baseVdisBySourceUuid
@@ -313,6 +235,9 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
return { baseVdisBySourceUuid, targetVmRef }
}
updateUuidAndChain() {
// nothing to do, the chaining is not modified in this case
}
prepare({ isFull }) {
// create the task related to this export and ensure all methods are called in this context
const task = new Task({
@@ -418,10 +343,6 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
if (baseDeltaVdiUuid !== undefined) {
// reuse the validated mapping built by checkBaseVdis
vdi.baseVdi = this.#baseVdisBySourceUuid.get(baseDeltaVdiUuid)
// BASE_DELTA_VDI is set, so the export is differencing. Without a base to clone,
// importIncrementalVm would create a blank VDI and write only the changed blocks
// into it, silently producing a corrupt replica: fail the job instead.
assert.notStrictEqual(vdi.baseVdi, undefined, `no validated target base for ${baseDeltaVdiUuid}`)
} else {
// first replication of this disk (full, no base)
vdi.baseVdi = undefined

View File

@@ -5,6 +5,10 @@ export class AbstractIncrementalWriter extends AbstractWriter {
throw new Error('Not implemented')
}
updateUuidAndChain() {
throw new Error('Not implemented')
}
cleanup() {
throw new Error('Not implemented')
}
@@ -16,6 +20,8 @@ export class AbstractIncrementalWriter extends AbstractWriter {
async transfer({ deltaExport, ...other }) {
try {
return await this._transfer({ deltaExport, ...other })
} catch (err) {
console.error({ err })
} finally {
// ensure all sources are properly closed
for (const disk of Object.values(deltaExport.disks)) {

View File

@@ -1,26 +0,0 @@
// Probe a disk for the DiskLargerBlock corruption signature (block 0 valid,
// following allocated blocks all zero). Uses an export (not NBD): block flow is guaranteed
// to be in index order, so block 0 comes first and inspecting the first few blocks is enough.
// Returns false only when no allocated non-zero block is found among the first ones.
export async function diskHasData(source) {
const empty = Buffer.alloc(source.getBlockSize(), 0)
const MAX_EMPTY = 10
let nbEmpty = 0
// diskBlocks() closes the source when the iteration ends or is broken out of
for await (const { index, data } of source.diskBlocks()) {
if (index === 0) {
// block 0 stays valid even in the corruption signature — skip it
continue
}
if (!data.equals(empty)) {
// an allocated block holds real data → not corrupt
return true
}
if (++nbEmpty >= MAX_EMPTY) {
break
}
}
// no allocated non-zero block among the first ones → looks corrupt (or empty; a full is cheap then)
return false
}

View File

@@ -230,6 +230,7 @@ Settings are described in [`@xen-orchestra/backups/\_runners/VmsXapi.mjs``](http
- `checkBaseVdis(baseUuidToSrcVdi, baseVm)`
- `prepare({ isFull })`
- `transfer({ timestamp, deltaExport, sizeContainers })`
- `updateUuidAndChain({ isVhdDifferencing, vdis })`
- `cleanup()`
- `healthCheck()` // is not executed if no health check sr or tag doesn't match
- **Full**

View File

@@ -8,7 +8,7 @@
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"version": "0.73.10",
"version": "0.73.7",
"engines": {
"node": ">=14.18"
},
@@ -27,17 +27,17 @@
"@vates/disposable": "^0.1.6",
"@vates/fuse-vhd": "^2.1.3",
"@vates/generator-toolbox": "^1.1.3",
"@vates/nbd-client": "^3.5.0",
"@vates/nbd-client": "^3.4.0",
"@vates/parse-duration": "^0.1.1",
"@vates/task": "^0.7.0",
"@vates/types": "^1.30.1",
"@vates/types": "^1.28.0",
"@xen-orchestra/async-map": "^0.1.3",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/disk-transform": "^1.3.1",
"@xen-orchestra/fs": "^4.9.2",
"@xen-orchestra/log": "^0.7.2",
"@xen-orchestra/qcow2": "^1.3.1",
"@xen-orchestra/template": "^0.1.1",
"@xen-orchestra/backup-archive": "^1.1.1",
"@xen-orchestra/backup-archive": "^1.0.4",
"app-conf": "^3.0.0",
"compare-versions": "^6.0.0",
"d3-time-format": "^4.1.0",
@@ -55,8 +55,8 @@
"tar": "^7.5.3",
"uuid": "^9.0.0",
"value-matcher": "^0.2.0",
"vhd-lib": "^4.16.1",
"xen-api": "^4.8.0",
"vhd-lib": "^4.16.0",
"xen-api": "^4.7.8",
"yazl": "^2.5.1"
},
"devDependencies": {
@@ -67,7 +67,7 @@
"typescript": "^5.9.3"
},
"peerDependencies": {
"@xen-orchestra/xapi": "^8.10.2"
"@xen-orchestra/xapi": "^8.9.0"
},
"license": "AGPL-3.0-or-later",
"author": {

View File

@@ -18,7 +18,7 @@
"preferGlobal": true,
"dependencies": {
"golike-defer": "^0.5.1",
"xen-api": "^4.8.0"
"xen-api": "^4.7.8"
},
"scripts": {
"postversion": "npm publish"

View File

@@ -1,7 +1,7 @@
{
"private": false,
"name": "@xen-orchestra/disk-cli",
"version": "2.2.0",
"version": "2.1.2",
"description": "CLI tool to inspect and manage disks in backup repositories",
"type": "module",
"bin": {
@@ -20,13 +20,13 @@
},
"dependencies": {
"@vates/async-each": "^1.0.3",
"@xen-orchestra/backups": "^0.73.10",
"@xen-orchestra/backup-archive": "^1.1.1",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/backups": "^0.73.7",
"@xen-orchestra/backup-archive": "^1.0.4",
"@xen-orchestra/disk-transform": "^1.3.1",
"@xen-orchestra/fs": "^4.9.2",
"@xen-orchestra/qcow2": "^1.3.1",
"promise-toolbox": "^0.21.0",
"vhd-lib": "^4.16.1"
"vhd-lib": "^4.16.0"
},
"devDependencies": {
"@types/node": "^22.3.0",

View File

@@ -1,12 +1,13 @@
{
"name": "@xen-orchestra/disk-transform",
"version": "1.3.3",
"version": "1.3.1",
"main": "./dist/index.mjs",
"license": "MIT",
"private": false,
"type": "module",
"devDependencies": {
"@eslint/js": "^9.19.0",
"@xen-orchestra/fs": "^4.9.2",
"rimraf": "^6.0.1",
"@types/node": "^22.3.0",
"typescript": "~5.6",
@@ -17,6 +18,7 @@
"dev": "tsc --watch",
"postversion": "npm publish --access public",
"test": "tsc && node --test **/*.test.mjs",
"test-integration": "node --test **/*.integ.mjs",
"clean": "rimraf dist/"
},
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/disk-transform",

View File

@@ -0,0 +1,109 @@
import { afterEach, beforeEach, test } from 'node:test'
import assert from 'node:assert'
import { mkdtemp } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { rimraf } from 'rimraf'
import { getSyncedHandler } from '@xen-orchestra/fs'
import type { FileAccessor } from './FileAccessor.mjs'
import {
AliasChainError,
AliasIsDirectoryError,
AliasMissingError,
AliasTooLongError,
ALIAS_MAX_PATH_LENGTH,
DiskAlias,
} from './DiskAlias.mjs'
let tempDir: string
let dispose: () => Promise<void>
let handler: FileAccessor
beforeEach(async () => {
tempDir = await mkdtemp(join(tmpdir(), 'disk-alias-'))
const synced = await getSyncedHandler({ url: `file://${tempDir}` })
handler = synced.value as unknown as FileAccessor
dispose = synced.dispose
})
afterEach(async () => {
await dispose()
await rimraf(tempDir)
})
test('DiskAlias resolve()', async t => {
await t.test('gets the path of the target file for an alias, same directory', async () => {
const vhdAlias = new DiskAlias('vhd')
const alias = 'alias.alias.vhd'
await handler.writeFile(alias, 'target.vhd')
assert.equal(await vhdAlias.resolve(handler, alias), 'target.vhd')
})
await t.test('gets the path of the target file for an alias, different directory', async () => {
const vhdAlias = new DiskAlias('vhd')
const alias = 'alias.alias.vhd'
await handler.mktree('sub')
await handler.writeFile(alias, 'sub/target.vhd', { flags: 'w' })
assert.equal(await vhdAlias.resolve(handler, alias), 'sub/target.vhd')
})
await t.test('throws AliasChainError on an alias to an alias', async () => {
const vhdAlias = new DiskAlias('vhd')
const alias = 'alias.alias.vhd'
const target = 'target.alias.vhd'
await handler.writeFile(alias, target)
await assert.rejects(async () => await vhdAlias.resolve(handler, alias), AliasChainError)
})
await t.test('throws AliasTooLongError on a file too big', async () => {
const vhdAlias = new DiskAlias('vhd')
await handler.writeFile('toobig.alias.vhd', '0'.repeat(ALIAS_MAX_PATH_LENGTH + 1))
await assert.rejects(async () => await vhdAlias.resolve(handler, 'toobig.alias.vhd'), AliasTooLongError)
})
await t.test('throws AliasMissingError when the alias file does not exist', async () => {
const vhdAlias = new DiskAlias('vhd')
await assert.rejects(async () => await vhdAlias.resolve(handler, 'missing.alias.vhd'), AliasMissingError)
})
await t.test('throws AliasIsDirectoryError when the alias path is a directory', async () => {
const vhdAlias = new DiskAlias('vhd')
await handler.mktree('broken.alias.vhd')
await assert.rejects(async () => await vhdAlias.resolve(handler, 'broken.alias.vhd'), AliasIsDirectoryError)
})
})
test('DiskAlias create()', async t => {
await t.test('writes the relative path from the alias to the target', async () => {
const vhdAlias = new DiskAlias('vhd')
await handler.mktree('data')
await vhdAlias.create(handler, 'disk.alias.vhd', 'data/disk.vhd')
assert.equal((await handler.readFile('disk.alias.vhd')).toString(), 'data/disk.vhd')
})
await t.test('rejects chaining alias to alias', async () => {
const vhdAlias = new DiskAlias('vhd')
await assert.rejects(
async () => await vhdAlias.create(handler, 'disk.alias.vhd', 'other.alias.vhd'),
AliasChainError
)
})
})
test('DiskAlias unlink()', async t => {
await t.test('removes the alias file and its target', async () => {
const vhdAlias = new DiskAlias('vhd')
await handler.writeFile('data.vhd', 'content')
await vhdAlias.create(handler, 'disk.alias.vhd', 'data.vhd')
await vhdAlias.unlink(handler, 'disk.alias.vhd')
await assert.rejects(async () => await handler.getSize('disk.alias.vhd'))
await assert.rejects(async () => await handler.getSize('data.vhd'))
})
await t.test('removes a broken alias that is actually a directory', async () => {
const vhdAlias = new DiskAlias('vhd')
await handler.mktree('broken.alias.vhd')
await vhdAlias.unlink(handler, 'broken.alias.vhd')
await assert.rejects(async () => await handler.getSize('broken.alias.vhd'))
})
})

View File

@@ -0,0 +1,121 @@
import { dirname, relative, resolve } from 'node:path'
import type { FileAccessor } from './FileAccessor.mjs'
export const ALIAS_MAX_PATH_LENGTH = 1024
export class DiskAliasError extends Error {}
export class AliasMissingError extends DiskAliasError {
code = 'ENOENT'
}
export class AliasIsDirectoryError extends DiskAliasError {
code = 'EISDIR'
}
export class AliasChainError extends DiskAliasError {}
export class AliasTooLongError extends DiskAliasError {}
function resolveRelativeFromFile(file: string, targetPath: string): string {
if (file.startsWith('/')) {
return resolve(dirname(file), targetPath)
}
return resolve('/', dirname(file), targetPath).slice(1)
}
/**
* an alias is a small text file containing the path, relative to itself,
* of the disk (file or directory) it points to
*/
export class DiskAlias {
#extension: string
constructor(extension: string) {
this.#extension = extension
}
get suffix(): string {
return `.alias.${this.#extension}`
}
isAlias(filename: string): boolean {
return filename.endsWith(this.suffix)
}
async resolve(handler: FileAccessor, filename: string): Promise<string> {
if (!this.isAlias(filename)) {
return filename
}
let aliasContent: string
try {
aliasContent = (await handler.readFile(filename)).toString().trim()
} catch (err: any) {
if (err.code === 'ENOENT') {
throw new AliasMissingError(`The alias file ${filename} does not exist`)
}
if (err.code === 'EISDIR') {
throw new AliasIsDirectoryError(`The alias file ${filename} is a directory`)
}
throw err
}
if (!handler.isEncrypted && aliasContent.length > ALIAS_MAX_PATH_LENGTH) {
throw new AliasTooLongError(`The alias file ${filename} is too long (${aliasContent.length} chars)`)
}
// also handle circular references and unreasonably long chains
if (this.isAlias(aliasContent)) {
throw new AliasChainError(`Chaining alias is forbidden ${filename} to ${aliasContent}`)
}
// the target is relative to the alias location
return resolveRelativeFromFile(filename, aliasContent)
}
async create(handler: FileAccessor, aliasPath: string, targetPath: string): Promise<void> {
if (!this.isAlias(aliasPath)) {
throw new DiskAliasError(`Alias must be named *${this.suffix}, ${aliasPath} given`)
}
if (this.isAlias(targetPath)) {
throw new AliasChainError(`Chaining alias is forbidden ${aliasPath} to ${targetPath}`)
}
// aliasPath and targetPath are absolute path from the root of the handler
// normalize them so they can't escape this dir
const aliasDir = dirname(resolve('/', aliasPath))
// only store the relative path from alias to target
const relativePathToTarget = relative(aliasDir, resolve('/', targetPath))
if (relativePathToTarget.length > ALIAS_MAX_PATH_LENGTH) {
throw new AliasTooLongError(
`Alias relative path ${relativePathToTarget} is too long : ${relativePathToTarget.length} chars, max is ${ALIAS_MAX_PATH_LENGTH}`
)
}
await handler.writeFile(aliasPath, relativePathToTarget)
}
async unlink(handler: FileAccessor, path: string): Promise<void> {
let resolved = path
try {
resolved = await this.resolve(handler, path)
} catch (err) {
// broken alias (named like an alias but is actually a directory) must still be unlinkable
if (!(err instanceof AliasIsDirectoryError)) {
throw err
}
}
try {
await handler.unlink(resolved)
} catch (err: any) {
if (err.code === 'EISDIR') {
await handler.rmtree(resolved)
} else {
throw err
}
}
// also delete the alias file
if (path !== resolved) {
await handler.unlink(path)
}
}
}

View File

@@ -0,0 +1,25 @@
import { test } from 'node:test'
import assert from 'node:assert'
import { DiskAlias } from './DiskAlias.mjs'
test('DiskAlias', async t => {
await t.test('isAlias() recognizes only *.alias.<extension> files', () => {
const vhdAlias = new DiskAlias('vhd')
assert.equal(vhdAlias.isAlias('filename.alias.vhd'), true)
assert.equal(vhdAlias.isAlias('alias.vhd'), false)
assert.equal(vhdAlias.isAlias('filename.vhd'), false)
assert.equal(vhdAlias.isAlias('filename.alias.vhd.other'), false)
})
await t.test('isAlias() is scoped to its own extension', () => {
const vhdAlias = new DiskAlias('vhd')
const qcow2Alias = new DiskAlias('qcow2')
assert.equal(vhdAlias.isAlias('filename.alias.qcow2'), false)
assert.equal(qcow2Alias.isAlias('filename.alias.qcow2'), true)
})
await t.test('resolve() returns the path in argument for a non alias file', async () => {
const vhdAlias = new DiskAlias('vhd')
assert.equal(await vhdAlias.resolve(undefined as any, 'filename.vhd'), 'filename.vhd')
})
})

View File

@@ -31,15 +31,11 @@ export class DiskLargerBlock extends RandomAccessDisk {
throw new Error('Method not implemented.')
}
async readBlock(index: number): Promise<DiskBlock> {
if (!this.hasBlock(index)) {
throw new Error(`Block ${index} not present in this disk`)
}
// @todo handle partial block at the end
const source = this.source
const destinationBlockData = Buffer.alloc(this.getBlockSize(), 0)
const destinationBlock = Buffer.alloc(this.getBlockSize(), 0)
const blockRatio = this.#blockSize / source.getBlockSize()
const firstSourceBlockIndex = index * blockRatio
for (let i = firstSourceBlockIndex; i < firstSourceBlockIndex + blockRatio; i++) {
for (let i = index * blockRatio; i < (index + 1) * blockRatio; i++) {
let data: Buffer | undefined
if (source.hasBlock(i)) {
data = (await source.readBlock(i)).data
@@ -55,12 +51,12 @@ export class DiskLargerBlock extends RandomAccessDisk {
}
}
if (data !== undefined) {
data.copy(destinationBlockData, (i - firstSourceBlockIndex) * source.getBlockSize())
data.copy(destinationBlock, i * source.getBlockSize())
}
}
return {
index,
data: destinationBlockData,
data: destinationBlock,
}
}
@@ -70,24 +66,22 @@ export class DiskLargerBlock extends RandomAccessDisk {
getBlockIndexes(): Array<number> {
const maxBlock = Math.ceil(this.getVirtualSize() / this.getBlockSize())
const blockRatio = this.getBlockSize() / this.source.getBlockSize()
const indexes = []
for (let i = 0; i < maxBlock; i++) {
if (this.hasBlock(i)) {
indexes.push(i)
for (let j = 0; j < blockRatio; j++) {
if (this.source.hasBlock(i * blockRatio + j)) {
indexes.push(i)
break
}
}
}
return indexes
}
getBlockIndexesCount(): number {
let count = 0
const maxBlock = Math.ceil(this.getVirtualSize() / this.getBlockSize())
for (let i = 0; i < maxBlock; i++) {
if (this.hasBlock(i)) {
count++
}
}
return count
let blockRatio = this.getBlockSize() / this.source.getBlockSize()
return this.#source.getBlockIndexesCount() / blockRatio
}
hasBlock(index: number): boolean {

View File

@@ -1,4 +1,4 @@
import assert, { strictEqual } from 'node:assert'
import assert from 'node:assert'
import { test } from 'node:test'
import { DiskLargerBlock } from './DiskLargerBlock.mjs'
import { RandomAccessDisk, DiskBlock, Disk } from './Disk.mjs'
@@ -45,7 +45,7 @@ class MockDisk extends RandomAccessDisk {
this.closed = true
}
isDifferencing(): boolean {
return this.parentDisk !== null || this.isDiff
return this.isDiff
}
instantiateParent(): RandomAccessDisk {
if (!this.parentDisk) throw new Error('No parent disk available')
@@ -118,29 +118,6 @@ test('readBlock with simple block mapping', async () => {
assert(result.data.subarray(512).equals(block2))
})
test('readBlock at index > 0 places source data at block-relative offsets', async () => {
// Regression test: a large block after index 0 must be assembled from its own
// source blocks at offsets relative to the start of that large block.
// With distinct, non-zero patterns this catches the case where copy() targets an
// absolute (disk-wide) offset and silently produces a zeroed block.
const blockC = createPatternBuffer(512, 'C')
const blockD = createPatternBuffer(512, 'D')
const source = new MockDisk(512, 4096, [
[2, blockC],
[3, blockD],
])
await source.init()
const disk = new DiskLargerBlock(source, 1024) // blockRatio = 2, so large block 1 = source blocks 2 & 3
await disk.init()
const result = await disk.readBlock(1)
assert.strictEqual(result.index, 1)
assert.strictEqual(result.data.length, 1024)
assert(result.data.subarray(0, 512).equals(blockC))
assert(result.data.subarray(512).equals(blockD))
})
test('hasBlock behavior', async () => {
const source = new MockDisk(512, 2048, [
[0, Buffer.alloc(512)],
@@ -237,34 +214,6 @@ test('close propagation', async () => {
await disk.close()
assert.strictEqual(source.closed, true)
})
test('getBlockIndexesCount', async () => {
const block = createPatternBuffer(512, 'BLOCK')
let source = new MockDisk(512, 4096, [
[2, block],
[3, block],
])
await source.init()
let disk = new DiskLargerBlock(source, 1024)
await disk.init()
assert.strictEqual(disk.getBlockIndexesCount(), 1)
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
await disk.close()
source = new MockDisk(512, 4096, [
[0, block],
[3, block],
])
await source.init()
disk = new DiskLargerBlock(source, 1024)
await disk.init()
assert.strictEqual(disk.getBlockIndexesCount(), 2)
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
await disk.close()
})
test('generator', async () => {
const source = new MockDisk(512, 1024)
@@ -276,29 +225,3 @@ test('generator', async () => {
assert.strictEqual(block.data.length, 1024)
}
})
test('readblock missing block throws', async () => {
const parentBlock = createPatternBuffer(512, 'PARENT')
const childBlock = createPatternBuffer(512, 'CHILD')
const sourceParent = new MockDisk(512, 2048, [
[0, parentBlock],
[1, parentBlock],
[2, parentBlock],
[3, parentBlock],
])
await sourceParent.init()
const source = new MockDisk(512, 2048, [[2, childBlock]])
source.parentDisk = sourceParent
await source.init()
const disk = new DiskLargerBlock(source, 1024)
await disk.init()
assert.strictEqual(disk.getBlockIndexesCount(), 1)
for await (const block of disk.diskBlocks()) {
assert.strictEqual(block.index, 1)
assert.ok(block.data.slice(0, 512).equals(childBlock), 'missing child data ')
assert.ok(block.data.slice(512, 1024).equals(parentBlock), 'missing parent data')
}
await assert.rejects(() => disk.readBlock(0))
})

View File

@@ -1,6 +1,11 @@
import type { Readable } from 'node:stream'
export type FileDescriptor = number
/** A file descriptor as returned by openFile() - implementation-defined (e.g. a number on local fs) */
export interface FileArg {
fd: unknown
path: string
}
export type FileDescriptor = number | string | FileArg
/**
* a base interface is defined to be able to add other accessor ,
@@ -13,10 +18,10 @@ export type FileDescriptor = number
export interface FileAccessor {
isEncrypted: boolean
list(path: string, opts?: unknown): Promise<string[]>
closeFile(filehandle: number): Promise<void>
openFile(path: string, opts?: unknown): Promise<number>
closeFile(filehandle: FileDescriptor): Promise<void>
openFile(path: string, opts?: unknown): Promise<FileDescriptor>
read(
file: string | number,
file: FileDescriptor,
buffer: Buffer | DataView,
position: number
): Promise<{ bytesRead: number; buffer: Buffer | DataView }>
@@ -26,6 +31,6 @@ export interface FileAccessor {
mktree(path: string): Promise<void>
rmtree(path: string): Promise<void>
unlink(path: string): Promise<void>
outputStream(stream: Readable): Promise<void>
outputStream(path: string, input: Readable, opts?: unknown): Promise<void>
rename(path: string, newPath: string): Promise<void>
}

View File

@@ -1,63 +1,60 @@
import { DiskBlock, RandomAccessDisk } from "./Disk.mjs";
import { FileAccessor } from "./FileAccessor.mjs";
import { DiskBlock, RandomAccessDisk } from './Disk.mjs'
import { FileAccessor, FileDescriptor } from './FileAccessor.mjs'
export class RawDisk extends RandomAccessDisk {
#accessor
#path
#descriptor: FileDescriptor | undefined
#blockSize: number
#size: number | undefined
export class RawDisk extends RandomAccessDisk{
#accessor
#path
#descriptor:number|undefined
#blockSize:number
#size: number|undefined
constructor(accessor: FileAccessor, path: string, blockSize:number){
super()
this.#accessor= accessor
this.#path = path
this.#blockSize = blockSize
constructor(accessor: FileAccessor, path: string, blockSize: number) {
super()
this.#accessor = accessor
this.#path = path
this.#blockSize = blockSize
}
async readBlock(index: number): Promise<DiskBlock> {
if (this.#descriptor === undefined) {
throw new Error("Can't call readBlock before init")
}
async readBlock(index: number): Promise<DiskBlock> {
if(this.#descriptor === undefined){
throw new Error("Can't call readBlock before init");
}
const data = Buffer.alloc(this.getBlockSize(), 0)
await this.#accessor.read(this.#descriptor, data, index*this.getBlockSize())
return {
index,
data
}
const data = Buffer.alloc(this.getBlockSize(), 0)
await this.#accessor.read(this.#descriptor, data, index * this.getBlockSize())
return {
index,
data,
}
getVirtualSize(): number {
if(this.#size === undefined){
throw new Error("Can't call getVirtualsize before init");
}
return this.#size
}
getVirtualSize(): number {
if (this.#size === undefined) {
throw new Error("Can't call getVirtualsize before init")
}
getBlockSize(): number {
return this.#blockSize
return this.#size
}
getBlockSize(): number {
return this.#blockSize
}
async init(): Promise<void> {
this.#descriptor = await this.#accessor.openFile(this.#path)
this.#size = await this.#accessor.getSize(this.#path)
}
async close(): Promise<void> {
this.#descriptor && (await this.#accessor.closeFile(this.#descriptor))
this.#descriptor = undefined
this.#size = undefined
}
isDifferencing(): boolean {
return false
}
getBlockIndexes(): Array<number> {
const nbBlocks = Math.ceil(this.getVirtualSize() / this.getBlockSize())
const index = []
for (let i = 0; i < nbBlocks; i++) {
index.push(i)
}
async init(): Promise<void> {
this.#descriptor = await this.#accessor.openFile(this.#path)
this.#size = await this.#accessor.getSize(this.#path)
}
async close(): Promise<void> {
this.#descriptor && await this.#accessor.closeFile(this.#descriptor)
this.#descriptor = undefined
this.#size = undefined
}
isDifferencing(): boolean {
return false
}
getBlockIndexes(): Array<number> {
const nbBlocks = Math.ceil(this.getVirtualSize()/ this.getBlockSize())
const index =[]
for(let i=0; i < nbBlocks; i ++){
index.push(i)
}
return index
}
hasBlock(index: number): boolean {
return index * this.getBlockSize() < this.getVirtualSize()
}
}
return index
}
hasBlock(index: number): boolean {
return index * this.getBlockSize() < this.getVirtualSize()
}
}

View File

@@ -1,9 +1,18 @@
export { Disk, DiskBlock, RandomAccessDisk } from './Disk.mjs'
export {
DiskAlias,
DiskAliasError,
AliasMissingError,
AliasIsDirectoryError,
AliasChainError,
AliasTooLongError,
ALIAS_MAX_PATH_LENGTH,
} from './DiskAlias.mjs'
export { DiskChain } from './DiskChain.mjs'
export { DiskLargerBlock } from './DiskLargerBlock.mjs'
export { DiskSmallerBlock } from './DiskSmallerBlock.mjs'
export { NegativeDisk } from './NegativeDisk.mjs'
export { FileAccessor } from './FileAccessor.mjs'
export { FileAccessor, FileArg, FileDescriptor } from './FileAccessor.mjs'
export { DiskPassthrough, RandomDiskPassthrough } from './DiskPassthrough.mjs'
export { RawDisk } from './RawDisk.mjs'
export { ReadAhead } from './ReadAhead.mjs'

View File

@@ -1,7 +1,7 @@
{
"private": false,
"name": "@xen-orchestra/fs",
"version": "4.9.3",
"version": "4.9.2",
"license": "AGPL-3.0-or-later",
"description": "The File System for Xen Orchestra backups.",
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/fs",

View File

@@ -441,11 +441,7 @@ export default class S3Handler extends RemoteHandlerAbstract {
new DeleteObjectsCommand({
Bucket: this.#bucket,
Delete: {
// only keep the key: `ETag` and `Size` are also part of `ObjectIdentifier`, where they
// mean "delete only if it still matches", and passing the whole listed object would
// serialize them in the request. Beyond making the deletion conditional, some
// providers reject these elements with a `MalformedXML` error.
Objects: (result.Contents ?? []).map(({ Key }) => ({ Key })),
Objects: result.Contents ?? [],
},
})
)

View File

@@ -164,3 +164,13 @@ export abstract class RemoteHandlerAbstract {
abstract useVhdDirectory(): boolean
abstract addPrefix(prefix: string): RemoteHandlerAbstract
}
// ─── Handler factories ───────────────────────────────────────────────────────
export interface SyncedHandler {
dispose: () => Promise<void>
value: RemoteHandlerAbstract
}
export declare function getHandler(remote: RemoteInfo, ...rest: unknown[]): RemoteHandlerAbstract
export declare function getSyncedHandler(remote: RemoteInfo, ...rest: unknown[]): Promise<SyncedHandler>

View File

@@ -38,7 +38,8 @@ immutabilityDuration = "7d"
## CLI commands
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably. It lifts expired immutability on startup, then every `liftEvery`.
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably.
- **`xo-lift-remote-immutability`**: Manually trigger a lifting pass. If `liftEvery` is set in the config, the process continues running and repeats the check on that interval.
## How protection works
@@ -85,8 +86,6 @@ The expiry reference is the **datetime in the filename**, not the file's `mtime`
On the **first lift run after startup**, all backup files are scanned unconditionally (full scan). This catches orphaned immutable files left by a previous partial or interrupted lock. Subsequent runs use a fast-path: only backups whose `.json` sentinel is currently immutable are processed.
The first run also walks the disk directories (`xo-vm-backups/<vmUUID>/vdis/<jobId>/<vdiId>/`) directly and lifts any expired disk found there, still using the datetime in its own filename. Both the locking and the regular lifting name a backup's disks from its `<datetime>.json`, so a disk stops being reachable that way once XO's retention has deleted that json — or once a merge has renamed the disk, since the surviving `data/<datetime>.vhd` then carries the datetime of the older backup its blocks came from. Such a disk would otherwise stay immutable forever, and an immutable disk prevents XO from ever merging or deleting the backups of that VDI.
## Troubleshooting
### Some files are still immutable after the duration expired
@@ -114,10 +113,8 @@ If one or a few VM had an issue and need manual cleanup, you can manually lift t
4. As root on the file server, run:
```bash
chattr +i /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/*.json
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/*.vhd
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/data/*.vhd
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/
```
Lock the disks, **not** the directories that hold them: `chattr +i -R …/vdis/` also locks `vdis`, the job and VDI directories and `data`, and an immutable directory rejects the files of the next backup, so every later run of that VM would fail. Depending on whether the remote uses VHD directories, one of the two commands above may report that it matched nothing.
Note that this VM will be mutable between step 2 and 4, it's up to you to document and test the backup after.
@@ -127,7 +124,7 @@ Change the setting. The next lift cycle will use the new duration; files already
### Reducing the immutability duration
Change the setting, then restart `xo-immutable-remote` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
Change the setting, then run `xo-lift-remote-immutability` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
### Why are my incremental backups not marked as protected in XO?

View File

@@ -54,7 +54,8 @@ immutabilityDuration = "7d"
## CLI commands
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably. It lifts expired immutability on startup, then every `liftEvery`.
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably.
- **`xo-lift-remote-immutability`**: Manually trigger a lifting pass. If `liftEvery` is set in the config, the process continues running and repeats the check on that interval.
## How protection works
@@ -101,8 +102,6 @@ The expiry reference is the **datetime in the filename**, not the file's `mtime`
On the **first lift run after startup**, all backup files are scanned unconditionally (full scan). This catches orphaned immutable files left by a previous partial or interrupted lock. Subsequent runs use a fast-path: only backups whose `.json` sentinel is currently immutable are processed.
The first run also walks the disk directories (`xo-vm-backups/<vmUUID>/vdis/<jobId>/<vdiId>/`) directly and lifts any expired disk found there, still using the datetime in its own filename. Both the locking and the regular lifting name a backup's disks from its `<datetime>.json`, so a disk stops being reachable that way once XO's retention has deleted that json — or once a merge has renamed the disk, since the surviving `data/<datetime>.vhd` then carries the datetime of the older backup its blocks came from. Such a disk would otherwise stay immutable forever, and an immutable disk prevents XO from ever merging or deleting the backups of that VDI.
## Troubleshooting
### Some files are still immutable after the duration expired
@@ -117,7 +116,7 @@ Restart `xo-immutable-remote`. The first lift run after startup always performs
chattr -i -R /path/to/remote/on/fileserver/
```
### Make one VM temporarily mutable again
### Make one VM mutable again temporarly
If one or a few VM had an issue and need manual cleanup, you can manually lift the immutability for one VM.
@@ -126,16 +125,14 @@ If one or a few VM had an issue and need manual cleanup, you can manually lift t
```bash
chattr -i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>
```
3. Run the backup job, it will fix what is repairable and purge the non recoverable backups
3. run the backup job, it will fix what is reparable and purge the non recoverable backups
4. As root on the file server, run:
```bash
chattr +i /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/*.json
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/*.vhd
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/data/*.vhd
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/
```
Lock the disks, **not** the directories that hold them: `chattr +i -R …/vdis/` also locks `vdis`, the job and VDI directories and `data`, and an immutable directory rejects the files of the next backup, so every later run of that VM would fail. Depending on whether the remote uses VHD directories, one of the two commands above may report that it matched nothing.
Note that this VM will be mutable between step 2 and 4, it's up to you to document and test the backup after.
Note that this VM will be mutable between step 2 and 4, it's up to you to document and test the backup after
### Increasing the immutability duration
@@ -143,7 +140,7 @@ Change the setting. The next lift cycle will use the new duration; files already
### Reducing the immutability duration
Change the setting, then restart `xo-immutable-remote` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
Change the setting, then run `xo-lift-remote-immutability` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
### Why are my incremental backups not marked as protected in XO?

View File

@@ -16,13 +16,13 @@
"xo-immutable-remote": "./dist/protectRemotes.mjs"
},
"license": "AGPL-3.0-or-later",
"version": "3.0.4",
"version": "3.0.3",
"engines": {
"node": ">=20.0.0"
},
"dependencies": {
"@vates/async-each": "^1.0.3",
"@xen-orchestra/backups": "^0.73.10",
"@xen-orchestra/backups": "^0.73.7",
"@xen-orchestra/log": "^0.7.2",
"app-conf": "^3.0.0",
"execa": "^5.0.0",

View File

@@ -8,18 +8,17 @@ export async function makeImmutable(dirPath: string): Promise<void> {
// chattr processes all paths even when some are missing (it does not abort on the first
// error), so every existing path is correctly lifted.
//
// Per-path "while trying to stat" messages (ENOENT) are silently ignored — these are always
// expected for optional paths (.xva, .alias.vhd, …) that are absent in delta backups. chattr
// translates that whole message, so it is run under `LC_ALL=C`: without it, every batch
// containing an optional missing path fails on a localised system, which means no backup ever
// gets locked there.
// Per-path "while trying to stat" messages (ENOENT) are silently ignored regardless of
// locale — these are always expected for optional paths (.xva, .alias.vhd, …) that are
// absent in delta backups. chattr localises the error description but "while trying to
// stat" is always emitted in English, so we match on that suffix only.
//
// Any other error (e.g. EAGAIN on NFS when the file is still open, permission denied) is
// retried up to 3 times with a 1 s delay before being re-thrown.
async function execChattrWithMissingFiles(args: string[]): Promise<void> {
for (let attempt = 0; ; attempt++) {
try {
await execa('chattr', args, { env: { LC_ALL: 'C' } })
await execa('chattr', args)
return
} catch (err) {
const stderr = (err as ExecaError).stderr ?? ''

View File

@@ -1,177 +0,0 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import path from 'node:path'
import { tmpdir } from 'node:os'
import { rimraf } from 'rimraf'
import execa from 'execa'
import * as Directory from './directory.mjs'
import { liftRemoteImmutability } from './liftProtection.mjs'
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const ONE_DAY_MS = 24 * 60 * 60 * 1000
const VM_UUID = 'aaaaaaaa-0000-0000-0000-000000000001'
const JOB_UUID = 'bbbbbbbb-0000-0000-0000-000000000001'
const VDI_UUID = 'cccccccc-0000-0000-0000-000000000001'
/** Well past any reasonable immutabilityDuration. */
const EXPIRED_DATE = '20240115T120000Z'
/** Inside the window: the expiry reference is the datetime in the name, not the file's dates. */
const RECENT_DATE = new Date().toISOString().replace(/[-:.]/g, '').slice(0, 15) + 'Z'
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
// Recursively lift all immutable flags inside `root`, then delete the tree.
// Must be run as root since chattr requires elevated privileges.
async function cleanupRoot(root: string): Promise<void> {
try {
await execa('chattr', ['-i', '-R', root])
} catch (_err) {}
await rimraf(root)
}
async function makeRoot(): Promise<string> {
return await fs.mkdtemp(path.join(tmpdir(), 'immut-lift-test-'))
}
function vmDirOf(root: string): string {
return path.join(root, 'xo-vm-backups', VM_UUID)
}
function vdiDirOf(root: string): string {
return path.join(vmDirOf(root), 'vdis', JOB_UUID, VDI_UUID)
}
// Creates `vdis/<jobId>/<vdiId>/<datetime>.alias.vhd` plus the VHD directory it points at, the way
// XO lays them out, and returns both paths along with one block file inside the VHD directory.
async function writeDisk(root: string, datetime: string) {
const vdiDir = vdiDirOf(root)
const dataDir = path.join(vdiDir, 'data')
const vhdDir = path.join(dataDir, `${datetime}.vhd`)
const blockFile = path.join(vhdDir, 'blocks', '0', '0')
await fs.mkdir(path.dirname(blockFile), { recursive: true })
await fs.writeFile(blockFile, 'block')
await fs.writeFile(path.join(vhdDir, 'footer'), 'footer')
const alias = path.join(vdiDir, `${datetime}.alias.vhd`)
await fs.writeFile(alias, path.relative(vdiDir, vhdDir))
return { alias, vhdDir, blockFile }
}
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
describe('liftProtection/liftRemoteImmutability', async () => {
it('lifts expired disks that no metadata json names any more', async () => {
const root = await makeRoot()
try {
// Retention deletes the json first and leaves the disks to the next cleanVm, so nothing names
// them: this is the state the sentinel-driven pass cannot reach.
const { alias, vhdDir, blockFile } = await writeDisk(root, EXPIRED_DATE)
await Directory.makeImmutableBatch([alias, vhdDir])
assert.strictEqual(await Directory.isImmutable(alias), true, 'alias should start immutable')
assert.strictEqual(await Directory.isImmutable(vhdDir), true, 'VHD directory should start immutable')
await liftRemoteImmutability(root, ONE_DAY_MS, true)
assert.strictEqual(await Directory.isImmutable(alias), false, 'alias should be lifted')
assert.strictEqual(await Directory.isImmutable(vhdDir), false, 'VHD directory should be lifted')
// A VHD directory is useless to XO unless its blocks are writable too: the merge moves block
// files out of it.
assert.strictEqual(await Directory.isImmutable(blockFile), false, 'blocks should be lifted too')
// and the files are really usable again
await fs.unlink(blockFile)
await fs.unlink(alias)
} finally {
await cleanupRoot(root)
}
})
it('keeps disks inside the immutability window locked', async () => {
const root = await makeRoot()
try {
const { alias, vhdDir, blockFile } = await writeDisk(root, RECENT_DATE)
await Directory.makeImmutableBatch([alias, vhdDir])
await liftRemoteImmutability(root, ONE_DAY_MS, true)
assert.strictEqual(await Directory.isImmutable(alias), true, 'recent alias must stay immutable')
assert.strictEqual(await Directory.isImmutable(vhdDir), true, 'recent VHD directory must stay immutable')
assert.strictEqual(await Directory.isImmutable(blockFile), true, 'recent blocks must stay immutable')
await assert.rejects(fs.unlink(alias), { code: 'EPERM' })
} finally {
await cleanupRoot(root)
}
})
it('does not sweep the disk directories outside of a full scan', async () => {
const root = await makeRoot()
try {
const { alias, vhdDir } = await writeDisk(root, EXPIRED_DATE)
await Directory.makeImmutableBatch([alias, vhdDir])
await liftRemoteImmutability(root, ONE_DAY_MS, false)
assert.strictEqual(await Directory.isImmutable(alias), true, 'alias should be untouched')
assert.strictEqual(await Directory.isImmutable(vhdDir), true, 'VHD directory should be untouched')
} finally {
await cleanupRoot(root)
}
})
it('lifts a disk whose name does not match the datetime of the backup referencing it', async () => {
const root = await makeRoot()
try {
// Shape left by a merge: the alias of the recent backup points at the VHD directory of the
// older one, whose blocks it now holds.
const { vhdDir, blockFile } = await writeDisk(root, EXPIRED_DATE)
const alias = path.join(vdiDirOf(root), `${RECENT_DATE}.alias.vhd`)
await fs.writeFile(alias, path.relative(vdiDirOf(root), vhdDir))
await fs.unlink(path.join(vdiDirOf(root), `${EXPIRED_DATE}.alias.vhd`))
await Directory.makeImmutableBatch([alias, vhdDir])
await liftRemoteImmutability(root, ONE_DAY_MS, true)
// The VHD directory carries an expired datetime, so it is released and stays mergeable — the
// reason mtime cannot be the reference: every merge would push it forward and it would never
// expire.
assert.strictEqual(await Directory.isImmutable(vhdDir), false, 'merged VHD directory should be lifted')
assert.strictEqual(await Directory.isImmutable(blockFile), false, 'its blocks should be lifted')
assert.strictEqual(await Directory.isImmutable(alias), true, 'the recent alias keeps its lock')
} finally {
await cleanupRoot(root)
}
})
it('still lifts through the metadata json when it is present', async () => {
const root = await makeRoot()
try {
const { alias, vhdDir } = await writeDisk(root, EXPIRED_DATE)
const json = path.join(vmDirOf(root), `${EXPIRED_DATE}.json`)
await fs.writeFile(json, '{}')
await Directory.makeImmutableBatch([json, alias, vhdDir])
// not a full scan: the fast path applies, and the json is immutable so it is picked up
await liftRemoteImmutability(root, ONE_DAY_MS, false)
assert.strictEqual(await Directory.isImmutable(json), false, 'json should be lifted')
assert.strictEqual(await Directory.isImmutable(alias), false, 'alias should be lifted')
assert.strictEqual(await Directory.isImmutable(vhdDir), false, 'VHD directory should be lifted')
} finally {
await cleanupRoot(root)
}
})
})

View File

@@ -118,68 +118,6 @@ async function liftExpiredVmBackups(root: string, immutabilityDuration: number,
})
}
// `liftExpiredVmBackups` names the files of a backup from the datetime of its `<datetime>.json`,
// like the watcher does when locking them. A disk can outlive that name:
//
// - retention deletes the metadata json first and leaves the disks to the next `cleanVm`, so
// nothing names them any more;
// - a merge renames a disk, and the surviving `data/<datetime>.vhd` keeps the name of the older
// backup its blocks came from.
//
// Such a disk would stay immutable forever — a full scan does not help, it only bypasses the
// `isImmutable` fast-path — and an immutable disk blocks every future merge and deletion in its VDI
// directory. So walk the VDI directories themselves and lift what is expired, using the datetime in
// each entry's own name, which is the reference the other passes use too.
//
// Only runs on the first pass after startup: it recovers states that should not happen, and looking
// hourly would not make it more effective.
async function liftExpiredOrphanDisks(root: string, immutabilityDuration: number): Promise<void> {
const threshold = Date.now() - immutabilityDuration
const vmDirs = await listDirs(join(root, 'xo-vm-backups'))
debug('scanning VDI directories for expired disks', { count: vmDirs.length })
await asyncEach(vmDirs, async vmDir => {
// disks live under `vdis/<jobId>/<vdiId>/`, so two levels of directories to walk first
const jobDirs = await listDirs(join(vmDir, 'vdis'))
const vdiDirs = (await Promise.all(jobDirs.map(jobDir => listDirs(jobDir)))).flat()
await asyncEach(vdiDirs, async vdiDir => {
try {
// `<datetime>.vhd` (flat VHD or alias) and `<datetime>.alias.vhd`
const entries = await fsp.readdir(vdiDir, { withFileTypes: true })
const candidates = entries.map(entry => join(vdiDir, entry.name))
// `data/<datetime>.vhd` VHD directories. They are locked recursively, but the attribute is
// set on the directory itself too, so its own entry is enough to decide — no need to look
// at the blocks inside.
if (entries.some(entry => entry.name === 'data' && entry.isDirectory())) {
const dataDir = join(vdiDir, 'data')
candidates.push(...(await fsp.readdir(dataDir)).map(name => join(dataDir, name)))
}
const expired: string[] = []
for (const path of candidates) {
// Entries without a datetime — `data` itself, merge state files — are left alone: there
// is nothing to compare them to.
const datetime = extractDatetime(basename(path))
if (datetime === undefined) continue
const backupTimestamp = parseDatetime(datetime)
if (backupTimestamp === undefined || backupTimestamp > threshold) continue
expired.push(path)
}
if (expired.length === 0) return
debug('lifting expired disks', { vdiDir, count: expired.length })
// Recursive: a VHD directory must be released together with its blocks, and `-R` is a no-op
// on the flat VHDs and aliases sharing the batch.
await Directory.liftImmutabilityBatch(expired)
} catch (err) {
// `cleanVm` may be merging or deleting these files at the same time
if (err.code !== 'ENOENT') warn('error lifting expired disks', { err, vdiDir })
}
})
})
}
// Walk `xo-config-backups/<scheduleId>/<datetime>/metadata.json` files and
// lift immutability on any backup directory whose metadata mtime is expired.
async function liftExpiredConfigBackups(root: string, immutabilityDuration: number, fullScan: boolean): Promise<void> {
@@ -242,12 +180,6 @@ export async function liftRemoteImmutability(
liftExpiredConfigBackups(root, immutabilityDuration, fullScan),
liftExpiredPoolBackups(root, immutabilityDuration, fullScan),
])
// after the passes above: every disk still named by a metadata json has been handled, so this one
// only has the leftovers to look at
if (fullScan) {
await liftExpiredOrphanDisks(root, immutabilityDuration)
}
}
// Lift immutability on all expired backups across every configured remote.

View File

@@ -13,7 +13,6 @@ for (const [remoteId, remote] of Object.entries(remotes)) {
}
info('setup watcher for immutability lifting')
await liftImmutability(remotes).catch(error => warn('error while lifting immutability', error))
setInterval(async () => {
await liftImmutability(remotes).catch(error => warn('error while lifting immutability', error))
}, liftEvery)

View File

@@ -1,12 +1,10 @@
# ChangeLog
## **0.24.0** (2026-07-30)
## **next**
- [Host/dashboard] Switch CPU and RAM panels order to match Pool dashboard layout (PR [#10059](https://github.com/vatesfr/xen-orchestra/pull/10059))
- Remove all "coming soon" disabled button placeholders from network, VM, and pool components (PR [#10068](https://github.com/vatesfr/xen-orchestra/pull/10068))
- [VM/Network] add possibility to “connect/disconnect” a VIF on a VM (PR [#10080](https://github.com/vatesfr/xen-orchestra/pull/10080))
- [Pool/networks] Add the possibility to copy information from one or more networks in JSON format (PR [#10083](https://github.com/vatesfr/xen-orchestra/pull/10083))
- Fix some design inconsistency between pages (PR [#10109](https://github.com/vatesfr/xen-orchestra/pull/10109))
## **0.23.0** (2026-06-30)
@@ -20,7 +18,6 @@
- [SidePanels] Add and use new `VtsCardObjectTitle` component to display object title and ID in side panels (PR [#9755](https://github.com/vatesfr/xen-orchestra/pull/9755))
- Replacement of the UiSpinner component with UiLoader from web-core (PR [#10023](https://github.com/vatesfr/xen-orchestra/pull/10023))
- [Pool,Host/Storage] Add Storage tabs (PR [#10005](https://github.com/vatesfr/xen-orchestra/pull/10005))
- [Pool,Host/Storage] Storage repositories can now be connected, disconnected and deleted from the Storage tabs (PR [#10006](https://github.com/vatesfr/xen-orchestra/pull/10006))
## **0.22.0** (2026-05-28)

View File

@@ -1,6 +1,6 @@
{
"name": "@xen-orchestra/lite",
"version": "0.24.0",
"version": "0.23.0",
"type": "module",
"scripts": {
"dev": "GIT_HEAD=$(git rev-parse HEAD) vite",
@@ -28,13 +28,13 @@
"@types/file-saver": "^2.0.7",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18.19.80",
"@vates/types": "^1.30.1",
"@vates/types": "^1.28.0",
"@vitejs/plugin-vue": "^6.0.0",
"@vue/tsconfig": "^0.9.0",
"@vueuse/core": "^14.0.0",
"@vueuse/math": "^14.0.0",
"@vueuse/shared": "^14.0.0",
"@xen-orchestra/web-core": "^0.58.0",
"@xen-orchestra/web-core": "^0.56.0",
"complex-matcher": "^1.1.1",
"d3-time-format": "^4.1.0",
"decorator-synchronized": "^0.6.0",

View File

@@ -11,7 +11,8 @@
</main>
</div>
</div>
<VtsOverlayList />
<VtsModalList />
<VtsDrawerList />
<VtsTooltipList />
</template>
@@ -22,7 +23,8 @@ import AppNavigation from '@/components/AppNavigation.vue'
import { useUnreachableHosts } from '@/composables/unreachable-hosts.composable'
import { usePoolStore } from '@/stores/xen-api/pool.store'
import { useXenApiStore } from '@/stores/xen-api.store'
import VtsOverlayList from '@core/components/overlay/VtsOverlayList.vue'
import VtsDrawerList from '@core/components/drawer/VtsDrawerList.vue'
import VtsModalList from '@core/components/modal/VtsModalList.vue'
import VtsTooltipList from '@core/components/tooltip-list/VtsTooltipList.vue'
import { useChartTheme } from '@core/composables/chart-theme.composable'
import { useUiStore } from '@core/stores/ui.store'

View File

@@ -20,7 +20,8 @@ import UiActionButton from '@/components/ui/UiActionButton.vue'
import UiFilter from '@/components/ui/UiFilter.vue'
import UiFilterGroup from '@/components/ui/UiFilterGroup.vue'
import type { Filters } from '@/types/filter'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
const { availableFilters } = defineProps<{
@@ -35,25 +36,18 @@ const emit = defineEmits<{
const { t } = useI18n()
const { open } = useOverlay({
component: () => import('@/components/modals/CollectionFilterModal.vue'),
events: {
onCancel: true,
const openFilterModal = useModal((editedFilter?: string) => ({
component: import('@/components/modals/CollectionFilterModal.vue'),
props: {
editedFilter,
availableFilters: computed(() => availableFilters),
},
})
onConfirm: async newFilter => {
if (editedFilter !== undefined) {
emit('removeFilter', editedFilter)
}
function openFilterModal(editedFilter?: string) {
return open({
props: { editedFilter, availableFilters },
events: {
onConfirm: newFilter => {
if (editedFilter !== undefined) {
emit('removeFilter', editedFilter)
}
emit('addFilter', newFilter)
},
},
})
}
emit('addFilter', newFilter)
},
}))
</script>

View File

@@ -4,7 +4,7 @@
<div class="inputs">
<UiInput v-if="newFilter.isAdvanced" v-model="filterContent" accent="brand" class="advanced-input" />
<template v-else>
<VtsSelect :id="builderPropertySelectId" accent="brand" />
<VtsSelect :id="builderPropertySelectId" accent="brand" :icon="currentFilterIcon" />
<VtsSelect v-if="hasComparisonSelect" :id="builderComparisonSelectId" accent="brand" />
<VtsSelect v-if="currentFilter?.type === 'enum'" :id="builderValueSelectId" accent="brand" />
<UiInput v-else-if="hasValueInput" v-model="newFilter.builder.value" accent="brand" />
@@ -20,6 +20,7 @@
<script lang="ts" setup>
import UiActionButton from '@/components/ui/UiActionButton.vue'
import { buildComplexMatcherNode } from '@/libs/complex-matcher.utils'
import { getFilterIcon } from '@/libs/utils'
import type { Filter, FilterComparisons, FilterComparisonType, Filters, FilterType, NewFilter } from '@/types/filter'
import VtsSelect from '@core/components/select/VtsSelect.vue'
import UiInput from '@core/components/ui/input/UiInput.vue'
@@ -103,6 +104,8 @@ function getDefaultComparisonType(property: string) {
const currentFilter = computed<Filter | undefined>(() => availableFilters[builderProperty.value])
const currentFilterIcon = computed(() => getFilterIcon(currentFilter.value))
const hasValueInput = computed(() =>
currentFilter.value ? ['string', 'number'].includes(currentFilter.value?.type) : false
)

View File

@@ -24,7 +24,8 @@ import UiFilter from '@/components/ui/UiFilter.vue'
import UiFilterGroup from '@/components/ui/UiFilterGroup.vue'
import type { ActiveSorts, Sorts } from '@/types/sort'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
const { availableSorts } = defineProps<{
@@ -40,17 +41,11 @@ const emit = defineEmits<{
const { t } = useI18n()
const { open } = useOverlay({
component: () => import('@/components/modals/CollectionSorterModal.vue'),
events: {
onConfirm: ({ property, isAscending }) => emit('addSort', property as TProperty, isAscending),
onCancel: true,
},
const openFormModal = useModal({
component: import('@/components/modals/CollectionSorterModal.vue'),
props: { availableSorts: computed(() => availableSorts) },
onConfirm: ({ property, isAscending }) => emit('addSort', property as TProperty, isAscending),
})
function openFormModal() {
return open({ props: { availableSorts } })
}
</script>
<style lang="postcss" scoped>

View File

@@ -87,7 +87,7 @@ import useSortedCollection from '@/composables/sorted-collection.composable'
import type { PropParam } from '@/libs/story/story-param'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import { vTooltip } from '@core/directives/tooltip.directive'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { useVModel } from '@vueuse/core'
import { toRef } from 'vue'
@@ -111,16 +111,10 @@ const params = useSortedCollection(toRef(props, 'params'), (p1, p2) => {
const model = useVModel(props, 'modelValue', emit)
const { open } = useOverlay({
component: () => import('@/components/modals/CodeHighlightModal.vue'),
events: {
onClose: true,
},
})
function openRawValueModal(code: string) {
return open({ props: { code } })
}
const openRawValueModal = useModal((code: string) => ({
component: import('@/components/modals/CodeHighlightModal.vue'),
props: { code },
}))
</script>
<style lang="postcss" scoped>

View File

@@ -4,7 +4,7 @@
<script lang="ts" setup>
import FormInput from '@/components/form/FormInput.vue'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { useVModel } from '@vueuse/core'
import { computed } from 'vue'
@@ -20,17 +20,11 @@ const model = useVModel(props, 'modelValue', emit)
const jsonValue = computed(() => JSON.stringify(model.value, undefined, 2))
const { open } = useOverlay({
component: () => import('@/components/modals/JsonEditorModal.vue'),
events: {
onConfirm: (newValue: string) => {
model.value = JSON.parse(newValue)
},
onCancel: true,
const openJsonModal = useModal({
component: import('@/components/modals/JsonEditorModal.vue'),
props: { initialValue: computed(() => jsonValue.value) },
onConfirm: newValue => {
model.value = JSON.parse(newValue)
},
})
function openJsonModal() {
return open({ props: { initialValue: jsonValue.value } })
}
</script>

View File

@@ -91,7 +91,6 @@
</template>
<template #addons>
<VtsCopyButton :value="ip" />
<VtsCopyAllMenuItem v-if="index === 0 && ipAddresses.length > 1" :values="ipAddresses" />
</template>
</VtsCardRowKeyValue>
</div>
@@ -175,7 +174,6 @@
</template>
<template v-if="device" #addons>
<VtsCopyButton :value="device" />
<VtsCopyAllMenuItem v-if="index === 0 && bondDevices.length > 1" :values="bondDevicesFiltered" />
</template>
</VtsCardRowKeyValue>
</div>
@@ -231,7 +229,6 @@ import { usePifMetricsStore } from '@/stores/xen-api/pif-metrics.store'
import { usePifStore } from '@/stores/xen-api/pif.store'
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
import VtsCardObjectTitle from '@core/components/card-object-title/VtsCardObjectTitle.vue'
import VtsCopyAllMenuItem from '@core/components/copy-all-menu-item/VtsCopyAllMenuItem.vue'
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
@@ -294,10 +291,6 @@ const ipConfigurationMode = computed(() => {
const bondDevices = computed(() => (pif !== undefined ? getBondsDevices(pif) : []))
const bondDevicesFiltered = computed(() => {
return bondDevices.value.filter((bondDevice): bondDevice is string => bondDevice !== undefined)
})
const isBond = computed(() => (pif !== undefined ? isBondMaster(pif) : false))
const speed = computed(() => {

View File

@@ -1,20 +1,16 @@
<template>
<UiModal accent="info" @dismiss="emit('close')">
<VtsModal accent="info" dismissible>
<template #content>
<CodeHighlight :code />
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import CodeHighlight from '@/components/CodeHighlight.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
defineProps<{
code: any
}>()
const emit = defineEmits<{
close: []
}>()
</script>

View File

@@ -1,5 +1,5 @@
<template>
<UiModal accent="info" @dismiss="emit('cancel')" @confirm="emit('confirm', generatedFilter)">
<VtsModal accent="info" dismissible @confirm="emit('confirm', generatedFilter)">
<template #content>
<div class="rows">
<CollectionFilterRow
@@ -10,9 +10,9 @@
@remove="removeNewFilter($event)"
/>
<div>
<VtsOverlayButton variant="tertiary" @click="addNewFilter()">
<VtsModalButton variant="tertiary" @click="addNewFilter()">
{{ t('add-or') }}
</VtsOverlayButton>
</VtsModalButton>
</div>
</div>
<div v-if="newFilters.some(filter => filter.isAdvanced)" class="available-properties">
@@ -25,12 +25,12 @@
</div>
</template>
<template #buttons>
<VtsOverlayCancelButton @click="emit('cancel')" />
<VtsOverlayConfirmButton :disabled="!isFilterValid">
<VtsModalCancelButton />
<VtsModalConfirmButton :disabled="!isFilterValid">
{{ editedFilter ? t('action:update') : t('action:add') }}
</VtsOverlayConfirmButton>
</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
@@ -38,10 +38,10 @@ import CollectionFilterRow from '@/components/CollectionFilterRow.vue'
import UiBadge from '@/components/ui/UiBadge.vue'
import { getFilterIcon } from '@/libs/utils'
import type { Filters, NewFilter } from '@/types/filter'
import VtsOverlayButton from '@core/components/overlay/VtsOverlayButton.vue'
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalButton from '@core/components/modal/VtsModalButton.vue'
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import { Or, parse } from 'complex-matcher'
import { computed, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -53,7 +53,6 @@ const { editedFilter } = defineProps<{
const emit = defineEmits<{
confirm: [filter: string]
cancel: []
}>()
const { t } = useI18n()

View File

@@ -1,5 +1,5 @@
<template>
<UiModal accent="info" @dismiss="emit('cancel')" @confirm="handleSubmit()">
<VtsModal accent="info" dismissible @confirm="handleSubmit()">
<template #content>
<div class="form-selects">
<VtsSelect :id="sortPropertySelectId" accent="brand" />
@@ -8,18 +8,18 @@
</template>
<template #buttons>
<VtsOverlayCancelButton @click="emit('cancel')" />
<VtsOverlayConfirmButton :disabled="!newSortProperty">{{ t('action:add') }}</VtsOverlayConfirmButton>
<VtsModalCancelButton />
<VtsModalConfirmButton :disabled="!newSortProperty">{{ t('action:add') }}</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import type { NewSort, Sorts } from '@/types/sort'
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import VtsSelect from '@core/components/select/VtsSelect.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import { useFormSelect } from '@core/packages/form-select'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -30,7 +30,6 @@ const { availableSorts } = defineProps<{
const emit = defineEmits<{
confirm: [sort: NewSort]
cancel: []
}>()
const { t } = useI18n()

View File

@@ -1,27 +1,23 @@
<template>
<UiModal accent="danger" icon="fa:exclamation-circle" @dismiss="emit('close')" @confirm="emit('close')">
<VtsModal accent="danger" dismissible icon="fa:exclamation-circle">
<template #title>{{ t('invalid-field') }}</template>
<template #content>{{ message }}</template>
<template #buttons>
<VtsOverlayConfirmButton>
<VtsModalConfirmButton>
{{ t('ok') }}
</VtsOverlayConfirmButton>
</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import { useI18n } from 'vue-i18n'
defineProps<{
message: string
}>()
const emit = defineEmits<{
close: []
}>()
const { t } = useI18n()
</script>

View File

@@ -1,32 +1,31 @@
<template>
<UiModal
<VtsModal
:accent="isJsonValid ? 'info' : 'danger'"
class="json-editor-modal"
icon="fa:code"
@confirm="handleSubmit()"
@dismiss="emit('cancel')"
>
<template #content>
<UiTextarea v-model="editedJson" accent="brand" class="modal-textarea" />
<VtsOverlayButton variant="tertiary" @click="formatJson()">
<VtsModalButton variant="tertiary" @click="formatJson()">
{{ t('action:reformat') }}
</VtsOverlayButton>
</VtsModalButton>
</template>
<template #buttons>
<VtsOverlayCancelButton @click="emit('cancel')" />
<VtsOverlayConfirmButton :disabled="!isJsonValid">
<VtsModalCancelButton />
<VtsModalConfirmButton :disabled="!isJsonValid">
{{ t('action:save') }}
</VtsOverlayConfirmButton>
</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import VtsOverlayButton from '@core/components/overlay/VtsOverlayButton.vue'
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalButton from '@core/components/modal/VtsModalButton.vue'
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import UiTextarea from '@core/components/ui/text-area/UiTextarea.vue'
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -37,7 +36,6 @@ const { initialValue } = defineProps<{
const emit = defineEmits<{
confirm: [editedJson: string]
cancel: []
}>()
const { t } = useI18n()

View File

@@ -1,5 +1,5 @@
<template>
<UiModal accent="danger" icon="object:host" @confirm="emit('confirm')">
<VtsModal accent="danger" icon="object:host">
<template #title>{{ t('unreachable-hosts') }}</template>
<template #content>
<div class="description">
@@ -13,30 +13,25 @@
</div>
</template>
<template #buttons>
<VtsOverlayCancelButton @click="emit('cancel')" />
<VtsOverlayConfirmButton>
<VtsModalCancelButton />
<VtsModalConfirmButton>
{{ t('unreachable-hosts-reload-page') }}
</VtsOverlayConfirmButton>
</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import UiLink from '@core/components/ui/link/UiLink.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import { useI18n } from 'vue-i18n'
defineProps<{
urls: string[]
}>()
const emit = defineEmits<{
confirm: []
cancel: []
}>()
const { t } = useI18n()
</script>

View File

@@ -0,0 +1,22 @@
<template>
<VtsDeleteModal>
<template #title>
{{ t('n-vms', { n: count }) }}
</template>
<template #confirm>
{{ t(`action:delete-n-vms`, { n: count }) }}
</template>
</VtsDeleteModal>
</template>
<script lang="ts" setup>
import VtsDeleteModal from '@core/components/modal/VtsDeleteModal.vue'
import { useI18n } from 'vue-i18n'
defineProps<{
count: number
}>()
const { t } = useI18n()
</script>

View File

@@ -1,5 +1,5 @@
<template>
<UiModal accent="info" icon="object:vm" @confirm="emit('close')" @dismiss="emit('close')">
<VtsModal accent="info" icon="object:vm">
<template #title>
{{ t('action:export-n-vms-manually', { n: labelWithUrl.length }) }}
</template>
@@ -18,16 +18,16 @@
</template>
<template #buttons>
<VtsOverlayConfirmButton>{{ t('action:close') }}</VtsOverlayConfirmButton>
<VtsModalConfirmButton>{{ t('action:close') }}</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
import { useVmStore } from '@/stores/xen-api/vm.store'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -35,10 +35,6 @@ const { blockedUrls } = defineProps<{
blockedUrls: URL[]
}>()
const emit = defineEmits<{
close: []
}>()
const { t } = useI18n()
const { getByOpaqueRef } = useVmStore().subscribe()

View File

@@ -1,5 +1,5 @@
<template>
<UiModal accent="info" icon="object:vm" @confirm="emit('confirm', compressionType)" @dismiss="emit('cancel')">
<VtsModal accent="info" icon="object:vm" @confirm="emit('confirm', compressionType)">
<template #title>
{{ t('action:export-n-vms', { n: count }) }}
</template>
@@ -12,21 +12,21 @@
</VtsInputWrapper>
</template>
<template #buttons>
<VtsOverlayCancelButton @click="emit('cancel')" />
<VtsOverlayConfirmButton>
<VtsModalCancelButton />
<VtsModalConfirmButton>
{{ t('action:export-n-vms', { n: count }) }}
</VtsOverlayConfirmButton>
</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums'
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import VtsSelect from '@core/components/select/VtsSelect.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import { useFormSelect } from '@core/packages/form-select'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -37,7 +37,6 @@ defineProps<{
const emit = defineEmits<{
confirm: [compressionType: VM_COMPRESSION_TYPE]
cancel: []
}>()
const { t } = useI18n()

View File

@@ -1,5 +1,5 @@
<template>
<UiModal accent="info" @confirm="emit('confirm', selectedHost)" @dismiss="emit('cancel')">
<VtsModal accent="info" @confirm="emit('confirm', selectedHost)">
<template #title>
{{ t('action:migrate-n-vms', { n: count }) }}
</template>
@@ -13,21 +13,21 @@
</template>
<template #buttons>
<VtsOverlayCancelButton @click="emit('cancel')" />
<VtsOverlayConfirmButton :disabled="!selectedHost">
<VtsModalCancelButton />
<VtsModalConfirmButton :disabled="!selectedHost">
{{ t('action:migrate-n-vms', { n: count }) }}
</VtsOverlayConfirmButton>
</VtsModalConfirmButton>
</template>
</UiModal>
</VtsModal>
</template>
<script lang="ts" setup>
import type { XenApiHost } from '@/libs/xen-api/xen-api.types'
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
import VtsModal from '@core/components/modal/VtsModal.vue'
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
import VtsSelect from '@core/components/select/VtsSelect.vue'
import UiModal from '@core/components/ui/modal/UiModal.vue'
import { useFormSelect } from '@core/packages/form-select'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -39,7 +39,6 @@ const { availableHosts } = defineProps<{
const emit = defineEmits<{
confirm: [selectedHost: XenApiHost | undefined]
cancel: []
}>()
const selectedHost = ref<XenApiHost>()

View File

@@ -2,17 +2,17 @@
<UiHeadBar icon="object:pool">
{{ name }}
<template #actions>
<UiLink size="medium" :to="{ name: '/vm/new' }" icon="fa:plus">
{{ t('new-vm') }}
</UiLink>
<RouterLink :to="{ name: '/vm/new' }">
<UiButton left-icon="fa:plus" variant="secondary" accent="brand" size="medium">{{ t('new-vm') }}</UiButton>
</RouterLink>
</template>
</UiHeadBar>
</template>
<script lang="ts" setup>
import { usePoolStore } from '@/stores/xen-api/pool.store'
import UiButton from '@core/components/ui/button/UiButton.vue'
import UiHeadBar from '@core/components/ui/head-bar/UiHeadBar.vue'
import UiLink from '@core/components/ui/link/UiLink.vue'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

View File

@@ -1,22 +1,5 @@
<template>
<VtsSidePanel :has-selection="!!network" @close="emit('close')">
<template v-if="network" #actions>
<MenuList placement="bottom-end">
<template #trigger="{ open, isOpen }">
<UiButtonIcon
v-tooltip="copied && t('copied')"
accent="brand"
size="small"
:icon="copied ? 'fa:check-circle' : 'action:more-actions'"
:selected="isOpen"
@click="open($event)"
/>
</template>
<MenuItem icon="action:copy" :disabled="!isClipboardSupported" @click="copy()">
{{ t('action:copy-info-json') }}
</MenuItem>
</MenuList>
</template>
<template v-if="network" #default>
<UiCard class="card-container">
<VtsCardObjectTitle :id="network.uuid" :label="network.name_label" />
@@ -95,19 +78,14 @@
<script setup lang="ts">
import PifRow from '@/components/pif/PifRow.vue'
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types.ts'
import { usePifStore } from '@/stores/xen-api/pif.store.ts'
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types'
import { usePifStore } from '@/stores/xen-api/pif.store'
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
import VtsCardObjectTitle from '@core/components/card-object-title/VtsCardObjectTitle.vue'
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
import MenuItem from '@core/components/menu/MenuItem.vue'
import MenuList from '@core/components/menu/MenuList.vue'
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
import UiCard from '@core/components/ui/card/UiCard.vue'
import UiCounter from '@core/components/ui/counter/UiCounter.vue'
import { vTooltip } from '@core/directives/tooltip.directive.ts'
import { useClipboard } from '@vueuse/core'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -140,10 +118,6 @@ const networkDefaultLockingMode = computed(() =>
)
const pifsCount = computed(() => pifs.value.length)
const networkAsJson = computed(() => JSON.stringify(network))
const { copy, copied, isSupported: isClipboardSupported } = useClipboard({ source: networkAsJson, legacy: true })
</script>
<style scoped lang="postcss">

View File

@@ -4,28 +4,10 @@
{{ t('networks') }}
</UiTitle>
<div class="container">
<div class="table-actions">
<UiQuerySearchBar @search="value => (searchQuery = value)" />
<UiTableActions :title="t('table-actions')">
<UiButton
v-tooltip="copied && t('copied')"
:disabled="!isClipboardSupported"
:left-icon="copied ? 'fa:check-circle' : 'action:copy'"
variant="tertiary"
accent="brand"
size="medium"
@click="selectedNetworkIds.length > 0 && copy()"
>
{{ t('action:copy-info-json') }}
</UiButton>
</UiTableActions>
</div>
<UiQuerySearchBar @search="value => (searchQuery = value)" />
<VtsTable :state :pagination-bindings sticky="right">
<thead>
<tr>
<VtsHeaderCell>
<UiCheckbox v-model="areAllNetworksSelected" accent="brand" />
</VtsHeaderCell>
<HeadCells />
</tr>
</thead>
@@ -35,9 +17,6 @@
:key="network.uuid"
:selected="selectedNetworkId === network.uuid"
>
<UiTableCell>
<UiCheckbox v-model="selectedNetworkIds" :value="network.uuid" accent="brand" />
</UiTableCell>
<BodyCells :item="network" />
</VtsRow>
</tbody>
@@ -47,26 +26,18 @@
</template>
<script setup lang="ts">
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types.ts'
import { useNetworkStore } from '@/stores/xen-api/network.store.ts'
import { usePifMetricsStore } from '@/stores/xen-api/pif-metrics.store.ts'
import { usePifStore } from '@/stores/xen-api/pif.store.ts'
import VtsHeaderCell from '@core/components/table/cells/VtsHeaderCell.vue'
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types'
import { useNetworkStore } from '@/stores/xen-api/network.store'
import { usePifMetricsStore } from '@/stores/xen-api/pif-metrics.store'
import { usePifStore } from '@/stores/xen-api/pif.store'
import VtsRow from '@core/components/table/VtsRow.vue'
import VtsTable from '@core/components/table/VtsTable.vue'
import UiButton from '@core/components/ui/button/UiButton.vue'
import UiCheckbox from '@core/components/ui/checkbox/UiCheckbox.vue'
import UiQuerySearchBar from '@core/components/ui/query-search-bar/UiQuerySearchBar.vue'
import UiTableActions from '@core/components/ui/table-actions/UiTableActions.vue'
import UiTableCell from '@core/components/ui/table-cell/UiTableCell.vue'
import UiTitle from '@core/components/ui/title/UiTitle.vue'
import { usePagination } from '@core/composables/pagination.composable.ts'
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
import useMultiSelect from '@core/composables/table/multi-select.composable.ts'
import { useTableState } from '@core/composables/table-state.composable.ts'
import { vTooltip } from '@core/directives/tooltip.directive.ts'
import { useNetworkColumns } from '@core/tables/column-sets/network-columns.ts'
import { useClipboard } from '@vueuse/core'
import { usePagination } from '@core/composables/pagination.composable'
import { useRouteQuery } from '@core/composables/route-query.composable'
import { useTableState } from '@core/composables/table-state.composable'
import { useNetworkColumns } from '@core/tables/column-sets/network-columns'
import { logicNot } from '@vueuse/math'
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -128,26 +99,6 @@ const filteredNetworks = computed(() => {
const { pageRecords: paginatedNetworks, paginationBindings } = usePagination('networks', filteredNetworks)
const { selected: selectedNetworkIds, areAllSelected: areAllNetworksSelected } = useMultiSelect(
computed(() => networks.map(network => network.uuid)),
computed(() => paginatedNetworks.value.map(network => network.uuid))
)
const selectedNetworksAsJson = computed(() => {
const selectedNetworks = networks.filter(network => selectedNetworkIds.value.includes(network.uuid))
return JSON.stringify(selectedNetworks)
})
const {
copy,
copied,
isSupported: isClipboardSupported,
} = useClipboard({
source: selectedNetworksAsJson,
legacy: true,
})
const state = useTableState({
busy: logicNot(isReady),
error: hasError,

View File

@@ -3,7 +3,7 @@
v-tooltip="!areAllSelectedVmsHalted && t(isSingleAction ? 'vm-is-running' : 'selected-vms-in-execution')"
:busy="areSomeSelectedVmsCloning"
:disabled="isDisabled"
icon="action:duplicate"
icon="fa:copy"
@click="handleCopy"
>
{{ t('action:copy') }}

View File

@@ -3,7 +3,7 @@
v-tooltip="areSomeVmsInExecution && t('selected-vms-in-execution')"
:disabled="isDisabled"
icon="fa:trash"
@click="openDeleteModal()"
@click="openDeleteModal"
>
{{ t('action:delete') }}
</MenuItem>
@@ -15,8 +15,8 @@ import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
import { useVmStore } from '@/stores/xen-api/vm.store'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import MenuItem from '@core/components/menu/MenuItem.vue'
import { useDeleteModal } from '@core/composables/modals/use-delete-modal.ts'
import { vTooltip } from '@core/directives/tooltip.directive'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -36,15 +36,9 @@ const isDisabled = computed(() => vms.value.length === 0 || areSomeVmsInExecutio
const xenApi = useXenApiStore().getXapi()
const { open: openModal } = useDeleteModal()
function openDeleteModal() {
return openModal({
events: { onConfirm: () => xenApi.vm.delete(vmRefs) },
props: {
subject: t('n-vms', { n: vmRefs.length }),
confirmLabel: t('action:delete-n-vms', { n: vmRefs.length }),
},
})
}
const openDeleteModal = useModal({
component: import('@/components/modals/VmDeleteModal.vue'),
props: { count: computed(() => vmRefs.length) },
onConfirm: () => xenApi.vm.delete(vmRefs),
})
</script>

View File

@@ -4,23 +4,23 @@
vmRefs.length > 0 && !isSomeExportable && t(isSingleAction ? 'vm-is-running' : 'no-selected-vm-can-be-exported')
"
:disabled="isDisabled"
icon="action:download"
@click="openExportModal()"
icon="object:vm"
@click="openExportModal"
>
{{ t('action:export-vm', isSingleAction ? 1 : 2) }}
</MenuItem>
</template>
<script lang="ts" setup>
import { useVmExport } from '@/composables/vm-export.composable.ts'
import { areSomeVmOperationAllowed } from '@/libs/vm'
import { VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
import { useVmStore } from '@/stores/xen-api/vm.store'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import MenuItem from '@core/components/menu/MenuItem.vue'
import { useDisabled } from '@core/composables/disabled.composable'
import { vTooltip } from '@core/directives/tooltip.directive'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -39,17 +39,13 @@ const isSomeExportable = computed(() =>
const isDisabled = useDisabled(() => !isSomeExportable.value)
const { exportVms } = useVmExport()
const xenApi = useXenApiStore().getXapi()
const { open: openModal } = useOverlay({
component: () => import('@/components/modals/VmExportModal.vue'),
events: {
onConfirm: compressionType => exportVms(vmRefs, compressionType),
onCancel: true,
},
const openModal = useModal()
const openExportModal = useModal({
component: import('@/components/modals/VmExportModal.vue'),
props: { count: computed(() => vmRefs.length) },
onConfirm: compressionType => xenApi.vm.export(vmRefs, compressionType, openModal),
})
function openExportModal() {
return openModal({ props: { count: vmRefs.length } })
}
</script>

View File

@@ -23,9 +23,8 @@ import { useVmStore } from '@/stores/xen-api/vm.store'
import MenuItem from '@core/components/menu/MenuItem.vue'
import { useDisabled } from '@core/composables/disabled.composable'
import { vTooltip } from '@core/directives/tooltip.directive'
import { KEEP_OVERLAY_OPEN } from '@core/packages/overlay/symbols.ts'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { reactiveComputed } from '@vueuse/core'
import { ABORT_MODAL } from '@core/packages/modal/types.ts'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -54,28 +53,20 @@ const isDisabled = useDisabled(() => !isMigratable.value)
const { selectedHost, availableHosts, isValid, migrate } = useVmMigration(() => selectedRefs)
const { open: openModal } = useOverlay({
component: () => import('@/components/modals/VmMigrateModal.vue'),
events: {
onConfirm: async host => {
selectedHost.value = host
const openMigrateModal = useModal({
component: import('@/components/modals/VmMigrateModal.vue'),
props: {
count: computed(() => selectedRefs.length),
availableHosts,
},
onConfirm: async host => {
selectedHost.value = host
if (!isValid.value) {
return KEEP_OVERLAY_OPEN
}
if (!isValid.value) {
return ABORT_MODAL
}
await migrate()
},
onCancel: true,
await migrate()
},
})
const modalProps = reactiveComputed(() => ({
count: selectedRefs.length,
availableHosts: availableHosts.value,
}))
function openMigrateModal() {
return openModal({ props: modalProps })
}
</script>

View File

@@ -25,7 +25,7 @@
<MenuItem
:busy="areVmsBusyToResume"
:disabled="!areVmsSuspended && !areVmsPaused"
icon="fa:play"
icon="fa:circle-play"
@click="xenApi.vm.resume(vmRefsWithPowerState)"
>
{{ t('action:resume') }}
@@ -33,7 +33,7 @@
<MenuItem
:busy="areVmsBusyToReboot"
:disabled="!areVmsRunning"
icon="action:reboot"
icon="fa:rotate-left"
@click="xenApi.vm.reboot(vmRefs)"
>
{{ t('action:reboot') }}
@@ -41,7 +41,7 @@
<MenuItem
:busy="areVmsBusyToForceReboot"
:disabled="!areVmsRunning && !areVmsPaused"
icon="action:force-reboot"
icon="fa:repeat"
@click="xenApi.vm.reboot(vmRefs, true)"
>
{{ t('action:force-reboot') }}
@@ -49,7 +49,7 @@
<MenuItem
:busy="areVmsBusyToShutdown"
:disabled="!areVmsRunning"
icon="action:shutdown"
icon="fa:power-off"
@click="xenApi.vm.shutdown(vmRefs)"
>
{{ t('action:shutdown') }}
@@ -57,7 +57,7 @@
<MenuItem
:busy="areVmsBusyToForceShutdown"
:disabled="!areVmsRunning && !areVmsSuspended && !areVmsPaused"
icon="action:force-shutdown"
icon="fa:plug"
@click="xenApi.vm.shutdown(vmRefs, true)"
>
{{ t('action:force-shutdown') }}

View File

@@ -1,27 +1,36 @@
<template>
<UiHeadBar icon="object:vm">
{{ vm?.name_label }}
<template #icon>
<VtsObjectIcon size="medium" :state="toLower(vm?.power_state)" type="vm" />
</template>
<TitleBar icon="object:vm">
{{ name }}
<template #actions>
<MenuList v-if="vm !== undefined" placement="bottom-start">
<template #trigger="{ open }">
<UiDropdownButton @click="open($event)">{{ t('action:change-state') }}</UiDropdownButton>
<MenuList v-if="vm !== undefined" placement="bottom-end">
<template #trigger="{ open, isOpen }">
<UiButton
size="medium"
accent="brand"
variant="primary"
:class="{ pressed: isOpen }"
left-icon="fa:power-off"
@click="open"
>
{{ t('action:change-state') }}
<VtsIcon name="fa:angle-down" size="medium" />
</UiButton>
</template>
<VmActionPowerStateItems :vm-refs="[vm.$ref]" />
</MenuList>
<MenuList v-if="vm !== undefined" placement="bottom-end">
<template #trigger="{ open }">
<template #trigger="{ open, isOpen }">
<UiButtonIcon
v-tooltip="{
placement: 'left',
content: t('more-actions'),
}"
:selected="isOpen"
icon="action:more-actions-vertical"
accent="brand"
class="more-actions-button"
size="medium"
@click="open($event)"
@click="open"
/>
</template>
<VmActionCopyItem :selected-refs="[vm.$ref]" is-single-action />
@@ -30,10 +39,11 @@
<VmActionMigrateItem :selected-refs="[vm.$ref]" is-single-action />
</MenuList>
</template>
</UiHeadBar>
</TitleBar>
</template>
<script lang="ts" setup>
import TitleBar from '@/components/TitleBar.vue'
import VmActionCopyItem from '@/components/vm/VmActionItems/VmActionCopyItem.vue'
import VmActionExportItem from '@/components/vm/VmActionItems/VmActionExportItem.vue'
import VmActionMigrateItem from '@/components/vm/VmActionItems/VmActionMigrateItem.vue'
@@ -41,13 +51,11 @@ import VmActionPowerStateItems from '@/components/vm/VmActionItems/VmActionPower
import VmActionSnapshotItem from '@/components/vm/VmActionItems/VmActionSnapshotItem.vue'
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
import { useVmStore } from '@/stores/xen-api/vm.store'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import MenuList from '@core/components/menu/MenuList.vue'
import VtsObjectIcon from '@core/components/object-icon/VtsObjectIcon.vue'
import UiButton from '@core/components/ui/button/UiButton.vue'
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
import UiDropdownButton from '@core/components/ui/dropdown-button/UiDropdownButton.vue'
import UiHeadBar from '@core/components/ui/head-bar/UiHeadBar.vue'
import { vTooltip } from '@core/directives/tooltip.directive'
import { toLower } from 'lodash-es'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
@@ -58,4 +66,6 @@ const { getByUuid: getVmByUuid } = useVmStore().subscribe()
const route = useRoute<'/vm/[uuid]'>()
const vm = computed(() => getVmByUuid(route.params.uuid as XenApiVm['uuid']))
const name = computed(() => vm.value?.name_label)
</script>

View File

@@ -51,15 +51,16 @@
import CollectionFilter from '@/components/CollectionFilter.vue'
import CollectionSorter from '@/components/CollectionSorter.vue'
import VmsActionsBar from '@/components/vm/VmsActionsBar.vue'
import useCollectionFilter from '@/composables/collection-filter.composable.ts'
import useCollectionSorter from '@/composables/collection-sorter.composable.ts'
import type { XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
import { usePageTitleStore } from '@/stores/page-title.store.ts'
import { useVbdStore } from '@/stores/xen-api/vbd.store.ts'
import { useVdiStore } from '@/stores/xen-api/vdi.store.ts'
import { useVmGuestMetricsStore } from '@/stores/xen-api/vm-guest-metrics.store.ts'
import { useVmMetricsStore } from '@/stores/xen-api/vm-metrics.store.ts'
import type { Filters } from '@/types/filter.ts'
import useCollectionFilter from '@/composables/collection-filter.composable'
import useCollectionSorter from '@/composables/collection-sorter.composable'
import useMultiSelect from '@/composables/multi-select.composable'
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
import { usePageTitleStore } from '@/stores/page-title.store'
import { useVbdStore } from '@/stores/xen-api/vbd.store'
import { useVdiStore } from '@/stores/xen-api/vdi.store'
import { useVmGuestMetricsStore } from '@/stores/xen-api/vm-guest-metrics.store'
import { useVmMetricsStore } from '@/stores/xen-api/vm-metrics.store'
import type { Filters } from '@/types/filter'
import VtsHeaderCell from '@core/components/table/cells/VtsHeaderCell.vue'
import VtsRow from '@core/components/table/VtsRow.vue'
import VtsTable from '@core/components/table/VtsTable.vue'
@@ -67,15 +68,14 @@ import UiCard from '@core/components/ui/card/UiCard.vue'
import UiCheckbox from '@core/components/ui/checkbox/UiCheckbox.vue'
import UiTableCell from '@core/components/ui/table-cell/UiTableCell.vue'
import UiTitle from '@core/components/ui/title/UiTitle.vue'
import { usePagination } from '@core/composables/pagination.composable.ts'
import useMultiSelect from '@core/composables/table/multi-select.composable.ts'
import { useTableState } from '@core/composables/table-state.composable.ts'
import { usePagination } from '@core/composables/pagination.composable'
import { useTableState } from '@core/composables/table-state.composable'
import { objectIcon } from '@core/icons'
import { useUiStore } from '@core/stores/ui.store.ts'
import { useVmColumns } from '@core/tables/column-sets/vm-columns.ts'
import { renderBodyCell } from '@core/tables/helpers/render-body-cell.ts'
import { renderLoadingCell } from '@core/tables/helpers/render-loading-cell.ts'
import { formatSizeRaw } from '@core/utils/size.util.ts'
import { useUiStore } from '@core/stores/ui.store'
import { useVmColumns } from '@core/tables/column-sets/vm-columns'
import { renderBodyCell } from '@core/tables/helpers/render-body-cell'
import { renderLoadingCell } from '@core/tables/helpers/render-loading-cell'
import { formatSizeRaw } from '@core/utils/size.util'
import { VM_POWER_STATE } from '@vates/types'
import { useSorted } from '@vueuse/core'
import { useArrayFilter } from '@vueuse/shared'

View File

@@ -76,7 +76,6 @@
<template #value>{{ ip }}</template>
<template #addons>
<VtsCopyButton :value="ip" />
<VtsCopyAllMenuItem v-if="index === 0 && ipAddresses.length > 1" :values="ipAddresses" />
</template>
</VtsCardRowKeyValue>
</div>
@@ -114,7 +113,6 @@ import { useVmGuestMetricsStore } from '@/stores/xen-api/vm-guest-metrics.store'
import { useVmStore } from '@/stores/xen-api/vm.store'
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
import VtsCardObjectTitle from '@core/components/card-object-title/VtsCardObjectTitle.vue'
import VtsCopyAllMenuItem from '@core/components/copy-all-menu-item/VtsCopyAllMenuItem.vue'
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
import VtsStatus from '@core/components/status/VtsStatus.vue'

View File

@@ -25,7 +25,7 @@
<script lang="ts" setup>
import type { XenApiNetwork, XenApiVif, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
import { useVifConnection } from '@/modules/vif/composables/use-vif-connection.composable.ts'
import { useVifConnectionToggleModal } from '@/modules/vif/composables/use-vif-connection-toggle-modal.composable.ts'
import { useNetworkStore } from '@/stores/xen-api/network.store'
import { useVifStore } from '@/stores/xen-api/vif.store'
import { useVmGuestMetricsStore } from '@/stores/xen-api/vm-guest-metrics.store'
@@ -36,8 +36,6 @@ import UiTitle from '@core/components/ui/title/UiTitle.vue'
import { usePagination } from '@core/composables/pagination.composable'
import { useRouteQuery } from '@core/composables/route-query.composable'
import { useTableState } from '@core/composables/table-state.composable'
import { useMapper } from '@core/packages/mapper'
import { type ActionItem } from '@core/tables/column-definitions/action-column.ts'
import { useVifColumns } from '@core/tables/column-sets/vif-columns'
import { CONNECTION_ACTION } from '@core/types/connection.ts'
import { getUniqueIpAddressesForDevice } from '@core/utils/ip-address.utils.ts'
@@ -97,40 +95,14 @@ const { HeadCells, BodyCells } = useVifColumns({
const ipAddresses = computed(() => getIpAddresses(vif))
const {
connectVifs,
disconnectVifs,
canConnectVifs,
canDisconnectVifs,
isConnectingVifs,
isDisconnectingVifs,
connectVifsErrorMessage,
disconnectVifsErrorMessage,
} = useVifConnection({
vifs: () => [vif],
vm: () => vm,
})
const connectionAction = useMapper(
openModal: openVifConnectionToggleModal,
canRun: canToggleVifConnection,
isRunning: isTogglingVifConnection,
errorMessage: toggleConnectionErrorMessage,
} = useVifConnectionToggleModal(
() => (vif.currently_attached ? CONNECTION_ACTION.DISCONNECT : CONNECTION_ACTION.CONNECT),
() => ({
connect: {
label: t('action:connect'),
icon: 'action:connect',
onClick: () => connectVifs(),
disabled: !canConnectVifs.value,
busy: isConnectingVifs.value,
hint: canConnectVifs.value ? undefined : connectVifsErrorMessage.value,
} satisfies ActionItem,
disconnect: {
label: t('action:disconnect'),
icon: 'action:disconnect',
onClick: () => disconnectVifs(),
disabled: !canDisconnectVifs.value,
busy: isDisconnectingVifs.value,
hint: canDisconnectVifs.value ? undefined : disconnectVifsErrorMessage.value,
} satisfies ActionItem,
}),
'connect'
() => [vif],
() => vm
)
return {
@@ -144,7 +116,16 @@ const { HeadCells, BodyCells } = useVifColumns({
actions: r =>
r({
onClick: () => (selectedVifId.value = vif.uuid),
actions: [connectionAction.value],
actions: [
{
label: vif.currently_attached ? t('action:disconnect') : t('action:connect'),
hint: !canToggleVifConnection.value ? toggleConnectionErrorMessage.value : undefined,
icon: vif.currently_attached ? 'action:disconnect' : 'action:connect',
onClick: () => openVifConnectionToggleModal(),
disabled: !canToggleVifConnection.value,
busy: isTogglingVifConnection.value,
},
],
}),
}
},

View File

@@ -0,0 +1,32 @@
import { computed, ref, unref, type MaybeRef, type Ref } from 'vue'
export default function useMultiSelect<T>(usableIds: MaybeRef<T[]>, selectableIds?: MaybeRef<T[]>) {
const $selected = ref(new Set()) as Ref<Set<T>>
const selected = computed({
get() {
return unref(usableIds).filter(usableId => $selected.value.has(usableId))
},
set(ids: T[]) {
$selected.value = new Set(ids)
},
})
const areAllSelected = computed({
get() {
return (unref(selectableIds) ?? unref(usableIds)).every(id => $selected.value.has(id))
},
set(value: boolean) {
if (value) {
$selected.value = new Set(unref(selectableIds) ?? unref(usableIds))
} else {
$selected.value = new Set()
}
},
})
return {
selected,
areAllSelected,
}
}

View File

@@ -1,9 +1,9 @@
import { ipToHostname } from '@/libs/utils'
import { useHostStore } from '@/stores/xen-api/host.store'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { reactiveComputed, whenever } from '@vueuse/core'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { whenever } from '@vueuse/core'
import { difference } from 'lodash-es'
import { ref, watch } from 'vue'
import { computed, ref, watch } from 'vue'
export const useUnreachableHosts = () => {
const { records: hosts } = useHostStore().subscribe()
@@ -18,33 +18,15 @@ export const useUnreachableHosts = () => {
})
})
const { open } = useOverlay({
component: () => import('@/components/modals/UnreachableHostsModal.vue'),
events: {
onConfirm: true,
onCancel: true,
},
const openModal = useModal({
keepOpenOnRouteChange: true,
component: import('@/components/modals/UnreachableHostsModal.vue'),
props: { urls: computed(() => Array.from(unreachableHostsUrls.value.values())) },
onConfirm: () => window.location.reload(),
onCancel: () => unreachableHostsUrls.value.clear(),
})
const modalProps = reactiveComputed(() => ({
urls: Array.from(unreachableHostsUrls.value.values()),
}))
async function openModal() {
const { event } = await open({ props: modalProps })
if (event === 'onConfirm') {
window.location.reload()
}
unreachableHostsUrls.value.clear()
}
whenever(
() => unreachableHostsUrls.value.size > 0,
() => openModal(),
{
immediate: true,
}
)
whenever(() => unreachableHostsUrls.value.size > 0, openModal, {
immediate: true,
})
}

View File

@@ -1,27 +0,0 @@
import type { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums.ts'
import type { XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
export function useVmExport() {
const xapi = useXenApiStore().getXapi()
const { open: openBlockedUrlsModal } = useOverlay({
component: () => import('@/components/modals/VmExportBlockedUrlsModal.vue'),
events: {
onClose: true,
},
})
async function exportVms(vmRefs: XenApiVm['$ref'][], compression: VM_COMPRESSION_TYPE) {
const { blockedUrls } = await xapi.vm.export(vmRefs, compression)
if (blockedUrls.length === 0) {
return
}
openBlockedUrlsModal({ props: { blockedUrls } })
}
return { exportVms }
}

View File

@@ -1,4 +1,4 @@
import type { XenApiHost, XenApiPbd, XenApiSr, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
import type { XenApiHost, XenApiVm } from '@/libs/xen-api/xen-api.types'
import { defineJobArg } from '@core/packages/job'
export const vmsArg = defineJobArg({
@@ -10,13 +10,3 @@ export const hostArg = defineJobArg({
identify: (host: XenApiHost) => host.$ref,
toArray: false,
})
export const srsArg = defineJobArg({
identify: (sr: XenApiSr) => sr.$ref,
toArray: true,
})
export const pbdsArg = defineJobArg({
identify: (pbd: XenApiPbd) => pbd.$ref,
toArray: true,
})

View File

@@ -1,26 +0,0 @@
import { pbdsArg } from '@/jobs/args.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
import { useI18n } from 'vue-i18n'
export const usePbdPlugJob = defineJob('pbd.plug', [pbdsArg], () => {
const xapi = useXenApiStore().getXapi()
const { t } = useI18n()
return {
run: pbds => xapi.pbd.plug(pbds.map(pbd => pbd.$ref)),
validate: (isRunning, pbds) => {
if (pbds.length === 0) {
throw new JobError(t('job:pbd-plug:missing-pbd'))
}
if (isRunning) {
throw new JobRunningError(t('job:connect:in-progress'))
}
if (pbds.some(pbd => pbd.currently_attached)) {
throw new JobError(t('job:pbd-plug:pbd-connected'))
}
},
}
})

View File

@@ -1,26 +0,0 @@
import { pbdsArg } from '@/jobs/args.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
import { useI18n } from 'vue-i18n'
export const usePbdUnplugJob = defineJob('pbd.unplug', [pbdsArg], () => {
const xapi = useXenApiStore().getXapi()
const { t } = useI18n()
return {
run: pbds => xapi.pbd.unplug(pbds.map(pbd => pbd.$ref)),
validate: (isRunning, pbds) => {
if (pbds.length === 0) {
throw new JobError(t('job:pbd-unplug:missing-pbd'))
}
if (isRunning) {
throw new JobRunningError(t('job:disconnect:in-progress'))
}
if (pbds.some(pbd => !pbd.currently_attached)) {
throw new JobError(t('job:pbd-unplug:pbd-disconnected'))
}
},
}
})

View File

@@ -1,22 +0,0 @@
import { srsArg } from '@/jobs/args.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
import { useI18n } from 'vue-i18n'
export const useSrDeleteJob = defineJob('sr.delete', [srsArg], () => {
const xapi = useXenApiStore().getXapi()
const { t } = useI18n()
return {
run: srs => xapi.sr.delete(srs.map(sr => sr.$ref)),
validate: (isRunning, srs) => {
if (srs.length === 0) {
throw new JobError(t('job:sr-delete:missing-sr'))
}
if (isRunning) {
throw new JobRunningError(t('job:delete:in-progress'))
}
},
}
})

View File

@@ -1,8 +1,9 @@
import { useVmExport } from '@/composables/vm-export.composable.ts'
import { vmsArg } from '@/jobs/args'
import { areSomeVmOperationAllowed, isVmOperationPending } from '@/libs/vm'
import { VM_COMPRESSION_TYPE, VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
import { useXenApiStore } from '@/stores/xen-api.store'
import { defineJob, defineJobArg, JobError, JobRunningError } from '@core/packages/job'
import { useModal } from '@core/packages/modal/use-modal.ts'
import { useI18n } from 'vue-i18n'
const compressionArg = defineJobArg<VM_COMPRESSION_TYPE>({
@@ -11,15 +12,16 @@ const compressionArg = defineJobArg<VM_COMPRESSION_TYPE>({
})
export const useVmExportJob = defineJob('vm.export', [vmsArg, compressionArg], () => {
const xapi = useXenApiStore().getXapi()
const { t } = useI18n()
const { exportVms } = useVmExport()
const openModal = useModal()
return {
run: (vms, compression) =>
exportVms(
xapi.vm.export(
vms.map(vm => vm.$ref),
compression
compression,
openModal
),
validate: (isRunning, vms, compression) => {
if (vms.length === 0) {

View File

@@ -1,14 +0,0 @@
import type XenApi from '@/libs/xen-api/xen-api.ts'
import type { XenApiPbd } from '@/libs/xen-api/xen-api.types.ts'
import type { MaybeArray } from '@core/types/utility.type.ts'
import { toArray } from '@core/utils/to-array.utils.ts'
export function createPbdOperations(xenApi: XenApi) {
type PbdRefs = MaybeArray<XenApiPbd['$ref']>
return {
plug: (pbdRefs: PbdRefs) => Promise.all(toArray(pbdRefs).map(pbdRef => xenApi.call('PBD.plug', [pbdRef]))),
unplug: (pbdRefs: PbdRefs) => Promise.all(toArray(pbdRefs).map(pbdRef => xenApi.call('PBD.unplug', [pbdRef]))),
}
}

View File

@@ -1,35 +0,0 @@
import type XenApi from '@/libs/xen-api/xen-api.ts'
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
import type { MaybeArray } from '@core/types/utility.type.ts'
import { toArray } from '@core/utils/to-array.utils.ts'
export function createSrOperations(xenApi: XenApi) {
type SrRefs = MaybeArray<XenApiSr['$ref']>
return {
delete: async (srRefs: SrRefs) => {
await Promise.all(
toArray(srRefs).map(async srRef => {
const pbdRefs = await xenApi.getField<XenApiSr['PBDs']>('SR', srRef, 'PBDs')
const attachedRefs = (
await Promise.all(
pbdRefs.map(async pbdRef => ({
pbdRef,
attached: await xenApi.getField<boolean>('PBD', pbdRef, 'currently_attached'),
}))
)
)
.filter(({ attached }) => attached)
.map(({ pbdRef }) => pbdRef)
if (attachedRefs.length > 0) {
await xenApi.pbd.unplug(attachedRefs)
}
await xenApi.call('SR.destroy', [srRef])
})
)
},
}
}

Some files were not shown because too many files have changed in this diff Show More