Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 May 2011 05:47:52 +0800
From:      Sergey Lobanov <wmn@siberianet.ru>
To:        freebsd-fs@freebsd.org
Subject:   fsck_ufs only in preen mode terminates with non-zero exit status trying to check absent device
Message-ID:  <201105040547.52216.wmn@siberianet.ru>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201105040547.52216.wmn>