MCPcopy
hub / github.com/lxc/incus / readonlySnapshot

Method readonlySnapshot

internal/server/storage/drivers/driver_btrfs_volumes.go:1397–1438  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
1397func (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.
1441func (d *btrfs) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs *localMigration.VolumeSourceArgs, op *operations.Operation) error {

Callers 2

MigrateVolumeMethod · 0.95
BackupVolumeMethod · 0.95

Calls 10

snapshotSubvolumeMethod · 0.95
NewFunction · 0.92
GetPoolMountPathFunction · 0.85
FailMethod · 0.80
MountPathMethod · 0.80
SuccessMethod · 0.80
AddMethod · 0.65
DebugMethod · 0.65
CloneMethod · 0.45

Tested by

no test coverage detected