From nobody@FreeBSD.org  Sun Dec  1 05:27:03 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 036B9BC4
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  1 Dec 2013 05:27:02 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id C3D21109C
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  1 Dec 2013 05:27:02 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id rB15R2PR089892
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 1 Dec 2013 05:27:02 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id rB15R2No089867;
	Sun, 1 Dec 2013 05:27:02 GMT
	(envelope-from nobody)
Message-Id: <201312010527.rB15R2No089867@oldred.freebsd.org>
Date: Sun, 1 Dec 2013 05:27:02 GMT
From: Zurvan Akarana <zurvan.akarana@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [regression] [patch] 'mfiutil show drives' from 9.2-REL shows 0.0 size for all drives
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         184405
>Category:       bin
>Synopsis:       [regression] [patch] mfiutil(8): 'mfiutil show drives' from 9.2-REL shows 0.0 size for all drives
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sbruno
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 01 05:30:00 UTC 2013
>Closed-Date:    Sun Jan 05 18:40:38 UTC 2014
>Last-Modified:  Sun Jan 05 18:40:38 UTC 2014
>Originator:     Zurvan Akarana
>Release:        9.2 RELEASE
>Organization:
N/A
>Environment:
FreeBSD [redacted] 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013     root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
Upgraded to 9.2-RELEASE on Nov. 29, 2013.

Have an LSI-2108-based raid controller supported without issues by mfi(4).

Prior to upgrade 'mfiutil show drives' showed drive sizes correctly.

After upgrade the output became like this

 0 (   0.0) ONLINE <[redacted] serial=[redacted]> SATA E1:S4

I.e., drive size was reported to be 0.0.

All other aspects of mfi(4) that I have tested so far seem to work fine, as they did before.
>How-To-Repeat:
Any run of 'mfiutil show drives' reproduces the problem. I use 3 TB drives connected to the controller but the problem is unaffected by drive size.
>Fix:
Traced the problem to usr.sbin/mfiutil/mfi_show.c file, function print_pd.

It makes a call to humanize_number(3) from libutil and supplies a 256-byte buffer named 'buf' to be filled for this purpose. Then prints it with format string '%6s' which results in this incorrect behavior.

Just using a 6-byte buffer, supplying it to humanize_number(3), and printing it fixes the problem. As seen in the other function print_ld in the same source file.

This bug has been introduced as the larger sized 'buf' was added to source to allow for formatting status messages for foreign configurations present in the array, a new mfiutil functionality.

Patch attached with submission follows:

*** mfi_show.c.orig	2013-12-01 05:21:58.000000000 +0000
--- mfi_show.c	2013-12-01 05:14:48.000000000 +0000
***************
*** 316,330 ****
  
  void
  print_pd(struct mfi_pd_info *info, int state_len)
  {
  	const char *s;
  	char buf[256];
  
! 	humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
  	    HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
! 	printf("(%6s) ", buf);
  	if (info->state.ddf.v.pd_type.is_foreign) {
  		sprintf(buf, "%s%s", mfi_pdstate(info->fw_state), foreign_state);
  		s = buf;
  	} else
  		s = mfi_pdstate(info->fw_state);
--- 316,331 ----
  
  void
  print_pd(struct mfi_pd_info *info, int state_len)
  {
  	const char *s;
+ 	char size[6];
  	char buf[256];
  
! 	humanize_number(size, sizeof(size), info->raw_size * 512, "",
  	    HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
! 	printf("(%6s) ", size);
  	if (info->state.ddf.v.pd_type.is_foreign) {
  		sprintf(buf, "%s%s", mfi_pdstate(info->fw_state), foreign_state);
  		s = buf;
  	} else
  		s = mfi_pdstate(info->fw_state);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-amd64->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Dec 1 22:30:06 UTC 2013 
Responsible-Changed-Why:  
reclassify. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=184405 
Responsible-Changed-From-To: freebsd-bugs->sbruno 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Dec 3 04:30:20 UTC 2013 
Responsible-Changed-Why:  
by suggestion of jhb. 

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

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/184405: [regression] [patch] mfiutil(8): 'mfiutil show
 drives' from 9.2-REL shows 0.0 size for all drives
Date: Mon, 2 Dec 2013 22:30:13 -0600

 ----- Forwarded message from John Baldwin <jhb@freebsd.org> -----
 
 Date: Mon, 2 Dec 2013 15:46:03 -0500
 From: John Baldwin <jhb@freebsd.org>
 To: freebsd-amd64@freebsd.org
 Cc: linimon@freebsd.org, freebsd-bugs@freebsd.org, Sean Bruno <sbruno@freebsd.org>
 Subject: Re: bin/184405: [regression] [patch] mfiutil(8): 'mfiutil show drives' from 9.2-REL shows 0.0 size for all drives
 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; )
 
 Sean, can you take care of this since you committed the foreign config stuff?
 
 I think you can simply replace sizeof(buf) in the call to humanize_number with
 6 instead rather than using a separate array for the size as in the patch.
 
 -- 
 John Baldwin
 
 ----- End forwarded message -----

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/184405: commit references a PR
Date: Wed,  4 Dec 2013 00:28:58 +0000 (UTC)

 Author: sbruno
 Date: Wed Dec  4 00:28:44 2013
 New Revision: 258901
 URL: http://svnweb.freebsd.org/changeset/base/258901
 
 Log:
   svn r251516 resized the buf argument a bit too much.  Pass a hardcoded
   size of 6 to humanize_number() to resolve this.
   
   PR:		184405
   Submitted by:	jhb
   MFC after:	2 weeks
 
 Modified:
   head/usr.sbin/mfiutil/mfi_show.c
 
 Modified: head/usr.sbin/mfiutil/mfi_show.c
 ==============================================================================
 --- head/usr.sbin/mfiutil/mfi_show.c	Wed Dec  4 00:10:37 2013	(r258900)
 +++ head/usr.sbin/mfiutil/mfi_show.c	Wed Dec  4 00:28:44 2013	(r258901)
 @@ -320,7 +320,7 @@ print_pd(struct mfi_pd_info *info, int s
  	const char *s;
  	char buf[256];
  
 -	humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
 +	humanize_number(buf, 6, info->raw_size * 512, "",
  	    HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
  	printf("(%6s) ", buf);
  	if (info->state.ddf.v.pd_type.is_foreign) {
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/184405: commit references a PR
Date: Sun,  5 Jan 2014 17:30:06 +0000 (UTC)

 Author: sbruno
 Date: Sun Jan  5 17:29:53 2014
 New Revision: 260324
 URL: http://svnweb.freebsd.org/changeset/base/260324
 
 Log:
   MFC r258901:
   
   svn r251516 resized the buf argument a bit too much. Pass a hardcoded
   size of 6 to humanize_number() to resolve this.
   
   PR:	bin/184405
   Submitted by:	jhb
 
 Modified:
   stable/10/usr.sbin/mfiutil/mfi_show.c
 Directory Properties:
   stable/10/   (props changed)
 
 Modified: stable/10/usr.sbin/mfiutil/mfi_show.c
 ==============================================================================
 --- stable/10/usr.sbin/mfiutil/mfi_show.c	Sun Jan  5 16:45:34 2014	(r260323)
 +++ stable/10/usr.sbin/mfiutil/mfi_show.c	Sun Jan  5 17:29:53 2014	(r260324)
 @@ -320,7 +320,7 @@ print_pd(struct mfi_pd_info *info, int s
  	const char *s;
  	char buf[256];
  
 -	humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
 +	humanize_number(buf, 6, info->raw_size * 512, "",
  	    HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
  	printf("(%6s) ", buf);
  	if (info->state.ddf.v.pd_type.is_foreign) {
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/184405: commit references a PR
Date: Sun,  5 Jan 2014 17:33:18 +0000 (UTC)

 Author: sbruno
 Date: Sun Jan  5 17:33:10 2014
 New Revision: 260325
 URL: http://svnweb.freebsd.org/changeset/base/260325
 
 Log:
   MFC r258901:
   
   svn r251516 resized the buf argument a bit too much. Pass a hardcoded
   size of 6 to humanize_number() to resolve this.
   
   PR:     bin/184405
   Submitted by:   jhb
 
 Modified:
   stable/9/usr.sbin/mfiutil/mfi_show.c
 Directory Properties:
   stable/9/usr.sbin/mfiutil/   (props changed)
 
 Modified: stable/9/usr.sbin/mfiutil/mfi_show.c
 ==============================================================================
 --- stable/9/usr.sbin/mfiutil/mfi_show.c	Sun Jan  5 17:29:53 2014	(r260324)
 +++ stable/9/usr.sbin/mfiutil/mfi_show.c	Sun Jan  5 17:33:10 2014	(r260325)
 @@ -320,7 +320,7 @@ print_pd(struct mfi_pd_info *info, int s
  	const char *s;
  	char buf[256];
  
 -	humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
 +	humanize_number(buf, 6, info->raw_size * 512, "",
  	    HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
  	printf("(%6s) ", buf);
  	if (info->state.ddf.v.pd_type.is_foreign) {
 _______________________________________________
 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: open->closed 
State-Changed-By: sbruno 
State-Changed-When: Sun Jan 5 18:40:16 UTC 2014 
State-Changed-Why:  
MFC to stable/9 and stable/10 complete 

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