From nobody@FreeBSD.org  Mon Mar 12 06:21:03 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id A53E61065672
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 12 Mar 2012 06:21:03 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 90D268FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 12 Mar 2012 06:21:03 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q2C6L2Ea078876
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 12 Mar 2012 06:21:03 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q2C6L2IY078875;
	Mon, 12 Mar 2012 06:21:02 GMT
	(envelope-from nobody)
Message-Id: <201203120621.q2C6L2IY078875@red.freebsd.org>
Date: Mon, 12 Mar 2012 06:21:02 GMT
From: Olivier Cochard-Labbe <olivier@cochard.me>
To: freebsd-gnats-submit@FreeBSD.org
Subject: growfs remove ufs label and it's no more possible to reset it with tunefs
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         165962
>Category:       kern
>Synopsis:       [ufs] growfs remove ufs label and it's no more possible to reset it with tunefs
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    trasz
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 12 06:30:10 UTC 2012
>Closed-Date:    Sun Feb 03 12:22:22 UTC 2013
>Last-Modified:  Sun Feb 03 12:22:22 UTC 2013
>Originator:     Olivier Cochard-Labbe
>Release:        9.0-RELEASE
>Organization:
BSD Router Project
>Environment:
FreeBSD laptop.bsdrp.net 9.0-RELEASE FreeBSD 9.0-RELEASE #2: Sat Jan  7 19:01:08 CET 2012     root@laptop.bsdrp.net:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
Once run growfs on a partition that had an UFS label, this label is
removed and it's no more possible to re-set it with tunefs:
tunefs -p display the label, but glabel didn't and the UFS name is not visible in /dev/ufs/.


>How-To-Repeat:
Here is how to reproduce this problem easly (tested on 8.3 and 9.0):

mdconfig -a -t malloc -s 10MB
gpart create -s mbr /dev/md0
gpart add -t freebsd -s 5MB /dev/md0
newfs -L THELABEL /dev/md0s1
glabel status | grep THELABEL
=> Label is present, now we resize the slice:
gpart resize -i 1 /dev/md0
glabel status | grep THELABEL
=> Label is still present, now we growfs the slice:
growfs /dev/md0s1
tunefs -p /dev/md0s1 | grep label
tunefs: volume label: (-L)  THELABEL
=> tunefs still see the volume label
glabel status | grep THELABEL
=> glabel didn't see the UFS label !
Ok, I will try to re-set it:
tunefs -L THELABEL /dev/md0s1
glabel status | grep THELABEL
=> Still no label
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Mar 12 07:23:27 UTC 2012 
Responsible-Changed-Why:  
sounds like something for freebsd-fs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165962 
Responsible-Changed-From-To: freebsd-fs->trasz 
Responsible-Changed-By: trasz 
Responsible-Changed-When: Mon Mar 12 18:10:32 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

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

From: =?ISO-8859-1?Q?Olivier_Cochard=2DLabb=E9?= <olivier@cochard.me>
To: bug-followup@freebsd.org, olivier@cochard.me
Cc: ivoras@freebsd.org
Subject: Re: kern/165962: [ufs] growfs remove ufs label and it&#39;s no more
 possible to reset it with tunefs
Date: Sat, 31 Mar 2012 08:28:57 +0200

 --047d7b338ed7a5e73104bc84139a
 Content-Type: text/plain; charset=ISO-8859-1
 
 Hi,
 
 here is another idea for avoiding this problem (proposed by ivoras@).
 In place of fixing growfs for a correct file system description in the
 superblock, the idea is "to remove the file system size checks
 from geom_label_ufs".
 I've applied and test this patch on FreeBSD 8.3-RC2 with success: Now
 using growfs didn't prevent the geom_label_ufs usage.
 
 Regards,
 
 Olivier
 
 --047d7b338ed7a5e73104bc84139a
 Content-Type: text/plain; charset=US-ASCII; name="g_label_ufs.patch.txt"
 Content-Disposition: attachment; filename="g_label_ufs.patch.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_h0ga4qba0
 
 LS0tIHN5cy9nZW9tL2xhYmVsL2dfbGFiZWxfdWZzLmMub3JpZwkyMDEyLTAzLTMxIDA2OjAwOjQ5
 LjAwMDAwMDAwMCArMDIwMAorKysgc3lzL2dlb20vbGFiZWwvZ19sYWJlbF91ZnMuYwkyMDEyLTAz
 LTMxIDA2OjAzOjExLjAwMDAwMDAwMCArMDIwMApAQCAtODEsMTIgKzgxLDEwIEBACiAJCWZzID0g
 KHN0cnVjdCBmcyAqKWdfcmVhZF9kYXRhKGNwLCBzdXBlcmJsb2NrLCBTQkxPQ0tTSVpFLCBOVUxM
 KTsKIAkJaWYgKGZzID09IE5VTEwpCiAJCQljb250aW51ZTsKLQkJLyogQ2hlY2sgZm9yIG1hZ2lj
 IGFuZCBtYWtlIHN1cmUgdGhpbmdzIGFyZSB0aGUgcmlnaHQgc2l6ZSAqLwotCQlpZiAoZnMtPmZz
 X21hZ2ljID09IEZTX1VGUzFfTUFHSUMgJiYgZnMtPmZzX2ZzaXplID4gMCAmJgotCQkgICAgcHAt
 Pm1lZGlhc2l6ZSAvIGZzLT5mc19mc2l6ZSA9PSBmcy0+ZnNfb2xkX3NpemUpIHsKKwkJLyogQ2hl
 Y2sgZm9yIG1hZ2ljICovCisJCWlmIChmcy0+ZnNfbWFnaWMgPT0gRlNfVUZTMV9NQUdJQyAmJiBm
 cy0+ZnNfZnNpemUgPiAwKSB7CiAJCSAgICAJLyogVmFsaWQgVUZTMS4gKi8KLQkJfSBlbHNlIGlm
 IChmcy0+ZnNfbWFnaWMgPT0gRlNfVUZTMl9NQUdJQyAmJiBmcy0+ZnNfZnNpemUgPiAwICYmCi0J
 CSAgICBwcC0+bWVkaWFzaXplIC8gZnMtPmZzX2ZzaXplID09IGZzLT5mc19zaXplKSB7CisJCX0g
 ZWxzZSBpZiAoZnMtPmZzX21hZ2ljID09IEZTX1VGUzJfTUFHSUMgJiYgZnMtPmZzX2ZzaXplID4g
 MCkgewogCQkgICAgCS8qIFZhbGlkIFVGUzIuICovCiAJCX0gZWxzZSB7CiAJCQlnX2ZyZWUoZnMp
 Owo=
 --047d7b338ed7a5e73104bc84139a--
State-Changed-From-To: open->closed 
State-Changed-By: trasz 
State-Changed-When: Thu May 24 16:48:51 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165962: commit references a PR
Date: Thu, 24 May 2012 16:48:47 +0000 (UTC)

 Author: trasz
 Date: Thu May 24 16:48:33 2012
 New Revision: 235918
 URL: http://svn.freebsd.org/changeset/base/235918
 
 Log:
   Make g_label(4) ignore provider size when looking for UFS labels.
   Without it, it fails to create labels for filesystems resized by
   growfs(8).
   
   PR:		kern/165962
   Submitted by:	Olivier Cochard-Labbe <olivier at cochard dot me>
 
 Modified:
   head/sys/geom/label/g_label_ufs.c
 
 Modified: head/sys/geom/label/g_label_ufs.c
 ==============================================================================
 --- head/sys/geom/label/g_label_ufs.c	Thu May 24 16:41:26 2012	(r235917)
 +++ head/sys/geom/label/g_label_ufs.c	Thu May 24 16:48:33 2012	(r235918)
 @@ -81,12 +81,10 @@ g_label_ufs_taste_common(struct g_consum
  		fs = (struct fs *)g_read_data(cp, superblock, SBLOCKSIZE, NULL);
  		if (fs == NULL)
  			continue;
 -		/* Check for magic and make sure things are the right size */
 -		if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0 &&
 -		    pp->mediasize / fs->fs_fsize == fs->fs_old_size) {
 +		/* Check for magic */
 +		if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0) {
  		    	/* Valid UFS1. */
 -		} else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 &&
 -		    pp->mediasize / fs->fs_fsize == fs->fs_size) {
 +		} else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0) {
  		    	/* Valid UFS2. */
  		} else {
  			g_free(fs);
 _______________________________________________
 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: closed->open 
State-Changed-By: trasz 
State-Changed-When: Fri May 25 09:53:12 UTC 2012 
State-Changed-Why:  
Erm, not so fast.  The mediasize check was there for a reason. 


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

From: Edward Napierala <trasz@FreeBSD.org>
To: bug-followup@FreeBSD.org, olivier@cochard.me
Cc:  
Subject: Re: kern/165962: [ufs] growfs remove ufs label and it's no more
 possible to reset it with tunefs
Date: Sat, 1 Sep 2012 14:25:58 +0200

 Attached below is what I believe to be a proper fix.  This patch
 requires growfs(8) to be rebuilt
 and rerun on the problematic filesystem.  I intend to commit it as
 soon as I get a review from Kirk.
 
 
 Index: growfs.c
 ===================================================================
 --- growfs.c    (revision 239980)
 +++ growfs.c    (working copy)
 @@ -582,27 +582,6 @@ updjcg(int cylno, time_t modtime, int fsi, int fso
         memcpy((void *)&cgun1, (void *)&cgun2, sizeof(cgun2));
 
         /*
 -        * If the cylinder group had already its new final size almost
 -        * nothing is to be done ... except:
 -        * For some reason the value of cg_ncyl in the last cylinder group has
 -        * to be zero instead of fs_cpg. As this is now no longer the last
 -        * cylinder group we have to change that value now to fs_cpg.
 -        */
 -
 -       if (cgbase(&osblock, cylno + 1) == osblock.fs_size) {
 -               if (sblock.fs_magic == FS_UFS1_MAGIC)
 -                       acg.cg_old_ncyl = sblock.fs_old_cpg;
 -
 -               wtfs(fsbtodb(&sblock, cgtod(&sblock, cylno)),
 -                   (size_t)sblock.fs_cgsize, (void *)&acg, fso, Nflag);
 -               DBG_PRINT0("jcg written\n");
 -               DBG_DUMP_CG(&sblock, "new joining cg", &acg);
 -
 -               DBG_LEAVE;
 -               return;
 -       }
 -
 -       /*         * Set up some variables needed later.
          */
         cbase = cgbase(&sblock, cylno);
 @@ -625,7 +604,10 @@ updjcg(int cylno, time_t modtime, int fsi, int fso
         acg.cg_time = modtime;
         if ((unsigned)cylno == sblock.fs_ncg - 1) {
                 /*
 -                * This is still the last cylinder group.
 +                * For some reason the value of cg_old_ncyl in the last
 +                * cylinder group has to be zero instead of fs_cpg.
 +                * As this is now no longer the last cylinder group
 +                * we have to change that value now to fs_cpg.
                  */
                 if (sblock.fs_magic == FS_UFS1_MAGIC)
                         acg.cg_old_ncyl =
 
 @@ -1601,9 +1583,10 @@ main(int argc, char **argv)
                 sblock.fs_ncg--;
                 if (sblock.fs_magic == FS_UFS1_MAGIC)
                         sblock.fs_old_ncyl = sblock.fs_ncg * sblock.fs_old_cpg;
 +#ifdef FS_DEBUG
                 printf("Warning: %jd sector(s) cannot be allocated.\n",
                     (intmax_t)fsbtodb(&sblock, sblock.fs_size % sblock.fs_fpg));
 -               sblock.fs_size = sblock.fs_ncg * sblock.fs_fpg;
 +#endif
         }
 
         /*

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/165962: commit references a PR
Date: Sun,  3 Feb 2013 12:17:58 +0000 (UTC)

 Author: trasz
 Date: Sun Feb  3 12:17:49 2013
 New Revision: 246284
 URL: http://svnweb.freebsd.org/changeset/base/246284
 
 Log:
   MFC r242379:
   
   Fix problem with geom_label(4) not recognizing UFS labels on filesystems
   extended using growfs(8).  The problem here is that geom_label checks if
   the filesystem size recorded in UFS superblock is equal to the provider
   (i.e. device) size.  This check cannot be removed due to backward
   compatibility.  On the other hand, in most cases growfs(8) cannot set
   fs_size in the superblock to match the provider size, because, differently
   from newfs(8), it cannot recompute cylinder group sizes.
   
   To fix this problem, add another superblock field, fs_providersize, used
   only for this purpose.  The geom_label(4) will attach if either fs_size
   (filesystem created with newfs(8)) or fs_providersize (filesystem expanded
   using growfs(8)) matches the device size.
   
   PR:		kern/165962
   Reviewed by:	mckusick
   Sponsored by:	FreeBSD Foundation
 
 Modified:
   stable/9/sbin/dumpfs/dumpfs.c
   stable/9/sbin/growfs/growfs.c
   stable/9/sbin/newfs/mkfs.c
   stable/9/sbin/newfs/newfs.c
   stable/9/sbin/newfs/newfs.h
   stable/9/sys/geom/label/g_label_ufs.c
   stable/9/sys/ufs/ffs/fs.h
 Directory Properties:
   stable/9/sbin/dumpfs/   (props changed)
   stable/9/sbin/growfs/   (props changed)
   stable/9/sbin/newfs/   (props changed)
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sbin/dumpfs/dumpfs.c
 ==============================================================================
 --- stable/9/sbin/dumpfs/dumpfs.c	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sbin/dumpfs/dumpfs.c	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -277,8 +277,9 @@ dumpfs(const char *name)
  		printf("unknown flags (%#x)", fsflags);
  	putchar('\n');
  	printf("fsmnt\t%s\n", afs.fs_fsmnt);
 -	printf("volname\t%s\tswuid\t%ju\n",
 -		afs.fs_volname, (uintmax_t)afs.fs_swuid);
 +	printf("volname\t%s\tswuid\t%ju\tprovidersize\t%ju\n",
 +		afs.fs_volname, (uintmax_t)afs.fs_swuid,
 +		(uintmax_t)afs.fs_providersize);
  	printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
  	afs.fs_csp = calloc(1, afs.fs_cssize);
  	if (bread(&disk, fsbtodb(&afs, afs.fs_csaddr), afs.fs_csp, afs.fs_cssize) == -1)
 
 Modified: stable/9/sbin/growfs/growfs.c
 ==============================================================================
 --- stable/9/sbin/growfs/growfs.c	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sbin/growfs/growfs.c	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -1504,6 +1504,7 @@ main(int argc, char **argv)
  	}
  
  	sblock.fs_size = dbtofsb(&osblock, size / DEV_BSIZE);
 +	sblock.fs_providersize = dbtofsb(&osblock, mediasize / DEV_BSIZE);
  
  	/*
  	 * Are we really growing?
 
 Modified: stable/9/sbin/newfs/mkfs.c
 ==============================================================================
 --- stable/9/sbin/newfs/mkfs.c	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sbin/newfs/mkfs.c	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -263,6 +263,7 @@ restart:
  	}
  	sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / sectorsize);
  	sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
 +	sblock.fs_providersize = dbtofsb(&sblock, mediasize / sectorsize);
  
  	/*
  	 * Before the filesystem is finally initialized, mark it
 
 Modified: stable/9/sbin/newfs/newfs.c
 ==============================================================================
 --- stable/9/sbin/newfs/newfs.c	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sbin/newfs/newfs.c	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -94,6 +94,7 @@ int	lflag;			/* enable multilabel for fi
  int	nflag;			/* do not create .snap directory */
  int	tflag;			/* enable TRIM */
  intmax_t fssize;		/* file system size */
 +off_t	mediasize;		/* device size */
  int	sectorsize;		/* bytes/sector */
  int	realsectorsize;		/* bytes/sector in hardware */
  int	fsize = 0;		/* fragment size */
 @@ -135,7 +136,6 @@ main(int argc, char *argv[])
  	char *cp, *special;
  	intmax_t reserved;
  	int ch, i, rval;
 -	off_t mediasize;
  	char part_name;		/* partition name, default to full disk */
  
  	part_name = 'c';
 
 Modified: stable/9/sbin/newfs/newfs.h
 ==============================================================================
 --- stable/9/sbin/newfs/newfs.h	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sbin/newfs/newfs.h	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -87,6 +87,7 @@ extern int	lflag;		/* enable multilabel 
  extern int	nflag;		/* do not create .snap directory */
  extern int	tflag;		/* enable TRIM */
  extern intmax_t	fssize;		/* file system size */
 +extern off_t	mediasize;	/* device size */
  extern int	sectorsize;	/* bytes/sector */
  extern int	realsectorsize;	/* bytes/sector in hardware*/
  extern int	fsize;		/* fragment size */
 
 Modified: stable/9/sys/geom/label/g_label_ufs.c
 ==============================================================================
 --- stable/9/sys/geom/label/g_label_ufs.c	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sys/geom/label/g_label_ufs.c	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -86,7 +86,8 @@ g_label_ufs_taste_common(struct g_consum
  		    pp->mediasize / fs->fs_fsize == fs->fs_old_size) {
  		    	/* Valid UFS1. */
  		} else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 &&
 -		    pp->mediasize / fs->fs_fsize == fs->fs_size) {
 +		    ((pp->mediasize / fs->fs_fsize == fs->fs_size) ||
 +		    (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) {
  		    	/* Valid UFS2. */
  		} else {
  			g_free(fs);
 
 Modified: stable/9/sys/ufs/ffs/fs.h
 ==============================================================================
 --- stable/9/sys/ufs/ffs/fs.h	Sun Feb  3 10:26:24 2013	(r246283)
 +++ stable/9/sys/ufs/ffs/fs.h	Sun Feb  3 12:17:49 2013	(r246284)
 @@ -332,7 +332,8 @@ struct fs {
  	int32_t	 fs_old_cpc;		/* cyl per cycle in postbl */
  	int32_t	 fs_maxbsize;		/* maximum blocking factor permitted */
  	int64_t	 fs_unrefs;		/* number of unreferenced inodes */
 -	int64_t	 fs_sparecon64[16];	/* old rotation block list head */
 +	int64_t  fs_providersize;	/* size of underlying GEOM provider */
 +	int64_t	 fs_sparecon64[15];	/* old rotation block list head */
  	int64_t	 fs_sblockloc;		/* byte offset of standard superblock */
  	struct	csum_total fs_cstotal;	/* (u) cylinder summary information */
  	ufs_time_t fs_time;		/* last time written */
 _______________________________________________
 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: trasz 
State-Changed-When: Sun Feb 3 12:22:20 UTC 2013 
State-Changed-Why:  
Fixed in 9-STABLE. 

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