From redpixel@lockdown.spectrum.fearmuffs.net  Wed Oct 22 11:39:27 2003
Return-Path: <redpixel@lockdown.spectrum.fearmuffs.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2C20416A4B3
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Oct 2003 11:39:27 -0700 (PDT)
Received: from lockdown.spectrum.fearmuffs.net (c-ed8870d5.010-2114-67626719.cust.bredbandsbolaget.se [213.112.136.237])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B638E43FD7
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Oct 2003 11:39:22 -0700 (PDT)
	(envelope-from redpixel@lockdown.spectrum.fearmuffs.net)
Received: from lockdown.spectrum.fearmuffs.net (localhost [127.0.0.1])
	by lockdown.spectrum.fearmuffs.net (8.12.10/8.12.10) with ESMTP id h9MIdUkF001258
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Oct 2003 20:39:31 +0200 (CEST)
	(envelope-from redpixel@lockdown.spectrum.fearmuffs.net)
Received: (from redpixel@localhost)
	by lockdown.spectrum.fearmuffs.net (8.12.10/8.12.10/Submit) id h9MIdQtj001257;
	Wed, 22 Oct 2003 20:39:26 +0200 (CEST)
	(envelope-from redpixel)
Message-Id: <200310221839.h9MIdQtj001257@lockdown.spectrum.fearmuffs.net>
Date: Wed, 22 Oct 2003 20:39:26 +0200 (CEST)
From: Martin Faxer <martin.faxer@home.se>
Reply-To: Martin Faxer <martin.faxer@home.se>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: bsdlabel fails to display an error message if the label could not be written
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         58390
>Category:       bin
>Synopsis:       bsdlabel(8) fails to display an error message if the label could not be written
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 22 11:40:18 PDT 2003
>Closed-Date:    Fri Aug 27 12:01:12 UTC 2010
>Last-Modified:  Sun Sep 26 17:00:17 UTC 2010
>Originator:     Martin Faxer
>Release:        FreeBSD 5.1-CURRENT-20031018-JPSNAP i386
>Organization:
>Environment:
System: FreeBSD lockdown.spectrum.fearmuffs.net 5.1-CURRENT-20031018-JPSNAP FreeBSD 5.1-CURRENT-20031018-JPSNAP #0: Mon Oct 20 15:21:10 CEST 2003 redpixel@lockdown.spectrum.fearmuffs.net:/usr/obj/usr/src/sys/LOCKDOWN i386


	
>Description:
	
bsdlabel fails to display any kind of error message when opening the special
device fails.  this might lead one to believe that the label was written when
it infact wasn't.  quite annoying!
>How-To-Repeat:
	
run bsdlabel on any special device that is bound to fail (eg. a currently
mounted disk) and try to save the label.  no error messages will appear but
the label will not get written to disk.
>Fix:
apply the patch below.

(i'm not really sure what all that geom code is trying to accomplish, since
the device can't be opened...  as far as i know my system is geom but the
code path taken in successful editing seems to be the write())
	

--- bsdlabel.diff begins here ---
Index: sbin/bsdlabel/bsdlabel.c
===================================================================
RCS file: /home/ncvs/src/sbin/bsdlabel/bsdlabel.c,v
retrieving revision 1.103
diff -u -r1.103 bsdlabel.c
--- sbin/bsdlabel/bsdlabel.c	18 Oct 2003 19:32:35 -0000	1.103
+++ sbin/bsdlabel/bsdlabel.c	22 Oct 2003 18:34:16 -0000
@@ -383,6 +383,7 @@
 
 	fd = open(specname, O_RDWR);
 	if (fd < 0) {
+		warn("updated label could not be written to disk");
 		grq = gctl_get_handle();
 		gctl_ro_param(grq, "verb", -1, "write label");
 		gctl_ro_param(grq, "class", -1, "BSD");
--- bsdlabel.diff ends here ---


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: jh 
State-Changed-When: Thu Jul 1 15:55:12 UTC 2010 
State-Changed-Why:  
Is this still a problem for you? 

On 8.0: 

/dev/md1 on /mnt (ufs, local) 
# bsdlabel -w /dev/md1 
bsdlabel: Class not found 

But this is because GEOM_BSD has been changed to GEOM_PART_BSD. 
The error message is not very informative. 

On 7.3 (uses GEOM_BSD): 

# bsdlabel -w /dev/md1 
bsdlabel: Geom not found: "md0" 

Not very informative either. 

This change makes the error message more understandable for me: 

%%% 
Index: sbin/bsdlabel/bsdlabel.c 
=================================================================== 
--- sbin/bsdlabel/bsdlabel.c	(revision 209622) 
+++ sbin/bsdlabel/bsdlabel.c	(working copy) 
@@ -382,7 +382,7 @@ static int 
writelabel(void) 
{ 
uint64_t *p, sum; 
-	int i, fd; 
+	int i, fd, serrno; 
struct gctl_req *grq; 
char const *errstr; 
struct disklabel *lp = &lab; 
@@ -413,6 +413,7 @@ writelabel(void) 

fd = open(specname, O_RDWR); 
if (fd < 0) { 
+		serrno = errno; 
if (is_file) { 
warn("cannot open file %s for writing label", specname); 
return(1); 
@@ -426,7 +427,7 @@ writelabel(void) 
bootarea + labeloffset + labelsoffset * secsize); 
errstr = gctl_issue(grq); 
if (errstr != NULL) { 
-			warnx("%s", errstr); 
+			warnc(serrno, "%s", specname); 
gctl_free(grq); 
return(1); 
} 
%%% 

With the patch applied: 

# bsdlabel -w /dev/md1  
bsdlabel: /dev/md1: Operation not permitted 



Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Thu Jul 1 15:55:12 UTC 2010 
Responsible-Changed-Why:  
Track. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/58390: commit references a PR
Date: Fri, 27 Aug 2010 11:08:24 +0000 (UTC)

 Author: jh
 Date: Fri Aug 27 11:08:11 2010
 New Revision: 211873
 URL: http://svn.freebsd.org/changeset/base/211873
 
 Log:
   Don't attempt to write label with GEOM_BSD based method if the class is
   not available. This improves error reporting when bsdlabel(8) is unable
   to open a device for writing. If GEOM_BSD was unavailable, only a rather
   obscure error message "Class not found" was printed.
   
   PR:		bin/58390
   Reviewed by:	ae
   Discussed with:	marcel
   MFC after:	1 month
 
 Modified:
   head/sbin/bsdlabel/bsdlabel.c
 
 Modified: head/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- head/sbin/bsdlabel/bsdlabel.c	Fri Aug 27 10:47:17 2010	(r211872)
 +++ head/sbin/bsdlabel/bsdlabel.c	Fri Aug 27 11:08:11 2010	(r211873)
 @@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$");
  #include "pathnames.h"
  
  static void	makelabel(const char *, struct disklabel *);
 +static int	geom_bsd_available(void);
  static int	writelabel(void);
  static int	readlabel(int flag);
  static void	display(FILE *, const struct disklabel *);
 @@ -379,10 +380,33 @@ readboot(void)
  }
  
  static int
 +geom_bsd_available(void)
 +{
 +	struct gclass *class;
 +	struct gmesh mesh;
 +	int error;
 +
 +	error = geom_gettree(&mesh);
 +	if (error != 0)
 +		errc(1, error, "Cannot get GEOM tree");
 +
 +	LIST_FOREACH(class, &mesh.lg_class, lg_class) {
 +		if (strcmp(class->lg_name, "BSD") == 0) {
 +			geom_deletetree(&mesh);
 +			return (1);
 +		}
 +	}
 +
 +	geom_deletetree(&mesh);
 +
 +	return (0);
 +}
 +
 +static int
  writelabel(void)
  {
  	uint64_t *p, sum;
 -	int i, fd;
 +	int i, fd, serrno;
  	struct gctl_req *grq;
  	char const *errstr;
  	struct disklabel *lp = &lab;
 @@ -416,6 +440,13 @@ writelabel(void)
  		if (is_file) {
  			warn("cannot open file %s for writing label", specname);
  			return(1);
 +		} else
 +			serrno = errno;
 +
 +		/* Give up if GEOM_BSD is not available. */
 +		if (geom_bsd_available() == 0) {
 +			warnc(serrno, "%s", specname);
 +			return (1);
  		}
  
  		grq = gctl_get_handle();
 _______________________________________________
 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: feedback->closed 
State-Changed-By: jh 
State-Changed-When: Fri Aug 27 12:00:00 UTC 2010 
State-Changed-Why:  
Feedback timeout. r211873 should improve error reporting when GEOM_BSD 
is unavailable. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/58390: commit references a PR
Date: Sun, 26 Sep 2010 16:52:11 +0000 (UTC)

 Author: jh
 Date: Sun Sep 26 16:52:05 2010
 New Revision: 213186
 URL: http://svn.freebsd.org/changeset/base/213186
 
 Log:
   MFC r211873:
   
   Don't attempt to write label with GEOM_BSD based method if the class is
   not available. This improves error reporting when bsdlabel(8) is unable
   to open a device for writing. If GEOM_BSD was unavailable, only a rather
   obscure error message "Class not found" was printed.
   
   PR:		bin/58390
 
 Modified:
   stable/8/sbin/bsdlabel/bsdlabel.c
 Directory Properties:
   stable/8/sbin/bsdlabel/   (props changed)
 
 Modified: stable/8/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- stable/8/sbin/bsdlabel/bsdlabel.c	Sun Sep 26 14:20:09 2010	(r213185)
 +++ stable/8/sbin/bsdlabel/bsdlabel.c	Sun Sep 26 16:52:05 2010	(r213186)
 @@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$");
  #include "pathnames.h"
  
  static void	makelabel(const char *, struct disklabel *);
 +static int	geom_bsd_available(void);
  static int	writelabel(void);
  static int	readlabel(int flag);
  static void	display(FILE *, const struct disklabel *);
 @@ -379,10 +380,33 @@ readboot(void)
  }
  
  static int
 +geom_bsd_available(void)
 +{
 +	struct gclass *class;
 +	struct gmesh mesh;
 +	int error;
 +
 +	error = geom_gettree(&mesh);
 +	if (error != 0)
 +		errc(1, error, "Cannot get GEOM tree");
 +
 +	LIST_FOREACH(class, &mesh.lg_class, lg_class) {
 +		if (strcmp(class->lg_name, "BSD") == 0) {
 +			geom_deletetree(&mesh);
 +			return (1);
 +		}
 +	}
 +
 +	geom_deletetree(&mesh);
 +
 +	return (0);
 +}
 +
 +static int
  writelabel(void)
  {
  	uint64_t *p, sum;
 -	int i, fd;
 +	int i, fd, serrno;
  	struct gctl_req *grq;
  	char const *errstr;
  	struct disklabel *lp = &lab;
 @@ -416,6 +440,13 @@ writelabel(void)
  		if (is_file) {
  			warn("cannot open file %s for writing label", specname);
  			return(1);
 +		} else
 +			serrno = errno;
 +
 +		/* Give up if GEOM_BSD is not available. */
 +		if (geom_bsd_available() == 0) {
 +			warnc(serrno, "%s", specname);
 +			return (1);
  		}
  
  		grq = gctl_get_handle();
 _______________________________________________
 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"
 
>Unformatted:
