Knob to turn off _POSIX_NO_TRUNC

Kostik Belousov kostikbel at gmail.com
Tue Apr 5 14:58:44 UTC 2011


On Tue, Apr 05, 2011 at 03:35:49PM +0100, Mark Blackman wrote:
> 
> On 5 Apr 2011, at 15:16, Kostik Belousov wrote:
> 
> > From very old and gloomy SysV times I remembered filesystem behaviour
> > that silently truncated the file name components to the NAME_MAX limit,
> > that was, AFAIR, 14. To much of my dismay, I met some usermode software
> > recently that blindly tried to create the file from externally provided
> > name, and sometimes failed with ENAMETOOLONG in similar situation.
> > The authors are not cooperative.
> > 
> > I ended up with the following hack, which almost turns off the
> > _POSIX_NO_TRUNC behaviour, globally on the system. Patch allowed me
> > to proceed. The cost in the default case is a single check, which is
> > performed only on ENAMETOOLONG path.
> 
> If this is global, it might deal with a failing test when building Perl
> on a ZFS-only system which also tests  this property.
> 
> In particular, I believe ZFS neither truncates nor returns an error for any 
> pathname length, so I'm not sure what the right test result should be.
> 
> Building perl produces something like..
> 
> Only one test fails:
> ok 25 - calling pathconf("/tmp", _PC_NO_TRUNC)
> not ok 26 -     checking that the returned value is defined (it isn't)
> or that errno is clear (it isn't, it's Invalid argument)
> #   Failed test '       checking that the returned value is defined
> #   (it isn't) or that errno is clear (it isn't, it's Invalid argument)'
> #   at t/sysconf.t line 63.
> 
> This thread..
> 
> http://lists.freebsd.org/pipermail/freebsd-fs/2010-November/010069.html
> 
> talked about the NO_TRUNC behaviour in the context of ZFS.
> 
Reporting _PC_NO_TRUNC from zfs is easy, I think Pawel just had no time
to care about this detail. Anyway, it is not directly relevant to what
the posted patch did.

Patch below incorporates zfs change, and also reporting of the
vfs.lookup_trim from pathconf(2), just in case.

diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
index 17eedee..9985716 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
@@ -5127,6 +5130,10 @@ zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
 		*valp = ACL_MAX_ENTRIES;
 		return (0);
 
+	case _PC_NO_TRUNC:
+		*valp = 1;
+		return (0);
+
 	default:
 		return (EOPNOTSUPP);
 	}
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index 50a2570..9ecf4e0 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -99,6 +99,11 @@ SYSCTL_INT(_vfs, OID_AUTO, lookup_shared, CTLFLAG_RW, &lookup_shared, 0,
     "Enables/Disables shared locks for path name translation");
 TUNABLE_INT("vfs.lookup_shared", &lookup_shared);
 
+int lookup_trim;
+SYSCTL_INT(_vfs, OID_AUTO, lookup_trim, CTLFLAG_RW, &lookup_trim, 0,
+    "Enables/Disables trim of the long path component instead of ENAMETOOLONG");
+TUNABLE_INT("vfs.lookup_trim", &lookup_trim);
+
 /*
  * Convert a pathname into a pointer to a locked vnode.
  *
@@ -514,8 +519,14 @@ dirloop:
 		continue;
 	cnp->cn_namelen = cp - cnp->cn_nameptr;
 	if (cnp->cn_namelen > NAME_MAX) {
-		error = ENAMETOOLONG;
-		goto bad;
+		if (!lookup_trim) {
+			error = ENAMETOOLONG;
+			goto bad;
+		}
+		ndp->ni_pathlen -= cnp->cn_namelen - NAME_MAX;
+		cnp->cn_namelen = NAME_MAX;
+		strcpy(cnp->cn_nameptr + cnp->cn_namelen, cp);
+		cp = cnp->cn_nameptr + cnp->cn_namelen;
 	}
 #ifdef NAMEI_DIAGNOSTIC
 	{ char c = *cp;
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 4fc198e..9020223 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -2528,6 +2528,8 @@ lpathconf(td, uap)
 	return (kern_pathconf(td, uap->path, UIO_USERSPACE, uap->name, NOFOLLOW));
 }
 
+extern int lookup_trim;
+
 int
 kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg, int name,
     u_long flags)
@@ -2549,6 +2551,8 @@ kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg, int name,
 		error = VOP_PATHCONF(nd.ni_vp, name, td->td_retval);
 	vput(nd.ni_vp);
 	VFS_UNLOCK_GIANT(vfslocked);
+	if (name == _PC_NO_TRUNC && error == 0 && td->td_retval != 0)
+		td->td_retval[0] = !lookup_trim;
 	return (error);
 }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20110405/aa7d6d85/attachment.pgp


More information about the freebsd-fs mailing list