From: Nathan Scott Date: Tue, 8 Aug 2006 15:35:06 +0000 (+0000) Subject: Cleanup logprint IO patterns by making it not use the libxfs buffer cache (uses raw... X-Git-Tag: v2.9.0~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6b359b3a90176da9d49fded129a3c1d5b92f48d;p=thirdparty%2Fxfsprogs-dev.git Cleanup logprint IO patterns by making it not use the libxfs buffer cache (uses raw mode again). Merge of master-melb:xfs-cmds:26732a by kenmcd. --- diff --git a/include/libxfs.h b/include/libxfs.h index fa7cb9d6c..d4680dbae 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -262,6 +262,10 @@ extern xfs_buf_t *libxfs_getbuf (dev_t, xfs_daddr_t, int); extern void libxfs_putbuf (xfs_buf_t *); extern void libxfs_purgebuf (xfs_buf_t *); +/* Buffer (Raw) Interfaces */ +extern xfs_buf_t *libxfs_getbufr (dev_t, xfs_daddr_t, int); +extern void libxfs_putbufr (xfs_buf_t *); + extern int libxfs_bhash_size; extern int libxfs_ihash_size; diff --git a/include/libxlog.h b/include/libxlog.h index cef47cd5b..2717d38da 100644 --- a/include/libxlog.h +++ b/include/libxlog.h @@ -79,8 +79,8 @@ extern void xlog_warn(char *fmt,...); extern void xlog_exit(char *fmt,...); extern void xlog_panic(char *fmt,...); -#define xlog_get_bp(log,bbs) libxfs_getbuf(x.logdev, (xfs_daddr_t)-1, (bbs)) -#define xlog_put_bp(bp) libxfs_putbuf(bp) +#define xlog_get_bp(log,bbs) libxfs_getbufr(x.logdev, (xfs_daddr_t)-1, (bbs)) +#define xlog_put_bp(bp) libxfs_putbufr(bp) #define xlog_bread(log,blkno,bbs,bp) \ (libxfs_readbufr(x.logdev, \ (log)->l_logBBstart+(blkno), bp, (bbs), 1), 0) diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 76e0f109a..d19022f29 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -108,7 +108,7 @@ libxfs_log_clear( int sunit, int fmt) { - xfs_buf_t *buf; + xfs_buf_t *bp; int len; if (!device || !fs_uuid) @@ -120,11 +120,11 @@ libxfs_log_clear( /* then write a log record header */ len = ((version == 2) && sunit) ? BTOBB(sunit) : 2; len = MAX(len, 2); - buf = libxfs_getbuf(device, start, len); - libxfs_log_header(XFS_BUF_PTR(buf), - fs_uuid, version, sunit, fmt, next, buf); - libxfs_writebufr(buf); - libxfs_putbuf(buf); + bp = libxfs_getbufr(device, start, len); + libxfs_log_header(XFS_BUF_PTR(bp), + fs_uuid, version, sunit, fmt, next, bp); + bp->b_flags |= LIBXFS_B_DIRTY; + libxfs_putbufr(bp); return 0; } @@ -238,6 +238,60 @@ libxfs_bprint(xfs_buf_t *bp) bp->b_flags, bp->b_node.cn_count); } +static void +libxfs_brelse(struct cache_node *node) +{ + xfs_buf_t *bp = (xfs_buf_t *)node; + xfs_buf_log_item_t *bip; + extern xfs_zone_t *xfs_buf_item_zone; + + if (bp != NULL) { + if (bp->b_flags & LIBXFS_B_DIRTY) + libxfs_writebufr(bp); + bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *); + if (bip) + libxfs_zone_free(xfs_buf_item_zone, bip); + free(bp->b_addr); + bp->b_addr = NULL; + bp->b_flags = 0; + free(bp); + bp = NULL; + } +} + +static void +libxfs_initbuf(xfs_buf_t *bp, dev_t device, xfs_daddr_t bno, unsigned int bytes) +{ + bp->b_flags = 0; + bp->b_blkno = bno; + bp->b_bcount = bytes; + bp->b_dev = device; + bp->b_addr = memalign(libxfs_device_alignment(), bytes); + if (!bp->b_addr) { + fprintf(stderr, + _("%s: %s can't memalign %u bytes: %s\n"), + progname, __FUNCTION__, bytes, + strerror(errno)); + exit(1); + } +} + +xfs_buf_t * +libxfs_getbufr(dev_t device, xfs_daddr_t blkno, int len) +{ + xfs_buf_t *bp; + + bp = libxfs_zone_zalloc(xfs_buf_zone); + libxfs_initbuf(bp, device, blkno, BBTOB(len)); + return bp; +} + +void +libxfs_putbufr(xfs_buf_t *bp) +{ + libxfs_brelse((struct cache_node *)bp); +} + xfs_buf_t * libxfs_getbuf(dev_t device, xfs_daddr_t blkno, int len) { @@ -254,18 +308,7 @@ libxfs_getbuf(dev_t device, xfs_daddr_t blkno, int len) fprintf(stderr, "%s: allocated buffer, key=%llu(%llu), %p\n", __FUNCTION__, BBTOB(len), LIBXFS_BBTOOFF64(blkno), blkno, buf); #endif - bp->b_flags = 0; - bp->b_blkno = blkno; - bp->b_bcount = bytes; - bp->b_dev = device; - bp->b_addr = memalign(libxfs_device_alignment(), bytes); - if (!bp->b_addr) { - fprintf(stderr, - _("%s: %s can't memalign %d bytes: %s\n"), - progname, __FUNCTION__, (int)bytes, - strerror(errno)); - exit(1); - } + libxfs_initbuf(bp, device, blkno, bytes); } return bp; } @@ -415,27 +458,6 @@ libxfs_bflush(struct cache_node *node) libxfs_writebufr(bp); } -static void -libxfs_brelse(struct cache_node *node) -{ - xfs_buf_t *bp = (xfs_buf_t *)node; - xfs_buf_log_item_t *bip; - extern xfs_zone_t *xfs_buf_item_zone; - - if (bp != NULL) { - if (bp->b_flags & LIBXFS_B_DIRTY) - libxfs_writebufr(bp); - bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *); - if (bip) - libxfs_zone_free(xfs_buf_item_zone, bip); - free(bp->b_addr); - bp->b_addr = NULL; - bp->b_flags = 0; - free(bp); - bp = NULL; - } -} - void libxfs_bcache_purge(void) {