diff --git sbin/tunefs/tunefs.c sbin/tunefs/tunefs.c index 08c127d..aee33fb 100644 --- sbin/tunefs/tunefs.c +++ sbin/tunefs/tunefs.c @@ -688,6 +688,19 @@ journal_findfile(void) return (0); } +static void +dir_clear_block(char *block, off_t off) +{ + struct direct *dp; + + for (; off < sblock.fs_bsize; off += DIRBLKSIZ) { + dp = (struct direct *)&block[off]; + dp->d_ino = 0; + dp->d_reclen = DIRBLKSIZ; + dp->d_type = DT_UNKNOWN; + } +} + /* * Insert the journal at inode 'ino' into directory blk 'blk' at the first * free offset of 'off'. DIRBLKSIZ blocks after off are initialized as @@ -710,13 +723,7 @@ dir_insert(ufs2_daddr_t blk, off_t off, ino_t ino) dp->d_type = DT_REG; dp->d_namlen = strlen(SUJ_FILE); bcopy(SUJ_FILE, &dp->d_name, strlen(SUJ_FILE)); - off += DIRBLKSIZ; - for (; off < sblock.fs_bsize; off += DIRBLKSIZ) { - dp = (struct direct *)&block[off]; - dp->d_ino = 0; - dp->d_reclen = DIRBLKSIZ; - dp->d_type = DT_UNKNOWN; - } + dir_clear_block(block, off + DIRBLKSIZ); if (bwrite(&disk, fsbtodb(&sblock, blk), block, sblock.fs_bsize) <= 0) { warn("Failed to write dir block"); return (-1); @@ -733,16 +740,19 @@ dir_extend(ufs2_daddr_t blk, ufs2_daddr_t nblk, off_t size, ino_t ino) { char block[MAXBSIZE]; - if (bread(&disk, fsbtodb(&sblock, blk), block, size) <= 0) { + if (bread(&disk, fsbtodb(&sblock, blk), block, + roundup(size, sblock.fs_fsize)) <= 0) { warn("Failed to read dir block"); return (-1); } - if (bwrite(&disk, fsbtodb(&sblock, nblk), block, size) <= 0) { + dir_clear_block(block, size); + if (bwrite(&disk, fsbtodb(&sblock, nblk), block, sblock.fs_bsize) + <= 0) { warn("Failed to write dir block"); return (-1); } - return dir_insert(nblk, size, ino); + return (dir_insert(nblk, size, ino)); } /* diff --git sys/ufs/ffs/ffs_softdep.c sys/ufs/ffs/ffs_softdep.c index 60d4600..6373dcf 100644 --- sys/ufs/ffs/ffs_softdep.c +++ sys/ufs/ffs/ffs_softdep.c @@ -747,7 +747,7 @@ static void handle_written_jnewblk(struct jnewblk *); static void handle_written_jfreeblk(struct jfreeblk *); static void handle_written_jfreefrag(struct jfreefrag *); static void complete_jseg(struct jseg *); -static void jseg_write(struct fs *, struct jblocks *, struct jseg *, +static void jseg_write(struct ufsmount *ump, struct jblocks *, struct jseg *, uint8_t *); static void jaddref_write(struct jaddref *, struct jseg *, uint8_t *); static void jremref_write(struct jremref *, struct jseg *, uint8_t *); @@ -886,7 +886,8 @@ static void handle_jwork(struct workhead *); static struct mkdir *setup_newdir(struct diradd *, ino_t, ino_t, struct buf *, struct mkdir **); static struct jblocks *jblocks_create(void); -static ufs2_daddr_t jblocks_alloc(struct jblocks *, int, int *); +static ufs2_daddr_t jblocks_alloc(struct ufsmount *, struct jblocks *, int, + int *); static void jblocks_free(struct jblocks *, struct mount *, int); static void jblocks_destroy(struct jblocks *); static void jblocks_add(struct jblocks *, ufs2_daddr_t, int); @@ -2135,7 +2136,8 @@ jblocks_create(void) } static ufs2_daddr_t -jblocks_alloc(jblocks, bytes, actual) +jblocks_alloc(ump, jblocks, bytes, actual) + struct ufsmount *ump; struct jblocks *jblocks; int bytes; int *actual; @@ -2145,7 +2147,7 @@ jblocks_alloc(jblocks, bytes, actual) int freecnt; int blocks; - blocks = bytes / DEV_BSIZE; + blocks = bytes / ump->um_devvp->v_bufobj.bo_bsize; jext = &jblocks->jb_extent[jblocks->jb_head]; freecnt = jext->je_blocks - jblocks->jb_off; if (freecnt == 0) { @@ -2157,7 +2159,7 @@ jblocks_alloc(jblocks, bytes, actual) } if (freecnt > blocks) freecnt = blocks; - *actual = freecnt * DEV_BSIZE; + *actual = freecnt * ump->um_devvp->v_bufobj.bo_bsize; daddr = jext->je_daddr + jblocks->jb_off; jblocks->jb_off += freecnt; jblocks->jb_free -= freecnt; @@ -2172,7 +2174,7 @@ jblocks_free(jblocks, mp, bytes) int bytes; { - jblocks->jb_free += bytes / DEV_BSIZE; + jblocks->jb_free += bytes / VFSTOUFS(mp)->um_devvp->v_bufobj.bo_bsize; if (jblocks->jb_suspended) worklist_speedup(); wakeup(jblocks); @@ -2422,7 +2424,8 @@ journal_space(ump, thresh) thresh = jblocks->jb_min; else thresh = jblocks->jb_low; - avail = (ump->softdep_on_journal * JREC_SIZE) / DEV_BSIZE; + avail = (ump->softdep_on_journal * JREC_SIZE) / + ump->um_devvp->v_bufobj.bo_bsize; avail = jblocks->jb_free - avail; return (avail > thresh); @@ -2555,8 +2558,8 @@ softdep_prelink(dvp, vp) } static void -jseg_write(fs, jblocks, jseg, data) - struct fs *fs; +jseg_write(ump, jblocks, jseg, data) + struct ufsmount *ump; struct jblocks *jblocks; struct jseg *jseg; uint8_t *data; @@ -2567,9 +2570,9 @@ jseg_write(fs, jblocks, jseg, data) rec->jsr_seq = jseg->js_seq; rec->jsr_oldest = jblocks->jb_oldestseq; rec->jsr_cnt = jseg->js_cnt; - rec->jsr_blocks = jseg->js_size / DEV_BSIZE; + rec->jsr_blocks = jseg->js_size / ump->um_devvp->v_bufobj.bo_bsize; rec->jsr_crc = 0; - rec->jsr_time = fs->fs_mtime; + rec->jsr_time = ump->um_fs->fs_mtime; } static inline void @@ -2719,19 +2722,21 @@ softdep_process_journal(mp, flags) int size; int cnt; int off; + int devbsize; if ((mp->mnt_kern_flag & MNTK_SUJ) == 0) return; ump = VFSTOUFS(mp); fs = ump->um_fs; jblocks = ump->softdep_jblocks; + devbsize = ump->um_devvp->v_bufobj.bo_bsize; /* * We write anywhere between a disk block and fs block. The upper * bound is picked to prevent buffer cache fragmentation and limit * processing time per I/O. */ - jrecmin = (DEV_BSIZE / JREC_SIZE) - 1; /* -1 for seg header */ - jrecmax = (fs->fs_bsize / DEV_BSIZE) * jrecmin; + jrecmin = (devbsize / JREC_SIZE) - 1; /* -1 for seg header */ + jrecmax = (fs->fs_bsize / devbsize) * jrecmin; segwritten = 0; while ((cnt = ump->softdep_on_journal) != 0) { /* @@ -2786,7 +2791,7 @@ softdep_process_journal(mp, flags) */ cnt = ump->softdep_on_journal; if (cnt < jrecmax) - size = howmany(cnt, jrecmin) * DEV_BSIZE; + size = howmany(cnt, jrecmin) * devbsize; else size = fs->fs_bsize; /* @@ -2794,9 +2799,10 @@ softdep_process_journal(mp, flags) * for truncation of the requested size if enough contiguous * space was not available. */ - bp->b_blkno = jblocks_alloc(jblocks, size, &size); + bp->b_blkno = jblocks_alloc(ump, jblocks, size, &size) * + btodb(devbsize); bp->b_lblkno = bp->b_blkno; - bp->b_offset = bp->b_blkno * DEV_BSIZE; + bp->b_offset = bp->b_blkno * devbsize; bp->b_bcount = size; bp->b_bufobj = &ump->um_devvp->v_bufobj; bp->b_flags &= ~B_INVAL; @@ -2806,7 +2812,7 @@ softdep_process_journal(mp, flags) * sequence number to it and link it in-order. */ cnt = MIN(ump->softdep_on_journal, - (size / DEV_BSIZE) * jrecmin); + (size / devbsize) * jrecmin); jseg->js_buf = bp; jseg->js_cnt = cnt; jseg->js_refs = cnt + 1; /* Self ref. */ @@ -2825,8 +2831,8 @@ softdep_process_journal(mp, flags) while ((wk = LIST_FIRST(&ump->softdep_journal_pending)) != NULL) { /* Place a segment header on every device block. */ - if ((off % DEV_BSIZE) == 0) { - jseg_write(fs, jblocks, jseg, data); + if ((off % devbsize) == 0) { + jseg_write(ump, jblocks, jseg, data); off += JREC_SIZE; data = bp->b_data + off; }