libceph: encapsulate some messenger cleanup code

Define a helper function to perform various cleanup operations.  Use
it both in the exit routine and in the init routine in the event of
an error.

Signed-off-by: Alex Elder <elder@dreamhost.com>
Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
Alex Elder 2012-02-14 14:05:33 -06:00
parent e0f43c9419
commit 6173d1f02f
1 changed files with 20 additions and 18 deletions

View File

@ -99,6 +99,20 @@ static void encode_my_addr(struct ceph_messenger *msgr)
*/ */
static struct workqueue_struct *ceph_msgr_wq; static struct workqueue_struct *ceph_msgr_wq;
void _ceph_msgr_exit(void)
{
if (ceph_msgr_wq)
destroy_workqueue(ceph_msgr_wq);
BUG_ON(zero_page_address == NULL);
zero_page_address = NULL;
BUG_ON(zero_page == NULL);
kunmap(zero_page);
page_cache_release(zero_page);
zero_page = NULL;
}
int ceph_msgr_init(void) int ceph_msgr_init(void)
{ {
BUG_ON(zero_page != NULL); BUG_ON(zero_page != NULL);
@ -109,33 +123,21 @@ int ceph_msgr_init(void)
zero_page_address = kmap(zero_page); zero_page_address = kmap(zero_page);
ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0); ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
if (!ceph_msgr_wq) { if (ceph_msgr_wq)
pr_err("msgr_init failed to create workqueue\n"); return 0;
zero_page_address = NULL; pr_err("msgr_init failed to create workqueue\n");
kunmap(zero_page); _ceph_msgr_exit();
page_cache_release(zero_page);
zero_page = NULL;
return -ENOMEM; return -ENOMEM;
}
return 0;
} }
EXPORT_SYMBOL(ceph_msgr_init); EXPORT_SYMBOL(ceph_msgr_init);
void ceph_msgr_exit(void) void ceph_msgr_exit(void)
{ {
BUG_ON(ceph_msgr_wq == NULL); BUG_ON(ceph_msgr_wq == NULL);
destroy_workqueue(ceph_msgr_wq);
BUG_ON(zero_page_address == NULL); _ceph_msgr_exit();
zero_page_address = NULL;
BUG_ON(zero_page == NULL);
kunmap(zero_page);
page_cache_release(zero_page);
zero_page = NULL;
} }
EXPORT_SYMBOL(ceph_msgr_exit); EXPORT_SYMBOL(ceph_msgr_exit);