From owner-freebsd-bugs@FreeBSD.ORG Wed Jun 20 21:00:13 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 710B016A421 for ; Wed, 20 Jun 2007 21:00:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 5018013C457 for ; Wed, 20 Jun 2007 21:00:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l5KL0DEU015199 for ; Wed, 20 Jun 2007 21:00:13 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l5KL0Dk0015198; Wed, 20 Jun 2007 21:00:13 GMT (envelope-from gnats) Resent-Date: Wed, 20 Jun 2007 21:00:13 GMT Resent-Message-Id: <200706202100.l5KL0Dk0015198@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Niki Denev Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AB4CE16A468 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: misc/113889: fsck_ffs does not do mount reload when preening mounted gjournal fs X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jun 2007 21:00:13 -0000 >Number: 113889 >Category: misc >Synopsis: fsck_ffs does not do mount reload when preening mounted gjournal fs >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jun 20 21:00:12 GMT 2007 >Closed-Date: >Last-Modified: >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 unclead 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: >Unformatted: