From dima@unixfreak.org  Thu Dec 28 04:08:03 2000
Return-Path: <dima@unixfreak.org>
Received: from bazooka.unixfreak.org (bazooka.unixfreak.org [63.198.170.138])
	by hub.freebsd.org (Postfix) with ESMTP id 1E8D537B400
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Dec 2000 04:08:03 -0800 (PST)
Received: from spike.unixfreak.org (spike [192.168.2.4])
	by bazooka.unixfreak.org (Postfix) with ESMTP id D16113E09
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Dec 2000 04:08:00 -0800 (PST)
Received: (from dima@localhost)
	by spike.unixfreak.org (8.11.1/8.11.1) id eBSC80501207;
	Thu, 28 Dec 2000 04:08:00 -0800 (PST)
	(envelope-from dima)
Message-Id: <200012281208.eBSC80501207@spike.unixfreak.org>
Date: Thu, 28 Dec 2000 04:08:00 -0800 (PST)
From: dima@unixfreak.org
Reply-To: dima@unixfreak.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] find -fstype local traverses non-local filesystems
X-Send-Pr-Version: 3.2

>Number:         23906
>Category:       bin
>Synopsis:       [PATCH] find -fstype local traverses non-local filesystems
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 28 04:10:00 PST 2000
>Closed-Date:    Fri Dec 29 04:32:33 PST 2000
>Last-Modified:  Fri Dec 29 04:33:11 PST 2000
>Originator:     Dima Dorfman
>Release:        FreeBSD 5.0-20001223-CURRENT i386
>Organization:
Private
>Environment:

At least (i.e., I've not tested with anything else) 4.2-RELEASE and
5.0-CURRENT.

>Description:

The '-fstype local' primary in find(1) is used to match files on a
local filesystem.  Among others, periodic(8) scripts use it to look
for files on local filesystems that have unknown user or group ids.
The problem is that although find(1) correctly doesn't match files on
remote filesystem when using the aforementioned primary, it still
traverses the remote filesystem.  This is a problem, for example, when
the noid periodic(8) script goes looking for files with unknown user
ids on remote filesystems.  The filesystem traversal causes
unnecessary load to the remote filesystem.

>How-To-Repeat:

For the purpose of this example, I will assume that a remote NFS
filesystem is mounted on /path/to/nfs/filesystem.

$ cd /path/to/nfs                  # don't add /filesystem!
$ find . -fstype local -print

find(1) will not match (and thus, won't print) files it finds on the
NFS server, but it is still traversing the tree.  You can use top(1)
or ps(1) on the NFS server to check that nfsd is consuming more
resources than it normally would if it were idle.

>Fix:

The attached patch causes '-fstype local' not to traverse a remote
filesystem.  In most cases, this should not affect the results
returned.  The only case I can think of where this may be undesireable
is when a local filesystem's mount point resides on a remote
filesystem (i.e., /path/to/nfs/filesystem/local is a local
mountpoint).  This is possible in theory, but I've never tried it; nor
can I think of why somebody would want to do that.

Index: function.c
===================================================================
RCS file: /st/src/FreeBSD/src/usr.bin/find/function.c,v
retrieving revision 1.27
diff -u -r1.27 function.c
--- function.c	2000/07/28 20:02:42	1.27
+++ function.c	2000/12/23 23:28:18
@@ -514,6 +514,8 @@
 	static int val_type, val_flags;
 	char *p, save[2];
 
+	extern FTS *tree;
+
 	/* Only check when we cross mount point. */
 	if (first || curdev != entry->fts_statp->st_dev) {
 		curdev = entry->fts_statp->st_dev;
@@ -555,6 +557,19 @@
 	}
 	switch (plan->flags) {
 	case F_MTFLAG:
+		/*
+		 * If the filesystem isn't local, and we're looking
+		 * for local filesystems (-fstype local), don't
+		 * traverse it.  Without this, we'll go on looking for
+		 * local files in a non-local filesystem.
+		 */
+		if (((val_flags & MNT_LOCAL) == 0) &&
+		    ((plan->mt_data & MNT_LOCAL) != 0)) {
+			if (fts_set(tree, entry, FTS_SKIP))
+				err(1, "%s", entry->fts_path);
+			return (0);
+		}
+
 		return (val_flags & plan->mt_data) != 0;
 	case F_MTTYPE:
 		return (val_type == plan->mt_data);



>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: dima@unixfreak.org
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: bin/23906: [PATCH] find -fstype local traverses non-local filesystems
Date: Thu, 28 Dec 2000 11:05:16 -0500 (EST)

 <<On Thu, 28 Dec 2000 04:08:00 -0800 (PST), dima@unixfreak.org said:
 
 > The problem is that although find(1) correctly doesn't match files on
 > remote filesystem when using the aforementioned primary, it still
 > traverses the remote filesystem.
 
 This is intentional, since a local filesystem might be mounted below a
 remote one.  If you wish to prune non-local filesystems, the correct
 syntax would be:
 
 $ find / \( ! -fstype local -prune \) -o [what you really want to search for]
 
 (POSIX unfortunately standardizes the broken `-xdev' and `-depth'
 primaries, which should have been implemented as command-line options
 and are in *BSD.)
 
 -GAWollman
 
 --
 Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
 wollman@lcs.mit.edu  | O Siem / The fires of freedom 
 Opinions not those of| Dance in the burning flame
 MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick
 

From: David Malone <dwmalone@maths.tcd.ie>
To: dima@unixfreak.org
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/23906: [PATCH] find -fstype local traverses non-local filesystems
Date: Thu, 28 Dec 2000 19:35:11 +0000

 On Thu, Dec 28, 2000 at 04:08:00AM -0800, dima@unixfreak.org wrote:
 
 > $ cd /path/to/nfs                  # don't add /filesystem!
 > $ find . -fstype local -print
 > 
 > find(1) will not match (and thus, won't print) files it finds on the
 > NFS server, but it is still traversing the tree.  You can use top(1)
 > or ps(1) on the NFS server to check that nfsd is consuming more
 > resources than it normally would if it were idle.
 
 If I'm not mistaken, this is what the -prune option is for. If the
 daily scripts don't use -prune then that's may be a bug in the
 daily scripts I guess. You probably want to say something like:
 
 	find . \( -fstype local -o -prune \) -print
 
 As you point out, the daily scripts may just be extra cautious
 by searching for local mount points within nonlocal file systems.
 
 	David.
 

From: Dima Dorfman <dima@unixfreak.org>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/23906: [PATCH] find -fstype local traverses non-local filesystems 
Date: Thu, 28 Dec 2000 15:25:04 -0800

 > On Thu, Dec 28, 2000 at 04:08:00AM -0800, dima@unixfreak.org wrote:
 > 
 > > $ cd /path/to/nfs                  # don't add /filesystem!
 > > $ find . -fstype local -print
 > > 
 > > [find traveses /path/to/nfs/filesystem]
 > 
 > If I'm not mistaken, this is what the -prune option is for. If the
 > daily scripts don't use -prune then that's may be a bug in the
 > daily scripts I guess. You probably want to say something like:
 
 Thanks for pointing this out.  I must've overlooked -prune.
 
 Thank you for the quick reply.  You may close this PR.  I'll see what
 I can do to the daily scripts to keep both groups (those who have
 local filesystems mounted below remote ones and those who don't)
 happy.
 
 Regards
 
 						Dima Dorfman
 						dima@unixfreak.org
 
State-Changed-From-To: open->closed 
State-Changed-By: dwmalone 
State-Changed-When: Fri Dec 29 04:32:33 PST 2000 
State-Changed-Why:  
Submitter says that -prune can do what they want. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23906 
>Unformatted:
