Skip to content

Commit

Permalink
Fix(mount): path already mounted.
Browse files Browse the repository at this point in the history
Signed-off-by: Wine93 <wine93.info@gmail.com>
  • Loading branch information
Wine93 authored and caoxianfei1 committed Aug 7, 2023
1 parent 1c45bfb commit c725b5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
13 changes: 6 additions & 7 deletions internal/task/task/fs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 3 additions & 6 deletions internal/task/task/fs/umount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
})
Expand Down

0 comments on commit c725b5d

Please sign in to comment.