Skip to content

Commit

Permalink
Move filesystem type discrepancy check into share-manager mount opera…
Browse files Browse the repository at this point in the history
…tion

Since we do this only for backwards compatibility it should be handled,
by the share-manager instead of the more general mount operation.

Longhorn #2991

Signed-off-by: Joshua Moody <joshua.moody@suse.com>
  • Loading branch information
joshimoo committed Sep 14, 2021
1 parent af8436b commit 9d9b948
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
26 changes: 25 additions & 1 deletion pkg/server/share_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -80,7 +81,7 @@ func (m *ShareManager) Run() error {
return err
}

if err := volume.MountVolume(devicePath, mountPath, vol.FsType, vol.MountOptions); err != nil {
if err := mountVolume(m.logger, vol, devicePath, mountPath); err != nil {
m.logger.WithError(err).Warn("failed to mount volume")
return err
}
Expand Down Expand Up @@ -155,6 +156,29 @@ func tearDownDevice(logger logrus.FieldLogger, vol volume.Volume) error {
return nil
}

func mountVolume(logger logrus.FieldLogger, vol volume.Volume, devicePath, mountPath string) error {
fsType := vol.FsType
mountOptions := vol.MountOptions

// https://github.com/longhorn/longhorn/issues/2991
// pre v1.2 we ignored the fsType and always formatted as ext4
// after v1.2 we include the user specified fsType to be able to
// mount priorly created volumes we need to switch to the existing fsType
diskFormat, err := volume.GetDiskFormat(devicePath)
if err != nil {
logger.WithError(err).Error("failed to evaluate disk format")
return err
}

// `unknown data, probably partitions` is used when the disk contains a partition table
if diskFormat != "" && !strings.Contains(diskFormat, "unknown data") && fsType != diskFormat {
logger.Warnf("disk is already formatted to %v but user requested fs is %v using existing device fs type for mount", diskFormat, fsType)
fsType = diskFormat
}

return volume.MountVolume(devicePath, mountPath, fsType, mountOptions)
}

func (m *ShareManager) runHealthCheck() {
m.logger.Info("starting health check for volume")
ticker := time.NewTicker(healthCheckInterval)
Expand Down
15 changes: 0 additions & 15 deletions pkg/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package volume
import (
"fmt"
"os"
"strings"

"k8s.io/kubernetes/pkg/volume/util/hostutil"
utilexec "k8s.io/utils/exec"
Expand Down Expand Up @@ -45,20 +44,6 @@ func MountVolume(devicePath, mountPath, fsType string, mountOptions []string) er
return nil
}

// https://github.com/longhorn/longhorn/issues/2991
// pre v1.2 we ignored the fsType and always formatted as ext4
// after v1.2 we include the user specified fsType to be able to
// mount priorly created volumes we need to switch to the existing fsType
diskFormat, err := GetDiskFormat(devicePath)
if err != nil {
return err
}

// `unknown data, probably partitions` is used when the disk contains a partition table
if diskFormat != "" && !strings.Contains(diskFormat, "unknown data") && fsType != diskFormat {
fsType = diskFormat
}

mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: utilexec.New()}

if exists, err := hostutil.NewHostUtil().PathExists(mountPath); !exists || err != nil {
Expand Down

0 comments on commit 9d9b948

Please sign in to comment.