当前位置: 首页>>代码示例>>C++>>正文


C++ Try::findByTarget方法代码示例

本文整理汇总了C++中Try::findByTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ Try::findByTarget方法的具体用法?C++ Try::findByTarget怎么用?C++ Try::findByTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Try的用法示例。


在下文中一共展示了Try::findByTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Error

// Make sure the target directory allow device files (i.e., there no
// `nodev` on the mounted filesystem that contains the target path).
static Try<Nothing> ensureAllowDevices(const string& _targetDir)
{
  // Mount table entries use realpaths. Therefore, we first get the
  // realpath of the target directory.
  Result<string> targetDir = os::realpath(_targetDir);
  if (!targetDir.isSome()) {
    return Error(
        "Failed to get the realpath of '" + _targetDir + "': " +
        (targetDir.isError() ? targetDir.error() : "Not found"));
  }

  Try<fs::MountInfoTable> table = fs::MountInfoTable::read();
  if (table.isError()) {
    return Error("Failed to get mount table: " + table.error());
  }

  // Trying to find the mount entry that contains the target
  // directory. We achieve that by doing a reverse traverse of the
  // mount table to find the first entry whose target is a prefix of
  // the target directory.
  Try<fs::MountInfoTable::Entry> targetDirMount =
    table->findByTarget(_targetDir);

  if (targetDirMount.isError()) {
    return Error(
        "Failed to find the mount containing '" + _targetDir +
        "': " + targetDirMount.error());
  }

  // No need to do anything if the mount has no `nodev`.
  if (!strings::contains(targetDirMount->vfsOptions, "nodev")) {
    return Nothing();
  }

  if (targetDirMount->target != targetDir.get()) {
    // This is the case where the target directory mount does not
    // exist in the mount table (e.g., a new host running Mesos
    // slave for the first time).
    LOG(INFO) << "Self bind mounting '" << targetDir.get()
              << "' and remounting with '-o remount,dev'";

    // NOTE: Instead of using fs::mount to perform the bind mount,
    // we use the shell command here because the syscall 'mount'
    // does not update the mount table (i.e., /etc/mtab). In other
    // words, the mount will not be visible if the operator types
    // command 'mount'. Since this mount will still be presented
    // after all containers and the slave are stopped, it's better
    // to make it visible. It's OK to use the blocking os::shell
    // here because 'create' will only be invoked during
    // initialization.
    Try<string> mount = os::shell(
        "mount --bind %s %s && "
        "mount -o remount,dev %s",
        targetDir.get(),
        targetDir.get(),
        targetDir.get());

    if (mount.isError()) {
      return Error(
          "Failed to self bind mount '" + targetDir.get() +
          "' and remount with '-o remount,dev': " + mount.error());
    }
  } else {
    // This is the case where the target directory mount is in the
    // mount table, but it's not remounted yet to remove 'nodev'
    // (possibly due to slave crash while preparing the target
    // directory mount). It's safe to re-do the following.
    LOG(INFO) << "Remounting '" << targetDir.get() << "' with '-o remount,dev'";

    Try<string> mount = os::shell(
        "mount -o remount,dev %s",
        targetDir.get());

    if (mount.isError()) {
      return Error(
          "Failed to remount '" + targetDir.get() +
          "' with '-o remount,dev': " + mount.error());
    }
  }

  return Nothing();
}
开发者ID:jfrazelle,项目名称:mesos,代码行数:84,代码来源:linux.cpp


注:本文中的Try::findByTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。