From dunstan@freebsd.czest.pl  Tue Apr  5 22:15:24 2005
Return-Path: <dunstan@freebsd.czest.pl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 140CB16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  5 Apr 2005 22:15:24 +0000 (GMT)
Received: from freebsd.czest.pl (silver.iplus.pl [80.48.250.4])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D490F43D41
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  5 Apr 2005 22:15:22 +0000 (GMT)
	(envelope-from dunstan@freebsd.czest.pl)
Received: from freebsd.czest.pl (freebsd.czest.pl [80.48.250.4])
	by freebsd.czest.pl (8.12.10/8.12.9) with ESMTP id j35MNQtf076972
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 5 Apr 2005 22:23:26 GMT
	(envelope-from dunstan@freebsd.czest.pl)
Received: (from dunstan@localhost)
	by freebsd.czest.pl (8.12.10/8.12.9/Submit) id j35MNPce076971;
	Tue, 5 Apr 2005 22:23:25 GMT
	(envelope-from dunstan)
Message-Id: <200504052223.j35MNPce076971@freebsd.czest.pl>
Date: Tue, 5 Apr 2005 22:23:25 GMT
From: "Wojciech A. Koszek" <dunstan@freebsd.czest.pl>
Reply-To: "Wojciech A. Koszek" <dunstan@freebsd.czest.pl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Fixes order of disks in 'mdconfig -l' output
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         79575
>Category:       kern
>Synopsis:       [md] [patch] Fixes order of disks in 'mdconfig -l' output
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 05 22:20:03 GMT 2005
>Closed-Date:    Mon Dec 26 04:48:38 UTC 2005
>Last-Modified:  Mon Dec 26 04:48:38 UTC 2005
>Originator:     Wojciech A. Koszek
>Release:        FreeBSD 5.4-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD dunstan.freebsd.czest.pl 5.4-PRERELEASE FreeBSD 5.4-PRERELEASE #6: Mon Apr 4 21:06:12 CEST 2005 dunstan@dunstan.freebsd.czest.pl:/usr/obj/usr/src/sys/HOME8 i386

Also -CURRENT.
>Description:
While listing memory disks, their order is reversed, which makes reading
harder. I was informed that old implementation ordered disks
correctly.
>How-To-Repeat:
mdconfig -a -t malloc -s 10m
mdconfig -a -t malloc -s 10m
mdconfig -a -t malloc -s 10m

And result:

mdconfig -l 
md2 md1 md0

>Fix:
This patch [diff.0.md.c] causes that result will be:
mdconfig -l
md0 md1 md2

--- diff.0.md.c begins here ---
(c) 2005 <Wojciech A. Koszek dunstan^freebsd.czest.pl>

Patch against FreeBSD 5.4-PRERELEASE, kern.osreldate: 503105.

diff -uprP /usr/src/sys/dev/md/md.c src/sys/dev/md/md.c
--- /usr/src/sys/dev/md/md.c	Tue Mar  1 22:49:18 2005
+++ src/sys/dev/md/md.c	Tue Apr  5 22:31:28 2005
@@ -63,6 +63,7 @@
 #include <sys/fcntl.h>
 #include <sys/kernel.h>
 #include <sys/kthread.h>
+#include <sys/libkern.h>
 #include <sys/linker.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
@@ -685,6 +686,12 @@ mdfind(int unit)
 	return (sc);
 }
 
+static int
+mdunitcmp (void *a, void *b)
+{
+	return (*(int *)a - *(int *)b);
+}
+
 static struct md_s *
 mdnew(int unit)
 {
@@ -1160,6 +1167,8 @@ mdctlioctl(struct cdev *dev, u_long cmd,
 				mdio->md_pad[i++] = sc->unit;
 		}
 		mdio->md_pad[0] = i - 1;
+		qsort(&mdio->md_pad[1], i - 1, sizeof(mdio->md_pad[1]),
+		    mdunitcmp);
 		return (0);
 	default:
 		return (ENOIOCTL);
--- diff.0.md.c ends here ---

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: dd 
State-Changed-When: Mon Dec 26 04:48:22 UTC 2005 
State-Changed-Why:  
Sorting added as requested. 

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