From 2ffc28e0e49f59f455f6fc82d6665d842ed916b4 Mon Sep 17 00:00:00 2001 From: "zhuangbowei.zbw" Date: Thu, 13 Jun 2024 17:49:01 +0800 Subject: [PATCH] convertor: option to disable sparse file Signed-off-by: zhuangbowei.zbw --- .github/workflows/ci-basic.yml | 6 ++++-- cmd/convertor/builder/builder.go | 4 ++++ cmd/convertor/builder/overlaybd_builder.go | 4 ++++ cmd/convertor/main.go | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-basic.yml b/.github/workflows/ci-basic.yml index c3cff0e3..7cb1c9a6 100644 --- a/.github/workflows/ci-basic.yml +++ b/.github/workflows/ci-basic.yml @@ -78,6 +78,7 @@ jobs: - name: CI - record trace shell: bash run: | + set -x /opt/overlaybd/snapshotter/ctr rpull registry.hub.docker.com/overlaybd/redis:6.2.1_obdconv echo "[ by record-trace ]" /opt/overlaybd/snapshotter/ctr record-trace --runtime "io.containerd.runc.v2" --disable-network-isolation --time 15 registry.hub.docker.com/overlaybd/redis:6.2.1_obdconv registry.hub.docker.com/overlaybd/redis:6.2.1_obdconv_trace @@ -85,8 +86,9 @@ jobs: echo "[ by label ]" touch /tmp/trace_file ctr run -d --snapshotter=overlaybd --snapshotter-label containerd.io/snapshot/overlaybd/record-trace=yes --snapshotter-label containerd.io/snapshot/overlaybd/record-trace-path=/tmp/trace_file registry.hub.docker.com/overlaybd/redis:6.2.1_obdconv demo - sleep 1s - ls -l /tmp/ | grep trace_file.lock + sleep 10s + ls -l /tmp/ + # ls -l /tmp/ | grep trace_file.lock sleep 15s ctr t ls | grep demo ctr t kill -s 9 demo && sleep 5s && ctr t ls diff --git a/cmd/convertor/builder/builder.go b/cmd/convertor/builder/builder.go index 6dd76009..932296f8 100644 --- a/cmd/convertor/builder/builder.go +++ b/cmd/convertor/builder/builder.go @@ -66,6 +66,9 @@ type BuilderOptions struct { // ConcurrencyLimit limits the number of manifests that can be built at once // 0 means no limit ConcurrencyLimit int + + // disable sparse file when converting overlaybd + DisableSparse bool } type graphBuilder struct { @@ -248,6 +251,7 @@ func (b *graphBuilder) buildOne(ctx context.Context, src v1.Descriptor, tag bool switch b.Engine { case Overlaybd: engine = NewOverlayBDBuilderEngine(engineBase) + engine.(*overlaybdBuilderEngine).disableSparse = b.DisableSparse case TurboOCI: engine = NewTurboOCIBuilderEngine(engineBase) } diff --git a/cmd/convertor/builder/overlaybd_builder.go b/cmd/convertor/builder/overlaybd_builder.go index 09a8c4f1..7d395124 100644 --- a/cmd/convertor/builder/overlaybd_builder.go +++ b/cmd/convertor/builder/overlaybd_builder.go @@ -51,6 +51,7 @@ type overlaybdConvertResult struct { type overlaybdBuilderEngine struct { *builderEngineBase + disableSparse bool overlaybdConfig *sn.OverlayBDBSConfig overlaybdLayers []overlaybdConvertResult } @@ -428,6 +429,9 @@ func (e *overlaybdBuilderEngine) getLayerDir(idx int) string { func (e *overlaybdBuilderEngine) create(ctx context.Context, dir string, mkfs bool, vsizeGB int) error { opts := []string{"-s", fmt.Sprintf("%d", vsizeGB)} + if !e.disableSparse { + opts = append(opts, "-s") + } if mkfs { opts = append(opts, "--mkfs") logrus.Infof("mkfs for baselayer, vsize: %d GB", vsizeGB) diff --git a/cmd/convertor/main.go b/cmd/convertor/main.go index b2e47962..9b9bdafc 100644 --- a/cmd/convertor/main.go +++ b/cmd/convertor/main.go @@ -48,6 +48,7 @@ var ( dbstr string dbType string concurrencyLimit int + disableSparse bool // certification certDirs []string @@ -104,6 +105,7 @@ Version: ` + commitID, NoUpload: noUpload, DumpManifest: dumpManifest, ConcurrencyLimit: concurrencyLimit, + DisableSparse: disableSparse, } if overlaybd != "" { logrus.Info("building [Overlaybd - Native] image...") @@ -165,6 +167,7 @@ func init() { rootCmd.Flags().StringVar(&dbstr, "db-str", "", "db str for overlaybd conversion") rootCmd.Flags().StringVar(&dbType, "db-type", "", "type of db to use for conversion deduplication. Available: mysql. Default none") rootCmd.Flags().IntVar(&concurrencyLimit, "concurrency-limit", 4, "the number of manifests that can be built at the same time, used for multi-arch images, 0 means no limit") + rootCmd.Flags().BoolVar(&disableSparse, "disable-sparse", false, "disable sparse file for overlaybd") // certification rootCmd.Flags().StringArrayVar(&certDirs, "cert-dir", nil, "In these directories, root CA should be named as *.crt and client cert should be named as *.cert, *.key")