nvme: output nvme_alloc() error message#2855
nvme: output nvme_alloc() error message#2855ikegami-t wants to merge 1 commit intolinux-nvme:masterfrom
Conversation
|
This related to the fix #2850. |
| if (!smart_log) { | ||
| nvme_show_error("failed to allocate aligned memory"); | ||
| return -ENOMEM; | ||
| } |
There was a problem hiding this comment.
can these 4 lines be a macro call, something like this to save code lines (any name for macro):
Check_And_Return_If_Mem_Error( mem);
There was a problem hiding this comment.
Seems nvme_alloc() itself also can be added into the macro. By the way is there any actual example for the macro in nvme-cli, libnvme or linux kernel do you know? Thank you.
There was a problem hiding this comment.
What I am referring is to have a simple macro to eliminate lots of code with 1 liner. The macro would be:
#define SHOW_ERROR_AND_RETURN_IF_NO_MEM(mem)
if (!mem) {
nvme_show_error("failed to allocate aligned memory");
return -ENOMEM;
} \
end the code above will become:
SHOW_ERROR_AND_RETURN_IF_NO_MEM(smart_log)
or below
SHOW_ERROR_AND_RETURN_IF_NO_MEM(ctrl)
Adding nvme_alloc() to the macro, if possible, would make the code ugly, but you can try.
|
The PR for the nvme_alloc() is based on the PR: #2850 for the issue: #2848 for the nvme_alloc_huge() error and just checked the PRs before then found the related PR: #2337 for -ENOMEM alloc error but closed the PR without merging. Also the PR was for the similar issue: #2336. So now I am thinking to close the PR as same. |
|
That But in case of And we have many mallocs around where we don't print anything. I'd rather leave this as it is. An idea I am toying with is that we just fail on allocation failures in nvme-cli. There is absolut no point in trying to recover from such scenario. E.g. we could use these hooks for malloc (https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html) and call abort. This would get rid of the error handling code, no one ever tests: ptr = malloc(sizeof(*ptr));
if (!ptr)
return -ENOMEM;Though for libnvme this is not an option. |
27420df to
7694358
Compare
|
Just fixed the patch to abort if malloc failed. About the macro for error return will do consider for other error cases later. Thank you. |
dd78fdf to
e44f63d
Compare
| ''', | ||
| name: 'weak_malloc' | ||
| ), | ||
| description: 'Does struct tm have a tm_gmtoff field?' |
There was a problem hiding this comment.
The description needs to be updated.
|
|
||
| return result; | ||
| } | ||
| #endif /* HAVE_WEAK_MALLOC */ |
There was a problem hiding this comment.
I guess we need the same thing at least for calloc and realloc.
There was a problem hiding this comment.
Thanks for looking into this. After looking at this again with fresh eyes, I think we don't gain alot with this approach. Because we can't really remove the p = malloc(...); if (p) { printf(...); return -1; } code. We still need it when the allocation fails.
That means it would make more sense to introduce nvme_malloc & Co which would check the allocation and update all call sites and remove the memory allocation checks. Basically like the idea from above but with function instead ugly macros.
Since the nvme-cli 2.x is entering the maintenance mode today this is something we could consider for nvme-cli3
There was a problem hiding this comment.
Thanks for your comment. I will do for nvme-cli3.
| if (!ptr) \ | ||
| abort(); \ | ||
| } while (false) | ||
|
|
There was a problem hiding this comment.
I don't think we need this macro as API. The whole point if this would be that we nvme-cli aborts directly when the allocation fails. Nothing should call this macro.
There was a problem hiding this comment.
just I thoght as we can use the macro for other pointer handling case but deleted the macro as mentioned. In future if really needed the macro I will do consider again to add. Thank you.
The __malloc_hook deprecated and malloc function is weak function. Then we can add malloc function to abort when failed to allocate. Signed-off-by: Tokunori Ikegami <[email protected]>
e44f63d to
b3fce85
Compare
|
Fixed the review comments. Thank you. |
Currently only the value -ENOMEM returned for the error. Also fixed some nvme_alloc() error handling.