-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split RW and RO Layer locks per method #473
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -491,7 +491,10 @@ func (r *layerStore) saveMounts() error { | |||||||||||||||||||
return r.loadMounts() | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (s *store) newLayerStore(rundir string, layerdir string, driver drivers.Driver) (LayerStore, error) { | ||||||||||||||||||||
// newLayerStore creates a new layer storage based on the provided directories | ||||||||||||||||||||
// and selected driver. The `withMountsLock` bool indicates if we want to | ||||||||||||||||||||
// enable mount locking, which is necessary to have write access to the storage. | ||||||||||||||||||||
func (s *store) newLayerStore(rundir string, layerdir string, driver drivers.Driver, withMountsLock bool) (LayerStore, error) { | ||||||||||||||||||||
saschagrunert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
if err := os.MkdirAll(rundir, 0700); err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
|
@@ -502,9 +505,12 @@ func (s *store) newLayerStore(rundir string, layerdir string, driver drivers.Dri | |||||||||||||||||||
if err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
mountsLockfile, err := GetLockfile(filepath.Join(rundir, "mountpoints.lock")) | ||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
var mountsLockfile Locker | ||||||||||||||||||||
if withMountsLock { | ||||||||||||||||||||
mountsLockfile, err = GetLockfile(filepath.Join(rundir, "mountpoints.lock")) | ||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
rlstore := layerStore{ | ||||||||||||||||||||
lockfile: lockfile, | ||||||||||||||||||||
|
@@ -524,27 +530,6 @@ func (s *store) newLayerStore(rundir string, layerdir string, driver drivers.Dri | |||||||||||||||||||
return &rlstore, nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func newROLayerStore(rundir string, layerdir string, driver drivers.Driver) (ROLayerStore, error) { | ||||||||||||||||||||
lockfile, err := GetROLockfile(filepath.Join(layerdir, "layers.lock")) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OTOH storage/pkg/lockfile/lockfile.go Lines 92 to 100 in 9f88983
|
||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
rlstore := layerStore{ | ||||||||||||||||||||
lockfile: lockfile, | ||||||||||||||||||||
mountsLockfile: nil, | ||||||||||||||||||||
driver: driver, | ||||||||||||||||||||
rundir: rundir, | ||||||||||||||||||||
layerdir: layerdir, | ||||||||||||||||||||
byid: make(map[string]*Layer), | ||||||||||||||||||||
bymount: make(map[string]*Layer), | ||||||||||||||||||||
byname: make(map[string]*Layer), | ||||||||||||||||||||
} | ||||||||||||||||||||
if err := rlstore.Load(); err != nil { | ||||||||||||||||||||
return nil, err | ||||||||||||||||||||
} | ||||||||||||||||||||
return &rlstore, nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (r *layerStore) lookup(id string) (*Layer, bool) { | ||||||||||||||||||||
if layer, ok := r.byid[id]; ok { | ||||||||||||||||||||
return layer, ok | ||||||||||||||||||||
|
@@ -1470,7 +1455,8 @@ func (r *layerStore) Modified() (bool, error) { | |||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (r *layerStore) IsReadWrite() bool { | ||||||||||||||||||||
return r.lockfile.IsReadWrite() | ||||||||||||||||||||
// the mountsLockfile is only set for read-write enabled stores. | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is preexisting = non-blocking:) This looks like a important invariant; it should be documented with the structure field. |
||||||||||||||||||||
return r.lockfile.IsReadWrite() && r.mountsLockfile != nil | ||||||||||||||||||||
saschagrunert marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (r *layerStore) TouchedSince(when time.Time) bool { | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really
withMountsLock
orreadWrite
? The latter seems semantically more useful, and might e.g. allow skipping theMkdirAll
calls below.