Skip to content

Commit 179330d

Browse files
authored
Merge pull request #1971 from MaximilianMeister/fix-kubernetes-issue-65204
fix brtfs issue where dir is sub-directory of a sub-volume
2 parents fc0bd7a + 87ddb0e commit 179330d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/fs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,21 @@ func (self *RealFsInfo) GetDirFsDevice(dir string) (*DeviceInfo, error) {
533533
}
534534

535535
mount, found := self.mounts[dir]
536+
// try the parent dir if not found until we reach the root dir
537+
// this is an issue on btrfs systems where the directory is not
538+
// the subvolume
539+
for !found {
540+
pathdir, _ := filepath.Split(dir)
541+
// break when we reach root
542+
if pathdir == "/" {
543+
break
544+
}
545+
// trim "/" from the new parent path otherwise the next possible
546+
// filepath.Split in the loop will not split the string any further
547+
dir = strings.TrimSuffix(pathdir, "/")
548+
mount, found = self.mounts[dir]
549+
}
550+
536551
if found && mount.Fstype == "btrfs" && mount.Major == 0 && strings.HasPrefix(mount.Source, "/dev/") {
537552
major, minor, err := getBtrfsMajorMinorIds(mount)
538553
if err != nil {

0 commit comments

Comments
 (0)