You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/10/13 05:34:41 UTC
[3/7] mesos git commit: Refactored 'MountInfoTable::read()' into two
separate functions.
Refactored 'MountInfoTable::read()' into two separate functions.
The original function now calls a helper which takes a string
representation of a 'MountInfoTable'. In a subsequent commit we will
use this helper to write more meaningful tests to stress the core
logic of the 'MountInfoTable::read()' functionality.
Review: https://reviews.apache.org/r/52704/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/44c43835
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/44c43835
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/44c43835
Branch: refs/heads/master
Commit: 44c438358def99d16024c1365355f01b80e4f66c
Parents: ccc746a
Author: Kevin Klues <kl...@gmail.com>
Authored: Wed Oct 12 22:34:12 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Oct 12 22:34:12 2016 -0700
----------------------------------------------------------------------
src/linux/fs.cpp | 35 +++++++++++++++++++++--------------
src/linux/fs.hpp | 17 +++++++++++++++++
2 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/44c43835/src/linux/fs.cpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.cpp b/src/linux/fs.cpp
index aeec882..f184d46 100644
--- a/src/linux/fs.cpp
+++ b/src/linux/fs.cpp
@@ -86,24 +86,13 @@ Try<bool> supported(const string& fsname)
return false;
}
-
Try<MountInfoTable> MountInfoTable::read(
- const Option<pid_t>& pid,
+ const string& lines,
bool hierarchicalSort)
{
MountInfoTable table;
- const string path = path::join(
- "/proc",
- (pid.isSome() ? stringify(pid.get()) : "self"),
- "mountinfo");
-
- Try<string> lines = os::read(path);
- if (lines.isError()) {
- return Error("Failed to read mountinfo file: " + lines.error());
- }
-
- foreach (const string& line, strings::tokenize(lines.get(), "\n")) {
+ foreach (const string& line, strings::tokenize(lines, "\n")) {
Try<Entry> parse = MountInfoTable::Entry::parse(line);
if (parse.isError()) {
return Error("Failed to parse entry '" + line + "': " + parse.error());
@@ -140,7 +129,7 @@ Try<MountInfoTable> MountInfoTable::read(
std::function<void(int)> sortFrom = [&](int parentId) {
CHECK(!visitedParents.contains(parentId))
<< "Cycle found in mount table hierarchy at entry"
- << " '" << stringify(parentId) << "': " << std::endl << lines.get();
+ << " '" << stringify(parentId) << "': " << std::endl << lines;
visitedParents.insert(parentId);
@@ -172,6 +161,24 @@ Try<MountInfoTable> MountInfoTable::read(
}
+Try<MountInfoTable> MountInfoTable::read(
+ const Option<pid_t>& pid,
+ bool hierarchicalSort)
+{
+ const string path = path::join(
+ "/proc",
+ (pid.isSome() ? stringify(pid.get()) : "self"),
+ "mountinfo");
+
+ Try<string> lines = os::read(path);
+ if (lines.isError()) {
+ return Error("Failed to read mountinfo file: " + lines.error());
+ }
+
+ return MountInfoTable::read(lines.get(), hierarchicalSort);
+}
+
+
Try<MountInfoTable::Entry> MountInfoTable::Entry::parse(const string& s)
{
MountInfoTable::Entry entry;
http://git-wip-us.apache.org/repos/asf/mesos/blob/44c43835/src/linux/fs.hpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.hpp b/src/linux/fs.hpp
index 090c826..da49c9e 100644
--- a/src/linux/fs.hpp
+++ b/src/linux/fs.hpp
@@ -222,6 +222,23 @@ struct MountInfoTable {
const Option<pid_t>& pid = None(),
bool hierarchicalSort = true);
+ // Read a mountinfo table from a string.
+ // @param lines The contents of a mountinfo table represented as
+ // a string. Different entries in the string are
+ // separated by a newline.
+ // @param hierarchicalSort
+ // A boolean indicating whether the entries in the
+ // mountinfo table should be sorted according to
+ // their parent / child relationship (as opposed to
+ // the temporal ordering of when they were
+ // mounted). The two orderings may differ (for
+ // example) if a filesystem is remounted after some
+ // of its children have been mounted.
+ // @return An instance of MountInfoTable if success.
+ static Try<MountInfoTable> read(
+ const std::string& lines,
+ bool hierarchicalSort = true);
+
// TODO(jieyu): Introduce 'find' methods to find entries that match
// the given conditions (e.g., target, root, devno, etc.).