From 31df2f2b750dd714e29cdff9fe48d0c0e4e9cbd8 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 17 Mar 2024 08:03:50 +0000 Subject: [PATCH] Add bcachefs growing (!123) Shrinking a bcachefs file system is not supported. # truncate -s $((1*1024*1024*1024)) /tmp/disk.img # losetup --find --show /tmp/disk.img /dev/loop0 # bcachefs format /dev/loop0 ... # bcachefs device resize /dev/loop0 $((1*1024*1024*1024 - 512)) Doing offline resize of /dev/loop0 mounting version 1.4: member_seq initializing new filesystem going read-write initializing freespace Shrinking not supported yet # echo $? 1 Growing a bcachefs file system is supported when unmounted. # truncate -s $((2*1024*1024*1024)) /tmp/disk.img # losetup --set-capacity /dev/loop0 # bcachefs device resize /dev/loop0 Doing offline resize of /dev/loop0 mounting version 1.6: btree_subvolume_children recovering from unclean shutdown journal read done, replaying entries 1-1 alloc_read... done stripes_read... done snapshots_read... done going read-write journal_replay... done resume_logged_ops... done delete_dead_inodes... done resizing /dev/loop0 to 16384 buckets # echo $? 0 # bcachefs show-super /dev/loop0 | egrep 'Device:|Size:' Device: 0 Size: 2.00 GiB Growing is also supported when mounted. # mount /dev/loop0 /mnt/0 # truncate -s $((3*1024*1024*1024)) /tmp/disk.img # losetup --set-capacity /dev/loop0 # bcachefs device resize /dev/loop0 Doing online resize of /dev/loop0 resizing /dev/loop0 to 24576 buckets # echo $? 0 # bcachefs show-super /dev/loop0 | egrep 'Device:|Size:' Device: 0 Size: 3.00 GiB Closes !123 - Add support for bcachefs, single device file systems only --- include/bcachefs.h | 1 + src/bcachefs.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/bcachefs.h b/include/bcachefs.h index 94a4d80f..b04744b9 100644 --- a/include/bcachefs.h +++ b/include/bcachefs.h @@ -36,6 +36,7 @@ public: bool create(const Partition& new_partition, OperationDetail& operationdetail); void read_label(Partition& partition); void read_uuid(Partition& partition); + bool resize(const Partition& partition_new, OperationDetail& operationdetail, bool fill_partition); }; diff --git a/src/bcachefs.cc b/src/bcachefs.cc index f8c1f082..1a6514ae 100644 --- a/src/bcachefs.cc +++ b/src/bcachefs.cc @@ -45,6 +45,11 @@ FS bcachefs::get_filesystem_support() fs.create_with_label = FS::EXTERNAL; fs.read_label = FS::EXTERNAL; fs.read_uuid = FS::EXTERNAL; + fs.grow = FS::EXTERNAL; +#ifdef ENABLE_ONLINE_RESIZE + if (Utils::kernel_version_at_least(3, 6, 0)) + fs.online_grow = FS::EXTERNAL; +#endif } fs_limits.min_size = 32 * MEBIBYTE; @@ -131,4 +136,11 @@ void bcachefs::read_uuid(Partition& partition) } +bool bcachefs::resize(const Partition& partition_new, OperationDetail& operationdetail, bool fill_partition) +{ + return ! execute_command("bcachefs device resize " + Glib::shell_quote(partition_new.get_path()), + operationdetail, EXEC_CHECK_STATUS); +} + + } //GParted