// SPDX-License-Identifier: GPL-2.0-or-later /* NFS filesystem cache interface * * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com)
*/
staticbool nfs_append_int(char *key, int *_len, unsignedlonglong x)
{ if (*_len > NFS_MAX_KEY_LEN) returnfalse; if (x == 0)
key[(*_len)++] = ','; else
*_len += sprintf(key + *_len, ",%llx", x); returntrue;
}
/* * Get the per-client index cookie for an NFS client if the appropriate mount * flag was set * - We always try and get an index cookie for the client, but get filehandle * cookies on a per-superblock basis, depending on the mount flags
*/ staticbool nfs_fscache_get_client_key(struct nfs_client *clp, char *key, int *_len)
{ conststruct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &clp->cl_addr; conststruct sockaddr_in *sin = (struct sockaddr_in *) &clp->cl_addr;
/* * Get the cache cookie for an NFS superblock. * * The default uniquifier is just an empty string, but it may be overridden * either by the 'fsc=xxx' option to mount, or by inheriting it from the parent * superblock across an automount point of some nature.
*/ int nfs_fscache_get_super_cookie(struct super_block *sb, constchar *uniq, int ulen)
{ struct fscache_volume *vcookie; struct nfs_server *nfss = NFS_SB(sb); unsignedint len = 3; char *key;
if (uniq) {
nfss->fscache_uniq = kmemdup_nul(uniq, ulen, GFP_KERNEL); if (!nfss->fscache_uniq) return -ENOMEM;
}
key = kmalloc(NFS_MAX_KEY_LEN + 24, GFP_KERNEL); if (!key) return -ENOMEM;
/* * Enable or disable caching for a file that is being opened as appropriate. * The cookie is allocated when the inode is initialised, but is not enabled at * that time. Enablement is deferred to file-open time to avoid stat() and * access() thrashing the cache. * * For now, with NFS, only regular files that are open read-only will be able * to use the cache. * * We enable the cache for an inode if we open it read-only and it isn't * currently open for writing. We disable the cache if the inode is open * write-only. * * The caller uses the file struct to pin i_writecount on the inode before * calling us when a file is opened for writing, so we can make use of that. * * Note that this may be invoked multiple times in parallel by parallel * nfs_open() functions.
*/ void nfs_fscache_open_file(struct inode *inode, struct file *filp)
{ struct nfs_fscache_inode_auxdata auxdata; struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode)); bool open_for_write = inode_is_open_for_write(inode);
rreq->netfs_priv = get_nfs_open_context(nfs_file_open_context(file));
rreq->debug_id = atomic_inc_return(&nfs_netfs_debug_id); /* [DEPRECATED] Use PG_private_2 to mark folio being written to the cache. */
__set_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags);
rreq->io_streams[0].sreq_max_len = NFS_SB(rreq->inode->i_sb)->rsize;
return 0;
}
staticvoid nfs_netfs_free_request(struct netfs_io_request *rreq)
{ if (rreq->netfs_priv)
put_nfs_open_context(rreq->netfs_priv);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.