(realPath string, desiredSwapSizeInBytes *uint64, labelPrefix string)
| 653 | } |
| 654 | |
| 655 | func (p linux) SetupEphemeralDiskWithPath(realPath string, desiredSwapSizeInBytes *uint64, labelPrefix string) error { |
| 656 | p.logger.Info(logTag, "Setting up ephemeral disk...") |
| 657 | mountPoint := p.dirProvider.DataDir() |
| 658 | |
| 659 | mountPointGlob := path.Join(mountPoint, "*") |
| 660 | contents, err := p.fs.Glob(mountPointGlob) |
| 661 | if err != nil { |
| 662 | return bosherr.WrapErrorf(err, "Globbing ephemeral disk mount point `%s'", mountPointGlob) |
| 663 | } |
| 664 | |
| 665 | if len(contents) > 0 { |
| 666 | // When agent bootstraps for the first time data directory should be empty. |
| 667 | // It might be non-empty on subsequent agent restarts. The ephemeral disk setup |
| 668 | // should be idempotent and partitioning will be skipped if disk is already |
| 669 | // partitioned as needed. If disk is not partitioned as needed we still want to |
| 670 | // partition it even if data directory is not empty. |
| 671 | p.logger.Debug(logTag, "Existing ephemeral mount `%s' is not empty. Contents: %s", mountPoint, contents) |
| 672 | } |
| 673 | |
| 674 | err = p.fs.MkdirAll(mountPoint, ephemeralDiskPermissions) |
| 675 | if err != nil { |
| 676 | return bosherr.WrapError(err, "Creating data dir") |
| 677 | } |
| 678 | |
| 679 | if p.options.SkipDiskSetup { |
| 680 | return nil |
| 681 | } |
| 682 | |
| 683 | var swapPartitionPath, dataPartitionPath string |
| 684 | |
| 685 | // Agent can only setup ephemeral data directory either on ephemeral device |
| 686 | // or on separate root partition. |
| 687 | // The real path can be empty if CPI did not provide ephemeral disk |
| 688 | // or if the provided disk was not found. |
| 689 | if realPath == "" { |
| 690 | if !p.options.CreatePartitionIfNoEphemeralDisk { |
| 691 | // Agent can not use root partition for ephemeral data directory. |
| 692 | return bosherr.Error("No ephemeral disk found, cannot use root partition as ephemeral disk") |
| 693 | } |
| 694 | |
| 695 | swapPartitionPath, dataPartitionPath, err = p.createEphemeralPartitionsOnRootDevice(desiredSwapSizeInBytes, labelPrefix) |
| 696 | if err != nil { |
| 697 | return bosherr.WrapError(err, "Creating ephemeral partitions on root device") |
| 698 | } |
| 699 | } else { |
| 700 | swapPartitionPath, dataPartitionPath, err = p.partitionEphemeralDisk(realPath, desiredSwapSizeInBytes, labelPrefix) |
| 701 | if err != nil { |
| 702 | return bosherr.WrapError(err, "Partitioning ephemeral disk") |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | if len(swapPartitionPath) > 0 { |
| 707 | canonicalSwapPartitionPath, err := resolveCanonicalLink(p.cmdRunner, swapPartitionPath) |
| 708 | if err != nil { |
| 709 | return err |
| 710 | } |
| 711 | |
| 712 | p.logger.Info(logTag, "Formatting `%s' (canonical path: %s) as swap", swapPartitionPath, canonicalSwapPartitionPath) |
nothing calls this directly
no test coverage detected