Skip to content

Commit a796d28

Browse files
author
Joel Becker
committed
ocfs2: Pass lksbs back from stackglue ast/bast functions.
The stackglue ast and bast functions tried to maintain the fiction that their arguments were void pointers. In reality, stack_user.c had to know that the argument was an ocfs2_lock_res in order to get the status off of the lksb. That's ugly. This changes stackglue to always pass the lksb as the argument to ast and bast functions. The caller can always use container_of() to get the ocfs2_lock_res or user_dlm_lock_res. The net effect to the caller is zero. They still get back the lockres in their ast. stackglue gets cleaner, and now can use the lksb itself. Signed-off-by: Joel Becker <joel.becker@oracle.com>
1 parent 34a9dd7 commit a796d28

5 files changed

Lines changed: 70 additions & 76 deletions

File tree

‎fs/ocfs2/dlmglue.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
297297
lockres->l_type == OCFS2_LOCK_TYPE_OPEN;
298298
}
299299

300+
static inline struct ocfs2_lock_res *ocfs2_lksb_to_lock_res(union ocfs2_dlm_lksb *lksb)
301+
{
302+
return container_of(lksb, struct ocfs2_lock_res, l_lksb);
303+
}
304+
300305
static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres)
301306
{
302307
BUG_ON(!ocfs2_is_inode_lock(lockres));
@@ -1041,9 +1046,9 @@ static unsigned int lockres_set_pending(struct ocfs2_lock_res *lockres)
10411046
}
10421047

10431048

1044-
static void ocfs2_blocking_ast(void *opaque, int level)
1049+
static void ocfs2_blocking_ast(union ocfs2_dlm_lksb *lksb, int level)
10451050
{
1046-
struct ocfs2_lock_res *lockres = opaque;
1051+
struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb);
10471052
struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres);
10481053
int needs_downconvert;
10491054
unsigned long flags;
@@ -1072,9 +1077,9 @@ static void ocfs2_blocking_ast(void *opaque, int level)
10721077
ocfs2_wake_downconvert_thread(osb);
10731078
}
10741079

1075-
static void ocfs2_locking_ast(void *opaque)
1080+
static void ocfs2_locking_ast(union ocfs2_dlm_lksb *lksb)
10761081
{
1077-
struct ocfs2_lock_res *lockres = opaque;
1082+
struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb);
10781083
struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres);
10791084
unsigned long flags;
10801085
int status;
@@ -1189,8 +1194,7 @@ static int ocfs2_lock_create(struct ocfs2_super *osb,
11891194
&lockres->l_lksb,
11901195
dlm_flags,
11911196
lockres->l_name,
1192-
OCFS2_LOCK_ID_MAX_LEN - 1,
1193-
lockres);
1197+
OCFS2_LOCK_ID_MAX_LEN - 1);
11941198
lockres_clear_pending(lockres, gen, osb);
11951199
if (ret) {
11961200
ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres);
@@ -1421,8 +1425,7 @@ static int __ocfs2_cluster_lock(struct ocfs2_super *osb,
14211425
&lockres->l_lksb,
14221426
lkm_flags,
14231427
lockres->l_name,
1424-
OCFS2_LOCK_ID_MAX_LEN - 1,
1425-
lockres);
1428+
OCFS2_LOCK_ID_MAX_LEN - 1);
14261429
lockres_clear_pending(lockres, gen, osb);
14271430
if (ret) {
14281431
if (!(lkm_flags & DLM_LKF_NOQUEUE) ||
@@ -1859,8 +1862,7 @@ int ocfs2_file_lock(struct file *file, int ex, int trylock)
18591862
spin_unlock_irqrestore(&lockres->l_lock, flags);
18601863

18611864
ret = ocfs2_dlm_lock(osb->cconn, level, &lockres->l_lksb, lkm_flags,
1862-
lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1,
1863-
lockres);
1865+
lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1);
18641866
if (ret) {
18651867
if (!trylock || (ret != -EAGAIN)) {
18661868
ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres);
@@ -3056,9 +3058,9 @@ void ocfs2_dlm_shutdown(struct ocfs2_super *osb,
30563058
mlog_exit_void();
30573059
}
30583060

3059-
static void ocfs2_unlock_ast(void *opaque, int error)
3061+
static void ocfs2_unlock_ast(union ocfs2_dlm_lksb *lksb, int error)
30603062
{
3061-
struct ocfs2_lock_res *lockres = opaque;
3063+
struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb);
30623064
unsigned long flags;
30633065

30643066
mlog_entry_void();
@@ -3167,8 +3169,7 @@ static int ocfs2_drop_lock(struct ocfs2_super *osb,
31673169

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

3170-
ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, lkm_flags,
3171-
lockres);
3172+
ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, lkm_flags);
31723173
if (ret) {
31733174
ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres);
31743175
mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
@@ -3309,8 +3310,7 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
33093310
&lockres->l_lksb,
33103311
dlm_flags,
33113312
lockres->l_name,
3312-
OCFS2_LOCK_ID_MAX_LEN - 1,
3313-
lockres);
3313+
OCFS2_LOCK_ID_MAX_LEN - 1);
33143314
lockres_clear_pending(lockres, generation, osb);
33153315
if (ret) {
33163316
ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres);
@@ -3365,7 +3365,7 @@ static int ocfs2_cancel_convert(struct ocfs2_super *osb,
33653365
mlog(0, "lock %s\n", lockres->l_name);
33663366

33673367
ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb,
3368-
DLM_LKF_CANCEL, lockres);
3368+
DLM_LKF_CANCEL);
33693369
if (ret) {
33703370
ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres);
33713371
ocfs2_recover_from_dlm_error(lockres, 0);

‎fs/ocfs2/stack_o2cb.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,26 @@ static int dlm_status_to_errno(enum dlm_status status)
161161

162162
static void o2dlm_lock_ast_wrapper(void *astarg)
163163
{
164+
union ocfs2_dlm_lksb *lksb = astarg;
165+
164166
BUG_ON(o2cb_stack.sp_proto == NULL);
165167

166-
o2cb_stack.sp_proto->lp_lock_ast(astarg);
168+
o2cb_stack.sp_proto->lp_lock_ast(lksb);
167169
}
168170

169171
static void o2dlm_blocking_ast_wrapper(void *astarg, int level)
170172
{
173+
union ocfs2_dlm_lksb *lksb = astarg;
174+
171175
BUG_ON(o2cb_stack.sp_proto == NULL);
172176

173-
o2cb_stack.sp_proto->lp_blocking_ast(astarg, level);
177+
o2cb_stack.sp_proto->lp_blocking_ast(lksb, level);
174178
}
175179

176180
static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status)
177181
{
182+
union ocfs2_dlm_lksb *lksb = astarg;
183+
178184
int error = dlm_status_to_errno(status);
179185

180186
BUG_ON(o2cb_stack.sp_proto == NULL);
@@ -193,16 +199,15 @@ static void o2dlm_unlock_ast_wrapper(void *astarg, enum dlm_status status)
193199
if (status == DLM_CANCELGRANT)
194200
return;
195201

196-
o2cb_stack.sp_proto->lp_unlock_ast(astarg, error);
202+
o2cb_stack.sp_proto->lp_unlock_ast(lksb, error);
197203
}
198204

199205
static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn,
200206
int mode,
201207
union ocfs2_dlm_lksb *lksb,
202208
u32 flags,
203209
void *name,
204-
unsigned int namelen,
205-
void *astarg)
210+
unsigned int namelen)
206211
{
207212
enum dlm_status status;
208213
int o2dlm_mode = mode_to_o2dlm(mode);
@@ -211,23 +216,22 @@ static int o2cb_dlm_lock(struct ocfs2_cluster_connection *conn,
211216

212217
status = dlmlock(conn->cc_lockspace, o2dlm_mode, &lksb->lksb_o2dlm,
213218
o2dlm_flags, name, namelen,
214-
o2dlm_lock_ast_wrapper, astarg,
219+
o2dlm_lock_ast_wrapper, lksb,
215220
o2dlm_blocking_ast_wrapper);
216221
ret = dlm_status_to_errno(status);
217222
return ret;
218223
}
219224

220225
static int o2cb_dlm_unlock(struct ocfs2_cluster_connection *conn,
221226
union ocfs2_dlm_lksb *lksb,
222-
u32 flags,
223-
void *astarg)
227+
u32 flags)
224228
{
225229
enum dlm_status status;
226230
int o2dlm_flags = flags_to_o2dlm(flags);
227231
int ret;
228232

229233
status = dlmunlock(conn->cc_lockspace, &lksb->lksb_o2dlm,
230-
o2dlm_flags, o2dlm_unlock_ast_wrapper, astarg);
234+
o2dlm_flags, o2dlm_unlock_ast_wrapper, lksb);
231235
ret = dlm_status_to_errno(status);
232236
return ret;
233237
}

‎fs/ocfs2/stack_user.c‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/reboot.h>
2626
#include <asm/uaccess.h>
2727

28-
#include "ocfs2.h" /* For struct ocfs2_lock_res */
2928
#include "stackglue.h"
3029

3130
#include <linux/dlm_plock.h>
@@ -664,16 +663,10 @@ static void ocfs2_control_exit(void)
664663
-rc);
665664
}
666665

667-
static struct dlm_lksb *fsdlm_astarg_to_lksb(void *astarg)
668-
{
669-
struct ocfs2_lock_res *res = astarg;
670-
return &res->l_lksb.lksb_fsdlm;
671-
}
672-
673666
static void fsdlm_lock_ast_wrapper(void *astarg)
674667
{
675-
struct dlm_lksb *lksb = fsdlm_astarg_to_lksb(astarg);
676-
int status = lksb->sb_status;
668+
union ocfs2_dlm_lksb *lksb = astarg;
669+
int status = lksb->lksb_fsdlm.sb_status;
677670

678671
BUG_ON(ocfs2_user_plugin.sp_proto == NULL);
679672

@@ -688,25 +681,26 @@ static void fsdlm_lock_ast_wrapper(void *astarg)
688681
*/
689682

690683
if (status == -DLM_EUNLOCK || status == -DLM_ECANCEL)
691-
ocfs2_user_plugin.sp_proto->lp_unlock_ast(astarg, 0);
684+
ocfs2_user_plugin.sp_proto->lp_unlock_ast(lksb, 0);
692685
else
693-
ocfs2_user_plugin.sp_proto->lp_lock_ast(astarg);
686+
ocfs2_user_plugin.sp_proto->lp_lock_ast(lksb);
694687
}
695688

696689
static void fsdlm_blocking_ast_wrapper(void *astarg, int level)
697690
{
691+
union ocfs2_dlm_lksb *lksb = astarg;
692+
698693
BUG_ON(ocfs2_user_plugin.sp_proto == NULL);
699694

700-
ocfs2_user_plugin.sp_proto->lp_blocking_ast(astarg, level);
695+
ocfs2_user_plugin.sp_proto->lp_blocking_ast(lksb, level);
701696
}
702697

703698
static int user_dlm_lock(struct ocfs2_cluster_connection *conn,
704699
int mode,
705700
union ocfs2_dlm_lksb *lksb,
706701
u32 flags,
707702
void *name,
708-
unsigned int namelen,
709-
void *astarg)
703+
unsigned int namelen)
710704
{
711705
int ret;
712706

@@ -716,20 +710,19 @@ static int user_dlm_lock(struct ocfs2_cluster_connection *conn,
716710

717711
ret = dlm_lock(conn->cc_lockspace, mode, &lksb->lksb_fsdlm,
718712
flags|DLM_LKF_NODLCKWT, name, namelen, 0,
719-
fsdlm_lock_ast_wrapper, astarg,
713+
fsdlm_lock_ast_wrapper, lksb,
720714
fsdlm_blocking_ast_wrapper);
721715
return ret;
722716
}
723717

724718
static int user_dlm_unlock(struct ocfs2_cluster_connection *conn,
725719
union ocfs2_dlm_lksb *lksb,
726-
u32 flags,
727-
void *astarg)
720+
u32 flags)
728721
{
729722
int ret;
730723

731724
ret = dlm_unlock(conn->cc_lockspace, lksb->lksb_fsdlm.sb_lkid,
732-
flags, &lksb->lksb_fsdlm, astarg);
725+
flags, &lksb->lksb_fsdlm, lksb);
733726
return ret;
734727
}
735728

‎fs/ocfs2/stackglue.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,35 +233,32 @@ EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_locking_protocol);
233233

234234

235235
/*
236-
* The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take
237-
* "struct ocfs2_lock_res *astarg" instead of "void *astarg" because the
238-
* underlying stack plugins need to pilfer the lksb off of the lock_res.
239-
* If some other structure needs to be passed as an astarg, the plugins
240-
* will need to be given a different avenue to the lksb.
236+
* The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take no argument
237+
* for the ast and bast functions. They will pass the lksb to the ast
238+
* and bast. The caller can wrap the lksb with their own structure to
239+
* get more information.
241240
*/
242241
int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
243242
int mode,
244243
union ocfs2_dlm_lksb *lksb,
245244
u32 flags,
246245
void *name,
247-
unsigned int namelen,
248-
struct ocfs2_lock_res *astarg)
246+
unsigned int namelen)
249247
{
250248
BUG_ON(lproto == NULL);
251249

252250
return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags,
253-
name, namelen, astarg);
251+
name, namelen);
254252
}
255253
EXPORT_SYMBOL_GPL(ocfs2_dlm_lock);
256254

257255
int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
258256
union ocfs2_dlm_lksb *lksb,
259-
u32 flags,
260-
struct ocfs2_lock_res *astarg)
257+
u32 flags)
261258
{
262259
BUG_ON(lproto == NULL);
263260

264-
return active_stack->sp_ops->dlm_unlock(conn, lksb, flags, astarg);
261+
return active_stack->sp_ops->dlm_unlock(conn, lksb, flags);
265262
}
266263
EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock);
267264

‎fs/ocfs2/stackglue.h‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ struct ocfs2_protocol_version {
5555
u8 pv_minor;
5656
};
5757

58-
/*
59-
* The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf.
60-
*/
61-
struct ocfs2_locking_protocol {
62-
struct ocfs2_protocol_version lp_max_version;
63-
void (*lp_lock_ast)(void *astarg);
64-
void (*lp_blocking_ast)(void *astarg, int level);
65-
void (*lp_unlock_ast)(void *astarg, int error);
66-
};
67-
68-
6958
/*
7059
* The dlm_lockstatus struct includes lvb space, but the dlm_lksb struct only
7160
* has a pointer to separately allocated lvb space. This struct exists only to
@@ -87,6 +76,17 @@ union ocfs2_dlm_lksb {
8776
struct fsdlm_lksb_plus_lvb padding;
8877
};
8978

79+
/*
80+
* The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf.
81+
*/
82+
struct ocfs2_locking_protocol {
83+
struct ocfs2_protocol_version lp_max_version;
84+
void (*lp_lock_ast)(union ocfs2_dlm_lksb *lksb);
85+
void (*lp_blocking_ast)(union ocfs2_dlm_lksb *lksb, int level);
86+
void (*lp_unlock_ast)(union ocfs2_dlm_lksb *lksb, int error);
87+
};
88+
89+
9090
/*
9191
* A cluster connection. Mostly opaque to ocfs2, the connection holds
9292
* state for the underlying stack. ocfs2 does use cc_version to determine
@@ -155,27 +155,29 @@ struct ocfs2_stack_operations {
155155
*
156156
* ast and bast functions are not part of the call because the
157157
* stack will likely want to wrap ast and bast calls before passing
158-
* them to stack->sp_proto.
158+
* them to stack->sp_proto. There is no astarg. The lksb will
159+
* be passed back to the ast and bast functions. The caller can
160+
* use this to find their object.
159161
*/
160162
int (*dlm_lock)(struct ocfs2_cluster_connection *conn,
161163
int mode,
162164
union ocfs2_dlm_lksb *lksb,
163165
u32 flags,
164166
void *name,
165-
unsigned int namelen,
166-
void *astarg);
167+
unsigned int namelen);
167168

168169
/*
169170
* Call the underlying dlm unlock function. The ->dlm_unlock()
170171
* function should convert the flags as appropriate.
171172
*
172173
* The unlock ast is not passed, as the stack will want to wrap
173-
* it before calling stack->sp_proto->lp_unlock_ast().
174+
* it before calling stack->sp_proto->lp_unlock_ast(). There is
175+
* no astarg. The lksb will be passed back to the unlock ast
176+
* function. The caller can use this to find their object.
174177
*/
175178
int (*dlm_unlock)(struct ocfs2_cluster_connection *conn,
176179
union ocfs2_dlm_lksb *lksb,
177-
u32 flags,
178-
void *astarg);
180+
u32 flags);
179181

180182
/*
181183
* Return the status of the current lock status block. The fs
@@ -249,12 +251,10 @@ int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
249251
union ocfs2_dlm_lksb *lksb,
250252
u32 flags,
251253
void *name,
252-
unsigned int namelen,
253-
struct ocfs2_lock_res *astarg);
254+
unsigned int namelen);
254255
int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
255256
union ocfs2_dlm_lksb *lksb,
256-
u32 flags,
257-
struct ocfs2_lock_res *astarg);
257+
u32 flags);
258258

259259
int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb);
260260
int ocfs2_dlm_lvb_valid(union ocfs2_dlm_lksb *lksb);

0 commit comments

Comments
 (0)