Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Feb 2002 22:58:01 -0800 (PST)
From:      Balaji <balajir12@yahoo.com>
To:        freebsd-questions@freebsd.org
Subject:   error in nfs-updatecache..plz help
Message-ID:  <20020215065801.85515.qmail@web14604.mail.yahoo.com>

next in thread | raw e-mail | index | archive | help
--0-543270655-1013756281=:83835
Content-Type: text/plain; charset=us-ascii


Hi, 
We want to log cache entries in a file when nfsd updates cache in nfs/nfs srvcache.c, we have used vn_open and vn_rdwr, but it is giving page faults when it encounters VCALL in server nfs code. This 
might be because of NDINIT not giving required vnode ptr. Here enclosed is the code of nfs_srvcache.c. The part of the code in red is the code that we've added.


-------------------------------------------------------- 
> /* 
> * Update a request cache entry after the rpc has been done 
> */ 
> void 
> nfsrv updatecache(nd, repvalid, repmbuf) 
> register struct nfsrv descript *nd; 
> int repvalid; 
> struct mbuf *repmbuf; 
> { 
> register struct nfsrvcache *rp; 
> struct proc *p = curproc; 
> struct nameidata *ndp; 
> 
> int error, resid; 
> 
> if (!nd->nd nam2) 
> return; 
> loop: 
> for (rp = NFSRCHASH(nd->nd retxid)->lh first; rp != 0; 
> rp = rp->rc hash.le next) { 
> if (nd->nd retxid == rp->rc xid && nd->nd procnum == rp->rc proc 
> && 
> netaddr match(NETFAMILY(rp), &rp->rc haddr, nd->nd nam)) { 
> NFS DPF(RC, ("U%03x", rp->rc xid & 0xfff)); 
> if ((rp->rc flag & RC LOCKED) != 0) { 
> rp->rc flag |= RC WANTED; 
> (void) tsleep((caddr t)rp, PZERO-1, "nfsrc", 0); 
> goto loop; 
> } 
> rp->rc flag |= RC LOCKED; 
> if (rp->rc state == RC DONE) { 
> /* 
> * This can occur if the cache is too small. 
> * Retransmits of the same request aren't 
> * dropped so we may see the operation 
> * complete more then once. 
> */ 
> if (rp->rc flag & RC REPMBUF) { 
> m freem(rp->rc reply); 
> rp->rc flag &= ~RC REPMBUF; 
> } 
> } 
> rp->rc state = RC DONE; 
> /* 
> * If we have a valid reply update status and save 
> * the reply for non-idempotent rpc's. 
> */ 
> if (repvalid && nonidempotent[nd->nd procnum]) { 
> 
> /*Code to open the cache file*/ 
> 
> ndp = malloc(sizeof(struct nameidata),M TEMP,M WAITOK); 
> NDINIT(ndp,LOOKUP,NOFOLLOW,UIO USERSPACE,"/usr/cache",p); 
> 
> error = namei(ndp); 
> error = vn open(ndp,FWRITE,0); 
> 
> NDFREE(ndp,NDF ONLY PNBUF); 
> VOP UNLOCK(ndp->ni vp,0,p); 
> 
> if(error < 0) { 
> uprintf("Error in vn open().\n"); 
> } 
> else { 
> printf("File open!!!!\n"); 
> } 
> 
> if ((nd->nd flag & ND NFSV3) == 0 && 
> nfsv2 repstat[nfsv2 procid[nd->nd procnum]]) { 
> rp->rc status = nd->nd repstat; 
> rp->rc flag |= RC REPSTATUS; 
> } else { 
> rp->rc reply = m copym(repmbuf, 
> 0, M COPYALL, M WAIT); 
> rp->rc flag |= RC REPMBUF; 
> } 
> /* Code to write cache entries to a file */ 
> 
> VOP LEASE(ndp->ni vp, p, p->p cred, LEASE WRITE); 
> error = vn rdwr(UIO WRITE, ndp->ni vp, (caddr t)rp, sizeof(struct 
> nfsrvcache), 0, UIO SYSSPACE, IO APPEND|IO UNIT, p->p ucred, (int 
> *)0, p); 
> 
> /*Close cache file after writting to it*/ 
> vn close(ndp->ni vp, FWRITE, p->p ucred, p); 
> } 
> rp->rc flag &= ~RC LOCKED; 
> if (rp->rc flag & RC WANTED) { 
> rp->rc flag &= ~RC WANTED; 
> wakeup((caddr t)rp); 
> } 
> return; 
> } 
> } 
> NFS DPF(RC, ("L%03x", nd->nd retxid & 0xfff)); 
> }



---------------------------------
Do You Yahoo!?
Got something to say? Say it better with Yahoo! Video Mail
--0-543270655-1013756281=:83835
Content-Type: text/html; charset=us-ascii

<P>Hi, <BR>We want to log cache entries in a file when nfsd updates cache in nfs/nfs srvcache.c, we have used vn_open and vn_rdwr, but it is giving page faults when it encounters VCALL in server nfs code. This <BR>might be because of NDINIT not giving required vnode ptr. Here enclosed is the code of nfs_srvcache.c. The part of the code in red is the code that we've added.</P>
<P><BR>-------------------------------------------------------- <BR>&gt; /* <BR>&gt; * Update a request cache entry after the rpc has been done <BR>&gt; */ <BR>&gt; void <BR>&gt; nfsrv updatecache(nd, repvalid, repmbuf) <BR>&gt; register struct nfsrv descript *nd; <BR>&gt; int repvalid; <BR>&gt; struct mbuf *repmbuf; <BR>&gt; { <BR>&gt; register struct nfsrvcache *rp; <BR>&gt; struct proc *p = curproc; <BR>&gt; struct nameidata *ndp; <BR>&gt; <BR>&gt; int error, resid; <BR>&gt; <BR>&gt; if (!nd-&gt;nd nam2) <BR>&gt; return; <BR>&gt; loop: <BR>&gt; for (rp = NFSRCHASH(nd-&gt;nd retxid)-&gt;lh first; rp != 0; <BR>&gt; rp = rp-&gt;rc hash.le next) { <BR>&gt; if (nd-&gt;nd retxid == rp-&gt;rc xid &amp;&amp; nd-&gt;nd procnum == rp-&gt;rc proc <BR>&gt; &amp;&amp; <BR>&gt; netaddr match(NETFAMILY(rp), &amp;rp-&gt;rc haddr, nd-&gt;nd nam)) { <BR>&gt; NFS DPF(RC, ("U%03x", rp-&gt;rc xid &amp; 0xfff)); <BR>&gt; if ((rp-&gt;rc flag &amp; RC LOCKED) != 0) { <BR>&gt; rp-&gt;rc flag |= RC WANTED; <BR>&gt; (void) tsleep((caddr t)rp, PZERO-1, "nfsrc", 0); <BR>&gt; goto loop; <BR>&gt; } <BR>&gt; rp-&gt;rc flag |= RC LOCKED; <BR>&gt; if (rp-&gt;rc state == RC DONE) { <BR>&gt; /* <BR>&gt; * This can occur if the cache is too small. <BR>&gt; * Retransmits of the same request aren't <BR>&gt; * dropped so we may see the operation <BR>&gt; * complete more then once. <BR>&gt; */ <BR>&gt; if (rp-&gt;rc flag &amp; RC REPMBUF) { <BR>&gt; m freem(rp-&gt;rc reply); <BR>&gt; rp-&gt;rc flag &amp;= ~RC REPMBUF; <BR>&gt; } <BR>&gt; } <BR>&gt; rp-&gt;rc state = RC DONE; <BR>&gt; /* <BR>&gt; * If we have a valid reply update status and save <BR>&gt; * the reply for non-idempotent rpc's. <BR>&gt; */ <BR>&gt; if (repvalid &amp;&amp; nonidempotent[nd-&gt;nd procnum]) { <BR>&gt; <BR><FONT color=red>&gt; /*Code to open the cache file*/ <BR>&gt; <BR>&gt; ndp = malloc(sizeof(struct nameidata),M TEMP,M WAITOK); <BR>&gt; NDINIT(ndp,LOOKUP,NOFOLLOW,UIO USERSPACE,"/usr/cache",p); <BR>&gt; <BR>&gt; error = namei(ndp); <BR>&gt; error = vn open(ndp,FWRITE,0); <BR>&gt; <BR>&gt; NDFREE(ndp,NDF ONLY PNBUF); <BR>&gt; VOP UNLOCK(ndp-&gt;ni vp,0,p); <BR>&gt; <BR>&gt; if(error &lt; 0) { <BR>&gt; uprintf("Error in vn open().\n"); <BR>&gt; } <BR>&gt; else { <BR>&gt; printf("File open!!!!\n"); <BR>&gt; }</FONT> <BR>&gt; <BR>&gt; if ((nd-&gt;nd flag &amp; ND NFSV3) == 0 &amp;&amp; <BR>&gt; nfsv2 repstat[nfsv2 procid[nd-&gt;nd procnum]]) { <BR>&gt; rp-&gt;rc status = nd-&gt;nd repstat; <BR>&gt; rp-&gt;rc flag |= RC REPSTATUS; <BR>&gt; } else { <BR>&gt; rp-&gt;rc reply = m copym(repmbuf, <BR>&gt; 0, M COPYALL, M WAIT); <BR>&gt; rp-&gt;rc flag |= RC REPMBUF; <BR>&gt; } <BR><FONT color=red>&gt; /* Code to write cache entries to a file */ <BR>&gt; <BR>&gt; VOP LEASE(ndp-&gt;ni vp, p, p-&gt;p cred, LEASE WRITE); <BR>&gt; error = vn rdwr(UIO WRITE, ndp-&gt;ni vp, (caddr t)rp, sizeof(struct <BR>&gt; nfsrvcache), 0, UIO SYSSPACE, IO APPEND|IO UNIT, p-&gt;p ucred, (int <BR>&gt; *)0, p); <BR>&gt; <BR>&gt; /*Close cache file after writting to it*/ <BR>&gt; vn close(ndp-&gt;ni vp, FWRITE, p-&gt;p ucred, p); <BR></FONT>&gt; } <BR>&gt; rp-&gt;rc flag &amp;= ~RC LOCKED; <BR>&gt; if (rp-&gt;rc flag &amp; RC WANTED) { <BR>&gt; rp-&gt;rc flag &amp;= ~RC WANTED; <BR>&gt; wakeup((caddr t)rp); <BR>&gt; } <BR>&gt; return; <BR>&gt; } <BR>&gt; } <BR>&gt; NFS DPF(RC, ("L%03x", nd-&gt;nd retxid &amp; 0xfff)); <BR>&gt; }</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Got something to say? Say it better with <a href="http://rd.yahoo.com/mail_us/tag/?http://promo.yahoo.com/videomail/">Yahoo! Video Mail</a>
--0-543270655-1013756281=:83835--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020215065801.85515.qmail>