aboutsummaryrefslogtreecommitdiff
path: root/brillo
diff options
context:
space:
mode:
authorBetul Soysal <betuls@google.com>2020-04-22 01:00:37 -0700
committerCommit Bot <commit-bot@chromium.org>2020-05-10 09:26:29 +0000
commit1bd717fc5bc5f50d6bb890616eb13b7557055416 (patch)
tree1c075f705b8e156e070ce519ff55a9dab70aef20 /brillo
parent1cc5ffb1e5e45518f4442c72acf067a7a2ed361d (diff)
downloadlibbrillo-1bd717fc5bc5f50d6bb890616eb13b7557055416.tar.gz
libbrillo: Add MountNamespaceInterface and UnownedMountNamespace
Add the interface class MountNamespaceInterface and the UnownedMountNamespace class which only has one method to return the namespace path. Only one process should have the ability to create MountNamespace at a given path. However more than one processes need to enter this namespace. Thus the path of the namespace is needed by multiple independent packages. The interface class is created for this need. BUG=chromium:1052197 TEST=FEATURES=test emerge-betty libbrillo Change-Id: I9892da25c5ff9614bc3574e9f7e589fa059f81c6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2160141 Tested-by: Betul Soysal <betuls@google.com> Commit-Queue: Betul Soysal <betuls@google.com> Reviewed-by: Mike Frysinger <vapier@chromium.org> Cr-Mirrored-From: https://chromium.googlesource.com/chromiumos/platform2 Cr-Mirrored-Commit: f8c0d1f43c844ac26f655d3724780c1022fbb4be
Diffstat (limited to 'brillo')
-rw-r--r--brillo/namespaces/mount_namespace.h33
1 files changed, 30 insertions, 3 deletions
diff --git a/brillo/namespaces/mount_namespace.h b/brillo/namespaces/mount_namespace.h
index 76ed07b..bfadff0 100644
--- a/brillo/namespaces/mount_namespace.h
+++ b/brillo/namespaces/mount_namespace.h
@@ -13,7 +13,34 @@
namespace brillo {
-class BRILLO_EXPORT MountNamespace {
+class BRILLO_EXPORT MountNamespaceInterface {
+ // An interface declaring the basic functionality of a mount namespace bound
+ // to a specific path. This basic functionality consists of reporting the
+ // namespace path.
+ public:
+ virtual ~MountNamespaceInterface() = default;
+
+ virtual const base::FilePath& path() const = 0;
+};
+
+class BRILLO_EXPORT UnownedMountNamespace : public MountNamespaceInterface {
+ // A class to store and retrieve the path of a persistent namespace. This
+ // class doesn't create nor destroy the namespace.
+ public:
+ explicit UnownedMountNamespace(const base::FilePath& ns_path)
+ : ns_path_(ns_path) {}
+
+ ~UnownedMountNamespace() override;
+
+ const base::FilePath& path() const override { return ns_path_; }
+
+ private:
+ base::FilePath ns_path_;
+
+ DISALLOW_COPY_AND_ASSIGN(UnownedMountNamespace);
+};
+
+class BRILLO_EXPORT MountNamespace : public MountNamespaceInterface {
// A class to create a persistent mount namespace bound to a specific path.
// A new mount namespace is unshared from the mount namespace of the calling
// process when Create() is called; the namespace of the calling process
@@ -24,11 +51,11 @@ class BRILLO_EXPORT MountNamespace {
// destroyed when the object goes out of scope.
public:
MountNamespace(const base::FilePath& ns_path, Platform* platform);
- ~MountNamespace();
+ ~MountNamespace() override;
bool Create();
bool Destroy();
- const base::FilePath& path() const { return ns_path_; }
+ const base::FilePath& path() const override { return ns_path_; }
private:
base::FilePath ns_path_;