From d49648604b29e33804aae5c0e78f7f63eab2e0d9 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 22 Oct 2026 22:51:58 +0200 Subject: [PATCH 1/6] =?UTF-8?q?f-74:=20qemu:=20num=C3=A9ro=20de=20s=C3=A9r?= =?UTF-8?q?ie=20=20sur=20chaque=20disque,=20ligne=20de=20commande=20c?= =?UTF-8?q?onstruite=20hors=20de=20Start=20#74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- internal/qemu/args.go | 112 +++++++++++++++++++++++++++++++++++ internal/qemu/args_test.go | 75 +++++++++++++++++++++++ internal/qemu/start_linux.go | 105 +------------------------------- 3 files changed, 190 insertions(+), 102 deletions(-) create mode 100644 internal/qemu/args.go create mode 100644 internal/qemu/args_test.go diff --git a/internal/qemu/args.go b/internal/qemu/args.go new file mode 100644 index 0000000..3e12f7a --- /dev/null +++ b/internal/qemu/args.go @@ -0,0 +1,112 @@ +package qemu + +import ( + "fmt" + "path/filepath" + "sort" + "strings" +) + +const ( + firstNICSlot = 0x03 + lastNICSlot = 0x1d + maxNICs = lastNICSlot - firstNICSlot + 1 +) + +func buildArgs(cfg Config) ([]string, error) { + memory := cfg.Memory + if memory == 0 { + memory = 512 + } + + cpus := cfg.CPUs + if cpus == 0 { + cpus = 1 + } + + serialSock := filepath.Join(cfg.SerialDir, cfg.Name+".sock") + monitorSock := filepath.Join(cfg.MonitorDir, cfg.Name+".sock") + qmpSock := filepath.Join(cfg.QMPDir, cfg.Name+".sock") + + args := []string{ + "-enable-kvm", + "-cpu", "host", + "-m", fmt.Sprintf("%d", memory), + "-smp", fmt.Sprintf("%d", cpus), + "-serial", fmt.Sprintf("unix:%s,server,nowait", serialSock), + "-monitor", fmt.Sprintf("unix:%s,server,nowait", monitorSock), + "-qmp", fmt.Sprintf("unix:%s,server,nowait", qmpSock), + "-display", "none", + } + + if cfg.UEFICodePath != "" && cfg.UEFIVarsPath != "" { + args = append(args, + "-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", cfg.UEFICodePath), + "-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", cfg.UEFIVarsPath), + ) + } + + hasScsi := false + virtioBlk := 0 + for _, d := range cfg.Disks { + if strings.HasPrefix(d.Dev, "sd") { + hasScsi = true + } else { + virtioBlk++ + } + } + if virtioBlk > 1 { + return nil, fmt.Errorf("qemu: %d disques virtio-blk (vd*) déclarés, un seul est supporté — utiliser des disques sd* pour les disques additionnels", virtioBlk) + } + if hasScsi { + args = append(args, "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x1e") + } + + sorted := make([]DiskConfig, len(cfg.Disks)) + copy(sorted, cfg.Disks) + // vd* avant sd* : les disques virtio-blk bootent en premier. + // À lettre égale de type, ordre alphabétique. + sort.Slice(sorted, func(i, j int) bool { + iVirtio := strings.HasPrefix(sorted[i].Dev, "vd") + jVirtio := strings.HasPrefix(sorted[j].Dev, "vd") + if iVirtio != jVirtio { + return iVirtio + } + return sorted[i].Dev < sorted[j].Dev + }) + + for idx, d := range sorted { + bootindex := idx + 1 + if strings.HasPrefix(d.Dev, "sd") { + scsiID := int(d.Dev[2] - 'a') + args = append(args, + "-drive", fmt.Sprintf("file=%s,if=none,id=%s", d.Path, d.Dev), + "-device", fmt.Sprintf("scsi-hd,drive=%s,bus=scsi0.0,scsi-id=%d,bootindex=%d,serial=%s", d.Dev, scsiID, bootindex, d.Dev), + ) + } else { + args = append(args, + "-drive", fmt.Sprintf("file=%s,if=none,id=%s", d.Path, d.Dev), + "-device", fmt.Sprintf("virtio-blk-pci,drive=%s,bus=pci.0,addr=0x1f,bootindex=%d,serial=%s", d.Dev, bootindex, d.Dev), + ) + } + } + + // Slots 0x03 à 0x1d réservés au réseau par la carte PCI (#36). Le slot est + // dérivé de l'index et non laissé à QEMU : c'est lui qui fixe le nom de + // l'interface dans le guest, et un slot flottant la renomme d'un démarrage + // à l'autre. + if len(cfg.NICs) == 0 { + return nil, fmt.Errorf("vm %s has no network interface", cfg.Name) + } + if len(cfg.NICs) > maxNICs { + return nil, fmt.Errorf("vm %s has %d interfaces, the pci map holds %d", cfg.Name, len(cfg.NICs), maxNICs) + } + for i, n := range cfg.NICs { + args = append(args, + "-netdev", fmt.Sprintf("tap,id=net%d,ifname=tap%d,script=no,downscript=no", i, n.TapID), + "-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s,bus=pci.0,addr=0x%02x", i, n.Mac, firstNICSlot+i), + ) + } + + return append(args, "-daemonize"), nil +} diff --git a/internal/qemu/args_test.go b/internal/qemu/args_test.go new file mode 100644 index 0000000..fe3b072 --- /dev/null +++ b/internal/qemu/args_test.go @@ -0,0 +1,75 @@ +package qemu + +import ( + "testing" +) + +func devicesOf(args []string) []string { + var devices []string + for i := 0; i+1 < len(args); i++ { + if args[i] == "-device" { + devices = append(devices, args[i+1]) + } + } + return devices +} + +func TestBuildArgs_DiskSerialIsDeclaredDev(t *testing.T) { + args, err := buildArgs(Config{ + Name: "vm1", + NICs: []NICConfig{{TapID: 1, Mac: "52:54:00:00:00:01"}}, + Disks: []DiskConfig{ + {Path: "/v/b.qcow2", Dev: "sdb"}, + {Path: "/v/root.qcow2", Dev: "vda"}, + {Path: "/v/a.qcow2", Dev: "sda"}, + }, + }) + if err != nil { + t.Fatalf("buildArgs a échoué : %v", err) + } + + want := []string{ + "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x1e", + "virtio-blk-pci,drive=vda,bus=pci.0,addr=0x1f,bootindex=1,serial=vda", + "scsi-hd,drive=sda,bus=scsi0.0,scsi-id=0,bootindex=2,serial=sda", + "scsi-hd,drive=sdb,bus=scsi0.0,scsi-id=1,bootindex=3,serial=sdb", + "virtio-net-pci,netdev=net0,mac=52:54:00:00:00:01,bus=pci.0,addr=0x03", + } + got := devicesOf(args) + if len(got) != len(want) { + t.Fatalf("devices = %q, attendu %q", got, want) + } + for i := range want { + if got[i] != want[i] { + t.Errorf("device %d = %q, attendu %q", i, got[i], want[i]) + } + } +} + +func TestBuildArgs_EndsWithDaemonize(t *testing.T) { + args, err := buildArgs(Config{Name: "vm1", NICs: []NICConfig{{TapID: 1, Mac: "52:54:00:00:00:01"}}}) + if err != nil { + t.Fatalf("buildArgs a échoué : %v", err) + } + if args[len(args)-1] != "-daemonize" { + t.Errorf("dernier argument = %q, attendu -daemonize", args[len(args)-1]) + } +} + +func TestBuildArgs_RejectsSecondVirtioDisk(t *testing.T) { + _, err := buildArgs(Config{ + Name: "vm1", + NICs: []NICConfig{{TapID: 1, Mac: "52:54:00:00:00:01"}}, + Disks: []DiskConfig{{Path: "/v/a", Dev: "vda"}, {Path: "/v/b", Dev: "vdb"}}, + }) + if err == nil { + t.Fatal("buildArgs a accepté deux disques virtio") + } +} + +func TestBuildArgs_RejectsNoNIC(t *testing.T) { + _, err := buildArgs(Config{Name: "vm1"}) + if err == nil { + t.Fatal("buildArgs a accepté une VM sans interface") + } +} diff --git a/internal/qemu/start_linux.go b/internal/qemu/start_linux.go index 1a8f918..4316180 100644 --- a/internal/qemu/start_linux.go +++ b/internal/qemu/start_linux.go @@ -6,28 +6,10 @@ import ( "fmt" "os" "os/exec" - "path/filepath" - "sort" "strings" ) -const ( - firstNICSlot = 0x03 - lastNICSlot = 0x1d - maxNICs = lastNICSlot - firstNICSlot + 1 -) - func Start(cfg Config) error { - memory := cfg.Memory - if memory == 0 { - memory = 512 - } - - cpus := cfg.CPUs - if cpus == 0 { - cpus = 1 - } - for _, dir := range []string{cfg.SerialDir, cfg.MonitorDir, cfg.QMPDir} { if dir != "" { if err := os.MkdirAll(dir, 0755); err != nil { @@ -36,92 +18,11 @@ func Start(cfg Config) error { } } - serialSock := filepath.Join(cfg.SerialDir, cfg.Name+".sock") - monitorSock := filepath.Join(cfg.MonitorDir, cfg.Name+".sock") - qmpSock := filepath.Join(cfg.QMPDir, cfg.Name+".sock") - - args := []string{ - "-enable-kvm", - "-cpu", "host", - "-m", fmt.Sprintf("%d", memory), - "-smp", fmt.Sprintf("%d", cpus), - "-serial", fmt.Sprintf("unix:%s,server,nowait", serialSock), - "-monitor", fmt.Sprintf("unix:%s,server,nowait", monitorSock), - "-qmp", fmt.Sprintf("unix:%s,server,nowait", qmpSock), - "-display", "none", + args, err := buildArgs(cfg) + if err != nil { + return err } - if cfg.UEFICodePath != "" && cfg.UEFIVarsPath != "" { - args = append(args, - "-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", cfg.UEFICodePath), - "-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", cfg.UEFIVarsPath), - ) - } - - hasScsi := false - virtioBlk := 0 - for _, d := range cfg.Disks { - if strings.HasPrefix(d.Dev, "sd") { - hasScsi = true - } else { - virtioBlk++ - } - } - if virtioBlk > 1 { - return fmt.Errorf("qemu: %d disques virtio-blk (vd*) déclarés, un seul est supporté — utiliser des disques sd* pour les disques additionnels", virtioBlk) - } - if hasScsi { - args = append(args, "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x1e") - } - - sorted := make([]DiskConfig, len(cfg.Disks)) - copy(sorted, cfg.Disks) - // vd* avant sd* : les disques virtio-blk bootent en premier. - // À lettre égale de type, ordre alphabétique. - sort.Slice(sorted, func(i, j int) bool { - iVirtio := strings.HasPrefix(sorted[i].Dev, "vd") - jVirtio := strings.HasPrefix(sorted[j].Dev, "vd") - if iVirtio != jVirtio { - return iVirtio - } - return sorted[i].Dev < sorted[j].Dev - }) - - for idx, d := range sorted { - bootindex := idx + 1 - if strings.HasPrefix(d.Dev, "sd") { - scsiID := int(d.Dev[2] - 'a') - args = append(args, - "-drive", fmt.Sprintf("file=%s,if=none,id=%s", d.Path, d.Dev), - "-device", fmt.Sprintf("scsi-hd,drive=%s,bus=scsi0.0,scsi-id=%d,bootindex=%d", d.Dev, scsiID, bootindex), - ) - } else { - args = append(args, - "-drive", fmt.Sprintf("file=%s,if=none,id=%s", d.Path, d.Dev), - "-device", fmt.Sprintf("virtio-blk-pci,drive=%s,bus=pci.0,addr=0x1f,bootindex=%d", d.Dev, bootindex), - ) - } - } - - // Slots 0x03 à 0x1d réservés au réseau par la carte PCI (#36). Le slot est - // dérivé de l'index et non laissé à QEMU : c'est lui qui fixe le nom de - // l'interface dans le guest, et un slot flottant la renomme d'un démarrage - // à l'autre. - if len(cfg.NICs) == 0 { - return fmt.Errorf("vm %s has no network interface", cfg.Name) - } - if len(cfg.NICs) > maxNICs { - return fmt.Errorf("vm %s has %d interfaces, the pci map holds %d", cfg.Name, len(cfg.NICs), maxNICs) - } - for i, n := range cfg.NICs { - args = append(args, - "-netdev", fmt.Sprintf("tap,id=net%d,ifname=tap%d,script=no,downscript=no", i, n.TapID), - "-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s,bus=pci.0,addr=0x%02x", i, n.Mac, firstNICSlot+i), - ) - } - - args = append(args, "-daemonize") - scopeArgs := append([]string{ "--scope", "--unit=" + ScopeName(cfg.Name), From 096ee1dc0ed716e85ed4dfa23a2a1b488648f46e Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 22 Oct 2026 22:52:05 +0200 Subject: [PATCH 2/6] =?UTF-8?q?f-74:=20e2e:=2026-multi-disque=20v=C3=A9rif?= =?UTF-8?q?ie=20les=20liens=20by-id=20au=20lieu=20du=20nom=20dans=20l'invi?= =?UTF-8?q?t=C3=A9=20#74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- test/e2e/suite/26-multi-disque.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/e2e/suite/26-multi-disque.sh b/test/e2e/suite/26-multi-disque.sh index 4e563f7..c756764 100644 --- a/test/e2e/suite/26-multi-disque.sh +++ b/test/e2e/suite/26-multi-disque.sh @@ -1,6 +1,6 @@ -# fonctionnalité: VM à plusieurs disques — virtio (vdX) et SCSI (sdX), tailles et bus vus par la VM, démarrage sur vda +# fonctionnalité: VM à plusieurs disques — virtio (vdX) et SCSI (sdX), tailles et bus vus par la VM, liens by-id par numéro de série, démarrage sur vda # hôtes: hv1 -# tickets: #32 +# tickets: #32, #74 on hv1 <<'NODE' KEY=$(vm_key) @@ -14,12 +14,14 @@ check "VM t26-d : vda (système), sdb, sda" vm_launch t26-d --nic sn-t26=10.26.1 check "API : trois disques" test "$(curl -fsS "${API}/vms/t26-d" | jq -r '[.storage[].dev] | sort | join(" ")')" = "sda sdb vda" check "t26-d joignable (démarrée sur vda)" vm_wait vp-t26 10.26.1.10 check "t26-d : racine sur vda" vm_grep vp-t26 10.26.1.10 'findmnt -n -o SOURCE /' '^/dev/vda' -size_is () { local v; v=$(vm_ssh vp-t26 10.26.1.10 "lsblk -b -dn -o SIZE /dev/${1}" 2>&1 | tr -d ' '); [ "${v}" = "${2}" ] || { echo "lu : ${v}"; return 1; }; } target_size () { local v; v=$(vm_ssh vp-t26 10.26.1.10 "lsblk -b -dn -o HCTL,SIZE" 2>&1 | awk -v t="${1}" '{split($1, h, ":")} h[3] == t {print $2}'); [ "${v}" = "${2}" ] || { echo "lu : ${v:-aucun disque sur la cible ${1}}"; return 1; }; } check "t26-d : sda déclaré → cible SCSI 0, 2 Gio" target_size 0 2147483648 check "t26-d : sdb déclaré → cible SCSI 1, 1 Gio" target_size 1 1073741824 -known_flaky "#74" "t26-d : nom dans l'invité = dev déclaré, sdb de 1 Gio" size_is sdb 1073741824 -known_flaky "#74" "t26-d : nom dans l'invité = dev déclaré, sda de 2 Gio" size_is sda 2147483648 +info "t26-d : /dev/disk/by-id : $(vm_ssh vp-t26 10.26.1.10 'ls /dev/disk/by-id' 2>&1 | tr '\n' ' ')" +by_id_size () { local v; v=$(vm_ssh vp-t26 10.26.1.10 "lsblk -b -dn -o SIZE \$(readlink -e /dev/disk/by-id/${1})" 2>&1 | tr -d ' '); [ "${v}" = "${2}" ] || { echo "lu : ${v}"; return 1; }; } +check "t26-d : sdb déclaré → by-id scsi-0QEMU_QEMU_HARDDISK_sdb, 1 Gio" by_id_size scsi-0QEMU_QEMU_HARDDISK_sdb 1073741824 +check "t26-d : sda déclaré → by-id scsi-0QEMU_QEMU_HARDDISK_sda, 2 Gio" by_id_size scsi-0QEMU_QEMU_HARDDISK_sda 2147483648 +check "t26-d : vda déclaré → by-id virtio-vda, disque système" test "$(vm_ssh vp-t26 10.26.1.10 'readlink -e /dev/disk/by-id/virtio-vda')" = /dev/vda check "t26-d : sdb en SCSI" vm_grep vp-t26 10.26.1.10 'readlink -f /sys/block/sdb/device/driver' 'sd$' check "t26-d : sda en SCSI (virtio-scsi)" vm_ssh vp-t26 10.26.1.10 'test -d /sys/block/sda/device/scsi_device && readlink -f /sys/block/sda | grep -q virtio' check "t26-d : vda n'est pas en SCSI (témoin)" vm_fails vp-t26 10.26.1.10 'test -d /sys/block/vda/device/scsi_device' From 9b5b4a6e62e863dc14146339239c36ced68a0443 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Thu, 22 Oct 2026 22:52:12 +0200 Subject: [PATCH 3/6] =?UTF-8?q?f-74:=20doc:=20dev=20d=C3=A9signe=20l'empla?= =?UTF-8?q?cement=20du=20disque,=20nom=20stable=20sous=20/dev/disk/by-id?= =?UTF-8?q?=20#74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- api/agent.yaml | 7 ++++++- docs/concepts/vpc-subnet-vm.rst | 4 +++- docs/demarrage/premier-vpc.rst | 8 +++++++- docs/developpement/lab.rst | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/api/agent.yaml b/api/agent.yaml index 04502fd..26b223e 100644 --- a/api/agent.yaml +++ b/api/agent.yaml @@ -566,7 +566,12 @@ components: example: /var/lib/two/volumes/abc.qcow2 dev: type: string - description: Device name inside the VM + description: >- + Disk slot: vda is the virtio-blk system disk (one at most), sdX + is SCSI target X (a → 0). Not a guaranteed name inside the VM: + the guest kernel names SCSI disks in detection order. The disk + serial is set to dev, so the guest finds it under + /dev/disk/by-id/ (virtio-, scsi-0QEMU_QEMU_HARDDISK_). pattern: '^[sv]d[a-z]$' example: vda diff --git a/docs/concepts/vpc-subnet-vm.rst b/docs/concepts/vpc-subnet-vm.rst index 8dcf2b7..212225e 100644 --- a/docs/concepts/vpc-subnet-vm.rst +++ b/docs/concepts/vpc-subnet-vm.rst @@ -96,7 +96,9 @@ subnet — l'ordre qui évite le trou noir de `#41 ``. Ce qui est stocké, et où ------------------------ diff --git a/docs/demarrage/premier-vpc.rst b/docs/demarrage/premier-vpc.rst index 562978f..3d3b2de 100644 --- a/docs/demarrage/premier-vpc.rst +++ b/docs/demarrage/premier-vpc.rst @@ -96,7 +96,7 @@ Là encore, attendez ``running`` : "interfaces": [{"subnet": "sn-000001", "ip": "10.1.1.2", "mac": "52:54:00:01:01:02", "primary": true}], "storage": [{"path": "/var/lib/two/volumes/i-web.qcow2", "dev": "vda"}]}' -Quatre points qui coûtent du temps quand on les découvre en production : +Six points qui coûtent du temps quand on les découvre en production : ``user_data`` est **encodé en base64** Un base64 invalide est rejeté en 400 plutôt que servi vide. L'agent n'interprète jamais ce @@ -119,6 +119,12 @@ Un seul disque ``vdX`` Les disques supplémentaires passent par ``sdX``. La carte PCI en dépend — voir :doc:`/architecture/contraintes`. +``dev`` désigne un emplacement, pas un nom dans le guest + ``sdb`` est la cible SCSI 1, mais le noyau du guest nomme les disques SCSI dans l'ordre de + détection : ``/dev/sdb`` peut être un autre disque. L'agent donne à chaque disque le numéro + de série ```` ; le nom stable est sous ``/dev/disk/by-id/`` : + ``scsi-0QEMU_QEMU_HARDDISK_sdb``, ``virtio-vda``. + 4. Vérifier ----------- diff --git a/docs/developpement/lab.rst b/docs/developpement/lab.rst index 3a7b599..a3972bb 100644 --- a/docs/developpement/lab.rst +++ b/docs/developpement/lab.rst @@ -320,9 +320,9 @@ Générée par ``test/e2e/run.sh --matrice`` à partir des en-têtes ; à régé - hv1 - #33, #62, #73 * - ``26-multi-disque`` - - VM à plusieurs disques — virtio (vdX) et SCSI (sdX), tailles et bus vus par la VM, démarrage sur vda + - VM à plusieurs disques — virtio (vdX) et SCSI (sdX), tailles et bus vus par la VM, liens ``by-id`` par numéro de série, démarrage sur vda - hv1 - - #32 + - #32, #74 * - ``27-reboot`` - redémarrage d'une VM depuis l'invité — même processus QEMU, même adresse, nouveau bail, user_data non rejoué - hv1 From e16edb00bf9edaae1c576b4147f97527e2f10349 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Fri, 23 Oct 2026 00:26:33 +0200 Subject: [PATCH 4/6] =?UTF-8?q?f-74:=20api:=20disques=20additionnels=20xvd?= =?UTF-8?q?X=20sur=20la=20cible=20SCSI=20de=20m=C3=AAme=20rang,=20sdX=20re?= =?UTF-8?q?fus=C3=A9,=20migration=20des=20cl=C3=A9s=20disk/sdX=20#74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- cmd/agent/main.go | 5 +++ internal/api/agent/vm_test.go | 63 ++++++++++++++++++-------- internal/api/agent/vms.go | 8 ++++ internal/migration/disk.go | 40 +++++++++++++++++ internal/migration/disk_test.go | 80 +++++++++++++++++++++++++++++++++ internal/qemu/args.go | 10 ++--- internal/qemu/args_test.go | 8 ++-- 7 files changed, 187 insertions(+), 27 deletions(-) create mode 100644 internal/migration/disk.go create mode 100644 internal/migration/disk_test.go diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 98b8e3d..548316e 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -68,6 +68,11 @@ func run(confFile string) int { return 1 } + if err := migration.MigrateVMDisks(db, log.With(slog.String("component", "migration"))); err != nil { + log.Error("vm disk migration failed", "error", err) + return 1 + } + if cfg.BGP.Enabled() { if err := applyBGPBase(cfg, frr.NewClient()); err != nil { log.Error("failed to apply the bgp base configuration", "error", err) diff --git a/internal/api/agent/vm_test.go b/internal/api/agent/vm_test.go index 7412d38..9761917 100644 --- a/internal/api/agent/vm_test.go +++ b/internal/api/agent/vm_test.go @@ -24,7 +24,7 @@ func TestVmFromDB_SingleDisk(t *testing.T) { "vm/vm-1/metadata_port": "1234", "vm/vm-1/memory": "512", "vm/vm-1/cpus": "1", - "vm/vm-1/disk/sda": "/data/root.qcow2", + "vm/vm-1/disk/xvda": "/data/root.qcow2", } vm, err := vmFromDB("vm-1", entries) if err != nil { @@ -33,7 +33,7 @@ func TestVmFromDB_SingleDisk(t *testing.T) { if len(vm.Storage) != 1 { t.Fatalf("attendu 1 disque, obtenu %d", len(vm.Storage)) } - if vm.Storage[0].Dev != "sda" || vm.Storage[0].Path != "/data/root.qcow2" { + if vm.Storage[0].Dev != "xvda" || vm.Storage[0].Path != "/data/root.qcow2" { t.Errorf("disque inattendu : %+v", vm.Storage[0]) } } @@ -46,8 +46,8 @@ func TestVmFromDB_MultiDisk(t *testing.T) { "vm/vm-2/metadata_port": "1235", "vm/vm-2/memory": "1024", "vm/vm-2/cpus": "2", - "vm/vm-2/disk/sda": "/data/root.qcow2", - "vm/vm-2/disk/sdb": "/data/data.qcow2", + "vm/vm-2/disk/xvda": "/data/root.qcow2", + "vm/vm-2/disk/xvdb": "/data/data.qcow2", } vm, err := vmFromDB("vm-2", entries) if err != nil { @@ -57,13 +57,13 @@ func TestVmFromDB_MultiDisk(t *testing.T) { t.Fatalf("attendu 2 disques, obtenu %d", len(vm.Storage)) } sort.Slice(vm.Storage, func(i, j int) bool { return vm.Storage[i].Dev < vm.Storage[j].Dev }) - if vm.Storage[0].Dev != "sda" || vm.Storage[1].Dev != "sdb" { - t.Errorf("devs attendus [sda sdb], obtenus [%s %s]", vm.Storage[0].Dev, vm.Storage[1].Dev) + if vm.Storage[0].Dev != "xvda" || vm.Storage[1].Dev != "xvdb" { + t.Errorf("devs attendus [xvda xvdb], obtenus [%s %s]", vm.Storage[0].Dev, vm.Storage[1].Dev) } } func TestVmFromDB_SlotGap(t *testing.T) { - // sdb absent — sda et sdc seulement + // xvdb absent — xvda et xvdc seulement entries := map[string]string{ "vm/vm-3/state": "running", "vm/vm-3/subnet": "sn-1", @@ -71,8 +71,8 @@ func TestVmFromDB_SlotGap(t *testing.T) { "vm/vm-3/metadata_port": "1236", "vm/vm-3/memory": "512", "vm/vm-3/cpus": "1", - "vm/vm-3/disk/sda": "/data/root.qcow2", - "vm/vm-3/disk/sdc": "/data/extra.qcow2", + "vm/vm-3/disk/xvda": "/data/root.qcow2", + "vm/vm-3/disk/xvdc": "/data/extra.qcow2", } vm, err := vmFromDB("vm-3", entries) if err != nil { @@ -85,11 +85,11 @@ func TestVmFromDB_SlotGap(t *testing.T) { for _, s := range vm.Storage { devs[s.Dev] = true } - if !devs["sda"] || !devs["sdc"] { - t.Errorf("attendu sda et sdc, obtenus %v", devs) + if !devs["xvda"] || !devs["xvdc"] { + t.Errorf("attendu xvda et xvdc, obtenus %v", devs) } - if devs["sdb"] { - t.Error("sdb ne devrait pas apparaître") + if devs["xvdb"] { + t.Error("xvdb ne devrait pas apparaître") } } @@ -107,8 +107,8 @@ func TestStartVM_MultiDisk(t *testing.T) { {Subnet: "sn-1", IP: "10.0.0.10", MAC: "52:54:00:00:00:05", Primary: true}, }, Storage: []VMStorage{ - {Path: "/data/root.qcow2", Dev: "sda"}, - {Path: "/data/data.qcow2", Dev: "sdb"}, + {Path: "/data/root.qcow2", Dev: "vda"}, + {Path: "/data/data.qcow2", Dev: "xvda"}, }, Memory: 1024, CPUs: 2, @@ -120,7 +120,7 @@ func TestStartVM_MultiDisk(t *testing.T) { t.Fatalf("attendu 202, obtenu %d : %s", w.Code, w.Body.String()) } - for _, dev := range []string{"sda", "sdb"} { + for _, dev := range []string{"vda", "xvda"} { if _, err := kv.GetFromDB(db, "vm/vm-10/disk/"+dev); err != nil { t.Errorf("disk/%s absent en DB après création", dev) } @@ -142,7 +142,7 @@ func TestStartVM_StorageReturnedInResponse(t *testing.T) { {Subnet: "sn-1", IP: "10.0.0.11", MAC: "52:54:00:00:00:05", Primary: true}, }, Storage: []VMStorage{ - {Path: "/data/root.qcow2", Dev: "sda"}, + {Path: "/data/root.qcow2", Dev: "xvda"}, }, }) @@ -157,11 +157,38 @@ func TestStartVM_StorageReturnedInResponse(t *testing.T) { if len(vm.Storage) != 1 { t.Fatalf("attendu 1 disque dans la réponse, obtenu %d", len(vm.Storage)) } - if vm.Storage[0].Dev != "sda" || vm.Storage[0].Path != "/data/root.qcow2" { + if vm.Storage[0].Dev != "xvda" || vm.Storage[0].Path != "/data/root.qcow2" { t.Errorf("disque inattendu dans la réponse : %+v", vm.Storage[0]) } } +func TestStartVM_RejectsInvalidDiskDev(t *testing.T) { + for _, dev := range []string{"sda", "sdb", "vdb", "xvd", "xvdA", "xvdaa", ""} { + s, db := newTestServer(t) + kv.AddInDB(db, "subnet/sn-1/state", "running") + kv.AddInDB(db, "subnet/sn-1/vpc", "vpc-1") + kv.AddInDB(db, "subnet/sn-1/cidr", "10.0.0.0/24") + + body, _ := json.Marshal(VMCreateRequest{ + Name: "vm-12", + Interfaces: []VMInterface{{Subnet: "sn-1", IP: "10.0.0.12", MAC: "52:54:00:00:00:05", Primary: true}}, + Storage: []VMStorage{{Path: "/data/root.qcow2", Dev: "vda"}, {Path: "/data/data.qcow2", Dev: dev}}, + }) + + w := httptest.NewRecorder() + s.VmsHandler(w, httptest.NewRequest(http.MethodPost, "/vms", bytes.NewReader(body))) + if w.Code != http.StatusBadRequest { + t.Errorf("dev %q : attendu 400, obtenu %d", dev, w.Code) + } + if !strings.Contains(w.Body.String(), "storage 1: dev") { + t.Errorf("dev %q : message inattendu %s", dev, w.Body.String()) + } + if _, err := kv.GetFromDB(db, "vm/vm-12/state"); err == nil { + t.Errorf("dev %q : la VM ne doit pas être enregistrée", dev) + } + } +} + // --- POST /vms : objet metadata --- func postVM(t *testing.T, name string, meta VMMetadata) (*httptest.ResponseRecorder, *badger.DB) { diff --git a/internal/api/agent/vms.go b/internal/api/agent/vms.go index d5ca436..03b617f 100644 --- a/internal/api/agent/vms.go +++ b/internal/api/agent/vms.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net/http" + "regexp" "strings" dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent" @@ -12,6 +13,8 @@ import ( "git.g3e.fr/syonad/two/pkg/db/kv" ) +var diskDev = regexp.MustCompile(`^(vda|xvd[a-z])$`) + func (s *Server) VmsHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") switch r.Method { @@ -88,6 +91,11 @@ func (s *Server) startVM(w http.ResponseWriter, r *http.Request) { disks := make([]dispatcher.VMDisk, len(req.Storage)) for i, s := range req.Storage { + if !diskDev.MatchString(s.Dev) { + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode(ErrorResponse{Error: fmt.Sprintf("storage %d: dev %q must be vda (root disk) or xvd[a-z]", i, s.Dev)}) + return + } disks[i] = dispatcher.VMDisk{Path: s.Path, Dev: s.Dev} } diff --git a/internal/migration/disk.go b/internal/migration/disk.go new file mode 100644 index 0000000..a1eb722 --- /dev/null +++ b/internal/migration/disk.go @@ -0,0 +1,40 @@ +package migration + +import ( + "fmt" + "log/slog" + "regexp" + "strings" + + "git.g3e.fr/syonad/two/pkg/db/kv" + + "github.com/dgraph-io/badger/v4" +) + +var legacyDiskKey = regexp.MustCompile(`^vm/([^/]+)/disk/sd([a-z])$`) + +func MigrateVMDisks(db *badger.DB, log *slog.Logger) error { + entries, err := kv.ListByPrefix(db, "vm/") + if err != nil { + return fmt.Errorf("list vm/: %w", err) + } + + for key, path := range entries { + m := legacyDiskKey.FindStringSubmatch(key) + if m == nil { + continue + } + target := strings.TrimSuffix(key, "sd"+m[2]) + "xvd" + m[2] + if existing, ok := entries[target]; ok && existing != path { + return fmt.Errorf("migrate %s: %s already holds %q", key, target, existing) + } + if err := kv.AddInDB(db, target, path); err != nil { + return fmt.Errorf("migrate %s: %w", key, err) + } + if err := kv.DeleteInDB(db, key); err != nil { + return fmt.Errorf("delete legacy %s: %w", key, err) + } + log.Info("vm disk migrated", "resource", "vm/"+m[1], "from", "sd"+m[2], "to", "xvd"+m[2]) + } + return nil +} diff --git a/internal/migration/disk_test.go b/internal/migration/disk_test.go new file mode 100644 index 0000000..6529964 --- /dev/null +++ b/internal/migration/disk_test.go @@ -0,0 +1,80 @@ +package migration + +import ( + "testing" + + "git.g3e.fr/syonad/two/pkg/db/kv" +) + +func TestMigrateVMDisks_RenamesSCSIDisks(t *testing.T) { + db := newNICDB(t) + kv.AddInDB(db, "vm/i-test1/disk/vda", "/v/root.qcow2") + kv.AddInDB(db, "vm/i-test1/disk/sda", "/v/a.qcow2") + kv.AddInDB(db, "vm/i-test1/disk/sdc", "/v/c.qcow2") + kv.AddInDB(db, "vm/i-test2/disk/sdb", "/v/b.qcow2") + + if err := MigrateVMDisks(db, quietLog()); err != nil { + t.Fatalf("MigrateVMDisks : %v", err) + } + + got, err := kv.ListByPrefix(db, "vm/") + if err != nil { + t.Fatalf("ListByPrefix : %v", err) + } + want := map[string]string{ + "vm/i-test1/disk/vda": "/v/root.qcow2", + "vm/i-test1/disk/xvda": "/v/a.qcow2", + "vm/i-test1/disk/xvdc": "/v/c.qcow2", + "vm/i-test2/disk/xvdb": "/v/b.qcow2", + } + if len(got) != len(want) { + t.Errorf("clés après migration : %v, attendu %v", got, want) + } + for key, value := range want { + if got[key] != value { + t.Errorf("%s = %q, attendu %q", key, got[key], value) + } + } +} + +func TestMigrateVMDisks_Idempotent(t *testing.T) { + db := newNICDB(t) + kv.AddInDB(db, "vm/i-test1/disk/sda", "/v/a.qcow2") + + for i := 0; i < 2; i++ { + if err := MigrateVMDisks(db, quietLog()); err != nil { + t.Fatalf("passe %d : %v", i, err) + } + } + if got, _ := kv.GetFromDB(db, "vm/i-test1/disk/xvda"); got != "/v/a.qcow2" { + t.Errorf("xvda = %q après deux passes", got) + } +} + +func TestMigrateVMDisks_LeavesOtherKeys(t *testing.T) { + db := newNICDB(t) + kv.AddInDB(db, "vm/i-test1/nic/0/sda", "x") + kv.AddInDB(db, "vm/i-test1/disk/sdaa", "/v/x.qcow2") + + if err := MigrateVMDisks(db, quietLog()); err != nil { + t.Fatalf("MigrateVMDisks : %v", err) + } + for _, key := range []string{"vm/i-test1/nic/0/sda", "vm/i-test1/disk/sdaa"} { + if _, err := kv.GetFromDB(db, key); err != nil { + t.Errorf("%s ne devait pas être touchée : %v", key, err) + } + } +} + +func TestMigrateVMDisks_RefusesConflict(t *testing.T) { + db := newNICDB(t) + kv.AddInDB(db, "vm/i-test1/disk/sda", "/v/a.qcow2") + kv.AddInDB(db, "vm/i-test1/disk/xvda", "/v/other.qcow2") + + if err := MigrateVMDisks(db, quietLog()); err == nil { + t.Fatal("un conflit sda/xvda doit faire échouer la migration") + } + if got, _ := kv.GetFromDB(db, "vm/i-test1/disk/sda"); got != "/v/a.qcow2" { + t.Errorf("sda ne doit pas être supprimée en cas de conflit : %q", got) + } +} diff --git a/internal/qemu/args.go b/internal/qemu/args.go index 3e12f7a..4aa7327 100644 --- a/internal/qemu/args.go +++ b/internal/qemu/args.go @@ -49,14 +49,14 @@ func buildArgs(cfg Config) ([]string, error) { hasScsi := false virtioBlk := 0 for _, d := range cfg.Disks { - if strings.HasPrefix(d.Dev, "sd") { + if strings.HasPrefix(d.Dev, "xvd") { hasScsi = true } else { virtioBlk++ } } if virtioBlk > 1 { - return nil, fmt.Errorf("qemu: %d disques virtio-blk (vd*) déclarés, un seul est supporté — utiliser des disques sd* pour les disques additionnels", virtioBlk) + return nil, fmt.Errorf("qemu: %d disques virtio-blk (vd*) déclarés, un seul est supporté — utiliser des disques xvd* pour les disques additionnels", virtioBlk) } if hasScsi { args = append(args, "-device", "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x1e") @@ -64,7 +64,7 @@ func buildArgs(cfg Config) ([]string, error) { sorted := make([]DiskConfig, len(cfg.Disks)) copy(sorted, cfg.Disks) - // vd* avant sd* : les disques virtio-blk bootent en premier. + // vd* avant xvd* : les disques virtio-blk bootent en premier. // À lettre égale de type, ordre alphabétique. sort.Slice(sorted, func(i, j int) bool { iVirtio := strings.HasPrefix(sorted[i].Dev, "vd") @@ -77,8 +77,8 @@ func buildArgs(cfg Config) ([]string, error) { for idx, d := range sorted { bootindex := idx + 1 - if strings.HasPrefix(d.Dev, "sd") { - scsiID := int(d.Dev[2] - 'a') + if strings.HasPrefix(d.Dev, "xvd") { + scsiID := int(d.Dev[3] - 'a') args = append(args, "-drive", fmt.Sprintf("file=%s,if=none,id=%s", d.Path, d.Dev), "-device", fmt.Sprintf("scsi-hd,drive=%s,bus=scsi0.0,scsi-id=%d,bootindex=%d,serial=%s", d.Dev, scsiID, bootindex, d.Dev), diff --git a/internal/qemu/args_test.go b/internal/qemu/args_test.go index fe3b072..6864994 100644 --- a/internal/qemu/args_test.go +++ b/internal/qemu/args_test.go @@ -19,9 +19,9 @@ func TestBuildArgs_DiskSerialIsDeclaredDev(t *testing.T) { Name: "vm1", NICs: []NICConfig{{TapID: 1, Mac: "52:54:00:00:00:01"}}, Disks: []DiskConfig{ - {Path: "/v/b.qcow2", Dev: "sdb"}, + {Path: "/v/b.qcow2", Dev: "xvdb"}, {Path: "/v/root.qcow2", Dev: "vda"}, - {Path: "/v/a.qcow2", Dev: "sda"}, + {Path: "/v/a.qcow2", Dev: "xvda"}, }, }) if err != nil { @@ -31,8 +31,8 @@ func TestBuildArgs_DiskSerialIsDeclaredDev(t *testing.T) { want := []string{ "virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x1e", "virtio-blk-pci,drive=vda,bus=pci.0,addr=0x1f,bootindex=1,serial=vda", - "scsi-hd,drive=sda,bus=scsi0.0,scsi-id=0,bootindex=2,serial=sda", - "scsi-hd,drive=sdb,bus=scsi0.0,scsi-id=1,bootindex=3,serial=sdb", + "scsi-hd,drive=xvda,bus=scsi0.0,scsi-id=0,bootindex=2,serial=xvda", + "scsi-hd,drive=xvdb,bus=scsi0.0,scsi-id=1,bootindex=3,serial=xvdb", "virtio-net-pci,netdev=net0,mac=52:54:00:00:00:01,bus=pci.0,addr=0x03", } got := devicesOf(args) From 8207ba84311e51b1108f7b308464de516f1176a3 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Fri, 23 Oct 2026 00:26:39 +0200 Subject: [PATCH 5/6] f-74: e2e: image du lab avec /dev/xvdX, 26 sur xvdX et ses partitions, 11 refuse sdX #74 Signed-off-by: GnomeZworc --- test/e2e/lib/vm.sh | 4 ++++ test/e2e/run_test.sh | 12 +++++------ test/e2e/suite/11-validation.sh | 5 ++++- test/e2e/suite/26-multi-disque.sh | 33 +++++++++++++++++-------------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/test/e2e/lib/vm.sh b/test/e2e/lib/vm.sh index b72a7e1..4c02d60 100644 --- a/test/e2e/lib/vm.sh +++ b/test/e2e/lib/vm.sh @@ -15,6 +15,10 @@ two_image () { > /mnt/two-image/etc/cloud/cloud.cfg.d/99_metadata.cfg printf '%s\n' '[Match]' 'Name=en*' '' '[Network]' 'DHCP=ipv4' \ > /mnt/two-image/etc/systemd/network/90-all-en.network + printf '%s\n' \ + 'SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL_SHORT}=="xvd[a-z]", SYMLINK+="$env{ID_SERIAL_SHORT}"' \ + 'SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL_SHORT}=="xvd[a-z]", SYMLINK+="$env{ID_SERIAL_SHORT}%n"' \ + > /mnt/two-image/etc/udev/rules.d/90-two-xvd.rules umount /mnt/two-image qemu-nbd -d /dev/nbd0 >/dev/null mv "${work}/${IMAGE_FILE}" "${TWO_IMAGE}" diff --git a/test/e2e/run_test.sh b/test/e2e/run_test.sh index 186424a..9cd27a8 100755 --- a/test/e2e/run_test.sh +++ b/test/e2e/run_test.sh @@ -361,16 +361,16 @@ test_vm_body_builds_the_create_request () { setup "vm_body : requête de création, disque par défaut, métadonnées et dev" [[ $(node 'vm_body t11-a sn-t11a 10.11.1.10') == '{"name":"t11-a","memory":1024,"cpus":1,"metadata":{},"interfaces":[{"subnet":"sn-t11a","ip":"10.11.1.10","mac":"52:54:00:0b:01:0a","primary":true}],"storage":[{"path":"/var/lib/two/volumes/t11-a.qcow2","dev":"vda"}]}' ]] \ || fail "défaut : $(node 'vm_body t11-a sn-t11a 10.11.1.10')" - [[ $(node 'vm_body t11-b sn-t11a 10.11.1.11 /x.qcow2 "{\"user_data\":\"YQ==\"}" sdb | jq -c "[.metadata.user_data, .storage[0].path, .storage[0].dev]"') == '["YQ==","/x.qcow2","sdb"]' ]] \ - || fail "options : $(node 'vm_body t11-b sn-t11a 10.11.1.11 /x.qcow2 "{\"user_data\":\"YQ==\"}" sdb')" + [[ $(node 'vm_body t11-b sn-t11a 10.11.1.11 /x.qcow2 "{\"user_data\":\"YQ==\"}" xvdb | jq -c "[.metadata.user_data, .storage[0].path, .storage[0].dev]"') == '["YQ==","/x.qcow2","xvdb"]' ]] \ + || fail "options : $(node 'vm_body t11-b sn-t11a 10.11.1.11 /x.qcow2 "{\"user_data\":\"YQ==\"}" xvdb')" teardown } test_vm_json_builds_nics_disks_metadata_and_uefi () { setup "vm_json : NIC (la première primaire), disques, métadonnées, uefi" local out - out=$(node 'vm_json t25-m --disk vda=/v/a.qcow2 --nic sn-a=10.0.1.10 --nic sn-b=10.0.2.10 --disk sda=/v/b.qcow2 --sshkey "ssh-ed25519 AAAA x" --password "\$6\$s\$h" --user-data "I2Nsb3Vk" --uefi') - [[ "${out}" == '{"name":"t25-m","memory":1024,"cpus":1,"metadata":{"sshkey":"ssh-ed25519 AAAA x","password":"$6$s$h","user_data":"I2Nsb3Vk"},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","mac":"52:54:00:00:01:0a","primary":true},{"subnet":"sn-b","ip":"10.0.2.10","mac":"52:54:00:00:02:0a","primary":false}],"storage":[{"path":"/v/a.qcow2","dev":"vda"},{"path":"/v/b.qcow2","dev":"sda"}],"uefi":true}' ]] \ + out=$(node 'vm_json t25-m --disk vda=/v/a.qcow2 --nic sn-a=10.0.1.10 --nic sn-b=10.0.2.10 --disk xvda=/v/b.qcow2 --sshkey "ssh-ed25519 AAAA x" --password "\$6\$s\$h" --user-data "I2Nsb3Vk" --uefi') + [[ "${out}" == '{"name":"t25-m","memory":1024,"cpus":1,"metadata":{"sshkey":"ssh-ed25519 AAAA x","password":"$6$s$h","user_data":"I2Nsb3Vk"},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","mac":"52:54:00:00:01:0a","primary":true},{"subnet":"sn-b","ip":"10.0.2.10","mac":"52:54:00:00:02:0a","primary":false}],"storage":[{"path":"/v/a.qcow2","dev":"vda"},{"path":"/v/b.qcow2","dev":"xvda"}],"uefi":true}' ]] \ || fail "complet : ${out}" out=$(node 'vm_json t21-a --nic sn-a=10.0.1.10') [[ "${out}" == '{"name":"t21-a","memory":1024,"cpus":1,"metadata":{},"interfaces":[{"subnet":"sn-a","ip":"10.0.1.10","mac":"52:54:00:00:01:0a","primary":true}],"storage":[],"uefi":false}' ]] || fail "minimal : ${out}" @@ -384,8 +384,8 @@ test_vm_json_builds_nics_disks_metadata_and_uefi () { test_vm_launch_copies_the_system_disk_first_and_waits () { setup "vm_launch : disque système vda copié en premier, POST, attente de running" local out - out=$(node 'VOLUMES=/v; TWO_IMAGE=/img; api_state () { echo; }; mkdir () { :; }; cp () { echo "CP $*"; }; api_post () { echo "POST $1 $(jq -c "[.storage[].dev, .interfaces[0].ip]" <<<"$2")"; }; wait_state () { echo "WAIT $*"; }; vm_launch t26-d --nic sn=10.0.0.10 --disk sda=/v/s.qcow2') - [[ "${out}" == $'CP /img /v/t26-d.qcow2\nPOST vms ["vda","sda","10.0.0.10"]\nWAIT vms/t26-d running' ]] || fail "${out}" + out=$(node 'VOLUMES=/v; TWO_IMAGE=/img; api_state () { echo; }; mkdir () { :; }; cp () { echo "CP $*"; }; api_post () { echo "POST $1 $(jq -c "[.storage[].dev, .interfaces[0].ip]" <<<"$2")"; }; wait_state () { echo "WAIT $*"; }; vm_launch t26-d --nic sn=10.0.0.10 --disk xvda=/v/s.qcow2') + [[ "${out}" == $'CP /img /v/t26-d.qcow2\nPOST vms ["vda","xvda","10.0.0.10"]\nWAIT vms/t26-d running' ]] || fail "${out}" [[ $(node 'api_state () { echo running; }; cp () { echo CP; }; api_post () { echo POST; }; vm_launch t --nic s=1.2.3.4 && echo OK') == OK ]] || fail "VM en running relancée" [[ $(node 'api_state () { echo; }; cp () { echo CP; }; vm_launch t --bad x || echo NON') == *NON ]] || fail "option invalide : disque copié ou POST envoyé" teardown diff --git a/test/e2e/suite/11-validation.sh b/test/e2e/suite/11-validation.sh index 3b63c60..b8f89ad 100644 --- a/test/e2e/suite/11-validation.sh +++ b/test/e2e/suite/11-validation.sh @@ -1,6 +1,6 @@ # fonctionnalité: validation de l'API — refus synchrones (400, 409, 422) des VPC, subnets et VM, sans trace en base # hôtes: hv1 -# tickets: #41, #57, #33, #62 +# tickets: #41, #57, #33, #62, #74 on hv1 <<'NODE' check "VPC vp-t11a, l3vni 1100 (témoin)" vpc_create vp-t11a 10.11.0.0/16 1100 @@ -40,6 +40,9 @@ done check "VM : subnet inconnu, 422" expect_code 422 api_post_code vms "$(vm_body t11-x sn-t11z 10.11.1.12 "${NONE}")" check "VM : aucune interface primaire, 400" expect_code 400 api_post_code vms "$(vm_body t11-x sn-t11a 10.11.1.12 "${NONE}" | sed 's/"primary":true/"primary":false/')" check "VM : interface sans mac, 400" expect_code 400 api_post_code vms "$(vm_body t11-x sn-t11a 10.11.1.12 "${NONE}" | jq -c 'del(.interfaces[0].mac)')" +for dev in sdb vdb xvdaa; do + check "VM : disque additionnel ${dev}, 400" expect_code 400 api_post_code vms "$(vm_body t11-x sn-t11a 10.11.1.12 "${NONE}" | jq -c --arg d "${dev}" '.storage += [{"path":"/x.qcow2","dev":$d}]')" +done check "VM : user_data en base64 invalide, 400" expect_code 400 api_post_code vms "$(vm_body t11-x sn-t11a 10.11.1.12 "${NONE}" '{"user_data":"pas du base64 !"}')" check "VMs refusées : aucune trace de t11-x" expect_code 404 api_code GET vms/t11-x cp "${TWO_IMAGE}" "${VOLUMES}/t11-ud.qcow2" diff --git a/test/e2e/suite/26-multi-disque.sh b/test/e2e/suite/26-multi-disque.sh index c756764..66902ac 100644 --- a/test/e2e/suite/26-multi-disque.sh +++ b/test/e2e/suite/26-multi-disque.sh @@ -1,29 +1,32 @@ -# fonctionnalité: VM à plusieurs disques — virtio (vdX) et SCSI (sdX), tailles et bus vus par la VM, liens by-id par numéro de série, démarrage sur vda +# fonctionnalité: VM à plusieurs disques — racine virtio (vda) et SCSI (xvdX), tailles et bus vus par la VM, liens /dev/xvdX et by-id par numéro de série, démarrage sur vda # hôtes: hv1 # tickets: #32, #74 on hv1 <<'NODE' KEY=$(vm_key) mkdir -p "${VOLUMES}" -check "volume t26-d-sdb 1 Gio" qemu-img create -q -f qcow2 "${VOLUMES}/t26-d-sdb.qcow2" 1G -check "volume t26-d-sda 2 Gio" qemu-img create -q -f qcow2 "${VOLUMES}/t26-d-sda.qcow2" 2G +check "volume t26-d-xvdb 1 Gio" qemu-img create -q -f qcow2 "${VOLUMES}/t26-d-xvdb.qcow2" 1G +check "volume t26-d-xvda 2 Gio" qemu-img create -q -f qcow2 "${VOLUMES}/t26-d-xvda.qcow2" 2G check "VPC vp-t26" vpc_create vp-t26 10.26.0.0/16 check "subnet sn-t26" subnet_create sn-t26 vp-t26 2601 10.26.1.0/24 -check "VM t26-d : vda (système), sdb, sda" vm_launch t26-d --nic sn-t26=10.26.1.10 --sshkey "${KEY}" \ - --disk "sdb=${VOLUMES}/t26-d-sdb.qcow2" --disk "sda=${VOLUMES}/t26-d-sda.qcow2" -check "API : trois disques" test "$(curl -fsS "${API}/vms/t26-d" | jq -r '[.storage[].dev] | sort | join(" ")')" = "sda sdb vda" +check "VM t26-d : vda (racine), xvdb, xvda" vm_launch t26-d --nic sn-t26=10.26.1.10 --sshkey "${KEY}" \ + --disk "xvdb=${VOLUMES}/t26-d-xvdb.qcow2" --disk "xvda=${VOLUMES}/t26-d-xvda.qcow2" +check "API : trois disques" test "$(curl -fsS "${API}/vms/t26-d" | jq -r '[.storage[].dev] | sort | join(" ")')" = "vda xvda xvdb" check "t26-d joignable (démarrée sur vda)" vm_wait vp-t26 10.26.1.10 check "t26-d : racine sur vda" vm_grep vp-t26 10.26.1.10 'findmnt -n -o SOURCE /' '^/dev/vda' target_size () { local v; v=$(vm_ssh vp-t26 10.26.1.10 "lsblk -b -dn -o HCTL,SIZE" 2>&1 | awk -v t="${1}" '{split($1, h, ":")} h[3] == t {print $2}'); [ "${v}" = "${2}" ] || { echo "lu : ${v:-aucun disque sur la cible ${1}}"; return 1; }; } -check "t26-d : sda déclaré → cible SCSI 0, 2 Gio" target_size 0 2147483648 -check "t26-d : sdb déclaré → cible SCSI 1, 1 Gio" target_size 1 1073741824 +check "t26-d : xvda déclaré → cible SCSI 0, 2 Gio" target_size 0 2147483648 +check "t26-d : xvdb déclaré → cible SCSI 1, 1 Gio" target_size 1 1073741824 info "t26-d : /dev/disk/by-id : $(vm_ssh vp-t26 10.26.1.10 'ls /dev/disk/by-id' 2>&1 | tr '\n' ' ')" -by_id_size () { local v; v=$(vm_ssh vp-t26 10.26.1.10 "lsblk -b -dn -o SIZE \$(readlink -e /dev/disk/by-id/${1})" 2>&1 | tr -d ' '); [ "${v}" = "${2}" ] || { echo "lu : ${v}"; return 1; }; } -check "t26-d : sdb déclaré → by-id scsi-0QEMU_QEMU_HARDDISK_sdb, 1 Gio" by_id_size scsi-0QEMU_QEMU_HARDDISK_sdb 1073741824 -check "t26-d : sda déclaré → by-id scsi-0QEMU_QEMU_HARDDISK_sda, 2 Gio" by_id_size scsi-0QEMU_QEMU_HARDDISK_sda 2147483648 -check "t26-d : vda déclaré → by-id virtio-vda, disque système" test "$(vm_ssh vp-t26 10.26.1.10 'readlink -e /dev/disk/by-id/virtio-vda')" = /dev/vda -check "t26-d : sdb en SCSI" vm_grep vp-t26 10.26.1.10 'readlink -f /sys/block/sdb/device/driver' 'sd$' -check "t26-d : sda en SCSI (virtio-scsi)" vm_ssh vp-t26 10.26.1.10 'test -d /sys/block/sda/device/scsi_device && readlink -f /sys/block/sda | grep -q virtio' +info "t26-d : noms du noyau : $(vm_ssh vp-t26 10.26.1.10 'lsblk -dn -o NAME,HCTL,SIZE' 2>&1 | tr '\n' ' ')" +link_size () { local v; v=$(vm_ssh vp-t26 10.26.1.10 "lsblk -b -dn -o SIZE \$(readlink -e ${1})" 2>&1 | tr -d ' '); [ "${v}" = "${2}" ] || { echo "lu : ${v}"; return 1; }; } +check "t26-d : /dev/xvda → 2 Gio (règle udev de l'image)" link_size /dev/xvda 2147483648 +check "t26-d : /dev/xvdb → 1 Gio (règle udev de l'image)" link_size /dev/xvdb 1073741824 +check "t26-d : by-id scsi-0QEMU_QEMU_HARDDISK_xvda → 2 Gio" link_size /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_xvda 2147483648 +check "t26-d : by-id scsi-0QEMU_QEMU_HARDDISK_xvdb → 1 Gio" link_size /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_xvdb 1073741824 +check "t26-d : by-id virtio-vda → /dev/vda" test "$(vm_ssh vp-t26 10.26.1.10 'readlink -e /dev/disk/by-id/virtio-vda')" = /dev/vda +check "t26-d : xvda et xvdb en SCSI (virtio-scsi)" vm_ssh vp-t26 10.26.1.10 'for d in xvda xvdb; do k=$(basename $(readlink -e /dev/$d)); test -d /sys/block/$k/device/scsi_device && readlink -f /sys/block/$k | grep -q virtio || exit 1; done' check "t26-d : vda n'est pas en SCSI (témoin)" vm_fails vp-t26 10.26.1.10 'test -d /sys/block/vda/device/scsi_device' -check "t26-d : écriture sur sdb et sda" vm_ssh vp-t26 10.26.1.10 'sudo dd if=/dev/zero of=/dev/sdb bs=1M count=8 oflag=direct status=none && sudo dd if=/dev/zero of=/dev/sda bs=1M count=8 oflag=direct status=none' +check "t26-d : partition sur xvdb → lien /dev/xvdb1" vm_ssh vp-t26 10.26.1.10 'echo ",,L" | sudo sfdisk -q /dev/xvdb >/dev/null && sudo udevadm settle && test -b "$(readlink -e /dev/xvdb1)"' +check "t26-d : écriture sur xvda et xvdb1" vm_ssh vp-t26 10.26.1.10 'sudo dd if=/dev/zero of=/dev/xvda bs=1M count=8 oflag=direct status=none && sudo dd if=/dev/zero of=/dev/xvdb1 bs=1M count=8 oflag=direct status=none' NODE From 8eb77b302b190de3ad541cb0df4197b4d964a6d7 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Fri, 23 Oct 2026 00:26:47 +0200 Subject: [PATCH 6/6] =?UTF-8?q?f-74:=20doc:=20vda=20racine,=20xvdX=20addit?= =?UTF-8?q?ionnels=20et=20/dev/xvdX=20par=20r=C3=A8gle=20udev=20d'image,?= =?UTF-8?q?=20migration,=20notes=20de=20version=20#74?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- api/agent.yaml | 14 ++++++++------ docs/architecture/contraintes.rst | 3 ++- docs/architecture/stockage.rst | 8 +++++++- docs/concepts/vpc-subnet-vm.rst | 11 ++++++----- docs/demarrage/premier-vpc.rst | 15 ++++++++------- docs/deploiement/image-qcow2.rst | 15 +++++++++++++++ docs/developpement/lab.rst | 4 ++-- release_notes/0.2.0.md | 17 ++++++++++++++++- 8 files changed, 64 insertions(+), 23 deletions(-) diff --git a/api/agent.yaml b/api/agent.yaml index 26b223e..03aad15 100644 --- a/api/agent.yaml +++ b/api/agent.yaml @@ -567,12 +567,14 @@ components: dev: type: string description: >- - Disk slot: vda is the virtio-blk system disk (one at most), sdX - is SCSI target X (a → 0). Not a guaranteed name inside the VM: - the guest kernel names SCSI disks in detection order. The disk - serial is set to dev, so the guest finds it under - /dev/disk/by-id/ (virtio-, scsi-0QEMU_QEMU_HARDDISK_). - pattern: '^[sv]d[a-z]$' + vda is the virtio-blk root disk, seen as /dev/vda and booted + first. xvdX is an additional disk on SCSI target X (xvda → 0), + seen by the guest kernel as some /dev/sdY in detection order. The + disk serial is set to dev: an image that follows the two image + requirements links it to /dev/xvdX, and udev always exposes it as + /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_xvdX (virtio-vda for the + root disk). Anything else → 400; sdX is no longer accepted. + pattern: '^(vda|xvd[a-z])$' example: vda VM: diff --git a/docs/architecture/contraintes.rst b/docs/architecture/contraintes.rst index c83fec6..42e8de2 100644 --- a/docs/architecture/contraintes.rst +++ b/docs/architecture/contraintes.rst @@ -39,7 +39,8 @@ Réseau QEMU et VM ---------- -* **Un seul disque ``vdX`` par VM** ; les disques additionnels passent par le SCSI (``sdX``). La +* **Un seul disque virtio, ``vda``, le disque racine** ; les disques additionnels passent par le SCSI + (``xvdX``, cible X). La carte PCI en dépend : NIC en ``0x03``, contrôleur SCSI en ``0x1e``, virtio-blk en ``0x1f``. * ``bus=pci.0`` est explicite sur les trois ``-device`` : un passage de la machine en **q35** casserait le démarrage (``Bus 'pci.0' not found``). diff --git a/docs/architecture/stockage.rst b/docs/architecture/stockage.rst index c8c9af4..431b92b 100644 --- a/docs/architecture/stockage.rst +++ b/docs/architecture/stockage.rst @@ -28,7 +28,7 @@ de sérialisation structurée. vm//nic//primary → "true" (exactement une interface ; absent sur les autres) vm//nic//tap_id → (alloué au premier démarrage, puis conservé) vm//metadata_port → - vm//disk/ → (une clé par disque : sda, vda, …) + vm//disk/ → (une clé par disque : vda, xvda, xvdb, …) vm//memory → (Mo) vm//cpus → vm//uefi → "true" (absent si SeaBIOS) @@ -55,6 +55,12 @@ clés. Les VM ``deleted`` sont ignorées. Une interface dont la MAC est introuva démarrage en la nommant, et la table reste en place tant que toutes les interfaces ne sont pas migrées. +**Anciens noms de disques.** Jusqu'en 0.1.0, les disques additionnels s'appelaient ``sdX``. Au +démarrage, l'agent renomme chaque clé ``vm//disk/sdX`` en ``vm//disk/xvdX`` (même +lettre, même cible SCSI). Si ``xvdX`` existe déjà avec un autre chemin, le démarrage échoue en +nommant la clé. Le numéro de série du disque, et donc son lien ``by-id``, prend le nouveau nom au +prochain lancement de la VM. + **Les états passent par ``state``.** Toujours ``state.Set`` / ``state.Get`` : ``Set`` refuse une valeur hors énumération, ``Get`` refuse de retourner une valeur non reconnue. ``error`` n'est écrit que par ``Dispatcher.Dispatch``, via ``cmd.Key()``. diff --git a/docs/concepts/vpc-subnet-vm.rst b/docs/concepts/vpc-subnet-vm.rst index 212225e..ca9ebcc 100644 --- a/docs/concepts/vpc-subnet-vm.rst +++ b/docs/concepts/vpc-subnet-vm.rst @@ -94,11 +94,12 @@ suppression, ces ``/32`` sont retirés **avant** l'arrêt de QEMU. Comme un subn supprimé tant qu'une VM l'utilise, le ``/32`` d'une VM est toujours retiré avant le ``/24`` de son subnet — l'ordre qui évite le trou noir de `#41 `_. -**Stockage.** Un seul disque ``vdX`` (virtio-blk) par VM ; les disques supplémentaires passent -par le contrôleur SCSI (``sdX``). Cette contrainte vient de la carte PCI figée — voir -:doc:`/architecture/contraintes`. ``dev`` fixe l'emplacement du disque (cible SCSI, slot PCI) -et son numéro de série, pas son nom dans le guest : le disque se retrouve par -``/dev/disk/by-id/…``. +**Stockage.** Un seul disque virtio par VM, ``vda``, le disque racine ; les disques +supplémentaires passent par le contrôleur SCSI (``xvdX``, cible X). Cette contrainte vient de la +carte PCI figée — voir :doc:`/architecture/contraintes`. ``dev`` fixe l'emplacement du disque +(cible SCSI, slot PCI) et son numéro de série, pas le nom que lui donne le noyau du guest +(``/dev/sdY``, dans l'ordre de détection) : le disque se retrouve par ``/dev/xvdX`` dans une +image conforme, et toujours par ``/dev/disk/by-id/…``. Ce qui est stocké, et où ------------------------ diff --git a/docs/demarrage/premier-vpc.rst b/docs/demarrage/premier-vpc.rst index 3d3b2de..567b5bc 100644 --- a/docs/demarrage/premier-vpc.rst +++ b/docs/demarrage/premier-vpc.rst @@ -115,15 +115,16 @@ Exactement une interface est ``primary`` slot PCI (``0x03 + index``), donc le nom de l'interface dans le guest. Tous les subnets d'une VM doivent appartenir au même VPC. -Un seul disque ``vdX`` - Les disques supplémentaires passent par ``sdX``. La carte PCI en dépend — voir +``vda`` pour la racine, ``xvdX`` pour les autres disques + ``vda`` est le disque racine, virtio, démarré en premier. Les disques supplémentaires sont des + ``xvdX`` (``xvda`` = cible SCSI 0) ; ``sdX`` est refusé (400). La carte PCI en dépend — voir :doc:`/architecture/contraintes`. -``dev`` désigne un emplacement, pas un nom dans le guest - ``sdb`` est la cible SCSI 1, mais le noyau du guest nomme les disques SCSI dans l'ordre de - détection : ``/dev/sdb`` peut être un autre disque. L'agent donne à chaque disque le numéro - de série ```` ; le nom stable est sous ``/dev/disk/by-id/`` : - ``scsi-0QEMU_QEMU_HARDDISK_sdb``, ``virtio-vda``. +``/dev/xvdX`` dans le guest, jamais ``/dev/sdX`` + Le noyau du guest nomme les disques SCSI ``sdX`` dans l'ordre de détection, qui change d'un + démarrage à l'autre. L'agent donne à chaque disque le numéro de série ```` ; une image + conforme (:doc:`/deploiement/image-qcow2`) en fait le lien ``/dev/xvdX``. Sans cette règle, + le nom stable reste ``/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_xvdX``. 4. Vérifier ----------- diff --git a/docs/deploiement/image-qcow2.rst b/docs/deploiement/image-qcow2.rst index a8e0488..5922a47 100644 --- a/docs/deploiement/image-qcow2.rst +++ b/docs/deploiement/image-qcow2.rst @@ -284,6 +284,21 @@ interface (``10-netplan-*``). Sur une image démarrée avec ``net.ifnames=0``, v l'image Rocky de cette page, n'est pas encore vérifié. Sans lui, une VM à plusieurs interfaces n'a de bail que sur la première. +**Noms stables des disques additionnels** + +.. code-block:: bash + + cat << 'ENDFILE' > /mnt/etc/udev/rules.d/90-two-xvd.rules + SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL_SHORT}=="xvd[a-z]", SYMLINK+="$env{ID_SERIAL_SHORT}" + SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL_SHORT}=="xvd[a-z]", SYMLINK+="$env{ID_SERIAL_SHORT}%n" + ENDFILE + +L'agent donne à chaque disque additionnel le numéro de série ``xvdX`` déclaré dans l'API ; ces +règles en font ``/dev/xvdX`` (et ``/dev/xvdXN`` pour ses partitions). Le noyau, lui, nomme les +disques SCSI ``/dev/sdY`` dans l'ordre de détection, qui change d'un démarrage à l'autre : une +``fstab`` ou un script de la VM doit viser ``/dev/xvdX``, jamais ``/dev/sdY``. Le disque racine +reste ``/dev/vda``. + **Services et durcissement** .. code-block:: bash diff --git a/docs/developpement/lab.rst b/docs/developpement/lab.rst index a3972bb..659ea24 100644 --- a/docs/developpement/lab.rst +++ b/docs/developpement/lab.rst @@ -320,7 +320,7 @@ Générée par ``test/e2e/run.sh --matrice`` à partir des en-têtes ; à régé - hv1 - #33, #62, #73 * - ``26-multi-disque`` - - VM à plusieurs disques — virtio (vdX) et SCSI (sdX), tailles et bus vus par la VM, liens ``by-id`` par numéro de série, démarrage sur vda + - VM à plusieurs disques — racine virtio (vda) et SCSI (xvdX), tailles et bus vus par la VM, liens ``/dev/xvdX`` et ``by-id`` par numéro de série, démarrage sur vda - hv1 - #32, #74 * - ``27-reboot`` @@ -412,7 +412,7 @@ Hypothèses vérifiées en lab, à garder en tête en écrivant un test : * systemd-networkd **ne réécrit pas** un bail renouvelé à l'identique : un renouvellement se vérifie par le DHCPACK dans le journal du serveur (``lease_renewed``), pas par le fichier de bail ; -* l'agent n'accepte **qu'un seul disque virtio** (le disque système) ; les autres sont des ``sdX`` ; +* l'agent n'accepte **qu'un seul disque virtio** (le disque racine, ``vda``) ; les autres sont des ``xvdX`` ; * sur Debian 12, ``ebtables -L`` (nft) garde les zéros de tête des MAC ; * ``interface_ip`` est posée en ``/32`` sur le bridge du netns en mode ``bridge`` ; * depuis le netns d'un hôte, une VM d'un autre hôte ne répond pas : la réponse repart vers la diff --git a/release_notes/0.2.0.md b/release_notes/0.2.0.md index 001f589..77c0798 100644 --- a/release_notes/0.2.0.md +++ b/release_notes/0.2.0.md @@ -87,6 +87,18 @@ L3VNI, avec une configuration BGP pilotée par l'agent ; documentation du projet leurs subnets (VM injoignable), et n'était pas tenable en IPv6 - Migration au démarrage : les VM existantes gardent leur MAC, recopiée sur chaque interface +**Disques : `vda` pour la racine, `xvdX` pour les autres (#74)** + +- `dev` accepte désormais `vda`, le disque racine virtio, et `xvda` à `xvdz` pour les disques + additionnels, sur la cible SCSI de même rang (`xvda` → 0). Toute autre valeur est refusée (400), + `sdX` compris +- Chaque disque reçoit le numéro de série ``. Le noyau de l'invité nomme les disques SCSI + `/dev/sdY` dans l'ordre de détection, qui change d'un démarrage à l'autre (mesuré en lab : `sda` + et `sdb` inversés 4 démarrages sur 6). Le nom stable est `/dev/xvdX`, créé par une règle udev + de l'image (exigence décrite dans la documentation de construction d'image), et toujours + `/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_xvdX` +- Migration au démarrage : les clés `vm//disk/sdX` deviennent `vm//disk/xvdX` + **Exploitation** - Le watchdog contrôle aussi, avec une section `bgp` : les sessions vers les route reflectors ; @@ -164,7 +176,7 @@ bash ./deploy.sh -t 0.2.0 ``` Sans `dhcp.backend` ni `bgp` dans `/etc/two/agent.yml`, le comportement est celui de la 0.1.0, à -trois exceptions près, qui touchent les appelants de l'API : +quatre exceptions près, qui touchent les appelants de l'API : - **`interface_ip` ne se fournit plus pour un subnet `vxlan`** : il est refusé (400), l'agent le calcule. Le retirer des appels de création, et ne plus placer de VM sur les deux dernières @@ -172,6 +184,9 @@ trois exceptions près, qui touchent les appelants de l'API : - **un subnet encore utilisé par une VM ne se supprime plus** : supprimer les VM d'abord - **chaque interface d'une VM doit porter sa `mac`** (400 sinon) : l'appelant la choisit et en garantit l'unicité. Les VM existantes gardent la leur, recopiée au premier démarrage de l'agent +- **les disques additionnels s'appellent `xvdX`** : `sdX` est refusé (400). Les VM existantes sont + migrées ; leurs disques prennent le numéro de série `xvdX` au prochain lancement, et une image + qui les montait par `/dev/sdY` doit passer à `/dev/xvdX` Les subnets `vxlan` existants gardent leur adressage et le modèle précédent (gateway sur le bridge) jusqu'à leur recréation.