Skip to content

Commit

Permalink
some enhancements for writable layer
Browse files Browse the repository at this point in the history
Signed-off-by: Lanzheng Liu <[email protected]>
  • Loading branch information
liulanzheng committed Nov 10, 2023
1 parent bc20e7f commit b569dda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
5 changes: 4 additions & 1 deletion pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
42 changes: 16 additions & 26 deletions pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b569dda

Please sign in to comment.