staging: lustre: mgc: handle config_llog_data::cld_refcount properly
Originally, the logic of handling config_llog_data::cld_refcount
is some confusing, it may cause the cld_refcount to be leaked or
trigger "LASSERT(atomic_read(&cld->cld_refcount) > 0);" when put
the reference. This patch clean related logic as following:
1) When the 'cld' is created, its reference is set as 1.
2) No need additional reference when add the 'cld' into the list
'config_llog_list'.
3) Inrease 'cld_refcount' when set lock data after mgc_enqueue()
done successfully by mgc_process_log().
4) When mgc_requeue_thread() traversals the 'config_llog_list',
it needs to take additional reference on each 'cld' to avoid
being freed during subsequent processing. The reference also
prevents the 'cld' to be dropped from the 'config_llog_list',
then the mgc_requeue_thread() can safely locate next 'cld',
and then decrease the 'cld_refcount' for previous one.
5) mgc_blocking_ast() will drop the reference of 'cld_refcount'
that is taken in mgc_process_log().
6) The others need to call config_log_find() to find the 'cld'
if want to access related config log data. That will increase
the 'cld_refcount' to avoid being freed during accessing. The
sponsor needs to call config_log_put() after using the 'cld'.
7) Other confused or redundant logic are dropped.
On the other hand, the patch also enhances the protection for
'config_llog_data' flags, such as 'cld_stopping'/'cld_lostlock'
as following.
a) Use 'config_list_lock' (spinlock) to handle the possible
parallel accessing of these flags among mgc_requeue_thread()
and others config llog data visitors, such as mount/umount,
blocking_ast, and so on.
b) Use 'config_llog_data::cld_lock' (mutex) to pretect other
parallel accessing of these flags among kinds of blockable
operations, such as mount, umount, and blocking ast.
The 'config_llog_data::cld_lock' is also used for protecting
the sub-cld members, such as 'cld_sptlrpc'/'cld_params', and
so on.
Signed-off-by: Fan Yong <fan.yong@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8408
Reviewed-on: http://review.whamcloud.com/21616
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Hongchao Zhang <hongchao.zhang@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>