-
Notifications
You must be signed in to change notification settings - Fork 697
List generic table #2924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List generic table #2924
Conversation
|
Changes for the issue #2912. |
1e6066d to
6dbe7b3
Compare
util/table.c
Outdated
| { | ||
| struct table *t = table_init(); | ||
|
|
||
| if (t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return pattern is the preferred coding style, as it avoids deep indention levels:
if (!t)
return NULL;
util/table.c
Outdated
| printf("%ld%s", val->ld, add_pad ? "" : " "); | ||
| else if (type == FMT_UNSIGNED_LONG) | ||
| printf("%lu", val->lu); | ||
| printf("%lu%s", val->lu, add_pad ? "" : " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would simpler to add a final printf for the padding. So just leave the above printfs as they are and after this block have something like:
if (add_pad)
puts(" ");|
|
||
| default: | ||
| fprintf(stderr, "Invalid format!\n"); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here Just add a final padding printf if it is needed.
| devname, genname, nvme_ns_get_serial(n), | ||
| nvme_ns_get_model(n), nvme_ns_get_nsid(n), usage, format, | ||
| nvme_ns_get_firmware(n)); | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say when the table allocation fails just error out. no need for a fallback mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is not for the allocation error but for the zns list plugin command. The print function used by the both commands but currently the generic table is used by only the list command. (Later I will do chnage the zns list command also to use the generic table.)
|
Looks good. I've tested quickly and for |
This combined table_init() and table_add_columns() functions. Signed-off-by: Tokunori Ikegami <[email protected]>
The value auto populated but change it for the existing tables. Signed-off-by: Tokunori Ikegami <[email protected]>
A space added between each columns but not necessary for end of line. Signed-off-by: Tokunori Ikegami <[email protected]>
Use the generic table code added instead of hard coded table. Signed-off-by: Tokunori Ikegami <[email protected]>
This changes as same with other switch case statements. Signed-off-by: Tokunori Ikegami <[email protected]>
Delete the padding flag by padding in the caller functions. Signed-off-by: Tokunori Ikegami <[email protected]>
6dbe7b3 to
68bfb16
Compare
|
Just fixed for the comments. Thank you. |
util/table.c
Outdated
| struct table *table_init(void) | ||
| { | ||
| struct table *t; | ||
| struct table *t = malloc(sizeof(struct table)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function could just be return calloc(1, sizeof(struct table));. Maybe we should drop the function as there is no real value in it and use calloc directly where currently table_init is used. Or do I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see, table_free is doing some work and to keep the symetry table_init makes sense. But I think the name shouldbe table_create or so. It's not initializing anything, it's just allocation it.
util/table.c
Outdated
| } | ||
|
|
||
| return t; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary empy line.
Also changed the function to return calloc() instead. Signed-off-by: Tokunori Ikegami <[email protected]>
|
Again fixed the review comments. Thank you! |
|
Thanks! |
No description provided.