Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM: Apply mount options to hotplugged disks #14898

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lxd-agent/events.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -161,8 +162,16 @@ func eventsProcess(event api.Event) {

_ = os.MkdirAll(e.Config["path"], 0755)

// Parse mount options, if provided.
var args []string
if len(e.Mount.Options) > 0 {
args = append(args, "-o", strings.Join(e.Mount.Options, ","))
}

args = append(args, "-t", "virtiofs", mntSource, e.Config["path"])

for i := 0; i < 5; i++ {
_, err = shared.RunCommand("mount", "-t", "virtiofs", mntSource, e.Config["path"])
_, err = shared.RunCommandContext(context.Background(), "mount", args...)
if err == nil {
l.Info("Mounted hotplug")
return
Expand Down
25 changes: 19 additions & 6 deletions lxd/instance/drivers/driver_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ func (d *common) setCoreSched(pids []int) error {
args = append(args, strconv.Itoa(pid))
}

_, err := shared.RunCommand(d.state.OS.ExecPath, args...)
_, err := shared.RunCommandContext(context.Background(), d.state.OS.ExecPath, args...)
return err
}

Expand Down Expand Up @@ -1575,12 +1575,25 @@ func (d *common) devicesUpdate(inst instance.Instance, removeDevices deviceConfi

if runConf != nil && len(runConf.Mounts) > 0 {
for _, opt := range runConf.Mounts[0].Opts {
if strings.HasPrefix(opt, "mountTag=") {
parts := strings.SplitN(opt, "=", 2)
event["mount"] = instancetype.VMAgentMount{
Source: parts[1],
}
key, value, _ := strings.Cut(opt, "=")
if key != "mountTag" {
continue
}

if value == "" {
return nil, errors.New(`Empty "mountTag" on device's mount options`)
}

agentMount := instancetype.VMAgentMount{
Source: value,
}

if shared.IsTrue(dev.Config()["readonly"]) {
// Tell the agent to mount with "ro" option for consistency.
agentMount.Options = []string{"ro"}
}

event["mount"] = agentMount
}
}

Expand Down
Loading