Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions chapi/chapidriver_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ func (driver *LinuxDriver) MountDevice(device *model.Device, mountPoint string,
log.Tracef("Filesystem %+v setup successful,", fsOpts)
}

// Check filesystem consistency
err := linux.CheckFileSystem(device.AltFullPathName)

// Setup mountpoint (Create mountpoint and apply mount options)
mount, err := linux.SetupMount(device, mountPoint, mountOptions)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions linux/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
updateDbConf = "/etc/updatedb.conf"
prunePathsPattern = "^PRUNEPATHS\\s*=\\s*\"(?P<paths>.*)\""
defaultFSCreateTimeout = 300 /* 5 minutes */
defaultFSCheckTimeout = 600 /* 10 minutes */
lsof = "lsof"
blkid = "blkid"
errCurrentlyMounted = "is currently mounted"
Expand Down Expand Up @@ -76,6 +77,8 @@ const (
fsext4command = "mkfs.ext4"
fsbtrfscommand = "mkfs.btrfs"
defaultNFSType = "nfs4"
fsckcommand = "fsck"
fsckoptions = "-a"
)

// HashMountID : get hash of the string
Expand Down Expand Up @@ -325,6 +328,25 @@ func RetryCreateFileSystemWithOptions(devPath string, fsType string, options []s
}
}

// CheckFileSystem: checks file system on the device for errors
func CheckFileSystem(devPath string) (err error) {
log.Tracef("checkFileSystem called with %s", devPath)
return checkFileSystem(devPath)
}

func checkFileSystem(devPath string) (err error) {
var output string
options := []string{fsckoptions, devPath}
output, _, err = util.ExecCommandOutputWithTimeout(fsckcommand, options, defaultFSCheckTimeout)
if err != nil {
return fmt.Errorf("unable to check filesystem using %s %s. Error: %s", fsckcommand, options, err.Error())
}
if output == "" {
return fmt.Errorf("filesystem not checked using %s %s", fsckcommand, options)
}
return nil
}

// CreateFileSystem : creates file system on the device
func CreateFileSystem(devPath string, fsType string) (err error) {
log.Tracef("createFileSystem called with %s %s", fsType, devPath)
Expand Down
5 changes: 4 additions & 1 deletion util/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func execCommandOutputWithTimeout(cmd string, args []string, stdinArgs []string,

// ExecCommandOutputWithTimeout executes ExecCommandOutput with the specified timeout
func ExecCommandOutputWithTimeout(cmd string, args []string, timeout int) (string, int, error) {
return execCommandOutputWithTimeout(cmd, args, []string{}, defaultTimeout)
if timeout == 0 {
timeout = defaultTimeout
}
return execCommandOutputWithTimeout(cmd, args, []string{}, timeout)
}
// ExecCommandOutput returns stdout and stderr in a single string, the return code, and error.
// If the return code is not zero, error will not be nil.
Expand Down