Skip to content

Commit a845511

Browse files
committed
NFSD: Refactor __nfsd_file_close_inode()
The code that computes the hashval is the same in both callers. To prevent them from going stale, reframe the documenting comments to remove descriptions of the underlying hash table structure, which is about to be replaced. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 8755326 commit a845511

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

fs/nfsd/filecache.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -559,59 +559,61 @@ static struct shrinker nfsd_file_shrinker = {
559559
.seeks = 1,
560560
};
561561

562-
static void
563-
__nfsd_file_close_inode(struct inode *inode, unsigned int hashval,
564-
struct list_head *dispose)
562+
/*
563+
* Find all cache items across all net namespaces that match @inode and
564+
* move them to @dispose. The lookup is atomic wrt nfsd_file_acquire().
565+
*/
566+
static unsigned int
567+
__nfsd_file_close_inode(struct inode *inode, struct list_head *dispose)
565568
{
569+
unsigned int hashval = (unsigned int)hash_long(inode->i_ino,
570+
NFSD_FILE_HASH_BITS);
571+
unsigned int count = 0;
566572
struct nfsd_file *nf;
567573
struct hlist_node *tmp;
568574

569575
spin_lock(&nfsd_file_hashtbl[hashval].nfb_lock);
570576
hlist_for_each_entry_safe(nf, tmp, &nfsd_file_hashtbl[hashval].nfb_head, nf_node) {
571-
if (inode == nf->nf_inode)
577+
if (inode == nf->nf_inode) {
572578
nfsd_file_unhash_and_release_locked(nf, dispose);
579+
count++;
580+
}
573581
}
574582
spin_unlock(&nfsd_file_hashtbl[hashval].nfb_lock);
583+
return count;
575584
}
576585

577586
/**
578587
* nfsd_file_close_inode_sync - attempt to forcibly close a nfsd_file
579588
* @inode: inode of the file to attempt to remove
580589
*
581-
* Walk the whole hash bucket, looking for any files that correspond to "inode".
582-
* If any do, then unhash them and put the hashtable reference to them and
583-
* destroy any that had their last reference put. Also ensure that any of the
584-
* fputs also have their final __fput done as well.
590+
* Unhash and put, then flush and fput all cache items associated with @inode.
585591
*/
586592
void
587593
nfsd_file_close_inode_sync(struct inode *inode)
588594
{
589-
unsigned int hashval = (unsigned int)hash_long(inode->i_ino,
590-
NFSD_FILE_HASH_BITS);
591595
LIST_HEAD(dispose);
596+
unsigned int count;
592597

593-
__nfsd_file_close_inode(inode, hashval, &dispose);
594-
trace_nfsd_file_close_inode_sync(inode, !list_empty(&dispose));
598+
count = __nfsd_file_close_inode(inode, &dispose);
599+
trace_nfsd_file_close_inode_sync(inode, count);
595600
nfsd_file_dispose_list_sync(&dispose);
596601
}
597602

598603
/**
599604
* nfsd_file_close_inode - attempt a delayed close of a nfsd_file
600605
* @inode: inode of the file to attempt to remove
601606
*
602-
* Walk the whole hash bucket, looking for any files that correspond to "inode".
603-
* If any do, then unhash them and put the hashtable reference to them and
604-
* destroy any that had their last reference put.
607+
* Unhash and put all cache item associated with @inode.
605608
*/
606609
static void
607610
nfsd_file_close_inode(struct inode *inode)
608611
{
609-
unsigned int hashval = (unsigned int)hash_long(inode->i_ino,
610-
NFSD_FILE_HASH_BITS);
611612
LIST_HEAD(dispose);
613+
unsigned int count;
612614

613-
__nfsd_file_close_inode(inode, hashval, &dispose);
614-
trace_nfsd_file_close_inode(inode, !list_empty(&dispose));
615+
count = __nfsd_file_close_inode(inode, &dispose);
616+
trace_nfsd_file_close_inode(inode, count);
615617
nfsd_file_dispose_list_delayed(&dispose);
616618
}
617619

fs/nfsd/trace.h

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -848,30 +848,52 @@ TRACE_EVENT(nfsd_file_open,
848848

849849
DECLARE_EVENT_CLASS(nfsd_file_search_class,
850850
TP_PROTO(
851-
struct inode *inode,
852-
int found
851+
const struct inode *inode,
852+
unsigned int count
853853
),
854-
TP_ARGS(inode, found),
854+
TP_ARGS(inode, count),
855855
TP_STRUCT__entry(
856-
__field(struct inode *, inode)
857-
__field(int, found)
856+
__field(const struct inode *, inode)
857+
__field(unsigned int, count)
858858
),
859859
TP_fast_assign(
860860
__entry->inode = inode;
861-
__entry->found = found;
861+
__entry->count = count;
862862
),
863-
TP_printk("inode=%p found=%d",
864-
__entry->inode, __entry->found)
863+
TP_printk("inode=%p count=%u",
864+
__entry->inode, __entry->count)
865865
);
866866

867867
#define DEFINE_NFSD_FILE_SEARCH_EVENT(name) \
868868
DEFINE_EVENT(nfsd_file_search_class, name, \
869-
TP_PROTO(struct inode *inode, int found), \
870-
TP_ARGS(inode, found))
869+
TP_PROTO( \
870+
const struct inode *inode, \
871+
unsigned int count \
872+
), \
873+
TP_ARGS(inode, count))
871874

872875
DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_close_inode_sync);
873876
DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_close_inode);
874-
DEFINE_NFSD_FILE_SEARCH_EVENT(nfsd_file_is_cached);
877+
878+
TRACE_EVENT(nfsd_file_is_cached,
879+
TP_PROTO(
880+
const struct inode *inode,
881+
int found
882+
),
883+
TP_ARGS(inode, found),
884+
TP_STRUCT__entry(
885+
__field(const struct inode *, inode)
886+
__field(int, found)
887+
),
888+
TP_fast_assign(
889+
__entry->inode = inode;
890+
__entry->found = found;
891+
),
892+
TP_printk("inode=%p is %scached",
893+
__entry->inode,
894+
__entry->found ? "" : "not "
895+
)
896+
);
875897

876898
TRACE_EVENT(nfsd_file_fsnotify_handle_event,
877899
TP_PROTO(struct inode *inode, u32 mask),

0 commit comments

Comments
 (0)