* Copyright (c) 1989 The Regents of the University of California.
* 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 are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* @(#)nfs_node.c 7.14 (Berkeley) %G%
/* The request list head */
extern struct nfsreq nfsreqh
;
#if ((NFSNOHSZ&(NFSNOHSZ-1)) == 0)
#define NFSNOHASH(fhsum) ((fhsum)&(NFSNOHSZ-1))
#define NFSNOHASH(fhsum) (((unsigned)(fhsum))%NFSNOHSZ)
struct nfsnode
*nh_chain
[2];
* Initialize hash links for nfsnodes
* and build nfsnode free list.
register union nhead
*nh
= nhead
;
if (VN_MAXPRIVATE
< sizeof(struct nfsnode
))
panic("nfs_nhinit: too small");
for (i
= NFSNOHSZ
; --i
>= 0; nh
++) {
* Compute an entry in the NFS hash table structure
fhpp
= &fhp
->fh_bytes
[0];
for (i
= 0; i
< NFSX_FH
; i
++)
return (&nhead
[NFSNOHASH(fhsum
)]);
* Look up a vnode/nfsnode by file handle.
* Callers must check for mount points!!
* In all cases, a pointer to a
* nfsnode structure is returned.
register struct nfsnode
*np
;
register struct vnode
*vp
;
extern struct vnodeops nfsv2_vnodeops
;
for (np
= nh
->nh_chain
[0]; np
!= (struct nfsnode
*)nh
; np
= np
->n_forw
) {
if (mntp
!= NFSTOV(np
)->v_mount
||
bcmp((caddr_t
)fhp
, (caddr_t
)&np
->n_fh
, NFSX_FH
))
if ((np
->n_flag
& NLOCKED
) != 0) {
sleep((caddr_t
)np
, PINOD
);
if (error
= getnewvnode(VT_NFS
, mntp
, &nfsv2_vnodeops
, &nvp
)) {
* Insert the nfsnode in the hash queue for its new file handle
bcopy((caddr_t
)fhp
, (caddr_t
)&np
->n_fh
, NFSX_FH
);
np
->n_sillyrename
= (struct sillyrename
*)0;
register struct nfsnode
*np
;
register struct nameidata
*ndp
;
register struct sillyrename
*sp
;
if (prtactive
&& vp
->v_count
!= 0)
printf("nfs_inactive: pushing active fileid %d fsid 0x%x\n",
np
->n_vattr
.va_fileid
, np
->n_vattr
.va_fsid
);
np
->n_sillyrename
= (struct sillyrename
*)0;
* Remove the silly file that was rename'd earlier
if (!nfs_nget(vp
->v_mount
, &sp
->s_fh
, &dnp
)) {
ndp
->ni_dvp
= NFSTOV(dnp
);
free((caddr_t
)sp
, M_TEMP
);
* Scan the request list for any requests left hanging about
while (rep
&& rep
!= &nfsreqh
) {
rep
->r_prev
->r_next
= rep2
= rep
->r_next
;
rep
->r_next
->r_prev
= rep
->r_prev
;
free((caddr_t
)rep
, M_NFSREQ
);
* Reclaim an nfsnode so that it can be used for other purposes.
register struct vnode
*vp
;
register struct nfsnode
*np
= VTONFS(vp
);
* Flush out any associated bio buffers that might be lying about
if (vp
->v_type
== VREG
&& (np
->n_flag
& NBUFFERED
)) {
nfs_blkflush(vp
, (daddr_t
)0, np
->n_size
, TRUE
);
if (prtactive
&& vp
->v_count
!= 0)
printf("nfs_reclaim: pushing active fileid %d fsid 0x%x\n",
np
->n_vattr
.va_fileid
, np
->n_vattr
.va_fsid
);
* Remove the nfsnode from its hash chain.
register struct nfsnode
*np
= VTONFS(vp
);
while (np
->n_flag
& NLOCKED
) {
sleep((caddr_t
)np
, PINOD
);
register struct nfsnode
*np
= VTONFS(vp
);
if (np
->n_flag
& NWANT
) {
* since I can't decide if dirs. should be locked, I will check for
* the lock and be flexible
register struct nfsnode
*np
= VTONFS(vp
);
if (np
->n_flag
& NLOCKED
)
register struct nameidata
*ndp
;
register struct nfsnode
*np
;
if (ndp
->ni_vp
!= NULL
) {
if (np
->n_flag
& NLOCKED
)
if (ndp
->ni_dvp
!= NULL
) {
np
= VTONFS(ndp
->ni_dvp
);
if (np
->n_flag
& NLOCKED
)
* This is silly, but if you use a macro and try and use it in a file
* that has mbuf.h included, m_data --> m_hdr.mh_data and this is not
struct nfsmount
*vfs_to_nfs(mp
)
return ((struct nfsmount
*)mp
->m_data
);