mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 00:10:51 +07:00
NFSv4.2: add client side xattr caching.
Implement client side caching for NFSv4.2 extended attributes. The cache is a per-inode hashtable, with name/value entries. There is one special entry for the listxattr cache. NFS inodes have a pointer to a cache structure. The cache structure is allocated on demand, freed when the cache is invalidated. Memory shrinkers keep the size in check. Large entries (> PAGE_SIZE) are collected by a separate shrinker, and freed more aggressively than others. Signed-off-by: Frank van der Linden <fllinden@amazon.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
parent
012a211abd
commit
95ad37f90c
@ -30,7 +30,7 @@ nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o
|
||||
nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o
|
||||
nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o
|
||||
nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o pnfs_nfs.o
|
||||
nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o
|
||||
nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o nfs42xattr.o
|
||||
|
||||
obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/
|
||||
obj-$(CONFIG_PNFS_BLOCK) += blocklayout/
|
||||
|
@ -193,6 +193,7 @@ bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags)
|
||||
|
||||
return nfs_check_cache_invalid_not_delegated(inode, flags);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nfs_check_cache_invalid);
|
||||
|
||||
static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
|
||||
{
|
||||
@ -234,11 +235,13 @@ static void nfs_zap_caches_locked(struct inode *inode)
|
||||
| NFS_INO_INVALID_DATA
|
||||
| NFS_INO_INVALID_ACCESS
|
||||
| NFS_INO_INVALID_ACL
|
||||
| NFS_INO_INVALID_XATTR
|
||||
| NFS_INO_REVAL_PAGECACHE);
|
||||
} else
|
||||
nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR
|
||||
| NFS_INO_INVALID_ACCESS
|
||||
| NFS_INO_INVALID_ACL
|
||||
| NFS_INO_INVALID_XATTR
|
||||
| NFS_INO_REVAL_PAGECACHE);
|
||||
nfs_zap_label_cache_locked(nfsi);
|
||||
}
|
||||
@ -1897,7 +1900,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
|
||||
if (!(have_writers || have_delegation)) {
|
||||
invalid |= NFS_INO_INVALID_DATA
|
||||
| NFS_INO_INVALID_ACCESS
|
||||
| NFS_INO_INVALID_ACL;
|
||||
| NFS_INO_INVALID_ACL
|
||||
| NFS_INO_INVALID_XATTR;
|
||||
/* Force revalidate of all attributes */
|
||||
save_cache_validity |= NFS_INO_INVALID_CTIME
|
||||
| NFS_INO_INVALID_MTIME
|
||||
@ -2100,6 +2104,9 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
|
||||
#if IS_ENABLED(CONFIG_NFS_V4)
|
||||
nfsi->nfs4_acl = NULL;
|
||||
#endif /* CONFIG_NFS_V4 */
|
||||
#ifdef CONFIG_NFS_V4_2
|
||||
nfsi->xattr_cache = NULL;
|
||||
#endif
|
||||
return &nfsi->vfs_inode;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nfs_alloc_inode);
|
||||
|
@ -1182,6 +1182,18 @@ static ssize_t _nfs42_proc_getxattr(struct inode *inode, const char *name,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* Normally, the caching is done one layer up, but for successful
|
||||
* RPCS, always cache the result here, even if the caller was
|
||||
* just querying the length, or if the reply was too big for
|
||||
* the caller. This avoids a second RPC in the case of the
|
||||
* common query-alloc-retrieve cycle for xattrs.
|
||||
*
|
||||
* Note that xattr_len is always capped to XATTR_SIZE_MAX.
|
||||
*/
|
||||
|
||||
nfs4_xattr_cache_add(inode, name, NULL, pages, res.xattr_len);
|
||||
|
||||
if (buflen) {
|
||||
if (res.xattr_len > buflen)
|
||||
return -ERANGE;
|
||||
|
1083
fs/nfs/nfs42xattr.c
Normal file
1083
fs/nfs/nfs42xattr.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -626,12 +626,34 @@ static inline bool nfs4_state_match_open_stateid_other(const struct nfs4_state *
|
||||
nfs4_stateid_match_other(&state->open_stateid, stateid);
|
||||
}
|
||||
|
||||
/* nfs42xattr.c */
|
||||
#ifdef CONFIG_NFS_V4_2
|
||||
extern int __init nfs4_xattr_cache_init(void);
|
||||
extern void nfs4_xattr_cache_exit(void);
|
||||
extern void nfs4_xattr_cache_add(struct inode *inode, const char *name,
|
||||
const char *buf, struct page **pages,
|
||||
ssize_t buflen);
|
||||
extern void nfs4_xattr_cache_remove(struct inode *inode, const char *name);
|
||||
extern ssize_t nfs4_xattr_cache_get(struct inode *inode, const char *name,
|
||||
char *buf, ssize_t buflen);
|
||||
extern void nfs4_xattr_cache_set_list(struct inode *inode, const char *buf,
|
||||
ssize_t buflen);
|
||||
extern ssize_t nfs4_xattr_cache_list(struct inode *inode, char *buf,
|
||||
ssize_t buflen);
|
||||
extern void nfs4_xattr_cache_zap(struct inode *inode);
|
||||
#else
|
||||
static inline void nfs4_xattr_cache_zap(struct inode *inode)
|
||||
{
|
||||
}
|
||||
#endif /* CONFIG_NFS_V4_2 */
|
||||
|
||||
#else /* CONFIG_NFS_V4 */
|
||||
|
||||
#define nfs4_close_state(a, b) do { } while (0)
|
||||
#define nfs4_close_sync(a, b) do { } while (0)
|
||||
#define nfs4_state_protect(a, b, c, d) do { } while (0)
|
||||
#define nfs4_state_protect_write(a, b, c, d) do { } while (0)
|
||||
|
||||
|
||||
#endif /* CONFIG_NFS_V4 */
|
||||
#endif /* __LINUX_FS_NFS_NFS4_FS.H */
|
||||
|
@ -7448,6 +7448,7 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
|
||||
size_t buflen, int flags)
|
||||
{
|
||||
struct nfs_access_entry cache;
|
||||
int ret;
|
||||
|
||||
if (!nfs_server_capable(inode, NFS_CAP_XATTR))
|
||||
return -EOPNOTSUPP;
|
||||
@ -7466,10 +7467,17 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
if (buf == NULL)
|
||||
return nfs42_proc_removexattr(inode, key);
|
||||
else
|
||||
return nfs42_proc_setxattr(inode, key, buf, buflen, flags);
|
||||
if (buf == NULL) {
|
||||
ret = nfs42_proc_removexattr(inode, key);
|
||||
if (!ret)
|
||||
nfs4_xattr_cache_remove(inode, key);
|
||||
} else {
|
||||
ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags);
|
||||
if (!ret)
|
||||
nfs4_xattr_cache_add(inode, key, buf, NULL, buflen);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
|
||||
@ -7477,6 +7485,7 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
|
||||
const char *key, void *buf, size_t buflen)
|
||||
{
|
||||
struct nfs_access_entry cache;
|
||||
ssize_t ret;
|
||||
|
||||
if (!nfs_server_capable(inode, NFS_CAP_XATTR))
|
||||
return -EOPNOTSUPP;
|
||||
@ -7486,7 +7495,17 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
return nfs42_proc_getxattr(inode, key, buf, buflen);
|
||||
ret = nfs_revalidate_inode(NFS_SERVER(inode), inode);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = nfs4_xattr_cache_get(inode, key, buf, buflen);
|
||||
if (ret >= 0 || (ret < 0 && ret != -ENOENT))
|
||||
return ret;
|
||||
|
||||
ret = nfs42_proc_getxattr(inode, key, buf, buflen);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
@ -7494,7 +7513,7 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
|
||||
{
|
||||
u64 cookie;
|
||||
bool eof;
|
||||
int ret, size;
|
||||
ssize_t ret, size;
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
struct nfs_access_entry cache;
|
||||
@ -7507,6 +7526,14 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = nfs_revalidate_inode(NFS_SERVER(inode), inode);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = nfs4_xattr_cache_list(inode, list, list_len);
|
||||
if (ret >= 0 || (ret < 0 && ret != -ENOENT))
|
||||
return ret;
|
||||
|
||||
cookie = 0;
|
||||
eof = false;
|
||||
buflen = list_len ? list_len : XATTR_LIST_MAX;
|
||||
@ -7526,6 +7553,9 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
|
||||
size += ret;
|
||||
}
|
||||
|
||||
if (list_len)
|
||||
nfs4_xattr_cache_set_list(inode, list, size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,7 @@ static void nfs4_evict_inode(struct inode *inode)
|
||||
pnfs_destroy_layout(NFS_I(inode));
|
||||
/* First call standard NFS clear_inode() code */
|
||||
nfs_clear_inode(inode);
|
||||
nfs4_xattr_cache_zap(inode);
|
||||
}
|
||||
|
||||
struct nfs_referral_count {
|
||||
@ -268,6 +269,12 @@ static int __init init_nfs_v4(void)
|
||||
if (err)
|
||||
goto out1;
|
||||
|
||||
#ifdef CONFIG_NFS_V4_2
|
||||
err = nfs4_xattr_cache_init();
|
||||
if (err)
|
||||
goto out2;
|
||||
#endif
|
||||
|
||||
err = nfs4_register_sysctl();
|
||||
if (err)
|
||||
goto out2;
|
||||
@ -288,6 +295,9 @@ static void __exit exit_nfs_v4(void)
|
||||
nfs4_pnfs_v3_ds_connect_unload();
|
||||
|
||||
unregister_nfs_version(&nfs_v4);
|
||||
#ifdef CONFIG_NFS_V4_2
|
||||
nfs4_xattr_cache_exit();
|
||||
#endif
|
||||
nfs4_unregister_sysctl();
|
||||
nfs_idmap_quit();
|
||||
nfs_dns_resolver_destroy();
|
||||
|
@ -102,6 +102,8 @@ struct nfs_delegation;
|
||||
|
||||
struct posix_acl;
|
||||
|
||||
struct nfs4_xattr_cache;
|
||||
|
||||
/*
|
||||
* nfs fs inode data in memory
|
||||
*/
|
||||
@ -188,6 +190,10 @@ struct nfs_inode {
|
||||
struct fscache_cookie *fscache;
|
||||
#endif
|
||||
struct inode vfs_inode;
|
||||
|
||||
#ifdef CONFIG_NFS_V4_2
|
||||
struct nfs4_xattr_cache *xattr_cache;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct nfs4_copy_state {
|
||||
|
@ -56,6 +56,7 @@
|
||||
#define NFSDBG_PNFS 0x1000
|
||||
#define NFSDBG_PNFS_LD 0x2000
|
||||
#define NFSDBG_STATE 0x4000
|
||||
#define NFSDBG_XATTRCACHE 0x8000
|
||||
#define NFSDBG_ALL 0xFFFF
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user