Whamcloud - gitweb
LU-12678 lnet: clarify initialization of lpni_refcount
This refcount is not explicitly initialized, so is implicitly
initialized to zero. This prohibits the use
lnet_peer_ni_addref_locked() for taking the first reference,
so a couple of places open-code the atomic_inc just in case.
There is code in lnet_peer_add_nid() which drops a reference before
accessing the structure. This isn't actually wrong, but it looks
weird.
lnet_destroy_peer_ni_locked() makes assumptions about the content of
the structure, so it cannot be used on a partially initialized
structure.
All these special cases make the code harder to understand. This
patch cleans this up:
- lpni_refcount is now initialized to one, so the called for
lnet_peer_ni_alloc() now owns a reference and must be sure
to release it.
- lnet_peer_attach_peer_ni() now consumes a reference to
the lpni. A pointer returned by lnet_peer_ni_alloc()
is most often passed to lnet_peer_attach_peer_ni() so
these to changes largely cancel each other out - not completely
- The two 'atomic_inc' calls are changed to
'lnet_peer_ni_addref_locked().
- A LIBCFS_FREE() is replaced by lnet_peer_ni_decref_locked(),
and that function is improved to cope with lpni_hashlist
being empty, or ->lpni_net being NULL.
- lnet_peer_add_nid() now holds a reference on the lpni until
it don't need it any more, then explicity drops it.
This should make no functional change, but should make the code a
little less confusing.
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Iec312e637d1e7b6eb14f2c363843403dd5cf8e8f
Reviewed-on: https://review.whamcloud.com/39120
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>