Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ parking_lot = "0.12"
dashmap = "5"
anyhow = "1"
thiserror = "1"
uuid = { version = "1", features = ["v4"] }
27 changes: 23 additions & 4 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use crate::storage;
pub(crate) const TTL: Duration = Duration::from_secs(0);
pub(crate) const BLOCK_SIZE: u32 = 512;

pub const BRANCHFS_IOC_COMMIT: u32 = 0x4201;
pub const BRANCHFS_IOC_ABORT: u32 = 0x4202;
pub const FS_IOC_BRANCH_CREATE: u32 = 0x6200; // _IO('b', 0)
pub const FS_IOC_BRANCH_COMMIT: u32 = 0x6201; // _IO('b', 1)
pub const FS_IOC_BRANCH_ABORT: u32 = 0x6202; // _IO('b', 2)

pub(crate) const CTL_FILE: &str = ".branchfs_ctl";
pub(crate) const CTL_INO: u64 = u64::MAX - 1;
Expand Down Expand Up @@ -1227,7 +1228,25 @@ impl Filesystem for BranchFs {
) {
let branch_name = self.get_branch_name();
match cmd {
BRANCHFS_IOC_COMMIT => {
FS_IOC_BRANCH_CREATE => {
let name = format!("branch-{}", uuid::Uuid::new_v4());
log::info!("ioctl: CREATE branch '{}' from '{}'", name, branch_name);
match self.manager.create_branch(&name, &branch_name) {
Ok(()) => {
self.switch_to_branch(&name);
log::info!("Switched to new branch '{}'", name);
// _IO encoding has no data direction, so we cannot
// return data through restricted FUSE ioctl. The
// mount is already switched to the new branch.
reply.ioctl(0, &[])
}
Err(e) => {
log::error!("create branch failed: {}", e);
reply.error(libc::EIO);
}
}
}
FS_IOC_BRANCH_COMMIT => {
log::info!("ioctl: COMMIT for branch '{}'", branch_name);
match self.manager.commit(&branch_name) {
Ok(parent) => {
Expand All @@ -1241,7 +1260,7 @@ impl Filesystem for BranchFs {
}
}
}
BRANCHFS_IOC_ABORT => {
FS_IOC_BRANCH_ABORT => {
log::info!("ioctl: ABORT for branch '{}'", branch_name);
match self.manager.abort(&branch_name) {
Ok(parent) => {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pub use daemon::{
Response,
};
pub use error::{BranchError, Result};
pub use fs::{FS_IOC_BRANCH_ABORT, FS_IOC_BRANCH_COMMIT, FS_IOC_BRANCH_CREATE};
Loading