31 #include <linux/export.h>
34 #define NFSDBG_FACILITY NFSDBG_PNFS
39 #define NFS4_DEVICE_ID_HASH_BITS 5
40 #define NFS4_DEVICE_ID_HASH_SIZE (1 << NFS4_DEVICE_ID_HASH_BITS)
41 #define NFS4_DEVICE_ID_HASH_MASK (NFS4_DEVICE_ID_HASH_SIZE - 1)
43 #define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ)
54 dprintk(
"%s: device id= [%x%x%x%x]\n", __func__,
55 p[0], p[1], p[2], p[3]);
63 unsigned char *cptr = (
unsigned char *)id->
data;
74 static struct nfs4_deviceid_node *
75 _lookup_deviceid(
const struct pnfs_layoutdriver_type *
ld,
79 struct nfs4_deviceid_node *
d;
82 hlist_for_each_entry_rcu(d, n, &nfs4_deviceid_cache[hash],
node)
99 static struct nfs4_deviceid_node *
100 _find_get_deviceid(
const struct pnfs_layoutdriver_type *ld,
104 struct nfs4_deviceid_node *
d;
107 d = _lookup_deviceid(ld, clp,
id, hash);
114 struct nfs4_deviceid_node *
118 return _find_get_deviceid(ld, clp,
id, nfs4_deviceid_hash(
id));
134 struct nfs4_deviceid_node *
d;
136 spin_lock(&nfs4_deviceid_lock);
138 d = _lookup_deviceid(ld, clp,
id, nfs4_deviceid_hash(
id));
141 spin_unlock(&nfs4_deviceid_lock);
144 hlist_del_init_rcu(&d->node);
145 spin_unlock(&nfs4_deviceid_lock);
150 d->ld->free_deviceid_node(d);
156 const struct pnfs_layoutdriver_type *ld,
160 INIT_HLIST_NODE(&d->node);
161 INIT_HLIST_NODE(&d->tmpnode);
163 d->nfs_client = nfs_client;
181 struct nfs4_deviceid_node *
184 struct nfs4_deviceid_node *
d;
187 spin_lock(&nfs4_deviceid_lock);
188 hash = nfs4_deviceid_hash(&new->deviceid);
189 d = _find_get_deviceid(new->ld, new->nfs_client, &new->deviceid, hash);
191 spin_unlock(&nfs4_deviceid_lock);
195 hlist_add_head_rcu(&new->node, &nfs4_deviceid_cache[hash]);
196 spin_unlock(&nfs4_deviceid_lock);
218 d->ld->free_deviceid_node(d);
226 node->timestamp_unavailable =
jiffies;
227 set_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
234 if (
test_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags)) {
241 clear_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
248 _deviceid_purge_client(
const struct nfs_client *clp,
long hash)
250 struct nfs4_deviceid_node *
d;
254 spin_lock(&nfs4_deviceid_lock);
256 hlist_for_each_entry_rcu(d, n, &nfs4_deviceid_cache[hash],
node)
258 hlist_del_init_rcu(&d->node);
259 hlist_add_head(&d->tmpnode, &
tmp);
262 spin_unlock(&nfs4_deviceid_lock);
264 if (hlist_empty(&
tmp))
268 while (!hlist_empty(&
tmp)) {
270 hlist_del(&d->tmpnode);
272 d->ld->free_deviceid_node(d);
284 _deviceid_purge_client(clp, h);
293 struct nfs4_deviceid_node *
d;
299 hlist_for_each_entry_rcu(d, n, &nfs4_deviceid_cache[i],
node)
300 if (d->nfs_client == clp)
301 set_bit(NFS_DEVICEID_INVALID, &d->flags);