freebsd-dev/sys/nfsclient/nfsm_subs.h

179 lines
5.1 KiB
C
Raw Normal View History

/*-
1994-05-24 10:09:53 +00:00
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
1999-08-28 01:08:13 +00:00
* $FreeBSD$
1994-05-24 10:09:53 +00:00
*/
#ifndef _NFSCLIENT_NFSM_SUBS_H_
#define _NFSCLIENT_NFSM_SUBS_H_
#include <nfs/nfs_common.h>
#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
struct ucred;
struct vnode;
1994-05-24 10:09:53 +00:00
/*
* These macros do strange and peculiar things to mbuf chains for
* the assistance of the nfs code. To attempt to use them for any
* other purpose will be dangerous. (they make weird assumptions)
*/
/*
* First define what the actual subs. return
*/
u_int32_t nfs_xid_gen(void);
/* *********************************** */
/* Request generation phase macros */
int nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb,
caddr_t *bpos);
void nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb,
caddr_t *bpos);
int nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb,
caddr_t *bpos);
#define nfsm_bcheck(t1, mreq) \
do { \
if (t1) { \
error = t1; \
m_freem(mreq); \
goto nfsmout; \
} \
} while (0)
1994-05-24 10:09:53 +00:00
#define nfsm_fhtom(v, v3) \
do { \
int32_t t1; \
t1 = nfsm_fhtom_xx((v), (v3), &mb, &bpos); \
nfsm_bcheck(t1, mreq); \
} while (0)
/* If full is true, set all fields, otherwise just set mode and time fields */
#define nfsm_v3attrbuild(a, full) \
nfsm_v3attrbuild_xx(a, full, &mb, &bpos)
#define nfsm_uiotom(p, s) \
do { \
int t1; \
t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \
nfsm_bcheck(t1, mreq); \
} while (0)
#define nfsm_strtom(a, s, m) \
do { \
int t1; \
t1 = nfsm_strtom_xx((a), (s), (m), &mb, &bpos); \
nfsm_bcheck(t1, mreq); \
} while (0)
/* *********************************** */
/* Send the request */
#define nfsm_request(v, t, p, c) \
do { \
sigset_t oldset; \
nfs_set_sigmask(p, &oldset); \
error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \
nfs_restore_sigmask(p, &oldset); \
if (error != 0) { \
if (error & NFSERR_RETERR) \
error &= ~NFSERR_RETERR; \
else \
goto nfsmout; \
} \
} while (0)
/* *********************************** */
/* Reply interpretation phase macros */
int nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f,
struct mbuf **md, caddr_t *dpos);
int nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md,
caddr_t *dpos);
int nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md,
caddr_t *dpos);
Close a race in NFS lookup processing that could result in stale name cache entries on one client when a directory was renamed on another client. The root cause for the stale entry being trusted is that each per-vnode nfsnode structure has a single 'n_ctime' timestamp used to validate positive name cache entries. However, if there are multiple entries for a single vnode, they all share a single timestamp. To fix this, extend the name cache to allow filesystems to optionally store a timestamp value in each name cache entry. The NFS clients now fetch the timestamp associated with each name cache entry and use that to validate cache hits instead of the timestamps previously stored in the nfsnode. Another part of the fix is that the NFS clients now use timestamps from the post-op attributes of RPCs when adding name cache entries rather than pulling the timestamps out of the file's attribute cache. The latter is subject to races with other lookups updating the attribute cache concurrently. Some more details: - Add a variant of nfsm_postop_attr() to the old NFS client that can return a vattr structure with a copy of the post-op attributes. - Handle lookups of "." as a special case in the NFS clients since the name cache does not store name cache entries for ".", so we cannot get a useful timestamp. It didn't really make much sense to recheck the attributes on the the directory to validate the namecache hit for "." anyway. - ABI compat shims for the name cache routines are present in this commit so that it is safe to MFC. MFC after: 2 weeks
2012-01-20 20:02:01 +00:00
int nfsm_postop_attr_xx(struct vnode **v, int *f, struct vattr *va,
struct mbuf **md, caddr_t *dpos);
int nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md,
caddr_t *dpos);
#define nfsm_mtofh(d, v, v3, f) \
do { \
int32_t t1; \
t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
1994-05-24 10:09:53 +00:00
#define nfsm_getfh(f, s, v3) \
do { \
int32_t t1; \
t1 = nfsm_getfh_xx(&(f), &(s), (v3), &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_loadattr(v, a) \
do { \
int32_t t1; \
t1 = nfsm_loadattr_xx(&v, a, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_postop_attr(v, f) \
do { \
int32_t t1; \
Close a race in NFS lookup processing that could result in stale name cache entries on one client when a directory was renamed on another client. The root cause for the stale entry being trusted is that each per-vnode nfsnode structure has a single 'n_ctime' timestamp used to validate positive name cache entries. However, if there are multiple entries for a single vnode, they all share a single timestamp. To fix this, extend the name cache to allow filesystems to optionally store a timestamp value in each name cache entry. The NFS clients now fetch the timestamp associated with each name cache entry and use that to validate cache hits instead of the timestamps previously stored in the nfsnode. Another part of the fix is that the NFS clients now use timestamps from the post-op attributes of RPCs when adding name cache entries rather than pulling the timestamps out of the file's attribute cache. The latter is subject to races with other lookups updating the attribute cache concurrently. Some more details: - Add a variant of nfsm_postop_attr() to the old NFS client that can return a vattr structure with a copy of the post-op attributes. - Handle lookups of "." as a special case in the NFS clients since the name cache does not store name cache entries for ".", so we cannot get a useful timestamp. It didn't really make much sense to recheck the attributes on the the directory to validate the namecache hit for "." anyway. - ABI compat shims for the name cache routines are present in this commit so that it is safe to MFC. MFC after: 2 weeks
2012-01-20 20:02:01 +00:00
t1 = nfsm_postop_attr_xx(&v, &f, NULL, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_postop_attr_va(v, f, va) \
do { \
int32_t t1; \
t1 = nfsm_postop_attr_xx(&v, &f, va, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
/* Used as (f) for nfsm_wcc_data() */
#define NFSV3_WCCRATTR 0
#define NFSV3_WCCCHK 1
#define nfsm_wcc_data(v, f) \
do { \
int32_t t1; \
t1 = nfsm_wcc_data_xx(&v, &f, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
1994-05-24 10:09:53 +00:00
#endif