MCPcopy Create free account
hub / github.com/cloudfoundry/bosh-agent / findRootDevicePathAndNumber

Method findRootDevicePathAndNumber

platform/linux_platform.go:1719–1765  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1717}
1718
1719func (p linux) findRootDevicePathAndNumber() (string, int, error) {
1720 mounts, err := p.diskManager.GetMountsSearcher().SearchMounts()
1721 if err != nil {
1722 return "", 0, bosherr.WrapError(err, "Searching mounts")
1723 }
1724
1725 for _, mount := range mounts {
1726 if mount.IsRoot() {
1727 p.logger.Debug(logTag, "Found root partition: `%s'", mount.PartitionPath)
1728
1729 stdout, _, _, err := p.cmdRunner.RunCommand("readlink", "-f", mount.PartitionPath)
1730 if err != nil {
1731 return "", 0, bosherr.WrapError(err, "Shelling out to readlink")
1732 }
1733 rootPartition := strings.Trim(stdout, "\n")
1734 p.logger.Debug(logTag, "Symlink is: `%s'", rootPartition)
1735
1736 validNVMeRootPartition := regexp.MustCompile(`^(/dev/[a-z]+\d+n\d+)p(\d+)$`)
1737 validSCSIRootPartition := regexp.MustCompile(`^/dev/[a-z]+\d$`)
1738
1739 nvmeMatches := validNVMeRootPartition.FindStringSubmatch(rootPartition)
1740 isValidSCSIPath := validSCSIRootPartition.MatchString(rootPartition)
1741 if nvmeMatches == nil && !isValidSCSIPath {
1742 return "", 0, bosherr.Errorf("Root partition has an invalid name%s", rootPartition)
1743 }
1744
1745 var devPath string
1746 var devNum int
1747 if nvmeMatches != nil {
1748 devPath = nvmeMatches[1]
1749 devNum, err = strconv.Atoi(nvmeMatches[2])
1750 if err != nil {
1751 return "", 0, bosherr.WrapError(err, "Parsing NVMe partition number failed")
1752 }
1753 } else {
1754 devPath = rootPartition[:len(rootPartition)-1]
1755 devNum, err = strconv.Atoi(rootPartition[len(rootPartition)-1:])
1756 if err != nil {
1757 return "", 0, bosherr.WrapError(err, "Parsing device number failed")
1758 }
1759 }
1760
1761 return devPath, devNum, nil
1762 }
1763 }
1764 return "", 0, bosherr.Error("Getting root partition device")
1765}
1766
1767func (p linux) createEphemeralPartitionsOnRootDevice(desiredSwapSizeInBytes *uint64, labelPrefix string) (string, string, error) {
1768 p.logger.Info(logTag, "Creating swap & ephemeral partitions on root disk...")

Callers 2

SetupRootDiskMethod · 0.95

Calls 6

IsRootMethod · 0.80
SearchMountsMethod · 0.65
GetMountsSearcherMethod · 0.65
DebugMethod · 0.65
RunCommandMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected