Compare commits

..

209 Commits

Author SHA1 Message Date
Pierre Brunet
8d56fae768 feat: add integ test 2026-09-04 11:25:58 +02:00
Pierre Brunet
2ba2ee4f50 chore: update log 2026-09-04 11:25:58 +02:00
Pierre Brunet
855c9fdf34 chore: update log 2026-09-04 11:25:58 +02:00
Pierre Brunet
846a387fcc fix(@xen-orchestra/proxy): give getState and upgrade their own updater connection 2026-09-04 11:25:57 +02:00
Bastien Nollet
9f72a1f900 feat: technical release (#10358)
* feat(@xen-orchestra/proxy): 0.31.10

* feat(xo-server): 5.208.3

* chore(CHANGELOG): update next
2026-09-04 11:20:47 +02:00
Florent BEAUCHAMP
003cc6f9cc fix(proxy): fetch failed (#10346)
* fix(backups): fetch failed

disable compresion between xoa on proxy on xoa side

* fix(xo-proxy): disable compression on the proxy

it was disable with hrp, replaced by #10038 since it was never
sending accept-encoding header

compression can be put back later on a route by route basis after
careful checks ( for example : file restore, backup listing )
2026-09-03 12:56:36 +02:00
Bastien Nollet
bca8f02b8a feat: release 6.8.1 (#10341) 2026-09-02 11:18:21 +02:00
Bastien Nollet
7a18762da4 feat: technical release (#10334)
* feat(@xen-orchestra/xapi): 8.10.5

* feat(@xen-orchestra/backups): 0.74.2

* feat(@xen-orchestra/proxy): 0.31.9

* feat(xo-server): 5.208.2

* chore(CHANGELOG): update next
2026-09-01 16:26:11 +02:00
Florent BEAUCHAMP
1004edb51f fix(backups): failing replication of qcow2 disks (#10319)
* fix(backups):  task label NBT->NBD

* fix: still force a list block only call for NBD + stream scenario , that was failing to transfer disk on fallback
2026-09-01 15:28:47 +02:00
Marie Garde
a67dd73304 feat(xo6/traffic rule): edit a traffic rule (#10056) 2026-09-01 11:22:03 +02:00
Mathieu
a2ce3bbc48 fix(@xen-orchestra/qa-test): downgrade engine to 22 to avoid build issue (#10323)
* fix(@xen-orchestra/qa-test): downgrade engine to 22 to avoid build issue

* fix >=
2026-09-01 09:14:56 +02:00
Bastien Nollet
3034955277 feat(lite): 0.25.0 (#10329) 2026-08-31 18:37:24 +02:00
Bastien Nollet
faf6745471 feat: release 6.8 (#10328) 2026-08-31 17:59:40 +02:00
Bastien Nollet
7e022940c3 feat: technical release (#10326)
* feat(@vates/types): 2.0.1

* feat(@xen-orchestra/web): 0.60.1

* feat(xo-server): 5.208.1

* chore(CHANGELOG): update next
2026-08-31 15:55:42 +02:00
Bastien Nollet
b33894c067 feat : technical release (#10322)
* feat(@xen-orchestra/web): 0.60.0

* feat(xo-server): 5.208.0

* feat(xo-server-openmetrics): 1.9.2

* feat(xo-web): 5.203.0

* chore(CHANGELOG): update next
2026-08-31 15:15:41 +02:00
Mathieu
2fba0ff4df fix(openmetrics): keep the Prometheus secret across xo-server restarts (#10290)
* fix(openmetrics): keep the Prometheus secret across xo-server restarts

The `secret` property of `configurationSchema` used a random `default`. That
expression is re-evaluated every time the module is loaded, and xo-server never
persists the values ajv fills in from schema defaults, so each restart handed
the metrics endpoint a brand new bearer token and Prometheus started getting
401s.

Drop the default and generate the secret in `load()` instead, saving it through
`xo.configurePlugin()` so it survives a restart.

Introduced by #9323
See https://xcp-ng.org/forum/topic/12415

* chore(changelog): add openmetrics secret entry

* fix(xo-server-openmetrics): generate a 256-bit Prometheus secret

Buffer.from(getRandomValues(new Uint32Array(8))) coerces each 32-bit
element to a single byte, so the generated secret held 64 bits of
entropy instead of 256. Use randomBytes(32) instead.

Introduced by fe29bd0d4
2026-08-31 13:45:02 +02:00
Pierre Donias
62cc3e3f5d feat(xo-web/new VM): allow admin to create VM in resource set (#10259) 2026-08-31 10:55:00 +02:00
Elise-F
d2d2d57c81 feat(lite): add action create internal network (#10235)
* feat(lite): add create network and network bonded actions

* remove vlan required and info message

* feedback number one

* feat(lite): add create network and network bonded actions

* feat(lite): add action create internal network

* update changelog file

* fix rebase

* feedback number one

* remove as const in cancelRoute

* feedback number two
2026-08-31 10:51:27 +02:00
Mathieu
c7bf0c59ef fix(@xen-orchestra/qa-test): fix node version (#10320) 2026-08-31 10:48:19 +02:00
Marie Garde
62013d4e79 feat(xo6): add detach host button (#10179)
* feat(xo6): rebase detach

* add redirect when detach ok

* fix post rebase

* remove dev route

* returns from MR

* add check master host

* use linked translation

* rebase ok
2026-08-31 09:03:33 +02:00
Bastien Nollet
6a4415ea1d feat: technical release (#10318)
* feat(@vates/nbd-client): 3.5.1

* feat(@vates/types): 2.0.0

* feat(@xen-orchestra/acl): 1.6.1

* feat(@xen-orchestra/backup-archive): 1.1.2

* feat(@xen-orchestra/xapi): 8.10.4

* feat(@xen-orchestra/backups): 0.74.1

* feat(@xen-orchestra/web-core): 0.60.0

* feat(@xen-orchestra/mcp): 1.4.2

* feat(@xen-orchestra/proxy): 0.31.8

* feat(@xen-orchestra/rest-api): 0.39.0

* feat(@xen-orchestra/web): 0.59.0

* feat(xo-server): 5.207.4

* feat(xo-server-ipmi-sensors): 2.1.1

* feat(xo-server-openmetrics): 1.9.1

* feat(xo-server-sdn-controller): 1.5.0

* chore(CHANGELOG): update next
2026-08-28 14:56:02 +02:00
Florent BEAUCHAMP
14e4c7d62c fix(backups): timeout NBD transfer omnibus fixes (#10306)
* fix(backups): timeout was not used correctly for NBD transfers
* fix(nbd-client): evict a dead client in multi instead
actual code was retrying 5 times, each time with a 60s timeout
multi also have its own retry on conneciton
since the client used is determnistic for a block, any stalled client
will be hammerred for a lot of time before giving up

this PR evict a nbd client that is failing to read a block (with its
retry logic)

* fix(nbd-client/multi): better spread read accross client
the actual code derivate the clientId from the block index
we have no information on the block distribution, only hopes that
it's random enough
this PR introduce a mechanism to use a round robin to select
the next client

* fix: correct fall back to full with /without nbd on qcow2
2026-08-28 10:57:17 +02:00
Marie Garde
d541af2c41 feat(xo6): add restart toolstack host button (#10178)
* feat(xo6): rebase from master

* add check restart toolstack on buttons

* add tooltip message

* Fix for PR

* remove loader

* add chengelog

* remove route map

* return form PR
2026-08-28 10:37:38 +02:00
Sandrine Barrucand
cdc4ddb652 feat(xo6/backups): add header title (#10303) 2026-08-27 11:49:53 +02:00
Joris K
2ebf18a636 feat(xo-lite): add vm tree actions and loader (#10304) 2026-08-27 10:56:34 +02:00
Grandalf
dfb4c925ec fix(sdn-controller): delete saved port on traffic rule patch (#10307) 2026-08-27 10:17:20 +02:00
Enée DI IORIO
c0d92f3061 feat(web-core): upgrade UiCheckbox component to v8 (#9777) 2026-08-27 10:12:31 +02:00
vates-bot
642dce30ef feat(web-stack/i18n): update Xen Orchestra 6 (#10181) 2026-08-27 10:11:02 +02:00
Thierry Goettelmann
970eca135e fix(@vates/types,@xen-orchestra/rest-api): remove ACL type parameters from XoRecord (#10308)
Introduced by 63d4334837
2026-08-26 18:12:53 +02:00
Bastien Nollet
9cdaf6bb41 feat: technical release (#10305)
* feat(@xen-orchestra/async-map): 0.1.4

* feat(xo-common): 0.11.0

* feat(xen-api): 4.9.0

* feat(@vates/types): 1.30.2

* feat(@xen-orchestra/acl): 1.6.0

* feat(@xen-orchestra/xapi): 8.10.3

* feat(@xen-orchestra/backups): 0.74.0

* feat(@xen-orchestra/backups-cli): 1.1.14

* feat(@xen-orchestra/disk-cli): 2.2.1

* feat(@xen-orchestra/immutable-backups): 3.0.5

* feat(@xen-orchestra/web-core): 0.59.0

* feat(@xen-orchestra/mixins): 0.20.2

* feat(@xen-orchestra/proxy): 0.31.7

* feat(@xen-orchestra/proxy-cli): 0.3.3

* feat(@xen-orchestra/qa-test): 1.2.0

* feat(@xen-orchestra/rest-api): 0.38.0

* feat(@xen-orchestra/upload-ova): 0.1.9

* feat(@xen-orchestra/web): 0.58.0

* feat(xo-acl-resolver): 0.5.4

* feat(xo-cli): 0.32.4

* feat(xo-server): 5.207.3

* feat(xo-server-audit): 0.15.2

* feat(xo-server-ipmi-sensors): 2.1.0

* feat(xo-server-netbox): 1.13.2

* feat(xo-server-sdn-controller): 1.4.1

* feat(xo-web): 5.202.0

* chore(CHANGELOG): update next
2026-08-25 16:19:35 +02:00
Florent BEAUCHAMP
9b4e1aee3e fix(xo-server): task controller leaking memory (#10237) 2026-08-25 15:42:12 +02:00
Thomas Moraine
ab7b2fc7a9 docs(xo): refine page titles and navigation structure (#10276)
* docs(xo): refine page titles and navigation structure

Make page titles clearer and more consistent with their content and
purpose. Reorder some pages (and sections) and align their sidebar labels with
their titles to make the documentation easier to navigate and
understand.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(sidebars.ts): move discover xo category back to where it was

Applying the change suggested by olivierlambert.
The 'Discover Xen Orchestra' category now follows
the 'Getting started' category.
The 'architecture' page/ 'How XO 6 is organized' stays
at the end of the Getting Started category.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(xo): specify navbar titles

Applying changes suggested by olivierlambert.

Some titles in the navigation bar were made too long,
in an attempt to make them identical to the titles in the corresponding doc pages.
Having different titles in the navbar and in the actual page
is not a defect, and can indeed help readers scan the
document structure quicker.
As a result, we're (re-)adding sidebar_label metadata
to specify a navbar title where the page title was too long.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(xo): revert individual page renames

Applying changes suggested by olivierlambert, following,
the reasoning he explained in the pull request.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(intro_support.md) change title to 'support'

Apply change suggested by olivierlambert.
'Support' instead of 'Support options' is shorter and
carries the same meaning overall.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(xo): update outdated internal link labels

A few commits ago, some page titles were changed.

This did not break any internal links, but it left some link labels outdated. This commit updates those labels to match the current page titles.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs: convert page titles to sentence case

Applying changes suggested by olivierlambert

Some page titles were still using title case, even though we use sentence case throughout the XO documentation.

This commit updates those titles to follow the same convention.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(xo): switch gerund titles to noun forms

Some page titles used gerunds (the -ing form), while others used nouns or noun phrases, resulting in an inconsistent style.

This commit changes the gerund titles to noun-based titles for consistency.

The "Troubleshooting" title is kept as-is because it is a noun, despite ending in -ing.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

---------

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>
2026-08-25 14:23:34 +02:00
Thierry Goettelmann
9cdd8e9d45 chore(web-core,web,lite): enforce .ts extension in imports (#10299) 2026-08-25 11:01:00 +02:00
Sandrine Barrucand
14e5352a40 feat(xo6/vm): add guest tools status (#10077) 2026-08-25 10:40:50 +02:00
Marie Garde
d955ffc4d1 feat(xo6): add smart reboot host button (#10177)
* feat(xo6): reset smart reboot branch ok

* Last returns

* Remove route map

* rebase ok

* add check onConfirm smart reboot
2026-08-25 09:56:16 +02:00
spacotte-vates
f812eaaeb6 feat(backup): implement synchronized snapshot option back (#10136)
Adds a synchronizedSnapshot backup setting. When enabled, all of a job's VM snapshots are taken up front in a batch before any transfer begins, and each VM's backup then reuses its pre-taken snapshot instead of snapshotting again.

Settings:
synchronizedSnapshot:

    false (default)
    true (synchronize every VM in the job)
    <tag> (synchronize only VMs carrying that tag, others are backed up normally).

snapshotConcurrency: max concurrent snapshots during the batch phase (default 2).

A batch member that fails to open is silently dropped from synchronization and backed up normally.

Unit tested where applicable and e2e tests added in qa-test.

Checkbox added in xo5 backup jobs to synchronize snapshots, tags not supported yet.
2026-08-24 17:58:03 +02:00
amouillard-vates
814bc96a8b feat(xo6): sr dedicated page general tab (#10100)
* feat(xo6): sr dedicated page general tab

* Remove dev routes

* Update CHANGELOG.unreleased.md

* Rename sr usage warning

* Rename vdi allocated space warning

* Remove useless variable

* Remove useless destructuring

* Remove useless destructuring

* Use UiInfo component and normalize margins

* Change variable name

* Add pool/host breadcrumb options

* Normalize fromContext with vdi page

* SR space unwritable alert

* Side panel space card info message

* Usage warning color

* Fix PR comments

* Add sr uuid resolver

* Fix CI

* Update getters name

* Full width UiInfo

* Consistent srUsagePercentage check

* Remove superfluous destructuration

* Reuse existing SR_SCOPE_TYPE

* Remove dev routes

* CSS nesting

* Fix PR comments

* Dev routes + UiPanelCard

* Move getSrPageLocation
2026-08-24 11:13:13 +02:00
Alina D
9ef53890b8 feat(xo-lite): add vdi page (#10269) 2026-08-21 17:31:45 +02:00
spacotte-vates
8b4505a2d5 fix(xo-server): changing vif mac adress destroy traffic rules (#10284) 2026-08-21 17:15:48 +02:00
amouillard-vates
a68c9534e9 fix(lite): add hasChildren prop to xo-lite tree view elements (#10244) 2026-08-21 14:59:23 +02:00
Bastien Nollet
46b0dc67bb chore(backups): use set_memory_limits instead of convoluted code (#10286) 2026-08-21 14:36:22 +02:00
Thierry Goettelmann
249137793f fix(web-core,web,lite): align side panel card spacing with the design system (#10279) 2026-08-20 12:03:44 +02:00
amouillard-vates
96e7e23f40 feat(xo-lite): enable scan PIFs button on host network page (#10147) 2026-08-19 14:01:04 +02:00
Anupam Mediratta
6c3e3e781d fix(backups): upgrade tar to 7.5.19 (CVE-2026-59873) (#10159) 2026-08-19 10:42:23 +02:00
Marie Garde
bcb0a7041f feat(xo6): add force reboot host button (#10175)
* manual rebase

* returns from stack PR

* rebase ok

* returns from PR

* fix import

* remove unescessary params

* remove reoute map

* Last return
2026-08-18 11:48:42 +02:00
Alina D
db0d009d5b feat(xo6/pool): add forget action (#10130) 2026-08-18 11:17:18 +02:00
Elise-F
de1c231873 feat(lite): add create network and network bonded actions (#10145)
* feat(lite): add create network and network bonded actions

* update changelog file

* remove vlan required and info message

* feedback number one

* feedback number two
2026-08-18 10:49:27 +02:00
Marie Garde
4235644950 feat(xo6): add reboot host button (#10141)
* continuefeat(xo6/host): add reboot host button

* fix fr.json

* Add loader on evacuate and reboot

* add check message evacuate VMs

* Fix message

* Returns from PR

* Remove vm migrate from host operations

* Change accent modal

* Rebase master ok

* Fix rebase
2026-08-17 09:40:40 +02:00
Marie Garde
7942d6a84a feat(xo6): add disable host and evacuate VMs (#10090)
* feat(xo6): add disable and enable host button

* Add button enable disable

* remove route map file

* Refacto for PR

* Add modal

* refacto for PR

* fix i18n

* fix route map

* change modale to VtsActionModale

* refacto for MR

* fix type VtsActionModal

* refacto for MR

* add enable disable un treeview

* refacto treeview

* wip

* add shutdown and start button and job

* Update changelog and remove route map

* wip i18n

* tests ok

* fix build

* refacto for mr

* refacto for PR

* add check pending action

* add check host not halted

* feat(xo6): add disable and enable host button

* Add button enable disable

* Refacto for PR

* Add modal

* refacto for PR

* change key i18n

* change modale to VtsActionModale

* refacto for MR

* fix type VtsActionModal

* refacto for MR

* refacto treeview

* wip

* Update changelog and remove route map

* wip

* wip forget

* test and refacto for PR

* fix error rebase

* fx rebase missing

* fix rebase

* fix rebase

* wip

* add shutdown and start button and job

* tests ok

* refacto for mr

* add check host not halted

* wip

* rebase for PR

* fx rebase missing

* wip

* change order button

* wip

* wip forget

* wip

* button and job ok

* add modal disable host and evacuate vm but tests not done

* refacto for PR

* fix fr json and route map

* fix rebase

* fix PR

* remove route map

* last fix

* Returns from PR

* Returns from PR

* Add ? on confirm i18n

* Fix job disable and enable running message

* Fix enable job

* Fix enable job

* Returns from PR

* Fix post rebase

* Fix post rebase

* Fix post rebase

* fix from rebase

* Returns from PR

* Returns from PR

* rebase ok
2026-08-17 08:33:33 +02:00
amouillard-vates
c5faec4cf6 fix(lite): remove multi-selection from pool networks table (#10268) 2026-08-14 15:39:33 +02:00
Thomas Moraine
c9149618f8 docs(xo): rename security tab into traffic rules (#10267)
The Pools -> Security tab in Xen Orchestra was
recently renamed as 'Traffic rules'.
This commit updates the XO documentation (screenshots included) to reflect that change.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>
2026-08-14 13:42:38 +02:00
Elise-F
438415a882 feat(xo6/traffic rules): added the error message related to the method and updated UI (#10202) 2026-08-14 10:41:45 +02:00
OlivierFL
ed78cc10cf feat(xo-6/vif): add VIF name in head bar on VIF detail page (#10252) 2026-08-14 09:05:02 +02:00
Marie Garde
1c18215bd1 feat(xo6): add host action button forget (#10089)
* feat(xo6): add disable and enable host button

* Add button enable disable

* remove route map file

* Refacto for PR

* Add modal

* refacto for PR

* change key i18n

* fix i18n

* fix route map

* change modale to VtsActionModale

* refacto for MR

* fix type VtsActionModal

* refacto for MR

* add enable disable un treeview

* refacto treeview

* wip

* add shutdown and start button and job

* Update changelog and remove route map

* wip i18n

* tests ok

* fix build

* refacto for mr

* refacto for PR

* add check pending action

* add check host not halted

* feat(xo6): add disable and enable host button

* Add button enable disable

* Refacto for PR

* Add modal

* refacto for PR

* change key i18n

* change modale to VtsActionModale

* refacto for MR

* fix type VtsActionModal

* refacto for MR

* refacto treeview

* wip

* Update changelog and remove route map

* refacto for mr

* wip

* add forget button host

* update button for menuitem

* wip forget

* test and refacto for PR

* fix error rebase

* fx rebase missing

* add changelog

* fix rebase

* fix rebase

* Add ? on confirm i18n

* Returns from PR

* rebase overlay ok

* fix changelog

* Add redirect if still on host page after forget

* Add redirect after delete
2026-08-14 09:00:50 +02:00
Pierre Donias
7cdb792bfe fix(xo-web/vm/console): make collapsed header state reliable (#10007)
The console tab kept its own `minimalLayout` state to track whether the page header was collapsed, separate from the VM page's `collapsedHeader`. The two desynced because the tab remounts on navigation while the VM page stays mounted.

Fix:
- Single source of truth `collapsedHeader` in the parent index.js
- Pass it to the child tab-console.js along with `setCollapsedHeader`
- Replace the `_toggleHeader` toggle with an explicit `_setCollapsedHeader(value)` setter
- Remove the duplicate local `minimalLayout` state that could get out of sync and use `collapsedHeader` instead
- Force off on VM shutdown (console no longer displayed) and on unmount (user changed page)
2026-08-13 15:15:25 +02:00
Grandalf
0601716fa4 fix(backups): return backups repository info one by one instead of erroring on first failure (#10205) 2026-08-13 15:09:53 +02:00
spacotte-vates
d53d2fc1c2 fix(xo-server): fix target not found error for warm migration (#10210) 2026-08-13 09:56:10 +02:00
Bruno Verachten
11ff21097f docs(snapshots): note that reverting restores VM metadata too (#10196)
Surfaced via https://xcp-ng.org/forum/topic/12148.
2026-08-12 17:39:33 +02:00
Greg-hub-dev
828c15cbb4 docs(backups.md) : Delete future RAM backup feature details (#10223) 2026-08-12 15:03:33 +02:00
Grandalf
798732e62a fix(async-map): allow return type to be different than input type (#10227) 2026-08-12 10:50:44 +02:00
Mathieu
1bfcc50b23 fix(xen-api): update platform for cores-per-socket update (#10201)
XO-2814
2026-08-10 15:52:07 +02:00
Olivier Lambert
c5d791a7de docs: full documentation revamp (#10212) 2026-08-07 16:36:09 +02:00
Grandalf
3293e69cc2 refactor(xo-server): remove hrp dependency (#10038)
replace http-request-plus external depedency by a a native wrapper around fetch
2026-08-07 11:58:20 +02:00
Grandalf
a0193085f5 feat(ipmi): add get sensors route (#10003) 2026-08-07 11:38:28 +02:00
Mathieu
2e5ec8c9e2 fix(xo-server): auth provider did not wait for token update (#10233) 2026-08-06 15:24:21 +02:00
Mathieu
8054d88a88 fix(xo-server): handle 'no-bundle' as legacy licence (#10241) 2026-08-06 15:22:22 +02:00
Thierry Goettelmann
20bedca539 refactor(web-core,lite,web): migrate from modal/drawer packages to the unified overlay system (#10096) 2026-08-05 17:13:15 +02:00
Grandalf
f61019b960 fix(rest-api): coerces strings into numbers in external-router when type="number" (#10213) 2026-08-05 16:22:09 +02:00
Thomas Moraine
be960b36b9 docs(advanced.md) fix broken link to kubernetes page (#10230)
The docs on devops tools and kubernetes was moved
from the Vates VMS doc to the Xen Orchestra doc.
As a result, one link to the kubernetes page broke in the XO doc.
This commit fixes that broken link.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>
2026-08-05 09:40:12 +02:00
Mathieu
40dede9e11 feat: release 6.7.1 (#10229) 2026-08-04 15:42:40 +02:00
Mathieu
e9548959c6 feat: technical release (#10228) 2026-08-04 12:05:18 +02:00
Florent BEAUCHAMP
be94d0d083 fix(xo-server/v2v): incorrect uuid for running VM without snapshot (#10194)
* add more details in task log
* fix an issue with VM with more than 10 snapshot, add unit test for this parsing
* fix the real bug: vmware do not update the vmdk description file before the next VM reboot. It means that the uid of the snapshot and vm are the same, thus finishing the transfer with " nothing to transfer" . We are now using the path on source as key + add unit test + add compatibiliy with legacy VM migrated with the uid.
* add e2e test for v2v
2026-08-04 10:41:07 +02:00
Julien PIALET
9c6d10327f doc(RBAC) : added details on POST privilege example (#10168) 2026-08-03 15:20:20 +02:00
spacotte-vates
a94eba4dd1 fix(nbd-client): fix long datamap read nbddisk (#10157)
Customer imported large VM from VMWare (> 3 To), import switched to Qcow2 automatically but the process was stuck while building the qcow2 L1/L2 address tables, where the NbdDisk's hasBlock is called for each l2 table entry which iterated over the disk dataMap which contained ~113,528 ranges. This froze the process for more than 18 minutes after which it was either killed or died due to OOM error.

This fix improves the NbdDisk by:

    Updating processDatamap to throw on overlapping ranges and merge touching extents.
    Override default getBlockIndexesCount with optimized Nbd one.
    Improve hasBlock with a built in cursor to improve performance.

Test file added to cover the new function and updated code.
2026-08-03 11:24:44 +02:00
Florent BEAUCHAMP
a6970b0150 fix(backups/filerestore): restore files from proxy as tgz (#10208)
from ticket 59505

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.
2026-08-02 14:57:48 +02:00
Bastien Nollet
26cd23179d fix(load-balancer): don't get disabled hosts (#10209)
The load balancer did not take into account that hosts may be in disabled state, which means it's impossible to migrate a VM to it.
This PR fixes that by ignoring these hosts instead.

Fixes ticket 62077
2026-08-02 14:56:58 +02:00
Joris K
03d2af39ad feat(xo6): add host scan PIFs button and job (#10191)
* changelog

* feat(xo6): add host scan PIFs button and job

* add changelog

* missing translation

* review

* review

---------

Co-authored-by: MathieuRA <contact@mathieu-raisin.fr>
2026-07-31 16:10:46 +02:00
Mathieu
be868a307b feat(rest-api): add scan-pifs endpoint (#10187)
* feat(rest-api): add scan-pifs endpoint

* changelog

* add pifs tag to the route

* fix typo

* fix  typo in changelog

* fix

* missing response
2026-07-31 11:50:05 +02:00
Florent BEAUCHAMP
01c00b110e test(immutable-backups): integration test of the new process 2026-07-31 11:28:25 +02:00
Florent BEAUCHAMP
65c32014d6 feat(immutable-backups): better cleanup on start
feat: changelog
2026-07-31 11:28:25 +02:00
Florent BEAUCHAMP
69dfeeaaf6 fix(immutable-backups): ensure shell is in english 2026-07-31 11:28:25 +02:00
Florent BEAUCHAMP
4a1269b898 feat(immutable-backups): run lift on proces start 2026-07-31 11:28:25 +02:00
Marie Garde
498cc7509f feat(xo6/host): host action button start shutdown (#10088)
* feat(xo6): add disable and enable host button

* Add button enable disable

* remove route map file

* Refacto for PR

* Add modal

* refacto for PR

* change key i18n

* fix i18n

* fix route map

* change modale to VtsActionModale

* refacto for MR

* fix type VtsActionModal

* refacto for MR

* add enable disable un treeview

* refacto treeview

* wip

* add shutdown and start button and job

* Update changelog and remove route map

* add check on disable button

* fix job error type

* update button for menuitem

* wip i18n

* add vtsaction modal

* tests ok

* fix build

* refacto for mr

* fix fr.json

* refacto for PR

* add check pending action

* add check host not halted

* fix enable disable button while host shutdown

* returns from MR

* fix changestate host header

* wip

* wip

* add check pending operations

* last fix for PR

* fix menuItem in mobile vue

* remove route map

* returns from MR

* fix start button

* Add changelog
2026-07-31 10:12:52 +02:00
Florent BEAUCHAMP
f98b4c9e4a docs(s3): add ovh as a tier 1 provider (#10206) 2026-07-31 09:40:37 +02:00
Mathieu
cc7ba53b29 feat(lite): 0.24.0 (#10204) 2026-07-30 17:46:20 +02:00
Mathieu
1a795970f9 feat: release 6.7.0 (#10203) 2026-07-30 17:26:51 +02:00
Mathieu
59306dce8f feat: technical release (#10198) 2026-07-30 11:08:08 +02:00
Florent BEAUCHAMP
6ba465be04 fix(xapi): don't try to compute progress on Buffer (#10195)
* fix(xapi): don't try to compute progress on Buffer

introduced by 76b45a9b3b

* port type to vates/types
2026-07-30 10:19:37 +02:00
Mathieu
068c4cdc86 feat: technical release (#10192) 2026-07-29 15:30:14 +02:00
Mathieu
93a7c3b509 fix(docs): fix yarn.lock and broken anchor (#10190)
Introduced by ada3cf745
2026-07-29 14:52:45 +02:00
Florent BEAUCHAMP
07c42bbd1e fix(fs/s3): improve delete multiple performances (#10189) 2026-07-29 11:29:55 +02:00
Florent BEAUCHAMP
ada3cf745c feat(xo-server): serve doc from xo + add backup calculator (#10154)
* feat(xo-server): serve doc locally
* the doc is already distributed from the mono repo
* add a build phase to the global yanr build that build a doc with the
right prefix
* add a http mount doc => embed build

* doc(backups): add a space calculator
* estimate the space needed for backups
* compute the duration protected by immutability
2026-07-29 09:48:41 +02:00
Mathieu
6a0332a784 fix(xapi/host): fix async use in a sync block for smart reboot (#10180)
* fix(xapi/host): fix async use in a sync block for smart reboot
2026-07-29 09:38:38 +02:00
Mathieu
09bd5c3425 feat(openmetrics): expose SR content and UUID (#10149)
Refs XO-2503
2026-07-29 09:24:34 +02:00
Florent BEAUCHAMP
26c36d485e fix(backups): don't hide errors during backup transfers (#10183) 2026-07-28 17:08:19 +02:00
Thierry Goettelmann
087fd5d397 feat(overlay): allow manually aborting overlays (#10167) 2026-07-28 16:47:45 +02:00
Grandalf
4636fcf820 feat(types): type-register-rest-routes (#10171) 2026-07-28 14:51:36 +02:00
Marie Garde
dd58fed217 feat(xo6/xolite): add copyall button xo and lite (#10081) 2026-07-28 13:38:57 +02:00
vates-bot
4aa8a31c25 feat(web-stack/i18n): update Xen Orchestra 6 (#10033) 2026-07-28 11:00:31 +02:00
Olivier Lambert
4ca263c10a feat(xo-server,xo-web/rpu): shut down and restart pinned VMs instead of aborting (#10125)
* feat(xo-server/rpu): opt-in shutdown/restart of pinned VMs instead of aborting
2026-07-28 10:05:43 +02:00
Alina D
8d58147d66 feat(xo6): align vertically all hosts in Treeview (#10153) 2026-07-28 09:53:07 +02:00
Joris K
5849844fca fix(lite): change defer type import on vm creation (#10176) 2026-07-28 09:22:52 +02:00
Mathieu
a5648aede8 fix(web-core): fix several store issues (#10156) 2026-07-28 09:22:45 +02:00
Florent BEAUCHAMP
84ce89d199 fix(disk-transform): implement a guardrail to ensure it does not read block only in parent 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
9140cd273b fix(disk-transform): fix getBlockIndexesCount
introduced by #10058

the current method assumes that source block are full but they can
be sparse. In the worst case getBlockIndexesCount can be the same as
the source
2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
e710135eda fix(backups): ensure replication never transmit a delta without a base
differentiate when it's expected to transmit a full , and throw an
error on any discrepency
2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
5509f62ccd fix(backups): fix aggregated backup failing instead of falling back to a full
map.foreach((value,key)=> , not map.foreach(key=>
2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
6c4f7336e1 fix(backup-archive): really run tests 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
65cd607a49 fix(backups): force a full on continuous replication if the base could have been empty 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
453ffc98d2 fix(backups): fall back to a full backup if it's possible that the base is broken 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
f8df78c03d feat(backup-archive): add method to get the root of a chain 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
3613b30aa1 fix(backups): stamp backup after the fix 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
58332e6b16 doc(backups): more clarification on qcow2 + nbd 2026-07-27 19:45:25 +02:00
Florent BEAUCHAMP
9388fa4bb6 fix(disk-transform): erronous offset in DiskLargerBlock when copying data
the offset must be relative to the start of THIS large block, not to the
start of the disk — otherwise every large block after index 0 lands past
the end of destinationBlock and copy() silently writes nothing (zeroed block).

affect qcow2 incremental backup with NBD disable

NBD + qcow2 and Vhd backups don't go through this code path
2026-07-27 19:45:25 +02:00
Olivier Lambert
f683817dec feat(docs): working cookieless Matomo tracking on a dedicated site
The previous static/js/matomo.js snippet never loaded the tracker
script, so nothing was ever recorded; it also pointed at site 5, the
XO website. Replace it with the client module from the Vates VMS docs
on the new dedicated docs site (23): cookieless page-view tracking that
follows SPA navigations, and instrumentation of the lunr search box
reporting each settled query with its suggestion count, so zero-result
searches surface missing content. The feedback widget mirrors votes and
thumbs-down reasons as doc_feedback events.

Also fills in the Formbricks IDs for the "XO Docs page feedback"
survey, enabling the feedback widget.
2026-07-27 19:25:51 +02:00
Olivier Lambert
51fe6b8920 feat(docs): page feedback widget wired to Formbricks
Swizzles DocItem/Footer to show a 'Was this page helpful?' widget under
every doc article, ported from the Vates VMS docs. Votes post to the
self-hosted Formbricks instance via its public client API; a thumbs-down
asks why (outdated, unclear, missing info, inaccurate) plus optional
free text. The vote is recorded on click so it survives the visitor
leaving before the follow-up. Page path rides along as a hidden field
for per-page filtering.
2026-07-27 19:25:51 +02:00
Mathieu
74b952be2b feat: technical release (#10174) 2026-07-27 15:05:16 +02:00
Florent BEAUCHAMP
efbfb664f7 fix(backup-archives): regenerate cache on discrepencies (#10132)
* ensure cache is generated completely at the end of the backup job
* ensure a broken cache is regenerated even without merge during the cleanup phase
* ensure a broken cache is regenerated on request
2026-07-27 14:19:17 +02:00
Bastien Nollet
1616ec6f41 feat(backups): make fallback cause appear in the task (#10148) 2026-07-27 14:10:03 +02:00
Alina D
246e2e4eba feat(xo6/pool): add connect/disconnect actions on page site (#10075) 2026-07-27 13:26:20 +02:00
Mathieu
bcb91e8b4f feat(rest-api): add POST /srs route to create a storage repository (#9990) 2026-07-27 10:37:55 +02:00
Florent BEAUCHAMP
76b45a9b3b fix(xo-server): ensure import task progress is correctly updated (#10133) 2026-07-27 10:23:29 +02:00
Sylvère
5f42e437c7 feat(lite): add SR connect/disconnect/delete (#10006) 2026-07-27 09:44:23 +02:00
Sylvère
b76294a1b1 feat(web-core): refactor the sidebar system (#10120) 2026-07-27 09:43:16 +02:00
Grandalf
b7bce8e7e7 fix(csp): update Content-Security-Policy to allow connections to GitH… (#10162) 2026-07-27 09:03:17 +02:00
Pierre Brunet
1445f986cf feat: add azure section (#10166)
* feat: linter

* feat: add Azure doc
2026-07-24 17:59:06 +02:00
MlssFrncJrg
83b43a44f6 feat(xo5/hub): open Hub to all plans and gate recipes individually (#10117) 2026-07-24 17:30:04 +02:00
Olivier Lambert
235ff3c455 feat(xo6/new-vm): set HA restart priority at VM creation (#10072) 2026-07-24 14:15:22 +02:00
Alina D
b0194b2c5f feat(xo6): update input version (#10009) 2026-07-24 11:47:22 +02:00
Marie Garde
316122a683 feat(xo6/users): Add Users Table (#10029) 2026-07-24 10:34:04 +02:00
Sandrine Barrucand
954c0aaa9e fix(xo6): add separator between label and hint in table actions (#10143) 2026-07-23 16:19:37 +02:00
Sandrine Barrucand
377e315e02 fix(xo6/host): wrap Network name in PIF side panel (#10155) 2026-07-23 14:54:56 +02:00
Joris K
9b6f882424 fix(xo6/lite): fix some design inconsistency between pages on xo6 and lite (#10109) 2026-07-23 14:23:37 +02:00
Marie Garde
874da48125 feat(xo6): add enable/disable host button (#10074) 2026-07-23 12:02:46 +02:00
Pierre Brunet
e22ee2547b Fix: avoid default value for "private" in normalize-packages script (#10121) 2026-07-23 11:43:21 +02:00
Mathieu
43e45667ab fix(xo-server/rpu): LINSTOR packages update progress no longer exceeds 100% (#10122) 2026-07-23 11:24:23 +02:00
Florent BEAUCHAMP
c05f9bb357 feat(backup): update footer and header at once (#10123) 2026-07-23 11:16:56 +02:00
amouillard-vates
92f8ed4077 feat(lite): add copy info into JSON action to pool networks table (#10083) 2026-07-23 11:10:52 +02:00
MathieuRA
fc6415b4ec fix(xo-server): fix group deletion checking RBAC authorization 2026-07-23 10:52:29 +02:00
MathieuRA
53014d7d18 feat(rest-api): expose acl-roles/:id/groups 2026-07-23 10:52:29 +02:00
MathieuRA
5bb4ac62bf fix(xo-server): delete user don't remove the link between user and acl-role 2026-07-23 10:52:29 +02:00
MathieuRA
b4433e4ecc feat(rest-api): expose acl-roles/:id/users 2026-07-23 10:52:29 +02:00
MathieuRA
fee9bf8334 feat(xo-server): add groupIds and userIds to acl-role object 2026-07-23 10:52:29 +02:00
MathieuRA
1455801282 feat(xo-server): add aclRoleIds property to groups 2026-07-23 10:52:29 +02:00
MathieuRA
bd5937366a feat(rest-api): expose groups/:id/acl-roles 2026-07-23 10:52:29 +02:00
Joris K
d2667ac64b feat(xo6/lite): updated the modal so it can be closed using the X or by clicking outside it (#10137) 2026-07-23 09:06:19 +02:00
Pierre Brunet
de9687e2c0 fix: issue on file overwriting during vhdDirectory creation (#10139) 2026-07-22 15:04:00 +02:00
Florent BEAUCHAMP
c12bd807ed feat(qa-test): add a script to do a load test (#10119)
add new option and script to launch a load test :

    number of vm is configurable
    concurrency is configurable
    number of backup run is configurable

will do multiple run, then a restore
2026-07-22 14:36:50 +02:00
amouillard-vates
7b21690721 feat(xo6/pool): add new VM button and disconnect to pool tree actions (#10046) 2026-07-22 14:19:26 +02:00
Sandrine Barrucand
b719c0a018 refactor(xo6/vif): merge connect/disconnect buttons into a single component (#10112) 2026-07-22 13:25:45 +02:00
Grandalf
8e8afeb1b5 feat(xo-server): add content security policy (#10101) 2026-07-22 12:15:16 +02:00
Elise-F
0a5693345f feat(traffic rule type by VIF): display only the traffic rules for VMs and disable VMs without a VIF. (#9977)
- Show only traffic rules of VMs. Don't include `vm-snapshot` or `vm-template`
- For VM selection, display all VMs and disable those without a VIF, with a
message displayed
2026-07-22 11:01:17 +02:00
Bruno Verachten
ebce0e508f docs(xo): document VBD attach and note ISO mount is JSON-RPC only (#9981) 2026-07-21 16:35:13 +02:00
Olivier Lambert
64f1327f46 feat(rest-api): allow setting HA restart priority on VM creation (#10070)
See #10069
2026-07-21 16:02:08 +02:00
bleader
d2c28450d4 docs(sdn_controller.md): clarify openssl3 update instructions (#9821) 2026-07-21 11:45:09 +02:00
MlssFrncJrg
4eb43fbc36 feat(xo6): resolve objects in tasks names (#9830) 2026-07-21 10:37:36 +02:00
Bastien Nollet
e44034285b fix(backups): fix failed status on successful retry (#10129)
A VM backup log status is calculated depending on its subtask status. Previously, we made that it would be a failure if at least one of its subtask is a failure.

However, in case of successful retries, the intended behaviour is to have failed subtasks, which should not affect the parent task status. The first commit of this PR fixes that.

The second commit simplifies the getStatus function and its usage.
---------

Co-authored-by: Florent BEAUCHAMP <florent.beauchamp@vates.tech>
2026-07-21 09:50:07 +02:00
Thierry Goettelmann
9c1aa104f5 chore(deps): hoist pinia, vite and vue-router to root devDependencies (#10138) 2026-07-21 09:30:21 +02:00
Thierry Goettelmann
4ff8af838f feat(web-core): add hide-permanently package (#10108) 2026-07-21 09:28:07 +02:00
amouillard-vates
101fb46ad1 fix(xo6/site): remove site tree view new vm action (#10135) 2026-07-21 09:04:44 +02:00
Thierry Goettelmann
687dd5f456 feat(web-core): add promise-based overlay system (#10095) 2026-07-20 17:34:09 +02:00
Mathieu
ee6c6b3bbc feat(xo-server): delay load balancer re-enable after RPU (#10111)
XO-2706
2026-07-20 16:51:45 +02:00
Mathieu
54260268ba fix(xo-server): demote successful fallback logs (#10131)
XO-2734
2026-07-20 16:00:13 +02:00
Elise-F
0d53d7621a feat(lite): add the “connect/disconnect” action for a VIF on a VM (#10080) 2026-07-20 15:12:46 +02:00
Florent BEAUCHAMP
c3a2e89c1f feat(disk-cli): add option to show chain info, size, and improve peformances (#10063) 2026-07-20 14:37:20 +02:00
Enée DI IORIO
27fe714e17 feat(web-core): update UiTextArea to V5 (#9855) 2026-07-20 11:10:33 +02:00
Mathieu
5e6c4ad96d fix(xo-server): automatically reconnect to XenServer after connection (#10086)
A server left enabled but without a Xapi instance was never retried by anything in
xo-server. Three paths lead to that state:

    a failed explicit connect: xo-server boots while a pool is down, a user clicks
    "connect" during an outage, or the host-eject path exhausts its 5 attempts;
    a SESSION_INVALID teardown after a pool master restart (_sessionCall calls
    disconnect(), and nothing listens to server:disconnected);
    fixing a server's credentials/address while it is disconnected (server.set never
    triggers a connection).

Once there, the server stays disconnected forever, showing an error that can be
minutes or hours old. Support ends up chasing false "pool is dead" reports, typically
right after a rolling pool update, which is exactly when hosts reboot by design.
2026-07-20 09:42:12 +02:00
Florent BEAUCHAMP
926eb348d3 feat(xo-server): log more data to track memory leaks (#10041)
* feat(xo-server): log more data to track memory leaks

* changelog
2026-07-17 16:35:06 +02:00
Mathieu
bfb6b15cfa fix(xo-server/rpu): retry check_update while updater plugin is busy (#10115) 2026-07-17 16:17:09 +02:00
Grandalf
d05be427fb fix(xo-server): replace hasPermissions (#10093) 2026-07-17 11:48:37 +02:00
Pierre Brunet
76fa4bba51 fix(CI): do not log "ENOENT" when unlink fails after check (#10102)
* fix(CI): do not log "ENOENT" when unlink fails after check

* fix: await for mkdirp before continuing
2026-07-17 10:16:07 +02:00
Grandalf
d02098a397 fix(xo-server): don't log the admin password on server creation (#10094)
XO-2647
Introduced by #3579
2026-07-17 09:43:51 +02:00
Sandrine Barrucand
20c9ed8a41 feat(xo6/vm): add New VM button on Host view (#10048) 2026-07-16 16:18:31 +02:00
Mathieu
2f19fda3a5 feat(xo-server/rpu): assert each host can be evacuated right before its evacuation (#10097) 2026-07-16 15:16:17 +02:00
Mathieu
798bdeb973 fix(xo-server): disable auto power on during rolling pool update/reboot (#10104) 2026-07-16 14:34:50 +02:00
MlssFrncJrg
ac52f8b75e fix(perf-alert): update URL generation for alarms to support v6 routing (#10054)
* fix(perf-alert): update URL generation for alarms to support v6 routing

* changelog entry

* fix changelog

* Apply suggestions from code review

Co-authored-by: Mathieu <goore.csmoviz@gmail.com>

---------

Co-authored-by: Mathieu <goore.csmoviz@gmail.com>
2026-07-16 10:25:24 +02:00
Enée DI IORIO
691af588d3 feat(Lite): remove all coming soon (#10068) 2026-07-15 17:26:22 +02:00
Grandalf
cda3c3a724 perf(xo-server): don't wait for errored br to send data (#10025) 2026-07-15 15:32:21 +02:00
John P. Cooper
f2d6b7f0e4 Update XCP-ng version label in supported_hosts.md to bring into sync with supported status (#10092) 2026-07-15 15:20:56 +02:00
Sandrine Barrucand
1afffb8f75 feat(xo6): add possibility to export VM (#9989) 2026-07-15 14:42:36 +02:00
Mathieu
2b7b6baf02 feat(xo-server-openmetrics): estimate per-VM power consumption from CPU (#10031)
* feat(xo-server-openmetrics): estimate per-VM power consumption from CPU
usage

* refactor(xo-server-openmetrics): move hostPowerWatts undefined guard to
caller

* fix(xo-server-openmetrics): log IPMI power read failure as info
2026-07-15 14:06:49 +02:00
Florent BEAUCHAMP
0cfcb998a2 feat(disk-transform): port getBlockIndexesCount to the relevant classes (#10058) 2026-07-15 14:04:53 +02:00
Sandrine Barrucand
3ffd9b1f56 feat(xo6/vm): in the VM actions, add a separator to Delete, placeholder actions and submenu (#10036) 2026-07-15 13:18:34 +02:00
Mathieu
184d65cef1 feat(xo-server): add crash-resistant on-disk observability for RPU/RPR (#10078)
* feat(xo-server): add crash-resistant on-disk observability for RPU/RPR
(XO-2640)

* fix(xo-server): reconcile RPU heartbeats left pending at boot (XO-2640)

* chore(CHANGELOG): add RPU observability entry (XO-2640)

* docs(rpu): document on-disk traces and heartbeat for troubleshooting

* refactor(xo-server): address RPU observability review feedback
2026-07-15 12:23:36 +02:00
Elise-F
a7ba7c6a89 feat(xo6): add VM duplicate action (#9580) 2026-07-15 12:16:34 +02:00
Sandrine Barrucand
25da6d4c4b fix(xo6/xolite): switch CPU and RAM panels (#10059) 2026-07-15 11:47:20 +02:00
amouillard-vates
8b78ab985d feat(xo6/site): add new VM button and connect pool to site tree actions (#10047) 2026-07-15 11:45:19 +02:00
Joris K
2bee8c279d feat(xo6): add possibility to create VIF (#9677) 2026-07-15 11:26:42 +02:00
Bastien Nollet
5de65620f1 fix(xapi-explore-sr): fix crash on unreferenced VDI (#10113)
Co-authored-by: Florent BEAUCHAMP <florent.beauchamp@vates.tech>
2026-07-15 11:20:33 +02:00
Olivier Lambert
b078d3d42d feat(xen-api): reconnect to a surviving pool member when the master is unreachable (#10016)
* feat(xen-api): reconnect to a surviving pool member when the master is unreachable

XO follows a pool master change only through HOST_IS_SLAVE redirection, which
needs the contacted host to be up and answering. That covers a graceful master
hand-over (the old master stays up as a slave and redirects us), but not the
case where the master host itself becomes unreachable while another host takes
over as master: HA automatic failover, or a manual emergency transition. The
stored URL then points at a host that no longer responds, login fails with a
transport error instead of HOST_IS_SLAVE, the existing retry never redirects,
and the connection stays stuck on the dead master.

Maintain a set of pool-member addresses (seeded from the configured target and
optional opts.candidateHostnames, refreshed from host.get_all_records on every
session open) and, when the current target is unreachable at the transport
level, probe the other members in parallel. The first to answer wins; if it is
a slave, its login redirects us to the current master through the existing
HOST_IS_SLAVE retry. XapiError responses (including auth failures) are not
failed over, so wrong credentials still fail fast.

* feat(xo-server): persist pool-member addresses so master failover survives a restart

The xen-api failover relies on an in-memory set of pool-member addresses, which
is lost when xo-server restarts: it then only knows the configured host. That is
exactly the address that is dead when XO runs on the very pool whose master just
failed and was HA-restarted onto a survivor, leaving XO unable to reconnect.

Persist the member addresses on the server record (Redis, JSON-encoded like the
existing error field), refresh them whenever the pool object is seen via the
xen-api candidateHostnames getter, and feed them back as opts.candidateHostnames
when (re)building the connection. After a restart the connection can then probe
the surviving members and reconnect to the new master.

* chore(changelog): reconnect to a surviving pool member on master failure

Add the user-facing changelog entry and list xen-api in the packages to
release for the master-failover reconnect feature.

* fix(xen-api): prune ejected hosts from pool-member failover candidates

host.get_all_records is authoritative current membership, so replace the
candidate set on refresh instead of unioning into it. An ejected host is
typically still alive as its own standalone master with the same
credentials, so leaving it in the set could make a failover probe
silently connect to the wrong pool. The currently-connected target is
preserved since host.address may differ from the address XO used to
reach it.

* fix(xen-api): harden surviving-member failover per review

- reject failover probes on sessionId-based connections (no reusable
  credentials to open a session on another host)
- bracket bare IPv6 addresses (host.address / HOST_IS_SLAVE) before using
  them as URL hostnames
- log the probe session out even when the host answers after the probe
  timeout, to avoid leaking a session
- abort the mid-session failover loop when the connection was torn down or
  replaced while waiting (e.g. user disconnected the server)
- xo-server: drop persisted pool-member addresses when the connection
  identity (host/credentials) changes, so a stale slave list can't send a
  failover to the wrong pool

See #10016
2026-07-15 11:04:16 +02:00
Bastien Nollet
913148ec2f chore(changelog): add previously unreleased package (#10106) 2026-07-13 10:48:01 +02:00
Mathieu
44e5ba4cf5 feat(rest-api): add PATCH /rest/v0/vdis/{id} (#9945) 2026-07-10 15:40:05 +02:00
Mathieu
db795ccfe2 feat(rest-api): ability to set transient for host.disable (#10040) 2026-07-10 15:33:08 +02:00
MlssFrncJrg
519b2bd7e1 feat(rest-api): add RBAC check for pool endpoints (#9891) 2026-07-10 15:27:26 +02:00
Grandalf
b5f5e39ddc feat(rest-api): add array type to FieldDefinition (#10055) 2026-07-10 14:33:00 +02:00
Alina D
f3f8519b7a fix(xo6): repair negative other value in backup repository dashboard (#10044) 2026-07-10 09:38:42 +02:00
Bastien Nollet
1d82c373da feat: release 6.6.2 (#10105) 2026-07-09 16:50:11 +02:00
Bastien Nollet
12b380e806 feat: technical release (#10103)
* feat(@xen-orchestra/fs): 4.9.2

* feat(@xen-orchestra/backup-archive): 1.0.4

* feat(@xen-orchestra/backups): 0.73.7

* feat(@xen-orchestra/proxy): 0.31.2

* feat(xo-server): 5.205.2

* chore(CHANGELOG): update next
2026-07-09 14:31:09 +02:00
Pierre Brunet
f8c9c66c40 fix(backups): remove warning for encrypted xva (size cannot be checked for encrypted data) 2026-07-09 12:00:48 +02:00
Pierre Brunet
1afa1e52ed fix(backups): transfer length and maxStreamLength in pipeline() 2026-07-09 12:00:48 +02:00
Florent BEAUCHAMP
b2a48ffacc fix(fs): compute the output stream precisely when encrypted (#10061)
* fix(fs): compute the output stream precisely when encrypted

the current encryption add 12 byte of initialization vector at
the start + 16 bytes of authentication tag at the end

thus, the destination stream can be bigger than the source stream,
and this length is used to compute the optimal chunk size for s3/
azure

from https://xcp-ng.org/forum/topic/12328/error-mirroring-full-backups-to-backblaze-b2

---------

Co-authored-by: Pierre Brunet <pierre.brunet@vates.tech>
2026-07-09 10:35:40 +02:00
Bastien Nollet
a3077cdb62 feat: release 6.6.1 (#10087) 2026-07-08 09:56:44 +02:00
Bastien Nollet
3ba9523dfe feat: technical release (#10084) 2026-07-07 14:37:05 +02:00
spacotte-vates
377581b44a fix(backups): add warn with debug for snapshot pileup issue (#10076) 2026-07-06 14:56:03 +02:00
Thomas Moraine
090ce7e721 docs(xo): refactor navbar navigation to create a unified documentation ecosystem (#10067)
* docs(xo): overhaul navbar to create a unified doc ecosystem

- Clean up the navbar by dropping the redundant GitHub link (retained in footer).
- Relocate "Blog" to the "What's new in XO 6" sidebar.
- Introduce direct navbar links for XCP-ng and Vates VMS.
- Rename "Documentation" to "Xen Orchestra".

This aligns the navigation layout across our three documentation sites, allowing readers to smoothly transition between ecosystems with a fully unified experience.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>

* docs(xo): move home link from header to footer

To make the navbar cleaner and make space
for the links to the other documentation websites
We're moving the Home link from the header to the footer
and renaming the link to 'About Xen Orchestra'.
Also, we're displaying the 'What's new in XO 6' section again
which now contains a link to the XO blog

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>
2026-07-03 10:30:40 +02:00
Thomas Moraine
d53dd3e990 docs(xo): import devops tools documentation from vates vms (#10062) 2026-07-03 09:24:44 +02:00
Thomas Moraine
1b0dbc7d3b docs(xo6): hide categories that dont contain any actual pages (#10066)
Recently we've introduced new sections for the xo6 category of the XO doc.
These categories were meant to be filled later with new pages.
The pages were created as placeholders, but didn't actually contain any text, just titles.
These made readers confused, so this commit
Hides the sections from the sidebar until we update them
With actual content.

Signed-off-by: Thomas Moraine <thomas.moraine@vates.tech>
2026-07-03 08:44:14 +02:00
Florent BEAUCHAMP
bb4daac07a fix(xo-server): store rrd as Float32 instead of string (#10039) 2026-07-02 15:57:43 +02:00
spacotte-vates
63f8d624fd fix(backups): improve resume of backup merge failure (#10053)
Introduced by #9765

When a backup merge fails on a VHD file, the footer might be missing. This caused a footer1 !== footer2 error and triggered a full backup while not deleting the previous chain and resulted in all further backup jobs to be displayed as failures even though the new backup chain was working properly.

The fix allows the cleanVm to resume the merge where it stops even if the VHD file footer is missing.
2026-07-01 17:01:38 +02:00
1684 changed files with 38601 additions and 13382 deletions

View File

@@ -85,6 +85,21 @@ module.exports = {
XO_LITE_GIT_HEAD: true,
},
rules: {
'import/extensions': [
'error',
'ignorePackages',
{
pattern: { ts: 'always', vue: 'always' },
checkTypeImports: true,
// '@core/*' and '@/*' look like scoped packages to the plugin, which 'ignorePackages' would skip
pathGroupOverrides: [
{ pattern: '@core/packages/*', action: 'ignore' }, // barrel files
{ pattern: '@core/icons', action: 'ignore' },
{ pattern: '@core/**', action: 'enforce' },
{ pattern: '@/**', action: 'enforce' },
],
},
],
'import/order': [
'error',
{
@@ -254,6 +269,7 @@ module.exports = {
'zh-Hans',
'sk',
'pt',
'ar',
],
},
],

View File

@@ -1,21 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Check for dev routes in route-map.d.ts
ROUTE_MAP="@xen-orchestra/web/src/route-map.d.ts"
if git diff --cached --name-only | grep -qF "$ROUTE_MAP"; then
if git diff --cached -- "$ROUTE_MAP" | grep -qE "^\+.*(/dev/|src/pages/dev/)"; then
echo ""
echo "Warning: route-map.d.ts contains staged dev routes (/dev/*)."
echo "These are development-only routes and should not be committed."
printf "Commit anyway? [y/N] "
read REPLY </dev/tty
case "$REPLY" in
[yY][eE][sS]|[yY]) ;;
*) echo "Aborted. Use --no-verify to bypass this check."; exit 1 ;;
esac
echo ""
fi
fi
npx lint-staged

View File

@@ -5,3 +5,7 @@
# Generated files
/@xen-orchestra/web/src/route-map.d.ts
/@xen-orchestra/lite/src/route-map.d.ts
# Docusaurus MDX content: prettier's markdown parser corrupts JSX
# comments ({/* … */} becomes {/_ … _/}) and other MDX constructs
/docs/docs/**/*.md

View File

@@ -24,7 +24,7 @@
},
"dependencies": {
"@vates/multi-key-map": "^0.2.0",
"@xen-orchestra/async-map": "^0.1.3",
"@xen-orchestra/async-map": "^0.1.4",
"@xen-orchestra/log": "^0.7.2",
"ensure-array": "^1.0.0"
},

View File

@@ -19,12 +19,12 @@
},
"main": "./index.mjs",
"dependencies": {
"@xen-orchestra/fs": "^4.9.1",
"@xen-orchestra/fs": "^4.9.3",
"@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.0"
"vhd-lib": "^4.16.1"
},
"bin": {
"xo-fuse-vhd": "./cli.mjs"

View File

@@ -19,6 +19,12 @@ export class NbdDisk extends RandomAccessDisk {
/** @type {number} */
#blockSize
/** @type {number | undefined} */
#hasBlockCursor
/** @type {number | undefined} */
#hasBlockPreviousIndex
constructor(nbdInfos, blockSize, { dataMap } = {}) {
super()
this.#blockSize = blockSize
@@ -27,11 +33,38 @@ export class NbdDisk extends RandomAccessDisk {
}
#processDatamap(rawDataMap) {
return rawDataMap
.filter(({ type }) => type === 0)
const ranges = rawDataMap
.filter(({ type, length }) => type === 0 && length > 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>}
@@ -117,6 +150,34 @@ 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}
@@ -125,8 +186,32 @@ export class NbdDisk extends RandomAccessDisk {
if (!this.#dataMap) {
throw new Error("can't hasBlock before init")
}
const blockStart = index * this.getBlockSize()
const blockEnd = (index + 1) * this.getBlockSize()
return this.#dataMap.some(({ offset, length }) => offset + length > blockStart && offset < blockEnd)
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
}
}

View File

@@ -0,0 +1,127 @@
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

@@ -7,6 +7,7 @@ const { warn } = createLogger('vates:nbd-client:multi')
export default class MultiNbdClient {
#clients = []
#nbdConcurrency
#nextClient = 0
#options
#readAhead
#settings
@@ -97,8 +98,31 @@ export default class MultiNbdClient {
* @returns {Promise<Buffer>}
*/
async readBlock(index, size = NBD_DEFAULT_BLOCK_SIZE) {
const clientId = index % this.#clients.length
return this.#clients[clientId].readBlock(index, size)
const clientId = this.#nextClient++ % this.#clients.length
const client = this.#clients[clientId]
try {
return await client.readBlock(index, size)
} catch (err) {
// client.readBlock() already exhausted its own retries/reconnects: this connection is dead.
// Evict it so future reads stop being routed to it, and retry this read on a surviving
// client, since the data is usually still reachable through the others.
this.#evict(client)
if (this.#clients.length === 0) {
throw err
}
warn(`evicted a dead nbd client, retrying block ${index} on a remaining client`, { err })
return this.readBlock(index, size)
}
}
// no-op if `client` was already evicted by a concurrent failed read on the same client
#evict(client) {
const i = this.#clients.indexOf(client)
if (i === -1) {
return
}
this.#clients.splice(i, 1)
client.disconnect().catch(() => {})
}
/**

View File

@@ -0,0 +1,130 @@
import { describe, it, mock } from 'node:test'
import assert from 'node:assert'
// MultiNbdClient instantiates NbdClient itself (`import NbdClient from './index.mjs'`), so the
// only way to control individual connections from a unit test is to replace that module with a
// fake before importing multi.mjs.
const created = []
class FakeNbdClient {
constructor(nbdInfo) {
this.nbdInfo = nbdInfo
this.disconnected = false
// overridden per-test after connect() to script this instance's behavior
this.readBlock = async () => {
throw new Error('readBlock not configured for this fake client')
}
created.push(this)
}
async connect() {}
async disconnect() {
this.disconnected = true
}
async getMap() {
return []
}
}
mock.module('./index.mjs', {
defaultExport: FakeNbdClient,
})
const { default: MultiNbdClient } = await import('./multi.mjs')
// a single settings entry is enough: connect() reuses candidates across concurrent slots, so
// nbdConcurrency still yields that many distinct FakeNbdClient instances
async function connectWithFakes(nbdConcurrency) {
created.length = 0
const client = new MultiNbdClient({ address: 'fake-host' }, { nbdConcurrency })
await client.connect()
return { client, fakes: created.slice() }
}
describe('MultiNbdClient.readBlock eviction', () => {
it('evicts a client whose readBlock rejects and retries on a surviving client', async () => {
const { client, fakes } = await connectWithFakes(2)
const [dead, alive] = fakes
dead.readBlock = async () => {
throw new Error('connection is dead')
}
alive.readBlock = async index => Buffer.from([index])
// index 0 initially routes to `dead` (0 % 2 === 0)
const data = await client.readBlock(0)
assert.deepStrictEqual(data, Buffer.from([0]))
assert.strictEqual(dead.disconnected, true, 'the dead client should have been disconnected')
// future reads must no longer be routed to the evicted client: with only `alive` left,
// every index should now succeed through it
alive.readBlock = async index => Buffer.from([index])
const data2 = await client.readBlock(1)
assert.deepStrictEqual(data2, Buffer.from([1]))
})
it('rejects once every client has been evicted, instead of retrying forever', async () => {
const { client, fakes } = await connectWithFakes(2)
const boom = new Error('connection is dead')
for (const fake of fakes) {
fake.readBlock = async () => {
throw boom
}
}
await assert.rejects(() => client.readBlock(0), boom)
assert.ok(
fakes.every(fake => fake.disconnected),
'every client should have been evicted (and disconnected) before giving up'
)
})
it('evicting the same dead client from concurrent failed reads is idempotent', async () => {
const { client, fakes } = await connectWithFakes(2)
const [dead, alive] = fakes
dead.readBlock = async () => {
throw new Error('connection is dead')
}
alive.readBlock = async index => Buffer.from([index])
let disconnectCalls = 0
dead.disconnect = async () => {
disconnectCalls++
dead.disconnected = true
}
// routing is round-robin by call order (0, 1, 0) over a 2-client pool: the 1st and 3rd
// calls both land on `dead` before either failure has been handled, so they race to evict
// the same client. The exact interleaving isn't guaranteed, only that eviction is safe
// either way and every read still completes.
const [data0, data1, data2] = await Promise.all([client.readBlock(10), client.readBlock(11), client.readBlock(12)])
assert.deepStrictEqual(data0, Buffer.from([10]))
assert.deepStrictEqual(data1, Buffer.from([11]))
assert.deepStrictEqual(data2, Buffer.from([12]))
assert.strictEqual(disconnectCalls, 1, 'the dead client must only be evicted/disconnected once')
})
})
describe('MultiNbdClient.readBlock routing', () => {
it('distributes reads round-robin by call order, not by index residue', async () => {
const { client, fakes } = await connectWithFakes(4)
const readsPerClient = fakes.map(() => 0)
fakes.forEach((fake, i) => {
fake.readBlock = async index => {
readsPerClient[i]++
return Buffer.from([index])
}
})
// a CBT-style changed-block set striding by exactly `nbdConcurrency`: under the old
// `index % clients.length` routing this would collapse entirely onto a single client
const stridedIndexes = Array.from({ length: 20 }, (_, i) => i * 4)
for (const index of stridedIndexes) {
await client.readBlock(index)
}
assert.deepStrictEqual(readsPerClient, [5, 5, 5, 5])
})
})

View File

@@ -13,7 +13,7 @@
"url": "https://vates.fr"
},
"license": "ISC",
"version": "3.4.0",
"version": "3.5.1",
"engines": {
"node": ">=14.0"
},
@@ -21,11 +21,11 @@
"dependencies": {
"@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.1",
"@xen-orchestra/async-map": "^0.1.4",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/log": "^0.7.2",
"promise-toolbox": "^0.21.0",
"xen-api": "^4.7.8"
"xen-api": "^4.9.0"
},
"devDependencies": {
"tap": "^18.7.0",
@@ -33,6 +33,7 @@
},
"scripts": {
"postversion": "npm publish --access public",
"test-integration": "tap --allow-incomplete-coverage"
"test": "node --experimental-test-module-mocks --test",
"test-integration": "tap --allow-incomplete-coverage tests/*.integ.mjs"
}
}

View File

@@ -153,7 +153,13 @@ CYu1Xn/FVPx1HoRgWc7E8wFhDcA/P3SJtfIQWHB9FzSaBflKGR4t8WCE2eE8+cTB
nbdServer = await spawnNbdKit(path)
}
}
assert.rejects(() => client.readBlock(100, CHUNK_SIZE))
// reading past the end of the export must reject: a single client so the failure isn't
// multiplied by nbdConcurrency evicting and retrying on every other (equally healthy, equally
// unable to satisfy this out-of-range request) client
const singleClient = new MultiNbdClient(connectionSettings, { nbdConcurrency: 1, readAhead: 2 })
await singleClient.connect()
await assert.rejects(() => singleClient.readBlock(100, CHUNK_SIZE))
await singleClient.disconnect()
await client.disconnect()
// double disconnection shouldn't pose any problem

View File

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

View File

@@ -755,9 +755,9 @@ export type TrafficRuleDirection = 'from' | 'to' | 'from/to'
export type RawTrafficRule = {
allow: boolean
protocol: string
protocol: TrafficRuleProtocol
ipRange: string
direction: string
direction: TrafficRuleDirection
port?: string
}

View File

@@ -5,3 +5,4 @@ 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

@@ -0,0 +1,96 @@
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 = { optional?: boolean; nullable?: boolean } & (
| {
type: 'string'
example?: string
}
| {
type: 'boolean'
example?: boolean
}
| {
type: 'number'
example?: number
}
| {
type: 'enum'
enum: string[]
example?: string
}
| {
type: 'object'
fields: Record<string, FieldDefinition>
}
| {
type: 'array'
items: FieldDefinition
example?: unknown[]
}
)
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,19 +1,24 @@
import { Branded } from '../common.mjs'
import type { XoGroup, XoUser } from '../xo.mjs'
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
}
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 XoAclSupportedActionsByResource = {
[resource: string]: Record<string, unknown>

View File

@@ -233,6 +233,36 @@ 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,
@@ -328,6 +358,7 @@ export interface Xapi {
vgpuType?: XoVgpuType['id']
gpuGroup?: XoGpuGroup['id']
copyHostBiosStrings?: boolean
highAvailability?: XoVm['high_availability']
hvmBootFirmware?: 'uefi' | 'bios'
secureBoot?: boolean
},
@@ -380,7 +411,7 @@ export interface Xapi {
): Promise<Readable & { length?: number }>
VDI_importContent(
vdiRef: XenApiVdi['$ref'],
stream: Readable,
stream: Readable | Buffer,
opts: { cancelToken?: unknown; format: SUPPORTED_VDI_FORMAT }
): Promise<void>
VIF_create(
@@ -419,8 +450,12 @@ export interface Xapi {
pathname: string,
params?: { host?: XenApiHost; query?: Record<string, unknown>; task?: boolean | XenApiTask['$ref'] }
): Promise<{ body: Readable }>
clearHost(host: Pick<XenApiHostWrapped, '$ref' | '$pool'>, force?: boolean): Promise<void>
disableHost(hostId: XoHost['id']): Promise<void>
clearHost(
host: Pick<XenApiHostWrapped, '$ref' | '$pool'>,
force?: boolean,
opts?: { transient?: boolean }
): Promise<void>
disableHost(hostId: XoHost['id'], opts?: { transient?: boolean }): Promise<void>
enableHost(hostId: XoHost['id']): Promise<void>
getRecordByUuid<
Type extends WrappedXenApiRecord['$type'],

View File

@@ -1,6 +1,5 @@
import { EventEmitter } from 'node:stream'
import type {
AnyXoBackupJob,
AnyXoJob,
AnyXoLog,
XapiXoRecord,
@@ -21,6 +20,7 @@ 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,6 +195,7 @@ 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 },
@@ -203,6 +204,8 @@ export type XoApp = {
backupGuard(poolId: XoPool['id']): Promise<void>
/* Throw if no authorization */
checkFeatureAuthorization(featureCode: FeatureCode): Promise<void>
/* validate, apply and persist the configuration of a plugin */
configurePlugin(id: string, configuration: unknown, mergeWithExisting?: boolean): Promise<void>
/* connect a server (XCP-ng/XenServer) */
connectXenServer(id: XoServer['id']): Promise<void>
// TODO: replace all XoAclBasePrivilege with a more strict type. (discriminate union)
@@ -233,7 +236,11 @@ 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']): Promise<boolean>
deleteAclV2GroupRole(
groupId: XoGroup['id'],
roleId: XoAclRole['id'],
opts?: { bypassAuthorization?: boolean }
): 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>
@@ -246,10 +253,22 @@ export type XoApp = {
getAclV2Privilege(id: XoAclBasePrivilege['id']): Promise<XoAclBasePrivilege>
getAclV2Privileges(): Promise<XoAclBasePrivilege[]>
getAclV2RolePrivileges(roleId: XoAclRole['id']): Promise<XoAclBasePrivilege[]>
getAclV2Role(id: XoAclRole['id']): Promise<XoAclRole>
deleteAclV2UserRole(userId: XoUser['id'], roleId: XoAclRole['id']): Promise<boolean>
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 }>[]>
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 }>[]>
@@ -311,10 +330,11 @@ export type XoApp = {
xo: Record<XoBackupRepository['id'], XoConfigBackupArchive[]>
pool: Record<XoBackupRepository['id'], Record<XoPool['id'], XoPoolBackupArchive[]>>
}>
/** `null` when the listing of a backup repository failed */
listVmBackupsNg(
backupRepositoryIds: XoBackupRepository['id'][],
opts?: { _forceRefresh?: boolean; vmId: XoVm['id'] }
): Promise<Record<XoBackupRepository['id'], Record<XoVm['id'], XoVmBackupArchive[]>>>
opts?: { _forceRefresh?: boolean; vmId?: XoVm['id'] }
): Promise<Record<XoBackupRepository['id'], Record<XoVm['id'], XoVmBackupArchive[]> | null>>
pingRemote(id: XoBackupRepository['id']): Promise<{ success: true }>
/** Allow to add a new server in the DB (XCP-ng/XenServer) */
registerXenServer(
@@ -324,8 +344,11 @@ export type XoApp = {
readOnly?: XoServer['readOnly']
}
): Promise<XoServer>
rollingPoolReboot(pool: XoPool, opts?: { parentTask?: VatesTask }): Promise<void>
rollingPoolUpdate(pool: XoPool, opts?: { rebootVm?: boolean; parentTask?: VatesTask }): Promise<void>
rollingPoolReboot(pool: XoPool, opts?: { parentTask?: VatesTask; shutdownPinnedVms?: boolean }): Promise<void>
rollingPoolUpdate(
pool: XoPool,
opts?: { rebootVm?: boolean; parentTask?: VatesTask; shutdownPinnedVms?: boolean }
): 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

@@ -19,7 +19,7 @@ import type {
VM_POWER_STATE,
} from './common.mjs'
import type * as CMType from './lib/complex-matcher.mjs'
import { XoAclPrivilege, XoAclRole, XoAclSupportedActionsByResource } from './lib/xen-orchestra-acl.mjs'
import { XoAclBasePrivilege, XoAclRole } from './lib/xen-orchestra-acl.mjs'
import type { XenApiHost, XenApiPool } from './xen-api.mjs'
type BaseXapiXo = {
@@ -76,7 +76,7 @@ type BaseXoVm = BaseXapiXo & {
expNestedHvm: boolean
isNestedVirtEnabled: boolean
hasVendorDevice: boolean
high_availability: string
high_availability: 'best-effort' | 'restart' | ''
installTime?: number | null
isFirmwareSupported: boolean
memory: {
@@ -222,6 +222,7 @@ export type XoGroup = {
provider?: string
providerGroupId?: string
users: XoUser['id'][]
aclRoleIds: XoAclRole['id'][]
}
export type XoHost = BaseXapiXo & {
@@ -613,7 +614,7 @@ export type XoSr = BaseXapiXo & {
VDIs: AnyXoVdi['id'][]
allocationStrategy?: 'thin' | 'thick' | 'unknown'
content_type: string
content_type: 'user' | 'iso' | 'disk'
current_operations: Record<string, STORAGE_OPERATIONS>
id: Branded<'SR'>
inMaintenanceMode: boolean
@@ -624,7 +625,28 @@ export type XoSr = BaseXapiXo & {
shared: boolean
size: number
sm_config: Record<string, string>
SR_type: 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'
tags: string[]
type: 'SR'
usage: number
@@ -867,10 +889,7 @@ export type XapiXoRecord =
| XoVtpm
| XoSm
export type NonXapiXoRecord<
TActionsByResource extends XoAclSupportedActionsByResource = never,
TResource extends string = never,
> =
export type NonXapiXoRecord =
| AnyXoBackupArchive
| AnyXoJob
| AnyXoLog
@@ -883,12 +902,9 @@ export type NonXapiXoRecord<
| XoTask
| XoUser
| XoAclRole
| XoAclPrivilege<TActionsByResource, TResource>
| XoAclBasePrivilege
export type XoRecord<
TActionsByResource extends XoAclSupportedActionsByResource = never,
TResource extends string = never,
> = XapiXoRecord | NonXapiXoRecord<TActionsByResource, TResource>
export type XoRecord = XapiXoRecord | NonXapiXoRecord
export type AnyXoVm = XoVm | XoVmSnapshot | XoVmTemplate | XoVmController

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.4.0",
"version": "1.6.1",
"license": "AGPL-3.0-or-later",
"private": false,
"type": "module",
@@ -30,7 +30,7 @@
},
"devDependencies": {
"@eslint/js": "^9.19.0",
"@vates/types": "^1.28.0",
"@vates/types": "^2.0.1",
"rimraf": "^6.0.1",
"typescript": "~5.6",
"typescript-eslint": "^8.61.0"

View File

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

View File

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

View File

@@ -7,6 +7,9 @@ export default {
'migrate-send': true,
read: true,
update: {
name_description: true,
name_label: true,
size: true,
tags: true,
},
}

View File

@@ -13,11 +13,11 @@ const wrapCall = (fn, arg, thisArg) => {
*
* WARNING: Does not handle plain objects
*
* @template Item,This
* @template Item, Result, [This=Iterable<Item>]
* @param {Iterable<Item>} iterable
* @param {(this: This, item: Item) => (Item | PromiseLike<Item>)} mapFn
* @param {This} [thisArg]
* @returns {Promise<Item[]>}
* @param {(this: This, item: Item) => (Result | PromiseLike<Result>)} mapFn
* @param {This} [thisArg] defaults to `iterable`
* @returns {Promise<Result[]>}
*/
exports.asyncMap = function asyncMap(iterable, mapFn, thisArg = iterable) {
return Promise.all(Array.from(iterable, mapFn, thisArg))
@@ -26,11 +26,11 @@ exports.asyncMap = function asyncMap(iterable, mapFn, thisArg = iterable) {
/**
* Like `asyncMap` but wait for all promises to settle before rejecting
*
* @template Item,This
* @template Item, Result, [This=Iterable<Item>]
* @param {Iterable<Item>} iterable
* @param {(this: This, item: Item) => (Item | PromiseLike<Item>)} mapFn
* @param {This} [thisArg]
* @returns {Promise<Item[]>}
* @param {(this: This, item: Item) => (Result | PromiseLike<Result>)} mapFn
* @param {This} [thisArg] defaults to `iterable`
* @returns {Promise<Result[]>}
*/
exports.asyncMapSettled = function asyncMapSettled(iterable, mapFn, thisArg = iterable) {
return new Promise((resolve, reject) => {

View File

@@ -1,7 +1,7 @@
{
"private": false,
"name": "@xen-orchestra/async-map",
"version": "0.1.3",
"version": "0.1.4",
"license": "ISC",
"description": "Promise.all + map for all iterables",
"keywords": [

View File

@@ -1,6 +1,6 @@
{
"name": "@xen-orchestra/backup-archive",
"version": "1.0.2",
"version": "1.1.2",
"description": "Helper to handle generic backup archives",
"license": "ISC",
"author": "",
@@ -21,23 +21,24 @@
"tar-stream": "^3.1.8",
"@types/tar-stream": "^3.1.4",
"tmp": "^0.2.1",
"@vates/types": "^1.28.0"
"@vates/types": "^2.0.1"
},
"dependencies": {
"@xen-orchestra/log": "^0.7.1",
"@xen-orchestra/fs": "^4.9.1",
"@xen-orchestra/disk-transform": "^1.3.1",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/disk-transform": "^1.3.3",
"@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.14.7"
"vhd-lib": "^4.16.1"
},
"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

@@ -21,6 +21,7 @@ import { limitConcurrency } from 'limit-concurrency-decorator'
import assert from 'node:assert/strict'
const defaultMergeLimiter = limitConcurrency(1)
const MERGE_STATE_FILE_RE = /^\.(.+)\.merge\.json$/
/**
* Tracks the disk chain for a single VDI across all backup snapshots.
* Owns merge and deletion decisions for its chain given which disks are still
@@ -84,11 +85,23 @@ export class RemoteDiskLineage {
}
}
const mergeParentPaths = new Set<string>()
for (const filePath of files) {
const match = MERGE_STATE_FILE_RE.exec(basename(filePath))
if (match !== null) {
mergeParentPaths.add(normalize(this.#vdiDir + '/' + match[1]))
}
}
const uuidToPath = new Map<string, string>()
for (const diskPath of this.#diskPaths) {
let disk: RemoteDisk | undefined
try {
disk = await openDisk({ handler: this.#handler, path: diskPath })
if (mergeParentPaths.has(diskPath)) {
disk = await openDisk({ handler: this.#handler, path: diskPath, force: true })
} else {
disk = await openDisk({ handler: this.#handler, path: diskPath })
}
} catch (error) {
if (error?.code === 'NOT_SUPPORTED' && this.#opts.merge) {
throw error

View File

@@ -10,6 +10,11 @@ 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,6 +39,10 @@ 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,
@@ -183,7 +187,7 @@ export class VmBackupDirectory implements VmBackupInterface {
{ concurrency: 2 }
)
if (allMergedSizes.size > 0 || cacheNeedsRegen) {
if (allMergedSizes.size > 0 || cacheNeedsRegen || this.#cacheOutOfSync) {
await this.#regenerateCache()
}
@@ -214,7 +218,8 @@ 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
if (actual !== expected) {
this.#cacheOutOfSync = actual !== expected
if (this.#cacheOutOfSync) {
this.opts.logWarn('unexpected number of entries in backup cache', { path: cachePath, actual, expected })
}
}

View File

@@ -43,12 +43,19 @@ const isValidTar = async (handler: RemoteHandlerAbstract, size: number, fd: File
return buf.every(byte => byte === 0)
}
export async function isValidXva(handler: RemoteHandlerAbstract, filePath: string): Promise<boolean> {
export async function isValidXva(
handler: RemoteHandlerAbstract,
filePath: string,
metadataSize?: number
): Promise<boolean> {
// size is longer when encrypted + reading part of an encrypted file is not implemented
if (handler.isEncrypted) {
return true
const size = await handler.getSizeOnDisk(filePath)
return size > 20
}
let isValid = true
const fd = await handler.openFile(filePath, 'r')
try {
const size = await handler.getSize(filePath)
@@ -56,13 +63,19 @@ export async function isValidXva(handler: RemoteHandlerAbstract, filePath: strin
// neither a valid gzip nor tar
return false
}
let validSize = true
if (metadataSize !== undefined) {
validSize = metadataSize === size
}
return (await isCompressedFile(handler, fd))
const validDisk = (await isCompressedFile(handler, fd))
? true // compressed files cannot be validated at this time
: await isValidTar(handler, size, fd)
isValid = validSize && validDisk
} finally {
handler.closeFile(fd).catch(noop)
}
return isValid
}
const noop = (): void => {}
@@ -101,28 +114,22 @@ export class VmFullBackupArchive implements VmBackupInterface {
*/
async check(): Promise<CheckResult> {
if (this.isValid === undefined) {
let fileSize = 0
let validDisk = false
let validSize = true
try {
fileSize = await this.handler.getSize(this.xvaPath)
validDisk = await isValidXva(this.handler, this.xvaPath)
this.isValid = await isValidXva(this.handler, this.xvaPath, this.metadata.size)
} catch (error) {
validDisk = false
this.isValid = false
if (error?.code === 'ENOENT') {
this.missingDisk = true
}
this.opts.logWarn('Issue while checking XVA', { error })
}
try {
await this.handler.getSize(`${this.xvaPath}.checksum`)
} catch (error) {
this.opts.logWarn('Checksum file not valid, not blocking', { error })
if (!this.handler.isEncrypted) {
try {
await this.handler.getSize(`${this.xvaPath}.checksum`)
} catch (error) {
this.opts.logWarn('Checksum file not valid, not blocking', { error })
}
}
if (this.metadata.size !== undefined) {
validSize = this.metadata.size === fileSize
}
this.isValid = fileSize > 0 && validSize && validDisk
}
if (!this.isValid) {
if (this.missingDisk) {

View File

@@ -8,13 +8,19 @@ import { getHandler } from '@xen-orchestra/fs'
import { pFromCallback } from 'promise-toolbox'
// eslint-disable-next-line n/no-missing-import
import { VmBackupDirectory } from '../dist/VmBackupDirectory.mjs'
import { RemoteVhdDisk } from '../dist/disks/RemoteVhdDisk.mjs'
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/'
@@ -412,6 +418,73 @@ test('it merges a chain of multiple consecutive orphan ancestors in one pass', a
assert.equal(remainingVhds.includes('child.vhd'), false)
})
test('it resumes, through cleanVm, an interrupted merge whose ancestor lost its footer', async () => {
// Reproduces the production "footer1 !== footer2" failure end-to-end via the full cleanVm
// pipeline. ancestor (full) <- child (differencing, the active backup).
const ancestor = await generateVhd(`${basePath}/ancestor.vhd`, { blocks: [0, 1] })
await generateVhd(`${basePath}/child.vhd`, {
header: { parentUnicodeName: 'ancestor.vhd', parentUuid: ancestor.footer.uuid },
blocks: [2, 3, 4, 5],
})
await handler.writeFile(
`${rootPath}/metadata.json`,
JSON.stringify({ mode: 'delta', size: 12000, vhds: [`${relativePath}/child.vhd`] })
)
// Simulate a merge killed mid-transfer: write 2 of the 4 child blocks into the ancestor
// (which overwrites its end footer) then throw before mergeMetadata() rewrites the footer.
// This leaves the ancestor footerless AND a `.merge.json` state file — the exact post-crash
// state that makes cleanVm take the resume path.
const parent = new RemoteVhdDisk({ handler, path: `${basePath}/ancestor.vhd` })
const child = new RemoteVhdDisk({ handler, path: `${basePath}/child.vhd` })
await parent.init({ force: false })
await child.init({ force: false })
const merger = new MergeRemoteDisk(handler, { removeUnused: true, writeStateDelay: 0 })
let written = 0
const realWriteBlock = parent.writeBlock.bind(parent)
parent.writeBlock = async diskBlock => {
if (written === 2) {
throw new Error('simulated interruption')
}
written++
return realWriteBlock(diskBlock)
}
await assert.rejects(merger.merge(parent, child), /simulated interruption/)
assert.ok(
(await handler.list(basePath)).includes('.ancestor.vhd.merge.json'),
'an interrupted-merge state file should remain'
)
// Full pipeline: cleanVm must recognize the interrupted merge and resume it — opening the
// footerless ancestor through the chain without throwing "footer1 !== footer2".
await VmBackupDirectory.cleanVm(handler, rootPath, {
remove: true,
merge: true,
logInfo: () => {},
logWarn: () => {},
})
// The merge completed: the ancestor was consolidated into child.vhd and the state file is gone.
const remaining = await handler.list(basePath)
assert.equal(remaining.includes('.ancestor.vhd.merge.json'), false, 'state file removed after successful resume')
assert.equal(remaining.includes('ancestor.vhd'), false, 'ancestor consolidated into the merge target')
assert.equal(remaining.includes('child.vhd'), true, 'merge target remains')
// No blocks lost: the resumed merge wrote the blocks (4, 5) that were never written before
// the crash, so the consolidated disk holds the full set.
const merged = new RemoteVhdDisk({ handler, path: `${basePath}/child.vhd` })
await merged.init({ force: false })
try {
assert.deepEqual(merged.getBlockIndexes(), [0, 1, 2, 3, 4, 5], 'all blocks present after resumed merge')
} finally {
await merged.close()
}
// The backup is consistent, so its metadata is preserved.
assert.ok((await handler.list(rootPath)).includes('metadata.json'), 'metadata should be preserved')
})
test('it does not warn "missing target of alias" for aliases deleted by merge', async () => {
// Regression: RemoteDiskLineage.#cleanOrphanDataFiles iterated #diskPaths entries just
// deleted during the same clean() call's merge phase, producing false "missing target of
@@ -759,3 +832,28 @@ 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

@@ -312,4 +312,12 @@ 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

@@ -15,9 +15,10 @@ import { RemoteVhdDiskChain } from './RemoteVhdDiskChain.mjs'
* @param {string} params.path
* @param {string | undefined} params.until
* @param {boolean} [params.force]
* @param {boolean} [params.ignoreBlockIndexes] - skip reading the block allocation table of each disk (cheaper, but blocks can't be read)
* @returns {Promise<RemoteDisk>}
*/
async function _openDiskChain($defer, { handler, path, until, force = false }) {
async function _openDiskChain($defer, { handler, path, until, force = false, ignoreBlockIndexes = false }) {
/**
* @type {RemoteVhdDisk}
*/
@@ -29,16 +30,18 @@ async function _openDiskChain($defer, { handler, path, until, force = false }) {
$defer.onFailure(() => Promise.all(disks.map(disk => disk.close())))
disk = new RemoteVhdDisk({ handler, path })
await disk.init({ force })
await disk.init({ force, ignoreBlockIndexes })
disks.push(disk)
let foundRootDisk = until === undefined
while (disk.isDifferencing()) {
disk = await disk.openParent()
if (disk.getPath() === until) {
if (disk.getParentPath() === until) {
foundRootDisk = true
await disk.close()
break
}
// Instantiate + init the parent directly (instead of openParent()) so the
// block allocation table read can be skipped when ignoreBlockIndexes is set.
disk = /** @type {RemoteVhdDisk} */ (disk.instantiateParent())
await disk.init({ force, ignoreBlockIndexes })
disks.unshift(disk)
}
if (!foundRootDisk) {
@@ -49,6 +52,6 @@ async function _openDiskChain($defer, { handler, path, until, force = false }) {
}
/**
* @type {(params: { handler: RemoteHandlerAbstract, path: string, until?: string, force?: boolean }) => Promise<RemoteDisk>}
* @type {(params: { handler: RemoteHandlerAbstract, path: string, until?: string, force?: boolean, ignoreBlockIndexes?: boolean }) => Promise<RemoteDisk>}
*/
export const openDiskChain = defer(_openDiskChain)

View File

@@ -7,9 +7,9 @@
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"dependencies": {
"@vates/async-each": "^1.0.3",
"@xen-orchestra/async-map": "^0.1.3",
"@xen-orchestra/backups": "^0.73.5",
"@xen-orchestra/fs": "^4.9.1",
"@xen-orchestra/async-map": "^0.1.4",
"@xen-orchestra/backups": "^0.74.2",
"@xen-orchestra/fs": "^4.9.3",
"filenamify": "^6.0.0",
"getopts": "^2.2.5",
"lodash": "^4.18.0",
@@ -28,7 +28,7 @@
"scripts": {
"postversion": "npm publish --access public"
},
"version": "1.1.13",
"version": "1.1.14",
"license": "AGPL-3.0-or-later",
"author": {
"name": "Vates SAS",

View File

@@ -315,6 +315,11 @@ 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)
}
}
}
@@ -383,8 +388,7 @@ export class RemoteAdapter {
return
}
// detached async action, will not reject
this._writeCache(path, backups)
await this._writeCache(path, backups)
return backups
}
@@ -449,7 +453,7 @@ export class RemoteAdapter {
return path
}
async writeVhd(path, disk, { validator = noop, writeBlockConcurrency } = {}) {
async writeVhd(path, disk, { validator = noop, writeBlockConcurrency, uuid, parentUuid, parentPath } = {}) {
const handler = this._handler
if (this.useVhdDirectory()) {
@@ -461,11 +465,19 @@ export class RemoteAdapter {
concurrency: writeBlockConcurrency,
validator,
compression: 'brotli',
uuid,
parentUuid,
parentPath,
},
})
} else {
const stream = await toVhdStream(disk)
const size = await this.outputStream(path, stream, { validator, checksum: false })
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,
})
await validator(path)
return size
}

View File

@@ -1,7 +1,8 @@
import { strict as assert } from 'node:assert'
import test from 'node:test'
import { execFile } from 'node:child_process'
import { copyFile, mkdtemp, rm } from 'node:fs/promises'
import { copyFile, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { Stream } from 'node:stream'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { promisify } from 'node:util'
@@ -39,6 +40,37 @@ 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,6 +12,7 @@ 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'
@@ -297,7 +298,15 @@ 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.
outputStream = tar.c({ cwd: path, gzip: true, jobs: 1 }, paths.map(makeRelative))
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 })
resolve(outputStream)
} else if (format === 'zip') {
const zip = new ZipFile()

View File

@@ -16,42 +16,15 @@ import { toQcow2Stream } from '@xen-orchestra/qcow2'
const ensureArray = value => (value === undefined ? [] : Array.isArray(value) ? value : [value])
const orderedMemoryLimits = ['memory_static_min', 'memory_dynamic_min', 'memory_dynamic_max', 'memory_static_max']
// The dynamic memory range MUST respect this inequality at any moment: static_min <= dynamic_min <= dynamic_max <= static_max.
// We must update these properties in the right order to avoid XAPI error.
// The order depends on the values. It can be an increase, a decrease or a mix of both, so any order could be required.
// VM.set_memory_limits sets all four fields atomically, so there is no intermediate state for XAPI to reject
export async function updateMemoryFields(xapi, targetVm, vmRecord) {
const memoryValues = {}
for (const key of orderedMemoryLimits) {
memoryValues[key] = {
currentValue: targetVm[key],
newValue: vmRecord[key] ?? targetVm[key],
}
}
const staticMin = vmRecord.memory_static_min ?? targetVm.memory_static_min
const staticMax = vmRecord.memory_static_max ?? targetVm.memory_static_max
const dynamicMin = vmRecord.memory_dynamic_min ?? targetVm.memory_dynamic_min
const dynamicMax = vmRecord.memory_dynamic_max ?? targetVm.memory_dynamic_max
while (await updateNextMemoryField(xapi, memoryValues, targetVm.$ref)) {
/* execute until all memory fields are updated */
}
}
// Update one more memory field if needed, then return a boolean describing if a field was updated or if all fields are up to date
async function updateNextMemoryField(xapi, memoryValues, vmRef) {
for (let i = 0; i < orderedMemoryLimits.length; i++) {
const currentField = memoryValues[orderedMemoryLimits[i]]
const nextField = i === orderedMemoryLimits.length - 1 ? undefined : memoryValues[orderedMemoryLimits[i + 1]]
if (
currentField.newValue !== currentField.currentValue &&
(nextField === undefined || currentField.newValue <= nextField.currentValue)
) {
// no need to check that previousField.currentValue <= currentField.newValue, as we can deduce it
await xapi.setField('VM', vmRef, orderedMemoryLimits[i], currentField.newValue)
await xapi.barrier()
currentField.currentValue = currentField.newValue
return true
}
}
return false
await xapi.call('VM.set_memory_limits', targetVm.$ref, staticMin, staticMax, dynamicMin, dynamicMax)
}
export async function exportIncrementalVm(

View File

@@ -1,122 +0,0 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { updateMemoryFields } from './_incrementalVm.mjs'
const MOCK_REF = 'mockRef'
function mockXapiVm(initialMemoryValues) {
const res = {
...initialMemoryValues,
updates: [],
barrier: () => {},
setField: (type, ref, field, value) => {
assert(type === 'VM')
assert(ref === MOCK_REF)
res.updates.push({ field, value })
res[field] = value
assert(res.memory_static_min <= res.memory_dynamic_min)
assert(res.memory_dynamic_min <= res.memory_dynamic_max)
assert(res.memory_dynamic_max <= res.memory_static_max)
},
}
return res
}
const tests = [
{
label: 'handles a memory increase',
targetVm: {
memory_static_min: 2,
memory_dynamic_min: 4,
memory_dynamic_max: 4,
memory_static_max: 8,
},
vmRecord: {
memory_static_min: 16,
memory_dynamic_min: 16,
memory_dynamic_max: 16,
memory_static_max: 16,
},
expectedUpdates: [
{ field: 'memory_static_max', value: 16 },
{ field: 'memory_dynamic_max', value: 16 },
{ field: 'memory_dynamic_min', value: 16 },
{ field: 'memory_static_min', value: 16 },
],
},
{
label: 'handles a memory decrease',
targetVm: {
memory_static_min: 4,
memory_dynamic_min: 8,
memory_dynamic_max: 16,
memory_static_max: 16,
},
vmRecord: {
memory_static_min: 2,
memory_dynamic_min: 2,
memory_dynamic_max: 2,
memory_static_max: 2,
},
expectedUpdates: [
{ field: 'memory_static_min', value: 2 },
{ field: 'memory_dynamic_min', value: 2 },
{ field: 'memory_dynamic_max', value: 2 },
{ field: 'memory_static_max', value: 2 },
],
},
{
label: 'handles a more complex case',
targetVm: {
memory_static_min: 1,
memory_dynamic_min: 2,
memory_dynamic_max: 8,
memory_static_max: 16,
},
vmRecord: {
memory_static_min: 4,
memory_dynamic_min: 4,
memory_dynamic_max: 4,
memory_static_max: 4,
},
expectedUpdates: [
{ field: 'memory_dynamic_min', value: 4 },
{ field: 'memory_static_min', value: 4 },
{ field: 'memory_dynamic_max', value: 4 },
{ field: 'memory_static_max', value: 4 },
],
},
{
label: 'avoids updating identical value',
targetVm: {
memory_static_min: 1,
memory_dynamic_min: 2,
memory_dynamic_max: 4,
memory_static_max: 8,
},
vmRecord: {
memory_static_min: 1,
memory_dynamic_min: 2,
memory_dynamic_max: 4,
memory_static_max: 8,
},
expectedUpdates: [],
},
]
describe('updateMemoryFields() should update in the right order', () => {
for (const test of tests) {
it(test.label, async () => {
const mock = mockXapiVm(test.targetVm)
test.targetVm.$ref = MOCK_REF
await updateMemoryFields(mock, test.targetVm, test.vmRecord)
assert.equal(mock.updates.length, test.expectedUpdates.length)
for (let i = 0; i < mock.updates.length; i++) {
assert.equal(mock.updates[i].value, test.expectedUpdates[i].value)
assert.equal(mock.updates[i].field, test.expectedUpdates[i].field)
}
})
}
})

View File

@@ -33,6 +33,13 @@ 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)
}
@@ -90,6 +97,7 @@ 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,
@@ -120,6 +128,10 @@ 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

@@ -137,6 +137,7 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
task.warning(`Retry the VM mirror backup due to an error`, {
attempt: nTriesByVmId[vmUuid],
error: taskError.message,
isRetry: true,
})
queue.add(vmUuid)
})

View File

@@ -9,7 +9,9 @@ import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
import { IncrementalXapi } from './_vmRunners/IncrementalXapi.mjs'
import { FullXapi } from './_vmRunners/FullXapi.mjs'
import { Throttle } from '@vates/generator-toolbox'
import { asyncEach } from '@vates/async-each'
import createStreamThrottle from './_createStreamThrottle.mjs'
import { selectSynchronizedSnapshotVms } from './_selectSynchronizedSnapshotVms.mjs'
const noop = Function.prototype
@@ -31,7 +33,9 @@ const DEFAULT_XAPI_VM_SETTINGS = {
nRetriesVmBackupFailures: 0,
offlineBackup: false,
offlineSnapshot: false,
snapshotConcurrency: 2,
snapshotRetention: 0,
synchronizedSnapshot: false,
timeout: 0,
useNbd: false,
unconditionalSnapshot: false,
@@ -47,6 +51,16 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
return baseSettings
}
_getVmBackup(jobMode, opts) {
if (jobMode === 'delta') {
return new IncrementalXapi(opts)
} else if (jobMode === 'full') {
return new FullXapi(opts)
}
throw new Error(`Job mode ${jobMode} not implemented`)
}
async run() {
const job = this._job
@@ -95,7 +109,81 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
const allSettings = this._job.settings
const baseSettings = this._baseSettings
const queue = new Set(vmIds)
const preTakenTimestampByVmId = {}
const failedSnapshotByVmId = {}
if (settings.synchronizedSnapshot) {
await Task.run({ properties: { name: 'snapshot VMs' } }, async () => {
await Disposable.use(
Disposable.all(vmIds.map(vmId => this._getRecord('VM', vmId).catch(noop))),
async vms => {
// remove vms that failed (already handled)
vms = vms.filter(_ => _ !== undefined)
const batchIds = selectSynchronizedSnapshotVms(settings.synchronizedSnapshot, vms)
await asyncEach(
[...vms].filter(vm => batchIds.has(vm.uuid)),
async vm => {
const vmSettings = { ...settings, ...allSettings[vm.uuid] }
const opts = {
baseSettings,
config,
getSnapshotNameLabel,
healthCheckSr,
job,
remoteAdapters,
schedule,
settings: vmSettings,
srs,
throttleGenerator,
throttleStream,
vm,
}
let vmBackup
try {
vmBackup = this._getVmBackup(job.mode, opts)
if (
!vmBackup._settings.offlineBackup &&
!vmBackup._settings.offlineSnapshot &&
(await vmBackup._mustDoSnapshot())
) {
await vmBackup._prepareAndSnapshot()
preTakenTimestampByVmId[vm.uuid] = vmBackup.timestamp
}
} catch (error) {
failedSnapshotByVmId[vm.uuid] = error
if (vmBackup !== undefined) {
try {
await vmBackup._fetchJobSnapshots()
await vmBackup._removeUnusedSnapshots()
await vmBackup._cleanMetadata()
} catch (cleanupError) {
// Best effort cleanup
}
}
}
},
{
concurrency: settings.snapshotConcurrency,
}
)
}
)
})
}
const snapshotedVmIds = new Set(vmIds.filter(id => !(id in failedSnapshotByVmId)))
Object.entries(failedSnapshotByVmId).forEach(([vmId, error]) => {
Task.run(
{
properties: { id: vmId, name: 'backup VM', type: 'VM' },
},
() => Promise.reject(error)
).catch(noop)
})
const queue = new Set(snapshotedVmIds)
const taskByVmId = {}
const nTriesByVmId = {}
@@ -118,6 +206,7 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
task.warning(`Retry the VM backup due to an error`, {
attempt: nTriesByVmId[vmUuid],
error: error.message,
isRetry: true,
})
queue.add(vmUuid)
}
@@ -154,21 +243,16 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
schedule,
settings: vmSettings,
srs,
// when set, the batch phase already snapshotted this VM; the
// runner re-finds that snapshot by its metadata (see _snapshot)
synchronizedSnapshotTimestamp: preTakenTimestampByVmId[vmUuid],
throttleGenerator,
throttleStream,
vm,
}
let vmBackup
if (job.mode === 'delta') {
vmBackup = new IncrementalXapi(opts)
} else {
if (job.mode === 'full') {
vmBackup = new FullXapi(opts)
} else {
throw new Error(`Job mode ${job.mode} not implemented`)
}
}
const vmBackup = this._getVmBackup(job.mode, opts)
return vmBackup.run().catch(error => {
taskError = error
})

View File

@@ -10,6 +10,9 @@ export default function createStreamThrottle(rate) {
}
const group = new ThrottleGroup({ rate })
return function throttleStream(stream) {
return pipeline(stream, group.createThrottle(), noop)
const throttled = pipeline(stream, group.createThrottle(), noop)
throttled.length = stream.length
throttled.maxStreamLength = stream.maxStreamLength
return throttled
}
}

View File

@@ -0,0 +1,58 @@
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { Readable } from 'node:stream'
import createStreamThrottle from './_createStreamThrottle.mjs'
const makeStream = (chunks, props = {}) => {
const stream = Readable.from(chunks)
Object.assign(stream, props)
return stream
}
const readAll = async stream => {
const chunks = []
for await (const chunk of stream) {
chunks.push(chunk)
}
return Buffer.concat(chunks.map(c => (typeof c === 'string' ? Buffer.from(c) : c))).toString()
}
describe('createStreamThrottle', () => {
it('rate=0 returns identity, stream data and props intact', async () => {
const throttleStream = createStreamThrottle(0)
const stream = makeStream(['hello world'], { length: 11, maxStreamLength: 20 })
const throttled = throttleStream(stream)
assert.strictEqual(throttled, stream)
assert.strictEqual(throttled.length, 11)
assert.strictEqual(throttled.maxStreamLength, 20)
assert.strictEqual(await readAll(throttled), 'hello world')
})
it('rate>0 passes data through and preserves length and maxStreamLength', async () => {
const throttleStream = createStreamThrottle(1024 * 1024)
const stream = makeStream(['hello world'], { length: 11, maxStreamLength: 20 })
const throttled = throttleStream(stream)
assert.strictEqual(throttled.length, 11)
assert.strictEqual(throttled.maxStreamLength, 20)
assert.strictEqual(await readAll(throttled), 'hello world')
})
it('rate>0 handles undefined length and maxStreamLength', async () => {
const throttleStream = createStreamThrottle(1024 * 1024)
const stream = makeStream(['hello world'])
const throttled = throttleStream(stream)
assert.strictEqual(throttled.length, undefined)
assert.strictEqual(throttled.maxStreamLength, undefined)
assert.strictEqual(await readAll(throttled), 'hello world')
})
// regression: maxStreamLength was lost after throttling, causing S3 to ignore it and cap at 50GB
it('rate>0 preserves maxStreamLength so S3 can compute correct partSize', async () => {
const throttleStream = createStreamThrottle(1024 * 1024)
const stream = makeStream(['hello world'], { maxStreamLength: 11 })
const throttled = throttleStream(stream)
assert.strictEqual(throttled.maxStreamLength, 11)
assert.strictEqual(await readAll(throttled), 'hello world')
})
})

View File

@@ -0,0 +1,19 @@
import { Task } from '@vates/task'
export function selectSynchronizedSnapshotVms(synchronizedSnapshot, vms) {
if (synchronizedSnapshot === false) {
return new Set()
}
let matches
if (typeof synchronizedSnapshot === 'string') {
matches = vms.filter(vm => vm.tags.includes(synchronizedSnapshot))
} else if (synchronizedSnapshot === true) {
matches = vms
} else {
Task.warning('unsupported synchronizedSnapshot option, expected a boolean or a tag name', { synchronizedSnapshot })
return new Set()
}
return new Set(matches.map(vm => vm.uuid))
}

View File

@@ -0,0 +1,73 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { selectSynchronizedSnapshotVms } from './_selectSynchronizedSnapshotVms.mjs'
// Helper mirroring the minimal VM record shape the selector needs.
const vm = (uuid, tags = []) => ({ uuid, tags })
// `selectSynchronizedSnapshotVms(synchronizedSnapshot, vms)` must return a Set
// of the UUIDs that should be snapshotted together in the batch phase.
// - false -> feature off, no VM is batched
// - true -> every VM is batched, regardless of tags
// - '<tagName>' -> only VMs carrying that exact tag are batched
const tests = [
{
label: 'false disables batching',
setting: false,
vms: [vm('a', ['prod']), vm('b')],
expected: [],
},
{
label: 'true batches every VM regardless of tags',
setting: true,
vms: [vm('a', ['prod']), vm('b')],
expected: ['a', 'b'],
},
{
label: 'tag batches only the VMs carrying it',
setting: 'prod',
vms: [vm('a', ['prod']), vm('b', ['dev']), vm('c', ['prod', 'other'])],
expected: ['a', 'c'],
},
{
label: 'tag carried by no VM yields an empty batch',
setting: 'prod',
vms: [vm('a', ['dev']), vm('b')],
expected: [],
},
{
label: 'tag carried by every VM batches all of them',
setting: 'prod',
vms: [vm('a', ['prod']), vm('b', ['prod'])],
expected: ['a', 'b'],
},
{
label: 'empty VM list yields an empty batch',
setting: true,
vms: [],
expected: [],
},
{
label: 'empty-string tag matches no VM when none carries an empty tag',
setting: '',
vms: [vm('a', ['prod'])],
expected: [],
},
{
label: 'non boolean or string yiels an empty batch',
setting: 1,
vms: [vm('a', ['prod'])],
expected: [],
},
]
describe('selectSynchronizedSnapshotVms()', () => {
for (const { label, setting, vms, expected } of tests) {
it(label, () => {
const result = selectSynchronizedSnapshotVms(setting, vms)
assert.ok(result instanceof Set, 'result must be a Set')
assert.deepEqual([...result].sort(), [...expected].sort())
})
}
})

View File

@@ -80,14 +80,14 @@ export const FullXapi = class FullXapiVmBackupRunner extends AbstractXapi {
const sizeContainer = watchStreamSize(stream)
const timestamp = Date.now()
const transferStart = Date.now()
await this._callWriters(
writer =>
writer.run({
maxStreamLength,
sizeContainer,
stream: forkStreamUnpipe(stream),
timestamp,
timestamp: this.timestamp,
vm,
vmSnapshot: exportedVm,
}),
@@ -95,8 +95,7 @@ export const FullXapi = class FullXapiVmBackupRunner extends AbstractXapi {
)
const { size } = sizeContainer
const end = Date.now()
const duration = end - timestamp
const duration = Date.now() - transferStart
debug('transfer complete', {
duration,
speed: duration !== 0 ? (size * 1e3) / 1024 / 1024 / duration : 0,

View File

@@ -99,6 +99,7 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {
writer =>
writer.transfer({
deltaExport: forkDeltaExport(incrementalExport, writer.constructor.name),
includeNonNbdQcow2Fix: metadata.includeNonNbdQcow2Fix,
isVhdDifferencing,
timestamp: metadata.timestamp,
vm: metadata.vm,
@@ -106,16 +107,6 @@ 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

@@ -13,7 +13,6 @@ import {
DELTA_CHAIN_LENGTH,
EXPORTED_SUCCESSFULLY,
setVmDeltaChainLength,
markExportSuccessfull,
} from '../../_otherConfig.mjs'
import { ThrottledDisk, SynchronizedDisk } from '@xen-orchestra/disk-transform'
import { AggregatedIncrementalRemoteWriter } from '../_writers/AggregatedIncrementalRemoteWriter.mjs'
@@ -68,27 +67,21 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
// @todo : reimplement throttle
const timestamp = Date.now()
await this._callWriters(
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,
timestamp: this.timestamp,
vm,
vmSnapshot: exportedVm,
}),
'writer.transfer()'
)
await this._callWriters(
writer =>
writer.updateUuidAndChain({
isVhdDifferencing,
timestamp,
vdis: deltaExport.vdis,
}),
'writer.updateUuidAndChain()'
)
if (isFull) {
await setVmDeltaChainLength(this._xapi, exportedVm.$ref, 0)
@@ -96,11 +89,6 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
await setVmDeltaChainLength(this._xapi, exportedVm.$ref, (this._deltaChainLength ?? 0) + 1)
}
// not the case if offlineBackup
if (exportedVm.is_a_snapshot) {
await markExportSuccessfull(this._xapi, exportedVm.$ref)
}
await this._callWriters(writer => writer.cleanup(), 'writer.cleanup()')
}

View File

@@ -7,6 +7,7 @@ import { asyncEach } from '@vates/async-each'
import { decorateMethodsWith } from '@vates/decorate-with'
import { defer } from 'golike-defer'
import { Task } from '@vates/task'
import { formatDateTime } from '@xen-orchestra/xapi'
import { getOldEntries } from '../../_getOldEntries.mjs'
import { Abstract } from './_Abstract.mjs'
@@ -16,9 +17,11 @@ import {
JOB_ID,
SCHEDULE_ID,
VM_UUID,
EXPORTED_SUCCESSFULLY,
resetVmOtherConfig,
setVmOtherConfig,
setVmSnapshotContentKeys,
markExportSuccessfull,
} from '../../_otherConfig.mjs'
const { warn, info } = createLogger('xo:backups:AbstractXapi')
@@ -36,6 +39,7 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
schedule,
settings,
srs,
synchronizedSnapshotTimestamp,
throttleGenerator,
throttleStream,
vm,
@@ -63,9 +67,9 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
// VM (snapshot) that is really exported
this._exportedVm = undefined
this._synchronizedSnapshotTimestamp = synchronizedSnapshotTimestamp
this._vm = vm
this._baseVdis = undefined
this._getSnapshotNameLabel = getSnapshotNameLabel
this._isIncremental = job.mode === 'delta'
this._healthCheckSr = healthCheckSr
@@ -180,6 +184,27 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
}
async _snapshot() {
if (this._synchronizedSnapshotTimestamp !== undefined) {
const datetime = formatDateTime(this._synchronizedSnapshotTimestamp)
const candidates = this._vm.$snapshots.filter(
snapshot =>
snapshot?.other_config[JOB_ID] === this._jobId &&
snapshot?.other_config[DATETIME] === datetime &&
!snapshot.other_config[EXPORTED_SUCCESSFULLY]
)
if (candidates.length === 1) {
this._exportedVm = candidates[0]
this.timestamp = this._synchronizedSnapshotTimestamp
return
}
warn('expected exactly one synchronized snapshot to reuse, taking a fresh one', {
vm: this._vm.uuid,
datetime,
count: candidates.length,
})
}
const vm = this._vm
const xapi = this._xapi
@@ -213,6 +238,35 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
vmUuid: vm.uuid,
})
await setVmSnapshotContentKeys(xapi, snapshotRef)
// Verify that setVmOtherConfig actually tagged every disk we expected.
// If the snapshot exposes fewer 'Disk' VBDs than the live VM has, the
// tagging call silently skipped some VDIs and the resulting snapshot
// will be invisible to retention/cleanup on the next run.
const liveDisks = await xapi.VM_getDisks(vm.$ref)
const snapshotDisks = await xapi.VM_getDisks(snapshotRef)
if (liveDisks.length !== snapshotDisks.length) {
const snapshotVbdRefs = await xapi.getField('VM', snapshotRef, 'VBDs')
const snapshotVbds = await xapi.getRecords('VBD', snapshotVbdRefs)
warn('inconsistent snapshot tagging detected', {
vmUuid: vm.uuid,
vmName: vm.name_label,
snapshotRef,
jobId: this._jobId,
timestamp: this.timestamp,
expectedDiskCount: liveDisks.length,
actualDiskCount: snapshotDisks.length,
liveDisks,
snapshotDisks,
snapshotVbds: snapshotVbds.map(vbd => ({
uuid: vbd.uuid,
type: vbd.type,
VDI: vbd.VDI,
currently_attached: vbd.currently_attached,
})),
})
}
const snapshot = await xapi.getRecord('VM', snapshotRef)
await snapshot.set_name_label(this._getSnapshotNameLabel(vm))
// reload data to ensure it is up to date with the new name label
@@ -367,7 +421,20 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
await xapi.barrier()
// ensure cached object are up to date
this._jobSnapshotVdis = this._jobSnapshotVdis.map(vdi => xapi.getObject(vdi.$ref))
const disklessVmSnapshots = this._disklessJobSnapshotVms.map(vm => xapi.getObject(vm.$ref))
let disklessVmSnapshots = this._disklessJobSnapshotVms.map(vm => xapi.getObject(vm.$ref))
// The synchronized snapshot for this run is taken up-front by the batch
// phase but transferred later. Until it has been exported, hide it from
// retention so it is neither reclaimed nor allowed to steal the delta
// base's "most recent" protection. This makes the pre-transfer pass behave
// like a normal run, where the snapshot does not exist yet.
if (this._synchronizedSnapshotTimestamp !== undefined) {
const datetime = formatDateTime(this._synchronizedSnapshotTimestamp)
const isInFlightSyncSnapshot = ({ other_config }) =>
other_config[DATETIME] === datetime && !other_config[EXPORTED_SUCCESSFULLY]
this._jobSnapshotVdis = this._jobSnapshotVdis.filter(vdi => !isInFlightSyncSnapshot(vdi))
disklessVmSnapshots = disklessVmSnapshots.filter(vm => !isInFlightSyncSnapshot(vm))
}
// get the datetime of the most recent snapshot across both VDI and diskless VM snapshots
const lastSnapshotDateTime = [...this._jobSnapshotVdis, ...disklessVmSnapshots]
@@ -435,6 +502,7 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
vm = vdiVm
}
}
if (vm?.$ref !== undefined) {
return xapi.VM_destroy(vm.$ref)
} else {
@@ -464,6 +532,7 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
if (this.job.mode === 'delta' && datetime === lastSnapshotDateTime) {
return
}
await xapi.VM_destroy(snapshotPerDatetime[datetime])
})
})
@@ -522,6 +591,11 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
throw new Error('Not implemented')
}
async _prepareAndSnapshot() {
await this._cleanMetadata()
await this._snapshot()
}
async run($defer) {
const settings = this._settings
assert(
@@ -585,6 +659,10 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
if (this._writers.size !== 0) {
await this._copy()
}
// not the case if offlineBackup
if (this._exportedVm.is_a_snapshot) {
await markExportSuccessfull(this._xapi, this._exportedVm.$ref)
}
} finally {
if (startAfter) {
ignoreErrors.call(vm.$callAsync('start', false, false))

View File

@@ -0,0 +1,327 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { formatDateTime } from '@xen-orchestra/xapi'
import { AbstractXapi } from './_AbstractXapi.mjs'
import { DATETIME, EXPORTED_SUCCESSFULLY, JOB_ID, SCHEDULE_ID } from '../../_otherConfig.mjs'
// Build an AbstractXapi instance without running its heavy constructor, then
// assign only the fields the method under test reads.
const makeRunner = props => Object.assign(Object.create(AbstractXapi.prototype), props)
describe('_snapshot() synchronized-snapshot reuse guard', () => {
it('reuses the batch snapshot, found by metadata, without snapshotting again', async () => {
let mustDoSnapshotCalls = 0
const timestamp = 1717200000000
// the snapshot taken by the batch phase, identified by its other_config
const batchSnapshot = {
$ref: 'batch-snapshot-ref',
other_config: {
[JOB_ID]: 'job-1',
[SCHEDULE_ID]: 'schedule-1',
[DATETIME]: formatDateTime(timestamp),
},
}
const runner = makeRunner({
_synchronizedSnapshotTimestamp: timestamp,
_jobId: 'job-1',
scheduleId: 'schedule-1',
_vm: { uuid: 'vm-uuid', $snapshots: [batchSnapshot] },
_xapi: { barrier: async () => {} },
// if the metadata lookup fails, _snapshot() falls through to here
_mustDoSnapshot: async () => {
mustDoSnapshotCalls++
return false
},
})
await runner._snapshot()
assert.equal(mustDoSnapshotCalls, 0, '_mustDoSnapshot() should not be called when the batch snapshot is found')
assert.equal(runner._exportedVm, batchSnapshot, '_exportedVm should be the batch snapshot found by metadata')
assert.equal(runner.timestamp, timestamp, 'timestamp should be the synchronized snapshot timestamp')
})
it('takes a fresh snapshot when the batch snapshot can no longer be found', async () => {
let mustDoSnapshotCalls = 0
const vm = { uuid: 'vm-uuid', $snapshots: [] } // the pre-taken snapshot is gone
const runner = makeRunner({
_synchronizedSnapshotTimestamp: 1717200000000,
_jobId: 'job-1',
scheduleId: 'schedule-1',
_vm: vm,
_xapi: { barrier: async () => {} },
_settings: {},
_mustDoSnapshot: async () => {
mustDoSnapshotCalls++
return false
},
})
await runner._snapshot()
assert.equal(
mustDoSnapshotCalls,
1,
'a missing batch snapshot should not be reused: _snapshot() should fall through and take a fresh snapshot'
)
assert.equal(
runner._exportedVm,
vm,
'_exportedVm should fall back to the freshly-snapshotted VM, not stay on a stale/missing batch snapshot'
)
})
it('without a pre-taken snapshot and no snapshot needed, exports the live VM', async () => {
let mustDoSnapshotCalls = 0
const vm = { uuid: 'vm-uuid' }
const runner = makeRunner({
_exportedVm: undefined,
_vm: vm,
_xapi: {},
_settings: {},
_mustDoSnapshot: async () => {
mustDoSnapshotCalls++
return false
},
})
await runner._snapshot()
assert.equal(mustDoSnapshotCalls, 1, '_mustDoSnapshot() should be called once when no snapshot was pre-taken')
assert.equal(runner._exportedVm, vm, '_exportedVm should be set to the live VM when no snapshot is needed')
assert.equal(typeof runner.timestamp, 'number', 'timestamp should be set when exporting the live VM')
})
})
describe('_removeUnusedSnapshots() protects the pre-taken synchronized snapshot', () => {
const OLD_DATETIME = '20240101T00:00:00Z'
const SYNC_TIMESTAMP = 1717200000000
const SYNC_DATETIME = formatDateTime(SYNC_TIMESTAMP)
// Full-mode job with snapshotRetention 0, so retention wants to remove every
// snapshot. `vdi-fresh` is the snapshot taken up-front by the synchronized
// batch phase (identified by SYNC_TIMESTAMP); until it is exported it must be
// hidden from retention.
const makeRemoveRunner = ({ exported }) => {
const destroyed = []
const snapshotVm = ($ref, name_label) => ({
$ref,
name_label,
is_control_domain: false,
$snapshot_of: 'live-vm-ref',
other_config: {},
})
const freshSnapshotVm = snapshotVm('vm-fresh', 'fresh')
const oldSnapshotVm = snapshotVm('vm-old', 'old')
const vdi = ($ref, datetime, snapshotVmRecord, isExported = false) => ({
$ref,
other_config: {
[DATETIME]: datetime,
[SCHEDULE_ID]: 'schedule-1',
...(isExported ? { [EXPORTED_SUCCESSFULLY]: 'true' } : {}),
},
$VBDs: [{ $VM: snapshotVmRecord }],
})
// the old snapshot was exported by a previous run
const oldVdi = vdi('vdi-old', OLD_DATETIME, oldSnapshotVm, true)
const freshVdi = vdi('vdi-fresh', SYNC_DATETIME, freshSnapshotVm, exported)
const registry = { 'vdi-old': oldVdi, 'vdi-fresh': freshVdi }
const runner = makeRunner({
_synchronizedSnapshotTimestamp: SYNC_TIMESTAMP,
_vm: { uuid: 'live-uuid', $snapshots: [] },
_baseSettings: { snapshotRetention: 0 },
_jobSnapshotVdis: [oldVdi, freshVdi],
_disklessJobSnapshotVms: [],
job: { mode: 'full', settings: {} },
_xapi: {
barrier: async () => {},
getObject: ref => registry[ref],
VM_destroy: async ref => {
destroyed.push(ref)
},
VDI_destroy: async ref => {
destroyed.push(ref)
},
},
})
return { runner, destroyed }
}
it('does not destroy the pre-taken snapshot before it has been transferred', async () => {
const { runner, destroyed } = makeRemoveRunner({ exported: false })
await runner._removeUnusedSnapshots()
assert.deepEqual(destroyed, ['vm-old'], 'only the older snapshot should be removed')
})
it('destroys the snapshot once it has been transferred (retention 0, no leak)', async () => {
const { runner, destroyed } = makeRemoveRunner({ exported: true })
await runner._removeUnusedSnapshots()
assert.deepEqual(destroyed.sort(), ['vm-fresh', 'vm-old'], 'both snapshots should be removed after transfer')
})
})
describe('_removeUnusedSnapshots() in the synchronized batch pre-snapshot state', () => {
it('delta mode: keeps the base snapshot when the fresh one has not been taken yet', async () => {
const destroyed = []
const BASE_DATETIME = '2024-06-01T00:00:00Z'
const baseSnapshotVm = {
$ref: 'vm-base',
name_label: 'base',
is_control_domain: false,
$snapshot_of: 'live-vm-ref',
// exported successfully by the previous run
other_config: { [EXPORTED_SUCCESSFULLY]: 'true' },
}
const baseVdi = {
$ref: 'vdi-base',
other_config: { [DATETIME]: BASE_DATETIME, [SCHEDULE_ID]: 'schedule-1' },
$VBDs: [{ $VM: baseSnapshotVm }],
}
const registry = { 'vdi-base': baseVdi }
const runner = makeRunner({
// batch pre-snapshot state: the synchronized snapshot has not been taken yet
_exportedVm: undefined,
_vm: { uuid: 'live-uuid', $snapshots: [] },
_baseSettings: { snapshotRetention: 0 },
_jobSnapshotVdis: [baseVdi],
_disklessJobSnapshotVms: [],
job: { mode: 'delta', settings: {} },
_xapi: {
barrier: async () => {},
getObject: ref => registry[ref],
VM_destroy: async ref => {
destroyed.push(ref)
},
VDI_destroy: async ref => {
destroyed.push(ref)
},
},
})
await runner._removeUnusedSnapshots()
assert.deepEqual(destroyed, [], 'the base snapshot must be kept as the delta base for the upcoming transfer')
})
})
describe('_removeUnusedSnapshots() reclaims orphan / CBT snapshot VDIs (no attached VM)', () => {
// Guards the `else` branch: snapshot VDIs that are not attached to any user VM
// (e.g. CBT metadata, orphans) must be reclaimed via VDI_destroy, not VM_destroy.
it('destroys snapshot VDIs directly when they are not attached to any VM', async () => {
const vmDestroyed = []
const vdiDestroyed = []
const orphanVdi = {
$ref: 'vdi-orphan',
other_config: { [DATETIME]: '2024-01-01T00:00:00Z', [SCHEDULE_ID]: 'schedule-1' },
$VBDs: [], // not attached to any VM
}
const registry = { 'vdi-orphan': orphanVdi }
const runner = makeRunner({
_exportedVm: undefined,
_vm: { uuid: 'live-uuid', $snapshots: [] },
_baseSettings: { snapshotRetention: 0 },
_jobSnapshotVdis: [orphanVdi],
_disklessJobSnapshotVms: [],
job: { mode: 'full', settings: {} },
_xapi: {
barrier: async () => {},
getObject: ref => registry[ref],
VM_destroy: async ref => {
vmDestroyed.push(ref)
},
VDI_destroy: async ref => {
vdiDestroyed.push(ref)
},
},
})
await runner._removeUnusedSnapshots()
assert.deepEqual(vdiDestroyed, ['vdi-orphan'], 'the orphan VDI should be reclaimed via VDI_destroy')
assert.deepEqual(vmDestroyed, [], 'no VM should be destroyed for an orphan VDI')
})
})
describe('_removeUnusedSnapshots() diskless VM snapshots', () => {
const OLD_DATETIME = '20240101T00:00:00Z'
const SYNC_TIMESTAMP = 1717200000000
const SYNC_DATETIME = formatDateTime(SYNC_TIMESTAMP)
// A diskless VM's backup snapshots are tracked as VM snapshots (no VDIs to
// anchor them). `dl-fresh` is the snapshot the synchronized batch pre-took,
// identified by SYNC_TIMESTAMP.
const makeDisklessRunner = ({ exported, mode = 'full' }) => {
const destroyed = []
const oldSnap = { $ref: 'dl-old', other_config: { [DATETIME]: OLD_DATETIME, [SCHEDULE_ID]: 'schedule-1' } }
const freshSnap = { $ref: 'dl-fresh', other_config: { [DATETIME]: SYNC_DATETIME, [SCHEDULE_ID]: 'schedule-1' } }
if (exported) freshSnap.other_config[EXPORTED_SUCCESSFULLY] = 'true'
const registry = { 'dl-old': oldSnap, 'dl-fresh': freshSnap }
const runner = makeRunner({
_synchronizedSnapshotTimestamp: SYNC_TIMESTAMP,
_vm: { uuid: 'live-uuid', $snapshots: [] },
_baseSettings: { snapshotRetention: 0 },
_jobSnapshotVdis: [],
_disklessJobSnapshotVms: [oldSnap, freshSnap],
job: { mode, settings: {} },
_xapi: {
barrier: async () => {},
getObject: ref => registry[ref],
VM_destroy: async ref => {
destroyed.push(ref)
},
VDI_destroy: async ref => {
destroyed.push(ref)
},
},
})
return { runner, destroyed }
}
it('does not destroy the pre-taken diskless snapshot before it has been transferred', async () => {
const { runner, destroyed } = makeDisklessRunner({ exported: false })
await runner._removeUnusedSnapshots()
assert.deepEqual(destroyed, ['dl-old'], 'only the older diskless snapshot should be removed')
})
it('destroys the diskless snapshot once it has been transferred (retention 0, no leak)', async () => {
const { runner, destroyed } = makeDisklessRunner({ exported: true })
await runner._removeUnusedSnapshots()
assert.deepEqual(
destroyed.sort(),
['dl-fresh', 'dl-old'],
'both diskless snapshots should be removed after transfer'
)
})
it('keeps the most recent diskless snapshot in delta mode (base for next delta)', async () => {
// Even after transfer (exported), delta mode must retain the latest
// snapshot so the next run can compute its delta against it.
const { runner, destroyed } = makeDisklessRunner({ exported: true, mode: 'delta' })
await runner._removeUnusedSnapshots()
assert.deepEqual(destroyed, ['dl-old'], 'the most recent diskless snapshot should be kept in delta mode')
})
})

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,13 +50,8 @@ export class AggregatedIncrementalRemoteWriter extends AbstractAggregatedRemoteW
await Promise.all(this.writers.map(writer => writer.prepare({ isFull })))
}
// write only on the main writer
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 })
transfer(args) {
return this.mainWriter.transfer(args)
}
// 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,11 +59,6 @@ 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,15 +16,18 @@ import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
import { checkVhd } from './_checkVhd.mjs'
import { packUuid } from './_packUuid.mjs'
import { Disposable } from 'promise-toolbox'
import { openDiskChain } from '@xen-orchestra/backup-archive/disks'
import { VDI_FORMAT_QCOW2 } from '@xen-orchestra/xapi'
import { diskHasData } from './_diskHasData.mjs'
const { warn } = createLogger('xo:backups:DeltaBackupWriter')
export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrementalWriter) {
#parentVdiPaths
#vhds
#parentUuids
async checkBaseVdis(baseUuidToSrcVdi) {
this.#parentVdiPaths = {}
this.#parentUuids = {}
const { handler } = this._adapter
const adapter = this._adapter
@@ -32,6 +35,7 @@ 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, {
@@ -47,6 +51,7 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
try {
if (await adapter.isMergeableParent(packedBaseUuid, path)) {
parentDestPath = path
parentUuid = packedBaseUuid
}
} catch (error) {
warn('checkBaseVdis', { error })
@@ -59,11 +64,77 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
if (parentDestPath === undefined) {
baseUuidToSrcVdi.delete(baseUuid)
} else {
this.#parentVdiPaths[vhdDir] = parentDestPath
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)
}
}
})
}
// 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 })
@@ -126,48 +197,6 @@ 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
@@ -178,7 +207,7 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
}
}
async _transfer($defer, { isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
async _transfer($defer, { includeNonNbdQcow2Fix, isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
const adapter = this._adapter
const job = this._job
const scheduleId = this._schedule.id
@@ -186,10 +215,8 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
const jobId = job.id
const handler = adapter.handler
const basename = formatFilenameDate(timestamp)
// update this.#vhds before eventually skipping transfer, so that
// updateUuidAndChain has all the mandatory data
const vhds = (this.#vhds = mapValues(
const filenameDate = formatFilenameDate(timestamp)
const vhds = mapValues(
deltaExport.vdis,
vdi =>
`vdis/${jobId}/${
@@ -198,8 +225,8 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
// don't do delta for it
vdi.uuid
: vdi.$snapshot_of$uuid
}/${adapter.getVhdFileName(basename)}`
))
}/${adapter.getVhdFileName(filenameDate)}`
)
let metadataContent = await this._isAlreadyTransferred(timestamp)
if (metadataContent !== undefined) {
@@ -209,6 +236,11 @@ 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,
@@ -229,12 +261,24 @@ 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,3 +1,4 @@
import assert from 'node:assert'
import humanFormat from 'human-format'
import { asyncMapSettled } from '@xen-orchestra/async-map'
@@ -20,6 +21,7 @@ import {
DATETIME,
VM_UUID,
CONTENT_KEY,
INCLUDE_NON_NBD_QCOW2_FIX,
resetVmOtherConfig,
} from '../../_otherConfig.mjs'
import { formatFilenameDate } from '../../_filenameDate.mjs'
@@ -27,8 +29,9 @@ 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 } = createLogger('xo:backups:IncrementalXapiWriter')
const { debug, warn } = createLogger('xo:backups:IncrementalXapiWriter')
export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWriter) {
// Map of source VDI UUID (COPY_OF) → validated active VDI on the target SR.
@@ -93,6 +96,45 @@ 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)
}
}
@@ -133,6 +175,42 @@ 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
@@ -185,6 +263,7 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
vdiRef: activeVdi.$ref,
baseRef: snapshot.$ref,
onlyListChangedBlocks: true,
preferNbd: this._settings.preferNbd,
})
await diffDisk.init()
if (diffDisk.getBlockIndexes().length === 0) {
@@ -235,9 +314,6 @@ 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({
@@ -343,6 +419,10 @@ 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,10 +5,6 @@ export class AbstractIncrementalWriter extends AbstractWriter {
throw new Error('Not implemented')
}
updateUuidAndChain() {
throw new Error('Not implemented')
}
cleanup() {
throw new Error('Not implemented')
}
@@ -20,8 +16,6 @@ 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

@@ -0,0 +1,26 @@
// 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,7 +230,6 @@ 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.5",
"version": "0.74.2",
"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.4.0",
"@vates/nbd-client": "^3.5.1",
"@vates/parse-duration": "^0.1.1",
"@vates/task": "^0.7.0",
"@vates/types": "^1.28.0",
"@xen-orchestra/async-map": "^0.1.3",
"@xen-orchestra/disk-transform": "^1.3.1",
"@xen-orchestra/fs": "^4.9.1",
"@vates/types": "^2.0.1",
"@xen-orchestra/async-map": "^0.1.4",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/log": "^0.7.2",
"@xen-orchestra/qcow2": "^1.3.1",
"@xen-orchestra/template": "^0.1.1",
"@xen-orchestra/backup-archive": "^1.0.2",
"@xen-orchestra/backup-archive": "^1.1.2",
"app-conf": "^3.0.0",
"compare-versions": "^6.0.0",
"d3-time-format": "^4.1.0",
@@ -52,11 +52,11 @@
"parse-pairs": "^2.0.0",
"promise-toolbox": "^0.21.0",
"proper-lockfile": "^4.1.2",
"tar": "^7.5.3",
"tar": "^7.5.19",
"uuid": "^9.0.0",
"value-matcher": "^0.2.0",
"vhd-lib": "^4.16.0",
"xen-api": "^4.7.8",
"vhd-lib": "^4.16.1",
"xen-api": "^4.9.0",
"yazl": "^2.5.1"
},
"devDependencies": {
@@ -67,7 +67,7 @@
"typescript": "^5.9.3"
},
"peerDependencies": {
"@xen-orchestra/xapi": "^8.9.0"
"@xen-orchestra/xapi": "^8.10.5"
},
"license": "AGPL-3.0-or-later",
"author": {

View File

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

View File

@@ -3,8 +3,8 @@ $ xo-disk-cli --help
Usage: xo-disk-cli <command> <handler-url> <path> [options]
Commands:
info Show disk info (virtual size, uid, parent uid, block size)
list List all disks at a path and display their properties in a table
info Show disk info (virtual size, uid, parent uid, block size); --chain shows the full parent chain, --size adds the size on disk
list List all disks at a path and display their properties in a table; --size adds the size on disk
transform Convert a disk to another format and write to stdout (raw | vhd | qcow2)
```
@@ -15,7 +15,7 @@ Commands:
Display metadata for a single disk file.
```
xo-disk-cli info <handler-url> <disk-path>
xo-disk-cli info <handler-url> <disk-path> [--chain] [--size]
```
Output includes: UID, parent UID (for differencing disks), virtual size, and block size.
@@ -29,16 +29,66 @@ Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd
Block size: 2.00 MiB (2097152 bytes)
```
By default the disk is opened without reading its block allocation table, which
is cheap but does not allow computing the size on disk. Pass `--size` to read
the block allocation table and print the size on disk as an extra line:
```
$ xo-disk-cli info file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd --size
Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd
UID: <uuid>
Parent UID: <parent-uuid>
Virtual size: 8.00 GiB (8589934592 bytes)
Block size: 2.00 MiB (2097152 bytes)
Size on disk: 128.00 MiB (134217728 bytes)
```
With `--chain`, the disk's full parent chain is opened and each disk is printed
from the root (base) disk down to the given leaf disk. `--chain` and `--size`
can be combined:
```
$ xo-disk-cli info file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd --chain
Disk chain: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd (2 disks, root → leaf)
Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/base.vhd
UID: <base-uuid>
Parent UID: (none)
Virtual size: 8.00 GiB (8589934592 bytes)
Block size: 2.00 MiB (2097152 bytes)
Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd
UID: <uuid>
Parent UID: <base-uuid>
Virtual size: 8.00 GiB (8589934592 bytes)
Block size: 2.00 MiB (2097152 bytes)
```
### `list`
List all disk files found at a directory path and display their properties in a table. Disks are sorted so that each child appears directly after its parent. When a disk's parent is the row immediately above, the parent UID column shows `↑` for quick chain health assessment.
```
xo-disk-cli list <handler-url> <dir-path>
xo-disk-cli list <handler-url> <dir-path> [--size]
```
By default disks are opened without reading their block allocation table (cheap),
so the "Size on disk" column is omitted:
```
$ xo-disk-cli list file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/
┌──────────────┬──────────────────────────────────────┬──────────────┬─────────────┬──────────────────────────────────────┐
│ File │ UID │ Virtual size │ Differencing │ Parent UID │
├──────────────┼──────────────────────────────────────┼──────────────┼─────────────┼──────────────────────────────────────┤
│ base.vhd │ xxxxxxxx-... │ 8.00 GiB │ no │ (none) │
│ snapshot.vhd │ yyyyyyyy-... │ 8.00 GiB │ yes │ ↑ │
└──────────────┴──────────────────────────────────────┴──────────────┴─────────────┴──────────────────────────────────────┘
```
Pass `--size` to read each disk's block allocation table and add the "Size on disk" column:
```
$ xo-disk-cli list file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/ --size
┌──────────────┬──────────────────────────────────────┬─────────────┬──────────────┬─────────────┬──────────────────────────────────────┐
│ File │ UID │ Size on disk│ Virtual size │ Differencing │ Parent UID │
├──────────────┼──────────────────────────────────────┼─────────────┼──────────────┼─────────────┼──────────────────────────────────────┤

View File

@@ -21,8 +21,8 @@ $ xo-disk-cli --help
Usage: xo-disk-cli <command> <handler-url> <path> [options]
Commands:
info Show disk info (virtual size, uid, parent uid, block size)
list List all disks at a path and display their properties in a table
info Show disk info (virtual size, uid, parent uid, block size); --chain shows the full parent chain, --size adds the size on disk
list List all disks at a path and display their properties in a table; --size adds the size on disk
transform Convert a disk to another format and write to stdout (raw | vhd | qcow2)
```
@@ -33,7 +33,7 @@ Commands:
Display metadata for a single disk file.
```
xo-disk-cli info <handler-url> <disk-path>
xo-disk-cli info <handler-url> <disk-path> [--chain] [--size]
```
Output includes: UID, parent UID (for differencing disks), virtual size, and block size.
@@ -47,16 +47,66 @@ Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd
Block size: 2.00 MiB (2097152 bytes)
```
By default the disk is opened without reading its block allocation table, which
is cheap but does not allow computing the size on disk. Pass `--size` to read
the block allocation table and print the size on disk as an extra line:
```
$ xo-disk-cli info file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd --size
Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd
UID: <uuid>
Parent UID: <parent-uuid>
Virtual size: 8.00 GiB (8589934592 bytes)
Block size: 2.00 MiB (2097152 bytes)
Size on disk: 128.00 MiB (134217728 bytes)
```
With `--chain`, the disk's full parent chain is opened and each disk is printed
from the root (base) disk down to the given leaf disk. `--chain` and `--size`
can be combined:
```
$ xo-disk-cli info file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd --chain
Disk chain: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd (2 disks, root → leaf)
Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/base.vhd
UID: <base-uuid>
Parent UID: (none)
Virtual size: 8.00 GiB (8589934592 bytes)
Block size: 2.00 MiB (2097152 bytes)
Disk info: /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/snapshot.vhd
UID: <uuid>
Parent UID: <base-uuid>
Virtual size: 8.00 GiB (8589934592 bytes)
Block size: 2.00 MiB (2097152 bytes)
```
### `list`
List all disk files found at a directory path and display their properties in a table. Disks are sorted so that each child appears directly after its parent. When a disk's parent is the row immediately above, the parent UID column shows `↑` for quick chain health assessment.
```
xo-disk-cli list <handler-url> <dir-path>
xo-disk-cli list <handler-url> <dir-path> [--size]
```
By default disks are opened without reading their block allocation table (cheap),
so the "Size on disk" column is omitted:
```
$ xo-disk-cli list file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/
┌──────────────┬──────────────────────────────────────┬──────────────┬─────────────┬──────────────────────────────────────┐
│ File │ UID │ Virtual size │ Differencing │ Parent UID │
├──────────────┼──────────────────────────────────────┼──────────────┼─────────────┼──────────────────────────────────────┤
│ base.vhd │ xxxxxxxx-... │ 8.00 GiB │ no │ (none) │
│ snapshot.vhd │ yyyyyyyy-... │ 8.00 GiB │ yes │ ↑ │
└──────────────┴──────────────────────────────────────┴──────────────┴─────────────┴──────────────────────────────────────┘
```
Pass `--size` to read each disk's block allocation table and add the "Size on disk" column:
```
$ xo-disk-cli list file:///mnt/backups /xo-vm-backups/<vm-uuid>/vdis/<vdi-uuid>/ --size
┌──────────────┬──────────────────────────────────────┬─────────────┬──────────────┬─────────────┬──────────────────────────────────────┐
│ File │ UID │ Size on disk│ Virtual size │ Differencing │ Parent UID │
├──────────────┼──────────────────────────────────────┼─────────────┼──────────────┼─────────────┼──────────────────────────────────────┤

View File

@@ -1,7 +1,7 @@
{
"private": false,
"name": "@xen-orchestra/disk-cli",
"version": "2.1.2",
"version": "2.2.1",
"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.5",
"@xen-orchestra/backup-archive": "^1.0.2",
"@xen-orchestra/disk-transform": "^1.3.1",
"@xen-orchestra/fs": "^4.9.1",
"@xen-orchestra/backups": "^0.74.2",
"@xen-orchestra/backup-archive": "^1.1.2",
"@xen-orchestra/disk-transform": "^1.3.3",
"@xen-orchestra/fs": "^4.9.3",
"@xen-orchestra/qcow2": "^1.3.1",
"promise-toolbox": "^0.21.0",
"vhd-lib": "^4.16.0"
"vhd-lib": "^4.16.1"
},
"devDependencies": {
"@types/node": "^22.3.0",

View File

@@ -1,22 +1,84 @@
import Disposable from 'promise-toolbox/Disposable'
import { getSyncedHandler } from '@xen-orchestra/fs'
import { openDisposableDisk, RemoteDisk } from '@xen-orchestra/backup-archive/disks'
import { getSyncedHandler, type RemoteHandler } from '@xen-orchestra/fs'
import { openDisposableDisk, openDiskChain, RemoteDisk, DiskDisposable } from '@xen-orchestra/backup-archive/disks'
import { formatBytes } from '../utils.mjs'
export async function infoCommand(handlerUrl: string, diskPath: string, _extraArgs: string[]): Promise<void> {
await Disposable.use(getSyncedHandler({ url: handlerUrl }), async handler => {
await Disposable.use(openDisposableDisk({ handler, path: diskPath }), async (disk: RemoteDisk) => {
const isDifferencing = disk.isDifferencing()
const virtualSize = disk.getVirtualSize()
const blockSize = disk.getBlockSize()
const uid = disk.getUuid()
const parentUid = isDifferencing ? disk.getParentUuid() : null
type DiskInfoLine = {
path: string
uid: string
parentUid: string | null
virtualSize: number
blockSize: number
// Only computed with --size; requires reading the block allocation table.
sizeOnDisk?: number
}
console.log(`Disk info: ${diskPath}`)
console.log(` UID: ${uid}`)
console.log(` Parent UID: ${parentUid ?? '(none)'}`)
console.log(` Virtual size: ${formatBytes(virtualSize)} (${virtualSize} bytes)`)
console.log(` Block size: ${formatBytes(blockSize)} (${blockSize} bytes)`)
})
function readDiskInfo(disk: RemoteDisk, path: string, showSize: boolean): DiskInfoLine {
const isDifferencing = disk.isDifferencing()
return {
path,
uid: disk.getUuid(),
parentUid: isDifferencing ? disk.getParentUuid() : null,
virtualSize: disk.getVirtualSize(),
blockSize: disk.getBlockSize(),
sizeOnDisk: showSize ? disk.getSizeOnDisk() : undefined,
}
}
function printDiskInfo(info: DiskInfoLine): void {
console.log(`Disk info: ${info.path}`)
console.log(` UID: ${info.uid}`)
console.log(` Parent UID: ${info.parentUid ?? '(none)'}`)
console.log(` Virtual size: ${formatBytes(info.virtualSize)} (${info.virtualSize} bytes)`)
console.log(` Block size: ${formatBytes(info.blockSize)} (${info.blockSize} bytes)`)
if (info.sizeOnDisk !== undefined) {
console.log(` Size on disk: ${formatBytes(info.sizeOnDisk)} (${info.sizeOnDisk} bytes)`)
}
}
// Opens the full chain (root → leaf) as a disposable, reusing the same chain
// walker as the `transform` command.
async function openDisposableChain(
handler: RemoteHandler,
path: string,
ignoreBlockIndexes: boolean
): Promise<DiskDisposable> {
const chain = await openDiskChain({ handler, path, ignoreBlockIndexes })
return { value: chain, dispose: () => chain.close() }
}
export async function infoCommand(handlerUrl: string, diskPath: string, extraArgs: string[]): Promise<void> {
const showChain = extraArgs.includes('--chain')
const showSize = extraArgs.includes('--size')
// Reading the block allocation table is costly, so only do it when the size on
// disk is requested; every other field comes from the footer/header.
const ignoreBlockIndexes = !showSize
await Disposable.use(getSyncedHandler({ url: handlerUrl }), async handler => {
if (!showChain) {
const info = await Disposable.use(
openDisposableDisk({ handler, path: diskPath, ignoreBlockIndexes }),
(disk: RemoteDisk) => readDiskInfo(disk, diskPath, showSize)
)
printDiskInfo(info)
return
}
// Resolve the full lineage (root → leaf), then print each disk's info.
const paths = await Disposable.use(openDisposableChain(handler, diskPath, ignoreBlockIndexes), chain =>
chain.getPaths()
)
console.log(`Disk chain: ${diskPath} (${paths.length} disk${paths.length === 1 ? '' : 's'}, root → leaf)\n`)
for (const [index, path] of paths.entries()) {
const info = await Disposable.use(openDisposableDisk({ handler, path, ignoreBlockIndexes }), (disk: RemoteDisk) =>
readDiskInfo(disk, path, showSize)
)
printDiskInfo(info)
if (index < paths.length - 1) {
console.log()
}
}
})
}

View File

@@ -3,13 +3,18 @@ import { getSyncedHandler } from '@xen-orchestra/fs'
import { isDisk, openDisposableDisk, RemoteDisk } from '@xen-orchestra/backup-archive/disks'
import { formatBytes, renderTable } from '../utils.mjs'
import { asyncEach } from '@vates/async-each'
const HEADERS = ['File', 'UID', 'Size on disk', 'Virtual size', 'Differencing', 'Parent UID']
// The "Size on disk" column is only shown with --size: computing it requires
// reading the block allocation table of every disk, which is costly.
function buildHeaders(showSize: boolean): string[] {
return ['File', 'UID', ...(showSize ? ['Size on disk'] : []), 'Virtual size', 'Differencing', 'Parent UID']
}
export type OkDiskInfo = {
ok: true
filename: string
uid: string
sizeOnDisk: string
sizeOnDisk?: string
virtualSize: string
differencing: boolean
parentUid: string | null
@@ -54,9 +59,10 @@ export function sortDisks(disks: DiskInfo[]): DiskInfo[] {
return [...sorted, ...errDisks]
}
export function toTableRow(disk: DiskInfo, prevDisk: DiskInfo | undefined): string[] {
export function toTableRow(disk: DiskInfo, prevDisk: DiskInfo | undefined, showSize: boolean): string[] {
if (!disk.ok) {
return [disk.filename, `(error: ${disk.error})`, '-', '-', '-', '-']
// filename + error message, then a placeholder for every remaining column.
return [disk.filename, `(error: ${disk.error})`, ...Array(showSize ? 4 : 3).fill('-')]
}
const parentIsAbove = disk.differencing && prevDisk?.ok && prevDisk.uid === disk.parentUid
@@ -64,14 +70,16 @@ export function toTableRow(disk: DiskInfo, prevDisk: DiskInfo | undefined): stri
return [
disk.filename,
disk.uid,
disk.sizeOnDisk,
...(showSize ? [disk.sizeOnDisk ?? '-'] : []),
disk.virtualSize,
disk.differencing ? 'yes' : 'no',
disk.differencing ? (parentIsAbove ? '↑' : (disk.parentUid ?? '')) : '(none)',
]
}
export async function listCommand(handlerUrl: string, dirPath: string, _extraArgs: string[]): Promise<void> {
export async function listCommand(handlerUrl: string, dirPath: string, extraArgs: string[]): Promise<void> {
const showSize = extraArgs.includes('--size')
await Disposable.use(getSyncedHandler({ url: handlerUrl }), async handler => {
const entries = await handler.list(dirPath, { prependDir: true })
const diskPaths = entries.filter(entry => isDisk(entry))
@@ -88,14 +96,14 @@ export async function listCommand(handlerUrl: string, dirPath: string, _extraArg
const filename = diskPath.slice(diskPath.lastIndexOf('/') + 1)
try {
const disk = await Disposable.use(
openDisposableDisk({ handler, path: diskPath }),
openDisposableDisk({ handler, path: diskPath, ignoreBlockIndexes: !showSize }),
async (disk: RemoteDisk) => {
const differencing = disk.isDifferencing()
return {
ok: true as const,
filename,
uid: disk.getUuid(),
sizeOnDisk: formatBytes(disk.getSizeOnDisk()),
sizeOnDisk: showSize ? formatBytes(disk.getSizeOnDisk()) : undefined,
virtualSize: formatBytes(disk.getVirtualSize()),
differencing,
parentUid: differencing ? disk.getParentUuid() : null,
@@ -111,7 +119,7 @@ export async function listCommand(handlerUrl: string, dirPath: string, _extraArg
)
const sorted = sortDisks(disks)
const rows = sorted.map((disk, i) => toTableRow(disk, sorted[i - 1]))
console.log(renderTable(HEADERS, rows))
const rows = sorted.map((disk, i) => toTableRow(disk, sorted[i - 1], showSize))
console.log(renderTable(buildHeaders(showSize), rows))
})
}

View File

@@ -42,6 +42,7 @@ declare module '@xen-orchestra/backup-archive/disks/openDiskChain.mjs' {
handler: RemoteHandler
path: string
until?: string
ignoreBlockIndexes?: boolean
}): Promise<RandomAccessDisk>
}
@@ -52,8 +53,10 @@ declare module '@xen-orchestra/backup-archive/disks' {
export interface RemoteDisk extends RandomAccessDisk {
getSizeOnDisk(): number
getPath(): string
getPaths(): string[]
getUuid(): string
getParentUuid(): string
getParentPath(): string
getMaxBlockCount(): number
}
@@ -64,11 +67,18 @@ declare module '@xen-orchestra/backup-archive/disks' {
export function isDisk(path: string): boolean
export function openDisposableDisk(params: { handler: RemoteHandler; path: string }): Promise<DiskDisposable>
export function openDisposableDisk(params: {
handler: RemoteHandler
path: string
force?: boolean
ignoreBlockIndexes?: boolean
}): Promise<DiskDisposable>
// Returns a RemoteVhdDiskChain, which is a RemoteDisk exposing getPaths() over the whole lineage.
export function openDiskChain(params: {
handler: RemoteHandler
path: string
until?: string
}): Promise<RandomAccessDisk>
ignoreBlockIndexes?: boolean
}): Promise<RemoteDisk>
}

View File

@@ -14,8 +14,8 @@ const COMMANDS: Record<string, CommandFn> = {
function showHelp(exitCode: number): never {
const commandDescriptions: Record<string, string> = {
info: 'Show disk info (virtual size, uid, parent uid, block size)',
list: 'List all disks at a path and display their properties in a table',
info: 'Show disk info (virtual size, uid, parent uid, block size); --chain shows the full parent chain, --size adds the size on disk',
list: 'List all disks at a path and display their properties in a table; --size adds the size on disk',
transform: 'Convert a disk to another format and write to stdout (raw | vhd | qcow2)',
}
@@ -30,7 +30,9 @@ ${commandList}
Examples:
xo-disk-cli info file:///mnt/backups /xo-vm-backups/uuid/disk.alias.vhd
xo-disk-cli info file:///mnt/backups /xo-vm-backups/uuid/disk.alias.vhd --chain --size
xo-disk-cli list file:///mnt/backups /xo-vm-backups/uuid/
xo-disk-cli list file:///mnt/backups /xo-vm-backups/uuid/ --size
xo-disk-cli transform file:///mnt/backups /xo-vm-backups/uuid/disk.vhd raw > disk.img
xo-disk-cli transform file:///mnt/backups /xo-vm-backups/uuid/disk.vhd qcow2 > disk.qcow2
`)

View File

@@ -4,25 +4,30 @@
* Focus:
* - Handler and disk are always disposed, even when disk methods throw.
* - Errors from broken disks are propagated (not swallowed).
* - By default disks are opened with ignoreBlockIndexes: true (cheap); --size
* opens with ignoreBlockIndexes: false and prints the size on disk.
* - --chain opens the whole lineage and prints each disk.
*
* Design: mock.module() is called once at the top level. The mock for openDisk
* reads `currentDisk` at call-time via closure, so individual tests can inject
* failure scenarios simply by reassigning the variable before calling the command.
* Design: mock.module() is called once at the top level. The mocks read mutable
* closure variables at call-time so individual tests can inject scenarios simply
* by reassigning a variable before calling the command.
*/
import { describe, test, mock, beforeEach } from 'node:test'
import assert from 'node:assert/strict'
// ---------------------------------------------------------------------------
// Spies — created once and reused; reset in beforeEach.
// Spies & mutable state — created once and reused; reset in beforeEach.
// ---------------------------------------------------------------------------
const handlerDispose = mock.fn(() => Promise.resolve())
const diskDispose = mock.fn(() => Promise.resolve())
const chainClose = mock.fn(() => Promise.resolve())
const baseDisk = {
isDifferencing: () => false,
getVirtualSize: () => 1024 * 1024 * 1024,
getBlockSize: () => 2 * 1024 * 1024,
getSizeOnDisk: () => 128 * 1024 * 1024,
getUuid: () => 'aaaa-bbbb',
getParentUuid: () => 'pppp-qqqq',
}
@@ -30,9 +35,20 @@ const baseDisk = {
// Reassigned per-test to inject different disk behaviours.
let currentDisk: typeof baseDisk = { ...baseDisk }
// Paths returned by the chain (root → leaf); reassigned per-test.
let chainPaths: string[] = ['/vdis/root.vhd', '/vdis/leaf.vhd']
// Records the options each openDisposableDisk call received.
const openDiskParams: Array<{ path: string; ignoreBlockIndexes?: boolean }> = []
const openChainParams: Array<{ path: string; ignoreBlockIndexes?: boolean }> = []
const openDiskChainSpy = mock.fn((params: { path: string; ignoreBlockIndexes?: boolean }) => {
openChainParams.push(params)
return Promise.resolve({ getPaths: () => chainPaths, close: chainClose })
})
// ---------------------------------------------------------------------------
// Module mocks — registered once. openDisk reads `currentDisk` at call-time
// so tests only need to reassign the variable, not re-mock the module.
// Module mocks — registered once. Implementations read mutable state at call-time.
// ---------------------------------------------------------------------------
mock.module('@xen-orchestra/fs', {
@@ -43,14 +59,31 @@ mock.module('@xen-orchestra/fs', {
mock.module('@xen-orchestra/backup-archive/disks', {
namedExports: {
openDisposableDisk: () => Promise.resolve({ value: currentDisk, dispose: diskDispose }),
openDisposableDisk: (params: { path: string; ignoreBlockIndexes?: boolean }) => {
openDiskParams.push(params)
return Promise.resolve({ value: currentDisk, dispose: diskDispose })
},
openDiskChain: openDiskChainSpy,
},
})
// Import the module under test AFTER mocks are registered so it receives the
// mocked implementations. The same infoCommand reference is reused for all tests.
// mocked implementations.
const { infoCommand } = await import('../../commands/info.mjs')
// Capture console.log output without polluting test output.
async function captureLog(fn: () => Promise<void>): Promise<string> {
const lines: string[] = []
const orig = console.log
console.log = (...args: unknown[]) => lines.push(args.map(String).join(' '))
try {
await fn()
} finally {
console.log = orig
}
return lines.join('\n')
}
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
@@ -59,11 +92,16 @@ describe('info command', () => {
beforeEach(() => {
handlerDispose.mock.resetCalls()
diskDispose.mock.resetCalls()
chainClose.mock.resetCalls()
openDiskChainSpy.mock.resetCalls()
openDiskParams.length = 0
openChainParams.length = 0
currentDisk = { ...baseDisk }
chainPaths = ['/vdis/root.vhd', '/vdis/leaf.vhd']
})
test('disposes handler and disk on success', async () => {
await infoCommand('file:///test', '/vdis/disk.vhd', [])
await captureLog(() => infoCommand('file:///test', '/vdis/disk.vhd', []))
assert.strictEqual(handlerDispose.mock.callCount(), 1, 'handler must be disposed once')
assert.strictEqual(diskDispose.mock.callCount(), 1, 'disk must be disposed once')
})
@@ -89,4 +127,63 @@ describe('info command', () => {
}
await assert.rejects(() => infoCommand('file:///test', '/vdis/disk.vhd', []), /corrupt header/)
})
test('by default opens the disk with ignoreBlockIndexes: true and hides size on disk', async () => {
const output = await captureLog(() => infoCommand('file:///test', '/vdis/disk.vhd', []))
assert.strictEqual(openDiskParams.length, 1)
assert.strictEqual(openDiskParams[0].ignoreBlockIndexes, true, 'block indexes must be skipped by default')
assert.ok(!output.includes('Size on disk'), 'size on disk must not be printed without --size')
})
test('--size opens the disk with ignoreBlockIndexes: false and prints size on disk', async () => {
const output = await captureLog(() => infoCommand('file:///test', '/vdis/disk.vhd', ['--size']))
assert.strictEqual(openDiskParams[0].ignoreBlockIndexes, false, 'block indexes must be read with --size')
assert.ok(output.includes('Size on disk'), 'size on disk must be printed with --size')
})
test('without --chain, openDiskChain is never called', async () => {
await captureLog(() => infoCommand('file:///test', '/vdis/disk.vhd', []))
assert.strictEqual(openDiskChainSpy.mock.callCount(), 0, 'openDiskChain must not be called without --chain')
})
test('--chain: opens the chain, opens each disk in it, and disposes everything', async () => {
await captureLog(() => infoCommand('file:///test', '/vdis/leaf.vhd', ['--chain']))
assert.strictEqual(openDiskChainSpy.mock.callCount(), 1, 'openDiskChain must be called once')
assert.strictEqual(chainClose.mock.callCount(), 1, 'chain must be closed after enumerating paths')
// One openDisposableDisk (and thus one dispose) per disk in the chain.
assert.strictEqual(diskDispose.mock.callCount(), chainPaths.length, 'each chain disk must be opened and disposed')
assert.strictEqual(handlerDispose.mock.callCount(), 1, 'handler must be disposed once')
})
test('--chain defaults to ignoreBlockIndexes: true for both the chain and each disk', async () => {
await captureLog(() => infoCommand('file:///test', '/vdis/leaf.vhd', ['--chain']))
assert.strictEqual(openChainParams[0].ignoreBlockIndexes, true, 'chain walk must skip block indexes by default')
assert.ok(
openDiskParams.every(p => p.ignoreBlockIndexes === true),
'each chain disk must be opened with ignoreBlockIndexes: true'
)
})
test('--chain --size reads block indexes and prints size on disk for each disk', async () => {
const output = await captureLog(() => infoCommand('file:///test', '/vdis/leaf.vhd', ['--chain', '--size']))
assert.strictEqual(openChainParams[0].ignoreBlockIndexes, false, 'chain walk must read block indexes with --size')
assert.ok(
openDiskParams.every(p => p.ignoreBlockIndexes === false),
'each chain disk must be opened with ignoreBlockIndexes: false'
)
const sizeLines = output.split('\n').filter(l => l.includes('Size on disk'))
assert.strictEqual(sizeLines.length, chainPaths.length, 'size on disk must be printed for each disk')
})
test('--chain: chain is closed even when opening a disk in it throws', async () => {
currentDisk = {
...baseDisk,
getUuid: () => {
throw new Error('corrupt header')
},
}
await assert.rejects(() => infoCommand('file:///test', '/vdis/leaf.vhd', ['--chain']), /corrupt header/)
assert.strictEqual(chainClose.mock.callCount(), 1, 'chain must be closed even on error')
assert.strictEqual(handlerDispose.mock.callCount(), 1, 'handler must be disposed even on error')
})
})

View File

@@ -27,6 +27,9 @@ const baseDisk = {
getParentUuid: () => null as unknown as string,
}
// Records the options each openDisposableDisk call received.
const openDiskParams: Array<{ path: string; ignoreBlockIndexes?: boolean }> = []
// Reassigned per-test to control what handler.list() returns (or throws).
let currentListImpl: () => Promise<string[]> = async () => []
@@ -52,8 +55,9 @@ mock.module('@xen-orchestra/fs', {
mock.module('@xen-orchestra/backup-archive/disks', {
namedExports: {
isDisk: (p: string) => p.endsWith('.vhd'),
openDisposableDisk: ({ path }: { path: string }) => {
if (brokenPaths.has(path)) throw new Error('disk header corrupted')
openDisposableDisk: (params: { path: string; ignoreBlockIndexes?: boolean }) => {
openDiskParams.push(params)
if (brokenPaths.has(params.path)) throw new Error('disk header corrupted')
return Promise.resolve({ value: { ...baseDisk }, dispose: diskDispose })
},
},
@@ -86,6 +90,7 @@ describe('list command', () => {
handlerDispose.mock.resetCalls()
diskDispose.mock.resetCalls()
brokenPaths.clear()
openDiskParams.length = 0
currentListImpl = async () => ['/dir/disk.vhd']
})
@@ -122,4 +127,22 @@ describe('list command', () => {
const output = await captureLog(() => listCommand('file:///test', '/dir', []))
assert.ok(output.includes('No disks found'))
})
test('by default opens disks with ignoreBlockIndexes: true and hides the size column', async () => {
const output = await captureLog(() => listCommand('file:///test', '/dir', []))
assert.ok(
openDiskParams.every(p => p.ignoreBlockIndexes === true),
'disks must be opened with ignoreBlockIndexes: true by default'
)
assert.ok(!output.includes('Size on disk'), 'the size column must be hidden without --size')
})
test('--size opens disks with ignoreBlockIndexes: false and shows the size column', async () => {
const output = await captureLog(() => listCommand('file:///test', '/dir', ['--size']))
assert.ok(
openDiskParams.every(p => p.ignoreBlockIndexes === false),
'disks must be opened with ignoreBlockIndexes: false with --size'
)
assert.ok(output.includes('Size on disk'), 'the size column must appear with --size')
})
})

View File

@@ -2,6 +2,10 @@ import { describe, test } from 'node:test'
import assert from 'node:assert/strict'
import { sortDisks, toTableRow, type DiskInfo } from '../commands/list.mjs'
// These tests assert on the full-width row (with the "Size on disk" column), so
// they always exercise toTableRow with showSize = true.
const toTableRowWithSize = (disk: DiskInfo, prevDisk: DiskInfo | undefined) => toTableRow(disk, prevDisk, true)
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
@@ -106,43 +110,43 @@ describe('sortDisks', () => {
describe('toTableRow', () => {
test('base disk shows "(none)" in parent uid column', () => {
const row = toTableRow(ok('a'), undefined)
const row = toTableRowWithSize(ok('a'), undefined)
assert.strictEqual(row[5], '(none)')
})
test('differencing disk with no previous disk shows parentUid', () => {
const row = toTableRow(ok('b', 'a'), undefined)
const row = toTableRowWithSize(ok('b', 'a'), undefined)
assert.strictEqual(row[5], 'a')
})
test('differencing disk whose parent is not the previous row shows parentUid', () => {
const row = toTableRow(ok('b', 'a'), ok('x'))
const row = toTableRowWithSize(ok('b', 'a'), ok('x'))
assert.strictEqual(row[5], 'a')
})
test('differencing disk whose parent is immediately above shows ↑', () => {
const row = toTableRow(ok('b', 'a'), ok('a'))
const row = toTableRowWithSize(ok('b', 'a'), ok('a'))
assert.strictEqual(row[5], '↑')
})
test('error disk shows error message in second column', () => {
const row = toTableRow(err('bad.vhd'), undefined)
const row = toTableRowWithSize(err('bad.vhd'), undefined)
assert.ok(row[1].includes('error'))
assert.ok(row[1].includes('disk header corrupted'))
})
test('differencing column shows "yes" for differencing disk', () => {
assert.strictEqual(toTableRow(ok('b', 'a'), undefined)[4], 'yes')
assert.strictEqual(toTableRowWithSize(ok('b', 'a'), undefined)[4], 'yes')
})
test('differencing column shows "no" for base disk', () => {
assert.strictEqual(toTableRow(ok('a'), undefined)[4], 'no')
assert.strictEqual(toTableRowWithSize(ok('a'), undefined)[4], 'no')
})
test('parent with multiple children: at least one child shows parent UID instead of ↑', () => {
const sorted = sortDisks([ok('c2', 'a'), ok('a'), ok('c1', 'a')])
const rows = sorted.map((disk, i) => toTableRow(disk, sorted[i - 1]))
const rows = sorted.map((disk, i) => toTableRowWithSize(disk, sorted[i - 1]))
// Find rows for the two children
const childRows = rows.filter((_row, i) => {

View File

@@ -1,6 +1,6 @@
{
"name": "@xen-orchestra/disk-transform",
"version": "1.3.1",
"version": "1.3.3",
"main": "./dist/index.mjs",
"license": "MIT",
"private": false,

View File

@@ -31,11 +31,15 @@ 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 destinationBlock = Buffer.alloc(this.getBlockSize(), 0)
const destinationBlockData = Buffer.alloc(this.getBlockSize(), 0)
const blockRatio = this.#blockSize / source.getBlockSize()
for (let i = index * blockRatio; i < (index + 1) * blockRatio; i++) {
const firstSourceBlockIndex = index * blockRatio
for (let i = firstSourceBlockIndex; i < firstSourceBlockIndex + blockRatio; i++) {
let data: Buffer | undefined
if (source.hasBlock(i)) {
data = (await source.readBlock(i)).data
@@ -51,12 +55,12 @@ export class DiskLargerBlock extends RandomAccessDisk {
}
}
if (data !== undefined) {
data.copy(destinationBlock, i * source.getBlockSize())
data.copy(destinationBlockData, (i - firstSourceBlockIndex) * source.getBlockSize())
}
}
return {
index,
data: destinationBlock,
data: destinationBlockData,
}
}
@@ -66,19 +70,26 @@ 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++) {
for (let j = 0; j < blockRatio; j++) {
if (this.source.hasBlock(i * blockRatio + j)) {
indexes.push(i)
break
}
if (this.hasBlock(i)) {
indexes.push(i)
}
}
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
}
hasBlock(index: number): boolean {
const source = this.source
let maxBlockSource = Math.ceil(source.getVirtualSize() / source.getBlockSize())

View File

@@ -1,4 +1,4 @@
import assert from 'node:assert'
import assert, { strictEqual } 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.isDiff
return this.parentDisk !== null || this.isDiff
}
instantiateParent(): RandomAccessDisk {
if (!this.parentDisk) throw new Error('No parent disk available')
@@ -118,6 +118,29 @@ 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)],
@@ -214,6 +237,34 @@ 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)
@@ -225,3 +276,29 @@ 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

@@ -42,6 +42,9 @@ export class DiskPassthrough extends Disk {
getBlockIndexes(): Array<number> {
return this.source.getBlockIndexes()
}
getBlockIndexesCount(): number {
return this.source.getBlockIndexesCount()
}
hasBlock(index: number): boolean {
return this.source.hasBlock(index)
}
@@ -102,6 +105,9 @@ export abstract class RandomDiskPassthrough extends RandomAccessDisk {
getBlockIndexes(): Array<number> {
return this.source.getBlockIndexes()
}
getBlockIndexesCount(): number {
return this.source.getBlockIndexesCount()
}
hasBlock(index: number): boolean {
return this.source.hasBlock(index)
}

View File

@@ -49,6 +49,9 @@ export class NegativeDisk extends RandomAccessDisk {
getBlockIndexes(): Array<number> {
return this.#child.getBlockIndexes()
}
getBlockIndexesCount(): number {
return this.#child.getBlockIndexesCount()
}
hasBlock(index: number): boolean {
return this.#child.hasBlock(index)
}

View File

@@ -1,7 +1,7 @@
{
"private": false,
"name": "@xen-orchestra/fs",
"version": "4.9.1",
"version": "4.9.3",
"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

@@ -19,6 +19,7 @@ function getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {
algorithm: 'none',
key: 'none',
ivLength: 0,
authTagLength: 0,
encryptData: buffer => buffer,
encryptStream: stream => stream,
decryptData: buffer => buffer,
@@ -127,6 +128,7 @@ function getEncryptor(algorithm = DEFAULT_ENCRYPTION_ALGORITHM, key) {
id: algorithm,
algorithm,
key,
authTagLength,
ivLength,
encryptData,
encryptStream,

View File

@@ -292,7 +292,14 @@ export default class RemoteHandlerAbstract {
async outputStream(path, input, { checksum = true, dirMode, maxStreamLength, streamLength, validator } = {}) {
path = normalizePath(path)
let checksumStream
info('will output stream ', { path, streamLength, maxStreamLength, isEncrypted: this.isEncrypted })
if (this.isEncrypted) {
info('stream is encrypted', { path, streamLength, maxStreamLength })
const overhead = this.#encryptor.ivLength + this.#encryptor.authTagLength
if (streamLength !== undefined) streamLength += overhead
if (maxStreamLength !== undefined) maxStreamLength += overhead
info('stream is updated ', { path, streamLength, maxStreamLength, overhead })
}
input = this.#encryptor.encryptStream(input)
if (checksum) {
checksumStream = createChecksumStream()

View File

@@ -441,7 +441,11 @@ export default class S3Handler extends RemoteHandlerAbstract {
new DeleteObjectsCommand({
Bucket: this.#bucket,
Delete: {
Objects: result.Contents ?? [],
// 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 })),
},
})
)

View File

@@ -157,7 +157,7 @@ export abstract class RemoteHandlerAbstract {
abstract getInfo(): Promise<RemoteInfoResult>
abstract getSize(file: FileDescriptor): Promise<number>
abstract getSizeOnDisk(file: FileArg): Promise<number>
abstract getSizeOnDisk(file: FileDescriptor): Promise<number>
abstract lock(path: string): Promise<LockDisposer>
abstract test(): Promise<TestResult>
abstract isImmutable(): boolean

View File

@@ -38,8 +38,7 @@ immutabilityDuration = "7d"
## CLI commands
- **`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.
- **`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`.
## How protection works
@@ -86,6 +85,8 @@ 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
@@ -113,8 +114,10 @@ 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/
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
```
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.
@@ -124,7 +127,7 @@ Change the setting. The next lift cycle will use the new duration; files already
### Reducing the immutability duration
Change the setting, then run `xo-lift-remote-immutability` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
Change the setting, then restart `xo-immutable-remote` 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,8 +54,7 @@ immutabilityDuration = "7d"
## CLI commands
- **`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.
- **`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`.
## How protection works
@@ -102,6 +101,8 @@ 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
@@ -116,7 +117,7 @@ Restart `xo-immutable-remote`. The first lift run after startup always performs
chattr -i -R /path/to/remote/on/fileserver/
```
### Make one VM mutable again temporarly
### Make one VM temporarily mutable again
If one or a few VM had an issue and need manual cleanup, you can manually lift the immutability for one VM.
@@ -125,14 +126,16 @@ 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 reparable and purge the non recoverable backups
3. Run the backup job, it will fix what is repairable 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/
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
```
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
@@ -140,7 +143,7 @@ Change the setting. The next lift cycle will use the new duration; files already
### Reducing the immutability duration
Change the setting, then run `xo-lift-remote-immutability` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
Change the setting, then restart `xo-immutable-remote` 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.3",
"version": "3.0.5",
"engines": {
"node": ">=20.0.0"
},
"dependencies": {
"@vates/async-each": "^1.0.3",
"@xen-orchestra/backups": "^0.73.5",
"@xen-orchestra/backups": "^0.74.2",
"@xen-orchestra/log": "^0.7.2",
"app-conf": "^3.0.0",
"execa": "^5.0.0",

View File

@@ -8,17 +8,18 @@ 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 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.
// 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.
//
// 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)
await execa('chattr', args, { env: { LC_ALL: 'C' } })
return
} catch (err) {
const stderr = (err as ExecaError).stderr ?? ''

View File

@@ -0,0 +1,177 @@
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,6 +118,68 @@ 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> {
@@ -180,6 +242,12 @@ 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,6 +13,7 @@ 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,5 +1,23 @@
# ChangeLog
## **0.25.0** (2026-08-31)
- [Treeview] Add VM tree actions (PR [#10304](https://github.com/vatesfr/xen-orchestra/pull/10304))
- [Pool/networks] Add the possibility to create new network or bonded network (PR [#10145](https://github.com/vatesfr/xen-orchestra/pull/10145))
- [VM] Add VDIs page with table and side panel (PR [#10269](https://github.com/vatesfr/xen-orchestra/pull/10269))
- [Host/Network] Add ability to rescan physical network interfaces (PIFs) (PR [#10147](https://github.com/vatesfr/xen-orchestra/pull/10147))
- Fix inconsistent spacing in side panel cards (PR [#10279](https://github.com/vatesfr/xen-orchestra/pull/10279))
- Fix missing collapse buttons on pools and hosts in the tree sidebar (added `hasChildren` prop) (PR [#10244](https://github.com/vatesfr/xen-orchestra/pull/10244))
- [Pool/networks] Add the possibility to create new internal network (PR [#10235](https://github.com/vatesfr/xen-orchestra/pull/10235))
## **0.24.0** (2026-07-30)
- [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)
- Update the UiTitle component to use the one from web-core (PR [#9869](https://github.com/vatesfr/xen-orchestra/pull/9869))
@@ -12,6 +30,7 @@
- [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.23.0",
"version": "0.25.0",
"type": "module",
"scripts": {
"dev": "GIT_HEAD=$(git rev-parse HEAD) vite",
@@ -23,18 +23,21 @@
"@fortawesome/vue-fontawesome": "^3.0.8",
"@intlify/unplugin-vue-i18n": "^6.0.3",
"@novnc/novnc": "~1.5.0",
"@regle/core": "^1.26.0",
"@regle/rules": "^1.26.0",
"@regle/schemas": "^1.20.2",
"@tsconfig/node18": "^18.2.4",
"@types/d3-time-format": "^4.0.3",
"@types/file-saver": "^2.0.7",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18.19.80",
"@vates/types": "^1.28.0",
"@vates/types": "^2.0.1",
"@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.56.0",
"@xen-orchestra/web-core": "^0.60.0",
"complex-matcher": "^1.1.1",
"d3-time-format": "^4.1.0",
"decorator-synchronized": "^0.6.0",

View File

@@ -11,8 +11,7 @@
</main>
</div>
</div>
<VtsModalList />
<VtsDrawerList />
<VtsOverlayList />
<VtsTooltipList />
</template>
@@ -20,14 +19,13 @@
import AppHeader from '@/components/AppHeader.vue'
import AppLogin from '@/components/AppLogin.vue'
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 VtsDrawerList from '@core/components/drawer/VtsDrawerList.vue'
import VtsModalList from '@core/components/modal/VtsModalList.vue'
import { useUnreachableHosts } from '@/composables/unreachable-hosts.composable.ts'
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import VtsOverlayList from '@core/components/overlay/VtsOverlayList.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'
import { useChartTheme } from '@core/composables/chart-theme.composable.ts'
import { useUiStore } from '@core/stores/ui.store.ts'
import { useActiveElement, useMagicKeys, whenever } from '@vueuse/core'
import { logicAnd } from '@vueuse/math'
import { computed } from 'vue'

View File

@@ -26,11 +26,11 @@
import AccountMenu from '@/components/account-menu/AccountMenu.vue'
import PoolOverrideWarning from '@/components/PoolOverrideWarning.vue'
import XoaButton from '@/components/XoaButton.vue'
import { useNavigationStore } from '@/stores/navigation.store'
import { useNavigationStore } from '@/stores/navigation.store.ts'
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
import UiLogoText from '@core/components/ui/logo-text/UiLogoText.vue'
import { useUiStore } from '@core/stores/ui.store'
import { useUiStore } from '@core/stores/ui.store.ts'
import { storeToRefs } from 'pinia'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

View File

@@ -42,9 +42,9 @@
import FormInput from '@/components/form/FormInput.vue'
import LoginError from '@/components/LoginError.vue'
import PoolOverrideWarning from '@/components/PoolOverrideWarning.vue'
import type { XenApiError } from '@/libs/xen-api/xen-api.types'
import { usePageTitleStore } from '@/stores/page-title.store'
import { useXenApiStore } from '@/stores/xen-api.store'
import type { XenApiError } from '@/libs/xen-api/xen-api.types.ts'
import { usePageTitleStore } from '@/stores/page-title.store.ts'
import { useXenApiStore } from '@/stores/xen-api.store.ts'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
import UiButton from '@core/components/ui/button/UiButton.vue'

View File

@@ -5,7 +5,7 @@
</template>
<script lang="ts" setup>
import markdown from '@/libs/markdown'
import markdown from '@/libs/markdown.ts'
import { useEventListener } from '@vueuse/core'
import { computed, type Ref, ref } from 'vue'

View File

@@ -10,7 +10,7 @@
<script lang="ts" setup>
import StoryMenu from '@/components/component-story/StoryMenu.vue'
import InfraPoolList from '@/components/infra/InfraPoolList.vue'
import { useNavigationStore } from '@/stores/navigation.store'
import { useNavigationStore } from '@/stores/navigation.store.ts'
import { onClickOutside, tryOnMounted, useTimeoutFn, watchImmediate } from '@vueuse/core'
import { storeToRefs } from 'pinia'
import { ref, watch } from 'vue'

View File

@@ -5,7 +5,7 @@
</template>
<script lang="ts" setup>
import { type AcceptedLanguage, highlight } from '@/libs/highlight'
import { type AcceptedLanguage, highlight } from '@/libs/highlight.ts'
import { computed } from 'vue'
const props = withDefaults(

View File

@@ -19,9 +19,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 { useModal } from '@core/packages/modal/use-modal.ts'
import { computed } from 'vue'
import type { Filters } from '@/types/filter.ts'
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
import { useI18n } from 'vue-i18n'
const { availableFilters } = defineProps<{
@@ -36,18 +35,25 @@ const emit = defineEmits<{
const { t } = useI18n()
const openFilterModal = useModal((editedFilter?: string) => ({
component: import('@/components/modals/CollectionFilterModal.vue'),
props: {
editedFilter,
availableFilters: computed(() => availableFilters),
const { open } = useOverlay({
component: () => import('@/components/modals/CollectionFilterModal.vue'),
events: {
onCancel: true,
},
onConfirm: async newFilter => {
if (editedFilter !== undefined) {
emit('removeFilter', editedFilter)
}
})
emit('addFilter', newFilter)
},
}))
function openFilterModal(editedFilter?: string) {
return open({
props: { editedFilter, availableFilters },
events: {
onConfirm: newFilter => {
if (editedFilter !== undefined) {
emit('removeFilter', editedFilter)
}
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" :icon="currentFilterIcon" />
<VtsSelect :id="builderPropertySelectId" accent="brand" />
<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" />
@@ -19,9 +19,8 @@
<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 { buildComplexMatcherNode } from '@/libs/complex-matcher.utils.ts'
import type { Filter, FilterComparisons, FilterComparisonType, Filters, FilterType, NewFilter } from '@/types/filter.ts'
import VtsSelect from '@core/components/select/VtsSelect.vue'
import UiInput from '@core/components/ui/input/UiInput.vue'
import { useFormSelect } from '@core/packages/form-select'
@@ -104,8 +103,6 @@ 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

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

View File

@@ -14,12 +14,12 @@
</template>
<script lang="ts" setup>
import type { XenApiPatchWithHostRefs } from '@/composables/host-patches.composable'
import type { XenApiPatchWithHostRefs } from '@/composables/host-patches.composable.ts'
import VtsRow from '@core/components/table/VtsRow.vue'
import VtsTable from '@core/components/table/VtsTable.vue'
import { useTableState } from '@core/composables/table-state.composable'
import { useUiStore } from '@core/stores/ui.store'
import { usePatchColumns } from '@core/tables/column-sets/patch-columns'
import { useTableState } from '@core/composables/table-state.composable.ts'
import { useUiStore } from '@core/stores/ui.store.ts'
import { usePatchColumns } from '@core/tables/column-sets/patch-columns.ts'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'

View File

@@ -11,7 +11,7 @@
</template>
<script lang="ts" setup>
import type { XenApiError } from '@/libs/xen-api/xen-api.types'
import type { XenApiError } from '@/libs/xen-api/xen-api.types.ts'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import { useI18n } from 'vue-i18n'

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