From c725b5d96d27ed84aa1b1060f18373497ba351c1 Mon Sep 17 00:00:00 2001 From: Wine93 Date: Fri, 16 Jun 2023 11:16:27 +0800 Subject: [PATCH] Fix(mount): path already mounted. Signed-off-by: Wine93 --- internal/task/task/fs/mount.go | 13 ++++++------- internal/task/task/fs/umount.go | 9 +++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/internal/task/task/fs/mount.go b/internal/task/task/fs/mount.go index bc1e49ce0..b82df45b4 100644 --- a/internal/task/task/fs/mount.go +++ b/internal/task/task/fs/mount.go @@ -217,12 +217,12 @@ func mountPoint2ContainerName(mountPoint string) string { return fmt.Sprintf("curvefs-filesystem-%s", utils.MD5Sum(mountPoint)) } -func checkMountStatus(mountPoint string, out *string) step.LambdaType { +func checkMountStatus(mountPoint, name string, out *string) step.LambdaType { return func(ctx *context.Context) error { - if len(*out) == 0 { - return nil + if *out == name { + return errno.ERR_FS_PATH_ALREADY_MOUNTED.F("mountPath: %s", mountPoint) } - return errno.ERR_FS_PATH_ALREADY_MOUNTED.F("mountPath: %s", mountPoint) + return nil } } @@ -305,14 +305,13 @@ func NewMountFSTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) (*task.T }) t.AddStep(&step.ListContainers{ ShowAll: true, - Format: "'{{.Status}}'", - Quiet: true, + Format: "'{{.Names}}'", Filter: fmt.Sprintf("name=%s", containerName), Out: &out, ExecOptions: curveadm.ExecOptions(), }) t.AddStep(&step.Lambda{ - Lambda: checkMountStatus(mountPoint, &out), + Lambda: checkMountStatus(mountPoint, containerName, &out), }) t.AddStep(&step.PullImage{ Image: cc.GetContainerImage(), diff --git a/internal/task/task/fs/umount.go b/internal/task/task/fs/umount.go index 6c14c93af..10cd425ff 100644 --- a/internal/task/task/fs/umount.go +++ b/internal/task/task/fs/umount.go @@ -117,10 +117,6 @@ func (s *step2RemoveContainer) Execute(ctx *context.Context) error { func NewUmountFSTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, error) { options := curveadm.MemStorage().Get(comm.KEY_MOUNT_OPTIONS).(MountOptions) fsId := curveadm.GetFilesystemId(options.Host, options.MountPoint) - containerId, err := curveadm.Storage().GetClientContainerId(fsId) - if err != nil { - return nil, errno.ERR_GET_CLIENT_CONTAINER_ID_FAILED.E(err) - } hc, err := curveadm.GetHost(options.Host) if err != nil { return nil, err @@ -133,11 +129,12 @@ func NewUmountFSTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, error) // add step to task var status string + containerId := mountPoint2ContainerName(mountPoint) + t.AddStep(&step.ListContainers{ ShowAll: true, Format: "'{{.Status}}'", - Quiet: true, - Filter: fmt.Sprintf("id=%s", containerId), + Filter: fmt.Sprintf("name=%s", containerId), Out: &status, ExecOptions: curveadm.ExecOptions(), })