Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some enhancements #242

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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