Skip to contentSkip to conversation

bcachefs: Don't pretty-print options in /proc/mounts

PATCH In review Gabriel de Perthuis 2 participants 3 messages Apr 25, 2025 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 03c6436f10a17e4e520c611d8dbca0b5a56532c8.1745590098.git.g2p.code@gmail.com

#1 lore raw

PATCH v2 1/1 bcachefs: Don't pretty-print options in /proc/mounts

Pretty printing of sizes could introduce spaces and break the expected space-separated format.

---
v2: Tested and working this time

 fs/bcachefs/opts.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/bcachefs/opts.c +5 -1
index b1cf88905b816..633137567f463 100644
@@ -452,25 +452,29 @@ int bch2_opt_parse(struct bch_fs *c,
 void bch2_opt_to_text(struct printbuf *out,
 		      struct bch_fs *c, struct bch_sb *sb,
 		      const struct bch_option *opt, u64 v,
 		      unsigned flags)
 {
+	enum opt_flags opt_flags = opt->flags;
+
 	if (flags & OPT_SHOW_MOUNT_STYLE) {
 		if (opt->type == BCH_OPT_BOOL) {
 			prt_printf(out, "%s%s",
 			       v ? "" : "no",
 			       opt->attr.name);
 			return;
 		}
 
 		prt_printf(out, "%s=", opt->attr.name);
+		// OPT_HUMAN_READABLE can introduce spaces which break the expected tabular format
+		opt_flags &= ~OPT_HUMAN_READABLE;
 	}
 
 	switch (opt->type) {
 	case BCH_OPT_BOOL:
 	case BCH_OPT_UINT:
-		if (opt->flags & OPT_HUMAN_READABLE)
+		if (opt_flags & OPT_HUMAN_READABLE)
 			prt_human_readable_u64(out, v);
 		else
 			prt_printf(out, "%lli", v);
 		break;
 	case BCH_OPT_STR:
Signature · 1 line
2.45.2
#2 lore raw
Quoted 3 lines · Gabriel de Perthuis

Pretty printing of sizes could introduce spaces and break the expected space-separated format.

we shoudldn't be including spaces when we print human readable numbers, that's the bug...

Quoted 46 lines

---
v2: Tested and working this time

 fs/bcachefs/opts.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/bcachefs/opts.c +5 -1
index b1cf88905b816..633137567f463 100644
@@ -452,25 +452,29 @@ int bch2_opt_parse(struct bch_fs *c,
 void bch2_opt_to_text(struct printbuf *out,
 		      struct bch_fs *c, struct bch_sb *sb,
 		      const struct bch_option *opt, u64 v,
 		      unsigned flags)
 {
+	enum opt_flags opt_flags = opt->flags;
+
 	if (flags & OPT_SHOW_MOUNT_STYLE) {
 		if (opt->type == BCH_OPT_BOOL) {
 			prt_printf(out, "%s%s",
 			       v ? "" : "no",
 			       opt->attr.name);
 			return;
 		}
 
 		prt_printf(out, "%s=", opt->attr.name);
+		// OPT_HUMAN_READABLE can introduce spaces which break the expected tabular format
+		opt_flags &= ~OPT_HUMAN_READABLE;
 	}
 
 	switch (opt->type) {
 	case BCH_OPT_BOOL:
 	case BCH_OPT_UINT:
-		if (opt->flags & OPT_HUMAN_READABLE)
+		if (opt_flags & OPT_HUMAN_READABLE)
 			prt_human_readable_u64(out, v);
 		else
 			prt_printf(out, "%lli", v);
 		break;
 	case BCH_OPT_STR:
Signature · 1 line
2.45.2

A message that is not in the archive (sent off-list or not yet received): CAMxhh=6nbSL2Ygb92DOMSiSbgbzXiFn20iEu6OvZMoR47VJ+bw@mail.gmail.com

#4 lore raw
Quoted 12 lines · On Fri, Apr 25, 2025 at 05:21:46PM +0200, g2p code wrote:
Quoted 7 lines · Kent Overstreet
Quoted 3 lines · Gabriel de Perthuis

Pretty printing of sizes could introduce spaces and break the expected space-separated format.

we shoudldn't be including spaces when we print human readable numbers, that's the bug...

Quoted 7 lines

I did a quick check, human-readable sizes from prt_human_readable_u64 also lose some precision.
That's fine for dmesg and other reporting, but there need to be easy and obvious
way to get the values back losslessly, I don't think /proc/mounts and /sys/fs/bcachefs/*/options/
should modify them.

Who's parsing /proc/mounts for the option values, though? That's primarily for human consumption, we have better ways of getting at that...