Skip to content

Commit 24ef181

Browse files
Joel BeckerMark Fasheh
authored andcommitted
ocfs2: Separate out dlm lock functions.
This is the first in a series of patches to isolate ocfs2 from the underlying cluster stack. Here we wrap the dlm locking functions with ocfs2-specific calls. Because ocfs2 always uses the same dlm lock status callbacks, we can eliminate the callbacks from the filesystem visible functions. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
1 parent 386a2ef commit 24ef181

6 files changed

Lines changed: 179 additions & 49 deletions

File tree

‎fs/ocfs2/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ocfs2-objs := \
2424
namei.o \
2525
resize.o \
2626
slot_map.o \
27+
stackglue.o \
2728
suballoc.o \
2829
super.o \
2930
symlink.o \

‎fs/ocfs2/dlmglue.c‎

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "heartbeat.h"
5454
#include "inode.h"
5555
#include "journal.h"
56+
#include "stackglue.h"
5657
#include "slot_map.h"
5758
#include "super.h"
5859
#include "uptodate.h"
@@ -888,22 +889,21 @@ static int ocfs2_lock_create(struct ocfs2_super *osb,
888889
lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
889890
spin_unlock_irqrestore(&lockres->l_lock, flags);
890891

891-
status = dlmlock(osb->dlm,
892-
level,
893-
&lockres->l_lksb,
894-
dlm_flags,
895-
lockres->l_name,
896-
OCFS2_LOCK_ID_MAX_LEN - 1,
897-
ocfs2_locking_ast,
898-
lockres,
899-
ocfs2_blocking_ast);
892+
status = ocfs2_dlm_lock(osb->dlm,
893+
level,
894+
&lockres->l_lksb,
895+
dlm_flags,
896+
lockres->l_name,
897+
OCFS2_LOCK_ID_MAX_LEN - 1,
898+
lockres);
900899
if (status != DLM_NORMAL) {
901-
ocfs2_log_dlm_error("dlmlock", status, lockres);
900+
ocfs2_log_dlm_error("ocfs2_dlm_lock", status, lockres);
902901
ret = -EINVAL;
903902
ocfs2_recover_from_dlm_error(lockres, 1);
904903
}
905904

906-
mlog(0, "lock %s, successfull return from dlmlock\n", lockres->l_name);
905+
mlog(0, "lock %s, successfull return from ocfs2_dlm_lock\n",
906+
lockres->l_name);
907907

908908
bail:
909909
mlog_exit(ret);
@@ -1091,29 +1091,27 @@ static int ocfs2_cluster_lock(struct ocfs2_super *osb,
10911091
lockres->l_name, lockres->l_level, level);
10921092

10931093
/* call dlm_lock to upgrade lock now */
1094-
status = dlmlock(osb->dlm,
1095-
level,
1096-
&lockres->l_lksb,
1097-
lkm_flags,
1098-
lockres->l_name,
1099-
OCFS2_LOCK_ID_MAX_LEN - 1,
1100-
ocfs2_locking_ast,
1101-
lockres,
1102-
ocfs2_blocking_ast);
1094+
status = ocfs2_dlm_lock(osb->dlm,
1095+
level,
1096+
&lockres->l_lksb,
1097+
lkm_flags,
1098+
lockres->l_name,
1099+
OCFS2_LOCK_ID_MAX_LEN - 1,
1100+
lockres);
11031101
if (status != DLM_NORMAL) {
11041102
if ((lkm_flags & LKM_NOQUEUE) &&
11051103
(status == DLM_NOTQUEUED))
11061104
ret = -EAGAIN;
11071105
else {
1108-
ocfs2_log_dlm_error("dlmlock", status,
1109-
lockres);
1106+
ocfs2_log_dlm_error("ocfs2_dlm_lock",
1107+
status, lockres);
11101108
ret = -EINVAL;
11111109
}
11121110
ocfs2_recover_from_dlm_error(lockres, 1);
11131111
goto out;
11141112
}
11151113

1116-
mlog(0, "lock %s, successfull return from dlmlock\n",
1114+
mlog(0, "lock %s, successfull return from ocfs2_dlm_lock\n",
11171115
lockres->l_name);
11181116

11191117
/* At this point we've gone inside the dlm and need to
@@ -1503,14 +1501,14 @@ int ocfs2_file_lock(struct file *file, int ex, int trylock)
15031501
lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0);
15041502
spin_unlock_irqrestore(&lockres->l_lock, flags);
15051503

1506-
ret = dlmlock(osb->dlm, level, &lockres->l_lksb, lkm_flags,
1507-
lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1,
1508-
ocfs2_locking_ast, lockres, ocfs2_blocking_ast);
1504+
ret = ocfs2_dlm_lock(osb->dlm, level, &lockres->l_lksb, lkm_flags,
1505+
lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1,
1506+
lockres);
15091507
if (ret != DLM_NORMAL) {
15101508
if (trylock && ret == DLM_NOTQUEUED)
15111509
ret = -EAGAIN;
15121510
else {
1513-
ocfs2_log_dlm_error("dlmlock", ret, lockres);
1511+
ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres);
15141512
ret = -EINVAL;
15151513
}
15161514

@@ -2699,15 +2697,15 @@ static int ocfs2_drop_lock(struct ocfs2_super *osb,
26992697

27002698
mlog(0, "lock %s\n", lockres->l_name);
27012699

2702-
status = dlmunlock(osb->dlm, &lockres->l_lksb, lkm_flags,
2703-
ocfs2_unlock_ast, lockres);
2700+
status = ocfs2_dlm_unlock(osb->dlm, &lockres->l_lksb, lkm_flags,
2701+
lockres);
27042702
if (status != DLM_NORMAL) {
2705-
ocfs2_log_dlm_error("dlmunlock", status, lockres);
2703+
ocfs2_log_dlm_error("ocfs2_dlm_unlock", status, lockres);
27062704
mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
27072705
dlm_print_one_lock(lockres->l_lksb.lockid);
27082706
BUG();
27092707
}
2710-
mlog(0, "lock %s, successfull return from dlmunlock\n",
2708+
mlog(0, "lock %s, successfull return from ocfs2_dlm_unlock\n",
27112709
lockres->l_name);
27122710

27132711
ocfs2_wait_on_busy_lock(lockres);
@@ -2832,17 +2830,15 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
28322830
if (lvb)
28332831
dlm_flags |= LKM_VALBLK;
28342832

2835-
status = dlmlock(osb->dlm,
2836-
new_level,
2837-
&lockres->l_lksb,
2838-
dlm_flags,
2839-
lockres->l_name,
2840-
OCFS2_LOCK_ID_MAX_LEN - 1,
2841-
ocfs2_locking_ast,
2842-
lockres,
2843-
ocfs2_blocking_ast);
2833+
status = ocfs2_dlm_lock(osb->dlm,
2834+
new_level,
2835+
&lockres->l_lksb,
2836+
dlm_flags,
2837+
lockres->l_name,
2838+
OCFS2_LOCK_ID_MAX_LEN - 1,
2839+
lockres);
28442840
if (status != DLM_NORMAL) {
2845-
ocfs2_log_dlm_error("dlmlock", status, lockres);
2841+
ocfs2_log_dlm_error("ocfs2_dlm_lock", status, lockres);
28462842
ret = -EINVAL;
28472843
ocfs2_recover_from_dlm_error(lockres, 1);
28482844
goto bail;
@@ -2854,7 +2850,7 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
28542850
return ret;
28552851
}
28562852

2857-
/* returns 1 when the caller should unlock and call dlmunlock */
2853+
/* returns 1 when the caller should unlock and call ocfs2_dlm_unlock */
28582854
static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb,
28592855
struct ocfs2_lock_res *lockres)
28602856
{
@@ -2896,18 +2892,17 @@ static int ocfs2_cancel_convert(struct ocfs2_super *osb,
28962892
mlog(0, "lock %s\n", lockres->l_name);
28972893

28982894
ret = 0;
2899-
status = dlmunlock(osb->dlm,
2900-
&lockres->l_lksb,
2901-
LKM_CANCEL,
2902-
ocfs2_unlock_ast,
2903-
lockres);
2895+
status = ocfs2_dlm_unlock(osb->dlm,
2896+
&lockres->l_lksb,
2897+
LKM_CANCEL,
2898+
lockres);
29042899
if (status != DLM_NORMAL) {
2905-
ocfs2_log_dlm_error("dlmunlock", status, lockres);
2900+
ocfs2_log_dlm_error("ocfs2_dlm_unlock", status, lockres);
29062901
ret = -EINVAL;
29072902
ocfs2_recover_from_dlm_error(lockres, 0);
29082903
}
29092904

2910-
mlog(0, "lock %s return from dlmunlock\n", lockres->l_name);
2905+
mlog(0, "lock %s return from ocfs2_dlm_unlock\n", lockres->l_name);
29112906

29122907
mlog_exit(ret);
29132908
return ret;
@@ -3211,6 +3206,23 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
32113206
return UNBLOCK_CONTINUE_POST;
32123207
}
32133208

3209+
static struct ocfs2_locking_protocol lproto = {
3210+
.lp_lock_ast = ocfs2_locking_ast,
3211+
.lp_blocking_ast = ocfs2_blocking_ast,
3212+
.lp_unlock_ast = ocfs2_unlock_ast,
3213+
};
3214+
3215+
/* This interface isn't the final one, hence the less-than-perfect names */
3216+
void dlmglue_init_stack(void)
3217+
{
3218+
o2cb_get_stack(&lproto);
3219+
}
3220+
3221+
void dlmglue_exit_stack(void)
3222+
{
3223+
o2cb_put_stack();
3224+
}
3225+
32143226
static void ocfs2_process_blocked_lock(struct ocfs2_super *osb,
32153227
struct ocfs2_lock_res *lockres)
32163228
{

‎fs/ocfs2/dlmglue.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@ void ocfs2_wake_downconvert_thread(struct ocfs2_super *osb);
114114
struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void);
115115
void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug);
116116

117+
void dlmglue_init_stack(void);
118+
void dlmglue_exit_stack(void);
119+
117120
extern const struct dlm_protocol_version ocfs2_locking_protocol;
118121
#endif /* DLMGLUE_H */

‎fs/ocfs2/stackglue.c‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* -*- mode: c; c-basic-offset: 8; -*-
2+
* vim: noexpandtab sw=8 ts=8 sts=0:
3+
*
4+
* stackglue.c
5+
*
6+
* Code which implements an OCFS2 specific interface to underlying
7+
* cluster stacks.
8+
*
9+
* Copyright (C) 2007 Oracle. All rights reserved.
10+
*
11+
* This program is free software; you can redistribute it and/or
12+
* modify it under the terms of the GNU General Public
13+
* License as published by the Free Software Foundation, version 2.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
* General Public License for more details.
19+
*/
20+
21+
#include <linux/types.h>
22+
#include <linux/list.h>
23+
24+
#include "dlm/dlmapi.h"
25+
26+
#include "stackglue.h"
27+
28+
static struct ocfs2_locking_protocol *lproto;
29+
30+
enum dlm_status ocfs2_dlm_lock(struct dlm_ctxt *dlm,
31+
int mode,
32+
struct dlm_lockstatus *lksb,
33+
u32 flags,
34+
void *name,
35+
unsigned int namelen,
36+
void *astarg)
37+
{
38+
BUG_ON(lproto == NULL);
39+
return dlmlock(dlm, mode, lksb, flags, name, namelen,
40+
lproto->lp_lock_ast, astarg,
41+
lproto->lp_blocking_ast);
42+
}
43+
44+
enum dlm_status ocfs2_dlm_unlock(struct dlm_ctxt *dlm,
45+
struct dlm_lockstatus *lksb,
46+
u32 flags,
47+
void *astarg)
48+
{
49+
BUG_ON(lproto == NULL);
50+
51+
return dlmunlock(dlm, lksb, flags, lproto->lp_unlock_ast, astarg);
52+
}
53+
54+
55+
void o2cb_get_stack(struct ocfs2_locking_protocol *proto)
56+
{
57+
BUG_ON(proto == NULL);
58+
59+
lproto = proto;
60+
}
61+
62+
void o2cb_put_stack(void)
63+
{
64+
lproto = NULL;
65+
}

‎fs/ocfs2/stackglue.h‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* -*- mode: c; c-basic-offset: 8; -*-
2+
* vim: noexpandtab sw=8 ts=8 sts=0:
3+
*
4+
* stackglue.h
5+
*
6+
* Glue to the underlying cluster stack.
7+
*
8+
* Copyright (C) 2007 Oracle. All rights reserved.
9+
*
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public
12+
* License as published by the Free Software Foundation, version 2.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* General Public License for more details.
18+
*/
19+
20+
21+
#ifndef STACKGLUE_H
22+
#define STACKGLUE_H
23+
24+
struct ocfs2_locking_protocol {
25+
void (*lp_lock_ast)(void *astarg);
26+
void (*lp_blocking_ast)(void *astarg, int level);
27+
void (*lp_unlock_ast)(void *astarg, enum dlm_status status);
28+
};
29+
30+
enum dlm_status ocfs2_dlm_lock(struct dlm_ctxt *dlm,
31+
int mode,
32+
struct dlm_lockstatus *lksb,
33+
u32 flags,
34+
void *name,
35+
unsigned int namelen,
36+
void *astarg);
37+
enum dlm_status ocfs2_dlm_unlock(struct dlm_ctxt *dlm,
38+
struct dlm_lockstatus *lksb,
39+
u32 flags,
40+
void *astarg);
41+
42+
void o2cb_get_stack(struct ocfs2_locking_protocol *proto);
43+
void o2cb_put_stack(void);
44+
45+
#endif /* STACKGLUE_H */

‎fs/ocfs2/super.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ static int __init ocfs2_init(void)
933933

934934
ocfs2_print_version();
935935

936+
dlmglue_init_stack();
937+
936938
status = init_ocfs2_uptodate_cache();
937939
if (status < 0) {
938940
mlog_errno(status);
@@ -988,6 +990,8 @@ static void __exit ocfs2_exit(void)
988990

989991
exit_ocfs2_uptodate_cache();
990992

993+
dlmglue_exit_stack();
994+
991995
mlog_exit_void();
992996
}
993997

0 commit comments

Comments
 (0)