xfs
[Top] [All Lists]

[PATCH 1/2] xfs_db: flush devices before exiting

To: xfs@xxxxxxxxxxx
Subject: [PATCH 1/2] xfs_db: flush devices before exiting
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Fri, 9 Nov 2012 18:02:57 +1100
In-reply-to: <1352444578-14600-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1352444578-14600-1-git-send-email-david@xxxxxxxxxxxxx>
From: Dave Chinner <dchinner@xxxxxxxxxx>

Test 287 uses xfs_db to change 32-bit project ID support while the
filesystem is unmounted. On a large filesystem the test was failing
due to the mount not seeing the feature bit in the superblock.

xfs_db uses a different address space to the filesystem when it is
mounte dby the kernel, so the only way to keep them coherent is to
ensure that all buffered data is written to disk before the other
entity tries to read it. xfs_db uses buffered IO, but does not close
the devices when it exits, thereby leaving changes it has written in
the block device cache rather than on disk. Hence when th ekernel
tries to mount the filesystem, it reads what is on disk and does not
see xfs_db's changes.

Fix this by ensuring that xfs_db flushes it's changes to disk before
it exits by caling libxfs_device_close(). This fsyncs the data and
flushes the caches to ensure that it is present on disk before
xfs_db exits.

Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx>
---
 db/init.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/db/init.c b/db/init.c
index 2a5ef2b..2a31cb8 100644
--- a/db/init.c
+++ b/db/init.c
@@ -170,7 +170,7 @@ main(
        }
        if (cmdline) {
                xfree(cmdline);
-               return exitcode;
+               goto close_devices;
        }
 
        while (!done) {
@@ -181,5 +181,13 @@ main(
                        done = command(c, v);
                doneline(input, v);
        }
+
+close_devices:
+       if (x.ddev)
+               libxfs_device_close(x.ddev);
+       if (x.logdev && x.logdev != x.ddev)
+               libxfs_device_close(x.logdev);
+       if (x.rtdev)
+               libxfs_device_close(x.rtdev);
        return exitcode;
 }
-- 
1.7.10

<Prev in Thread] Current Thread [Next in Thread>