Bug 125680

Summary: [patch] atacontrol(8): atacontrol depends on executable in /usr
Product: Base System Reporter: Stef Walter <stef>
Component: binAssignee: Antoine Brodin <antoine>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 6.3-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
atacontrol.diff none

Description Stef Walter 2008-07-16 16:40:01 UTC
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...

Fix: 

Move /usr/bin/nice to /bin/nice
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
Comment 1 Kris Kennaway freebsd_committer freebsd_triage 2008-07-16 16:55:43 UTC
Better fix: use /bin/csh and the built-in nice.

Kris
Comment 2 David Schultz freebsd_committer freebsd_triage 2008-07-16 22:28:31 UTC
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.
Comment 3 Kris Kennaway freebsd_committer freebsd_triage 2008-07-16 23:04:28 UTC
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
Comment 4 Antoine Brodin freebsd_committer freebsd_triage 2008-07-20 22:37:13 UTC
Could you try the attached patch ?

Cheers,

Antoine
Comment 5 Antoine Brodin freebsd_committer freebsd_triage 2008-07-22 23:25:05 UTC
State Changed
From-To: open->feedback

I asked the submitter to test a patch. 


Comment 6 Antoine Brodin freebsd_committer freebsd_triage 2008-07-22 23:25:05 UTC
Responsible Changed
From-To: freebsd-bugs->antoine

Take.
Comment 7 Stef Walter 2008-08-06 18:08:07 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!
Comment 8 dfilter service freebsd_committer freebsd_triage 2008-08-06 19:08:35 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"
Comment 9 Antoine Brodin freebsd_committer freebsd_triage 2008-08-06 19:11:17 UTC
State Changed
From-To: feedback->patched

Patched in head.
Comment 10 dfilter service freebsd_committer freebsd_triage 2009-01-25 19:35:38 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"
Comment 11 Antoine Brodin freebsd_committer freebsd_triage 2009-01-25 19:44:31 UTC
State Changed
From-To: patched->closed

Close: fix committed in head and stable/7.