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

Method AdjustPersistentDiskPartitioning

platform/linux_platform.go:1381–1456  ·  view source on GitHub ↗
(diskSetting boshsettings.DiskSettings, mountPoint string)

Source from the content-addressed store, hash-verified

1379}
1380
1381func (p linux) AdjustPersistentDiskPartitioning(diskSetting boshsettings.DiskSettings, mountPoint string) error {
1382 if p.options.UsePreformattedPersistentDisk {
1383 return nil
1384 }
1385 p.logger.Debug(logTag, "Adjusting size for persistent disk %+v", diskSetting)
1386
1387 devicePath, _, err := p.devicePathResolver.GetRealDevicePath(diskSetting)
1388 if err != nil {
1389 return bosherr.WrapError(err, "Getting real device path")
1390 }
1391
1392 firstPartitionPath := p.partitionPath(devicePath, 1)
1393
1394 partitioner, err := p.diskManager.GetPersistentDevicePartitioner(diskSetting.Partitioner)
1395 if err != nil {
1396 return bosherr.WrapError(err, "Selecting partitioner")
1397 }
1398
1399 singlePartNeedsResize, err := partitioner.SinglePartitionNeedsResize(devicePath, boshdisk.PartitionTypeLinux)
1400 if err != nil {
1401 return bosherr.WrapError(err, "Failed to determine whether partitions need rezising")
1402 }
1403 p.logger.Debug(logTag, "Persistent disk single partition needs resize: %+v", singlePartNeedsResize)
1404
1405 if singlePartNeedsResize { //nolint:nestif
1406 err = partitioner.ResizeSinglePartition(devicePath)
1407 if err != nil {
1408 return bosherr.WrapError(err, "Resizing disk partition")
1409 }
1410
1411 err = p.fs.MkdirAll(mountPoint, persistentDiskPermissions)
1412 if err != nil {
1413 return bosherr.WrapErrorf(err, "Creating directory %s", mountPoint)
1414 }
1415
1416 err := p.diskManager.GetMounter().Mount(firstPartitionPath, mountPoint, diskSetting.MountOptions...)
1417 if err != nil {
1418 return bosherr.WrapError(err, "Failed to mount partition for filesystem growing")
1419 }
1420
1421 err = p.diskManager.GetFormatter().GrowFilesystem(firstPartitionPath)
1422 if err != nil {
1423 return bosherr.WrapError(err, "Failed to grow filesystem")
1424 }
1425
1426 _, err = p.diskManager.GetMounter().Unmount(firstPartitionPath)
1427 if err != nil {
1428 return bosherr.WrapError(err, "Failed to unmount partition after filesystem growing")
1429 }
1430 } else {
1431 singlePartPartitioning := []boshdisk.Partition{
1432 {Type: boshdisk.PartitionTypeLinux},
1433 }
1434 err = partitioner.Partition(devicePath, singlePartPartitioning)
1435 if err != nil {
1436 return bosherr.WrapError(err, "Partitioning disk")
1437 }
1438

Callers

nothing calls this directly

Calls 15

partitionPathMethod · 0.95
MkdirAllMethod · 0.80
DebugMethod · 0.65
GetRealDevicePathMethod · 0.65
ResizeSinglePartitionMethod · 0.65
MountMethod · 0.65
GetMounterMethod · 0.65
GrowFilesystemMethod · 0.65
GetFormatterMethod · 0.65
UnmountMethod · 0.65

Tested by

no test coverage detected