Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  Device operations for the pnfs client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (c) 2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  The Regents of the University of Michigan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Dean Hildebrand <dhildebz@umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Garth Goodson   <Garth.Goodson@netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  Permission is granted to use, copy, create derivative works, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  redistribute this software and such derivative works for any purpose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  so long as the name of the University of Michigan is not used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  any advertising or publicity pertaining to the use or distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  of this software without specific, written prior authorization. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *  the above copyright notice or any other identification of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  University of Michigan is included in any copy of any portion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *  this software, then the disclaimer below must also be included.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  This software is provided as is, without representation or warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  of any kind either express or implied, including without limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *  the implied warranties of merchantability, fitness for a particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *  purpose, or noninfringement.  The Regents of the University of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *  Michigan shall not be liable for any damages, including special,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *  indirect, incidental, or consequential damages, with respect to any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *  claim arising out of or in connection with the use of the software,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *  even if it has been or is hereafter advised of the possibility of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *  such damages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "nfs4session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define NFSDBG_FACILITY		NFSDBG_PNFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * Device ID RCU cache. A device ID is unique per server and layout type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define NFS4_DEVICE_ID_HASH_BITS	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define NFS4_DEVICE_ID_HASH_SIZE	(1 << NFS4_DEVICE_ID_HASH_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define NFS4_DEVICE_ID_HASH_MASK	(NFS4_DEVICE_ID_HASH_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static DEFINE_SPINLOCK(nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #ifdef NFS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) nfs4_print_deviceid(const struct nfs4_deviceid *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u32 *p = (u32 *)id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	dprintk("%s: device id= [%x%x%x%x]\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		p[0], p[1], p[2], p[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) EXPORT_SYMBOL_GPL(nfs4_print_deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) nfs4_deviceid_hash(const struct nfs4_deviceid *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	unsigned char *cptr = (unsigned char *)id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned int nbytes = NFS4_DEVICEID4_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u32 x = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	while (nbytes--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		x *= 37;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		x += *cptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return x & NFS4_DEVICE_ID_HASH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static struct nfs4_deviceid_node *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) _lookup_deviceid(const struct pnfs_layoutdriver_type *ld,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		 const struct nfs_client *clp, const struct nfs4_deviceid *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		 long hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct nfs4_deviceid_node *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[hash], node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (d->ld == ld && d->nfs_client == clp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		    !memcmp(&d->deviceid, id, sizeof(*id))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			if (atomic_read(&d->ref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static struct nfs4_deviceid_node *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) nfs4_get_device_info(struct nfs_server *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		const struct nfs4_deviceid *dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		const struct cred *cred, gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct nfs4_deviceid_node *d = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct pnfs_device *pdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct page **pages = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	u32 max_resp_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int max_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 * Use the session max response size as the basis for setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * GETDEVICEINFO's maxcount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (server->pnfs_curr_ld->max_deviceinfo_size &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	    server->pnfs_curr_ld->max_deviceinfo_size < max_resp_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		max_resp_sz = server->pnfs_curr_ld->max_deviceinfo_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	max_pages = nfs_page_array_len(0, max_resp_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	dprintk("%s: server %p max_resp_sz %u max_pages %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		__func__, server, max_resp_sz, max_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	pdev = kzalloc(sizeof(*pdev), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (!pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto out_free_pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	for (i = 0; i < max_pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		pages[i] = alloc_page(gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (!pages[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			goto out_free_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	pdev->layout_type = server->pnfs_curr_ld->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	pdev->pages = pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	pdev->pgbase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	pdev->pglen = max_resp_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	pdev->mincount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	pdev->maxcount = max_resp_sz - nfs41_maxgetdevinfo_overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	rc = nfs4_proc_getdeviceinfo(server, pdev, cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	dprintk("%s getdevice info returns %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		goto out_free_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Found new device, need to decode it and then add it to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * list of known devices for this mountpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	d = server->pnfs_curr_ld->alloc_deviceid_node(server, pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (d && pdev->nocache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		set_bit(NFS_DEVICEID_NOCACHE, &d->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) out_free_pages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	for (i = 0; i < max_pages; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		__free_page(pages[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	kfree(pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) out_free_pdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	kfree(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	dprintk("<-- %s d %p\n", __func__, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * Lookup a deviceid in cache and get a reference count on it if found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * @clp nfs_client associated with deviceid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * @id deviceid to look up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static struct nfs4_deviceid_node *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) __nfs4_find_get_deviceid(struct nfs_server *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		const struct nfs4_deviceid *id, long hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct nfs4_deviceid_node *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	d = _lookup_deviceid(server->pnfs_curr_ld, server->nfs_client, id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (d != NULL && !atomic_inc_not_zero(&d->ref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		d = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct nfs4_deviceid_node *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) nfs4_find_get_deviceid(struct nfs_server *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		const struct nfs4_deviceid *id, const struct cred *cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	long hash = nfs4_deviceid_hash(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct nfs4_deviceid_node *d, *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	d = __nfs4_find_get_deviceid(server, id, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	new = nfs4_get_device_info(server, id, cred, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (!new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	spin_lock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	d = __nfs4_find_get_deviceid(server, id, hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		spin_unlock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		server->pnfs_curr_ld->free_deviceid_node(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	hlist_add_head_rcu(&new->node, &nfs4_deviceid_cache[hash]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	atomic_inc(&new->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	spin_unlock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) EXPORT_SYMBOL_GPL(nfs4_find_get_deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * Remove a deviceid from cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * @clp nfs_client associated with deviceid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * @id the deviceid to unhash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * @ret the unhashed node, if found and dereferenced to zero, NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *ld,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			 const struct nfs_client *clp, const struct nfs4_deviceid *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct nfs4_deviceid_node *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	spin_lock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	d = _lookup_deviceid(ld, clp, id, nfs4_deviceid_hash(id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (!d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		spin_unlock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	hlist_del_init_rcu(&d->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	clear_bit(NFS_DEVICEID_NOCACHE, &d->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	spin_unlock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	/* balance the initial ref set in pnfs_insert_deviceid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	nfs4_put_deviceid_node(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) EXPORT_SYMBOL_GPL(nfs4_delete_deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) nfs4_init_deviceid_node(struct nfs4_deviceid_node *d, struct nfs_server *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			const struct nfs4_deviceid *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	INIT_HLIST_NODE(&d->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	INIT_HLIST_NODE(&d->tmpnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	d->ld = server->pnfs_curr_ld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	d->nfs_client = server->nfs_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	d->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	d->deviceid = *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	atomic_set(&d->ref, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) EXPORT_SYMBOL_GPL(nfs4_init_deviceid_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * Dereference a deviceid node and delete it when its reference count drops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @d deviceid node to put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * return true iff the node was deleted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * Note that since the test for d->ref == 0 is sufficient to establish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * that the node is no longer hashed in the global device id cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) nfs4_put_deviceid_node(struct nfs4_deviceid_node *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (test_bit(NFS_DEVICEID_NOCACHE, &d->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		if (atomic_add_unless(&d->ref, -1, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		nfs4_delete_deviceid(d->ld, d->nfs_client, &d->deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (!atomic_dec_and_test(&d->ref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	d->ld->free_deviceid_node(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) EXPORT_SYMBOL_GPL(nfs4_put_deviceid_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) nfs4_mark_deviceid_available(struct nfs4_deviceid_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (test_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		clear_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) EXPORT_SYMBOL_GPL(nfs4_mark_deviceid_available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) nfs4_mark_deviceid_unavailable(struct nfs4_deviceid_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	node->timestamp_unavailable = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	smp_mb__before_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	set_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) EXPORT_SYMBOL_GPL(nfs4_mark_deviceid_unavailable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (test_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		unsigned long start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		end = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		start = end - PNFS_DEVICE_RETRY_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		if (time_in_range(node->timestamp_unavailable, start, end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		clear_bit(NFS_DEVICEID_UNAVAILABLE, &node->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) EXPORT_SYMBOL_GPL(nfs4_test_deviceid_unavailable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) _deviceid_purge_client(const struct nfs_client *clp, long hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct nfs4_deviceid_node *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	HLIST_HEAD(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	spin_lock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[hash], node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		if (d->nfs_client == clp && atomic_read(&d->ref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			hlist_del_init_rcu(&d->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			hlist_add_head(&d->tmpnode, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			clear_bit(NFS_DEVICEID_NOCACHE, &d->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	spin_unlock(&nfs4_deviceid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (hlist_empty(&tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	while (!hlist_empty(&tmp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		d = hlist_entry(tmp.first, struct nfs4_deviceid_node, tmpnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		hlist_del(&d->tmpnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		nfs4_put_deviceid_node(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) nfs4_deviceid_purge_client(const struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	long h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (!(clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_MDS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	for (h = 0; h < NFS4_DEVICE_ID_HASH_SIZE; h++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		_deviceid_purge_client(clp, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * Stop use of all deviceids associated with an nfs_client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) nfs4_deviceid_mark_client_invalid(struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct nfs4_deviceid_node *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	for (i = 0; i < NFS4_DEVICE_ID_HASH_SIZE; i ++){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[i], node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			if (d->nfs_client == clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				set_bit(NFS_DEVICEID_INVALID, &d->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }