1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

incus-agent: Handle path mount removal

Signed-off-by: Benjamin Somers <benjamin.somers@imt-atlantique.fr>
This commit is contained in:
Benjamin Somers
2025-07-31 09:04:21 +00:00
parent 6392eea29b
commit 457e09d906
3 changed files with 26 additions and 17 deletions

View File

@@ -131,11 +131,6 @@ func eventsProcess(event api.Event) {
return
}
// Only care about device additions, we don't try to handle remove.
if e.Action != "added" {
return
}
// We only handle disk hotplug.
if e.Config["type"] != "disk" {
return
@@ -146,22 +141,27 @@ func eventsProcess(event api.Event) {
return
}
// Attempt to perform the mount.
mntSource := fmt.Sprintf("incus_%s", e.Name)
for range 20 {
time.Sleep(500 * time.Millisecond)
if e.Action == "added" {
// Attempt to perform the mount.
for range 20 {
time.Sleep(500 * time.Millisecond)
err = osMountShared(mntSource, e.Config["path"], "virtiofs", nil)
if err == nil {
break
err = osMountShared(mntSource, e.Config["path"], "virtiofs", nil)
if err == nil {
break
}
}
}
if err != nil {
logger.Infof("Failed to mount hotplug %q (Type: %q) to %q", mntSource, "virtiofs", e.Config["path"])
return
}
if err != nil {
logger.Infof("Failed to mount hotplug %q (Type: %q) to %q", mntSource, "virtiofs", e.Config["path"])
return
}
logger.Infof("Mounted hotplug %q (Type: %q) to %q", mntSource, "virtiofs", e.Config["path"])
logger.Infof("Mounted hotplug %q (Type: %q) to %q", mntSource, "virtiofs", e.Config["path"])
} else if e.Action == "removed" {
// Attempt to unmount the disk.
_ = osUmount(mntSource)
}
}

View File

@@ -157,6 +157,11 @@ func osMountShared(src string, dst string, fstype string, opts []string) error {
return nil
}
func osUmount(src string) error {
_, err := subprocess.RunCommand("umount", src)
return err
}
func osGetCPUMetrics(d *Daemon) ([]metrics.CPUMetrics, error) {
stats, err := os.ReadFile("/proc/stat")
if err != nil {

View File

@@ -56,6 +56,10 @@ func osMountShared(src string, dst string, fstype string, opts []string) error {
return errors.New("Dynamic mounts aren't supported on Windows")
}
func osUmount(src string) error {
return errors.New("Dynamic mounts aren't supported on Windows")
}
func osGetCPUMetrics(d *Daemon) ([]metrics.CPUMetrics, error) {
return []metrics.CPUMetrics{}, errors.New("Metrics aren't supported on Windows")
}