Skip to content

Commit

Permalink
fix(host): cephfs mount (#22010)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Jan 23, 2025
1 parent 6199873 commit 0dbdf59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
20 changes: 2 additions & 18 deletions pkg/hostman/container/volume_mount/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"fmt"
"path/filepath"

"yunion.io/x/log"
"yunion.io/x/pkg/errors"

"yunion.io/x/onecloud/pkg/apis"
hostapi "yunion.io/x/onecloud/pkg/apis/host"
container_storage "yunion.io/x/onecloud/pkg/hostman/container/storage"
"yunion.io/x/onecloud/pkg/util/mountutils"
"yunion.io/x/onecloud/pkg/util/procutils"
)

Expand All @@ -38,27 +38,11 @@ func (h cephFS) Mount(pod IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMou
if err != nil {
return err
}
if err := EnsureDir(dir); err != nil {
return errors.Wrap(err, "EnsureDir")
}
if err := procutils.NewRemoteCommandAsFarAsPossible("mountpoint", dir).Run(); err == nil {
log.Warningf("mountpoint %s is already mounted", dir)
return nil
}
options := fmt.Sprintf("name=%s,secret=%s", vm.CephFS.Name, vm.CephFS.Secret)
if vm.ReadOnly {
options += ",ro"
}
args := []string{
"-t", "ceph",
fmt.Sprintf("%s:%s", vm.CephFS.MonHost, vm.CephFS.Path), dir,
"-o", options,
}
out, err := procutils.NewRemoteCommandAsFarAsPossible("mount", args...).Output()
if err != nil {
return errors.Wrapf(err, "mount %s: %s", dir, out)
}
return nil
return mountutils.MountWithParams(fmt.Sprintf("%s:%s", vm.CephFS.MonHost, vm.CephFS.Path), dir, "ceph", []string{"-o", options})
}

func (h cephFS) Unmount(pod IPodInfo, ctrId string, vm *hostapi.ContainerVolumeMount) error {
Expand Down
13 changes: 13 additions & 0 deletions pkg/util/mountutils/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ func Mount(devPath string, mountPoint string, fsType string) error {
})
}

func MountWithParams(devPath string, mountPoint string, fsType string, opts []string) error {
return mountWrap(mountPoint, func() error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
args := []string{"-t", fsType, devPath, mountPoint}
args = append(args, opts...)
if out, err := procutils.NewRemoteCommandContextAsFarAsPossible(ctx, "mount", args...).Output(); err != nil {
return errors.Wrapf(err, "mount %s to %s with fs %s: %s", devPath, mountPoint, fsType, string(out))
}
return nil
})
}

func MountOverlay(lowerDir []string, upperDir string, workDir string, mergedDir string) error {
return mountOverlay(lowerDir, upperDir, workDir, mergedDir, nil)
}
Expand Down

0 comments on commit 0dbdf59

Please sign in to comment.