difs,interfaces/mount: add support for locking namespaces #3311

Merged
merged 3 commits into from May 15, 2017

Conversation

Projects
None yet
3 participants
Contributor

zyga commented May 12, 2017

This patch adds helpers for working with locks that are also used by
snap-confine. They are used by the update-ns feature.

Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

zyga added some commits Apr 24, 2017

difs,interfaces/mount: add support for locking namespaces
This patch adds helpers for working with locks that are also used by
snap-confine. They are used by the update-ns feature.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/mount: actually there are LOCK_{EX,UN} constants
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
+
+// Close closes the lock, unlocking it automatically if needed.
+func (l *NSLock) Close() error {
+ return l.file.Close()
@morphis

morphis May 15, 2017

Contributor

Worth to check if the file is really open and return an error if it is not? If l.file is nil then this will result in a SEGV.

@zyga

zyga May 15, 2017

Contributor

l.file can never be nil because only OpenFile can create an instance of l and it checks for errors already.

@morphis

morphis May 15, 2017

Contributor

Very much depends on the OpenFile implementation. Feel better when we check l.file as well. But fine if you don't want that. Didn't blocked because of this.

@zyga

zyga May 15, 2017

Contributor

I didn't do it because we don't have a habit of checking object fields for being nil unless they can reasonably be nil as a normal case.

+
+// Lock acquires an exclusive lock on the mount namespace.
+func (l *NSLock) Lock() error {
+ return syscall.Flock(int(l.file.Fd()), syscall.LOCK_EX)
@morphis

morphis May 15, 2017

Contributor

Check l.file for not being nil

+
+// Unlock releases an acquired lock.
+func (l *NSLock) Unlock() error {
+ return syscall.Flock(int(l.file.Fd()), syscall.LOCK_UN)
@morphis

morphis May 15, 2017

Contributor

Check l.file for not being nil

@zyga zyga merged commit 3348589 into snapcore:master May 15, 2017

7 checks passed

artful-amd64 autopkgtest finished (success)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-i386 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details

@zyga zyga deleted the zyga:feature/update-ns/locking branch May 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment