btrfs: add NO_FS_INFO to btrfs_printk
PATCH 1/4 btrfs: add NO_FS_INFO to btrfs_printk
The first argument to btrfs_printk() wrappers such as btrfs_warn_in_rcu(), btrfs_info_in_rcu(), etc.. is fs_info, but in some context like scan and assembling of the volumes there isn't fs_info yet, so those code generally don't use the btrfs_printk() wrappers and it could could still use NULL but then it would become hard to distinguish whether fs_info is NULL for genuine reason or a bug.
So introduce a define NO_FS_INFO to be used instead of NULL so that we know the code where fs_info isn't initialized and also we have a consistent logging functions. Thanks.
--- fs/btrfs/ctree.h | 5 +++++ fs/btrfs/super.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +5 -0
@@ -110,6 +110,11 @@ struct btrfs_ref;#define BTRFS_STAT_CURR 0#define BTRFS_STAT_PREV 1 +/* +* Used when we know that fs_info is not yet initialized. +*/ +#define NO_FS_INFO ((void *)0x1) +/* * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size */
fs/btrfs/super.c +11 -3
@@ -216,9 +216,17 @@ void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, . vaf.fmt = fmt; vaf.va = &args; -if (__ratelimit (ratelimit)) -printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, - fs_info ? fs_info->sb->s_id :"<unknown>" , &vaf); +if (__ratelimit (ratelimit)) { +if (fs_info ==NULL ) +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, +"<unknown>" , &vaf); +else if (fs_info ==NO_FS_INFO ) +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, +"..." , &vaf); +else +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, + fs_info->sb->s_id, &vaf); + }va_end (args); }
Signature · 1 line
2.23.0
PATCH 2/4 btrfs: stop using uninitiazlised fs_info in device_list_add()
fs_info is born during mount, and operations before the mount such as scanning and assembling of the device volume should happen without any reference to fs_info.
However the patch commit a9261d4125c9 (btrfs: harden agaist duplicate fsid on scanned devices) used fs_info to call btrfs_warn_in_rcu() and btrfs_info_in_rcu(), so if fs_info is NULL, the stacked functions which leads to btrfs_printk() which shall print "unknown" instead of sb->s_id. Or even might UAF as reported in [1].
So do the right thing, don't use fs_info instead use NO_FS_INFO in btrfs_warn_in_rcu() and btrfs_info_in_rcu() for the btrfs_printk() to take care of it properly.
Link:
[1] https://www.spinics.net/lists/linux-btrfs/msg96524.html
--- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +2 -2
@@ -889,14 +889,14 @@ static noinline struct btrfs_device *device_list_add(const char *path,if (device->bdev != path_bdev) {bdput (path_bdev);mutex_unlock (&fs_devices->device_list_mutex); -btrfs_warn_in_rcu (device->fs_info, +btrfs_warn_in_rcu (NO_FS_INFO ,"duplicate device fsid:devid for %pU:%llu old:%s new:%s" , disk_super->fsid, devid,rcu_str_deref (device->name), path);return ERR_PTR (-EEXIST ); }bdput (path_bdev); -btrfs_info_in_rcu (device->fs_info, +btrfs_info_in_rcu (NO_FS_INFO ,"device fsid %pU devid %llu moved old:%s new:%s" , disk_super->fsid, devid,rcu_str_deref (device->name), path);
Signature · 1 line
2.23.0
Re: [PATCH 2/4] btrfs: stop using uninitiazlised fs_info in device_list_add()
Quoted 9 lines · Anand Jain
fs_infois born during mount, and operations before the mount such as scanning and assembling of the device volume should happen without any reference tofs_info.However the patch commit
a9261d4125c9(btrfs: harden agaist duplicate fsid on scanned devices) usedfs_infoto callbtrfs_warn_in_rcu()andbtrfs_info_in_rcu(), so iffs_infois NULL, the stacked functions which leads tobtrfs_printk()which shall print "unknown" instead ofsb->s_id. Or even might UAF as reported in [1].
With your previous patch, which already checked NULL pointer, I didn't see the need for NO_FS_INFO.
Or do you believe this calling site is a special?
If so, I still didn't get the point of NO_FS_INFO, just extra lines using __func__ or "during scan: xxxxx" looks enough to me.
Thanks,
Qu
Quoted 35 lines
So do the right thing, don't use
fs_infoinstead useNO_FS_INFOinbtrfs_warn_in_rcu()andbtrfs_info_in_rcu()for thebtrfs_printk()to take care of it properly.Link:
[1] https://www.spinics.net/lists/linux-btrfs/msg96524.htmlFixes a9261d4125c9 (btrfs: harden agaist duplicate fsid on scanned devices)Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/volumes.c +2
-2@@ -889,14 +889,14 @@ static noinline struct btrfs_device *device_list_add(const char *path,if (device->bdev != path_bdev) {bdput (path_bdev);mutex_unlock (&fs_devices->device_list_mutex); -btrfs_warn_in_rcu (device->fs_info, +btrfs_warn_in_rcu (NO_FS_INFO ,"duplicate device fsid:devid for %pU:%llu old:%s new:%s" , disk_super->fsid, devid,rcu_str_deref (device->name), path);return ERR_PTR (-EEXIST ); }bdput (path_bdev); -btrfs_info_in_rcu (device->fs_info, +btrfs_info_in_rcu (NO_FS_INFO ,"device fsid %pU devid %llu moved old:%s new:%s" , disk_super->fsid, devid,rcu_str_deref (device->name), path);
Re: [PATCH 2/4] btrfs: stop using uninitiazlised fs_info in device_list_add()
Quoted 13 lines · Qu Wenruo
Quoted 9 lines · Anand Jain
fs_infois born during mount, and operations before the mount such as scanning and assembling of the device volume should happen without any reference tofs_info.However the patch commit
a9261d4125c9(btrfs: harden agaist duplicate fsid on scanned devices) usedfs_infoto callbtrfs_warn_in_rcu()andbtrfs_info_in_rcu(), so iffs_infois NULL, the stacked functions which leads tobtrfs_printk()which shall print "unknown" instead ofsb->s_id. Or even might UAF as reported in [1].
Quoted 6 lines
With your previous patch, which already checked NULL pointer, I didn't see the need for
NO_FS_INFO.Or do you believe this calling site is a special?
If so, I still didn't get the point ofNO_FS_INFO, just extra lines using__func__or "during scan: xxxxx" looks enough to me.
I agree with this assessment. What value does NO_FS_INFO bring in comparison to plain NULL that it warrants a special case?
Quoted 4 lines
Thanks,
Qu
PATCH 3/4 btrfs: make the scan logs consistent
In reply to Anand JainTypically we follow, a logging format <parameter> <value> and no ":" so just follow that here.
---
David,
If required you may roll this into the patch 2/4 in this series. I didn't dare, as there may be some concerns that it isn't relevent there.
fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +2 -2
@@ -890,14 +890,14 @@ static noinline struct btrfs_device *device_list_add(const char *path,bdput (path_bdev);mutex_unlock (&fs_devices->device_list_mutex);btrfs_warn_in_rcu (NO_FS_INFO , -"duplicate device fsid:devid for %pU:%llu old:%s new:%s" , +"duplicate device fsid %pU devid %llu exisitng %s new %s" , disk_super->fsid, devid,rcu_str_deref (device->name), path);return ERR_PTR (-EEXIST ); }bdput (path_bdev);btrfs_info_in_rcu (NO_FS_INFO , -"device fsid %pU devid %llu moved old:%s new:%s" , +"device fsid %pU devid %llu moved old %s new %s" , disk_super->fsid, devid,rcu_str_deref (device->name), path); }
Signature · 1 line
2.23.0
PATCH 4/4 btrfs: use btrfs consistent logging wrappers
In reply to Anand JainNow as we could use the btrfs_info(), btrfs_warn() etc.. in the context where fs_info is not yet initialized, so replace pr_info with btrfs_info in device_list_add() for a consistent log format from btrfs.
--- fs/btrfs/volumes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +4 -4
@@ -824,13 +824,13 @@ static noinline struct btrfs_device *device_list_add(const char *path, *new_device_added = true;if (disk_super->label[0 ]) -pr_info ( -"BTRFS: device label %s devid %llu transid %llu %s scanned by %s (%d)\n" , +btrfs_info (NO_FS_INFO , +"device label %s devid %llu transid %llu %s scanned by %s (%d)" , disk_super->label, devid, found_transid, path, current->comm,task_pid_nr (current));else -pr_info ( -"BTRFS: device fsid %pU devid %llu transid %llu %s scanned by %s (%d)\n" , +btrfs_info (NO_FS_INFO , +"device fsid %pU devid %llu transid %llu %s scanned by %s (%d)" , disk_super->fsid, devid, found_transid, path, current->comm,task_pid_nr (current));
Signature · 1 line
2.23.0
Quoted 10 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.
I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
Thanks,
Qu
Quoted 50 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/ctree.h | 5 +++++ fs/btrfs/super.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +5
-0@@ -110,6 +110,11 @@ struct btrfs_ref;#define BTRFS_STAT_CURR 0#define BTRFS_STAT_PREV 1 +/* +* Used when we know that fs_info is not yet initialized. +*/ +#define NO_FS_INFO ((void *)0x1) +/* * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size */ fs/btrfs/super.c +11
-3@@ -216,9 +216,17 @@ void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, . vaf.fmt = fmt; vaf.va = &args; -if (__ratelimit (ratelimit)) -printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, - fs_info ? fs_info->sb->s_id :"<unknown>" , &vaf); +if (__ratelimit (ratelimit)) { +if (fs_info ==NULL ) +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, +"<unknown>" , &vaf); +else if (fs_info ==NO_FS_INFO ) +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, +"..." , &vaf); +else +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, + fs_info->sb->s_id, &vaf); + }va_end (args); }
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.
Quoted 8 lines
Quoted 3 lines
So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
The first argument in btrfs_info_in_rcu() can be NULL like for example.. btrfs_info_in_rcu(NULL, ..) which then it shall print the prefix..
BTRFS info (device <unknown>):
Lets say due to some bug local copy of the variable fs_info wasn't
initialized then we end up printing the same unknown <unknown>.
So in the context of device_list_add() as there is no fs_info
genuinely and be different from unknown we use btrfs_info_in_rcu(NO_FS_INFO, ..) to get prefix something like..
BTRFS info (device ...):
Thanks, Anand
Quoted 54 lines
Thanks,
QuQuoted 50 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/ctree.h | 5 +++++ fs/btrfs/super.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +5
-0@@ -110,6 +110,11 @@ struct btrfs_ref;#define BTRFS_STAT_CURR 0#define BTRFS_STAT_PREV 1 +/* +* Used when we know that fs_info is not yet initialized. +*/ +#define NO_FS_INFO ((void *)0x1) +/* * Count how many BTRFS_MAX_EXTENT_SIZE cover the @size */ fs/btrfs/super.c +11
-3@@ -216,9 +216,17 @@ void __cold btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, . vaf.fmt = fmt; vaf.va = &args; -if (__ratelimit (ratelimit)) -printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, - fs_info ? fs_info->sb->s_id :"<unknown>" , &vaf); +if (__ratelimit (ratelimit)) { +if (fs_info ==NULL ) +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, +"<unknown>" , &vaf); +else if (fs_info ==NO_FS_INFO ) +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, +"..." , &vaf); +else +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, + fs_info->sb->s_id, &vaf); + }va_end (args); }
Quoted 22 lines · Anand Jain
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.Quoted 8 lines
Quoted 3 lines
So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
Quoted 7 lines
The first argument in
btrfs_info_in_rcu()can be NULL like for example..btrfs_info_in_rcu(NULL, ..)which then it shall print the prefix..BTRFS info (device <unknown>):
Lets say due to some bug local copy of the variable
fs_infowasn't initialized then we end up printing the same unknown <unknown>.
This is wrong if the local copy variable is not initialized then it will get random value from stack which will likely crash during deref because it will most certainly not be NULL.
Quoted 62 lines
So in the context of
device_list_add()as there is nofs_infogenuinely and be different from unknown we usebtrfs_info_in_rcu(NO_FS_INFO, ..)to get prefix something like..BTRFS info (device ...):
Thanks, Anand
Quoted 52 lines
Thanks,
QuQuoted 48 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>---
fs/btrfs/ctree.h| 5 +++++
fs/btrfs/super.c| 14 +++++++++++---2 files changed, 16 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +0
-0@@ -110,6 +110,11 @@ struct btrfs_ref; #define BTRFS_STAT_CURR 0 #define BTRFS_STAT_PREV 1+/*
+ * Used when we know thatfs_infois not yet initialized.
+ */fs/btrfs/ctree.h +2
-0+#define NO_FS_INFO ((void *)0x1) +/*
* Count how manyBTRFS_MAX_EXTENT_SIZEcover the @size */fs/btrfs/super.c +0
-0@@ -216,9 +216,17 @@ void __cold btrfs_printk(const struct
btrfs_fs_info*fs_info, const char *fmt, .
vaf.fmt = fmt;
vaf.va = &args;
- if (__ratelimit(ratelimit))
- printk("%sBTRFS %s (device %s): %pV\n", lvl, type, -fs_info?fs_info->sb->s_id: "<unknown>", &vaf); + if (__ratelimit(ratelimit)) {
+ if (fs_info== NULL)
+printk("%sBTRFS %s (device %s): %pV\n", lvl, type, + "<unknown>", &vaf);
+ else if (fs_info==NO_FS_INFO)
+printk("%sBTRFS %s (device %s): %pV\n", lvl, type, + "...", &vaf);
+ else
+ printk("%sBTRFS %s (device %s): %pV\n", lvl, type, +fs_info->sb->s_id, &vaf);
+ }
va_end(args);
}
Quoted 22 lines · Anand Jain
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.Quoted 8 lines
Quoted 3 lines
So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
Quoted 7 lines
The first argument in
btrfs_info_in_rcu()can be NULL like for example..btrfs_info_in_rcu(NULL, ..)which then it shall print the prefix..BTRFS info (device <unknown>):
Lets say due to some bug local copy of the variable
fs_infowasn't initialized then we end up printing the same unknown <unknown>.
Then that's a bug to fix.
Quoted 6 lines
So in the context of
device_list_add()as there is nofs_infogenuinely and be different from unknown we usebtrfs_info_in_rcu(NO_FS_INFO, ..)to get prefix something like..BTRFS info (device ...):
But that's the only context we don't have an initialized fs_info.
I don't like the idea to use some random pointer as a special indicator only for 1 or 2 call sites.
And if you don't like the "<unknown>" string, unifing them to "..." looks better to me.
Thanks,
Qu
Quoted 56 lines
Thanks, Anand
Quoted 52 lines
Thanks,
QuQuoted 48 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>---
fs/btrfs/ctree.h| 5 +++++
fs/btrfs/super.c| 14 +++++++++++---2 files changed, 16 insertions(+), 3 deletions(-)fs/btrfs/ctree.h +0
-0@@ -110,6 +110,11 @@ struct btrfs_ref; #define BTRFS_STAT_CURR 0 #define BTRFS_STAT_PREV 1+/*
+ * Used when we know thatfs_infois not yet initialized.
+ */fs/btrfs/ctree.h +2
-0+#define NO_FS_INFO ((void *)0x1) +/*
* Count how manyBTRFS_MAX_EXTENT_SIZEcover the @size */fs/btrfs/super.c +0
-0@@ -216,9 +216,17 @@ void __cold btrfs_printk(const struct
btrfs_fs_info*fs_info, const char *fmt, .
vaf.fmt = fmt;
vaf.va = &args;
- if (__ratelimit(ratelimit))
- printk("%sBTRFS %s (device %s): %pV\n", lvl, type, -fs_info?fs_info->sb->s_id: "<unknown>", &vaf); + if (__ratelimit(ratelimit)) {
+ if (fs_info== NULL)
+printk("%sBTRFS %s (device %s): %pV\n", lvl, type, + "<unknown>", &vaf);
+ else if (fs_info==NO_FS_INFO)
+printk("%sBTRFS %s (device %s): %pV\n", lvl, type, + "...", &vaf);
+ else
+ printk("%sBTRFS %s (device %s): %pV\n", lvl, type, +fs_info->sb->s_id, &vaf);
+ }
va_end(args);
}
Quoted 22 lines · Anand Jain
Quoted 8 lines · Qu Wenruo
Quoted 7 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.Quoted 7 lines
Quoted 3 lines
So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
The first argument in
btrfs_info_in_rcu()can be NULL like for example..btrfs_info_in_rcu(NULL, ..)which then it shall print the prefix..BTRFS info (device <unknown>):
Quoted 8 lines
Lets say due to some bug local copy of the variable
fs_infowasn't
initialized then we end up printing the same unknown <unknown>.So in the context of
device_list_add()as there is nofs_info
genuinely and be different from unknown we usebtrfs_info_in_rcu(NO_FS_INFO, ..)to get prefix something like..BTRFS info (device ...):
With the fixup to set fs_info to NULL on a device that's unmounted, do we still need the NO_FS_INFO stub? The only difference I can see is a to print "..." instead of "<unknown>" that I don't find too useful or improving the output.
My idea about the stub fs info was to avoid any access to fs_info inside device_list_add in case we can't reliably close the race where scan can read device::fs_info during mount that sets it up, but as I'm told it's not a problem anymore.
Quoted 26 lines · David Sterba
Quoted 25 lines · Anand Jain
Quoted 8 lines · Qu Wenruo
Quoted 7 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.Quoted 7 lines
Quoted 3 lines
So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
The first argument in
btrfs_info_in_rcu()can be NULL like for example..btrfs_info_in_rcu(NULL, ..)which then it shall print the prefix..BTRFS info (device <unknown>):
Lets say due to some bug local copy of the variable
fs_infowasn't
initialized then we end up printing the same unknown <unknown>.
Quoted 8 lines
Quoted 5 lines
So in the context of
device_list_add()as there is nofs_info
genuinely and be different from unknown we usebtrfs_info_in_rcu(NO_FS_INFO, ..)to get prefix something like..BTRFS info (device ...):
With the fixup to set
fs_infoto NULL on a device that's unmounted, do we still need theNO_FS_INFOstub?
Its trivial we don't need NO_FS_INFO IMO.
Quoted 3 lines
The only difference I can see is a
to print "..." instead of "<unknown>" that I don't find too useful or improving the output.
Agree. Two ways we can make it better one use open code. Patch [1] disk that.
[1]
[PATCH 1/2] btrfs: open code log helpers in device_list_add()
two, change btrfs_printk() and all its wrapper to use fs_devices instead of fs_info. It solves two purposes, device name does not make sense for logging of volume so will use fsid, and avoid confusion when the device errors are being reported. Secondly we could use btrfs_printk() wrappers in the unmounted context. And added bonus is logging becomes truly consistent.
Let me know if you think this is the right way, will look into it.
Quoted 4 lines
My idea about the stub fs info was to avoid any access to
fs_infoinsidedevice_list_addin case we can't reliably close the race where scan can readdevice::fs_infoduring mount that sets it up, but as I'm told it's not a problem anymore.
Using NULL instead of fs_info or open code or using fs_devices (as discussed above) will solve it.
The analysis about the race needed few more information, so I am not sure.
My idea is to make it theoretically correct. Using uninitialized fs_info in device_list_add is wrong.
Thanks, Anand
David,
Ping on this.
Any idea if the open code as in the patch below [1] is better or how do we fix it? My proposal about using fsid in the btrfs_printk() instead of current sb->s_id is another choice.
[1]
[PATCH 1/2] btrfs: open code log helpers in device_list_add()
I think for now make it open code as in [1] so it stands correct.
Thanks, Anand
Quoted 71 lines · Anand Jain
Quoted 26 lines · David Sterba
Quoted 25 lines · Anand Jain
Quoted 8 lines · Qu Wenruo
Quoted 7 lines · Anand Jain
The first argument to
btrfs_printk()wrappers such asbtrfs_warn_in_rcu(),btrfs_info_in_rcu(), etc.. isfs_info, but in some context like scan and assembling of the volumes there isn'tfs_infoyet, so those code generally don't use thebtrfs_printk()wrappers and it could could still use NULL but then it would become hard to distinguish whetherfs_infois NULL for genuine reason or a bug.Quoted 7 lines
Quoted 3 lines
So introduce a define
NO_FS_INFOto be used instead of NULL so that we know the code wherefs_infoisn't initialized and also we have a consistent logging functions. Thanks.I'm not sure why this is needed.
Could you give me an example in which NULL is not clear enough?
The first argument in
btrfs_info_in_rcu()can be NULL like for example..btrfs_info_in_rcu(NULL, ..)which then it shall print the prefix..BTRFS info (device <unknown>):
Lets say due to some bug local copy of the variable
fs_infowasn't initialized then we end up printing the same unknown <unknown>.Quoted 8 lines
Quoted 5 lines
So in the context of
device_list_add()as there is nofs_infogenuinely and be different from unknown we usebtrfs_info_in_rcu(NO_FS_INFO, ..)to get prefix something like..BTRFS info (device ...):
With the fixup to set
fs_infoto NULL on a device that's unmounted, do we still need theNO_FS_INFOstub?Its trivial we don't need
NO_FS_INFOIMO.Quoted 3 lines
The only difference I can see is a
to print "..." instead of "<unknown>" that I don't find too useful or improving the output.Agree. Two ways we can make it better one use open code. Patch [1] disk that.
[1]
[PATCH 1/2] btrfs: open code log helpers indevice_list_add()two, change
btrfs_printk()and all its wrapper to usefs_devicesinstead offs_info. It solves two purposes, device name does not make sense for logging of volume so will use fsid, and avoid confusion when the device errors are being reported. Secondly we could usebtrfs_printk()wrappers in the unmounted context. And added bonus is logging becomes truly consistent.
Let me know if you think this is the right way, will look into it.Quoted 4 lines
My idea about the stub fs info was to avoid any access to
fs_infoinsidedevice_list_addin case we can't reliably close the race where scan can readdevice::fs_infoduring mount that sets it up, but as I'm told it's not a problem anymore.Using NULL instead of
fs_infoor open code or usingfs_devices(as discussed above) will solve it.The analysis about the race needed few more information, so I am not sure.
My idea is to make it theoretically correct. Using uninitialized
fs_infoindevice_list_addis wrong.Thanks, Anand