summaryrefslogtreecommitdiff
path: root/src/wrappers
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/wrappers
parent1d39ee23af0daff6f0a6d616e74fec8cc9c5db54 (diff)
cmd_subvolume: Fix snapshot creation with implicit source
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'src/wrappers')
-rw-r--r--src/wrappers/handle.rs16
1 files changed, 11 insertions, 5 deletions
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
}
}