All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] super1: replace hard-coded values with bit definitions
@ 2017-03-29  9:40 Gioh Kim
  2017-03-29  9:40 ` [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value" Gioh Kim
  2017-03-29 15:41 ` [PATCH 1/2] super1: replace hard-coded values with bit definitions jes.sorensen
  0 siblings, 2 replies; 9+ messages in thread
From: Gioh Kim @ 2017-03-29  9:40 UTC (permalink / raw)
  To: jes.sorensen; +Cc: neilb, linux-raid, linux-kernel, Gioh Kim

Some hard-coded values for disk status are replaced
with bit definitions.

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
---
 super1.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/super1.c b/super1.c
index f3520ac..e8b9f61 100644
--- a/super1.c
+++ b/super1.c
@@ -1010,7 +1010,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, char *map)
 		info->disk.state = 0; /* spare: not active, not sync, not faulty */
 		break;
 	case MD_DISK_ROLE_FAULTY:
-		info->disk.state = 1; /* faulty */
+		info->disk.state = (1 << MD_DISK_FAULTY); /* faulty */
 		break;
 	case MD_DISK_ROLE_JOURNAL:
 		info->disk.state = (1 << MD_DISK_JOURNAL);
@@ -1503,11 +1503,12 @@ static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
 	}
 
 	dk_state = dk->state & ~(1<<MD_DISK_FAILFAST);
-	if ((dk_state & 6) == 6) /* active, sync */
+	if ((dk_state & (1<<MD_DISK_ACTIVE)) &&
+	    (dk_state & (1<<MD_DISK_SYNC)))/* active, sync */
 		*rp = __cpu_to_le16(dk->raid_disk);
 	else if (dk_state & (1<<MD_DISK_JOURNAL))
                 *rp = MD_DISK_ROLE_JOURNAL;
-	else if ((dk_state & ~2) == 0) /* active or idle -> spare */
+	else if ((dk_state & ~(1<<MD_DISK_ACTIVE)) == 0) /* active or idle -> spare */
 		*rp = MD_DISK_ROLE_SPARE;
 	else
 		*rp = MD_DISK_ROLE_FAULTY;
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
  2017-03-29  9:40 [PATCH 1/2] super1: replace hard-coded values with bit definitions Gioh Kim
@ 2017-03-29  9:40 ` Gioh Kim
  2017-03-29 15:47   ` jes.sorensen
  2017-03-29 15:41 ` [PATCH 1/2] super1: replace hard-coded values with bit definitions jes.sorensen
  1 sibling, 1 reply; 9+ messages in thread
From: Gioh Kim @ 2017-03-29  9:40 UTC (permalink / raw)
  To: jes.sorensen; +Cc: neilb, linux-raid, linux-kernel, Gioh Kim

Remove a boolean expression in switch condition
to prevent compile error of some compilers.

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
---
 mdadm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mdadm.c b/mdadm.c
index 08ddcab..a98a051 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
 			rv |= SetAction(dv->devname, c->action);
 			continue;
 		}
-		switch(dv->devname[0] == '/') {
-			case 0:
+		switch(dv->devname[0]) {
+			default:
 				mdfd = open_dev(dv->devname);
 				if (mdfd >= 0) break;
-			case 1:
+			case '/':
 				mdfd = open_mddev(dv->devname, 1);  
 		}
 		if (mdfd>=0) {
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] super1: replace hard-coded values with bit definitions
  2017-03-29  9:40 [PATCH 1/2] super1: replace hard-coded values with bit definitions Gioh Kim
  2017-03-29  9:40 ` [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value" Gioh Kim
@ 2017-03-29 15:41 ` jes.sorensen
  1 sibling, 0 replies; 9+ messages in thread
From: jes.sorensen @ 2017-03-29 15:41 UTC (permalink / raw)
  To: Gioh Kim; +Cc: neilb, linux-raid, linux-kernel

Gioh Kim <gi-oh.kim@profitbricks.com> writes:
> Some hard-coded values for disk status are replaced
> with bit definitions.
>
> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
> ---
>  super1.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Applied!

Please use --cover-letter when you send out multi-commit patch sets,
which includes a short description of what the set includes. That way I
can just respond to the cover letter if all the patches are applied.

Thanks,
Jes

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
  2017-03-29  9:40 ` [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value" Gioh Kim
@ 2017-03-29 15:47   ` jes.sorensen
  2017-03-29 15:50     ` Gioh Kim
  2017-03-29 21:38       ` NeilBrown
  0 siblings, 2 replies; 9+ messages in thread
From: jes.sorensen @ 2017-03-29 15:47 UTC (permalink / raw)
  To: Gioh Kim; +Cc: neilb, linux-raid, linux-kernel

Gioh Kim <gi-oh.kim@profitbricks.com> writes:
> Remove a boolean expression in switch condition
> to prevent compile error of some compilers.

Please be specific, which compile is unable to handle this?

> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
> ---
>  mdadm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mdadm.c b/mdadm.c
> index 08ddcab..a98a051 100644
> --- a/mdadm.c
> +++ b/mdadm.c
> @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
>  			rv |= SetAction(dv->devname, c->action);
>  			continue;
>  		}
> -		switch(dv->devname[0] == '/') {
> -			case 0:
> +		switch(dv->devname[0]) {
> +			default:
>  				mdfd = open_dev(dv->devname);
>  				if (mdfd >= 0) break;
> -			case 1:
> +			case '/':
>  				mdfd = open_mddev(dv->devname, 1);  
>  		}
>  		if (mdfd>=0) {

While I agree the original code is ugly, I am not convinced your
replacement is a lot prettier.

Thanks,
Jes

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
  2017-03-29 15:47   ` jes.sorensen
@ 2017-03-29 15:50     ` Gioh Kim
  2017-03-29 21:38       ` NeilBrown
  1 sibling, 0 replies; 9+ messages in thread
From: Gioh Kim @ 2017-03-29 15:50 UTC (permalink / raw)
  To: jes.sorensen; +Cc: neilb, linux-raid, linux-kernel

On Wed, Mar 29, 2017 at 11:47:28AM -0400, jes.sorensen@gmail.com wrote:
> Gioh Kim <gi-oh.kim@profitbricks.com> writes:
> > Remove a boolean expression in switch condition
> > to prevent compile error of some compilers.
> 
> Please be specific, which compile is unable to handle this?
> 
> > Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
> > ---
> >  mdadm.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/mdadm.c b/mdadm.c
> > index 08ddcab..a98a051 100644
> > --- a/mdadm.c
> > +++ b/mdadm.c
> > @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
> >  			rv |= SetAction(dv->devname, c->action);
> >  			continue;
> >  		}
> > -		switch(dv->devname[0] == '/') {
> > -			case 0:
> > +		switch(dv->devname[0]) {
> > +			default:
> >  				mdfd = open_dev(dv->devname);
> >  				if (mdfd >= 0) break;
> > -			case 1:
> > +			case '/':
> >  				mdfd = open_mddev(dv->devname, 1);  
> >  		}
> >  		if (mdfd>=0) {
> 
> While I agree the original code is ugly, I am not convinced your
> replacement is a lot prettier.
> 

Yes, it's not elegant ;-)
Following is my compiler version and error message.

gohkim@ws00837:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
5.2.1-22ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-5 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib
--disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) 

gohkim@ws00837:~/work/tools/mdadm-mainstream$ make
cc -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter -ggdb
-DSendmail=\""/usr/sbin/sendmail -t"\" -DCONFFILE=\"/etc/mdadm.conf\"
-DCONFFILE2=\"/etc/mdadm/mdadm.conf\" -DMAP_DIR=\"/run/mdadm\"
-DMAP_FILE=\"map\" -DMDMON_DIR=\"/run/mdadm\"
-DFAILED_SLOTS_DIR=\"/run/mdadm/failed-slots\" -DNO_COROSYNC -DNO_DLM
-DVERSION=\"4.0-25-gddb13a5\" -DVERS_DATE="\"2017-03-29\"" -DUSE_PTHREADS
-DBINDIR=\"/sbin\"  -c -o mdadm.o mdadm.c
mdadm.c: In function ��misc_list��:
mdadm.c:1908:10: error: switch condition has boolean value
[-Werror=switch-bool]
   switch(dv->devname[0] == '/') {
             ^
             cc1: all warnings being treated as errors
             <builtin>: recipe for target 'mdadm.o' failed
             make: *** [mdadm.o] Error 1


-- 
Best regards,
Gi-Oh Kim
TEL: 0176 2697 8962

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
  2017-03-29 15:47   ` jes.sorensen
@ 2017-03-29 21:38       ` NeilBrown
  2017-03-29 21:38       ` NeilBrown
  1 sibling, 0 replies; 9+ messages in thread
From: NeilBrown @ 2017-03-29 21:38 UTC (permalink / raw)
  To: jes.sorensen, Gioh Kim; +Cc: linux-raid, linux-kernel, Wol

[-- Attachment #1: Type: text/plain, Size: 1211 bytes --]

On Thu, Mar 30 2017, jes.sorensen@gmail.com wrote:

> Gioh Kim <gi-oh.kim@profitbricks.com> writes:
>> Remove a boolean expression in switch condition
>> to prevent compile error of some compilers.
>
> Please be specific, which compile is unable to handle this?
>
>> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
>> ---
>>  mdadm.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/mdadm.c b/mdadm.c
>> index 08ddcab..a98a051 100644
>> --- a/mdadm.c
>> +++ b/mdadm.c
>> @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
>>  			rv |= SetAction(dv->devname, c->action);
>>  			continue;
>>  		}
>> -		switch(dv->devname[0] == '/') {
>> -			case 0:
>> +		switch(dv->devname[0]) {
>> +			default:
>>  				mdfd = open_dev(dv->devname);
>>  				if (mdfd >= 0) break;
>> -			case 1:
>> +			case '/':
>>  				mdfd = open_mddev(dv->devname, 1);  
>>  		}
>>  		if (mdfd>=0) {
>
> While I agree the original code is ugly, I am not convinced your
> replacement is a lot prettier.
>

Maybe

		if (dv->devname[0] == '/' ||
		    (mdfd = open_dev(dv->devname)) < 0)
				mdfd = open_mddev(dv->devname, 1);

??
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
@ 2017-03-29 21:38       ` NeilBrown
  0 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2017-03-29 21:38 UTC (permalink / raw)
  To: jes.sorensen, Gioh Kim; +Cc: linux-raid, linux-kernel, Wol

[-- Attachment #1: Type: text/plain, Size: 1211 bytes --]

On Thu, Mar 30 2017, jes.sorensen@gmail.com wrote:

> Gioh Kim <gi-oh.kim@profitbricks.com> writes:
>> Remove a boolean expression in switch condition
>> to prevent compile error of some compilers.
>
> Please be specific, which compile is unable to handle this?
>
>> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
>> ---
>>  mdadm.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/mdadm.c b/mdadm.c
>> index 08ddcab..a98a051 100644
>> --- a/mdadm.c
>> +++ b/mdadm.c
>> @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
>>  			rv |= SetAction(dv->devname, c->action);
>>  			continue;
>>  		}
>> -		switch(dv->devname[0] == '/') {
>> -			case 0:
>> +		switch(dv->devname[0]) {
>> +			default:
>>  				mdfd = open_dev(dv->devname);
>>  				if (mdfd >= 0) break;
>> -			case 1:
>> +			case '/':
>>  				mdfd = open_mddev(dv->devname, 1);  
>>  		}
>>  		if (mdfd>=0) {
>
> While I agree the original code is ugly, I am not convinced your
> replacement is a lot prettier.
>

Maybe

		if (dv->devname[0] == '/' ||
		    (mdfd = open_dev(dv->devname)) < 0)
				mdfd = open_mddev(dv->devname, 1);

??
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
  2017-03-29 21:38       ` NeilBrown
  (?)
@ 2017-03-30  7:52       ` Gioh Kim
  2017-03-30 15:53         ` Jes Sorensen
  -1 siblings, 1 reply; 9+ messages in thread
From: Gioh Kim @ 2017-03-30  7:52 UTC (permalink / raw)
  To: NeilBrown; +Cc: jes.sorensen, linux-raid, linux-kernel, Wol

On Thu, Mar 30, 2017 at 08:38:35AM +1100, NeilBrown wrote:
> On Thu, Mar 30 2017, jes.sorensen@gmail.com wrote:
> 
> > Gioh Kim <gi-oh.kim@profitbricks.com> writes:
> >> Remove a boolean expression in switch condition
> >> to prevent compile error of some compilers.
> >
> > Please be specific, which compile is unable to handle this?
> >
> >> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
> >> ---
> >>  mdadm.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/mdadm.c b/mdadm.c
> >> index 08ddcab..a98a051 100644
> >> --- a/mdadm.c
> >> +++ b/mdadm.c
> >> @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
> >>  			rv |= SetAction(dv->devname, c->action);
> >>  			continue;
> >>  		}
> >> -		switch(dv->devname[0] == '/') {
> >> -			case 0:
> >> +		switch(dv->devname[0]) {
> >> +			default:
> >>  				mdfd = open_dev(dv->devname);
> >>  				if (mdfd >= 0) break;
> >> -			case 1:
> >> +			case '/':
> >>  				mdfd = open_mddev(dv->devname, 1);  
> >>  		}
> >>  		if (mdfd>=0) {
> >
> > While I agree the original code is ugly, I am not convinced your
> > replacement is a lot prettier.
> >
> 
> Maybe
> 
> 		if (dv->devname[0] == '/' ||
> 		    (mdfd = open_dev(dv->devname)) < 0)
> 				mdfd = open_mddev(dv->devname, 1);
> 
> ??
> NeilBrown

Yes, the initial version I thought was:

if (dev->devname[0] != '/')
    mdfd = open_dev(dv->devname);
if (dev->devname[0] == '/' || mdfd < 0)
    mdfd = open_mddev(dv->devname, 1);

But I thought you have a reason to use switch-case expression,
so I kept switch-case.
If you agree, I'll send v2 patch using if-expression.

-- 
Best regards,
Gi-Oh Kim
TEL: 0176 2697 8962

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value"
  2017-03-30  7:52       ` Gioh Kim
@ 2017-03-30 15:53         ` Jes Sorensen
  0 siblings, 0 replies; 9+ messages in thread
From: Jes Sorensen @ 2017-03-30 15:53 UTC (permalink / raw)
  To: Gioh Kim, NeilBrown; +Cc: linux-raid, linux-kernel, Wol

On 03/30/2017 03:52 AM, Gioh Kim wrote:
> On Thu, Mar 30, 2017 at 08:38:35AM +1100, NeilBrown wrote:
>> On Thu, Mar 30 2017, jes.sorensen@gmail.com wrote:
>>
>>> Gioh Kim <gi-oh.kim@profitbricks.com> writes:
>>>> Remove a boolean expression in switch condition
>>>> to prevent compile error of some compilers.
>>>
>>> Please be specific, which compile is unable to handle this?
>>>
>>>> Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
>>>> ---
>>>>  mdadm.c | 6 +++---
>>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/mdadm.c b/mdadm.c
>>>> index 08ddcab..a98a051 100644
>>>> --- a/mdadm.c
>>>> +++ b/mdadm.c
>>>> @@ -1905,11 +1905,11 @@ static int misc_list(struct mddev_dev *devlist,
>>>>  			rv |= SetAction(dv->devname, c->action);
>>>>  			continue;
>>>>  		}
>>>> -		switch(dv->devname[0] == '/') {
>>>> -			case 0:
>>>> +		switch(dv->devname[0]) {
>>>> +			default:
>>>>  				mdfd = open_dev(dv->devname);
>>>>  				if (mdfd >= 0) break;
>>>> -			case 1:
>>>> +			case '/':
>>>>  				mdfd = open_mddev(dv->devname, 1);
>>>>  		}
>>>>  		if (mdfd>=0) {
>>>
>>> While I agree the original code is ugly, I am not convinced your
>>> replacement is a lot prettier.
>>>
>>
>> Maybe
>>
>> 		if (dv->devname[0] == '/' ||
>> 		    (mdfd = open_dev(dv->devname)) < 0)
>> 				mdfd = open_mddev(dv->devname, 1);
>>
>> ??
>> NeilBrown
>
> Yes, the initial version I thought was:
>
> if (dev->devname[0] != '/')
>     mdfd = open_dev(dv->devname);
> if (dev->devname[0] == '/' || mdfd < 0)
>     mdfd = open_mddev(dv->devname, 1);
>
> But I thought you have a reason to use switch-case expression,
> so I kept switch-case.
> If you agree, I'll send v2 patch using if-expression.
>

I like this solution better, I much favor code that is more explicit in 
what it does. Request less brain capacity for me to read :)

Cheers,
Jes

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-03-30 15:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29  9:40 [PATCH 1/2] super1: replace hard-coded values with bit definitions Gioh Kim
2017-03-29  9:40 ` [PATCH 2/2] mdadm.c: fix compile error "switch condition has boolean value" Gioh Kim
2017-03-29 15:47   ` jes.sorensen
2017-03-29 15:50     ` Gioh Kim
2017-03-29 21:38     ` NeilBrown
2017-03-29 21:38       ` NeilBrown
2017-03-30  7:52       ` Gioh Kim
2017-03-30 15:53         ` Jes Sorensen
2017-03-29 15:41 ` [PATCH 1/2] super1: replace hard-coded values with bit definitions jes.sorensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.