Skip to content

Commit a151f7b

Browse files
authored
Merge pull request #333 from BigVan/main
[feat.] Refactor Attach/Detach functions from private to public.
2 parents f2f7b53 + f4ff1a0 commit a151f7b

File tree

2 files changed

+233
-175
lines changed

2 files changed

+233
-175
lines changed

pkg/snapshot/overlay.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
502502
downloadBlob := info.Labels[label.DownloadRemoteBlob]
503503
if downloadBlob == "download" && stype == storageTypeRemoteBlock {
504504
log.G(ctx).Infof("download blob %s", targetRef)
505-
if err := o.constructOverlayBDSpec(ctx, key, false); err != nil {
505+
if err := o.ConstructOverlayBDSpec(ctx, key, false); err != nil {
506506
return nil, err
507507
}
508508
rollback = false
@@ -531,7 +531,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
531531
return nil, err
532532
}
533533

534-
if err := o.constructOverlayBDSpec(ctx, targetRef, false); err != nil {
534+
if err := o.ConstructOverlayBDSpec(ctx, targetRef, false); err != nil {
535535
return nil, err
536536
}
537537

@@ -552,7 +552,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
552552
log.G(ctx).Infof("Preparing rootfs(%s). writeType: %s", s.ID, writeType)
553553
if writeType != RoDir {
554554
stype = storageTypeLocalBlock
555-
if err := o.constructOverlayBDSpec(ctx, key, true); err != nil {
555+
if err := o.ConstructOverlayBDSpec(ctx, key, true); err != nil {
556556
log.G(ctx).Errorln(err.Error())
557557
return nil, err
558558
}
@@ -612,7 +612,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
612612
}
613613
}
614614
log.G(ctx).Debugf("attachAndMountBlockDevice (obdID: %s, writeType: %s, fsType %s, targetPath: %s)",
615-
obdID, writeType, fsType, o.overlaybdTargetPath(obdID))
615+
obdID, writeType, fsType, overlaybdTargetPath(obdHbaNum(o.tenant), obdID))
616616
if err = o.attachAndMountBlockDevice(ctx, obdID, writeType, fsType, parent == ""); err != nil {
617617
log.G(ctx).Errorf("%v", err)
618618
return nil, fmt.Errorf("failed to attach and mount for snapshot %v: %w", obdID, err)
@@ -828,7 +828,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
828828
} else if _, err := o.loadBackingStoreConfig(id); err != nil {
829829
log.G(ctx).Info("not an overlaybd writable layer")
830830
} else {
831-
if err := o.unmountAndDetachBlockDevice(ctx, id, key); err != nil {
831+
if err := o.UnmountAndDetachBlockDevice(ctx, id); err != nil {
832832
return fmt.Errorf("failed to destroy target device for snapshot %s: %w", key, err)
833833
}
834834

@@ -863,7 +863,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
863863
// since there could be multiple fs metadata in a turboOCI layer
864864
if isTurboOCI, digest, _ := o.checkTurboOCI(info.Labels); isTurboOCI {
865865
log.G(ctx).Infof("commit turboOCI.v1 layer: (%s, %s)", id, digest)
866-
if err := o.constructOverlayBDSpec(ctx, name, false); err != nil {
866+
if err := o.ConstructOverlayBDSpec(ctx, name, false); err != nil {
867867
return fmt.Errorf("failed to construct overlaybd config: %w", err)
868868
}
869869
stype = storageTypeNormal
@@ -873,14 +873,14 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
873873
// then change stype to 'storageTypeLocalBlock' which can make it attach a overlaybd block
874874
if stype == storageTypeLocalLayer {
875875
log.G(ctx).Infof("convet a local blob to turboOCI layer (sn: %s)", id)
876-
if err := o.constructOverlayBDSpec(ctx, name, false); err != nil {
876+
if err := o.ConstructOverlayBDSpec(ctx, name, false); err != nil {
877877
return fmt.Errorf("failed to construct overlaybd config: %w", err)
878878
}
879879
stype = storageTypeLocalBlock
880880
}
881881

882882
if stype == storageTypeLocalBlock {
883-
if err := o.constructOverlayBDSpec(ctx, name, false); err != nil {
883+
if err := o.ConstructOverlayBDSpec(ctx, name, false); err != nil {
884884
return fmt.Errorf("failed to construct overlaybd config: %w", err)
885885
}
886886

@@ -1022,7 +1022,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
10221022
if stype != storageTypeNormal {
10231023
_, err = os.Stat(o.overlaybdBackstoreMarkFile(id))
10241024
if err == nil {
1025-
err = o.unmountAndDetachBlockDevice(ctx, id, key)
1025+
err = o.UnmountAndDetachBlockDevice(ctx, id)
10261026
if err != nil {
10271027
return mylog.TracedErrorf(ctx, "failed to destroy target device for snapshot %s: %w", key, err)
10281028
}
@@ -1039,7 +1039,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
10391039

10401040
log.G(ctx).Debugf("try to verify parent snapshots format.")
10411041
if st, err := o.identifySnapshotStorageType(ctx, s.ParentIDs[0], info); err == nil && st != storageTypeNormal {
1042-
err = o.unmountAndDetachBlockDevice(ctx, s.ParentIDs[0], "")
1042+
err = o.UnmountAndDetachBlockDevice(ctx, s.ParentIDs[0])
10431043
if err != nil {
10441044
return mylog.TracedErrorf(ctx, "failed to destroy target device for snapshot %s: %w", key, err)
10451045
}

0 commit comments

Comments
 (0)