* [PATCH] xfs: don't hold onto reserved blocks on remount,ro
@ 2010-01-25 5:32 Dave Chinner
2010-01-25 11:44 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Dave Chinner @ 2010-01-25 5:32 UTC (permalink / raw)
To: xfs
If we hold onto reserved blocks when doing a remount,ro we end
up writing the blocks used count to disk that includes the reserved
blocks. Reserved blocks are not actually used, so this results in
the values in the superblock being incorrect.
Hence if we run xfs_check or xfs_repair -n while the filesystem is
mounted remount,ro we end up with an inconsistent filesystem being
reported. Also, running xfs_copy on the remount,ro filesystem will
result in an inconsistent image being generated.
To fix this, unreserve the blocks when doing the remount,ro, and
reserved them again on remount,rw. This way a remount,ro filesystem
will appear consistent on disk to all utilities.
Signed-off-by: Dave Chinner <david@fromorbit.com>
---
fs/xfs/linux-2.6/xfs_super.c | 28 ++++++++++++++++++++++++++++
fs/xfs/xfs_mount.h | 1 +
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 9f2e398..67001ec 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -1318,6 +1318,8 @@ xfs_fs_remount(
/* ro -> rw */
if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
+ __uint64_t resblks;
+
mp->m_flags &= ~XFS_MOUNT_RDONLY;
if (mp->m_flags & XFS_MOUNT_BARRIER)
xfs_mountfs_check_barriers(mp);
@@ -1335,11 +1337,37 @@ xfs_fs_remount(
}
mp->m_update_flags = 0;
}
+
+ /*
+ * Fill out the reserve pool if it is empty. Use the stashed
+ * value if it is non-zero, otherwise go with the default.
+ */
+ if (mp->m_resblks_ro) {
+ resblks = mp->m_resblks_ro;
+ mp->m_resblks_ro = 0;
+ } else {
+ resblks = mp->m_sb.sb_dblocks;
+ do_div(resblks, 20);
+ resblks = min_t(__uint64_t, resblks, 1024);
+ }
+ xfs_reserve_blocks(mp, &resblks, NULL);
}
/* rw -> ro */
if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
+ /*
+ * After we have synced the data but before we sync the
+ * metadata, we need to free up the reserve block pool so that
+ * the used block count in the superblock on disk is correct at
+ * the end of the remount. Stash the current reserve pool size
+ * so that if we get remounted rw, we can return it to the same
+ * size.
+ */
+ __uint64_t resblks = 0;
+
xfs_quiesce_data(mp);
+ mp->m_resblks_ro = mp->m_resblks;
+ xfs_reserve_blocks(mp, &resblks, NULL);
xfs_quiesce_attr(mp);
mp->m_flags |= XFS_MOUNT_RDONLY;
}
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index f4d1441..a3de553 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -225,6 +225,7 @@ typedef struct xfs_mount {
__uint64_t m_maxioffset; /* maximum inode offset */
__uint64_t m_resblks; /* total reserved blocks */
__uint64_t m_resblks_avail;/* available reserved blocks */
+ __uint64_t m_resblks_ro; /* reserved blks @ remount,ro */
int m_dalign; /* stripe unit */
int m_swidth; /* stripe width */
int m_sinoalign; /* stripe unit inode alignment */
--
1.6.5
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: don't hold onto reserved blocks on remount,ro
2010-01-25 5:32 [PATCH] xfs: don't hold onto reserved blocks on remount,ro Dave Chinner
@ 2010-01-25 11:44 ` Christoph Hellwig
2010-01-26 4:09 ` Dave Chinner
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2010-01-25 11:44 UTC (permalink / raw)
To: Dave Chinner; +Cc: xfs
On Mon, Jan 25, 2010 at 04:32:52PM +1100, Dave Chinner wrote:
> If we hold onto reserved blocks when doing a remount,ro we end
> up writing the blocks used count to disk that includes the reserved
> blocks. Reserved blocks are not actually used, so this results in
> the values in the superblock being incorrect.
>
> Hence if we run xfs_check or xfs_repair -n while the filesystem is
> mounted remount,ro we end up with an inconsistent filesystem being
> reported. Also, running xfs_copy on the remount,ro filesystem will
> result in an inconsistent image being generated.
>
> To fix this, unreserve the blocks when doing the remount,ro, and
> reserved them again on remount,rw. This way a remount,ro filesystem
> will appear consistent on disk to all utilities.
Looks good to me, the only thing that was rather confusing when trying
to read the patch is the m_resblks_ro field in struct xfs_mount, it's
more a m_resblks_save, as in the saved value before we modified the
block count during remount,ro.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: don't hold onto reserved blocks on remount,ro
2010-01-25 11:44 ` Christoph Hellwig
@ 2010-01-26 4:09 ` Dave Chinner
0 siblings, 0 replies; 3+ messages in thread
From: Dave Chinner @ 2010-01-26 4:09 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: xfs
On Mon, Jan 25, 2010 at 06:44:33AM -0500, Christoph Hellwig wrote:
> On Mon, Jan 25, 2010 at 04:32:52PM +1100, Dave Chinner wrote:
> > If we hold onto reserved blocks when doing a remount,ro we end
> > up writing the blocks used count to disk that includes the reserved
> > blocks. Reserved blocks are not actually used, so this results in
> > the values in the superblock being incorrect.
> >
> > Hence if we run xfs_check or xfs_repair -n while the filesystem is
> > mounted remount,ro we end up with an inconsistent filesystem being
> > reported. Also, running xfs_copy on the remount,ro filesystem will
> > result in an inconsistent image being generated.
> >
> > To fix this, unreserve the blocks when doing the remount,ro, and
> > reserved them again on remount,rw. This way a remount,ro filesystem
> > will appear consistent on disk to all utilities.
>
> Looks good to me, the only thing that was rather confusing when trying
> to read the patch is the m_resblks_ro field in struct xfs_mount, it's
> more a m_resblks_save, as in the saved value before we modified the
> block count during remount,ro.
Ok, I changed the variable name.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-26 4:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-25 5:32 [PATCH] xfs: don't hold onto reserved blocks on remount,ro Dave Chinner
2010-01-25 11:44 ` Christoph Hellwig
2010-01-26 4:09 ` Dave Chinner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox