-
Notifications
You must be signed in to change notification settings - Fork 55
/
fs.go
620 lines (547 loc) · 20.9 KB
/
fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*
Copyright The Soci Snapshotter Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Copyright 2019 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the NOTICE.md file.
*/
//
// Implementation of FileSystem of SOCI snapshotter
//
package fs
import (
"context"
"fmt"
golog "log"
"os/exec"
"sync"
"syscall"
"time"
"github.com/awslabs/soci-snapshotter/config"
bf "github.com/awslabs/soci-snapshotter/fs/backgroundfetcher"
"github.com/awslabs/soci-snapshotter/fs/layer"
commonmetrics "github.com/awslabs/soci-snapshotter/fs/metrics/common"
layermetrics "github.com/awslabs/soci-snapshotter/fs/metrics/layer"
"github.com/awslabs/soci-snapshotter/fs/remote"
"github.com/awslabs/soci-snapshotter/fs/source"
"github.com/awslabs/soci-snapshotter/metadata"
"github.com/awslabs/soci-snapshotter/snapshot"
"github.com/awslabs/soci-snapshotter/soci"
"github.com/awslabs/soci-snapshotter/soci/store"
"github.com/containerd/containerd/mount"
ctdsnapshotters "github.com/containerd/containerd/pkg/snapshotters"
"github.com/containerd/containerd/reference"
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/log"
metrics "github.com/docker/go-metrics"
fusefs "github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
)
var (
defaultIndexSelectionPolicy = SelectFirstPolicy
fusermountBin = "fusermount"
)
type Option func(*options)
type options struct {
getSources source.GetSources
resolveHandlers map[string]remote.Handler
metadataStore metadata.Store
overlayOpaqueType layer.OverlayOpaqueType
}
func WithGetSources(s source.GetSources) Option {
return func(opts *options) {
opts.getSources = s
}
}
func WithResolveHandler(name string, handler remote.Handler) Option {
return func(opts *options) {
if opts.resolveHandlers == nil {
opts.resolveHandlers = make(map[string]remote.Handler)
}
opts.resolveHandlers[name] = handler
}
}
func WithMetadataStore(metadataStore metadata.Store) Option {
return func(opts *options) {
opts.metadataStore = metadataStore
}
}
func WithOverlayOpaqueType(overlayOpaqueType layer.OverlayOpaqueType) Option {
return func(opts *options) {
opts.overlayOpaqueType = overlayOpaqueType
}
}
func NewFilesystem(ctx context.Context, root string, cfg config.FSConfig, opts ...Option) (_ snapshot.FileSystem, err error) {
var fsOpts options
for _, o := range opts {
o(&fsOpts)
}
var (
mountTimeout = time.Duration(cfg.MountTimeoutSec) * time.Second
fuseMetricsEmitWaitDuration = time.Duration(cfg.FuseMetricsEmitWaitDurationSec) * time.Second
attrTimeout = time.Duration(cfg.FuseConfig.AttrTimeout) * time.Second
entryTimeout = time.Duration(cfg.FuseConfig.EntryTimeout) * time.Second
negativeTimeout = time.Duration(cfg.FuseConfig.NegativeTimeout) * time.Second
bgFetchPeriod = time.Duration(cfg.BackgroundFetchConfig.FetchPeriodMsec) * time.Millisecond
bgSilencePeriod = time.Duration(cfg.BackgroundFetchConfig.SilencePeriodMsec) * time.Millisecond
bgEmitMetricPeriod = time.Duration(cfg.BackgroundFetchConfig.EmitMetricPeriodSec) * time.Second
bgMaxQueueSize = cfg.BackgroundFetchConfig.MaxQueueSize
)
metadataStore := fsOpts.metadataStore
getSources := fsOpts.getSources
if getSources == nil {
getSources = source.FromDefaultLabels(func(refspec reference.Spec) (hosts []docker.RegistryHost, _ error) {
return docker.ConfigureDefaultRegistries(docker.WithPlainHTTP(docker.MatchLocalhost))(refspec.Hostname())
})
}
ctx, store, err := store.NewContentStore(ctx, store.WithType(store.ContentStoreType(cfg.ContentStoreConfig.Type)), store.WithNamespace(cfg.ContentStoreConfig.Namespace))
if err != nil {
return nil, fmt.Errorf("cannot create content store: %w", err)
}
var bgFetcher *bf.BackgroundFetcher
if !cfg.BackgroundFetchConfig.Disable {
log.G(context.Background()).WithFields(logrus.Fields{
"fetchPeriod": bgFetchPeriod,
"silencePeriod": bgSilencePeriod,
"maxQueueSize": bgMaxQueueSize,
"emitMetricPeriod": bgEmitMetricPeriod,
}).Info("constructing background fetcher")
bgFetcher, err = bf.NewBackgroundFetcher(bf.WithFetchPeriod(bgFetchPeriod),
bf.WithSilencePeriod(bgSilencePeriod),
bf.WithMaxQueueSize(bgMaxQueueSize),
bf.WithEmitMetricPeriod(bgEmitMetricPeriod))
if err != nil {
return nil, fmt.Errorf("cannot create background fetcher: %w", err)
}
go bgFetcher.Run(context.Background())
} else {
log.G(context.Background()).Info("background fetch is disabled")
}
r, err := layer.NewResolver(root, cfg, fsOpts.resolveHandlers, metadataStore, store, fsOpts.overlayOpaqueType, bgFetcher)
if err != nil {
return nil, fmt.Errorf("failed to setup resolver: %w", err)
}
var ns *metrics.Namespace
if !cfg.NoPrometheus {
ns = metrics.NewNamespace("soci", "fs", nil)
commonmetrics.Register() // Register common metrics. This will happen only once.
}
c := layermetrics.NewLayerMetrics(ns)
if ns != nil {
metrics.Register(ns) // Register layer metrics.
}
go commonmetrics.ListenForFuseFailure(ctx)
return &filesystem{
// it's generally considered bad practice to store a context in a struct,
// however `filesystem` has it's own lifecycle as well as a per-request lifecycle.
// Some operations (e.g. remote calls) exist within a per-request lifecycle and use
// the context passed to the specific function, but some operations (e.g. fuse operation counts)
// are tied to the lifecycle of the filesystem itself. In order to avoid leaking goroutines,
// we store the snapshotter's lifecycle in the struct itself so that we can tie new goroutines
// to it later.
ctx: ctx,
resolver: r,
getSources: getSources,
debug: cfg.Debug,
layer: make(map[string]layer.Layer),
allowNoVerification: cfg.AllowNoVerification,
disableVerification: cfg.DisableVerification,
metricsController: c,
attrTimeout: attrTimeout,
entryTimeout: entryTimeout,
negativeTimeout: negativeTimeout,
httpConfig: cfg.RetryableHTTPClientConfig,
contentStore: store,
bgFetcher: bgFetcher,
mountTimeout: mountTimeout,
fuseMetricsEmitWaitDuration: fuseMetricsEmitWaitDuration,
}, nil
}
type sociContext struct {
cachedErr error
cachedErrMu sync.RWMutex
bgFetchPauseOnce sync.Once
fetchOnce sync.Once
sociIndex *soci.Index
imageLayerToSociDesc map[string]ocispec.Descriptor
fuseOperationCounter *layer.FuseOperationCounter
}
func (c *sociContext) Init(fsCtx context.Context, ctx context.Context, imageRef, indexDigest, imageManifestDigest string, store store.Store, fuseOpEmitWaitDuration time.Duration, httpConfig config.RetryableHTTPClientConfig) error {
var retErr error
c.fetchOnce.Do(func() {
defer func() {
if retErr != nil {
c.cachedErrMu.Lock()
c.cachedErr = retErr
c.cachedErrMu.Unlock()
}
}()
refspec, err := reference.Parse(imageRef)
if err != nil {
retErr = err
return
}
remoteStore, err := newRemoteStore(refspec, httpConfig)
if err != nil {
retErr = err
return
}
client := NewOCIArtifactClient(remoteStore)
indexDesc := ocispec.Descriptor{
Digest: digest.Digest(indexDigest),
}
if indexDigest == "" {
log.G(ctx).Info("index digest not provided, making a Referrers API call to fetch list of indices")
imgDigest, err := digest.Parse(imageManifestDigest)
if err != nil {
retErr = fmt.Errorf("unable to parse image digest: %w", err)
}
desc, err := client.SelectReferrer(ctx, ocispec.Descriptor{Digest: imgDigest}, defaultIndexSelectionPolicy)
if err != nil {
retErr = fmt.Errorf("cannot fetch list of referrers: %w", err)
return
}
indexDesc = desc
}
log.G(ctx).WithField("digest", indexDesc.Digest.String()).Infof("fetching SOCI artifacts using index descriptor")
index, err := FetchSociArtifacts(fsCtx, refspec, indexDesc, store, remoteStore)
if err != nil {
retErr = fmt.Errorf("error trying to fetch SOCI artifacts: %w", err)
return
}
c.sociIndex = index
c.populateImageLayerToSociMapping(index)
// Create the FUSE operation counter.
// Metrics are emitted after a wait time of fuseOpEmitWaitDuration.
c.fuseOperationCounter = layer.NewFuseOperationCounter(digest.Digest(imageManifestDigest), fuseOpEmitWaitDuration)
go c.fuseOperationCounter.Run(fsCtx)
})
c.cachedErrMu.RLock()
retErr = c.cachedErr
c.cachedErrMu.RUnlock()
return retErr
}
func (c *sociContext) populateImageLayerToSociMapping(sociIndex *soci.Index) {
c.imageLayerToSociDesc = make(map[string]ocispec.Descriptor, len(sociIndex.Blobs))
for _, desc := range sociIndex.Blobs {
ociDigest := desc.Annotations[soci.IndexAnnotationImageLayerDigest]
c.imageLayerToSociDesc[ociDigest] = desc
}
}
type filesystem struct {
ctx context.Context
resolver *layer.Resolver
debug bool
layer map[string]layer.Layer
layerMu sync.Mutex
allowNoVerification bool
disableVerification bool
getSources source.GetSources
metricsController *layermetrics.Controller
attrTimeout time.Duration
entryTimeout time.Duration
negativeTimeout time.Duration
httpConfig config.RetryableHTTPClientConfig
sociContexts sync.Map
contentStore store.Store
bgFetcher *bf.BackgroundFetcher
mountTimeout time.Duration
fuseMetricsEmitWaitDuration time.Duration
}
func (fs *filesystem) MountLocal(ctx context.Context, mountpoint string, labels map[string]string, mounts []mount.Mount) error {
imageRef, ok := labels[ctdsnapshotters.TargetRefLabel]
if !ok {
return fmt.Errorf("unable to get image ref from labels")
}
// Get source information of this layer.
src, err := fs.getSources(labels)
if err != nil {
return err
} else if len(src) == 0 {
return fmt.Errorf("blob info not found for any labels in %s", fmt.Sprint(labels))
}
// download the target layer
s := src[0]
archive := NewLayerArchive()
refspec, err := reference.Parse(imageRef)
if err != nil {
return fmt.Errorf("cannot parse image ref (%s): %w", imageRef, err)
}
remoteStore, err := newRemoteStore(refspec, fs.httpConfig)
if err != nil {
return fmt.Errorf("cannot create remote store: %w", err)
}
fetcher, err := newArtifactFetcher(refspec, fs.contentStore, remoteStore)
if err != nil {
return fmt.Errorf("cannot create fetcher: %w", err)
}
unpacker := NewLayerUnpacker(fetcher, archive)
desc := s.Target
err = unpacker.Unpack(ctx, desc, mountpoint, mounts)
if err != nil {
return fmt.Errorf("cannot unpack the layer: %w", err)
}
return nil
}
func (fs *filesystem) getSociContext(ctx context.Context, imageRef, indexDigest, imageManifestDigest string) (*sociContext, error) {
cAny, _ := fs.sociContexts.LoadOrStore(imageManifestDigest, &sociContext{})
c, ok := cAny.(*sociContext)
if !ok {
return nil, fmt.Errorf("could not load index: fs soci context is invalid type for %s", indexDigest)
}
err := c.Init(fs.ctx, ctx, imageRef, indexDigest, imageManifestDigest, fs.contentStore, fs.fuseMetricsEmitWaitDuration, fs.httpConfig)
return c, err
}
func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[string]string) (retErr error) {
// Setting the start time to measure the Mount operation duration.
start := time.Now()
ctx = log.WithLogger(ctx, log.G(ctx).WithField("mountpoint", mountpoint))
// If this is empty or the label doesn't exist, then we will use the referrers API later
// to get find an index digest.
sociIndexDigest := labels[source.TargetSociIndexDigestLabel]
imageRef, ok := labels[ctdsnapshotters.TargetRefLabel]
if !ok {
return fmt.Errorf("unable to get image ref from labels")
}
imgDigest, ok := labels[ctdsnapshotters.TargetManifestDigestLabel]
if !ok {
return fmt.Errorf("unable to get image digest from labels")
}
c, err := fs.getSociContext(ctx, imageRef, sociIndexDigest, imgDigest)
if err != nil {
return fmt.Errorf("unable to fetch SOCI artifacts: %w", err)
}
// Get source information of this layer.
src, err := fs.getSources(labels)
if err != nil {
return err
} else if len(src) == 0 {
return fmt.Errorf("source must be passed")
}
// Resolve the target layer
var (
resultChan = make(chan layer.Layer)
errChan = make(chan error)
)
go func() {
var rErr error
for _, s := range src {
sociDesc, ok := c.imageLayerToSociDesc[s.Target.Digest.String()]
if !ok {
log.G(ctx).WithFields(logrus.Fields{
"layerDigest": s.Target.Digest.String(),
"image": s.Name.String(),
}).Infof("skipping mounting layer as FUSE mount: %v", snapshot.ErrNoZtoc)
rErr = fmt.Errorf("skipping mounting layer %s as FUSE mount: %w", s.Target.Digest.String(), snapshot.ErrNoZtoc)
break
}
l, err := fs.resolver.Resolve(ctx, s.Hosts, s.Name, s.Target, sociDesc, c.fuseOperationCounter, fs.disableVerification)
if err == nil {
resultChan <- l
return
}
rErr = fmt.Errorf("failed to resolve layer %q from %q: %w", s.Target.Digest, s.Name, err)
}
errChan <- rErr
}()
// Also resolve and cache other layers in parallel
preResolve := src[0] // TODO: should we pre-resolve blobs in other sources as well?
for _, desc := range neighboringLayers(preResolve.Manifest, preResolve.Target) {
desc := desc
go func() {
// Avoids to get canceled by client.
ctx := log.WithLogger(context.Background(), log.G(ctx).WithField("mountpoint", mountpoint))
sociDesc, ok := c.imageLayerToSociDesc[desc.Digest.String()]
if !ok {
log.G(ctx).WithError(snapshot.ErrNoZtoc).WithField("layerDigest", desc.Digest.String()).Debug("skipping layer pre-resolve")
return
}
l, err := fs.resolver.Resolve(ctx, preResolve.Hosts, preResolve.Name, desc, sociDesc, c.fuseOperationCounter, fs.disableVerification)
if err != nil {
log.G(ctx).WithError(err).Debug("failed to pre-resolve")
return
}
// Release this layer because this isn't target and we don't use it anymore here.
// However, this will remain on the resolver cache until eviction.
l.Done()
}()
}
// Wait for resolving completion
var l layer.Layer
select {
case l = <-resultChan:
case err := <-errChan:
retErr = err
return
case <-time.After(fs.mountTimeout):
log.G(ctx).WithFields(logrus.Fields{
"timeout": fs.mountTimeout.String(),
"layerDigest": labels[ctdsnapshotters.TargetLayerDigestLabel],
}).Info("timeout waiting for layer to resolve")
retErr = fmt.Errorf("timeout waiting for layer %s to resolve", labels[ctdsnapshotters.TargetLayerDigestLabel])
return
}
defer func() {
if retErr != nil {
l.Done() // don't use this layer.
}
}()
// Verification is needed to instantiate reader
l.SkipVerify()
log.G(ctx).Infof("Verification forcefully skipped")
// Maybe we should reword the log here or remove it entirely,
// since the old Verify() function no longer serves any purpose.
node, err := l.RootNode(0)
if err != nil {
log.G(ctx).WithError(err).Warnf("Failed to get root node")
retErr = fmt.Errorf("failed to get root node: %w", err)
return
}
// Measuring duration of Mount operation for resolved layer.
digest := l.Info().Digest // get layer sha
defer commonmetrics.MeasureLatencyInMilliseconds(commonmetrics.Mount, digest, start)
// Register the mountpoint layer
fs.layerMu.Lock()
fs.layer[mountpoint] = l
fs.layerMu.Unlock()
fs.metricsController.Add(mountpoint, l)
// mount the node to the specified mountpoint
// TODO: bind mount the state directory as a read-only fs on snapshotter's side
rawFS := fusefs.NewNodeFS(node, &fusefs.Options{
AttrTimeout: &fs.attrTimeout,
EntryTimeout: &fs.entryTimeout,
NegativeTimeout: &fs.negativeTimeout,
NullPermissions: true,
})
// Pass in a logger to go-fuse with the layer digest
// The go-fuse logs are useful for tracing exactly what's happening at the fuse level.
logger := log.L.
WithField("layerDigest", labels[ctdsnapshotters.TargetLayerDigestLabel]).
WriterLevel(logrus.TraceLevel)
mountOpts := &fuse.MountOptions{
AllowOther: true, // allow users other than root&mounter to access fs
FsName: "soci", // name this filesystem as "soci"
Debug: fs.debug,
Logger: golog.New(logger, "", 0),
}
if _, err := exec.LookPath(fusermountBin); err == nil {
mountOpts.Options = []string{"suid"} // option for fusermount; allow setuid inside container
} else {
log.G(ctx).WithError(err).Infof("%s not installed; trying direct mount", fusermountBin)
mountOpts.DirectMount = true
}
server, err := fuse.NewServer(rawFS, mountpoint, mountOpts)
if err != nil {
log.G(ctx).WithError(err).Debug("failed to make filesystem server")
retErr = err
return
}
go server.Serve()
// Send a signal to the background fetcher that a new image is being mounted
// and to pause all background fetches.
c.bgFetchPauseOnce.Do(func() {
if fs.bgFetcher != nil {
fs.bgFetcher.Pause()
}
})
return server.WaitMount()
}
func (fs *filesystem) Check(ctx context.Context, mountpoint string, labels map[string]string) error {
ctx = log.WithLogger(ctx, log.G(ctx).WithField("mountpoint", mountpoint))
fs.layerMu.Lock()
l := fs.layer[mountpoint]
fs.layerMu.Unlock()
if l == nil {
log.G(ctx).Debug("layer not registered")
return fmt.Errorf("layer not registered")
}
// Check the blob connectivity and try to refresh the connection on failure
if err := fs.check(ctx, l, labels); err != nil {
log.G(ctx).WithError(err).Warn("check failed")
return err
}
return nil
}
func (fs *filesystem) check(ctx context.Context, l layer.Layer, labels map[string]string) error {
err := l.Check()
if err == nil {
return nil
}
log.G(ctx).WithError(err).Warn("failed to connect to blob")
// Check failed. Try to refresh the connection with fresh source information
src, err := fs.getSources(labels)
if err != nil {
return err
}
var (
retrynum = 1
rErr = fmt.Errorf("failed to refresh connection")
)
for retry := 0; retry < retrynum; retry++ {
log.G(ctx).Warnf("refreshing(%d)...", retry)
for _, s := range src {
err := l.Refresh(ctx, s.Hosts, s.Name, s.Target)
if err == nil {
log.G(ctx).Debug("Successfully refreshed connection")
return nil
}
log.G(ctx).WithError(err).Warnf("failed to refresh the layer %q from %q",
s.Target.Digest, s.Name)
rErr = fmt.Errorf("failed(layer:%q, ref:%q): %v: %w",
s.Target.Digest, s.Name, err, rErr)
}
}
return rErr
}
func (fs *filesystem) Unmount(ctx context.Context, mountpoint string) error {
fs.layerMu.Lock()
l, ok := fs.layer[mountpoint]
if !ok {
fs.layerMu.Unlock()
return fmt.Errorf("specified path %q isn't a mountpoint", mountpoint)
}
delete(fs.layer, mountpoint) // unregisters the corresponding layer
l.Done()
fs.layerMu.Unlock()
fs.metricsController.Remove(mountpoint)
// The goroutine which serving the mountpoint possibly becomes not responding.
// In case of such situations, we use MNT_FORCE here and abort the connection.
// In the future, we might be able to consider to kill that specific hanging
// goroutine using channel, etc.
// See also: https://www.kernel.org/doc/html/latest/filesystems/fuse.html#aborting-a-filesystem-connection
return syscall.Unmount(mountpoint, syscall.MNT_FORCE)
}
// neighboringLayers returns layer descriptors except the `target` layer in the specified manifest.
func neighboringLayers(manifest ocispec.Manifest, target ocispec.Descriptor) (descs []ocispec.Descriptor) {
for _, desc := range manifest.Layers {
if desc.Digest.String() != target.Digest.String() {
descs = append(descs, desc)
}
}
return
}