Skip to content

Commit

Permalink
Merge pull request #197 from HileQAQ/main
Browse files Browse the repository at this point in the history
expose const of writable layer
  • Loading branch information
BigVan committed May 25, 2023
2 parents 6dff475 + c88666c commit ba5a856
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
34 changes: 17 additions & 17 deletions pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const (
)

const (
roDir = "overlayfs" // overlayfs as rootfs. upper + lower (overlaybd)
rwDir = "dir" // mount overlaybd as rootfs
rwDev = "dev" // use overlaybd directly
RoDir = "overlayfs" // overlayfs as rootfs. upper + lower (overlaybd)
RwDir = "dir" // mount overlaybd as rootfs
RwDev = "dev" // use overlaybd directly
)

type BootConfig struct {
Expand Down Expand Up @@ -299,20 +299,20 @@ func (o *snapshotter) getWritableType(ctx context.Context, id string, info snaps
if id != "" {
if _, err := o.loadBackingStoreConfig(id); err != nil {
log.G(ctx).Debugf("[%s] is not an overlaybd image.", id)
return roDir
return RoDir
}
} else {
log.G(ctx).Debugf("empty snID get. It should be an initial layer.")
}
// overlaybd
rwMode := func(m string) string {
if m == "dir" {
return rwDir
return RwDir
}
if m == "dev" {
return rwDev
return RwDev
}
return roDir
return RoDir
}
m, ok := info.Labels[label.SupportReadWriteMode]
if !ok {
Expand Down Expand Up @@ -455,7 +455,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
// If Preparing for rootfs, find metadata from its parent (top layer), launch and mount backstore device.
if _, ok := info.Labels[label.TargetSnapshotRef]; !ok {
log.G(ctx).Infof("Preparing rootfs. writeType: %s", writeType)
if writeType != roDir {
if writeType != RoDir {
stype = storageTypeLocalBlock
if err := o.constructOverlayBDSpec(ctx, key, true); err != nil {
log.G(ctx).Errorln(err.Error())
Expand All @@ -481,7 +481,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
// If parent is already an acceleration layer, there is certainly no need to record trace.
// Just mark this layer to get accelerated (trace replay)
err = o.updateSpec(parentID, true, "")
if writeType != roDir {
if writeType != RoDir {
o.updateSpec(id, true, "")
}
} else if needRecordTrace && recordTracePath != "" {
Expand All @@ -497,7 +497,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,

var obdID string
var obdInfo *snapshots.Info
if writeType != roDir {
if writeType != RoDir {
obdID = id
obdInfo = &info
} else {
Expand All @@ -517,7 +517,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
}

defer func() {
if retErr != nil && writeType == rwDir { // It's unnecessary to umount overlay block device if writeType == writeTypeRawDev
if retErr != nil && writeType == RwDir { // It's unnecessary to umount overlay block device if writeType == writeTypeRawDev
if rerr := mount.Unmount(o.overlaybdMountpoint(obdID), 0); rerr != nil {
log.G(ctx).WithError(rerr).Warnf("failed to umount writable block %s", o.overlaybdMountpoint(obdID))
}
Expand Down Expand Up @@ -621,7 +621,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) (_ []mount.Mount,
}

writeType := o.getWritableType(ctx, s.ID, info)
if writeType != roDir {
if writeType != RoDir {
return o.basedOnBlockDeviceMount(ctx, s, writeType)
}

Expand All @@ -640,10 +640,10 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) (_ []mount.Mount,
if !ok {
fsType = "ext4"
}
if err := o.attachAndMountBlockDevice(ctx, parentID, roDir, fsType, false); err != nil {
if err := o.attachAndMountBlockDevice(ctx, parentID, RoDir, fsType, false); err != nil {
return nil, errors.Wrapf(err, "failed to attach and mount for snapshot %v", key)
}
return o.basedOnBlockDeviceMount(ctx, s, roDir)
return o.basedOnBlockDeviceMount(ctx, s, RoDir)
}
}
return o.normalOverlayMount(s), nil
Expand Down Expand Up @@ -889,11 +889,11 @@ func (o *snapshotter) basedOnBlockDeviceMount(ctx context.Context, s storage.Sna
}
}()
rwflag := "rw"
if s.Kind == snapshots.KindView && (writeType == rwflag || writeType == rwDev) {
if s.Kind == snapshots.KindView && (writeType == rwflag || writeType == RwDev) {
log.G(ctx).Infof("snapshot.Kind == View, reset overlaybd as READ-ONLY.")
rwflag = "ro"
}
if writeType == rwDir {
if writeType == RwDir {
return []mount.Mount{
{
Source: o.overlaybdMountpoint(s.ID),
Expand All @@ -905,7 +905,7 @@ func (o *snapshotter) basedOnBlockDeviceMount(ctx context.Context, s storage.Sna
},
}, nil
}
if writeType == rwDev {
if writeType == RwDev {
devName, err := os.ReadFile(o.overlaybdBackstoreMarkFile(s.ID))
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (o *snapshotter) unmountAndDetachBlockDevice(ctx context.Context, snID stri
if err != nil {
log.G(ctx).Errorf("read device name failed: %s, err: %v", o.overlaybdBackstoreMarkFile(snID), err)
}
if writeType != rwDev {
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)
Expand Down Expand Up @@ -394,7 +394,7 @@ func (o *snapshotter) attachAndMountBlockDevice(ctx context.Context, snID string
}

var mflag uintptr = unix.MS_RDONLY
if writable != roDir {
if writable != RoDir {
mflag = 0
}

Expand Down Expand Up @@ -426,7 +426,7 @@ func (o *snapshotter) attachAndMountBlockDevice(ctx context.Context, snID string
}
}

if writable != rwDev {
if writable != RwDev {
if fstype != "ntfs" {
log.G(ctx).Infof("fs type: %s, mount options: %s, rw: %s", fstype, data, writable)
//if err := unix.Mount(device, mountPoint, "ext4", mflag, "discard"); err != nil {
Expand All @@ -444,7 +444,7 @@ func (o *snapshotter) attachAndMountBlockDevice(ctx context.Context, snID string
}
} else {
args := []string{"-t", fstype}
if writable == roDir {
if writable == RoDir {
args = append(args, "-r")
}
if data != "" {
Expand Down

0 comments on commit ba5a856

Please sign in to comment.