summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-02-05 20:33:10 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-02-05 21:31:08 -0500
commit1ef396b684a419b5a50ab215103486d189068800 (patch)
tree33bd8374f7d2d9eabd1712c33bc0ef63952afc85 /src
parent1d39ee23af0daff6f0a6d616e74fec8cc9c5db54 (diff)
cmd_subvolume: Fix snapshot creation with implicit source
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'src')
-rw-r--r--src/commands/cmd_subvolume.rs3
-rw-r--r--src/wrappers/handle.rs16
2 files changed, 13 insertions, 6 deletions
diff --git a/src/commands/cmd_subvolume.rs b/src/commands/cmd_subvolume.rs
index 57c679a1..85183fa4 100644
--- a/src/commands/cmd_subvolume.rs
+++ b/src/commands/cmd_subvolume.rs
@@ -22,11 +22,12 @@ enum Subcommands {
/// Path
target: PathBuf
},
+ #[command(allow_missing_positional = true)]
Snapshot {
/// Make snapshot read only
#[arg(long, short = 'r')]
read_only: bool,
- source: PathBuf,
+ source: Option<PathBuf>,
dest: PathBuf
}
}
diff --git a/src/wrappers/handle.rs b/src/wrappers/handle.rs
index 9dd66188..336a029f 100644
--- a/src/wrappers/handle.rs
+++ b/src/wrappers/handle.rs
@@ -82,17 +82,23 @@ impl BcachefsHandle {
/// Snapshot a subvolume for this bcachefs filesystem
/// at the given path
- pub fn snapshot_subvolume<P: AsRef<Path>>(&self, extra_flags: u32, src: P, dst: P) -> Result<(), Errno> {
- let src = CString::new(src.as_ref().as_os_str().as_bytes()).expect("Failed to cast source path for subvolume in a C-style string");
+ pub fn snapshot_subvolume<P: AsRef<Path>>(&self, extra_flags: u32, src: Option<P>, dst: P) -> Result<(), Errno> {
+ let src = src.map(|src| CString::new(src.as_ref().as_os_str().as_bytes()).expect("Failed to cast source path for subvolume in a C-style string"));
let dst = CString::new(dst.as_ref().as_os_str().as_bytes()).expect("Failed to cast destination path for subvolume in a C-style string");
- self.ioctl(BcachefsIoctl::SubvolumeCreate, &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume {
+
+ let res = self.ioctl(BcachefsIoctl::SubvolumeCreate, &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume {
flags: BCH_SUBVOL_SNAPSHOT_CREATE | extra_flags,
dirfd: libc::AT_FDCWD,
mode: 0o777,
- src_ptr: src.as_ptr() as u64,
+ src_ptr: src.as_ref().map_or(0, |x| x.as_ptr() as u64),
+ //src_ptr: if let Some(src) = src { src.as_ptr() } else { std::ptr::null() } as u64,
dst_ptr: dst.as_ptr() as u64,
..Default::default()
- }))
+ }));
+
+ drop(src);
+ drop(dst);
+ res
}
}