mdadm/Detail: Can't show container name correctly when unpluging disks
PATCH 1/1 mdadm/Detail: Can't show container name correctly when unpluging disks
The test case is:
1. create one imsm container
2. create a raid5 device from the container
3. unplug two disks
4. mdadm --detail /dev/md126
[root@rhel85 ~]# mdadm -D /dev/md126/dev/md126:
Container : ��, member 0
The Detail function first gets container name by function map_dev_preferred. Then it tries to find which disks are available. In patch db5377883fef(It should be FAILED..) uses map_dev_preferred to find which disks are under /dev.
But now, the major/minor information comes from kernel space. map_dev_preferred malloc memory and init a device list when first be called by Detail. It can't find the device in the list by the major/minor. It free the memory and reinit the list.
The container name now points to an area tha has been freed. So the containt is a mess.
This patch replaces map_dev_preferred with access.
---
v2: use access rather than devid2kname
--- Detail.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
Detail.c +11 -8
@@ -351,14 +351,17 @@ int Detail(char *dev, struct context *c) avail =xcalloc (array.raid_disks,1 );for (d =0 ; d < array.raid_disks; d++) { -char *dv, *dv_rep; - dv =map_dev_preferred (disks[d*2 ].major, - disks[d*2 ].minor,0 , c->prefer); - dv_rep =map_dev_preferred (disks[d*2 +1 ].major, - disks[d*2 +1 ].minor,0 , c->prefer); - -if ((dv && (disks[d*2 ].state & (1 <<MD_DISK_SYNC ))) || - (dv_rep && (disks[d*2 +1 ].state & (1 <<MD_DISK_SYNC )))) { +char dv[32 ], dv_rep[32 ]; + +sprintf (dv,"/sys/dev/block/%d:%d" , + disks[d*2 ].major, disks[d*2 ].minor); +sprintf (dv_rep,"/sys/dev/block/%d:%d" , + disks[d*2 +1 ].major, disks[d*2 +1 ].minor); + +if ((!access (dv,R_OK ) && + (disks[d*2 ].state & (1 <<MD_DISK_SYNC ))) || + (!access (dv_rep,R_OK ) && + (disks[d*2 +1 ].state & (1 <<MD_DISK_SYNC )))) { avail_disks ++; avail[d] =1 ; }else
Signature · 1 line
2.7.5
Hi Xiao,
Detail.c int Detail(char *dev, struct context *c) · line 362
Quoted 9 lines · Xiao Ni
Detail.c +9
-0+char dv[32 ], dv_rep[32 ]; + +sprintf (dv,"/sys/dev/block/%d:%d" , + disks[d*2 ].major, disks[d*2 ].minor); +sprintf (dv_rep,"/sys/dev/block/%d:%d" , + disks[d*2+1].major, disks[d*2+1].minor);Please use snprintf and PATH_MAX instead 32. + + if ((!access(dv, R_OK) && + (disks[d*2].state & (1<<MD_DISK_SYNC))) ||
IMO not correct style, please verify with checkpatch. should be: [d * 2]
Detail.c int Detail(char *dev, struct context *c) · line 364
Quoted 2 lines
Detail.c +2
-0+ (!access(dv_rep, R_OK) && + (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) {
Could you define function for that?
something like (you can add access() verification if needed):is_dev_alive(mdu_disk_info_t *disk)
{
char *devnm = devid2kname(makedev..);
if (devnm)
return true;
return false;
}using true/false will require to add #include <stdbool.h>. Jes suggests to use meaningful return values. This is only suggestion so you can ignore it and use 0 and 1.
and then check:
if (is_dev_alive([d * 2]) & disks[d * 2].state & (1<<MD_DISK_SYNC) ||
(is_dev_alive([d * 2 + 1]) & disks[d * 2 + 1].state & (1<<MD_DISK_SYNC))
What do you think?
Thanks,
Mariusz
Quoted 14 lines · Mariusz
Hi Xiao,
Detail.c int Detail(char *dev, struct context *c) · line 362
Quoted 9 lines · Xiao Ni
Detail.c +9
-0+char dv[32 ], dv_rep[32 ]; + +sprintf (dv,"/sys/dev/block/%d:%d" , + disks[d*2 ].major, disks[d*2 ].minor); +sprintf (dv_rep,"/sys/dev/block/%d:%d" , + disks[d*2+1].major, disks[d*2+1].minor);Please use snprintf and PATH_MAX instead 32. + + if ((!access(dv, R_OK) && + (disks[d*2].state & (1<<MD_DISK_SYNC))) ||IMO not correct style, please verify with checkpatch. should be: [d * 2]
Hi Mariusz
I ran checkpatch before sending this patch. The checkpatch I used is from Song's git
(https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git). It only reports one warning
like this:
WARNING: Unknown commit id 'db5377883fef', maybe rebased or not pulled? #34:
total: 0 errors, 1 warnings, 25 lines checked
It's right. Because the commit is from mdadm git. Do we use different checkpatch?
Quoted 6 lines
Detail.c int Detail(char *dev, struct context *c) · line 364
Quoted 2 lines
Detail.c +2
-0+ (!access(dv_rep, R_OK) && + (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) {Could you define function for that?
something like (you can addaccess()verification if needed):is_dev_alive(mdu_disk_info_t *disk)
Quoted 6 lines
{
char *devnm = devid2kname(makedev..);
if (devnm)
return true;
return false;
}Sure, it sounds better. I'll do this in the next version.
Quoted 4 lines
using true/false will require to add #include <
stdbool.h>. Jes suggests to use meaningful return values. This is only suggestion so you can ignore it and use 0 and 1.
<stdbool.h> is a c++ header and it needs libstdc++-devel, I don't want to include one package only for using true/false.
Quoted 6 lines
and then check:
if (is_dev_alive([d * 2])& disks[d * 2].state & (1<<MD_DISK_SYNC) ||(is_dev_alive([d * 2 + 1]) & disks[d * 2 + 1].state & (1<<MD_DISK_SYNC))What do you think?
It's good for me.
Best Regards
Xiao
Quoted 8 lines · Xiao Ni
Quoted 4 lines
using true/false will require to add #include <
stdbool.h>. Jes suggests to use meaningful return values. This is only suggestion so you can ignore it and use 0 and 1.<
stdbool.h> is a c++ header and it needs libstdc++-devel, I don't want to include one package only for using true/false.
Hi all
Do you think the method is better?
typedef int bool
#define true 1
#define false 0
So we don't need to inlcuce <stdboo.h> and we can use true/false too. If we include <stdbool.h>, it needs to add the corresponding package in the spec file too to resolve dependency problems.
Regards
Xiao
Quoted 25 lines · Xiao Ni
Quoted 14 lines · Mariusz
Hi Xiao,
Detail.c int Detail(char *dev, struct context *c) · line 362
Quoted 9 lines · Xiao Ni
Detail.c +9
-0+char dv[32 ], dv_rep[32 ]; + +sprintf (dv,"/sys/dev/block/%d:%d" , + disks[d*2 ].major, disks[d*2 ].minor); +sprintf (dv_rep,"/sys/dev/block/%d:%d" , + disks[d*2+1].major, disks[d*2+1].minor);Please use snprintf and PATH_MAX instead 32. + + if ((!access(dv, R_OK) && + (disks[d*2].state & (1<<MD_DISK_SYNC))) ||IMO not correct style, please verify with checkpatch. should be: [d * 2]
Hi Mariusz
I ran checkpatch before sending this patch. The checkpatch I used is from Song's git
(https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git). It only reports one warning
like this:
Quoted 8 lines
WARNING: Unknown commit id '
db5377883fef', maybe rebased or not pulled? #34:Fixes db5377883fef (It should be FAILED when raid has)total: 0 errors, 1 warnings, 25 lines checked
It's right. Because the commit is from mdadm git. Do we use different checkpatch?
checkpatch is awful in general, but I agree with Mariusz, adding the spaces is a lot prettier.
Quoted 14 lines
Quoted 7 lines
Detail.c int Detail(char *dev, struct context *c) · line 364
Quoted 3 lines
Detail.c +2
-0+ (!access(dv_rep, R_OK) && + (disks[d*2+1].state & (1<<MD_DISK_SYNC)))) {Could you define function for that?
something like (you can addaccess()verification if needed):is_dev_alive(mdu_disk_info_t *disk)Quoted 6 lines
{ char *devnm = devid2kname(makedev..); if (devnm) return true; return false; }
Quoted 8 lines
Sure, it sounds better. I'll do this in the next version.
Quoted 4 lines
using true/false will require to add #include <
stdbool.h>. Jes suggests to use meaningful return values. This is only suggestion so you can ignore it and use 0 and 1.<
stdbool.h> is a c++ header and it needs libstdc++-devel, I don't want to include one package only for using true/false.
stdbool.h is provided by GCC directly on Fedora 33 it's /usr/lib/gcc/x86_64-redhat-linux/10/include/stdbool.h
Quoted 7 lines
Quoted 5 lines
and then check:
if (is_dev_alive([d * 2])& disks[d * 2].state & (1<<MD_DISK_SYNC) ||(is_dev_alive([d * 2 + 1]) & disks[d * 2 + 1].state & (1<<MD_DISK_SYNC))What do you think?
It's good for me.
I think using bool for this makes sense when the helper is called 'is_dev_alive()' (as much as I dislike the bool type).
Cheers,
Jes