Skip to content

Commit 6173d1f

Browse files
author
Alex Elder
committed
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>
1 parent e0f43c9 commit 6173d1f

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

‎net/ceph/messenger.c‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ static void encode_my_addr(struct ceph_messenger *msgr)
9999
*/
100100
static struct workqueue_struct *ceph_msgr_wq;
101101

102+
void _ceph_msgr_exit(void)
103+
{
104+
if (ceph_msgr_wq)
105+
destroy_workqueue(ceph_msgr_wq);
106+
107+
BUG_ON(zero_page_address == NULL);
108+
zero_page_address = NULL;
109+
110+
BUG_ON(zero_page == NULL);
111+
kunmap(zero_page);
112+
page_cache_release(zero_page);
113+
zero_page = NULL;
114+
}
115+
102116
int ceph_msgr_init(void)
103117
{
104118
BUG_ON(zero_page != NULL);
@@ -109,33 +123,21 @@ int ceph_msgr_init(void)
109123
zero_page_address = kmap(zero_page);
110124

111125
ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
112-
if (!ceph_msgr_wq) {
113-
pr_err("msgr_init failed to create workqueue\n");
114-
115-
zero_page_address = NULL;
116-
kunmap(zero_page);
117-
page_cache_release(zero_page);
118-
zero_page = NULL;
126+
if (ceph_msgr_wq)
127+
return 0;
119128

120-
return -ENOMEM;
121-
}
129+
pr_err("msgr_init failed to create workqueue\n");
130+
_ceph_msgr_exit();
122131

123-
return 0;
132+
return -ENOMEM;
124133
}
125134
EXPORT_SYMBOL(ceph_msgr_init);
126135

127136
void ceph_msgr_exit(void)
128137
{
129138
BUG_ON(ceph_msgr_wq == NULL);
130-
destroy_workqueue(ceph_msgr_wq);
131139

132-
BUG_ON(zero_page_address == NULL);
133-
zero_page_address = NULL;
134-
135-
BUG_ON(zero_page == NULL);
136-
kunmap(zero_page);
137-
page_cache_release(zero_page);
138-
zero_page = NULL;
140+
_ceph_msgr_exit();
139141
}
140142
EXPORT_SYMBOL(ceph_msgr_exit);
141143

0 commit comments

Comments
 (0)