7777 metricsCtr * layermetrics.Controller
7878)
7979
80+ func applyDefaults (cfg * config.Config ) {
81+ if cfg .MaxConcurrency == 0 {
82+ cfg .MaxConcurrency = defaultMaxConcurrency
83+ }
84+ if cfg .AttrTimeout == 0 {
85+ cfg .AttrTimeout = int64 (defaultFuseTimeout .Seconds ())
86+ }
87+ if cfg .EntryTimeout == 0 {
88+ cfg .EntryTimeout = int64 (defaultFuseTimeout .Seconds ())
89+ }
90+ }
91+
8092type Option func (* options )
8193
8294type options struct {
@@ -132,20 +144,11 @@ func NewFilesystem(root string, cfg config.Config, opts ...Option) (_ snapshot.F
132144 for _ , o := range opts {
133145 o (& fsOpts )
134146 }
135- maxConcurrency := cfg .MaxConcurrency
136- if maxConcurrency == 0 {
137- maxConcurrency = defaultMaxConcurrency
138- }
147+ applyDefaults (& cfg )
139148
149+ maxConcurrency := cfg .MaxConcurrency
140150 attrTimeout := time .Duration (cfg .AttrTimeout ) * time .Second
141- if attrTimeout == 0 {
142- attrTimeout = defaultFuseTimeout
143- }
144-
145151 entryTimeout := time .Duration (cfg .EntryTimeout ) * time .Second
146- if entryTimeout == 0 {
147- entryTimeout = defaultFuseTimeout
148- }
149152
150153 metadataStore := fsOpts .metadataStore
151154 if metadataStore == nil {
@@ -205,6 +208,7 @@ type filesystem struct {
205208 debug bool
206209 layer map [string ]layer.Layer
207210 layerMu sync.Mutex
211+ configMu sync.RWMutex
208212 backgroundTaskManager * task.BackgroundTaskManager
209213 allowNoVerification bool
210214 disableVerification bool
@@ -214,6 +218,23 @@ type filesystem struct {
214218 entryTimeout time.Duration
215219}
216220
221+ func (fs * filesystem ) UpdateConfig (ctx context.Context , cfg config.Config ) error {
222+ applyDefaults (& cfg )
223+ fs .configMu .Lock ()
224+ fs .prefetchSize = cfg .PrefetchSize
225+ fs .noprefetch = cfg .NoPrefetch
226+ fs .noBackgroundFetch = cfg .NoBackgroundFetch
227+ fs .debug = cfg .Debug
228+ fs .allowNoVerification = cfg .AllowNoVerification
229+ fs .disableVerification = cfg .DisableVerification
230+ fs .attrTimeout = time .Duration (cfg .AttrTimeout ) * time .Second
231+ fs .entryTimeout = time .Duration (cfg .EntryTimeout ) * time .Second
232+ fs .configMu .Unlock ()
233+
234+ fs .resolver .UpdateConfig (ctx , cfg )
235+ return nil
236+ }
237+
217238func (fs * filesystem ) Mount (ctx context.Context , mountpoint string , labels map [string ]string ) (retErr error ) {
218239 // Setting the start time to measure the Mount operation duration.
219240 start := time .Now ()
@@ -233,7 +254,9 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
233254 return fmt .Errorf ("source must be passed" )
234255 }
235256
257+ fs .configMu .RLock ()
236258 defaultPrefetchSize := fs .prefetchSize
259+ fs .configMu .RUnlock ()
237260 if psStr , ok := labels [config .TargetPrefetchSizeLabel ]; ok {
238261 if ps , err := strconv .ParseInt (psStr , 10 , 64 ); err == nil {
239262 defaultPrefetchSize = ps
@@ -297,7 +320,15 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
297320 }()
298321
299322 // Verify layer's content
300- if fs .disableVerification {
323+ fs .configMu .RLock ()
324+ disableVerification := fs .disableVerification
325+ allowNoVerification := fs .allowNoVerification
326+ attrTimeout := fs .attrTimeout
327+ entryTimeout := fs .entryTimeout
328+ debug := fs .debug
329+ fs .configMu .RUnlock ()
330+
331+ if disableVerification {
301332 // Skip if verification is disabled completely
302333 l .SkipVerify ()
303334 log .G (ctx ).Infof ("Verification forcefully skipped" )
@@ -313,7 +344,7 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
313344 return fmt .Errorf ("invalid stargz layer: %w" , err )
314345 }
315346 log .G (ctx ).Debugf ("verified" )
316- } else if _ , ok := labels [config .TargetSkipVerifyLabel ]; ok && fs . allowNoVerification {
347+ } else if _ , ok := labels [config .TargetSkipVerifyLabel ]; ok && allowNoVerification {
317348 // If unverified layer is allowed, use it with warning.
318349 // This mode is for legacy stargz archives which don't contain digests
319350 // necessary for layer verification.
@@ -342,14 +373,14 @@ func (fs *filesystem) Mount(ctx context.Context, mountpoint string, labels map[s
342373 // mount the node to the specified mountpoint
343374 // TODO: bind mount the state directory as a read-only fs on snapshotter's side
344375 rawFS := fusefs .NewNodeFS (node , & fusefs.Options {
345- AttrTimeout : & fs . attrTimeout ,
346- EntryTimeout : & fs . entryTimeout ,
376+ AttrTimeout : & attrTimeout ,
377+ EntryTimeout : & entryTimeout ,
347378 NullPermissions : true ,
348379 })
349380 mountOpts := & fuse.MountOptions {
350381 AllowOther : true , // allow users other than root&mounter to access fs
351382 FsName : "stargz" , // name this filesystem as "stargz"
352- Debug : fs . debug ,
383+ Debug : debug ,
353384 DirectMount : true ,
354385 }
355386 server , err := fuse .NewServer (rawFS , mountpoint , mountOpts )
@@ -391,7 +422,10 @@ func (fs *filesystem) Check(ctx context.Context, mountpoint string, labels map[s
391422 }
392423
393424 // Wait for prefetch compeletion
394- if ! fs .noprefetch {
425+ fs .configMu .RLock ()
426+ noprefetch := fs .noprefetch
427+ fs .configMu .RUnlock ()
428+ if ! noprefetch {
395429 if err := l .WaitForPrefetchCompletion (); err != nil {
396430 log .G (ctx ).WithError (err ).Warn ("failed to sync with prefetch completion" )
397431 }
@@ -473,12 +507,17 @@ func unmount(target string, flags int) error {
473507
474508func (fs * filesystem ) prefetch (ctx context.Context , l layer.Layer , defaultPrefetchSize int64 , start time.Time ) {
475509 // Prefetch a layer. The first Check() for this layer waits for the prefetch completion.
476- if ! fs .noprefetch {
510+ fs .configMu .RLock ()
511+ noprefetch := fs .noprefetch
512+ noBackgroundFetch := fs .noBackgroundFetch
513+ fs .configMu .RUnlock ()
514+
515+ if ! noprefetch {
477516 go l .Prefetch (defaultPrefetchSize )
478517 }
479518
480519 // Fetch whole layer aggressively in background.
481- if ! fs . noBackgroundFetch {
520+ if ! noBackgroundFetch {
482521 go func () {
483522 if err := l .BackgroundFetch (); err == nil {
484523 // write log record for the latency between mount start and last on demand fetch
0 commit comments