Compare commits

..

3 commits

Author SHA1 Message Date
a3b85f5926
Merge branch 'feature-32'
All checks were successful
Pre Release Workflow / set-release-target (push) Successful in 1s
Pre Release Workflow / build (metadata, amd64, linux) (push) Successful in 1m40s
Pre Release Workflow / build (agent, amd64, linux) (push) Successful in 2m1s
Pre Release Workflow / upload-scripts (run-dnsmasq-in-netns.sh) (push) Successful in 6s
Pre Release Workflow / prerelease (push) Successful in 10s
2026-06-14 23:05:16 +02:00
4ab880a32d
f-32: vm: fix incomplete stop vm
All checks were successful
Pre Release Workflow / set-release-target (push) Successful in 1s
Pre Release Workflow / build (agent, amd64, linux) (push) Successful in 1m36s
Pre Release Workflow / build (metadata, amd64, linux) (push) Successful in 2m19s
Pre Release Workflow / upload-scripts (run-dnsmasq-in-netns.sh) (push) Successful in 6s
Pre Release Workflow / prerelease (push) Successful in 11s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-05-24 19:02:31 +02:00
c3f26836cd
f-32: fix: update boot order
All checks were successful
Pre Release Workflow / set-release-target (push) Successful in 1s
Pre Release Workflow / upload-scripts (run-dnsmasq-in-netns.sh) (push) Successful in 6s
Pre Release Workflow / build (agent, amd64, linux) (push) Successful in 1m34s
Pre Release Workflow / build (metadata, amd64, linux) (push) Successful in 1m31s
Pre Release Workflow / prerelease (push) Successful in 10s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-05-24 16:47:49 +02:00
2 changed files with 40 additions and 21 deletions

View file

@ -65,18 +65,29 @@ func Start(cfg Config) error {
sorted := make([]DiskConfig, len(cfg.Disks))
copy(sorted, cfg.Disks)
sort.Slice(sorted, func(i, j int) bool { return sorted[i].Dev < sorted[j].Dev })
// 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 _, d := range sorted {
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", d.Dev, scsiID),
"-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=virtio,id=%s", d.Path, d.Dev),
"-drive", fmt.Sprintf("file=%s,if=none,id=%s", d.Path, d.Dev),
"-device", fmt.Sprintf("virtio-blk-pci,drive=%s,bootindex=%d", d.Dev, bootindex),
)
}
}

View file

@ -33,25 +33,18 @@ func StopVM(db *badger.DB, name string, cfg *configuration.Config) error {
socketPath := filepath.Join(cfg.QEMU.QMPDir, name+".sock")
if _, err := qmp.Send(socketPath, []string{`{"execute":"system_powerdown"}`}); err != nil {
return fmt.Errorf("qmp system_powerdown: %w", err)
if _, err := os.Stat(socketPath); err == nil {
// socket présent : tenter l'arrêt gracieux
if _, err := qmp.Send(socketPath, []string{`{"execute":"system_powerdown"}`}); err == nil {
waitQMPDead(socketPath,
time.Duration(cfg.Dispatcher.TimeoutSeconds)*time.Second,
time.Duration(cfg.Dispatcher.PollSeconds)*time.Second,
)
}
// connexion QMP échouée : QEMU déjà mort
}
// socket absent ou QEMU déjà arrêté : cleanup direct
// attendre l'arrêt effectif de la VM ; forcer via quit après timeout
timeout := time.After(time.Duration(cfg.Dispatcher.TimeoutSeconds) * time.Second)
poll := time.Duration(cfg.Dispatcher.PollSeconds) * time.Second
stopped := false
for !stopped {
select {
case <-timeout:
qmp.Send(socketPath, []string{`{"execute":"quit"}`})
stopped = true
case <-time.After(poll):
if _, err := qmp.Send(socketPath, nil); err != nil {
stopped = true
}
}
}
if err := netns.Call(d.vpcName, func() error {
return iptables.DeleteMetadataRedirect(d.ip, d.interfaceIP, d.metadataPort)
@ -74,3 +67,18 @@ func StopVM(db *badger.DB, name string, cfg *configuration.Config) error {
return kv.AddInDB(db, "vm/"+name+"/state", "stopped")
}
func waitQMPDead(socketPath string, timeout, poll time.Duration) {
timer := time.After(timeout)
for {
select {
case <-timer:
qmp.Send(socketPath, []string{`{"execute":"quit"}`})
return
case <-time.After(poll):
if _, err := qmp.Send(socketPath, nil); err != nil {
return
}
}
}
}