Skip to content

Commit c383436

Browse files
author
Kazuyoshi Kato
committed
snapshots/devmapper: suspend a device to avoid data corruption
According to https://github.com/torvalds/linux/blob/v5.7/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. However the devmapper snapshotter was not doing that. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent c763f3a commit c383436

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

snapshots/devmapper/pool_device.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,23 @@ func (p *PoolDevice) CreateSnapshotDevice(ctx context.Context, deviceName string
306306
return metaErr
307307
}
308308

309+
// The base device must be suspend before taking a snapshot to
310+
// avoid corruption.
311+
// https://github.com/torvalds/linux/blob/v5.7/Documentation/admin-guide/device-mapper/thin-provisioning.rst#internal-snapshots
312+
if p.IsLoaded(deviceName) {
313+
log.G(ctx).Debugf("suspending %q before taking its snapshot", deviceName)
314+
suspendErr := p.SuspendDevice(ctx, deviceName)
315+
if suspendErr != nil {
316+
return suspendErr
317+
}
318+
defer func() {
319+
err := p.ResumeDevice(ctx, deviceName)
320+
if err != nil {
321+
log.G(ctx).WithError(err).Errorf("failed to resume base device %q after taking its snapshot", baseInfo.Name)
322+
}
323+
}()
324+
}
325+
309326
// Create thin device snapshot
310327
devErr = p.createSnapshot(ctx, baseInfo, snapInfo)
311328
if devErr != nil {

0 commit comments

Comments
 (0)