@@ -197,21 +197,19 @@ static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status)
197197 lproto -> lp_unlock_ast (astarg , error );
198198}
199199
200- int ocfs2_dlm_lock (struct ocfs2_cluster_connection * conn ,
201- int mode ,
202- union ocfs2_dlm_lksb * lksb ,
203- u32 flags ,
204- void * name ,
205- unsigned int namelen ,
206- void * astarg )
200+ static int o2cb_dlm_lock (struct ocfs2_cluster_connection * conn ,
201+ int mode ,
202+ union ocfs2_dlm_lksb * lksb ,
203+ u32 flags ,
204+ void * name ,
205+ unsigned int namelen ,
206+ void * astarg )
207207{
208208 enum dlm_status status ;
209209 int o2dlm_mode = mode_to_o2dlm (mode );
210210 int o2dlm_flags = flags_to_o2dlm (flags );
211211 int ret ;
212212
213- BUG_ON (lproto == NULL );
214-
215213 status = dlmlock (conn -> cc_lockspace , o2dlm_mode , & lksb -> lksb_o2dlm ,
216214 o2dlm_flags , name , namelen ,
217215 o2dlm_lock_ast_wrapper , astarg ,
@@ -220,43 +218,80 @@ int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
220218 return ret ;
221219}
222220
223- int ocfs2_dlm_unlock (struct ocfs2_cluster_connection * conn ,
224- union ocfs2_dlm_lksb * lksb ,
225- u32 flags ,
226- void * astarg )
221+ int ocfs2_dlm_lock (struct ocfs2_cluster_connection * conn ,
222+ int mode ,
223+ union ocfs2_dlm_lksb * lksb ,
224+ u32 flags ,
225+ void * name ,
226+ unsigned int namelen ,
227+ void * astarg )
228+ {
229+ BUG_ON (lproto == NULL );
230+
231+ return o2cb_dlm_lock (conn , mode , lksb , flags ,
232+ name , namelen , astarg );
233+ }
234+
235+ static int o2cb_dlm_unlock (struct ocfs2_cluster_connection * conn ,
236+ union ocfs2_dlm_lksb * lksb ,
237+ u32 flags ,
238+ void * astarg )
227239{
228240 enum dlm_status status ;
229241 int o2dlm_flags = flags_to_o2dlm (flags );
230242 int ret ;
231243
232- BUG_ON (lproto == NULL );
233-
234244 status = dlmunlock (conn -> cc_lockspace , & lksb -> lksb_o2dlm ,
235245 o2dlm_flags , o2dlm_unlock_ast_wrapper , astarg );
236246 ret = dlm_status_to_errno (status );
237247 return ret ;
238248}
239249
240- int ocfs2_dlm_lock_status (union ocfs2_dlm_lksb * lksb )
250+ int ocfs2_dlm_unlock (struct ocfs2_cluster_connection * conn ,
251+ union ocfs2_dlm_lksb * lksb ,
252+ u32 flags ,
253+ void * astarg )
254+ {
255+ BUG_ON (lproto == NULL );
256+
257+ return o2cb_dlm_unlock (conn , lksb , flags , astarg );
258+ }
259+
260+ static int o2cb_dlm_lock_status (union ocfs2_dlm_lksb * lksb )
241261{
242262 return dlm_status_to_errno (lksb -> lksb_o2dlm .status );
243263}
244264
265+ int ocfs2_dlm_lock_status (union ocfs2_dlm_lksb * lksb )
266+ {
267+ return o2cb_dlm_lock_status (lksb );
268+ }
269+
245270/*
246271 * Why don't we cast to ocfs2_meta_lvb? The "clean" answer is that we
247272 * don't cast at the glue level. The real answer is that the header
248273 * ordering is nigh impossible.
249274 */
250- void * ocfs2_dlm_lvb (union ocfs2_dlm_lksb * lksb )
275+ static void * o2cb_dlm_lvb (union ocfs2_dlm_lksb * lksb )
251276{
252277 return (void * )(lksb -> lksb_o2dlm .lvb );
253278}
254279
255- void ocfs2_dlm_dump_lksb (union ocfs2_dlm_lksb * lksb )
280+ void * ocfs2_dlm_lvb (union ocfs2_dlm_lksb * lksb )
281+ {
282+ return o2cb_dlm_lvb (lksb );
283+ }
284+
285+ static void o2cb_dlm_dump_lksb (union ocfs2_dlm_lksb * lksb )
256286{
257287 dlm_print_one_lock (lksb -> lksb_o2dlm .lockid );
258288}
259289
290+ void ocfs2_dlm_dump_lksb (union ocfs2_dlm_lksb * lksb )
291+ {
292+ o2cb_dlm_dump_lksb (lksb );
293+ }
294+
260295/*
261296 * Called from the dlm when it's about to evict a node. This is how the
262297 * classic stack signals node death.
@@ -271,6 +306,62 @@ static void o2dlm_eviction_cb(int node_num, void *data)
271306 conn -> cc_recovery_handler (node_num , conn -> cc_recovery_data );
272307}
273308
309+ static int o2cb_cluster_connect (struct ocfs2_cluster_connection * conn )
310+ {
311+ int rc = 0 ;
312+ u32 dlm_key ;
313+ struct dlm_ctxt * dlm ;
314+ struct o2dlm_private * priv ;
315+ struct dlm_protocol_version dlm_version ;
316+
317+ BUG_ON (conn == NULL );
318+
319+ /* for now we only have one cluster/node, make sure we see it
320+ * in the heartbeat universe */
321+ if (!o2hb_check_local_node_heartbeating ()) {
322+ rc = - EINVAL ;
323+ goto out ;
324+ }
325+
326+ priv = kzalloc (sizeof (struct o2dlm_private ), GFP_KERNEL );
327+ if (!priv ) {
328+ rc = - ENOMEM ;
329+ goto out_free ;
330+ }
331+
332+ /* This just fills the structure in. It is safe to pass conn. */
333+ dlm_setup_eviction_cb (& priv -> op_eviction_cb , o2dlm_eviction_cb ,
334+ conn );
335+
336+ conn -> cc_private = priv ;
337+
338+ /* used by the dlm code to make message headers unique, each
339+ * node in this domain must agree on this. */
340+ dlm_key = crc32_le (0 , conn -> cc_name , conn -> cc_namelen );
341+ dlm_version .pv_major = conn -> cc_version .pv_major ;
342+ dlm_version .pv_minor = conn -> cc_version .pv_minor ;
343+
344+ dlm = dlm_register_domain (conn -> cc_name , dlm_key , & dlm_version );
345+ if (IS_ERR (dlm )) {
346+ rc = PTR_ERR (dlm );
347+ mlog_errno (rc );
348+ goto out_free ;
349+ }
350+
351+ conn -> cc_version .pv_major = dlm_version .pv_major ;
352+ conn -> cc_version .pv_minor = dlm_version .pv_minor ;
353+ conn -> cc_lockspace = dlm ;
354+
355+ dlm_register_eviction_cb (dlm , & priv -> op_eviction_cb );
356+
357+ out_free :
358+ if (rc && conn -> cc_private )
359+ kfree (conn -> cc_private );
360+
361+ out :
362+ return rc ;
363+ }
364+
274365int ocfs2_cluster_connect (const char * group ,
275366 int grouplen ,
276367 void (* recovery_handler )(int node_num ,
@@ -280,10 +371,6 @@ int ocfs2_cluster_connect(const char *group,
280371{
281372 int rc = 0 ;
282373 struct ocfs2_cluster_connection * new_conn ;
283- u32 dlm_key ;
284- struct dlm_ctxt * dlm ;
285- struct o2dlm_private * priv ;
286- struct dlm_protocol_version dlm_version ;
287374
288375 BUG_ON (group == NULL );
289376 BUG_ON (conn == NULL );
@@ -294,13 +381,6 @@ int ocfs2_cluster_connect(const char *group,
294381 goto out ;
295382 }
296383
297- /* for now we only have one cluster/node, make sure we see it
298- * in the heartbeat universe */
299- if (!o2hb_check_local_node_heartbeating ()) {
300- rc = - EINVAL ;
301- goto out ;
302- }
303-
304384 new_conn = kzalloc (sizeof (struct ocfs2_cluster_connection ),
305385 GFP_KERNEL );
306386 if (!new_conn ) {
@@ -316,64 +396,53 @@ int ocfs2_cluster_connect(const char *group,
316396 /* Start the new connection at our maximum compatibility level */
317397 new_conn -> cc_version = lproto -> lp_max_version ;
318398
319- priv = kzalloc (sizeof (struct o2dlm_private ), GFP_KERNEL );
320- if (!priv ) {
321- rc = - ENOMEM ;
322- goto out_free ;
323- }
324-
325- /* This just fills the structure in. It is safe to use new_conn. */
326- dlm_setup_eviction_cb (& priv -> op_eviction_cb , o2dlm_eviction_cb ,
327- new_conn );
328-
329- new_conn -> cc_private = priv ;
330-
331- /* used by the dlm code to make message headers unique, each
332- * node in this domain must agree on this. */
333- dlm_key = crc32_le (0 , group , grouplen );
334- dlm_version .pv_major = new_conn -> cc_version .pv_major ;
335- dlm_version .pv_minor = new_conn -> cc_version .pv_minor ;
336-
337- dlm = dlm_register_domain (group , dlm_key , & dlm_version );
338- if (IS_ERR (dlm )) {
339- rc = PTR_ERR (dlm );
399+ rc = o2cb_cluster_connect (new_conn );
400+ if (rc ) {
340401 mlog_errno (rc );
341402 goto out_free ;
342403 }
343404
344- new_conn -> cc_version .pv_major = dlm_version .pv_major ;
345- new_conn -> cc_version .pv_minor = dlm_version .pv_minor ;
346- new_conn -> cc_lockspace = dlm ;
347-
348- dlm_register_eviction_cb (dlm , & priv -> op_eviction_cb );
349-
350405 * conn = new_conn ;
351406
352407out_free :
353- if (rc ) {
354- kfree (new_conn -> cc_private );
408+ if (rc )
355409 kfree (new_conn );
356- }
357410
358411out :
359412 return rc ;
360413}
361414
362415
363- int ocfs2_cluster_disconnect (struct ocfs2_cluster_connection * conn )
416+ static int o2cb_cluster_disconnect (struct ocfs2_cluster_connection * conn )
364417{
365418 struct dlm_ctxt * dlm = conn -> cc_lockspace ;
366419 struct o2dlm_private * priv = conn -> cc_private ;
367420
368421 dlm_unregister_eviction_cb (& priv -> op_eviction_cb );
369- dlm_unregister_domain (dlm );
370-
422+ conn -> cc_private = NULL ;
371423 kfree (priv );
372- kfree (conn );
424+
425+ dlm_unregister_domain (dlm );
426+ conn -> cc_lockspace = NULL ;
373427
374428 return 0 ;
375429}
376430
431+ int ocfs2_cluster_disconnect (struct ocfs2_cluster_connection * conn )
432+ {
433+ int ret ;
434+
435+ BUG_ON (conn == NULL );
436+
437+ ret = o2cb_cluster_disconnect (conn );
438+
439+ /* XXX Should we free it anyway? */
440+ if (!ret )
441+ kfree (conn );
442+
443+ return ret ;
444+ }
445+
377446static void o2hb_stop (const char * group )
378447{
379448 int ret ;
@@ -406,15 +475,20 @@ static void o2hb_stop(const char *group)
406475 *
407476 * Other stacks will eventually provide a NULL ->hangup() pointer.
408477 */
478+ static void o2cb_cluster_hangup (const char * group , int grouplen )
479+ {
480+ o2hb_stop (group );
481+ }
482+
409483void ocfs2_cluster_hangup (const char * group , int grouplen )
410484{
411485 BUG_ON (group == NULL );
412486 BUG_ON (group [grouplen ] != '\0' );
413487
414- o2hb_stop (group );
488+ o2cb_cluster_hangup (group , grouplen );
415489}
416490
417- int ocfs2_cluster_this_node (unsigned int * node )
491+ static int o2cb_cluster_this_node (unsigned int * node )
418492{
419493 int node_num ;
420494
@@ -429,6 +503,11 @@ int ocfs2_cluster_this_node(unsigned int *node)
429503 return 0 ;
430504}
431505
506+ int ocfs2_cluster_this_node (unsigned int * node )
507+ {
508+ return o2cb_cluster_this_node (node );
509+ }
510+
432511void ocfs2_stack_glue_set_locking_protocol (struct ocfs2_locking_protocol * proto )
433512{
434513 BUG_ON (proto != NULL );
0 commit comments