From nobody@FreeBSD.org  Fri Sep  7 13:10:59 2007
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 8125E16A41A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  7 Sep 2007 13:10:59 +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 6119C13C45A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  7 Sep 2007 13:10:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.1/8.14.1) with ESMTP id l87DAwV3041199
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 7 Sep 2007 13:10:58 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.1/8.14.1/Submit) id l87DAwcO041198;
	Fri, 7 Sep 2007 13:10:58 GMT
	(envelope-from nobody)
Message-Id: <200709071310.l87DAwcO041198@www.freebsd.org>
Date: Fri, 7 Sep 2007 13:10:58 GMT
From: Denis Barov <dindin@dindin.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: rc.d/mdconfig2 script fail at -CURRENT
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         116177
>Category:       conf
>Synopsis:       rc.d/mdconfig2 script fail at -CURRENT
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    flz
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 07 13:20:01 GMT 2007
>Closed-Date:    Thu Dec 06 11:58:29 UTC 2007
>Last-Modified:  Thu Dec  6 12:00:08 UTC 2007
>Originator:     Denis Barov
>Release:        FreeBSD 5.x, 6.x, 7.x
>Organization:
OAO TPK TBT
>Environment:
FreeBSD patient.tbt.ru 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Mon Jul 23 14:40:33 UTC 2007     root@patient.tbt.ru:/usr/obj/usr/sync/RELENG_7/src/sys/GENERIC  i386
>Description:
Due some changes in mdconfig(8) mdconfig no longer returns different errorstates when we do mdconfig -l. This causes errors when starting mdconfig2 script. In rc.conf we have:

mdconfig_md0="-t vnode -f /home/dindin/test.ufs2"

Runnung /etc/rc.d/mdconfig2 start/stop:

eternalpatient# /etc/rc.d/mdconfig2 stop
/etc/rc.d/mdconfig2: DEBUG: run_rc_command: doit: mdconfig2_stop
/etc/rc.d/mdconfig2: DEBUG: md0 config: -t vnode -f /home/dindin/test.ufs2
/etc/rc.d/mdconfig2: DEBUG: md0 type: vnode
/etc/rc.d/mdconfig2: DEBUG: md0 dev: /dev/md0
/etc/rc.d/mdconfig2: DEBUG: md0 file: /home/dindin/test.ufs2
/etc/rc.d/mdconfig2: DEBUG: md0 fs: /usr
/etc/rc.d/mdconfig2: DEBUG: md0 owner:
/etc/rc.d/mdconfig2: DEBUG: md0 perms:
/etc/rc.d/mdconfig2: DEBUG: md0 files:
/etc/rc.d/mdconfig2: DEBUG: md0 populate cmd:
Device /dev/md0 isn't mounted.
Destroying md0.
mdconfig: ioctl(/dev/mdctl): No such file or directory
eternalpatient# /etc/rc.d/mdconfig2 start
/etc/rc.d/mdconfig2: DEBUG: run_rc_command: start_precmd: [ -n "${_mdconfig2_list}" ]
/etc/rc.d/mdconfig2: DEBUG: load_kld: geom_md kernel module already loaded.
/etc/rc.d/mdconfig2: DEBUG: run_rc_command: doit: mdconfig2_start
/etc/rc.d/mdconfig2: DEBUG: md0 config: -t vnode -f /home/dindin/test.ufs2
/etc/rc.d/mdconfig2: DEBUG: md0 type: vnode
/etc/rc.d/mdconfig2: DEBUG: md0 dev: /dev/md0
/etc/rc.d/mdconfig2: DEBUG: md0 file: /home/dindin/test.ufs2
/etc/rc.d/mdconfig2: DEBUG: md0 fs: /usr
/etc/rc.d/mdconfig2: DEBUG: md0 owner:
/etc/rc.d/mdconfig2: DEBUG: md0 perms:
/etc/rc.d/mdconfig2: DEBUG: md0 files:
/etc/rc.d/mdconfig2: DEBUG: md0 populate cmd:
/etc/rc.d/mdconfig2: ERROR: md0 already exists


>How-To-Repeat:
On -CURRENT run:

# dd if=/dev/zero of=/tmpfile count=100000
# mdconfig -a -t vnode -f /tmpfile
# newfs /dev/md0

add into rc.conf this:

mdconfig_md0="-t vnode -f /tmpfile"

then run:
# /etc/rc.d/mdconfig2 start
# /etc/rc.d/mdconfig2 stop

>Fix:


Patch attached with submission follows:

--- /etc/rc.d/mdconfig2.orig	2006-12-31 10:37:18.000000000 +0000
+++ /etc/rc.d/mdconfig2		2007-07-25 12:07:00.000000000 +0000
@@ -128,7 +128,7 @@
 				warn "${_fs} is mounted read-only, skipping ${_md}."
 				continue
 			fi
-			if mdconfig -l -u ${_md} >/dev/null 2>&1; then
+			if [ -n "`mdconfig -l -u ${_md}`" ]; then
 				err 3 "${_md} already exists"
 			fi
 			echo "Creating ${_md} device (${_type})."


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: remko 
Responsible-Changed-When: Fri Sep 7 21:46:08 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer. 

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

From: =?ISO-8859-1?Q?R=E9mi_Guyomarch?= <rguyom@pobox.com>
To: bug-followup@FreeBSD.org,  dindin@dindin.ru
Cc:  
Subject: Re: conf/116177: rc.d/mdconfig2 script fail at -CURRENT
Date: Sun, 30 Sep 2007 16:57:42 +0200

 I had the exact same problem but I fixed it by patching /sbin/mdconfig 
 instead. With this patch, "/sbin/mdconfig -l -u md0" will return 0 if 
 md0 exists and -1 if not. It has the advantage of fixing the bug in both 
 /etc/rc.d/mdconfig and /etc/rc.d/mdconfig2.
 
 --- /usr/src/sbin/mdconfig/mdconfig.c~  2007-09-30 15:25:16.000000000 +0200
 +++ /usr/src/sbin/mdconfig/mdconfig.c   2007-09-30 15:25:16.000000000 +0200
 @@ -284,7 +284,7 @@
                           */
                          md_list(NULL, OPT_LIST);
                  } else {
 -                       md_query(mdunit);
 +                       return (md_query(mdunit));
                  }
          } else if (action == ATTACH) {
                  if (cmdline < 2)
 @@ -323,7 +323,7 @@
          struct ggeom *gg;
          struct gclass *gcl;
          void *sq;
 -       int retcode;
 +       int retcode, found;
          char *type, *file, *length;
 
          type = file = length = NULL;
 @@ -338,6 +338,7 @@
          if (sq == NULL)
                  return (-1);
 
 +       found = 0;
          while ((gsp = geom_stats_snapshot_next(sq)) != NULL) {
                  gid = geom_lookupid(&gm, gsp->id);
                  if (gid == NULL)
 @@ -352,6 +353,8 @@
                                  retcode = md_find(units, pp->lg_name);
                                  if (retcode != 1)
                                          continue;
 +                               else
 +                                       found = 1;
                          }
                          gc = &pp->lg_config;
                          printf("%s", pp->lg_name);
 @@ -380,7 +383,10 @@
                  printf("\n");
          /* XXX: Check if it's enough to clean everything. */
          geom_stats_snapshot_free(sq);
 -       return (-1);
 +       if ((opt & OPT_UNIT) && found)
 +               return (0);
 +       else
 +               return (-1);
   }
 
   /*
 

From: Ben Kelly <bkelly@vadev.org>
To: bug-followup@FreeBSD.org,  dindin@dindin.ru
Cc:  
Subject: Re: conf/116177: rc.d/mdconfig2 script fail at -CURRENT
Date: Wed, 07 Nov 2007 00:02:52 -0500

 If you are going to patch /etc/rc.d/mdconfig2 I think you also need to 
 update the mdconfig script as well.  It has the same problem.
 
 --- /usr/src/etc/rc.d/mdconfig  2007-08-25 00:19:17.000000000 +0000
 +++ /etc/rc.d/mdconfig  2007-11-04 16:42:24.000000000 +0000
 @@ -119,7 +119,7 @@
                                          sleep 2
                                  fi
                          fi
 -                       if mdconfig -l -u ${_md} >/dev/null 2>&1; then
 +                       if [ -n "`mdconfig -l -u ${_md}`" ]; then
                                  err 3 "${_md} already exists"
                          fi
                          echo "Creating ${_md} device (${_type})."
State-Changed-From-To: open->patched 
State-Changed-By: flz 
State-Changed-When: Ven 16 nov 2007 17:42:47 UTC 
State-Changed-Why:  
Commmitted to HEAD. MFC to RELENG_[67] after 3 days. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=116177 
Responsible-Changed-From-To: freebsd-rc->flz 
Responsible-Changed-By: flz 
Responsible-Changed-When: Ven 16 nov 2007 17:43:16 UTC 
Responsible-Changed-Why:  
I'll take care of the MFC. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/116177: commit references a PR
Date: Fri, 16 Nov 2007 17:40:32 +0000 (UTC)

 flz         2007-11-16 17:40:24 UTC
 
   FreeBSD src repository
 
   Modified files:
     sbin/mdconfig        mdconfig.c 
   Log:
   Fix exit code when using -l on a non-existent md(4) device.
   
   PR:             conf/116177
   Submitted by:   Remi Guyomarch <rguyom@pobox.com>
   MFC after:      3 days
   
   Revision  Changes    Path
   1.55      +9 -3      src/sbin/mdconfig/mdconfig.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: patched->closed 
State-Changed-By: flz 
State-Changed-When: Jeu 6 dc 2007 11:58:28 UTC 
State-Changed-Why:  
MFC'ed to RELENG_7. Thanks for your report! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/116177: commit references a PR
Date: Thu,  6 Dec 2007 11:54:47 +0000 (UTC)

 flz         2007-12-06 11:54:36 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sbin/mdconfig        mdconfig.c 
   Log:
   MFC: Fix exit code when using -l on a non-existent md(4) device.
   
     src/sbin/mdconfig/mdconfig.c: rev 1.54 -> 1.55
   
   PR:             conf/116177
   Submitted by:   Remi Guyomarch <rguyom@pobox.com>
   Approved by:    re (kensmith)
   
   Revision  Changes    Path
   1.54.2.1  +9 -3      src/sbin/mdconfig/mdconfig.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"
 
>Unformatted:
