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

Method MigratePersistentDisk

platform/linux_platform.go:1556–1610  ·  view source on GitHub ↗
(fromMountPoint, toMountPoint string)

Source from the content-addressed store, hash-verified

1554}
1555
1556func (p linux) MigratePersistentDisk(fromMountPoint, toMountPoint string) error {
1557 p.logger.Debug(logTag, "Migrating persistent disk %v to %v", fromMountPoint, toMountPoint)
1558
1559 err := p.diskManager.GetMounter().RemountAsReadonly(fromMountPoint)
1560 if err != nil {
1561 return bosherr.WrapError(err, "Remounting persistent disk as readonly")
1562 }
1563
1564 // Golang does not implement a file copy that would allow us to preserve dates...
1565 // So we have to shell out to tar to perform the copy instead of delegating to the FileSystem
1566 // The --xattrs and --xattrs-include=*.* flags ensure that all extended attributes (ex. capabilities) are preserved
1567 tarCopy := fmt.Sprintf("(tar -C %s --xattrs --xattrs-include=*.* --sparse -cf - .) | (tar -C %s --xattrs --xattrs-include=*.* -xpf -)", fromMountPoint, toMountPoint)
1568 _, _, _, err = p.cmdRunner.RunCommand("sh", "-c", tarCopy)
1569 if err != nil {
1570 return bosherr.WrapError(err, "Copying files from old disk to new disk")
1571 }
1572
1573 // Find iSCSI device id of fromMountPoint
1574 var iscsiID string
1575 if p.options.DevicePathResolutionType == "iscsi" {
1576 mounts, err := p.diskManager.GetMountsSearcher().SearchMounts()
1577 if err != nil {
1578 return bosherr.WrapError(err, "Search persistent disk as readonly")
1579 }
1580
1581 devMapperPart1Regexp := regexp.MustCompile(`/dev/mapper/(.*?)-part1`)
1582 for _, mount := range mounts {
1583 if mount.MountPoint == fromMountPoint {
1584 matches := devMapperPart1Regexp.FindStringSubmatch(mount.PartitionPath)
1585 if len(matches) > 1 {
1586 iscsiID = matches[1]
1587 }
1588 }
1589 }
1590 }
1591
1592 _, err = p.diskManager.GetMounter().Unmount(fromMountPoint)
1593 if err != nil {
1594 return bosherr.WrapError(err, "Unmounting old persistent disk")
1595 }
1596
1597 err = p.diskManager.GetMounter().Remount(toMountPoint, fromMountPoint)
1598 if err != nil {
1599 err = bosherr.WrapError(err, "Remounting new disk on original mountpoint")
1600 }
1601
1602 if p.options.DevicePathResolutionType == "iscsi" && iscsiID != "" {
1603 err = p.flushMultipathDevice(iscsiID)
1604 if err != nil {
1605 return err
1606 }
1607 }
1608
1609 return err
1610}
1611
1612func (p linux) IsPersistentDiskMounted(diskSettings boshsettings.DiskSettings) (bool, error) {
1613 p.logger.Debug(logTag, "Checking whether persistent disk %+v is mounted", diskSettings)

Callers

nothing calls this directly

Calls 9

flushMultipathDeviceMethod · 0.95
DebugMethod · 0.65
RemountAsReadonlyMethod · 0.65
GetMounterMethod · 0.65
RunCommandMethod · 0.65
SearchMountsMethod · 0.65
GetMountsSearcherMethod · 0.65
UnmountMethod · 0.65
RemountMethod · 0.65

Tested by

no test coverage detected