From nobody@FreeBSD.org  Tue May  6 10:54:34 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4B00C106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 May 2008 10:54:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 3417F8FC19
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 May 2008 10:54:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m46ArgIh089716
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 6 May 2008 10:53:42 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m46Arg8J089713;
	Tue, 6 May 2008 10:53:42 GMT
	(envelope-from nobody)
Message-Id: <200805061053.m46Arg8J089713@www.freebsd.org>
Date: Tue, 6 May 2008 10:53:42 GMT
From: KOIE Hidetaka <hide@koie.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /usr/bin/fstat shows error messages and hang.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         123456
>Category:       amd64
>Synopsis:       fstat(1): /usr/bin/fstat shows error messages and hang.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-amd64
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 06 11:00:04 UTC 2008
>Closed-Date:    Sun Dec 05 13:54:15 UTC 2010
>Last-Modified:  Sun Dec 05 13:54:15 UTC 2010
>Originator:     KOIE Hidetaka
>Release:        FreeBSD 8.0-CURRENT amd64
>Organization:
surigiken
>Environment:
System: FreeBSD guriandgura 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Mon May 5 13:17:50 JST 2008 koie@guriandgura:/usr/obj/usr/src\
/sys/GURIANDGURA amd64

>Description:
        fstat -v shows error message like this:
                can't read vnode at 0x0 for pid ***
                can't read znode_phys at 0x**** for pid ***
                unknown file type 5 for file 5 of pid ***

        fstat / hangs.

>How-To-Repeat:

>Fix:
        Patch for "can't read vnode at 0x0 for pid ***":
        vtrans() is invoked iff vp is not null.

        Patch for "can't read znode_phys at 0x**** for pid ***":
        znode_phys is void *, not int.

        Patch for "unknown file type 5 for file 5 of pid ***":
        consider other DTYPEs.

        Patch for hanging:
        sysctl "debug.sizeof.znode" returns int, not size_t.


Patch attached with submission follows:

diff -c -r1.65 fstat.c
*** fstat.c	5 Nov 2007 23:15:02 -0000	1.65
--- fstat.c	6 May 2008 10:11:33 -0000
***************
*** 348,354 ****
  	/*
  	 * current working directory vnode
  	 */
! 	vtrans(filed.fd_cdir, CDIR, FREAD);
  	/*
  	 * jail root, if any.
  	 */
--- 348,355 ----
  	/*
  	 * current working directory vnode
  	 */
! 	if (filed.fd_cdir)
! 		vtrans(filed.fd_cdir, CDIR, FREAD);
  	/*
  	 * jail root, if any.
  	 */
***************
*** 390,417 ****
  			    i, (void *)ofiles[i], Pid);
  			continue;
  		}
! 		if (file.f_type == DTYPE_VNODE)
  			vtrans(file.f_vnode, i, file.f_flag);
! 		else if (file.f_type == DTYPE_SOCKET) {
  			if (checkfile == 0)
  				socktrans(file.f_data, i);
! 		}
  #ifdef DTYPE_PIPE
! 		else if (file.f_type == DTYPE_PIPE) {
  			if (checkfile == 0)
  				pipetrans(file.f_data, i, file.f_flag);
! 		}
  #endif
  #ifdef DTYPE_FIFO
! 		else if (file.f_type == DTYPE_FIFO) {
  			if (checkfile == 0)
  				vtrans(file.f_vnode, i, file.f_flag);
! 		}
  #endif
! 		else {
  			dprintf(stderr,
  			    "unknown file type %d for file %d of pid %d\n",
  			    file.f_type, i, Pid);
  		}
  	}
  }
--- 391,435 ----
  			    i, (void *)ofiles[i], Pid);
  			continue;
  		}
! 		switch (file.f_type) {
! 		case DTYPE_VNODE:
  			vtrans(file.f_vnode, i, file.f_flag);
! 			break;
! 		case DTYPE_SOCKET:
  			if (checkfile == 0)
  				socktrans(file.f_data, i);
! 			break;
  #ifdef DTYPE_PIPE
! 		case DTYPE_PIPE:
  			if (checkfile == 0)
  				pipetrans(file.f_data, i, file.f_flag);
! 			break;
  #endif
  #ifdef DTYPE_FIFO
! 		case DTYPE_FIFO:
  			if (checkfile == 0)
  				vtrans(file.f_vnode, i, file.f_flag);
! 			break;
  #endif
! #ifdef DTYPE_KQUEUE
! 		case DTYPE_KQUEUE:
! #endif
! #ifdef DTYPE_CRYPTO
! 		case DTYPE_CRYPTO:
! #endif
! #ifdef DTYPE_MQUEUE
! 		case DTYPE_MQUEUE:
! #endif
! #ifdef DTYPE_SHM
! 		case DTYPE_SHM:
! #endif
! 			/* not supported */
! 			break;
! 		default:
  			dprintf(stderr,
  			    "unknown file type %d for file %d of pid %d\n",
  			    file.f_type, i, Pid);
+ 			break;
  		}
  	}
  }
diff -c -r1.2 zfs.c
*** zfs.c	17 Nov 2007 23:21:38 -0000	1.2
--- zfs.c	6 May 2008 10:02:48 -0000
***************
*** 68,75 ****
  	uint64_t *zid;
  	void *znodeptr, *vnodeptr;
  	char *dataptr;
! 	int *zphys_addr;
! 	size_t len, size;
  
  	len = sizeof(size);
  	if (sysctlbyname("debug.sizeof.znode", &size, &len, NULL, 0) == -1) {
--- 68,76 ----
  	uint64_t *zid;
  	void *znodeptr, *vnodeptr;
  	char *dataptr;
! 	void *zphys_addr;
! 	size_t len;
! 	int size;
  
  	len = sizeof(size);
  	if (sysctlbyname("debug.sizeof.znode", &size, &len, NULL, 0) == -1) {
***************
*** 84,90 ****
  
  	/* Since we have problems including vnode.h, we'll use the wrappers. */
  	vnodeptr = getvnodedata(vp);
! 	if (!KVM_READ(vnodeptr, znodeptr, size)) {
  		dprintf(stderr, "can't read znode at %p for pid %d\n",
  		    (void *)vnodeptr, Pid);
  		goto bad;
--- 85,91 ----
  
  	/* Since we have problems including vnode.h, we'll use the wrappers. */
  	vnodeptr = getvnodedata(vp);
! 	if (!KVM_READ(vnodeptr, znodeptr, (size_t)size)) {
  		dprintf(stderr, "can't read znode at %p for pid %d\n",
  		    (void *)vnodeptr, Pid);
  		goto bad;
***************
*** 99,107 ****
  	 */
  	dataptr = znodeptr;
  	zid = (uint64_t *)(dataptr + LOCATION_ZID);
! 	zphys_addr = (int *)(dataptr + LOCATION_ZPHYS(size));
  
! 	if (!KVM_READ(*zphys_addr, &zphys, sizeof(zphys))) {
  		dprintf(stderr, "can't read znode_phys at %p for pid %d\n",
  		    zphys_addr, Pid);
  		goto bad;
--- 100,108 ----
  	 */
  	dataptr = znodeptr;
  	zid = (uint64_t *)(dataptr + LOCATION_ZID);
! 	zphys_addr = *(void **)(dataptr + LOCATION_ZPHYS(size));
  
! 	if (!KVM_READ(zphys_addr, &zphys, sizeof(zphys))) {
  		dprintf(stderr, "can't read znode_phys at %p for pid %d\n",
  		    zphys_addr, Pid);
  		goto bad;



>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/123456: commit references a PR
Date: Wed,  7 May 2008 17:49:39 +0000 (UTC)

 jhb         2008-05-07 17:49:31 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/fstat        fstat.c 
   Log:
   Only output details about the current working directory of a process if
   the vnode pointer is not NULL.  This avoids spurious warnings in fstat -v
   output for kernel processes.
   
   MFC after:      1 week
   PR:             amd64/123456
   Submitted by:   KOIE Hidetaka | hide koie.org
   
   Revision  Changes    Path
   1.66      +2 -1      src/usr.bin/fstat/fstat.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/123456: commit references a PR
Date: Wed,  7 May 2008 17:55:36 +0000 (UTC)

 jhb         2008-05-07 17:55:28 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/fstat        zfs.c 
   Log:
   The debug.sizeof.znode sysctl returns an int, not a size_t.  This can cause
   a hang on 64-bit platforms.
   
   MFC after:      1 week
   PR:             amd64/123456
   Submitted by:   KOIE Hidetaka | hide koie.org
   
   Revision  Changes    Path
   1.3       +3 -2      src/usr.bin/fstat/zfs.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/123456: commit references a PR
Date: Wed,  7 May 2008 18:27:45 +0000 (UTC)

 jhb         2008-05-07 18:27:38 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/fstat        zfs.c 
   Log:
   Fix reading the address of a znode_phys from a znode on 64-bit platforms
   where sizeof(pointer) != sizeof(int).
   
   MFC after:      1 week
   PR:             amd64/123456
   Submitted by:   KOIE Hidetaka | hide koie.org
   
   Revision  Changes    Path
   1.4       +3 -3      src/usr.bin/fstat/zfs.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: John Baldwin <jhb@freebsd.org>
To: freebsd-amd64@freebsd.org
Cc: KOIE Hidetaka <hide@koie.org>, freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/123456: /usr/bin/fstat shows error messages and hang.
Date: Wed, 7 May 2008 14:29:27 -0400

 On Tuesday 06 May 2008 06:53:42 am KOIE Hidetaka wrote:
 > >Description:
 >         fstat -v shows error message like this:
 >                 can't read vnode at 0x0 for pid ***
 >                 can't read znode_phys at 0x**** for pid ***
 >                 unknown file type 5 for file 5 of pid ***
 > 
 >         fstat / hangs.
 > 
 > >How-To-Repeat:
 > 
 > >Fix:
 >         Patch for "can't read vnode at 0x0 for pid ***":
 >         vtrans() is invoked iff vp is not null.
 > 
 >         Patch for "can't read znode_phys at 0x**** for pid ***":
 >         znode_phys is void *, not int.
 > 
 >         Patch for "unknown file type 5 for file 5 of pid ***":
 >         consider other DTYPEs.
 > 
 >         Patch for hanging:
 >         sysctl "debug.sizeof.znode" returns int, not size_t.
 
 I've applied all of the fixes except for the 3rd one.  I think that each file 
 type should show up as unknown until support for it is added to fstat.
 
 -- 
 John Baldwin

From: KOIE Hidetaka (=?iso-2022-jp?B?GyRCOHE5PjFRTjQbKEI=?=) <hide@koie.org>
To: jhb@freebsd.org
Cc: freebsd-amd64@freebsd.org, freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/123456: /usr/bin/fstat shows error messages and hang.
Date: Thu, 08 May 2008 15:41:11 +0900 (JST)

   Message-Id: <200805071429.27293.jhb@freebsd.org>
   Date:       Wed, 7 May 2008 14:29:27 -0400
   From:       John Baldwin <jhb@freebsd.org>
   Subject:    Re: amd64/123456: /usr/bin/fstat shows error messages an..
 
   | On Tuesday 06 May 2008 06:53:42 am KOIE Hidetaka wrote:
   | > >Description:
   | >         fstat -v shows error message like this:
   | >                 can't read vnode at 0x0 for pid ***
   | >                 can't read znode_phys at 0x**** for pid ***
   | >                 unknown file type 5 for file 5 of pid ***
   | > 
   | >         fstat / hangs.
   | > 
   | > >How-To-Repeat:
   | > 
   | > >Fix:
   | >         Patch for "can't read vnode at 0x0 for pid ***":
   | >         vtrans() is invoked iff vp is not null.
   | > 
   | >         Patch for "can't read znode_phys at 0x**** for pid ***":
   | >         znode_phys is void *, not int.
   | > 
   | >         Patch for "unknown file type 5 for file 5 of pid ***":
   | >         consider other DTYPEs.
   | > 
   | >         Patch for hanging:
   | >         sysctl "debug.sizeof.znode" returns int, not size_t.
   | 
   | I've applied all of the fixes except for the 3rd one.  I think that each file 
   | type should show up as unknown until support for it is added to fstat.
 
 Yes, any message should be showed.  But,
 "unknown file type" impresses user-kernel version mismatch to me...
 
 --
 KOIE Hidetaka <hide@koie.org>
State-Changed-From-To: open->patched 
State-Changed-By: jh 
State-Changed-When: Sun Jan 17 16:37:09 UTC 2010 
State-Changed-Why:  
Patched in head and stable/8 (r178831, r178832 and r178833). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123456 
State-Changed-From-To: patched->closed 
State-Changed-By: avg 
State-Changed-When: Sun Dec 5 13:53:37 UTC 2010 
State-Changed-Why:  
I think that the problem can be considered resolved and 
there is no reason to keep this PR open. 

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