Skip to content

Commit

Permalink
resolvers: make names a bit more descriptive
Browse files Browse the repository at this point in the history
I doubt we will add new implementations any time soon, but the names
"Kernel" and "Emulated" aren't really descriptive enough for the people
who would care enough to want to change the default setting.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
  • Loading branch information
cyphar committed Jul 19, 2024
1 parent fec6a8a commit 53f9aa1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/resolvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use crate::{error::Error, Handle};

use std::{fs::File, path::Path};

/// `openat2(2)`-based in-kernel resolver.
pub mod kernel;
/// `O_PATH`-based userspace resolver.
pub mod user;
pub mod opath;
/// `openat2(2)`-based in-kernel resolver.
pub mod openat2;

bitflags! {
/// Optional flags to modify the resolution of paths inside a [`Root`].
Expand All @@ -48,19 +48,19 @@ bitflags! {
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ResolverBackend {
/// Use the native `openat2(2)` backend (requires kernel support).
Kernel,
KernelOpenat2,
/// Use the userspace "emulated" backend.
Emulated,
EmulatedOpath,
// TODO: Implement a HardcoreEmulated which does pivot_root(2) and all the
// rest of it. It'd be useful to compare against and for some
// hyper-concerned users.
}

lazy_static! {
static ref DEFAULT_RESOLVER_TYPE: ResolverBackend = if *kernel::IS_SUPPORTED {
ResolverBackend::Kernel
static ref DEFAULT_RESOLVER_TYPE: ResolverBackend = if *openat2::IS_SUPPORTED {
ResolverBackend::KernelOpenat2
} else {
ResolverBackend::Emulated
ResolverBackend::EmulatedOpath
};
}

Expand All @@ -74,8 +74,8 @@ impl ResolverBackend {
/// Checks if the resolver is supported on the current platform.
pub fn supported(self) -> bool {
match self {
ResolverBackend::Kernel => *kernel::IS_SUPPORTED,
ResolverBackend::Emulated => true,
ResolverBackend::KernelOpenat2 => *openat2::IS_SUPPORTED,
ResolverBackend::EmulatedOpath => true,
}
}
}
Expand All @@ -101,8 +101,8 @@ impl Resolver {
#[inline]
pub(crate) fn resolve<P: AsRef<Path>>(&self, root: &File, path: P) -> Result<Handle, Error> {
match self.backend {
ResolverBackend::Kernel => kernel::resolve(root, path, self.flags),
ResolverBackend::Emulated => user::resolve(root, path, self.flags),
ResolverBackend::KernelOpenat2 => openat2::resolve(root, path, self.flags),
ResolverBackend::EmulatedOpath => opath::resolve(root, path, self.flags),
}
}
}
10 changes: 5 additions & 5 deletions src/resolvers/user.rs → src/resolvers/opath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* with this program. If not, see <https://www.gnu.org/licenses/>.
*/

//! libpathrs::user implements an emulated version of the openat(2) patchset's
//! features. The primary method by which this is done is through shameless
//! abuse of procfs and O_PATH magic-links. The basic idea is that we need to
//! perform all of the path resolution steps (walking down the set of
//! components, handling the effect of symlinks on the resolution, etc).
//! libpathrs::opath implements an emulated version of openat2(RESOLVE_IN_ROOT).
//! The primary method by which this is done is through shameless abuse of
//! procfs and O_PATH magic-links. The basic idea is that we need to perform all
//! of the path resolution steps (walking down the set of components, handling
//! the effect of symlinks on the resolution, etc).
//!
//! In order to do this safely we need to verify after the walk is done whether
//! the path of the final file descriptor is what we expected (most importantly,
Expand Down
File renamed without changes.

0 comments on commit 53f9aa1

Please sign in to comment.