From b569dda870f57e9f08a2980001e6b0ebc45c0737 Mon Sep 17 00:00:00 2001 From: liulanzheng Date: Fri, 10 Nov 2023 18:06:51 +0800 Subject: [PATCH] some enhancements for writable layer Signed-off-by: Lanzheng Liu --- pkg/snapshot/overlay.go | 5 ++++- pkg/snapshot/storage.go | 42 ++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/pkg/snapshot/overlay.go b/pkg/snapshot/overlay.go index 721483df..3a3e14b7 100644 --- a/pkg/snapshot/overlay.go +++ b/pkg/snapshot/overlay.go @@ -717,6 +717,8 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap // TODO(fuweid): how to rollback? if oinfo.Labels[label.AccelerationLayer] == "yes" { log.G(ctx).Info("Commit accel-layer requires no writable_data") + } else if _, err := o.loadBackingStoreConfig(id); err != nil { + log.G(ctx).Info("not an overlaybd writable layer") } else { if err := o.unmountAndDetachBlockDevice(ctx, id, key); err != nil { return errors.Wrapf(err, "failed to destroy target device for snapshot %s", key) @@ -752,7 +754,8 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap } info.Labels[label.LocalOverlayBDPath] = o.overlaybdSealedFilePath(id) - info, err = storage.UpdateInfo(ctx, info, fmt.Sprintf("labels.%s", label.LocalOverlayBDPath)) + delete(info.Labels, label.SupportReadWriteMode) + info, err = storage.UpdateInfo(ctx, info) if err != nil { return err } diff --git a/pkg/snapshot/storage.go b/pkg/snapshot/storage.go index 21c9eec3..31a3ea52 100644 --- a/pkg/snapshot/storage.go +++ b/pkg/snapshot/storage.go @@ -180,34 +180,24 @@ func (o *snapshotter) parseAndCheckMounted(ctx context.Context, r io.Reader, dir // unmountAndDetachBlockDevice func (o *snapshotter) unmountAndDetachBlockDevice(ctx context.Context, snID string, snKey string) (err error) { - - var info snapshots.Info - if snKey != "" { - _, info, _, err = storage.GetInfo(ctx, snKey) - if err != nil { - return errors.Wrapf(err, "can't get snapshot info.") - } - } - writeType := o.getWritableType(ctx, snID, info) - overlaybd, err := os.ReadFile(o.overlaybdBackstoreMarkFile(snID)) + devName, err := os.ReadFile(o.overlaybdBackstoreMarkFile(snID)) if err != nil { log.G(ctx).Errorf("read device name failed: %s, err: %v", o.overlaybdBackstoreMarkFile(snID), err) } - if writeType != RwDev { - mountPoint := o.overlaybdMountpoint(snID) - log.G(ctx).Debugf("check overlaybd mountpoint is in use: %s", mountPoint) - busy, err := o.checkOverlaybdInUse(ctx, mountPoint) - if err != nil { - return err - } - if busy { - log.G(ctx).Infof("device still in use.") - return nil - } - log.G(ctx).Infof("umount device, mountpoint: %s", mountPoint) - if err := mount.UnmountAll(mountPoint, 0); err != nil { - return errors.Wrapf(err, "failed to umount %s", mountPoint) - } + + mountPoint := o.overlaybdMountpoint(snID) + log.G(ctx).Debugf("check overlaybd mountpoint is in use: %s", mountPoint) + busy, err := o.checkOverlaybdInUse(ctx, mountPoint) + if err != nil { + return err + } + if busy { + log.G(ctx).Infof("device still in use.") + return nil + } + log.G(ctx).Infof("umount device, mountpoint: %s", mountPoint) + if err := mount.UnmountAll(mountPoint, 0); err != nil { + return errors.Wrapf(err, "failed to umount %s", mountPoint) } loopDevID := o.overlaybdLoopbackDeviceID(snID) @@ -243,7 +233,7 @@ func (o *snapshotter) unmountAndDetachBlockDevice(ctx context.Context, snID stri if err != nil { return errors.Wrapf(err, "failed to remove target dir %s", targetPath) } - log.G(ctx).Infof("destroy overlaybd device success(sn: %s): %s", snID, overlaybd) + log.G(ctx).Infof("destroy overlaybd device success(sn: %s): %s", snID, devName) return nil }