Skip to content

Commit 1775bc3

Browse files
Benny HalevyBoaz Harrosh
authored andcommitted
NFSv4.1: purge deviceid cache on nfs_free_client
Use the pnfs_layoutdriver_type both as a qualifier for the deviceid, distinguishing deviceid from different layout types on the server, and for freeing the layout-driver allocated structure containing the nfs4_deviceid_node. [BUG in _deviceid_purge_client] [layout_driver MUST set free_deviceid_node if using dev-cache] [let ver < 4.1 compile] Signed-off-by: Boaz Harrosh <[email protected]> [removed EXPORT_SYMBOL_GPL(nfs4_deviceid_purge_client)] Signed-off-by: Benny Halevy <[email protected]>
1 parent a1eaecb commit 1775bc3

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

fs/nfs/client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ static void nfs_free_client(struct nfs_client *clp)
290290
if (clp->cl_machine_cred != NULL)
291291
put_rpccred(clp->cl_machine_cred);
292292

293+
nfs4_deviceid_purge_client(clp);
294+
293295
kfree(clp->cl_hostname);
294296
kfree(clp);
295297

fs/nfs/nfs4filelayout.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
862862
return -ENOMEM;
863863
}
864864

865+
static void
866+
filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d)
867+
{
868+
nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
869+
}
870+
865871
static struct pnfs_layoutdriver_type filelayout_type = {
866872
.id = LAYOUT_NFSV4_1_FILES,
867873
.name = "LAYOUT_NFSV4_1_FILES",
@@ -874,6 +880,7 @@ static struct pnfs_layoutdriver_type filelayout_type = {
874880
.commit_pagelist = filelayout_commit_pagelist,
875881
.read_pagelist = filelayout_read_pagelist,
876882
.write_pagelist = filelayout_write_pagelist,
883+
.free_deviceid_node = filelayout_free_deveiceid_node,
877884
};
878885

879886
static int __init nfs4filelayout_init(void)

fs/nfs/nfs4filelayout.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ u32 nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j);
9898
struct nfs4_pnfs_ds *nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg,
9999
u32 ds_idx);
100100
extern void nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
101+
extern void nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
101102
struct nfs4_file_layout_dsaddr *
102103
get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags);
103104

fs/nfs/nfs4filelayoutdev.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ destroy_ds(struct nfs4_pnfs_ds *ds)
156156
kfree(ds);
157157
}
158158

159-
static void
159+
void
160160
nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
161161
{
162162
struct nfs4_pnfs_ds *ds;
@@ -386,7 +386,9 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
386386
dsaddr->stripe_indices = stripe_indices;
387387
stripe_indices = NULL;
388388
dsaddr->ds_num = num;
389-
nfs4_init_deviceid_node(&dsaddr->id_node, NFS_SERVER(ino)->nfs_client,
389+
nfs4_init_deviceid_node(&dsaddr->id_node,
390+
NFS_SERVER(ino)->pnfs_curr_ld,
391+
NFS_SERVER(ino)->nfs_client,
390392
&pdev->dev_id);
391393

392394
for (i = 0; i < dsaddr->ds_num; i++) {
@@ -548,8 +550,7 @@ get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_fla
548550
void
549551
nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
550552
{
551-
if (nfs4_put_deviceid_node(&dsaddr->id_node))
552-
nfs4_fl_free_deviceid(dsaddr);
553+
nfs4_put_deviceid_node(&dsaddr->id_node);
553554
}
554555

555556
/*

fs/nfs/pnfs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ enum {
6565
NFS_LAYOUT_DESTROYED, /* no new use of layout allowed */
6666
};
6767

68+
struct nfs4_deviceid_node;
69+
6870
/* Per-layout driver specific registration structure */
6971
struct pnfs_layoutdriver_type {
7072
struct list_head pnfs_tblid;
@@ -90,6 +92,8 @@ struct pnfs_layoutdriver_type {
9092
*/
9193
enum pnfs_try_status (*read_pagelist) (struct nfs_read_data *nfs_data);
9294
enum pnfs_try_status (*write_pagelist) (struct nfs_write_data *nfs_data, int how);
95+
96+
void (*free_deviceid_node) (struct nfs4_deviceid_node *);
9397
};
9498

9599
struct pnfs_layout_hdr {
@@ -160,6 +164,7 @@ int pnfs_layoutcommit_inode(struct inode *inode, bool sync);
160164
/* pnfs_dev.c */
161165
struct nfs4_deviceid_node {
162166
struct hlist_node node;
167+
const struct pnfs_layoutdriver_type *ld;
163168
const struct nfs_client *nfs_client;
164169
struct nfs4_deviceid deviceid;
165170
atomic_t ref;
@@ -169,10 +174,12 @@ void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
169174
struct nfs4_deviceid_node *nfs4_find_get_deviceid(const struct nfs_client *, const struct nfs4_deviceid *);
170175
struct nfs4_deviceid_node *nfs4_unhash_put_deviceid(const struct nfs_client *, const struct nfs4_deviceid *);
171176
void nfs4_init_deviceid_node(struct nfs4_deviceid_node *,
177+
const struct pnfs_layoutdriver_type *,
172178
const struct nfs_client *,
173179
const struct nfs4_deviceid *);
174180
struct nfs4_deviceid_node *nfs4_insert_deviceid_node(struct nfs4_deviceid_node *);
175181
bool nfs4_put_deviceid_node(struct nfs4_deviceid_node *);
182+
void nfs4_deviceid_purge_client(const struct nfs_client *);
176183

177184
static inline int lo_fail_bit(u32 iomode)
178185
{
@@ -349,6 +356,10 @@ static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync)
349356
{
350357
return 0;
351358
}
359+
360+
static inline void nfs4_deviceid_purge_client(struct nfs_client *ncl)
361+
{
362+
}
352363
#endif /* CONFIG_NFS_V4_1 */
353364

354365
#endif /* FS_NFS_PNFS_H */

fs/nfs/pnfs_dev.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,26 @@ EXPORT_SYMBOL_GPL(nfs4_find_get_deviceid);
9696

9797
void
9898
nfs4_init_deviceid_node(struct nfs4_deviceid_node *d,
99+
const struct pnfs_layoutdriver_type *ld,
99100
const struct nfs_client *nfs_client,
100101
const struct nfs4_deviceid *id)
101102
{
103+
INIT_HLIST_NODE(&d->node);
104+
d->ld = ld;
102105
d->nfs_client = nfs_client;
103106
d->deviceid = *id;
107+
atomic_set(&d->ref, 1);
104108
}
105109
EXPORT_SYMBOL_GPL(nfs4_init_deviceid_node);
106110

107111
/*
108112
* Uniquely initialize and insert a deviceid node into cache
109113
*
110114
* @new new deviceid node
111-
* Note that the caller must set up new->nfs_client and new->deviceid
115+
* Note that the caller must set up the following members:
116+
* new->ld
117+
* new->nfs_client
118+
* new->deviceid
112119
*
113120
* @ret the inserted node, if none found, otherwise, the found entry.
114121
*/
@@ -125,8 +132,6 @@ nfs4_insert_deviceid_node(struct nfs4_deviceid_node *new)
125132
return d;
126133
}
127134

128-
INIT_HLIST_NODE(&new->node);
129-
atomic_set(&new->ref, 1);
130135
hash = nfs4_deviceid_hash(&new->deviceid);
131136
hlist_add_head_rcu(&new->node, &nfs4_deviceid_cache[hash]);
132137
spin_unlock(&nfs4_deviceid_lock);
@@ -151,6 +156,42 @@ nfs4_put_deviceid_node(struct nfs4_deviceid_node *d)
151156
hlist_del_init_rcu(&d->node);
152157
spin_unlock(&nfs4_deviceid_lock);
153158
synchronize_rcu();
159+
d->ld->free_deviceid_node(d);
154160
return true;
155161
}
156162
EXPORT_SYMBOL_GPL(nfs4_put_deviceid_node);
163+
164+
static void
165+
_deviceid_purge_client(const struct nfs_client *clp, long hash)
166+
{
167+
struct nfs4_deviceid_node *d;
168+
struct hlist_node *n, *next;
169+
HLIST_HEAD(tmp);
170+
171+
rcu_read_lock();
172+
hlist_for_each_entry_rcu(d, n, &nfs4_deviceid_cache[hash], node)
173+
if (d->nfs_client == clp && atomic_read(&d->ref)) {
174+
hlist_del_init_rcu(&d->node);
175+
hlist_add_head(&d->node, &tmp);
176+
}
177+
rcu_read_unlock();
178+
179+
if (hlist_empty(&tmp))
180+
return;
181+
182+
synchronize_rcu();
183+
hlist_for_each_entry_safe(d, n, next, &tmp, node)
184+
if (atomic_dec_and_test(&d->ref))
185+
d->ld->free_deviceid_node(d);
186+
}
187+
188+
void
189+
nfs4_deviceid_purge_client(const struct nfs_client *clp)
190+
{
191+
long h;
192+
193+
spin_lock(&nfs4_deviceid_lock);
194+
for (h = 0; h < NFS4_DEVICE_ID_HASH_SIZE; h++)
195+
_deviceid_purge_client(clp, h);
196+
spin_unlock(&nfs4_deviceid_lock);
197+
}

0 commit comments

Comments
 (0)