Bug#309218: broken xfs_freeze calls in grub-install

Christoph Hellwig Christoph Hellwig <hch@lst.de>, 309218@bugs.debian.org
Sun, 15 May 2005 19:38:42 +0200


Package: grub
Version: 0.95+cvs20040624-17

grub-install calls xfs_freeze while doing write I/O to the filesystem
that is frozen.  This is a sure guarantee for deadlocking.  It's also
doing the freeze far too late, after's it's already been reading from
the block deviced directly (which it shouldn't do at all in the end,
but..)

Also it gives an odd warning about xfs_freeze segfaulting on non-XFS
filesystems which wasn't true for any version SGI released.

The patch below fixes all this:

--- /sbin/grub-install~	2005-05-11 21:08:31.214462360 +0200
+++ /sbin/grub-install	2005-05-11 21:20:08.837321736 +0200
@@ -462,6 +462,16 @@
     cp -f $file ${grubdir} || exit 1
 done
 
+# Try some black magic to make the ondisk filesystem structure on disk
+# uptodate.
+# In reality there's no defined way to make that happen, and grub shouldn't
+# dare to access a mounted block device directly.  To keep the grub developers
+# illusion, try some ways to push as much as possible to disk.
+sync
+if which xfs_freeze >/dev/null; then
+  xfs_freeze -f ${grubdir} >/dev/null 2>&1 && xfs_freeze -u ${grubdir}
+fi
+
 # Make sure that GRUB reads the same images as the host OS.
 test -n "$mkimg" && img_file=`$mkimg`
 test -n "$mklog" && log_file=`$mklog`
@@ -494,20 +504,6 @@
 # Create a safe temporary file.
 test -n "$mklog" && log_file=`$mklog`
 
-# Sync to prevent GRUB from not finding stage files (notably, on XFS)
-sync
-
-# XFS needs special magic
-xfs_frozen=false
-if which xfs_freeze > /dev/null ; then
-  cat << EOF
-Due to a bug in xfs_freeze, the following command might produce a segmentation
-fault when ${grubdir} is not in an XFS filesystem. This error is harmless and
-can be ignored.
-EOF
-  if xfs_freeze -f ${grubdir} ; then xfs_frozen=true ; fi
-fi
-
 # Now perform the installation.
 $grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
 root $root_drive
@@ -515,10 +511,6 @@
 quit
 EOF
 
-if ${xfs_frozen} ; then
-  xfs_freeze -u ${grubdir}
-fi
-
 if grep "Error [0-9]*: " $log_file >/dev/null || test $debug = yes; then
     cat $log_file 1>&2
     exit 1