2011-05-19 20:14:47 -06:00
|
|
|
/*
|
|
|
|
* Device operations for the pnfs client.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002
|
|
|
|
* The Regents of the University of Michigan
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Dean Hildebrand <dhildebz@umich.edu>
|
|
|
|
* Garth Goodson <Garth.Goodson@netapp.com>
|
|
|
|
*
|
|
|
|
* Permission is granted to use, copy, create derivative works, and
|
|
|
|
* redistribute this software and such derivative works for any purpose,
|
|
|
|
* so long as the name of the University of Michigan is not used in
|
|
|
|
* any advertising or publicity pertaining to the use or distribution
|
|
|
|
* of this software without specific, written prior authorization. If
|
|
|
|
* the above copyright notice or any other identification of the
|
|
|
|
* University of Michigan is included in any copy of any portion of
|
|
|
|
* this software, then the disclaimer below must also be included.
|
|
|
|
*
|
|
|
|
* This software is provided as is, without representation or warranty
|
|
|
|
* of any kind either express or implied, including without limitation
|
|
|
|
* the implied warranties of merchantability, fitness for a particular
|
|
|
|
* purpose, or noninfringement. The Regents of the University of
|
|
|
|
* Michigan shall not be liable for any damages, including special,
|
|
|
|
* indirect, incidental, or consequential damages, with respect to any
|
|
|
|
* claim arising out of or in connection with the use of the software,
|
|
|
|
* even if it has been or is hereafter advised of the possibility of
|
|
|
|
* such damages.
|
|
|
|
*/
|
|
|
|
|
2011-05-26 14:00:52 -06:00
|
|
|
#include <linux/export.h>
|
2014-09-02 22:27:57 -06:00
|
|
|
#include <linux/nfs_fs.h>
|
|
|
|
#include "nfs4session.h"
|
|
|
|
#include "internal.h"
|
2011-05-19 20:14:47 -06:00
|
|
|
#include "pnfs.h"
|
|
|
|
|
|
|
|
#define NFSDBG_FACILITY NFSDBG_PNFS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device ID RCU cache. A device ID is unique per server and layout type.
|
|
|
|
*/
|
|
|
|
#define NFS4_DEVICE_ID_HASH_BITS 5
|
|
|
|
#define NFS4_DEVICE_ID_HASH_SIZE (1 << NFS4_DEVICE_ID_HASH_BITS)
|
|
|
|
#define NFS4_DEVICE_ID_HASH_MASK (NFS4_DEVICE_ID_HASH_SIZE - 1)
|
|
|
|
|
2012-09-18 17:51:12 -06:00
|
|
|
#define PNFS_DEVICE_RETRY_TIMEOUT (120*HZ)
|
|
|
|
|
2011-05-19 20:14:47 -06:00
|
|
|
static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE];
|
|
|
|
static DEFINE_SPINLOCK(nfs4_deviceid_lock);
|
|
|
|
|
2012-03-20 12:12:46 -06:00
|
|
|
#ifdef NFS_DEBUG
|
2011-05-19 20:14:47 -06:00
|
|
|
void
|
|
|
|
nfs4_print_deviceid(const struct nfs4_deviceid *id)
|
|
|
|
{
|
|
|
|
u32 *p = (u32 *)id;
|
|
|
|
|
|
|
|
dprintk("%s: device id= [%x%x%x%x]\n", __func__,
|
|
|
|
p[0], p[1], p[2], p[3]);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_print_deviceid);
|
2012-03-20 12:12:46 -06:00
|
|
|
#endif
|
2011-05-19 20:14:47 -06:00
|
|
|
|
|
|
|
static inline u32
|
|
|
|
nfs4_deviceid_hash(const struct nfs4_deviceid *id)
|
|
|
|
{
|
|
|
|
unsigned char *cptr = (unsigned char *)id->data;
|
|
|
|
unsigned int nbytes = NFS4_DEVICEID4_SIZE;
|
|
|
|
u32 x = 0;
|
|
|
|
|
|
|
|
while (nbytes--) {
|
|
|
|
x *= 37;
|
|
|
|
x += *cptr++;
|
|
|
|
}
|
|
|
|
return x & NFS4_DEVICE_ID_HASH_MASK;
|
|
|
|
}
|
|
|
|
|
2011-05-22 10:47:09 -06:00
|
|
|
static struct nfs4_deviceid_node *
|
2011-05-24 09:04:02 -06:00
|
|
|
_lookup_deviceid(const struct pnfs_layoutdriver_type *ld,
|
|
|
|
const struct nfs_client *clp, const struct nfs4_deviceid *id,
|
2011-05-22 10:47:09 -06:00
|
|
|
long hash)
|
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *d;
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 18:06:00 -07:00
|
|
|
hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[hash], node)
|
2011-05-24 09:04:02 -06:00
|
|
|
if (d->ld == ld && d->nfs_client == clp &&
|
|
|
|
!memcmp(&d->deviceid, id, sizeof(*id))) {
|
2011-05-22 10:47:09 -06:00
|
|
|
if (atomic_read(&d->ref))
|
|
|
|
return d;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-02 22:27:57 -06:00
|
|
|
static struct nfs4_deviceid_node *
|
|
|
|
nfs4_get_device_info(struct nfs_server *server,
|
|
|
|
const struct nfs4_deviceid *dev_id,
|
|
|
|
struct rpc_cred *cred, gfp_t gfp_flags)
|
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *d = NULL;
|
|
|
|
struct pnfs_device *pdev = NULL;
|
|
|
|
struct page **pages = NULL;
|
|
|
|
u32 max_resp_sz;
|
|
|
|
int max_pages;
|
|
|
|
int rc, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the session max response size as the basis for setting
|
|
|
|
* GETDEVICEINFO's maxcount
|
|
|
|
*/
|
|
|
|
max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
|
|
|
|
if (server->pnfs_curr_ld->max_deviceinfo_size &&
|
|
|
|
server->pnfs_curr_ld->max_deviceinfo_size < max_resp_sz)
|
|
|
|
max_resp_sz = server->pnfs_curr_ld->max_deviceinfo_size;
|
|
|
|
max_pages = nfs_page_array_len(0, max_resp_sz);
|
|
|
|
dprintk("%s: server %p max_resp_sz %u max_pages %d\n",
|
|
|
|
__func__, server, max_resp_sz, max_pages);
|
|
|
|
|
|
|
|
pdev = kzalloc(sizeof(*pdev), gfp_flags);
|
|
|
|
if (!pdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags);
|
|
|
|
if (!pages)
|
|
|
|
goto out_free_pdev;
|
|
|
|
|
|
|
|
for (i = 0; i < max_pages; i++) {
|
|
|
|
pages[i] = alloc_page(gfp_flags);
|
|
|
|
if (!pages[i])
|
|
|
|
goto out_free_pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id));
|
|
|
|
pdev->layout_type = server->pnfs_curr_ld->id;
|
|
|
|
pdev->pages = pages;
|
|
|
|
pdev->pgbase = 0;
|
|
|
|
pdev->pglen = max_resp_sz;
|
|
|
|
pdev->mincount = 0;
|
|
|
|
pdev->maxcount = max_resp_sz - nfs41_maxgetdevinfo_overhead;
|
|
|
|
|
|
|
|
rc = nfs4_proc_getdeviceinfo(server, pdev, cred);
|
|
|
|
dprintk("%s getdevice info returns %d\n", __func__, rc);
|
|
|
|
if (rc)
|
|
|
|
goto out_free_pages;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Found new device, need to decode it and then add it to the
|
|
|
|
* list of known devices for this mountpoint.
|
|
|
|
*/
|
|
|
|
d = server->pnfs_curr_ld->alloc_deviceid_node(server, pdev,
|
|
|
|
gfp_flags);
|
|
|
|
|
|
|
|
out_free_pages:
|
|
|
|
for (i = 0; i < max_pages; i++)
|
|
|
|
__free_page(pages[i]);
|
|
|
|
kfree(pages);
|
|
|
|
out_free_pdev:
|
|
|
|
kfree(pdev);
|
|
|
|
dprintk("<-- %s d %p\n", __func__, d);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2011-05-19 20:14:47 -06:00
|
|
|
/*
|
|
|
|
* Lookup a deviceid in cache and get a reference count on it if found
|
|
|
|
*
|
|
|
|
* @clp nfs_client associated with deviceid
|
|
|
|
* @id deviceid to look up
|
|
|
|
*/
|
2012-03-11 11:11:00 -06:00
|
|
|
static struct nfs4_deviceid_node *
|
2014-09-02 22:27:57 -06:00
|
|
|
__nfs4_find_get_deviceid(struct nfs_server *server,
|
|
|
|
const struct nfs4_deviceid *id, long hash)
|
2011-05-22 10:47:09 -06:00
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *d;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2014-09-02 22:27:57 -06:00
|
|
|
d = _lookup_deviceid(server->pnfs_curr_ld, server->nfs_client, id,
|
|
|
|
hash);
|
2011-06-14 10:18:11 -06:00
|
|
|
if (d != NULL)
|
|
|
|
atomic_inc(&d->ref);
|
2011-05-22 10:47:09 -06:00
|
|
|
rcu_read_unlock();
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2011-05-19 20:14:47 -06:00
|
|
|
struct nfs4_deviceid_node *
|
2014-09-02 22:27:57 -06:00
|
|
|
nfs4_find_get_deviceid(struct nfs_server *server,
|
|
|
|
const struct nfs4_deviceid *id, struct rpc_cred *cred,
|
|
|
|
gfp_t gfp_mask)
|
2011-05-22 10:47:09 -06:00
|
|
|
{
|
2014-09-02 22:27:57 -06:00
|
|
|
long hash = nfs4_deviceid_hash(id);
|
|
|
|
struct nfs4_deviceid_node *d, *new;
|
|
|
|
|
|
|
|
d = __nfs4_find_get_deviceid(server, id, hash);
|
|
|
|
if (d)
|
|
|
|
return d;
|
|
|
|
|
|
|
|
new = nfs4_get_device_info(server, id, cred, gfp_mask);
|
|
|
|
if (!new)
|
|
|
|
return new;
|
|
|
|
|
|
|
|
spin_lock(&nfs4_deviceid_lock);
|
|
|
|
d = __nfs4_find_get_deviceid(server, id, hash);
|
|
|
|
if (d) {
|
|
|
|
spin_unlock(&nfs4_deviceid_lock);
|
|
|
|
server->pnfs_curr_ld->free_deviceid_node(new);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
hlist_add_head_rcu(&new->node, &nfs4_deviceid_cache[hash]);
|
|
|
|
atomic_inc(&new->ref);
|
|
|
|
spin_unlock(&nfs4_deviceid_lock);
|
|
|
|
|
|
|
|
return new;
|
2011-05-22 10:47:09 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_find_get_deviceid);
|
|
|
|
|
|
|
|
/*
|
2011-06-14 10:18:11 -06:00
|
|
|
* Remove a deviceid from cache
|
2011-05-22 10:47:09 -06:00
|
|
|
*
|
|
|
|
* @clp nfs_client associated with deviceid
|
|
|
|
* @id the deviceid to unhash
|
|
|
|
*
|
|
|
|
* @ret the unhashed node, if found and dereferenced to zero, NULL otherwise.
|
|
|
|
*/
|
2011-06-14 10:18:11 -06:00
|
|
|
void
|
|
|
|
nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *ld,
|
2011-05-24 09:04:02 -06:00
|
|
|
const struct nfs_client *clp, const struct nfs4_deviceid *id)
|
2011-05-19 20:14:47 -06:00
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *d;
|
|
|
|
|
2011-05-22 10:47:09 -06:00
|
|
|
spin_lock(&nfs4_deviceid_lock);
|
2011-05-19 20:14:47 -06:00
|
|
|
rcu_read_lock();
|
2011-05-24 09:04:02 -06:00
|
|
|
d = _lookup_deviceid(ld, clp, id, nfs4_deviceid_hash(id));
|
2011-05-19 20:14:47 -06:00
|
|
|
rcu_read_unlock();
|
2011-05-22 10:47:09 -06:00
|
|
|
if (!d) {
|
|
|
|
spin_unlock(&nfs4_deviceid_lock);
|
2011-06-14 10:18:11 -06:00
|
|
|
return;
|
2011-05-22 10:47:09 -06:00
|
|
|
}
|
|
|
|
hlist_del_init_rcu(&d->node);
|
|
|
|
spin_unlock(&nfs4_deviceid_lock);
|
|
|
|
synchronize_rcu();
|
|
|
|
|
|
|
|
/* balance the initial ref set in pnfs_insert_deviceid */
|
|
|
|
if (atomic_dec_and_test(&d->ref))
|
2011-06-14 10:18:11 -06:00
|
|
|
d->ld->free_deviceid_node(d);
|
2011-05-22 10:47:09 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_delete_deviceid);
|
2011-05-19 20:14:47 -06:00
|
|
|
|
|
|
|
void
|
2014-09-02 22:27:57 -06:00
|
|
|
nfs4_init_deviceid_node(struct nfs4_deviceid_node *d, struct nfs_server *server,
|
2011-05-19 20:14:47 -06:00
|
|
|
const struct nfs4_deviceid *id)
|
|
|
|
{
|
2011-05-20 05:47:33 -06:00
|
|
|
INIT_HLIST_NODE(&d->node);
|
2011-05-31 19:46:50 -06:00
|
|
|
INIT_HLIST_NODE(&d->tmpnode);
|
2014-09-02 22:27:57 -06:00
|
|
|
d->ld = server->pnfs_curr_ld;
|
|
|
|
d->nfs_client = server->nfs_client;
|
2011-06-15 15:52:40 -06:00
|
|
|
d->flags = 0;
|
2011-05-19 20:14:47 -06:00
|
|
|
d->deviceid = *id;
|
2011-05-20 05:47:33 -06:00
|
|
|
atomic_set(&d->ref, 1);
|
2011-05-19 20:14:47 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_init_deviceid_node);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dereference a deviceid node and delete it when its reference count drops
|
|
|
|
* to zero.
|
|
|
|
*
|
|
|
|
* @d deviceid node to put
|
|
|
|
*
|
2011-06-14 10:18:11 -06:00
|
|
|
* return true iff the node was deleted
|
|
|
|
* Note that since the test for d->ref == 0 is sufficient to establish
|
|
|
|
* that the node is no longer hashed in the global device id cache.
|
2011-05-19 20:14:47 -06:00
|
|
|
*/
|
|
|
|
bool
|
|
|
|
nfs4_put_deviceid_node(struct nfs4_deviceid_node *d)
|
|
|
|
{
|
2011-06-14 10:18:11 -06:00
|
|
|
if (!atomic_dec_and_test(&d->ref))
|
2011-05-19 20:14:47 -06:00
|
|
|
return false;
|
2011-05-20 05:47:33 -06:00
|
|
|
d->ld->free_deviceid_node(d);
|
2011-05-19 20:14:47 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_put_deviceid_node);
|
2011-05-20 05:47:33 -06:00
|
|
|
|
2012-09-18 17:51:12 -06:00
|
|
|
void
|
|
|
|
nfs4_mark_deviceid_unavailable(struct nfs4_deviceid_node *node)
|
|
|
|
{
|
|
|
|
node->timestamp_unavailable = jiffies;
|
|
|
|
set_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_mark_deviceid_unavailable);
|
|
|
|
|
|
|
|
bool
|
|
|
|
nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node)
|
|
|
|
{
|
|
|
|
if (test_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags)) {
|
|
|
|
unsigned long start, end;
|
|
|
|
|
|
|
|
end = jiffies;
|
|
|
|
start = end - PNFS_DEVICE_RETRY_TIMEOUT;
|
|
|
|
if (time_in_range(node->timestamp_unavailable, start, end))
|
|
|
|
return true;
|
|
|
|
clear_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nfs4_test_deviceid_unavailable);
|
|
|
|
|
2011-05-20 05:47:33 -06:00
|
|
|
static void
|
|
|
|
_deviceid_purge_client(const struct nfs_client *clp, long hash)
|
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *d;
|
|
|
|
HLIST_HEAD(tmp);
|
|
|
|
|
2011-05-31 19:46:50 -06:00
|
|
|
spin_lock(&nfs4_deviceid_lock);
|
2011-05-20 05:47:33 -06:00
|
|
|
rcu_read_lock();
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 18:06:00 -07:00
|
|
|
hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[hash], node)
|
2011-05-20 05:47:33 -06:00
|
|
|
if (d->nfs_client == clp && atomic_read(&d->ref)) {
|
|
|
|
hlist_del_init_rcu(&d->node);
|
2011-05-31 19:46:50 -06:00
|
|
|
hlist_add_head(&d->tmpnode, &tmp);
|
2011-05-20 05:47:33 -06:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2011-05-31 19:46:50 -06:00
|
|
|
spin_unlock(&nfs4_deviceid_lock);
|
2011-05-20 05:47:33 -06:00
|
|
|
|
|
|
|
if (hlist_empty(&tmp))
|
|
|
|
return;
|
|
|
|
|
|
|
|
synchronize_rcu();
|
2011-05-31 19:46:50 -06:00
|
|
|
while (!hlist_empty(&tmp)) {
|
|
|
|
d = hlist_entry(tmp.first, struct nfs4_deviceid_node, tmpnode);
|
|
|
|
hlist_del(&d->tmpnode);
|
2011-05-20 05:47:33 -06:00
|
|
|
if (atomic_dec_and_test(&d->ref))
|
|
|
|
d->ld->free_deviceid_node(d);
|
2011-05-31 19:46:50 -06:00
|
|
|
}
|
2011-05-20 05:47:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs4_deviceid_purge_client(const struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
long h;
|
|
|
|
|
2011-05-31 19:46:50 -06:00
|
|
|
if (!(clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_MDS))
|
|
|
|
return;
|
2011-05-20 05:47:33 -06:00
|
|
|
for (h = 0; h < NFS4_DEVICE_ID_HASH_SIZE; h++)
|
|
|
|
_deviceid_purge_client(clp, h);
|
|
|
|
}
|
2011-06-15 15:52:40 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop use of all deviceids associated with an nfs_client
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs4_deviceid_mark_client_invalid(struct nfs_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_deviceid_node *d;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
for (i = 0; i < NFS4_DEVICE_ID_HASH_SIZE; i ++){
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 18:06:00 -07:00
|
|
|
hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[i], node)
|
2011-06-15 15:52:40 -06:00
|
|
|
if (d->nfs_client == clp)
|
|
|
|
set_bit(NFS_DEVICEID_INVALID, &d->flags);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|