]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
cmd_subvolume: Fix snapshot creation with implicit source
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 6 Feb 2024 01:33:10 +0000 (20:33 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 6 Feb 2024 02:31:08 +0000 (21:31 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
src/commands/cmd_subvolume.rs
src/wrappers/handle.rs

index 57c679a1ea07cafd944b038ce778fd8b9dd661d4..85183fa4889525b13c069195a42df26f46881779 100644 (file)
@@ -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
     }
 }
index 9dd66188d4dbbac54d4aa44ff2432af50cfa22bc..336a029f5fae9632eba3e0520729bc1c511ed8f5 100644 (file)
@@ -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
     }
 }