Skip to contentSkip to conversation

bcachefs: opts.rebalance_on_ac_only

PATCH New Kent Overstreet 1 participant 1 message May 6, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: opts.rebalance_on_ac_only

Add an option for setting rebalance to only run when connected to mains power.

---
 fs/bcachefs/bcachefs_format.h |  1 +
 fs/bcachefs/opts.h            |  5 ++++
 fs/bcachefs/rebalance.c       | 48 ++++++++++++++++++++++++++++++++---
 fs/bcachefs/rebalance.h       |  4 ++-
 fs/bcachefs/rebalance_types.h |  3 +++
 fs/bcachefs/super.c           |  3 ++-
 6 files changed, 58 insertions(+), 6 deletions(-)
fs/bcachefs/bcachefs_format.h +1 -0
index baaf9786238b..a483d440fa39 100644
@@ -871,6 +871,7 @@ LE64_BITMASK(BCH_SB_WRITE_ERROR_TIMEOUT,struct bch_sb, flags[6],  4, 14);
 LE64_BITMASK(BCH_SB_CSUM_ERR_RETRY_NR,	struct bch_sb, flags[6], 14, 20);
 LE64_BITMASK(BCH_SB_DEGRADED_ACTION,	struct bch_sb, flags[6], 20, 22);
 LE64_BITMASK(BCH_SB_CASEFOLD,		struct bch_sb, flags[6], 22, 23);
+LE64_BITMASK(BCH_SB_REBALANCE_AC_ONLY,	struct bch_sb, flags[6], 23, 24);
 
 static inline __u64 BCH_SB_COMPRESSION_TYPE(const struct bch_sb *sb)
 {
fs/bcachefs/opts.h +5 -0
index b8cd0b04e62a..f4c014ad43c1 100644
@@ -490,6 +490,11 @@ enum fsck_err_opts {
 	  BCH2_NO_SB_OPT,			true,			\
 	  NULL,		"Enable rebalance: disable for debugging, or to\n"\
 			"quiet the system when doing performance testing\n")\
+	x(rebalance_on_ac_only,		u8,				\
+	  OPT_FS|OPT_MOUNT|OPT_RUNTIME,					\
+	  OPT_BOOL(),							\
+	  BCH_SB_REBALANCE_AC_ONLY,		false,			\
+	  NULL,		"Enable rebalance while on mains power only\n")	\
 	x(no_data_io,			u8,				\
 	  OPT_MOUNT,							\
 	  OPT_BOOL(),							\
fs/bcachefs/rebalance.c +44 -4

68 lines not on this page · raw message

fs/bcachefs/rebalance.h +3 -1
index b7c8c0652ad6..5d9214fe1a22 100644
@@ -52,7 +52,9 @@ void bch2_rebalance_status_to_text(struct printbuf *, struct bch_fs *);
 
 void bch2_rebalance_stop(struct bch_fs *);
 int bch2_rebalance_start(struct bch_fs *);
-void bch2_fs_rebalance_init(struct bch_fs *);
+
+void bch2_fs_rebalance_exit(struct bch_fs *);
+int bch2_fs_rebalance_init(struct bch_fs *);
 
 int bch2_check_rebalance_work(struct bch_fs *);
 
fs/bcachefs/rebalance_types.h +3 -0
index fe5098c17dfc..76187c6572ea 100644
@@ -30,6 +30,9 @@ struct bch_fs_rebalance {
 	struct bbpos			scan_start;
 	struct bbpos			scan_end;
 	struct bch_move_stats		scan_stats;
+
+	bool				on_battery;
+	struct notifier_block		power_notifier;
 };
 
 #endif /* _BCACHEFS_REBALANCE_TYPES_H */
fs/bcachefs/super.c +2 -1
index a33872d0172c..c6c63ae0ae97 100644
@@ -578,6 +578,7 @@ static void __bch2_fs_free(struct bch_fs *c)
 	bch2_fs_snapshots_exit(c);
 	bch2_fs_sb_errors_exit(c);
 	bch2_fs_replicas_exit(c);
+	bch2_fs_rebalance_exit(c);
 	bch2_fs_quota_exit(c);
 	bch2_fs_nocow_locking_exit(c);
 	bch2_fs_journal_exit(&c->journal);
@@ -862,7 +863,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
 	bch2_fs_move_init(c);
 	bch2_fs_nocow_locking_init_early(c);
 	bch2_fs_quota_init(c);
-	bch2_fs_rebalance_init(c);
 	bch2_fs_sb_errors_init_early(c);
 	bch2_fs_snapshots_init_early(c);
 	bch2_fs_subvolumes_init_early(c);
@@ -984,6 +984,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
 	    bch2_fs_fsio_init(c) ?:
 	    bch2_fs_fs_io_direct_init(c) ?:
 	    bch2_fs_io_read_init(c) ?:
+	    bch2_fs_rebalance_init(c) ?:
 	    bch2_fs_sb_errors_init(c) ?:
 	    bch2_fs_vfs_init(c);
 	if (ret)
Signature · 1 line
2.49.0