From nobody@FreeBSD.org  Wed Jul 16 15:37:03 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 1FEAF106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Jul 2008 15:37:03 +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 11B308FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Jul 2008 15:37:03 +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 m6GFb2hC003242
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Jul 2008 15:37:02 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m6GFb2qu003241;
	Wed, 16 Jul 2008 15:37:02 GMT
	(envelope-from nobody)
Message-Id: <200807161537.m6GFb2qu003241@www.freebsd.org>
Date: Wed, 16 Jul 2008 15:37:02 GMT
From: Stef Walter <stef@memberwebs.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: atacontrol depends on executable in /usr
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         125680
>Category:       bin
>Synopsis:       [patch] atacontrol(8): atacontrol depends on executable in /usr
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    antoine
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 16 15:40:01 UTC 2008
>Closed-Date:    Sun Jan 25 19:44:59 UTC 2009
>Last-Modified:  Sun Jan 25 19:44:59 UTC 2009
>Originator:     Stef Walter
>Release:        6.3-RELEASE-p2
>Organization:
>Environment:
FreeBSD m2.npubs.com 6.3-RELEASE-p2 FreeBSD 6.3-RELEASE-p2 #3: Fri Jul 11 15:39:09 UTC 2008     root@m2.npubs.com:/usr/obj/usr/src/sys/RACK2  i386

>Description:
When using atacontrol from single user mode, one cannot rebuild a RAID
array. The command /usr/bin/nice is not mounted or available in single
user mode.

# atacontrol rebuild ar0
/usr/bin/nice: not found

The raid is marked as rebuilding, but never completes. When rebooted the
RAID is marked as ready:

ar0: 476937MB <Intel MatrixRAID RAID1> status: READY
ar0: disk0 READY (master) using ad4 at ata2-master
ar0: disk1 READY (mirror) using ad6 at ata3-master


However this obviously results in file system corruption:

 bad dir ino 50722 at offset 0: mangled entry
panic: ufs_dirbad: bad dir
cpuid = 1
Uptime: 25s
Cannot dump. No dump device defined.
Automatic reboot in 15 seconds - press a key on the console to abort
Rebooting...

>How-To-Repeat:
Remove one drive of an ata raid device:

# atacontrol detach ata3

Reboot into single user mode, add spare and try to rebuild:

# atacontrol addspare ar0 ad6
# atacontrol rebuild ar0


>Fix:
Move /usr/bin/nice to /bin/nice

>Release-Note:
>Audit-Trail:

From: Kris Kennaway <kris@FreeBSD.org>
To: Stef Walter <stef@memberwebs.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/125680: atacontrol depends on executable in /usr
Date: Wed, 16 Jul 2008 17:55:43 +0200

 Better fix: use /bin/csh and the built-in nice.
 
 Kris

From: David Schultz <das@FreeBSD.ORG>
To: Kris Kennaway <kris@FreeBSD.ORG>
Cc: bug-followup@FreeBSD.ORG
Subject: Re: misc/125680: atacontrol depends on executable in /usr
Date: Wed, 16 Jul 2008 17:28:31 -0400

 On Wed, Jul 16, 2008, Kris Kennaway wrote:
 >  Better fix: use /bin/csh and the built-in nice.
 
 Better yet, given that it's a C program that invokes
        /usr/bin/nice -n 20 /bin/dd if=/dev/ar%d of=/dev/null bs=1m &
 via system(3), would be to use nice(3). Actually, the whole thing
 is sort of dubious: What if my libraries are corrupted and I'm trying
 to use /rescue/atacontrol to fix things, but it gives an error because
 it's hardwired to use /bin/dd instead of /rescue/dd? A simple
 while (!eof) read(); loop should suffice.

From: Kris Kennaway <kris@FreeBSD.org>
To: David Schultz <das@FreeBSD.ORG>
Cc: bug-followup@FreeBSD.ORG
Subject: Re: misc/125680: atacontrol depends on executable in /usr
Date: Thu, 17 Jul 2008 00:04:28 +0200

 David Schultz wrote:
 > On Wed, Jul 16, 2008, Kris Kennaway wrote:
 >>  Better fix: use /bin/csh and the built-in nice.
 > 
 > Better yet, given that it's a C program that invokes
 >        /usr/bin/nice -n 20 /bin/dd if=/dev/ar%d of=/dev/null bs=1m &
 > via system(3), would be to use nice(3). Actually, the whole thing
 > is sort of dubious: What if my libraries are corrupted and I'm trying
 > to use /rescue/atacontrol to fix things, but it gives an error because
 > it's hardwired to use /bin/dd instead of /rescue/dd? A simple
 > while (!eof) read(); loop should suffice.
 > 
 > 
 
 You make a good point, sir :)
 
 Kris
 

From: Antoine Brodin <antoine@FreeBSD.org>
To: bug-followup@FreeBSD.org, stef@memberwebs.com
Cc:  
Subject: Re: bin/125680: atacontrol(8): atacontrol depends on executable in
 /usr
Date: Sun, 20 Jul 2008 23:37:13 +0200

 This is a multi-part message in MIME format.
 
 --Multipart=_Sun__20_Jul_2008_23_37_13_+0200_SBQJ0Ag63L4yRB6c
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 
 Could you try the attached patch ?
 
 Cheers,
 
 Antoine
 
 --Multipart=_Sun__20_Jul_2008_23_37_13_+0200_SBQJ0Ag63L4yRB6c
 Content-Type: text/x-diff;
  name="atacontrol.diff"
 Content-Disposition: attachment;
  filename="atacontrol.diff"
 Content-Transfer-Encoding: 7bit
 
 Index: sbin/atacontrol/atacontrol.c
 ===================================================================
 RCS file: /home/ncvs/src/sbin/atacontrol/atacontrol.c,v
 retrieving revision 1.48
 diff -u -r1.48 atacontrol.c
 --- sbin/atacontrol/atacontrol.c	15 May 2008 01:25:29 -0000	1.48
 +++ sbin/atacontrol/atacontrol.c	20 Jul 2008 21:18:35 -0000
 @@ -37,6 +37,7 @@
  #include <stdlib.h>
  #include <string.h>
  #include <sysexits.h>
 +#include <unistd.h>
  
  static const char *
  mode2str(int mode)
 @@ -517,12 +518,29 @@
  		if (ioctl(fd, IOCATARAIDREBUILD, &array) < 0)
  			warn("ioctl(IOCATARAIDREBUILD)");
  		else {
 -			char buffer[128];
 -			sprintf(buffer, "/usr/bin/nice -n 20 /bin/dd "
 -				"if=/dev/ar%d of=/dev/null bs=1m &",
 -				array);
 -			if (system(buffer))
 -				warn("background dd");
 +			char device[64];
 +			char *buffer;
 +			int arfd;
 +
 +			switch (fork()) {
 +			case -1:
 +				err(1, "fork");
 +			case 0:
 +				nice(20);
 +				snprintf(device, sizeof(device), "/dev/ar%d",
 +					array);
 +				if ((arfd = open(device, O_RDONLY)) == -1)
 +					err(1, "open %s", device);
 +				if ((buffer = malloc(1024 * 1024)) == NULL)
 +					err(1, "malloc");
 +				while (read(arfd, buffer, 1024 * 1024) > 0)
 +					;
 +				free(buffer);
 +				close(arfd);
 +				break;
 +			default:
 +				break;
 +			}
  		}
  		exit(EX_OK);
  	}
 
 
 --Multipart=_Sun__20_Jul_2008_23_37_13_+0200_SBQJ0Ag63L4yRB6c--
State-Changed-From-To: open->feedback 
State-Changed-By: antoine 
State-Changed-When: Tue Jul 22 22:25:05 UTC 2008 
State-Changed-Why:  
I asked the submitter to test a patch. 


Responsible-Changed-From-To: freebsd-bugs->antoine 
Responsible-Changed-By: antoine 
Responsible-Changed-When: Tue Jul 22 22:25:05 UTC 2008 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125680 

From: Stef Walter <stef@memberwebs.com>
To: antoine@FreeBSD.org, bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125680: [patch] atacontrol(8): atacontrol depends on executable
 in /usr
Date: Wed,  6 Aug 2008 17:08:07 +0000 (UTC)

 Yes, I can confirm this works as expected. I setup a test machine and
 tested this on an IHC7 based Intel Matrix RAID.
 
 ar0: 476940MB <Intel MatrixRAID RAID1> status: READY
 ar0: disk0 READY (master) using ad4 at ata2-master
 ar0: disk1 READY (mirror) using ad6 at ata3-master
 
 Nice. Thanks!
 
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125680: commit references a PR
Date: Wed,  6 Aug 2008 18:08:35 +0000 (UTC)

 antoine     2008-08-06 18:08:02 UTC
 
   FreeBSD src repository
 
   Modified files:
     sbin/atacontrol      atacontrol.c 
   Log:
   SVN rev 181349 on 2008-08-06 18:08:02Z by antoine
   
   Make atacontrol(8) rebuild work when /usr is not mounted or from /rescue
   
   PR:             bin/125680
   MFC after:      1 month
   Tested by:      Stef Walter
   
   Revision  Changes    Path
   1.49      +25 -6     src/sbin/atacontrol/atacontrol.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"
 
State-Changed-From-To: feedback->patched 
State-Changed-By: antoine 
State-Changed-When: Wed Aug 6 18:11:17 UTC 2008 
State-Changed-Why:  
Patched in head. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125680 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125680: commit references a PR
Date: Sun, 25 Jan 2009 19:35:38 +0000 (UTC)

 Author: antoine
 Date: Sun Jan 25 19:35:23 2009
 New Revision: 187697
 URL: http://svn.freebsd.org/changeset/base/187697
 
 Log:
   MFC r181349 to stable/7:
     Make atacontrol(8) rebuild work when /usr is not mounted or from /rescue
   
     PR:             bin/125680
     MFC after:      1 month
     Tested by:      Stef Walter
 
 Modified:
   stable/7/sbin/atacontrol/   (props changed)
   stable/7/sbin/atacontrol/atacontrol.c
 
 Modified: stable/7/sbin/atacontrol/atacontrol.c
 ==============================================================================
 --- stable/7/sbin/atacontrol/atacontrol.c	Sun Jan 25 19:25:41 2009	(r187696)
 +++ stable/7/sbin/atacontrol/atacontrol.c	Sun Jan 25 19:35:23 2009	(r187697)
 @@ -37,6 +37,7 @@
  #include <stdlib.h>
  #include <string.h>
  #include <sysexits.h>
 +#include <unistd.h>
  
  static const char *
  mode2str(int mode)
 @@ -517,12 +518,30 @@ main(int argc, char **argv)
  		if (ioctl(fd, IOCATARAIDREBUILD, &array) < 0)
  			warn("ioctl(IOCATARAIDREBUILD)");
  		else {
 -			char buffer[128];
 -			sprintf(buffer, "/usr/bin/nice -n 20 /bin/dd "
 -				"if=/dev/ar%d of=/dev/null bs=1m &",
 -				array);
 -			if (system(buffer))
 -				warn("background dd");
 +			char device[64];
 +			char *buffer;
 +			ssize_t len;
 +			int arfd;
 +
 +			if (daemon(0, 1) == -1)
 +				err(1, "daemon");
 +			nice(20);
 +			snprintf(device, sizeof(device), "/dev/ar%d",
 +			    array);
 +			if ((arfd = open(device, O_RDONLY)) == -1)
 +				err(1, "open %s", device);
 +			if ((buffer = malloc(1024 * 1024)) == NULL)
 +				err(1, "malloc");
 +			while ((len = read(arfd, buffer, 1024 * 1024)) > 0)
 +				;
 +			if (len == -1)
 +				err(1, "read");
 +			else
 +				fprintf(stderr,
 +				    "atacontrol: ar%d rebuild completed\n",
 +				    array);
 +			free(buffer);
 +			close(arfd);
  		}
  		exit(EX_OK);
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: antoine 
State-Changed-When: Sun Jan 25 19:44:31 UTC 2009 
State-Changed-Why:  
Close: fix committed in head and stable/7. 

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