Discussion:
[Ipmitool-devel] Code Review - ID: 86 - Add support for enable/disable PEF policy entries
Zdenek Styblik
2013-12-09 08:51:03 UTC
Permalink
Hello Jordan,

since SF.net kinda sucks, let's do code review over e-mail.

~~~
+<<<<<<< ipmi_mc.h
+/* IPMI 2.0 command for system information*/
[...]
+=======
[...]
+>>>>>>> 1.12
~~~

Errr ... what???

~~~
+int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
+ int len, void *buffer);
+int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
~~~

If you want to make these available outside of 'lib/ipmi_mc.c', then
names of these functions must be 'ipmi_mc_...'. Therefore, two
steps/tickets are required. One is to change names of these functions
and second is the one under discussion.

~~~
+#define IPMI_CMD_SET_PEF_CONFIG_PARMS 0x12
+struct pef_cfgparm_set_policy_table_entry
+{
+ uint8_t id;
+ uint8_t sel;
+ struct pef_policy_entry entry;
+} ATTRIBUTE_PACKING;
~~~

Such things go into header file. Also, where is check whether
ATTRIBUTE_PACKING is supported/defined? What if it isn't???

~~~
+ rsp = ipmi_pef_msg_exchange(intf, &req, "Set Alert policy table entry");
+ if (!rsp) {
+ lprintf(LOG_ERR, " **Error setting Alert policy table entry");
+ return -1;
+ }
+ return 0;
~~~

No check for ccode? Huh?

~~~
+static void
+ipmi_pef_policy_enable(struct ipmi_intf * intf, int set, int enable)
+{
~~~

No, this function *returns* integer.

~~~
+ if (ptbl) {
+ free(ptbl);
+ }
~~~

You've missed ``ptbl = NULL;'' there.

~~~
+ if (set > 0 && set <= tbl_size) {
[...]
+ } else {
+ lprintf(LOG_ERR, "Invalid policy index, valid range =
(1..%d)", tbl_size);
+ }
~~~

Invert ``if'' and return early.

~~~
+static struct valstr endis[] = {
+ { .str = "enable", .val = 0x01 },
+ { .str = "disable", .val = 0x00 },
+ { .val = -1 },
+};
+
~~~

No, use strcmp()/strncmp() or whatever.

~~~
+ else if (!strncmp(argv[0], "setpolicy", 6)) {
~~~

Now, I'm not exactly fond of adding 'setpolicy'. How about to give
'pef' a bit of thought and redesign 'pef' cli interface? I find it
rather, well, not good, to be honest. And this isn't making it any
better.
I can only wonder why there isn't something like 'pef list
<policy|entry>' instead of 'policy' which lists policies and 'list'
which list entries. I'm sorry, but it makes no sense.

~~~
+ if (argc > 2) {
+ str2int(argv[1], &set);
~~~

A good one. :)

Also, please, read
http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
code formatting in your patch.

Best regards,
Z.

--
Zdenek Styblik
email: ***@gmail.com
jabber: ***@gmail.com
J***@Dell.com
2013-12-09 18:05:30 UTC
Permalink
Ok thanks for the update.. see below. @@@

--jordan hargrave
Dell Enterprise Linux Engineering
________________________________________
From: Zdenek Styblik [***@gmail.com]
Sent: Monday, December 09, 2013 2:51 AM
To: Hargrave, Jordan
Cc: ipmitool-devel
Subject: Code Review - ID: 86 - Add support for enable/disable PEF policy entries

Hello Jordan,

since SF.net kinda sucks, let's do code review over e-mail.

~~~
+<<<<<<< ipmi_mc.h
+/* IPMI 2.0 command for system information*/
[...]
+=======
[...]
+>>>>>>> 1.12
~~~

Errr ... what???

@@@oops. not sure how that got there. I did a cvs up of my source tree and merged back in my changes in ipmi_pef.c and ipmitool.1 only.

~~~
+int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
+ int len, void *buffer);
+int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
~~~

If you want to make these available outside of 'lib/ipmi_mc.c', then
names of these functions must be 'ipmi_mc_...'. Therefore, two
steps/tickets are required. One is to change names of these functions
and second is the one under discussion.

@@@See above. Those functions are already in the existing .h file

~~~
+#define IPMI_CMD_SET_PEF_CONFIG_PARMS 0x12
+struct pef_cfgparm_set_policy_table_entry
+{
+ uint8_t id;
+ uint8_t sel;
+ struct pef_policy_entry entry;
+} ATTRIBUTE_PACKING;
~~~

Such things go into header file. Also, where is check whether
ATTRIBUTE_PACKING is supported/defined? What if it isn't???

@@@ ATTRIBUTE_PACKING is used in many other places so I assume that is the correct way.

~~~
+ rsp = ipmi_pef_msg_exchange(intf, &req, "Set Alert policy table entry");
+ if (!rsp) {
+ lprintf(LOG_ERR, " **Error setting Alert policy table entry");
+ return -1;
+ }
+ return 0;
~~~

No check for ccode? Huh?

@@@ ccode is already checked in ipmi_pef_msg_exchange

~~~
+static void
+ipmi_pef_policy_enable(struct ipmi_intf * intf, int set, int enable)
+{
~~~

No, this function *returns* integer.

@@@ should it? the other pef (ipmi_pef_list_policies) etc do not.

~~~
+ if (ptbl) {
+ free(ptbl);
+ }
~~~

You've missed ``ptbl = NULL;'' there.

@@@ do you mean if (ptbl != NULL)

~~~
+ if (set > 0 && set <= tbl_size) {
[...]
+ } else {
+ lprintf(LOG_ERR, "Invalid policy index, valid range =
(1..%d)", tbl_size);
+ }
~~~

Invert ``if'' and return early.

@@@ ok, can do that.

~~~
+static struct valstr endis[] = {
+ { .str = "enable", .val = 0x01 },
+ { .str = "disable", .val = 0x00 },
+ { .val = -1 },
+};
+
~~~

No, use strcmp()/strncmp() or whatever.

@@@ ok can do that. but str2val is also used with argv[] elsewhere in the code.

~~~
+ else if (!strncmp(argv[0], "setpolicy", 6)) {
~~~

Now, I'm not exactly fond of adding 'setpolicy'. How about to give
'pef' a bit of thought and redesign 'pef' cli interface? I find it
rather, well, not good, to be honest. And this isn't making it any
better.
I can only wonder why there isn't something like 'pef list
<policy|entry>' instead of 'policy' which lists policies and 'list'
which list entries. I'm sorry, but it makes no sense.

~~~
+ if (argc > 2) {
+ str2int(argv[1], &set);
~~~

A good one. :)

@@@ str2int is used elsewhere in the code as well

Also, please, read
http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
code formatting in your patch.

Best regards,
Z.

--
Zdenek Styblik
email: ***@gmail.com
jabber: ***@gmail.com
Zdenek Styblik
2013-12-09 18:24:51 UTC
Permalink
> @@@oops. not sure how that got there. I did a cvs up of my source tree and merged back in my changes in ipmi_pef.c and ipmitool.1 only.

Alright.

>
> ~~~
> +int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
> + int len, void *buffer);
> +int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
> ~~~
[...]
> @@@See above. Those functions are already in the existing .h file

Yes, they do. And they're prefixed as I've said. Therefore I'm a bit
confused what were you actually doing there.

>
> Such things go into header file. Also, where is check whether
> ATTRIBUTE_PACKING is supported/defined? What if it isn't???
>
> @@@ ATTRIBUTE_PACKING is used in many other places so I assume that is the correct way.
>

Indeed it is, but it's conditional. Check other header files and
copy-paste, because that's the correct way if you want attribute
packing.

> @@@ ccode is already checked in ipmi_pef_msg_exchange

Ok.

> @@@ should it? the other pef (ipmi_pef_list_policies) etc do not.

Yes, it definitely should.

>
> ~~~
> + if (ptbl) {
> + free(ptbl);
> + }
> ~~~
>
> You've missed ``ptbl = NULL;'' there.
>
> @@@ do you mean if (ptbl != NULL)

No, I meant:

~~~
if (ptbl) {
free(ptbl);
ptbl = NULL;
}
~~~

[...]
> ~~~
> +static struct valstr endis[] = {
> + { .str = "enable", .val = 0x01 },
> + { .str = "disable", .val = 0x00 },
> + { .val = -1 },
> +};
> +
> ~~~
>
> No, use strcmp()/strncmp() or whatever.
>
> @@@ ok can do that. but str2val is also used with argv[] elsewhere in the code.
>

Yes, it's and I don't want to see more of it. You don't have to repeat
every stupid/silly thing somebody else did in the code ;)

[...]
> A good one. :)
>
> @@@ str2int is used elsewhere in the code as well

Ok, I'll be more specific. You don't bother with checking return code.

Z.

>
> Also, please, read
> http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
> code formatting in your patch.
>
> Best regards,
> Z.
>
> --
> Zdenek Styblik
> email: ***@gmail.com
> jabber: ***@gmail.com
Zdenek Styblik
2013-12-09 18:31:59 UTC
Permalink
On Mon, Dec 9, 2013 at 7:24 PM, Zdenek Styblik <***@gmail.com> wrote:
>> @@@oops. not sure how that got there. I did a cvs up of my source tree and merged back in my changes in ipmi_pef.c and ipmitool.1 only.
>
> Alright.
>
>>
>> ~~~
>> +int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
>> + int len, void *buffer);
>> +int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
>> ~~~
> [...]
>> @@@See above. Those functions are already in the existing .h file
>
> Yes, they do. And they're prefixed as I've said. Therefore I'm a bit
> confused what were you actually doing there.
>
>>
>> Such things go into header file. Also, where is check whether
>> ATTRIBUTE_PACKING is supported/defined? What if it isn't???
>>
>> @@@ ATTRIBUTE_PACKING is used in many other places so I assume that is the correct way.
>>
>
> Indeed it is, but it's conditional. Check other header files and
> copy-paste, because that's the correct way if you want attribute
> packing.
>
>> @@@ ccode is already checked in ipmi_pef_msg_exchange
>
> Ok.
>
>> @@@ should it? the other pef (ipmi_pef_list_policies) etc do not.
>
> Yes, it definitely should.
>
>>
>> ~~~
>> + if (ptbl) {
>> + free(ptbl);
>> + }
>> ~~~
>>
>> You've missed ``ptbl = NULL;'' there.
>>
>> @@@ do you mean if (ptbl != NULL)
>
> No, I meant:
>
> ~~~
> if (ptbl) {
> free(ptbl);
> ptbl = NULL;
> }
> ~~~
>
> [...]
>> ~~~
>> +static struct valstr endis[] = {
>> + { .str = "enable", .val = 0x01 },
>> + { .str = "disable", .val = 0x00 },
>> + { .val = -1 },
>> +};
>> +
>> ~~~
>>
>> No, use strcmp()/strncmp() or whatever.
>>
>> @@@ ok can do that. but str2val is also used with argv[] elsewhere in the code.
>>
>
> Yes, it's and I don't want to see more of it. You don't have to repeat
> every stupid/silly thing somebody else did in the code ;)
>
> [...]
>> A good one. :)
>>
>> @@@ str2int is used elsewhere in the code as well
>
> Ok, I'll be more specific. You don't bother with checking return code.
>

I'm also sure there is only a limited amount of PEF policies or
whatever. This should be checked as well. Therefore no ID < 0 and ID >
MAX_PEF_POLICY_ID either.

Z.

> Z.
>
>>
>> Also, please, read
>> http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
>> code formatting in your patch.
>>
>> Best regards,
>> Z.
>>
>> --
>> Zdenek Styblik
>> email: ***@gmail.com
>> jabber: ***@gmail.com
J***@Dell.com
2013-12-09 18:50:42 UTC
Permalink
--jordan hargrave
Dell Enterprise Linux Engineering
________________________________________
From: Zdenek Styblik [***@gmail.com]
Sent: Monday, December 09, 2013 12:31 PM
To: Hargrave, Jordan
Cc: ipmitool-devel
Subject: Re: Code Review - ID: 86 - Add support for enable/disable PEF policy entries

On Mon, Dec 9, 2013 at 7:24 PM, Zdenek Styblik <***@gmail.com> wrote:
>> @@@oops. not sure how that got there. I did a cvs up of my source tree and merged back in my changes in ipmi_pef.c and ipmitool.1 only.
>
> Alright.
>
>>
>> ~~~
>> +int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
>> + int len, void *buffer);
>> +int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
>> ~~~
> [...]
>> @@@See above. Those functions are already in the existing .h file
>
> Yes, they do. And they're prefixed as I've said. Therefore I'm a bit
> confused what were you actually doing there.
>
>>
>> Such things go into header file. Also, where is check whether
>> ATTRIBUTE_PACKING is supported/defined? What if it isn't???
>>
>> @@@ ATTRIBUTE_PACKING is used in many other places so I assume that is the correct way.
>>
>
> Indeed it is, but it's conditional. Check other header files and
> copy-paste, because that's the correct way if you want attribute
> packing.
>
>> @@@ ccode is already checked in ipmi_pef_msg_exchange
>
> Ok.
>
>> @@@ should it? the other pef (ipmi_pef_list_policies) etc do not.
>
> Yes, it definitely should.
>
>>
>> ~~~
>> + if (ptbl) {
>> + free(ptbl);
>> + }
>> ~~~
>>
>> You've missed ``ptbl = NULL;'' there.
>>
>> @@@ do you mean if (ptbl != NULL)
>
> No, I meant:
>
> ~~~
> if (ptbl) {
> free(ptbl);
> ptbl = NULL;
> }
> ~~~
>
> [...]
>> ~~~
>> +static struct valstr endis[] = {
>> + { .str = "enable", .val = 0x01 },
>> + { .str = "disable", .val = 0x00 },
>> + { .val = -1 },
>> +};
>> +
>> ~~~
>>
>> No, use strcmp()/strncmp() or whatever.
>>
>> @@@ ok can do that. but str2val is also used with argv[] elsewhere in the code.
>>
>
> Yes, it's and I don't want to see more of it. You don't have to repeat
> every stupid/silly thing somebody else did in the code ;)
>
> [...]
>> A good one. :)
>>
>> @@@ str2int is used elsewhere in the code as well
>
> Ok, I'll be more specific. You don't bother with checking return code.
>

I'm also sure there is only a limited amount of PEF policies or
whatever. This should be checked as well. Therefore no ID < 0 and ID >
MAX_PEF_POLICY_ID either.

Z.

@@@ On our systems it is currently 8 IIRC. Not sure of a hard limit.

> Z.
>
>>
>> Also, please, read
>> http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
>> code formatting in your patch.
>>
>> Best regards,
>> Z.
>>
>> --
>> Zdenek Styblik
>> email: ***@gmail.com
>> jabber: ***@gmail.com
J***@Dell.com
2013-12-11 19:01:32 UTC
Permalink
ok uploaded the latest patch.

--jordan hargrave
Dell Enterprise Linux Engineering
________________________________________
From: Zdenek Styblik [***@gmail.com]
Sent: Monday, December 09, 2013 12:31 PM
To: Hargrave, Jordan
Cc: ipmitool-devel
Subject: Re: Code Review - ID: 86 - Add support for enable/disable PEF policy entries

On Mon, Dec 9, 2013 at 7:24 PM, Zdenek Styblik <***@gmail.com> wrote:
>> @@@oops. not sure how that got there. I did a cvs up of my source tree and merged back in my changes in ipmi_pef.c and ipmitool.1 only.
>
> Alright.
>
>>
>> ~~~
>> +int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
>> + int len, void *buffer);
>> +int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
>> ~~~
> [...]
>> @@@See above. Those functions are already in the existing .h file
>
> Yes, they do. And they're prefixed as I've said. Therefore I'm a bit
> confused what were you actually doing there.
>
>>
>> Such things go into header file. Also, where is check whether
>> ATTRIBUTE_PACKING is supported/defined? What if it isn't???
>>
>> @@@ ATTRIBUTE_PACKING is used in many other places so I assume that is the correct way.
>>
>
> Indeed it is, but it's conditional. Check other header files and
> copy-paste, because that's the correct way if you want attribute
> packing.
>
>> @@@ ccode is already checked in ipmi_pef_msg_exchange
>
> Ok.
>
>> @@@ should it? the other pef (ipmi_pef_list_policies) etc do not.
>
> Yes, it definitely should.
>
>>
>> ~~~
>> + if (ptbl) {
>> + free(ptbl);
>> + }
>> ~~~
>>
>> You've missed ``ptbl = NULL;'' there.
>>
>> @@@ do you mean if (ptbl != NULL)
>
> No, I meant:
>
> ~~~
> if (ptbl) {
> free(ptbl);
> ptbl = NULL;
> }
> ~~~
>
> [...]
>> ~~~
>> +static struct valstr endis[] = {
>> + { .str = "enable", .val = 0x01 },
>> + { .str = "disable", .val = 0x00 },
>> + { .val = -1 },
>> +};
>> +
>> ~~~
>>
>> No, use strcmp()/strncmp() or whatever.
>>
>> @@@ ok can do that. but str2val is also used with argv[] elsewhere in the code.
>>
>
> Yes, it's and I don't want to see more of it. You don't have to repeat
> every stupid/silly thing somebody else did in the code ;)
>
> [...]
>> A good one. :)
>>
>> @@@ str2int is used elsewhere in the code as well
>
> Ok, I'll be more specific. You don't bother with checking return code.
>

I'm also sure there is only a limited amount of PEF policies or
whatever. This should be checked as well. Therefore no ID < 0 and ID >
MAX_PEF_POLICY_ID either.

Z.

> Z.
>
>>
>> Also, please, read
>> http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
>> code formatting in your patch.
>>
>> Best regards,
>> Z.
>>
>> --
>> Zdenek Styblik
>> email: ***@gmail.com
>> jabber: ***@gmail.com
J***@Dell.com
2013-12-09 18:49:21 UTC
Permalink
--jordan hargrave
Dell Enterprise Linux Engineering
________________________________________
From: Zdenek Styblik [***@gmail.com]
Sent: Monday, December 09, 2013 12:24 PM
To: Hargrave, Jordan
Cc: ipmitool-devel
Subject: Re: Code Review - ID: 86 - Add support for enable/disable PEF policy entries

> @@@oops. not sure how that got there. I did a cvs up of my source tree and merged back in my changes in ipmi_pef.c and ipmitool.1 only.

Alright.

>
> ~~~
> +int ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
> + int len, void *buffer);
> +int ipmi_setsysinfo(struct ipmi_intf * intf, int len, void *buffer);
> ~~~
[...]
> @@@See above. Those functions are already in the existing .h file

Yes, they do. And they're prefixed as I've said. Therefore I'm a bit
confused what were you actually doing there.

>
> Such things go into header file. Also, where is check whether
> ATTRIBUTE_PACKING is supported/defined? What if it isn't???
>
> @@@ ATTRIBUTE_PACKING is used in many other places so I assume that is the correct way.
>

Indeed it is, but it's conditional. Check other header files and
copy-paste, because that's the correct way if you want attribute
packing.

@@@@ Ok have made the change into ipmi_pef.h

> @@@ ccode is already checked in ipmi_pef_msg_exchange

Ok.

> @@@ should it? the other pef (ipmi_pef_list_policies) etc do not.

Yes, it definitely should.

@@@@ Ok made that change too

>
> ~~~
> + if (ptbl) {
> + free(ptbl);
> + }
> ~~~
>
> You've missed ``ptbl = NULL;'' there.
>
> @@@ do you mean if (ptbl != NULL)

No, I meant:

~~~
if (ptbl) {
free(ptbl);
ptbl = NULL;
}
~~~

@@@@ Should it? ptbl isn't used elsewhere. That's more a personal perference style, but I can add it.

[...]
> ~~~
> +static struct valstr endis[] = {
> + { .str = "enable", .val = 0x01 },
> + { .str = "disable", .val = 0x00 },
> + { .val = -1 },
> +};
> +
> ~~~
>
> No, use strcmp()/strncmp() or whatever.
>
> @@@ ok can do that. but str2val is also used with argv[] elsewhere in the code.
>

Yes, it's and I don't want to see more of it. You don't have to repeat
every stupid/silly thing somebody else did in the code ;)

@@@@ I like the use though, makes the code cleaner IMHO. But I can add the strcmps.

[...]
> A good one. :)
>
> @@@ str2int is used elsewhere in the code as well

Ok, I'll be more specific. You don't bother with checking return code.

Z.

@@@@ ah. could do. but it's also checked in setpolicy.

>
> Also, please, read
> http://sourceforge.net/p/ipmitool/wiki/coding_standards/ and change
> code formatting in your patch.
>
> Best regards,
> Z.
>
> --
> Zdenek Styblik
> email: ***@gmail.com
> jabber: ***@gmail.com
Loading...