Linux Audio

Check our new training course

Loading...
v4.17
 
  1/* NFS FS-Cache index structure definition
  2 *
  3 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  4 * Written by David Howells (dhowells@redhat.com)
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public Licence
  8 * as published by the Free Software Foundation; either version
  9 * 2 of the Licence, or (at your option) any later version.
 10 */
 11
 12#include <linux/init.h>
 13#include <linux/kernel.h>
 14#include <linux/sched.h>
 15#include <linux/mm.h>
 16#include <linux/nfs_fs.h>
 17#include <linux/nfs_fs_sb.h>
 18#include <linux/in6.h>
 19#include <linux/iversion.h>
 20
 21#include "internal.h"
 22#include "fscache.h"
 23
 24#define NFSDBG_FACILITY		NFSDBG_FSCACHE
 25
 26/*
 27 * Define the NFS filesystem for FS-Cache.  Upon registration FS-Cache sticks
 28 * the cookie for the top-level index object for NFS into here.  The top-level
 29 * index can than have other cache objects inserted into it.
 30 */
 31struct fscache_netfs nfs_fscache_netfs = {
 32	.name		= "nfs",
 33	.version	= 0,
 34};
 35
 36/*
 37 * Register NFS for caching
 38 */
 39int nfs_fscache_register(void)
 40{
 41	return fscache_register_netfs(&nfs_fscache_netfs);
 42}
 43
 44/*
 45 * Unregister NFS for caching
 46 */
 47void nfs_fscache_unregister(void)
 48{
 49	fscache_unregister_netfs(&nfs_fscache_netfs);
 50}
 51
 52/*
 53 * Define the server object for FS-Cache.  This is used to describe a server
 54 * object to fscache_acquire_cookie().  It is keyed by the NFS protocol and
 55 * server address parameters.
 56 */
 57const struct fscache_cookie_def nfs_fscache_server_index_def = {
 58	.name		= "NFS.server",
 59	.type 		= FSCACHE_COOKIE_TYPE_INDEX,
 60};
 61
 62/*
 63 * Define the superblock object for FS-Cache.  This is used to describe a
 64 * superblock object to fscache_acquire_cookie().  It is keyed by all the NFS
 65 * parameters that might cause a separate superblock.
 66 */
 67const struct fscache_cookie_def nfs_fscache_super_index_def = {
 68	.name		= "NFS.super",
 69	.type 		= FSCACHE_COOKIE_TYPE_INDEX,
 70};
 71
 72/*
 73 * Consult the netfs about the state of an object
 74 * - This function can be absent if the index carries no state data
 75 * - The netfs data from the cookie being used as the target is
 76 *   presented, as is the auxiliary data
 77 */
 78static
 79enum fscache_checkaux nfs_fscache_inode_check_aux(void *cookie_netfs_data,
 80						  const void *data,
 81						  uint16_t datalen,
 82						  loff_t object_size)
 83{
 84	struct nfs_fscache_inode_auxdata auxdata;
 85	struct nfs_inode *nfsi = cookie_netfs_data;
 86
 87	if (datalen != sizeof(auxdata))
 88		return FSCACHE_CHECKAUX_OBSOLETE;
 89
 90	memset(&auxdata, 0, sizeof(auxdata));
 91	auxdata.mtime = nfsi->vfs_inode.i_mtime;
 92	auxdata.ctime = nfsi->vfs_inode.i_ctime;
 
 
 93
 94	if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
 95		auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
 96
 97	if (memcmp(data, &auxdata, datalen) != 0)
 98		return FSCACHE_CHECKAUX_OBSOLETE;
 99
100	return FSCACHE_CHECKAUX_OKAY;
101}
102
103/*
104 * Get an extra reference on a read context.
105 * - This function can be absent if the completion function doesn't require a
106 *   context.
107 * - The read context is passed back to NFS in the event that a data read on the
108 *   cache fails with EIO - in which case the server must be contacted to
109 *   retrieve the data, which requires the read context for security.
110 */
111static void nfs_fh_get_context(void *cookie_netfs_data, void *context)
112{
113	get_nfs_open_context(context);
114}
115
116/*
117 * Release an extra reference on a read context.
118 * - This function can be absent if the completion function doesn't require a
119 *   context.
120 */
121static void nfs_fh_put_context(void *cookie_netfs_data, void *context)
122{
123	if (context)
124		put_nfs_open_context(context);
125}
126
127/*
128 * Define the inode object for FS-Cache.  This is used to describe an inode
129 * object to fscache_acquire_cookie().  It is keyed by the NFS file handle for
130 * an inode.
131 *
132 * Coherency is managed by comparing the copies of i_size, i_mtime and i_ctime
133 * held in the cache auxiliary data for the data storage object with those in
134 * the inode struct in memory.
135 */
136const struct fscache_cookie_def nfs_fscache_inode_object_def = {
137	.name		= "NFS.fh",
138	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
139	.check_aux	= nfs_fscache_inode_check_aux,
140	.get_context	= nfs_fh_get_context,
141	.put_context	= nfs_fh_put_context,
142};
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* NFS FS-Cache index structure definition
  3 *
  4 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  5 * Written by David Howells (dhowells@redhat.com)
 
 
 
 
 
  6 */
  7
  8#include <linux/init.h>
  9#include <linux/kernel.h>
 10#include <linux/sched.h>
 11#include <linux/mm.h>
 12#include <linux/nfs_fs.h>
 13#include <linux/nfs_fs_sb.h>
 14#include <linux/in6.h>
 15#include <linux/iversion.h>
 16
 17#include "internal.h"
 18#include "fscache.h"
 19
 20#define NFSDBG_FACILITY		NFSDBG_FSCACHE
 21
 22/*
 23 * Define the NFS filesystem for FS-Cache.  Upon registration FS-Cache sticks
 24 * the cookie for the top-level index object for NFS into here.  The top-level
 25 * index can than have other cache objects inserted into it.
 26 */
 27struct fscache_netfs nfs_fscache_netfs = {
 28	.name		= "nfs",
 29	.version	= 0,
 30};
 31
 32/*
 33 * Register NFS for caching
 34 */
 35int nfs_fscache_register(void)
 36{
 37	return fscache_register_netfs(&nfs_fscache_netfs);
 38}
 39
 40/*
 41 * Unregister NFS for caching
 42 */
 43void nfs_fscache_unregister(void)
 44{
 45	fscache_unregister_netfs(&nfs_fscache_netfs);
 46}
 47
 48/*
 49 * Define the server object for FS-Cache.  This is used to describe a server
 50 * object to fscache_acquire_cookie().  It is keyed by the NFS protocol and
 51 * server address parameters.
 52 */
 53const struct fscache_cookie_def nfs_fscache_server_index_def = {
 54	.name		= "NFS.server",
 55	.type 		= FSCACHE_COOKIE_TYPE_INDEX,
 56};
 57
 58/*
 59 * Define the superblock object for FS-Cache.  This is used to describe a
 60 * superblock object to fscache_acquire_cookie().  It is keyed by all the NFS
 61 * parameters that might cause a separate superblock.
 62 */
 63const struct fscache_cookie_def nfs_fscache_super_index_def = {
 64	.name		= "NFS.super",
 65	.type 		= FSCACHE_COOKIE_TYPE_INDEX,
 66};
 67
 68/*
 69 * Consult the netfs about the state of an object
 70 * - This function can be absent if the index carries no state data
 71 * - The netfs data from the cookie being used as the target is
 72 *   presented, as is the auxiliary data
 73 */
 74static
 75enum fscache_checkaux nfs_fscache_inode_check_aux(void *cookie_netfs_data,
 76						  const void *data,
 77						  uint16_t datalen,
 78						  loff_t object_size)
 79{
 80	struct nfs_fscache_inode_auxdata auxdata;
 81	struct nfs_inode *nfsi = cookie_netfs_data;
 82
 83	if (datalen != sizeof(auxdata))
 84		return FSCACHE_CHECKAUX_OBSOLETE;
 85
 86	memset(&auxdata, 0, sizeof(auxdata));
 87	auxdata.mtime_sec  = nfsi->vfs_inode.i_mtime.tv_sec;
 88	auxdata.mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec;
 89	auxdata.ctime_sec  = nfsi->vfs_inode.i_ctime.tv_sec;
 90	auxdata.ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec;
 91
 92	if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
 93		auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
 94
 95	if (memcmp(data, &auxdata, datalen) != 0)
 96		return FSCACHE_CHECKAUX_OBSOLETE;
 97
 98	return FSCACHE_CHECKAUX_OKAY;
 99}
100
101/*
102 * Get an extra reference on a read context.
103 * - This function can be absent if the completion function doesn't require a
104 *   context.
105 * - The read context is passed back to NFS in the event that a data read on the
106 *   cache fails with EIO - in which case the server must be contacted to
107 *   retrieve the data, which requires the read context for security.
108 */
109static void nfs_fh_get_context(void *cookie_netfs_data, void *context)
110{
111	get_nfs_open_context(context);
112}
113
114/*
115 * Release an extra reference on a read context.
116 * - This function can be absent if the completion function doesn't require a
117 *   context.
118 */
119static void nfs_fh_put_context(void *cookie_netfs_data, void *context)
120{
121	if (context)
122		put_nfs_open_context(context);
123}
124
125/*
126 * Define the inode object for FS-Cache.  This is used to describe an inode
127 * object to fscache_acquire_cookie().  It is keyed by the NFS file handle for
128 * an inode.
129 *
130 * Coherency is managed by comparing the copies of i_size, i_mtime and i_ctime
131 * held in the cache auxiliary data for the data storage object with those in
132 * the inode struct in memory.
133 */
134const struct fscache_cookie_def nfs_fscache_inode_object_def = {
135	.name		= "NFS.fh",
136	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
137	.check_aux	= nfs_fscache_inode_check_aux,
138	.get_context	= nfs_fh_get_context,
139	.put_context	= nfs_fh_put_context,
140};