Skip to content

Commit

Permalink
Merge pull request #272 from salvete2022/dev_erofs
Browse files Browse the repository at this point in the history
add support for tarerofs for TurboOCI
  • Loading branch information
liulanzheng authored Mar 27, 2024
2 parents e935064 + 00fc151 commit ba8e12d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
10 changes: 7 additions & 3 deletions pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type BootConfig struct {
ExporterConfig metrics.ExporterConfig `json:"exporterConfig"`
WritableLayerType string `json:"writableLayerType"` // append or sparse
MirrorRegistry []Registry `json:"mirrorRegistry"`
DefaultFsType string `json:"defaultFsType"`
}

func DefaultBootConfig() *BootConfig {
Expand All @@ -104,6 +105,7 @@ func DefaultBootConfig() *BootConfig {
},
MirrorRegistry: nil,
WritableLayerType: "append",
DefaultFsType: "ext4",
}
}

Expand Down Expand Up @@ -169,6 +171,7 @@ type snapshotter struct {
autoRemoveDev bool
writableLayerType string
mirrorRegistry []Registry
defaultFsType string

locker *locker.Locker
}
Expand Down Expand Up @@ -220,6 +223,7 @@ func NewSnapshotter(bootConfig *BootConfig, opts ...Opt) (snapshots.Snapshotter,
autoRemoveDev: bootConfig.AutoRemoveDev,
writableLayerType: bootConfig.WritableLayerType,
mirrorRegistry: bootConfig.MirrorRegistry,
defaultFsType: bootConfig.DefaultFsType,
locker: locker.New(),
}, nil
}
Expand Down Expand Up @@ -546,8 +550,8 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
}
fsType, ok := obdInfo.Labels[label.OverlayBDBlobFsType]
if !ok {
log.G(ctx).Warnf("cannot get fs type from label, %v, using ext4", obdInfo.Labels)
fsType = "ext4"
log.G(ctx).Warnf("cannot get fs type from label, %v, using %s", obdInfo.Labels, o.defaultFsType)
fsType = o.defaultFsType
}
log.G(ctx).Debugf("attachAndMountBlockDevice (obdID: %s, writeType: %s, fsType %s, targetPath: %s)",
obdID, writeType, fsType, o.overlaybdTargetPath(obdID))
Expand Down Expand Up @@ -705,7 +709,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) (_ []mount.Mount,
if parentStype == storageTypeRemoteBlock || parentStype == storageTypeLocalBlock {
fsType, ok := parentInfo.Labels[label.OverlayBDBlobFsType]
if !ok {
fsType = "ext4"
fsType = o.defaultFsType
}
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)
Expand Down
34 changes: 23 additions & 11 deletions pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,32 @@ func (o *snapshotter) constructOverlayBDSpec(ctx context.Context, key string, wr
// 1. generate tar meta for oci layer blob
// 2. convert local layer.tarmeta to overlaybd
// 3. create layer's config
log.G(ctx).Infof("generate metadata of layer blob (sn: %s)", id)
if err := utils.GenerateTarMeta(ctx, o.overlaybdOCILayerPath(id), o.overlaybdOCILayerMeta(id)); err != nil {
log.G(ctx).Errorf("generate tar metadata failed. (sn: %s)", id)
return err
}
opt := &utils.ConvertOption{
TarMetaPath: o.overlaybdOCILayerMeta(id),
Workdir: o.convertTempdir(id),
Ext4FSMetaPath: o.magicFilePath(id), // overlaybd.commit
Config: configJSON,
var opt *utils.ConvertOption
rootfs_type := o.defaultFsType
if rootfs_type == "erofs" {
opt = &utils.ConvertOption{
TarMetaPath: o.overlaybdOCILayerPath(id),
Workdir: o.convertTempdir(id),
Ext4FSMetaPath: o.magicFilePath(id), // overlaybd.commit
Config: configJSON,
}
} else {
log.G(ctx).Infof("generate metadata of layer blob (sn: %s)", id)
if err := utils.GenerateTarMeta(ctx, o.overlaybdOCILayerPath(id), o.overlaybdOCILayerMeta(id)); err != nil {
log.G(ctx).Errorf("generate tar metadata failed. (sn: %s)", id)
return err
}

opt = &utils.ConvertOption{
TarMetaPath: o.overlaybdOCILayerMeta(id),
Workdir: o.convertTempdir(id),
Ext4FSMetaPath: o.magicFilePath(id), // overlaybd.commit
Config: configJSON,
}
}
log.G(ctx).Infof("convert layer to turboOCI (sn: %s)", id)

if err := utils.ConvertLayer(ctx, opt); err != nil {
if err := utils.ConvertLayer(ctx, opt, rootfs_type); err != nil {
log.G(ctx).Error(err.Error())
os.RemoveAll(opt.Workdir)
os.Remove(opt.Ext4FSMetaPath)
Expand Down
10 changes: 7 additions & 3 deletions pkg/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func GenerateTarMeta(ctx context.Context, srcTarFile string, dstTarMeta string)
}

// ConvertLayer produce a turbooci layer, target is path of ext4.fs.meta
func ConvertLayer(ctx context.Context, opt *ConvertOption) error {
func ConvertLayer(ctx context.Context, opt *ConvertOption, fs_type string) error {
if opt.Workdir == "" {
opt.Workdir = "tmp_conv"
}
Expand All @@ -199,7 +199,7 @@ func ConvertLayer(ctx context.Context, opt *ConvertOption) error {

// overlaybd-create
args := []string{pathWritableData, pathWritableIndex, "256", "-s", "--turboOCI"}
if len(opt.Config.Lowers) == 0 {
if fs_type != "erofs" && len(opt.Config.Lowers) == 0 {
args = append(args, "--mkfs")
}
if out, err := exec.CommandContext(ctx, obdBinCreate, args...).CombinedOutput(); err != nil {
Expand Down Expand Up @@ -231,9 +231,13 @@ func ConvertLayer(ctx context.Context, opt *ConvertOption) error {
}
args = []string{
opt.TarMetaPath, pathConfig,
"--import",
"--service_config_path", pathService,
"--fstype", fs_type,
}
if fs_type != "erofs" {
args = append(args, "--import")
}

log.G(ctx).Debugf("%s %s", obdBinTurboOCIApply, strings.Join(args, " "))
if out, err := exec.CommandContext(ctx, obdBinTurboOCIApply,
args...,
Expand Down

0 comments on commit ba8e12d

Please sign in to comment.