lockd: make nlm_traverse_* more flexible
Subsystems (2)
PATCH 12/22 lockd: make nlm_traverse_* more flexible
From: Olaf Kirch <[email protected]>
Subject: lockd: make nlm_traverse_* more flexible
This patch makes nlm_traverse{locks,blocks,shares} and friends use a function pointer rather than a "action" enum.
This function pointer is given two nlm_hosts (one given by the caller, the other taken from the lock/block/share currently visited), and is free to do with them as it wants. If it returns a non-zero value, the lockd/block/share is released.
fs/lockd/svclock.c | 29 ++++-------- fs/lockd/svcshare.c | 20 +++----- fs/lockd/svcsubs.c | 104 ++++++++++++++++++++++++++++++++------------ include/linux/lockd/lockd.h | 15 ++---- include/linux/lockd/share.h | 3 - 5 files changed, 104 insertions(+), 67 deletions(-)
include/linux/lockd/share.h +2 -1
@@ -25,6 +25,7 @@ u32 nlmsvc_share_file(struct nlm_host *, struct nlm_args *);u32 nlmsvc_unshare_file (struct nlm_host *,struct nlm_file *,struct nlm_args *); -void nlmsvc_traverse_shares (struct nlm_host *,struct nlm_file *,int ); +void nlmsvc_traverse_shares (struct nlm_host *,struct nlm_file *, +nlm_host_match_fn_t );#endif /* LINUX_LOCKD_SHARE_H */
fs/lockd/svclock.c +11 -18
@@ -262,24 +262,30 @@ static void nlmsvc_release_block(structkref_put (&block->b_count, nlmsvc_free_block); } -static void nlmsvc_act_mark (struct nlm_host *host,struct nlm_file *file) +void nlmsvc_mark_blocks (struct nlm_file *file) {struct nlm_block *block;down (&file->f_sema); -for (block = file->f_blocks; block !=NULL ; block = block->b_fnext) +list_for_each_entry (block, &file->f_blocks, b_flist) block->b_host->h_inuse =1 ;up (&file->f_sema); } -static void nlmsvc_act_unlock (struct nlm_host *host,struct nlm_file *file) +/* +* Loop over all blocks and delete blocks held by +* a matching host. +*/ +void nlmsvc_traverse_blocks (struct nlm_host *host, +struct nlm_file *file, +nlm_host_match_fn_t match) { -struct nlm_block *block; +struct nlm_block *block, *next; restart:down (&file->f_sema);list_for_each_entry_safe (block, next, &file->f_blocks, b_flist) { -if (host !=NULL && host != block->b_host) +if (!match (block->b_host, host))continue ;/* Do not destroy blocks that are not on * the global retry list - why? */
@@ -295,19 +301,6 @@ restart: }/* -* Loop over all blocks and perform the action specified. -* (NLM_ACT_CHECK handled by nlmsvc_inspect_file). -*/ -void -nlmsvc_traverse_blocks (struct nlm_host *host,struct nlm_file *file,int action) -{ -if (action ==NLM_ACT_MARK ) -nlmsvc_act_mark (host, file); -else -nlmsvc_act_unlock (host, file); -} - -/* * Initialize arguments for GRANTED call. The nlm_rqst structure * has been cleared already. */
fs/lockd/svcsubs.c +76 -28
172 lines not on this page · raw message
include/linux/lockd/lockd.h +7 -8
@@ -135,13 +135,6 @@ struct nlm_block { };/* -* Valid actions for nlmsvc_traverse_files -*/ -#define NLM_ACT_CHECK 0/* check for locks */ -#define NLM_ACT_MARK 1/* mark & sweep */ -#define NLM_ACT_UNLOCK 2/* release all locks */ - -/* * Global variables */ extern struct rpc_program nlm_program;
@@ -185,6 +178,12 @@ void nsm_release(struct nsm_handle *)/* +* This is used in garbage collection and resource reclain +* A return value != 0 means destroy the lock/block/share +*/ +typedef int (*nlm_host_match_fn_t )(struct nlm_host *cur,struct nlm_host *ref); + +/* * Server-side lock handling */ u32 nlmsvc_lock(struct svc_rqst *, struct nlm_file *,
@@ -195,7 +194,7 @@ u32 nlmsvc_testlock(struct nlm_file *u32 nlmsvc_cancel_blocked (struct nlm_file *,struct nlm_lock *);unsigned long nlmsvc_retry_blocked (void );void nlmsvc_traverse_blocks (struct nlm_host *,struct nlm_file *, -int action); +nlm_host_match_fn_t match);void nlmsvc_grant_reply (struct svc_rqst *,struct nlm_cookie *,u32 );/*
fs/lockd/svcshare.c +8 -12
@@ -85,24 +85,20 @@ nlmsvc_unshare_file(struct nlm_host *hos }/* -* Traverse all shares for a given file (and host). -* NLM_ACT_CHECK is handled by nlmsvc_inspect_file. +* Traverse all shares for a given file, and delete +* those owned by the given (type of) host */ -void -nlmsvc_traverse_shares (struct nlm_host *host,struct nlm_file *file,int action) +void nlmsvc_traverse_shares (struct nlm_host *host,struct nlm_file *file, +nlm_host_match_fn_t match) {struct nlm_share *share, **shpp; shpp = &file->f_shares;while ((share = *shpp) !=NULL ) { -if (action ==NLM_ACT_MARK ) - share->s_host->h_inuse =1 ; -else if (action ==NLM_ACT_UNLOCK ) { -if (host ==NULL || host == share->s_host) { - *shpp = share->s_next; -kfree (share); -continue ; - } +if (match (share->s_host, host)) { + *shpp = share->s_next; +kfree (share); +continue ; } shpp = &share->s_next; }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs