mdadm:checking level once mode has been set
cover mdadm:checking level once mode has been set
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level. such as:
./mdadm -CR /dev/md0 -b internal -n2 -x1 /dev/loop[0-2]
Create.c +0 -4
@@ -125,10 +125,6 @@ int Create(struct supertype *st, char *mddev,memset (&info,0 ,sizeof (info));if (s->level == UnSet && st && st->ss->default_geometry) st->ss->default_geometry (st, &s->level,NULL ,NULL ); -if (s->level == UnSet) { -pr_err ("a RAID level is needed to create an array.\n" ); -return 1 ; - }if (s->raiddisks <4 && s->level ==6 ) {pr_err ("at least 4 raid-devices needed for level 6\n" );return 1 ;
mdadm.c +6 -0
@@ -350,6 +350,12 @@ int main(int argc, char *argv[])pr_err ("Must give -a/--add for devices to add: %s\n" , optarg);exit (2 ); } +if (devs_found >0 && s.level == UnSet && !devmode) { +if (mode ==CREATE || mode ==BUILD ) { +pr_err ("a RAID level is needed to create or build an array.\n" ); +exit (2 ); + } + } dv =xmalloc (sizeof (*dv)); dv->devname = optarg; dv->disposition = devmode;
Signature · 1 line
2.10.2
PATCH 1/4 mdadm:bitmap cannot be set twice
mdadm:it doesn't make sense to set bitmap twice.
mdadm.c +4 -0
@@ -1137,6 +1137,10 @@ int main(int argc, char *argv[])case O (CREATE ,Bitmap):/* here we create the bitmap */ case O (GROW ,'b' ):case O (GROW ,Bitmap): +if (s.bitmap_file) { +pr_err ("bitmap cannot be set twice. Second value: %s.\n" , optarg); +exit (2 ); + }if (strcmp (optarg,"internal" ) ==0 ||strcmp (optarg,"none" ) ==0 ||strchr (optarg,'/' ) !=NULL ) {
Signature · 1 line
2.10.2
PATCH 5/5 mdadm:checking level once mode has been set
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level parameter. such as:
./mdadm -CR /dev/md0 -b internal -n2 -x1 /dev/loop[0-2]
Create.c +0 -4
@@ -125,10 +125,6 @@ int Create(struct supertype *st, char *mddev,memset (&info,0 ,sizeof (info));if (s->level == UnSet && st && st->ss->default_geometry) st->ss->default_geometry (st, &s->level,NULL ,NULL ); -if (s->level == UnSet) { -pr_err ("a RAID level is needed to create an array.\n" ); -return 1 ; - }if (s->raiddisks <4 && s->level ==6 ) {pr_err ("at least 4 raid-devices needed for level 6\n" );return 1 ;
mdadm.c +6 -0
@@ -349,6 +349,12 @@ int main(int argc, char *argv[])pr_err ("Must give -a/--add for devices to add: %s\n" , optarg);exit (2 ); } +if (devs_found >0 && s.level == UnSet && !devmode) { +if (mode ==CREATE || mode ==BUILD ) { +pr_err ("a RAID level is needed to create or build an array.\n" ); +exit (2 ); + } + } dv =xmalloc (sizeof (*dv)); dv->devname = optarg; dv->disposition = devmode;
Signature · 1 line
2.10.2
PATCH 2/4 mdadm:external bitmap only supports ext filesystem
In reply to Zhilong Liumdadm: ensure that the external bitmap_file is stored by ext[2-4] file system, because bmap() of linux/driver/md/bitmap.c exits directly when the bitmap_file isn't suitable. mdadm should make users aware of this scenario and give a prompt.
Create.c +0 -5
@@ -831,11 +831,6 @@ int Create(struct supertype *st, char *mddev, goto abort_locked; } bitmap_fd =open (s->bitmap_file,O_RDWR ); -if (bitmap_fd <0 ) { -pr_err ("weird: %s cannot be openned\n" , - s->bitmap_file); - goto abort_locked; - }if (ioctl (mdfd,SET_BITMAP_FILE , bitmap_fd) <0 ) {pr_err ("Cannot set bitmap file for %s: %s\n" , mddev,strerror (errno));
mdadm.c +16 -0
@@ -28,6 +28,7 @@#include "mdadm.h" #include "md_p.h" #include <ctype.h> +#include <sys/vfs.h> static int scan_assemble(struct supertype *ss, struct context *c,
@@ -1143,6 +1144,21 @@ int main(int argc, char *argv[]) strcmp(optarg, "none") == 0 || strchr(optarg, '/') != NULL) { s.bitmap_file = optarg; +if (strchr (s.bitmap_file,'/' ) !=NULL ) { + bitmap_fd =open (s.bitmap_file,O_RDWR ); +if (bitmap_fd <0 ) { +pr_err ("weird: %s cannot be openned\n" , s.bitmap_file); +exit (2 ); + } +close (bitmap_fd); +struct statfs ext_bitmap; +statfs (s.bitmap_file, &ext_bitmap); +if (ext_bitmap.f_type !=0xEF53 ){ +pr_err ("external bitmap only supports ext[2-4] filesystem, %s.\n" , + s.bitmap_file); +exit (2 ); + } + }continue ; }if (strcmp (optarg,"clustered" ) ==0 ) {
Signature · 1 line
2.10.2
Re: [PATCH 2/4] mdadm:external bitmap only supports ext filesystem
as this patch's purpose, just wanna improve the prompt when using the
external bitmap mode, and this patch maybe a little redundant.
For the errno rule, RUN_ARRAY returned EINVAL indeed and the man page
has indicated that external bitmap only works with ext[2-4] file system.
I think it would be more user-friendly if prints one prompt and
returned
EINVAL at the same time when the bmap() got failure.
Such as:
drivers/md/bitmap.c +1 -0
@@ -381,6 +381,7 @@ static int read_page(struct file *file, unsigned long index, bh->b_blocknr =bmap (inode, block);if (bh->b_blocknr ==0 ) {/* Cannot use this file! */ +pr_err ("The external bitmap only works with ext[2-4] filesystem.\n" ); ret = -EINVAL ; goto out; }
Thanks,
-Zhilong
Quoted 58 lines · Zhilong Liu
mdadm: ensure that the external
bitmap_fileis stored by ext[2-4] file system, becausebmap()oflinux/driver/md/bitmap.cexits directly when thebitmap_fileisn't suitable. mdadm should make users aware of this scenario and give a prompt.Signed-off-by Zhilong Liu <[email protected]>Create.c +0
-5@@ -831,11 +831,6 @@ int Create(struct supertype *st, char *mddev, goto abort_locked; } bitmap_fd =open (s->bitmap_file,O_RDWR ); -if (bitmap_fd <0 ) { -pr_err ("weird: %s cannot be openned\n" , - s->bitmap_file); - goto abort_locked; - }if (ioctl (mdfd,SET_BITMAP_FILE , bitmap_fd) <0 ) {pr_err ("Cannot set bitmap file for %s: %s\n" , mddev,strerror (errno));mdadm.c +16
-0@@ -28,6 +28,7 @@#include "mdadm.h" #include "md_p.h" #include <ctype.h> +#include <sys/vfs.h> static int scan_assemble(struct supertype *ss, struct context *c,@@ -1143,6 +1144,21 @@ int main(int argc, char *argv[]) strcmp(optarg, "none") == 0 || strchr(optarg, '/') != NULL) { s.bitmap_file = optarg; +if (strchr (s.bitmap_file,'/' ) !=NULL ) { + bitmap_fd =open (s.bitmap_file,O_RDWR ); +if (bitmap_fd <0 ) { +pr_err ("weird: %s cannot be openned\n" , s.bitmap_file); +exit (2 ); + } +close (bitmap_fd); +struct statfs ext_bitmap; +statfs (s.bitmap_file, &ext_bitmap); +if (ext_bitmap.f_type !=0xEF53 ){ +pr_err ("external bitmap only supports ext[2-4] filesystem, %s.\n" , + s.bitmap_file); +exit (2 ); + } + }continue ; }if (strcmp (optarg,"clustered" ) ==0 ) {
Re: [PATCH 2/4] mdadm:external bitmap only supports ext filesystem
In reply to Zhilong Liu as the purpose to improve the prompt when using the external bitmap
mode, maybe push this patch to mdadm is a little redundant.
For errno rule, RUN_ARRAY returned EINVAL indeed and the man-page
has indicated that external bitmap only works with ext[2-4] file system.
I think it would be more user-friendly if prints one prompt and
returned
EINVAL at the same time when the bmap() got failure, so that user knows where the EINVAL comes.
Such as:
drivers/md/bitmap.c +1 -0
@@ -381,6 +381,7 @@ static int read_page(struct file *file, unsigned long index, bh->b_blocknr =bmap (inode, block);if (bh->b_blocknr ==0 ) {/* Cannot use this file! */ +pr_err ("writing external bitmap only supports a file under ext[2-4] filesystem.\n" ); ret = -EINVAL ; goto out; }
Thanks,
-Zhilong
Quoted 58 lines · Zhilong Liu
mdadm: ensure that the external
bitmap_fileis stored by ext[2-4] file system, becausebmap()oflinux/driver/md/bitmap.cexits directly when thebitmap_fileisn't suitable. mdadm should make users aware of this scenario and give a prompt.Signed-off-by Zhilong Liu <[email protected]>Create.c +0
-5@@ -831,11 +831,6 @@ int Create(struct supertype *st, char *mddev, goto abort_locked; } bitmap_fd =open (s->bitmap_file,O_RDWR ); -if (bitmap_fd <0 ) { -pr_err ("weird: %s cannot be openned\n" , - s->bitmap_file); - goto abort_locked; - }if (ioctl (mdfd,SET_BITMAP_FILE , bitmap_fd) <0 ) {pr_err ("Cannot set bitmap file for %s: %s\n" , mddev,strerror (errno));mdadm.c +16
-0@@ -28,6 +28,7 @@#include "mdadm.h" #include "md_p.h" #include <ctype.h> +#include <sys/vfs.h> static int scan_assemble(struct supertype *ss, struct context *c,@@ -1143,6 +1144,21 @@ int main(int argc, char *argv[]) strcmp(optarg, "none") == 0 || strchr(optarg, '/') != NULL) { s.bitmap_file = optarg; +if (strchr (s.bitmap_file,'/' ) !=NULL ) { + bitmap_fd =open (s.bitmap_file,O_RDWR ); +if (bitmap_fd <0 ) { +pr_err ("weird: %s cannot be openned\n" , s.bitmap_file); +exit (2 ); + } +close (bitmap_fd); +struct statfs ext_bitmap; +statfs (s.bitmap_file, &ext_bitmap); +if (ext_bitmap.f_type !=0xEF53 ){ +pr_err ("external bitmap only supports ext[2-4] filesystem, %s.\n" , + s.bitmap_file); +exit (2 ); + } + }continue ; }if (strcmp (optarg,"clustered" ) ==0 ) {
PATCH 3/4 mdadm:triggers core dump when stat2devnm return NULL
In reply to Zhilong Liuensure that the device should be a block device when uses --wait parameter, such as the 'f' and 'd' type file would be triggered core dumped.
./mdadm --wait /dev/md/, happened core dump.
Monitor.c +4 -0
@@ -1002,6 +1002,10 @@ int Wait(char *dev) strerror(errno));return 2 ; } +if ((S_IFMT & stb.st_mode) !=S_IFBLK ) { +pr_err ("%s is not a block device.\n" , dev); +return 2 ; + }strcpy (devnm,stat2devnm (&stb));while (1 ) {
lib.c +0 -3
@@ -89,9 +89,6 @@ char *devid2kname(int devid)char *stat2kname (struct stat *st) { -if ((S_IFMT & st->st_mode) !=S_IFBLK ) -return NULL ; -return devid2kname (st->st_rdev); }
Signature · 1 line
2.10.2
Re: [PATCH 3/4] mdadm:triggers core dump when stat2devnm return NULL
Quoted 12 lines · Zhilong Liu
ensure that the device should be a block device when uses --wait parameter, such as the 'f' and 'd' type file would be triggered core dumped.
./mdadm --wait/dev/md/, happened core dump.Signed-off-by Zhilong Liu <[email protected]>Monitor.c +0
-0
Monitor.c int Wait(char *dev) · line 1009
Quoted 8 lines
Monitor.c +4
-0@@ -1002,6 +1002,10 @@ int Wait(char *dev) strerror(errno));return 2 ; } +if ((S_IFMT & stb.st_mode) !=S_IFBLK ) { +pr_err ("%s is not a block device.\n" , dev); +return 2 ; + }strcpy (devnm,stat2devnm (&stb));
Surely it would be cleaner to do something like:
tmp = stat2devnm(&stb);
if (!tmp) {
pr_err("%s is not a block device.\n", dev);
return 2;
}
strcpy(devnm, tmp);This makes it more obvious how you have fixed the crash.
Quoted 7 lines
Monitor.c +0
-0while (1 ) {lib.c +0
-0
lib.c char *devid2kname(int devid) · line 93
Quoted 8 lines
lib.c +0
-3@@ -89,9 +89,6 @@ char *devid2kname(int devid)char *stat2kname (struct stat *st) { -if ((S_IFMT & st->st_mode) !=S_IFBLK ) -return NULL ; -return devid2kname (st->st_rdev); }
Why are you removing this test? It has nothing to do with the other part of the patch.
NeilBrown
Re: [PATCH 3/4] mdadm:triggers core dump when stat2devnm return NULL
Quoted 24 lines · NeilBrown
Quoted 12 lines · Zhilong Liu
ensure that the device should be a block device when uses --wait parameter, such as the 'f' and 'd' type file would be triggered core dumped.
./mdadm --wait/dev/md/, happened core dump.Signed-off-by Zhilong Liu <[email protected]>Monitor.c +0
-0Monitor.c int Wait(char *dev) · line 1009
Quoted 8 lines
Monitor.c +4
-0@@ -1002,6 +1002,10 @@ int Wait(char *dev) strerror(errno));return 2 ; } +if ((S_IFMT & stb.st_mode) !=S_IFBLK ) { +pr_err ("%s is not a block device.\n" , dev); +return 2 ; + }strcpy (devnm,stat2devnm (&stb));Surely it would be cleaner to do something like:
Quoted 8 lines
tmp = stat2devnm(&stb); if (!tmp) { pr_err("%s is not a block device.\n", dev); return 2; } strcpy(devnm, tmp);This makes it more obvious how you have fixed the crash.
Yes, this method is much better than I did. Great thanks for your improvement.
Quoted 8 lines
Quoted 8 lines
Monitor.c +0
-0while (1 ) {lib.c +0
-0@@ -89,9 +89,6 @@ char *devid2kname(int devid)
Quoted 9 lines
lib.c char *devid2kname(int devid) · line 93
Quoted 7 lines
lib.c +0
-3char *stat2kname (struct stat *st) { -if ((S_IFMT & st->st_mode) !=S_IFBLK ) -return NULL ; -return devid2kname (st->st_rdev); }Why are you removing this test? It has nothing to do with the other part of the patch.
Yes, I would remove this part in next revision.
Thanks,
-Zhilong
Quoted 1 line
NeilBrown
PATCH 3/4 mdadm:triggers core dump when stat2devnm return NULL
In reply to NeilBrownmonitor: ensure that the device should be a block device when uses --wait parameter, such as the 'f' and 'd' type file would be triggered core dumped. ./mdadm --wait /dev/md/, happened core dump.
--- Monitor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Monitor.c +6 -1
@@ -1002,7 +1002,12 @@ int Wait(char *dev) strerror(errno));return 2 ; } -strcpy (devnm,stat2devnm (&stb)); +char *tmp =stat2devnm (&stb); +if (!tmp) { +pr_err ("%s is not a block device.\n" , dev); +return 2 ; + } +strcpy (devnm, tmp);while (1 ) {struct mdstat_ent *ms =mdstat_read (1 ,0 );
Signature · 1 line
2.6.6
Quoted 4 lines · Zhilong Liu
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level. such as:
./mdadm -CR/dev/md0-b internal -n2 -x1 /dev/loop[0-2]
When I run that command I get:
mdadm: a RAID level is needed to create an array.
What do you get?
NeilBrown
Quoted 42 lines
Signed-off-by Zhilong Liu <[email protected]>Create.c +0
-4@@ -125,10 +125,6 @@ int Create(struct supertype *st, char *mddev,memset (&info,0 ,sizeof (info));if (s->level == UnSet && st && st->ss->default_geometry) st->ss->default_geometry (st, &s->level,NULL ,NULL ); -if (s->level == UnSet) { -pr_err ("a RAID level is needed to create an array.\n" ); -return 1 ; - }if (s->raiddisks <4 && s->level ==6 ) {pr_err ("at least 4 raid-devices needed for level 6\n" );return 1 ;mdadm.c +6
-0@@ -350,6 +350,12 @@ int main(int argc, char *argv[])pr_err ("Must give -a/--add for devices to add: %s\n" , optarg);exit (2 ); } +if (devs_found >0 && s.level == UnSet && !devmode) { +if (mode ==CREATE || mode ==BUILD ) { +pr_err ("a RAID level is needed to create or build an array.\n" ); +exit (2 ); + } + } dv =xmalloc (sizeof (*dv)); dv->devname = optarg; dv->disposition = devmode;Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · NeilBrown
Quoted 4 lines · Zhilong Liu
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level. such as:
./mdadm -CR/dev/md0-b internal -n2 -x1 /dev/loop[0-2]
Quoted 6 lines
When I run that command I get:
mdadm: a RAID level is needed to create an array.
What do you get?
I'm sorry I have provided the wrong command, for this scenario, issues "mdadm --build /dev/md0 -n2 /dev/loop[0-1]" should be proper. it's the purpose to check --level earlier.
If this patch is useful, I would send the v1 patch for it, correct the comments.
Thanks,
-Zhilong
Quoted 44 lines
NeilBrown
Quoted 41 lines
Signed-off-by Zhilong Liu <[email protected]>Create.c +0
-4@@ -125,10 +125,6 @@ int Create(struct supertype *st, char *mddev,memset (&info,0 ,sizeof (info));if (s->level == UnSet && st && st->ss->default_geometry) st->ss->default_geometry (st, &s->level,NULL ,NULL ); -if (s->level == UnSet) { -pr_err ("a RAID level is needed to create an array.\n" ); -return 1 ; - }if (s->raiddisks <4 && s->level ==6 ) {pr_err ("at least 4 raid-devices needed for level 6\n" );return 1 ;mdadm.c +6
-0@@ -350,6 +350,12 @@ int main(int argc, char *argv[])pr_err ("Must give -a/--add for devices to add: %s\n" , optarg);exit (2 ); } +if (devs_found >0 && s.level == UnSet && !devmode) { +if (mode ==CREATE || mode ==BUILD ) { +pr_err ("a RAID level is needed to create or build an array.\n" ); +exit (2 ); + } + } dv =xmalloc (sizeof (*dv)); dv->devname = optarg; dv->disposition = devmode;Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · zhilong
Quoted 8 lines · NeilBrown
Quoted 4 lines · Zhilong Liu
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level. such as:
./mdadm -CR/dev/md0-b internal -n2 -x1 /dev/loop[0-2]When I run that command I get:
Quoted 8 lines
Quoted 4 lines
mdadm: a RAID level is needed to create an array.
What do you get?
I'm sorry I have provided the wrong command, for this scenario, issues "mdadm --build
/dev/md0-n2 /dev/loop[0-1]" should be proper. it's the purpose to check --level earlier.
OK, that makes sense.
Quoted 3 lines
If this patch is useful, I would send the v1 patch for it, correct the comments.
My preference would be to have the check in Build.c, but Jes might have different ideas.
NeilBrown
Quoted 18 lines · NeilBrown
Quoted 9 lines · zhilong
Quoted 8 lines · NeilBrown
Quoted 4 lines · Zhilong Liu
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level. such as:
./mdadm -CR/dev/md0-b internal -n2 -x1 /dev/loop[0-2]When I run that command I get:
Quoted 7 lines
Quoted 4 lines
mdadm: a RAID level is needed to create an array.
What do you get?
I'm sorry I have provided the wrong command, for this scenario, issues "mdadm --build
/dev/md0-n2 /dev/loop[0-1]" should be proper. it's the purpose to check --level earlier.
Quoted 6 lines
OK, that makes sense.
Quoted 2 lines
If this patch is useful, I would send the v1 patch for it, correct the comments.
My preference would be to have the check in
Build.c, but Jes might have different ideas.
copy that, thanks very much.
Best regards,
-Zhilong
Quoted 1 line
NeilBrown
Quoted 6 lines · Zhilong Liu
mdadm: it would be better to check --level ealier, because it would fall to different prompt if user forgets to specify the --level. such as:
./mdadm -CR/dev/md0-b internal -n2 -x1 /dev/loop[0-2]Signed-off-by Zhilong Liu <[email protected]>
This patchset is completely messed up - 0/4 contains actual code instead of being a cover letter. 5/5 is a reply to 1/4 and you posted a v1 of something which I assume needs to be the v2 given the v1 is the original posting.
Would you mind sending out a clean set of these patches?
Thanks,
Jes