readonlySnapshot creates a readonly snapshot. Returns a revert fail function that can be used to undo this function if a subsequent step fails.
(vol Volume)
| 1395 | // readonlySnapshot creates a readonly snapshot. |
| 1396 | // Returns a revert fail function that can be used to undo this function if a subsequent step fails. |
| 1397 | func (d *btrfs) readonlySnapshot(vol Volume) (string, revert.Hook, error) { |
| 1398 | reverter := revert.New() |
| 1399 | defer reverter.Fail() |
| 1400 | |
| 1401 | sourcePath := vol.MountPath() |
| 1402 | poolPath := GetPoolMountPath(d.name) |
| 1403 | tmpDir, err := os.MkdirTemp(poolPath, "backup.") |
| 1404 | if err != nil { |
| 1405 | return "", nil, err |
| 1406 | } |
| 1407 | |
| 1408 | reverter.Add(func() { |
| 1409 | _ = os.RemoveAll(tmpDir) |
| 1410 | }) |
| 1411 | |
| 1412 | err = os.Chmod(tmpDir, 0o100) |
| 1413 | if err != nil { |
| 1414 | return "", nil, err |
| 1415 | } |
| 1416 | |
| 1417 | mountPath := filepath.Join(tmpDir, vol.name) |
| 1418 | |
| 1419 | cleanup, err := d.snapshotSubvolume(sourcePath, mountPath, true) |
| 1420 | if err != nil { |
| 1421 | return "", nil, err |
| 1422 | } |
| 1423 | |
| 1424 | if cleanup != nil { |
| 1425 | reverter.Add(cleanup) |
| 1426 | } |
| 1427 | |
| 1428 | err = d.setSubvolumeReadonlyProperty(mountPath, true) |
| 1429 | if err != nil { |
| 1430 | return "", nil, err |
| 1431 | } |
| 1432 | |
| 1433 | d.logger.Debug("Created read-only backup snapshot", logger.Ctx{"sourcePath": sourcePath, "path": mountPath}) |
| 1434 | |
| 1435 | cleanup = reverter.Clone().Fail |
| 1436 | reverter.Success() |
| 1437 | return mountPath, cleanup, nil |
| 1438 | } |
| 1439 | |
| 1440 | // MigrateVolume sends a volume for migration. |
| 1441 | func (d *btrfs) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs *localMigration.VolumeSourceArgs, op *operations.Operation) error { |
no test coverage detected