From owner-freebsd-fs@FreeBSD.ORG Tue May 3 22:05:50 2011 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 66D971065672 for ; Tue, 3 May 2011 22:05:50 +0000 (UTC) (envelope-from wmn@siberianet.ru) Received: from mail.siberianet.ru (mail.siberianet.ru [89.105.136.7]) by mx1.freebsd.org (Postfix) with ESMTP id C0DF08FC15 for ; Tue, 3 May 2011 22:05:49 +0000 (UTC) Received: from wmn.localnet (wmn.siberianet.ru [89.105.137.12]) by mail.siberianet.ru (Postfix) with ESMTPA id 612695028AE for ; Wed, 4 May 2011 05:47:58 +0800 (KRAST) From: Sergey Lobanov Organization: ISP "SiberiaNet" Date: Wed, 4 May 2011 05:47:52 +0800 User-Agent: KMail/1.13.7 (Linux/2.6.38-ARCH; KDE/4.6.2; i686; ; ) MIME-Version: 1.0 X-Length: 2409 X-UID: 18 To: freebsd-fs@freebsd.org Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201105040547.52216.wmn@siberianet.ru> Subject: fsck_ufs only in preen mode terminates with non-zero exit status trying to check absent device X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2011 22:05:50 -0000 Hello, I am trying to workaround problem in setup with md(4) file-backed images mounted in jails(8). I could not find how to automatically check file systems on md images during system boot or jail start. That is, after hard system reset (for example, because of power loss) file systems on md file-backed images are all dirty and is not auto-repaired out of the box. May be I've missed something, feel free to point me out to the documentation describing the case. Here is workaround i am trying to make: 1) md images are all added into jail fstabs so system can boot normally (because if images are in host fstab, system stops on check of such obviously absent at boot time devices). 2) I use ezjail, so we add hack into its rc-NG script which executes external script to check file systems on corresponding md images before jail start; ezjail script relies on exit status of this external script, so we can skip jail if check have been failed. 3) The script for check of md images gets jail name as parameter, greps /dev/md* rows from corresponding fstab file and tries to fsck in preen mode first and then in normal mode if first fails. And here we get problem with fsck: in preen mode it exits with non-zero status if device is not present, but if we then launch it in normal mode for the same device, it prints errors and terminates with status 0. Example script (test-fsck-ufs.sh): -------------------- #!/bin/sh rc_info="YES" . /etc/rc.subr /sbin/fsck_ufs -p /dev/md-non-existent if [ $? -ne 0 ]; then warn "Could not check in preen mode, trying normal..." /sbin/fsck_ufs -y /dev/md-non-existent || err $? "Could not check in normal mode, XXX IMAGE FILE IS CORRUPT XXX" else info "Consistent" fi -------------------- Result of execution of above script on 8.2-stable r220968 and 7.3-stable r215651: Can't stat /dev/md-non-existent: No such file or directory ./test-fsck-ufs.sh: WARNING: Could not check in preen mode, trying normal... Can't stat /dev/md-non-existent: No such file or directory Can't stat /dev/md-non-existent: No such file or directory Which is incorrect from my point of view, fsck_ffs(8) clearly states at the very end: "EXIT STATUS The fsck_ffs utility exits 0 on success, and >0 if an error occurs." I can definitely hack fsck_ffs so it will return error on such conditions, something like this (fixes my case but was not checked in normal operation, patch for releng8): ---patch start--- --- sbin/fsck_ffs/main.c.orig 2011-05-04 04:11:18.000000000 +0800 +++ sbin/fsck_ffs/main.c 2011-05-04 04:29:23.000000000 +0800 @@ -70,6 +70,7 @@ static int checkfilesys(char *filesys); static int chkdoreload(struct statfs *mntp); static struct statfs *getmntpt(const char *); +char fails = 0; int main(int argc, char *argv[]) @@ -179,6 +180,8 @@ if (returntosingle) ret = 2; + else + if (fails) ret = EEXIT; exit(ret); } @@ -373,6 +376,7 @@ case 0: if (preen) pfatal("CAN'T CHECK FILE SYSTEM."); + fails = 1; return (0); case -1: clean: ---patch end--- but may be there is some other, more sane way. Or I've just missed something, there is strong reason for such behaviour and it is a feature actually :} I am subscribed to the list so there is no need to add me to CC. -- ISP SiberiaNet System and Network Administrator