From 0e4f2108b51bd4927c3e3d92a5f929ee73cdcf93 Mon Sep 17 00:00:00 2001 From: ningmingxiao Date: Wed, 29 May 2024 21:52:58 +0800 Subject: [PATCH] support to syncfs after pull by using diff plugin Signed-off-by: ningmingxiao --- plugins/services/diff/local.go | 11 ++++++++++- plugins/services/diff/service_unix.go | 3 ++- plugins/services/diff/service_windows.go | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/services/diff/local.go b/plugins/services/diff/local.go index d8ad822105ab..64aa5eae1aa3 100644 --- a/plugins/services/diff/local.go +++ b/plugins/services/diff/local.go @@ -42,6 +42,10 @@ type config struct { // correct output, allowing any ordering to be used to prefer // more optimimal implementations. Order []string `toml:"default"` + // sync_fs is an experimental setting. It's to force sync + // filesystem during unpacking to ensure that data integrity. + // It is effective for all containerd client. + SyncFs bool `toml:"sync_fs"` } type differ interface { @@ -62,7 +66,7 @@ func init() { if err != nil { return nil, err } - + syncFs := ic.Config.(*config).SyncFs orderedNames := ic.Config.(*config).Order ordered := make([]differ, len(orderedNames)) for i, n := range orderedNames { @@ -79,6 +83,7 @@ func init() { return &local{ differs: ordered, + syncfs: syncFs, }, nil }, }) @@ -86,6 +91,7 @@ func init() { type local struct { differs []differ + syncfs bool } var _ diffapi.DiffClient = &local{} @@ -106,6 +112,9 @@ func (l *local) Apply(ctx context.Context, er *diffapi.ApplyRequest, _ ...grpc.C } opts = append(opts, diff.WithPayloads(payloads)) } + if l.syncfs { + er.SyncFs = true + } opts = append(opts, diff.WithSyncFs(er.SyncFs)) for _, differ := range l.differs { diff --git a/plugins/services/diff/service_unix.go b/plugins/services/diff/service_unix.go index 51240d282baf..1160b89dba49 100644 --- a/plugins/services/diff/service_unix.go +++ b/plugins/services/diff/service_unix.go @@ -19,5 +19,6 @@ package diff var defaultDifferConfig = &config{ - Order: []string{"walking"}, + Order: []string{"walking"}, + SyncFs: false, } diff --git a/plugins/services/diff/service_windows.go b/plugins/services/diff/service_windows.go index 2d19de093e6c..d6f1e5a1a16a 100644 --- a/plugins/services/diff/service_windows.go +++ b/plugins/services/diff/service_windows.go @@ -17,5 +17,6 @@ package diff var defaultDifferConfig = &config{ - Order: []string{"windows", "windows-lcow"}, + Order: []string{"windows", "windows-lcow"}, + SyncFs: false, }