From nobody@FreeBSD.org  Wed Jun 20 20:55:05 2007
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 AB4CE16A468
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Jun 2007 20:55:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id C5BD013C45B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Jun 2007 20:55:03 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l5KKt3hX059715
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Jun 2007 20:55:03 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l5KKt3Ml059714;
	Wed, 20 Jun 2007 20:55:03 GMT
	(envelope-from nobody)
Message-Id: <200706202055.l5KKt3Ml059714@www.freebsd.org>
Date: Wed, 20 Jun 2007 20:55:03 GMT
From: Niki Denev <niki@totalterror.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fsck_ffs does not do mount reload when preening mounted gjournal fs
X-Send-Pr-Version: www-3.0

>Number:         113889
>Category:       bin
>Synopsis:       [patch] fsck(8): fsck_ffs does not do mount reload when preening mounted gjournal fs
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 20 21:00:12 GMT 2007
>Closed-Date:    Fri Aug 10 06:30:38 GMT 2007
>Last-Modified:  Fri Aug 10 06:40:01 GMT 2007
>Originator:     Niki Denev
>Release:        7.0-CURRENT
>Organization:
>Environment:
FreeBSD nomad.totalterror.net 7.0-CURRENT FreeBSD 7.0-CURRENT #7: Wed Jun 20 02:07:10 UTC 2007 root@nomad.totalterror.net:/usr/obj/usr/src/sys/PCGU3 i386
>Description:
When using a gjournaled ffs as root filesystem and it has been marked
unclean due to power failure, etc. on the next reboot fsck_ffs in preed
mode will try to do the minimal garbage collection needed for gjournaled
filesystems and mark it clean. The problem is when this is root filesystem,
as it is already mounted read-only and to propagate the changes to the
filesystem (being marked clean) fsck needs to do MNT_RELOAD so the
superblock can be re-read from the disk, otherwise the kernel complains
that the filesystem is still dirty, regardless of the fact that on-disk
it is already checked and marked clean.
>How-To-Repeat:
Unplug your power while using gjournaled ffs as root filesystem, and then
on the next boot r/w remount after fsck will fail and you will be dropped
to shell to do manual fsck.
>Fix:
The attached patch works for me, and makes two of my machines startup
normally when booted with unclean root filesystems.

Patch attached with submission follows:

--- src/sbin/fsck_ffs/main.c.orig	Wed Jun 20 22:55:58 2007
+++ src/sbin/fsck_ffs/main.c	Wed Jun 20 23:42:03 2007
@@ -67,6 +67,7 @@
 static void usage(void) __dead2;
 static int argtoi(int flag, const char *req, const char *str, int base);
 static int checkfilesys(char *filesys);
+static int chkdoreload(struct statfs *mntp);
 static struct statfs *getmntpt(const char *);
 
 int
@@ -253,7 +254,10 @@
 			}
 			if ((sblock.fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) == 0) {
 				gjournal_check(filesys);
-				exit(0);
+				ret = chkdoreload(mntp);
+				if (ret == 0)
+					exit(0);
+				exit(4);
 			} else {
 				pfatal("UNEXPECTED INCONSISTENCY, %s\n",
 				    "CANNOT RUN FAST FSCK\n");
@@ -483,29 +487,45 @@
 		printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
 	if (rerun)
 		printf("\n***** PLEASE RERUN FSCK *****\n");
-	if (mntp != NULL) {
-		/*
-		 * We modified a mounted file system.  Do a mount update on
-		 * it unless it is read-write, so we can continue using it
-		 * as safely as possible.
-		 */
-		if (mntp->f_flags & MNT_RDONLY) {
-			args.fspec = 0;
-			args.export.ex_flags = 0;
-			args.export.ex_root = 0;
-			ret = mount("ufs", mntp->f_mntonname,
-			    mntp->f_flags | MNT_UPDATE | MNT_RELOAD, &args);
-			if (ret == 0)
-				return (0);
-			pwarn("mount reload of '%s' failed: %s\n\n",
-			    mntp->f_mntonname, strerror(errno));
-		}
+	ret = chkdoreload(mntp);
+	if (ret) {
 		if (!fsmodified)
 			return (0);
 		if (!preen)
 			printf("\n***** REBOOT NOW *****\n");
 		sync();
 		return (4);
+	}
+	return (0);
+}
+
+static int
+chkdoreload(struct statfs *mntp)
+{
+	struct ufs_args args;
+	int ret;
+
+	if (mntp == NULL)
+		return (0);
+	/*
+	 * We modified a mounted file system.  Do a mount update on
+	 * it unless it is read-write, so we can continue using it
+	 * as safely as possible.
+	 */
+	if (mntp->f_flags & MNT_RDONLY) {
+		memset(&args, 0, sizeof args);
+		/*
+		 * args.fspec = 0;
+		 * args.export.ex_flags = 0;
+		 * args.export.ex_root = 0;
+		 */
+		ret = mount("ufs", mntp->f_mntonname,
+		    mntp->f_flags | MNT_UPDATE | MNT_RELOAD, &args);
+		if (ret == 0)
+			return (0);
+		pwarn("mount reload of '%s' failed: %s\n\n",
+		    mntp->f_mntonname, strerror(errno));
+		return (1);
 	}
 	return (0);
 }


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: Thu Aug 9 13:01:23 UTC 2007 
Responsible-Changed-Why:  
I'll take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=113889 
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: Fri Aug 10 06:30:10 UTC 2007 
State-Changed-Why:  
Patch committed to HEAD, thank you! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/113889: commit references a PR
Date: Fri, 10 Aug 2007 06:30:02 +0000 (UTC)

 pjd         2007-08-10 06:29:54 UTC
 
   FreeBSD src repository
 
   Modified files:
     sbin/fsck_ffs        main.c 
   Log:
   Fix fscking gjournaled root file system: root file system is already mounted
   read-only, so we can't simply exit right after calling gjournal_check(),
   instead we need to ask about super block reload.
   
   Submitted by:   Niki Denev <niki@totalterror.net>
   PR:             misc/113889
   Approved by:    re (kensmith)
   
   Revision  Changes    Path
   1.46      +36 -19    src/sbin/fsck_ffs/main.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:
