On  9 Sep, Don Lewis wrote:
> On  9 Sep, Robert Watson wrote:
> 
>> What I'd actually like to do is lock vp on going in to the VOP.  I need to
>> grab the lock in the link() code anyway to do the MAC check.  UFS and
>> others all immediately lock the vnode on entry anyway...
> 
> Here's a patch to implement this.  It compiles and seems to work OK, but
> needs review.  There are a couple of issues that definitely need a look:

> The VOP_LINK(9) man page needs would also need to be updated.

Here's a patch to the man page that also fixes a bunch of bit rot that
has accumulated:

Index: VOP_LINK.9
===================================================================
RCS file: /home/ncvs/src/share/man/man9/VOP_LINK.9,v
retrieving revision 1.13
diff -u -r1.13 VOP_LINK.9
--- VOP_LINK.9  1 Oct 2001 16:09:24 -0000       1.13
+++ VOP_LINK.9  10 Sep 2002 22:21:53 -0000
@@ -52,18 +52,13 @@
 pathname information about the file
 .El
 .Pp
-The pathname info must be released on exit.  The directory and
-file vnodes should NOT be released on exit.
+The pathname info should NOT be released on exit because it is done
+by the caller.
+The directory and file vnodes should NOT be released on exit.
 .Sh LOCKS
-The directory,
-.Fa dvp
-is locked on entry and should remain locked on return.
-The file
-.Fa vp
-is not locked on entry and should remain that way on return.
-If your VOP code locks
-.Fa vp ,
-it must be sure to unlock prior to returning.
+.Xr VOP_LINK 9
+expects the directory and file vnodes to be locked on entry and will leave
+the vnodes locked on return.  
 .Sh RETURN VALUES
 Zero is returned if the file was linked successfully, otherwise an
 error is returned.
@@ -74,27 +69,14 @@
 {
     int error = 0;
 
-    if (vp->v_mount != dvp->v_mount) {
-       error = EXDEV;
-       goto out2;
-    }
-    if (vp != dvp && (error = VOP_LOCK(vp))) {
-       goto out2;
-    }
-
-    /*
-     * now that we've locked vp, we have to use out1 instead of out2
-     */
+    if (vp->v_mount != dvp->v_mount)
+       return (EXDEV);
 
-    if (vp would have too many links) {
-       error = EMLINK;
-       goto out1;
-    }
+    if (vp would have too many links)
+       return (EMLINK);
 
-    if (vp is immutable) {
-       error = EPERM;
-       goto out1;
-    }
+    if (vp is immutable)
+       return (EPERM);
 
     /*
      * Increment link count of vp and write back the on-disc version of it.
@@ -108,19 +90,21 @@
        ...;
     }
 
-    free(cnp->cn_pnbuf, M_NAMEI);
-out1:
-    if (vp != dvp)
-       VOP_UNLOCK(vp);
-out2:
-
     return error;
 }
 .Ed
 .Sh ERRORS
 .Bl -tag -width Er
+.It Bq Er EMLINK
+the file has too many links
+.El
+.Bl -tag -width Er
 .It Bq Er EPERM
 the file is immutable
+.El
+.Bl -tag -width Er
+.It Bq Er EXDEV
+a hard link is not possible between different file systems
 .El
 .Sh SEE ALSO
 .Xr vnode 9 ,



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to