|
23 | 23 | updateDbConf = "/etc/updatedb.conf" |
24 | 24 | prunePathsPattern = "^PRUNEPATHS\\s*=\\s*\"(?P<paths>.*)\"" |
25 | 25 | defaultFSCreateTimeout = 300 /* 5 minutes */ |
| 26 | + defaultFSCheckTimeout = 600 /* 10 minutes */ |
26 | 27 | lsof = "lsof" |
27 | 28 | blkid = "blkid" |
28 | 29 | errCurrentlyMounted = "is currently mounted" |
@@ -76,6 +77,8 @@ const ( |
76 | 77 | fsext4command = "mkfs.ext4" |
77 | 78 | fsbtrfscommand = "mkfs.btrfs" |
78 | 79 | defaultNFSType = "nfs4" |
| 80 | + fsckcommand = "fsck" |
| 81 | + fsckoptions = "-a" |
79 | 82 | ) |
80 | 83 |
|
81 | 84 | // HashMountID : get hash of the string |
@@ -325,6 +328,25 @@ func RetryCreateFileSystemWithOptions(devPath string, fsType string, options []s |
325 | 328 | } |
326 | 329 | } |
327 | 330 |
|
| 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 | + |
328 | 350 | // CreateFileSystem : creates file system on the device |
329 | 351 | func CreateFileSystem(devPath string, fsType string) (err error) { |
330 | 352 | log.Tracef("createFileSystem called with %s %s", fsType, devPath) |
|
0 commit comments