Skip to content

Commit 2a70d12

Browse files
sondavidbaustinvazquez
authored andcommitted
Disable xattrs by default
Change --optimizations xattr to be default behavior, and add a new flag to disable this annotation when creating a SOCI index. This change also eliminated the need for the optimizations structure in the CLI. Signed-off-by: David Son <[email protected]>
1 parent cc90b9b commit 2a70d12

File tree

6 files changed

+47
-59
lines changed

6 files changed

+47
-59
lines changed

cmd/soci/commands/create.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package commands
1818

1919
import (
2020
"errors"
21-
"fmt"
2221
"os"
2322

2423
"github.com/awslabs/soci-snapshotter/cmd/soci/commands/internal"
@@ -32,7 +31,7 @@ const (
3231
buildToolIdentifier = "AWS SOCI CLI v0.1"
3332
spanSizeFlag = "span-size"
3433
minLayerSizeFlag = "min-layer-size"
35-
optimizationFlag = "optimizations"
34+
disableXAttrsFlag = "disable-xattrs"
3635
)
3736

3837
// CreateCommand creates SOCI index for an image
@@ -55,9 +54,9 @@ var CreateCommand = cli.Command{
5554
Usage: "Minimum layer size to build zTOC for. Smaller layers won't have zTOC and not lazy pulled. Default is 10 MiB.",
5655
Value: 10 << 20,
5756
},
58-
cli.StringSliceFlag{
59-
Name: optimizationFlag,
60-
Usage: fmt.Sprintf("(Experimental) Enable optional optimizations. Valid values are %v", soci.Optimizations),
57+
cli.BoolTFlag{
58+
Name: disableXAttrsFlag,
59+
Usage: "When true, adds DisableXAttrs annotation to SOCI index. This annotation often helps performance at pull time. Default is true",
6160
},
6261
),
6362
Action: func(cliContext *cli.Context) error {
@@ -66,15 +65,6 @@ var CreateCommand = cli.Command{
6665
return errors.New("source image needs to be specified")
6766
}
6867

69-
var optimizations []soci.Optimization
70-
for _, o := range cliContext.StringSlice(optimizationFlag) {
71-
optimization, err := soci.ParseOptimization(o)
72-
if err != nil {
73-
return err
74-
}
75-
optimizations = append(optimizations, optimization)
76-
}
77-
7868
client, ctx, cancel, err := internal.NewClient(cliContext)
7969
if err != nil {
8070
return err
@@ -119,7 +109,10 @@ var CreateCommand = cli.Command{
119109
soci.WithMinLayerSize(minLayerSize),
120110
soci.WithSpanSize(spanSize),
121111
soci.WithBuildToolIdentifier(buildToolIdentifier),
122-
soci.WithOptimizations(optimizations),
112+
}
113+
114+
if !cliContext.Bool(disableXAttrsFlag) {
115+
builderOpts = append(builderOpts, soci.WithNoDisableXAttrs())
123116
}
124117

125118
for _, plat := range ps {

config/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ allow_no_verification=true
1919
# disable_verification=false
2020
# Causes TestRunWithDefaultConfig to break, but
2121
# fine to use in /etc/soci-snapshotter-grpc-config.toml
22-
max_concurrency=0 # Actually zero
22+
max_concurrency=0
2323
no_prometheus=false
2424
mount_timeout_sec=0
2525
fuse_metrics_emit_wait_duration_sec=0

docs/cli-usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Flags:
3333

3434
- ```--span-size``` : Span size that soci index uses to segment layer data. Default is 4MiB
3535
- ```--min-layer-size``` : Minimum layer size to build zTOC for. Smaller layers won't have zTOC and not lazy pulled. Default is 10MiB
36+
- ```--disable-xattrs``` : When true, adds DisableXAttrs annotation to SOCI index. This annotation often helps performance at pull time. Default is true.
3637

3738
**Example:**
3839
```

fs/layer/layer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ func (r *Resolver) Resolve(ctx context.Context, hosts []docker.RegistryHost, ref
345345
if err != nil {
346346
return nil, fmt.Errorf("failed to read layer: %w", err)
347347
}
348-
disableXattrs := getDisableXAttrAnnotation(sociDesc)
348+
disableXAttrs := getDisableXAttrAnnotation(sociDesc)
349349
// Combine layer information together and cache it.
350-
l := newLayer(r, desc, blobR, vr, bgLayerResolver, opCounter, disableXattrs)
350+
l := newLayer(r, desc, blobR, vr, bgLayerResolver, opCounter, disableXAttrs)
351351
r.layerCacheMu.Lock()
352352
cachedL, done2, added := r.layerCache.Add(name, l)
353353
r.layerCacheMu.Unlock()
354354
if !added {
355-
l.close() // layer already exists in the cache. discrad this.
355+
l.close() // layer already exists in the cache. discard this.
356356
}
357357

358358
log.G(ctx).Debugf("resolved layer")

soci/soci_index.go

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const (
6868
// [soci-snapshotter] NOTE: this is a duplicate of fs/layer/layer.go so that the SOCI package and the snapshotter can
6969
// be independent (and SOCI could be split out into it's own module in the future).
7070
whiteoutOpaqueDir = ".wh..wh..opq"
71+
disableXAttrsTrue = "true"
7172
)
7273

7374
var (
@@ -215,39 +216,7 @@ type buildConfig struct {
215216
buildToolIdentifier string
216217
artifactsDb *ArtifactsDb
217218
platform ocispec.Platform
218-
optimizations []Optimization
219-
}
220-
221-
func (b *buildConfig) hasOptimization(o Optimization) bool {
222-
for _, optimization := range b.optimizations {
223-
if o == optimization {
224-
return true
225-
}
226-
}
227-
return false
228-
}
229-
230-
// Optimization represents an optional optimization to be applied when building the SOCI index
231-
type Optimization string
232-
233-
const (
234-
// XAttrOptimization optimizes xattrs by disabling them for layers where there are no xattrs or opaque directories
235-
XAttrOptimization Optimization = "xattr"
236-
// Be sure to add any new optimizations to `Optimizations` below
237-
)
238-
239-
// Optimizations contains the list of all known optimizations
240-
var Optimizations = []Optimization{XAttrOptimization}
241-
242-
// ParseOptimization parses a string into a known optimization.
243-
// If the string does not match a known optimization, an error is returned.
244-
func ParseOptimization(s string) (Optimization, error) {
245-
for _, optimization := range Optimizations {
246-
if s == string(optimization) {
247-
return optimization, nil
248-
}
249-
}
250-
return "", fmt.Errorf("optimization %s is not a valid optimization %v", s, Optimizations)
219+
disableXAttrs bool
251220
}
252221

253222
// BuildOption specifies a config change to build soci indices.
@@ -269,10 +238,10 @@ func WithMinLayerSize(minLayerSize int64) BuildOption {
269238
}
270239
}
271240

272-
// WithOptimizations enables optional optimizations when building the SOCI Index (experimental)
273-
func WithOptimizations(optimizations []Optimization) BuildOption {
241+
// WithNoDisableXAttrs will skip checking DisableXAttrs annotation
242+
func WithNoDisableXAttrs() BuildOption {
274243
return func(c *buildConfig) error {
275-
c.optimizations = optimizations
244+
c.disableXAttrs = false
276245
return nil
277246
}
278247
}
@@ -318,6 +287,7 @@ func NewIndexBuilder(contentStore content.Store, blobStore orascontent.Storage,
318287
minLayerSize: defaultMinLayerSize,
319288
buildToolIdentifier: defaultBuildToolIdentifier,
320289
platform: defaultPlatform,
290+
disableXAttrs: true,
321291
}
322292

323293
for _, opt := range opts {
@@ -511,6 +481,9 @@ func (b *IndexBuilder) buildSociLayer(ctx context.Context, desc ocispec.Descript
511481
IndexAnnotationImageLayerDigest: desc.Digest.String(),
512482
}
513483
b.maybeAddDisableXattrAnnotation(&ztocDesc, toc)
484+
if desc.Annotations[IndexAnnotationDisableXAttrs] == disableXAttrsTrue {
485+
log.G(ctx).WithField("layer", ztocDesc.Digest.String()).Debug("xattrs disabled")
486+
}
514487
return &ztocDesc, err
515488
}
516489

@@ -648,11 +621,11 @@ func WriteSociIndex(ctx context.Context, indexWithMetadata *IndexWithMetadata, c
648621
}
649622

650623
func (b *IndexBuilder) maybeAddDisableXattrAnnotation(ztocDesc *ocispec.Descriptor, ztoc *ztoc.Ztoc) {
651-
if b.config.hasOptimization(XAttrOptimization) && shouldDisableXattrs(ztoc) {
624+
if b.config.disableXAttrs && shouldDisableXattrs(ztoc) {
652625
if ztocDesc.Annotations == nil {
653626
ztocDesc.Annotations = make(map[string]string, 1)
654627
}
655-
ztocDesc.Annotations[IndexAnnotationDisableXAttrs] = "true"
628+
ztocDesc.Annotations[IndexAnnotationDisableXAttrs] = disableXAttrsTrue
656629
}
657630
}
658631

soci/soci_index_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func TestDisableXattrs(t *testing.T) {
235235
name string
236236
metadata []ztoc.FileMetadata
237237
shouldDisableXattrs bool
238+
disableXAttrs bool
238239
}{
239240
{
240241
name: "ztoc with xattrs should not have xattrs disabled",
@@ -247,6 +248,7 @@ func TestDisableXattrs(t *testing.T) {
247248
},
248249
},
249250
shouldDisableXattrs: false,
251+
disableXAttrs: true,
250252
},
251253
{
252254
name: "ztoc with opaque dirs should not have xattrs disabled",
@@ -259,6 +261,7 @@ func TestDisableXattrs(t *testing.T) {
259261
},
260262
},
261263
shouldDisableXattrs: false,
264+
disableXAttrs: true,
262265
},
263266
{
264267
name: "ztoc with no xattrs or opaque dirs should have xattrs disabled",
@@ -271,6 +274,20 @@ func TestDisableXattrs(t *testing.T) {
271274
},
272275
},
273276
shouldDisableXattrs: true,
277+
disableXAttrs: true,
278+
},
279+
{
280+
name: "ztoc with no xattrs and forced GetXAttrs should have xattrs enabled",
281+
metadata: []ztoc.FileMetadata{
282+
{
283+
Name: "dir/",
284+
},
285+
{
286+
Name: "dir/file",
287+
},
288+
},
289+
shouldDisableXattrs: false,
290+
disableXAttrs: false,
274291
},
275292
}
276293
for _, tc := range testcases {
@@ -293,9 +310,13 @@ func TestDisableXattrs(t *testing.T) {
293310
if err != nil {
294311
t.Fatalf("can't create a test db")
295312
}
296-
builder, _ := NewIndexBuilder(cs, blobStore, artifactsDb, WithOptimizations([]Optimization{XAttrOptimization}))
313+
opts := []BuildOption{}
314+
if !tc.disableXAttrs {
315+
opts = append(opts, WithNoDisableXAttrs())
316+
}
317+
builder, _ := NewIndexBuilder(cs, blobStore, artifactsDb, opts...)
297318
builder.maybeAddDisableXattrAnnotation(&desc, &ztoc)
298-
disableXattrs := desc.Annotations[IndexAnnotationDisableXAttrs] == "true"
319+
disableXattrs := desc.Annotations[IndexAnnotationDisableXAttrs] == disableXAttrsTrue
299320
if disableXattrs != tc.shouldDisableXattrs {
300321
t.Fatalf("expected xattrs to be disabled = %v, actual = %v", tc.shouldDisableXattrs, disableXattrs)
301322
}

0 commit comments

Comments
 (0)