* 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, with or without
* modification, are permitted provided that the following conditions
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 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
* @(#)nfs_node.c 7.34 (Berkeley) 5/15/91
/* 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) {
(void) tsleep((caddr_t
)np
, PINOD
, "nfsnode", 0);
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 sillyrename
*sp
;
if (prtactive
&& vp
->v_usecount
!= 0)
vprint("nfs_inactive: pushing active", vp
);
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
)) {
free((caddr_t
)sp
, M_NFSREQ
);
* 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
);
if (prtactive
&& vp
->v_usecount
!= 0)
vprint("nfs_reclaim: pushing active", vp
);
* Remove the nfsnode from its hash chain.
* In theory, NFS does not need locking, but we make provision
* for doing it just in case it is needed.
register struct nfsnode
*np
= VTONFS(vp
);
while (np
->n_flag
& NLOCKED
) {
if (np
->n_lockholder
== curproc
->p_pid
)
panic("locking against myself");
np
->n_lockwaiter
= curproc
->p_pid
;
(void) tsleep((caddr_t
)np
, PINOD
, "nfslock", 0);
np
->n_lockholder
= curproc
->p_pid
;
register struct nfsnode
*np
= VTONFS(vp
);
if (np
->n_flag
& NWANT
) {
* Check for a locked nfsnode
if (VTONFS(vp
)->n_flag
& NLOCKED
)
* 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
)
* Nfs abort op, called after namei() when a CREATE/DELETE isn't actually
* done. Currently nothing to do.
if ((ndp
->ni_nameiop
& (HASBUF
| SAVESTART
)) == HASBUF
)
FREE(ndp
->ni_pnbuf
, M_NAMEI
);