Skip to content

Commit

Permalink
driver: do not use source to check mount
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Aug 21, 2018
1 parent 299c1e6 commit 5087aa3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 41 deletions.
19 changes: 10 additions & 9 deletions driver/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Mounter interface {
// in a correct way (i.e: propagated). It returns true if it's mounted. An
// error is returned in case of system errors or if it's mounted
// incorrectly.
IsMounted(source, target string) (bool, error)
IsMounted(target string) (bool, error)
}

// TODO(arslan): this is Linux only for now. Refactor this into a package with
Expand Down Expand Up @@ -215,11 +215,7 @@ func (m *mounter) IsFormatted(source string) (bool, error) {
return true, nil
}

func (m *mounter) IsMounted(source, target string) (bool, error) {
if source == "" {
return false, errors.New("source is not specified for checking the mount")
}

func (m *mounter) IsMounted(target string) (bool, error) {
if target == "" {
return false, errors.New("target is not specified for checking the mount")
}
Expand All @@ -233,12 +229,12 @@ func (m *mounter) IsMounted(source, target string) (bool, error) {
return false, err
}

findmntArgs := []string{"-o", "TARGET,PROPAGATION,FSTYPE,OPTIONS", source, "-J"}
findmntArgs := []string{"-o", "TARGET,PROPAGATION,FSTYPE,OPTIONS", "-M", target, "-J"}

m.log.WithFields(logrus.Fields{
"cmd": findmntCmd,
"args": findmntArgs,
}).Info("checking if source is mounted")
}).Info("checking if target is mounted")

out, err := exec.Command(findmntCmd, findmntArgs...).CombinedOutput()
if err != nil {
Expand All @@ -251,6 +247,11 @@ func (m *mounter) IsMounted(source, target string) (bool, error) {
err, findmntCmd, string(out))
}

// no response means there is no mount
if string(out) == "" {
return false, nil
}

var resp *findmntResponse
err = json.Unmarshal(out, &resp)
if err != nil {
Expand All @@ -261,7 +262,7 @@ func (m *mounter) IsMounted(source, target string) (bool, error) {
for _, fs := range resp.FileSystems {
// check if the mount is propagated correctly. It should be set to shared.
if fs.Propagation != "shared" {
return true, fmt.Errorf("mount propagation for target %q is not enabled or the block device %q does not exist anymore", target, source)
return true, fmt.Errorf("mount propagation for target %q is not enabled", target)
}

// the mountpoint should match as well
Expand Down
47 changes: 15 additions & 32 deletions driver/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5087aa3

Please sign in to comment.