Skip to content

Commit 81acbcf

Browse files
author
Kazuyoshi Kato
committed
snapshots/devmapper: suspend a device to avoid data corruption
According to https://github.com/torvalds/linux/blob/c309b6f24222246c18a8b65d3950e6e755440865/Documentation/admin-guide/device-mapper/thin-provisioning.rst#internal-snapshots; > If the origin device that you wish to snapshot is active, you > must suspend it before creating the snapshot to avoid corruption. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent be75852 commit 81acbcf

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

snapshots/devmapper/pool_device.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,20 @@ func (p *PoolDevice) CreateSnapshotDevice(ctx context.Context, deviceName string
304304
return metaErr
305305
}
306306

307+
if p.IsLoaded(deviceName) {
308+
log.G(ctx).Debugf("suspending %q", deviceName)
309+
suspendErr := p.SuspendDevice(ctx, deviceName)
310+
if suspendErr != nil {
311+
return suspendErr
312+
}
313+
defer func() {
314+
err := p.ResumeDevice(ctx, deviceName)
315+
if err != nil {
316+
log.G(ctx).WithError(err).Errorf("failed to resume %q", baseInfo.Name)
317+
}
318+
}()
319+
}
320+
307321
// Create thin device snapshot
308322
devErr = p.createSnapshot(ctx, baseInfo, snapInfo)
309323
if devErr != nil {

0 commit comments

Comments
 (0)