From 8f359bc68c24ccfff3754c753a4a65d529f60b30 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sat, 3 Oct 1998 16:19:28 +0000 Subject: [PATCH] Quick fix for not being able to sync all the buffers in boot() if an ext2fs file system is mounted. The soft update changes added a check for B_DELWRI buffers. This exposed the complete brokenness of the previous quick fix for failing syncs (PR 3571, committed on 1997/08/04). Use a new buffer flag B_DIRTY and don't abuse B_DELWRI. B_DIRTY buffers are still written too late, as broken in the previous fix. This is fairly harmless, because B_DIRTY is only used for bitmap buffers and fsck.ext2 can fix up the bitmaps perfectly. Fixed a race in ULCK_BUF() (bremfree() was outside of the splbio() section). --- sys/gnu/ext2fs/ext2_linux_ialloc.c | 6 +----- sys/gnu/ext2fs/fs.h | 12 +++++++++--- sys/gnu/fs/ext2fs/ext2_linux_ialloc.c | 6 +----- sys/gnu/fs/ext2fs/fs.h | 12 +++++++++--- sys/sys/bio.h | 6 +++--- sys/sys/buf.h | 6 +++--- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/sys/gnu/ext2fs/ext2_linux_ialloc.c b/sys/gnu/ext2fs/ext2_linux_ialloc.c index 00e1a5a5e0d2..4cfb6a721dfa 100644 --- a/sys/gnu/ext2fs/ext2_linux_ialloc.c +++ b/sys/gnu/ext2fs/ext2_linux_ialloc.c @@ -56,11 +56,7 @@ void mark_buffer_dirty(struct buf *bh) int s; s = splbio(); - if (!(bh->b_flags & B_DELWRI)) { - numdirtybuffers++; - bh->b_flags |= B_DELWRI; - bh->b_flags &= ~(B_READ | B_ERROR); - } + bh->b_flags |= B_DIRTY; splx(s); } diff --git a/sys/gnu/ext2fs/fs.h b/sys/gnu/ext2fs/fs.h index 3cb4fc0095d1..17b5beb7fa16 100644 --- a/sys/gnu/ext2fs/fs.h +++ b/sys/gnu/ext2fs/fs.h @@ -168,10 +168,16 @@ extern u_char *fragtbl[]; } #define ULCK_BUF(bp) { \ + long flags; \ int s; \ s = splbio(); \ - (bp)->b_flags &= ~B_LOCKED; \ - splx(s); \ + flags = (bp)->b_flags; \ + (bp)->b_flags &= ~(B_DIRTY | B_LOCKED); \ bremfree(bp); \ - brelse(bp); \ + (bp)->b_flags |= B_BUSY; \ + splx(s); \ + if (flags & B_DIRTY) \ + bdwrite(bp); \ + else \ + brelse(bp); \ } diff --git a/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c b/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c index 00e1a5a5e0d2..4cfb6a721dfa 100644 --- a/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c +++ b/sys/gnu/fs/ext2fs/ext2_linux_ialloc.c @@ -56,11 +56,7 @@ void mark_buffer_dirty(struct buf *bh) int s; s = splbio(); - if (!(bh->b_flags & B_DELWRI)) { - numdirtybuffers++; - bh->b_flags |= B_DELWRI; - bh->b_flags &= ~(B_READ | B_ERROR); - } + bh->b_flags |= B_DIRTY; splx(s); } diff --git a/sys/gnu/fs/ext2fs/fs.h b/sys/gnu/fs/ext2fs/fs.h index 3cb4fc0095d1..17b5beb7fa16 100644 --- a/sys/gnu/fs/ext2fs/fs.h +++ b/sys/gnu/fs/ext2fs/fs.h @@ -168,10 +168,16 @@ extern u_char *fragtbl[]; } #define ULCK_BUF(bp) { \ + long flags; \ int s; \ s = splbio(); \ - (bp)->b_flags &= ~B_LOCKED; \ - splx(s); \ + flags = (bp)->b_flags; \ + (bp)->b_flags &= ~(B_DIRTY | B_LOCKED); \ bremfree(bp); \ - brelse(bp); \ + (bp)->b_flags |= B_BUSY; \ + splx(s); \ + if (flags & B_DIRTY) \ + bdwrite(bp); \ + else \ + brelse(bp); \ } diff --git a/sys/sys/bio.h b/sys/sys/bio.h index 9c9f53e0ae8d..7e702a99434d 100644 --- a/sys/sys/bio.h +++ b/sys/sys/bio.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)buf.h 8.9 (Berkeley) 3/30/95 - * $Id: buf.h,v 1.57 1998/09/24 15:02:46 luoqi Exp $ + * $Id: buf.h,v 1.58 1998/09/25 17:34:49 peter Exp $ */ #ifndef _SYS_BUF_H_ @@ -151,7 +151,7 @@ struct buf { #define B_PHYS 0x00040000 /* I/O to user memory. */ #define B_RAW 0x00080000 /* Set by physio for raw transfers. */ #define B_READ 0x00100000 /* Read buffer. */ -#define B_AVAIL3 0x00200000 /* Available flag */ +#define B_DIRTY 0x00200000 /* Needs writing later. */ #define B_RELBUF 0x00400000 /* Release VMIO buffer. */ #define B_WANTED 0x00800000 /* Process wants this buffer. */ #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ @@ -165,7 +165,7 @@ struct buf { #define B_AVAIL1 0x80000000 /* Available flag */ #define PRINT_BUF_FLAGS "\20\40avail1\37cluster\36vmio\35ram\34ordered" \ - "\33paging\32xxx\31writeinprog\30wanted\27relbuf\26avail3" \ + "\33paging\32xxx\31writeinprog\30wanted\27relbuf\26dirty" \ "\25read\24raw\23phys\22clusterok\21malloc\20nocache" \ "\17locked\16inval\15avail2\14error\13eintr\12done\11freebuf" \ "\10delwri\7call\6cache\5busy\4bad\3async\2needcommit\1age" diff --git a/sys/sys/buf.h b/sys/sys/buf.h index 9c9f53e0ae8d..7e702a99434d 100644 --- a/sys/sys/buf.h +++ b/sys/sys/buf.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)buf.h 8.9 (Berkeley) 3/30/95 - * $Id: buf.h,v 1.57 1998/09/24 15:02:46 luoqi Exp $ + * $Id: buf.h,v 1.58 1998/09/25 17:34:49 peter Exp $ */ #ifndef _SYS_BUF_H_ @@ -151,7 +151,7 @@ struct buf { #define B_PHYS 0x00040000 /* I/O to user memory. */ #define B_RAW 0x00080000 /* Set by physio for raw transfers. */ #define B_READ 0x00100000 /* Read buffer. */ -#define B_AVAIL3 0x00200000 /* Available flag */ +#define B_DIRTY 0x00200000 /* Needs writing later. */ #define B_RELBUF 0x00400000 /* Release VMIO buffer. */ #define B_WANTED 0x00800000 /* Process wants this buffer. */ #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ @@ -165,7 +165,7 @@ struct buf { #define B_AVAIL1 0x80000000 /* Available flag */ #define PRINT_BUF_FLAGS "\20\40avail1\37cluster\36vmio\35ram\34ordered" \ - "\33paging\32xxx\31writeinprog\30wanted\27relbuf\26avail3" \ + "\33paging\32xxx\31writeinprog\30wanted\27relbuf\26dirty" \ "\25read\24raw\23phys\22clusterok\21malloc\20nocache" \ "\17locked\16inval\15avail2\14error\13eintr\12done\11freebuf" \ "\10delwri\7call\6cache\5busy\4bad\3async\2needcommit\1age"