Skip to content

Commit 9fad6cb

Browse files
committed
add CheckFileSystem
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 97cb25c commit 9fad6cb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

chapi/chapidriver_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ func (driver *LinuxDriver) MountDevice(device *model.Device, mountPoint string,
267267
log.Tracef("Filesystem %+v setup successful,", fsOpts)
268268
}
269269

270+
// Check filesystem consistency
271+
err := linux.CheckFileSystem(device.AltFullPathName)
272+
270273
// Setup mountpoint (Create mountpoint and apply mount options)
271274
mount, err := linux.SetupMount(device, mountPoint, mountOptions)
272275
if err != nil {

linux/mount.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
updateDbConf = "/etc/updatedb.conf"
2424
prunePathsPattern = "^PRUNEPATHS\\s*=\\s*\"(?P<paths>.*)\""
2525
defaultFSCreateTimeout = 300 /* 5 minutes */
26+
defaultFSCheckTimeout = 600 /* 10 minutes */
2627
lsof = "lsof"
2728
blkid = "blkid"
2829
errCurrentlyMounted = "is currently mounted"
@@ -76,6 +77,8 @@ const (
7677
fsext4command = "mkfs.ext4"
7778
fsbtrfscommand = "mkfs.btrfs"
7879
defaultNFSType = "nfs4"
80+
fsckcommand = "fsck"
81+
fsckoptions = "-a"
7982
)
8083

8184
// HashMountID : get hash of the string
@@ -325,6 +328,25 @@ func RetryCreateFileSystemWithOptions(devPath string, fsType string, options []s
325328
}
326329
}
327330

331+
// CheckFileSystem: checks file system on the device for errors
332+
func CheckFileSystem(devPath string) (err error) {
333+
log.Tracef("checkFileSystem called with %s", devPath)
334+
return checkFileSystem(devPath)
335+
}
336+
337+
func checkFileSystem(devPath string) (err error) {
338+
var output string
339+
options := []string{fsckoptions, devPath}
340+
output, _, err = util.ExecCommandOutputWithTimeout(fsckcommand, options, defaultFSCheckTimeout)
341+
if err != nil {
342+
return fmt.Errorf("unable to check filesystem using %s %s. Error: %s", fsckcommand, options, err.Error())
343+
}
344+
if output == "" {
345+
return fmt.Errorf("filesystem not checked using %s %s", fsckcommand, options)
346+
}
347+
return nil
348+
}
349+
328350
// CreateFileSystem : creates file system on the device
329351
func CreateFileSystem(devPath string, fsType string) (err error) {
330352
log.Tracef("createFileSystem called with %s %s", fsType, devPath)

0 commit comments

Comments
 (0)