[LU-5411] cfs_hlist_for_each_entry() not working as intended Created: 24/Jul/14 Updated: 08/Sep/14 Resolved: 08/Sep/14 |
|
| Status: | Resolved |
| Project: | Lustre |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Frank Zago (Inactive) | Assignee: | WC Triage |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Severity: | 3 | ||||||||
| Rank (Obsolete): | 15052 | ||||||||
| Description |
|
When HAVE_HLIST_FOR_EACH_3ARG is defined, cfs_hlist_for_each_entry_safe (and similarly cfs_hlist_for_each_entry) are defined as this: pos = NULL; hlist_for_each_entry_safe(tpos, n, head, member) However if we have some code like: for (i = 0; i < REMOTE_PERM_HASHSIZE; i++)
cfs_hlist_for_each_entry_safe(lrp, node, next, hash + i,
lrp_list)
free_ll_remote_perm(lrp);
we end up actually doing:
for (i = 0; i < REMOTE_PERM_HASHSIZE; i++)
pos = NULL;
hlist_for_each_entry_safe(lrp, node, next, hash + i, lrp_list)
free_ll_remote_perm(lrp);
which is probably not what was intended. pos = NULL can be safely removed since it's an internal cursor. However that will generate some "unused" warnings on platforms where HAVE_HLIST_FOR_EACH_3ARG is defined. The other option is to add braces around the call, such as:
for (i = 0; i < REMOTE_PERM_HASHSIZE; i++) {
cfs_hlist_for_each_entry_safe(lrp, node, next, hash + i,
lrp_list)
free_ll_remote_perm(lrp);
}
However that won't prevent a similar bug from being introduced in the future. |
| Comments |
| Comment by James A Simmons [ 24/Jul/14 ] |
|
Discovering this during your SLES12 testing http://review.whamcloud.com/#/c/10387 Patch 103887 needs to be rebased but I was waiting until patch 11005 lands first. Perhaps we can roll your changes into the 10387 patches after 11005 lands. My other patches for lustre/obdclass/capa.c We will need to coordinate our work in some way. |
| Comment by James A Simmons [ 24/Jul/14 ] |
|
Your bracket idea is not working. /usr/src/kernels/3.12.22/arch/x86/Makefile:113: CONFIG_X86_X32 enabled but no binutils support I think it will need a more complex solution. Thinking... |
| Comment by Frank Zago (Inactive) [ 24/Jul/14 ] |
|
A bit ugly, but the unused attribute could be used: cfs_hlist_node_t *pos __attribute__ ((unused)); |
| Comment by James A Simmons [ 24/Jul/14 ] |
|
Very gcc specific. Perhaps we could do a pragma equivalent. |
| Comment by Frank Zago (Inactive) [ 24/Jul/14 ] |
|
It's supported by clang too, and probably (Intel's) icc. |
| Comment by James A Simmons [ 24/Jul/14 ] |
|
Been looking at how linux has this to make it compatible. It appears they have a macro to handle this across different compilers. We should use __maybe_unused instead. |
| Comment by James A Simmons [ 08/Sep/14 ] |
|
Patch http://review.whamcloud.com/#/c/11005 which has been merged has resolved these issues. This ticket can be closed. |