From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH, v2] libceph: encapsulate some messenger cleanup code
Date: Wed, 29 Feb 2012 09:44:26 -0800 [thread overview]
Message-ID: <4F4E63FA.20307@dreamhost.com> (raw)
In-Reply-To: <4F4DADA8.4090508@dreamhost.com>
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>
---
v2: updated due to switch to using ZERO_PAGE(0) in an earlier patch
in the series.
net/ceph/messenger.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
Index: b/net/ceph/messenger.c
===================================================================
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -99,6 +99,20 @@ static void encode_my_addr(struct ceph_m
*/
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)
{
BUG_ON(zero_page != NULL);
@@ -109,33 +123,21 @@ int ceph_msgr_init(void)
zero_page_address = kmap(zero_page);
ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
- if (!ceph_msgr_wq) {
- pr_err("msgr_init failed to create workqueue\n");
-
- zero_page_address = NULL;
- kunmap(zero_page);
- page_cache_release(zero_page);
- zero_page = NULL;
+ if (ceph_msgr_wq)
+ return 0;
- return -ENOMEM;
- }
+ pr_err("msgr_init failed to create workqueue\n");
+ _ceph_msgr_exit();
- return 0;
+ return -ENOMEM;
}
EXPORT_SYMBOL(ceph_msgr_init);
void ceph_msgr_exit(void)
{
BUG_ON(ceph_msgr_wq == NULL);
- 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;
+ _ceph_msgr_exit();
}
EXPORT_SYMBOL(ceph_msgr_exit);
next prev parent reply other threads:[~2012-02-29 17:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-29 4:44 [PATCH 0/4] libceph: miscellaneous cleanups Alex Elder
2012-02-29 4:46 ` [PATCH 1/4] libceph: make ceph_msgr_wq private Alex Elder
2012-02-29 4:46 ` [PATCH 2/4] libceph: encapsulate some messenger cleanup code Alex Elder
2012-02-29 17:44 ` Alex Elder [this message]
2012-02-29 4:46 ` [PATCH 3/4] libceph: make ceph_tcp_connect() return int Alex Elder
2012-02-29 4:46 ` [PATCH 4/4] libceph: a few small changes Alex Elder
2012-03-02 21:40 ` Sage Weil
2012-03-02 23:28 ` Alex Elder
2012-03-02 21:42 ` [PATCH 0/4] libceph: miscellaneous cleanups Sage Weil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F4E63FA.20307@dreamhost.com \
--to=elder@dreamhost.com \
--cc=ceph-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.