aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-02-15 04:35:59 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-02-21 09:38:21 +0000
commit2bfd8992c7c7301166c74931ad63d4755bb4a6c7 (patch)
tree8e4f3af63c611303bed064826ba2daf7751ba0e6
parentd485c77f203fb0f4cdc08dea5ff81631b51d8809 (diff)
downloadsrc-2bfd8992c7c7301166c74931ad63d4755bb4a6c7.tar.gz
src-2bfd8992c7c7301166c74931ad63d4755bb4a6c7.zip
vnode: move write cluster support data to inodes.
The data is only needed by filesystems that 1. use buffer cache 2. utilize clustering write support. Requested by: mjg Reviewed by: asomers (previous version), fsu (ext2 parts), mckusick Tested by: pho Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28679
-rw-r--r--sys/fs/ext2fs/ext2_vfsops.c1
-rw-r--r--sys/fs/ext2fs/ext2_vnops.c3
-rw-r--r--sys/fs/ext2fs/inode.h3
-rw-r--r--sys/fs/fuse/fuse_io.c3
-rw-r--r--sys/fs/fuse/fuse_node.c1
-rw-r--r--sys/fs/fuse/fuse_node.h2
-rw-r--r--sys/fs/msdosfs/denode.h3
-rw-r--r--sys/fs/msdosfs/msdosfs_denode.c1
-rw-r--r--sys/fs/msdosfs/msdosfs_vnops.c4
-rw-r--r--sys/kern/vfs_cluster.c85
-rw-r--r--sys/kern/vfs_subr.c1
-rw-r--r--sys/sys/buf.h16
-rw-r--r--sys/sys/vnode.h8
-rw-r--r--sys/ufs/ffs/ffs_inode.c2
-rw-r--r--sys/ufs/ffs/ffs_vfsops.c1
-rw-r--r--sys/ufs/ffs/ffs_vnops.c4
-rw-r--r--sys/ufs/ufs/inode.h3
17 files changed, 87 insertions, 54 deletions
diff --git a/sys/fs/ext2fs/ext2_vfsops.c b/sys/fs/ext2fs/ext2_vfsops.c
index a64e28186769..099d6bfec981 100644
--- a/sys/fs/ext2fs/ext2_vfsops.c
+++ b/sys/fs/ext2fs/ext2_vfsops.c
@@ -1229,6 +1229,7 @@ ext2_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
ip->i_e2fs = fs = ump->um_e2fs;
ip->i_ump = ump;
ip->i_number = ino;
+ cluster_init_vn(&ip->i_clusterw);
lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
error = insmntque(vp, mp);
diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c
index e52db1416890..e00dbc3e0adc 100644
--- a/sys/fs/ext2fs/ext2_vnops.c
+++ b/sys/fs/ext2fs/ext2_vnops.c
@@ -2313,7 +2313,8 @@ ext2_write(struct vop_write_args *ap)
} else if (xfersize + blkoffset == fs->e2fs_fsize) {
if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0) {
bp->b_flags |= B_CLUSTEROK;
- cluster_write(vp, bp, ip->i_size, seqcount, 0);
+ cluster_write(vp, &ip->i_clusterw, bp,
+ ip->i_size, seqcount, 0);
} else {
bawrite(bp);
}
diff --git a/sys/fs/ext2fs/inode.h b/sys/fs/ext2fs/inode.h
index 2077b6b276ea..2b9ec687a75c 100644
--- a/sys/fs/ext2fs/inode.h
+++ b/sys/fs/ext2fs/inode.h
@@ -44,6 +44,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/queue.h>
+#include <sys/buf.h>
#include <fs/ext2fs/ext2_extents.h>
@@ -118,6 +119,8 @@ struct inode {
};
struct ext4_extent_cache i_ext_cache; /* cache for ext4 extent */
+
+ struct vn_clusterw i_clusterw; /* Buffer clustering information */
};
/*
diff --git a/sys/fs/fuse/fuse_io.c b/sys/fs/fuse/fuse_io.c
index 3f23a35a8626..bcf6e5f601bf 100644
--- a/sys/fs/fuse/fuse_io.c
+++ b/sys/fs/fuse/fuse_io.c
@@ -870,7 +870,8 @@ again:
bp->b_flags |= B_CLUSTEROK;
SDT_PROBE2(fusefs, , io, write_biobackend_issue,
4, bp);
- cluster_write(vp, bp, filesize, seqcount, 0);
+ cluster_write(vp, &fvdat->clusterw, bp,
+ filesize, seqcount, 0);
} else {
SDT_PROBE2(fusefs, , io, write_biobackend_issue,
5, bp);
diff --git a/sys/fs/fuse/fuse_node.c b/sys/fs/fuse/fuse_node.c
index d19e49358a22..6acd1df29361 100644
--- a/sys/fs/fuse/fuse_node.c
+++ b/sys/fs/fuse/fuse_node.c
@@ -164,6 +164,7 @@ fuse_vnode_init(struct vnode *vp, struct fuse_vnode_data *fvdat,
}
vp->v_type = vtyp;
vp->v_data = fvdat;
+ cluster_init_vn(&fvdat->clusterw);
counter_u64_add(fuse_node_count, 1);
}
diff --git a/sys/fs/fuse/fuse_node.h b/sys/fs/fuse/fuse_node.h
index c92874334aa1..e5fb13d43bec 100644
--- a/sys/fs/fuse/fuse_node.h
+++ b/sys/fs/fuse/fuse_node.h
@@ -68,6 +68,7 @@
#include <sys/fnv_hash.h>
#include <sys/types.h>
#include <sys/mutex.h>
+#include <sys/buf.h>
#include "fuse_file.h"
@@ -118,6 +119,7 @@ struct fuse_vnode_data {
struct vattr cached_attrs;
uint64_t nlookup;
enum vtype vtype;
+ struct vn_clusterw clusterw;
};
/*
diff --git a/sys/fs/msdosfs/denode.h b/sys/fs/msdosfs/denode.h
index 9a4de4acbe2e..f06c11772621 100644
--- a/sys/fs/msdosfs/denode.h
+++ b/sys/fs/msdosfs/denode.h
@@ -52,6 +52,8 @@
#ifndef _FS_MSDOSFS_DENODE_H_
#define _FS_MSDOSFS_DENODE_H_
+#include <sys/buf.h>
+
/*
* This is the pc filesystem specific portion of the vnode structure.
*
@@ -142,6 +144,7 @@ struct fatcache {
*/
struct denode {
struct vnode *de_vnode; /* addr of vnode we are part of */
+ struct vn_clusterw de_clusterw; /* buffer clustering information */
u_long de_flag; /* flag bits */
u_long de_dirclust; /* cluster of the directory file containing this entry */
u_long de_diroffset; /* offset of this entry in the directory cluster */
diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c
index 158b3cdda4da..369533067ce9 100644
--- a/sys/fs/msdosfs/msdosfs_denode.c
+++ b/sys/fs/msdosfs/msdosfs_denode.c
@@ -162,6 +162,7 @@ deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset,
ldep->de_dirclust = dirclust;
ldep->de_diroffset = diroffset;
ldep->de_inode = inode;
+ cluster_init_vn(&ldep->de_clusterw);
lockmgr(nvp->v_vnlock, LK_EXCLUSIVE, NULL);
fc_purge(ldep, 0); /* init the FAT cache for this denode */
error = insmntque(nvp, mntp);
diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index 8885ac856588..5cd2c27cb46b 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -796,8 +796,8 @@ msdosfs_write(struct vop_write_args *ap)
bawrite(bp);
else if (n + croffset == pmp->pm_bpcluster) {
if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
- cluster_write(vp, bp, dep->de_FileSize,
- seqcount, 0);
+ cluster_write(vp, &dep->de_clusterw, bp,
+ dep->de_FileSize, seqcount, 0);
else
bawrite(bp);
} else
diff --git a/sys/kern/vfs_cluster.c b/sys/kern/vfs_cluster.c
index 60f22fd38764..7e328454c877 100644
--- a/sys/kern/vfs_cluster.c
+++ b/sys/kern/vfs_cluster.c
@@ -59,7 +59,7 @@ static uma_zone_t cluster_pbuf_zone;
static void cluster_init(void *);
static struct cluster_save *cluster_collectbufs(struct vnode *vp,
- struct buf *last_bp, int gbflags);
+ struct vn_clusterw *vnc, struct buf *last_bp, int gbflags);
static struct buf *cluster_rbuild(struct vnode *vp, u_quad_t filesize,
daddr_t lbn, daddr_t blkno, long size, int run, int gbflags,
struct buf *fbp);
@@ -643,8 +643,8 @@ cluster_wbuild_wb(struct vnode *vp, long size, daddr_t start_lbn, int len,
* 4. end of a cluster - asynchronously write cluster
*/
void
-cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
- int gbflags)
+cluster_write(struct vnode *vp, struct vn_clusterw *vnc, struct buf *bp,
+ u_quad_t filesize, int seqcount, int gbflags)
{
daddr_t lbn;
int maxclen, cursize;
@@ -666,12 +666,12 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
/* Initialize vnode to beginning of file. */
if (lbn == 0)
- vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
+ vnc->v_lasta = vnc->v_clen = vnc->v_cstart = vnc->v_lastw = 0;
- if (vp->v_clen == 0 || lbn != vp->v_lastw + 1 ||
- (bp->b_blkno != vp->v_lasta + btodb(lblocksize))) {
+ if (vnc->v_clen == 0 || lbn != vnc->v_lastw + 1 ||
+ (bp->b_blkno != vnc->v_lasta + btodb(lblocksize))) {
maxclen = vp->v_mount->mnt_iosize_max / lblocksize - 1;
- if (vp->v_clen != 0) {
+ if (vnc->v_clen != 0) {
/*
* Next block is not sequential.
*
@@ -688,18 +688,19 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
* later on in the buf_daemon or update daemon
* flush.
*/
- cursize = vp->v_lastw - vp->v_cstart + 1;
- if (((u_quad_t) bp->b_offset + lblocksize) != filesize ||
- lbn != vp->v_lastw + 1 || vp->v_clen <= cursize) {
+ cursize = vnc->v_lastw - vnc->v_cstart + 1;
+ if ((u_quad_t)bp->b_offset + lblocksize != filesize ||
+ lbn != vnc->v_lastw + 1 || vnc->v_clen <= cursize) {
if (!async && seqcount > 0) {
cluster_wbuild_wb(vp, lblocksize,
- vp->v_cstart, cursize, gbflags);
+ vnc->v_cstart, cursize, gbflags);
}
} else {
struct buf **bpp, **endbp;
struct cluster_save *buflist;
- buflist = cluster_collectbufs(vp, bp, gbflags);
+ buflist = cluster_collectbufs(vp, vnc, bp,
+ gbflags);
if (buflist == NULL) {
/*
* Cluster build failed so just write
@@ -725,7 +726,7 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
free(buflist, M_SEGMENT);
if (seqcount > 1) {
cluster_wbuild_wb(vp,
- lblocksize, vp->v_cstart,
+ lblocksize, vnc->v_cstart,
cursize, gbflags);
}
} else {
@@ -736,8 +737,8 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
bpp <= endbp; bpp++)
bdwrite(*bpp);
free(buflist, M_SEGMENT);
- vp->v_lastw = lbn;
- vp->v_lasta = bp->b_blkno;
+ vnc->v_lastw = lbn;
+ vnc->v_lasta = bp->b_blkno;
return;
}
}
@@ -747,27 +748,27 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
* cluster as large as possible, otherwise find size of
* existing cluster.
*/
- if ((vp->v_type == VREG) &&
- ((u_quad_t) bp->b_offset + lblocksize) != filesize &&
- (bp->b_blkno == bp->b_lblkno) &&
- (VOP_BMAP(vp, lbn, NULL, &bp->b_blkno, &maxclen, NULL) ||
- bp->b_blkno == -1)) {
+ if (vp->v_type == VREG &&
+ (u_quad_t) bp->b_offset + lblocksize != filesize &&
+ bp->b_blkno == bp->b_lblkno &&
+ (VOP_BMAP(vp, lbn, NULL, &bp->b_blkno, &maxclen,
+ NULL) != 0 || bp->b_blkno == -1)) {
bawrite(bp);
- vp->v_clen = 0;
- vp->v_lasta = bp->b_blkno;
- vp->v_cstart = lbn + 1;
- vp->v_lastw = lbn;
+ vnc->v_clen = 0;
+ vnc->v_lasta = bp->b_blkno;
+ vnc->v_cstart = lbn + 1;
+ vnc->v_lastw = lbn;
return;
}
- vp->v_clen = maxclen;
+ vnc->v_clen = maxclen;
if (!async && maxclen == 0) { /* I/O not contiguous */
- vp->v_cstart = lbn + 1;
+ vnc->v_cstart = lbn + 1;
bawrite(bp);
} else { /* Wait for rest of cluster */
- vp->v_cstart = lbn;
+ vnc->v_cstart = lbn;
bdwrite(bp);
}
- } else if (lbn == vp->v_cstart + vp->v_clen) {
+ } else if (lbn == vnc->v_cstart + vnc->v_clen) {
/*
* At end of cluster, write it out if seqcount tells us we
* are operating sequentially, otherwise let the buf or
@@ -775,11 +776,11 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
*/
bdwrite(bp);
if (seqcount > 1) {
- cluster_wbuild_wb(vp, lblocksize, vp->v_cstart,
- vp->v_clen + 1, gbflags);
+ cluster_wbuild_wb(vp, lblocksize, vnc->v_cstart,
+ vnc->v_clen + 1, gbflags);
}
- vp->v_clen = 0;
- vp->v_cstart = lbn + 1;
+ vnc->v_clen = 0;
+ vnc->v_cstart = lbn + 1;
} else if (vm_page_count_severe()) {
/*
* We are low on memory, get it going NOW
@@ -791,8 +792,8 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount,
*/
bdwrite(bp);
}
- vp->v_lastw = lbn;
- vp->v_lasta = bp->b_blkno;
+ vnc->v_lastw = lbn;
+ vnc->v_lasta = bp->b_blkno;
}
/*
@@ -1039,19 +1040,20 @@ cluster_wbuild(struct vnode *vp, long size, daddr_t start_lbn, int len,
* Plus add one additional buffer.
*/
static struct cluster_save *
-cluster_collectbufs(struct vnode *vp, struct buf *last_bp, int gbflags)
+cluster_collectbufs(struct vnode *vp, struct vn_clusterw *vnc,
+ struct buf *last_bp, int gbflags)
{
struct cluster_save *buflist;
struct buf *bp;
daddr_t lbn;
int i, j, len, error;
- len = vp->v_lastw - vp->v_cstart + 1;
+ len = vnc->v_lastw - vnc->v_cstart + 1;
buflist = malloc(sizeof(struct buf *) * (len + 1) + sizeof(*buflist),
M_SEGMENT, M_WAITOK);
buflist->bs_nchildren = 0;
buflist->bs_children = (struct buf **) (buflist + 1);
- for (lbn = vp->v_cstart, i = 0; i < len; lbn++, i++) {
+ for (lbn = vnc->v_cstart, i = 0; i < len; lbn++, i++) {
error = bread_gb(vp, lbn, last_bp->b_bcount, NOCRED,
gbflags, &bp);
if (error != 0) {
@@ -1075,3 +1077,12 @@ cluster_collectbufs(struct vnode *vp, struct buf *last_bp, int gbflags)
buflist->bs_nchildren = i + 1;
return (buflist);
}
+
+void
+cluster_init_vn(struct vn_clusterw *vnc)
+{
+ vnc->v_lasta = 0;
+ vnc->v_clen = 0;
+ vnc->v_cstart = 0;
+ vnc->v_lastw = 0;
+}
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 3e39d19666e5..3f7dae762de0 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1823,7 +1823,6 @@ freevnode(struct vnode *vp)
vp->v_unpcb = NULL;
vp->v_rdev = NULL;
vp->v_fifoinfo = NULL;
- vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
vp->v_iflag = 0;
vp->v_vflag = 0;
bo->bo_flag = 0;
diff --git a/sys/sys/buf.h b/sys/sys/buf.h
index aacad3a057d2..d6c4c7f44795 100644
--- a/sys/sys/buf.h
+++ b/sys/sys/buf.h
@@ -407,6 +407,16 @@ struct cluster_save {
struct buf **bs_children; /* List of associated buffers. */
};
+/*
+ * Vnode clustering tracker
+ */
+struct vn_clusterw {
+ daddr_t v_cstart; /* v start block of cluster */
+ daddr_t v_lasta; /* v last allocation */
+ daddr_t v_lastw; /* v last write */
+ int v_clen; /* v length of cur. cluster */
+};
+
#ifdef _KERNEL
static __inline int
@@ -571,10 +581,14 @@ void bd_speedup(void);
extern uma_zone_t pbuf_zone;
uma_zone_t pbuf_zsecond_create(const char *name, int max);
+struct vn_clusterw;
+
+void cluster_init_vn(struct vn_clusterw *vnc);
int cluster_read(struct vnode *, u_quad_t, daddr_t, long,
struct ucred *, long, int, int, struct buf **);
int cluster_wbuild(struct vnode *, long, daddr_t, int, int);
-void cluster_write(struct vnode *, struct buf *, u_quad_t, int, int);
+void cluster_write(struct vnode *, struct vn_clusterw *, struct buf *,
+ u_quad_t, int, int);
void vfs_bio_brelse(struct buf *bp, int ioflags);
void vfs_bio_bzero_buf(struct buf *bp, int base, int size);
void vfs_bio_clrbuf(struct buf *);
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 9d68f9e236f6..d71f3bfcb817 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -163,14 +163,6 @@ struct vnode {
struct lockf *v_lockf; /* Byte-level advisory lock list */
struct rangelock v_rl; /* Byte-range lock */
- /*
- * clustering stuff
- */
- daddr_t v_cstart; /* v start block of cluster */
- daddr_t v_lasta; /* v last allocation */
- daddr_t v_lastw; /* v last write */
- int v_clen; /* v length of cur. cluster */
-
u_int v_holdcnt; /* I prevents recycling. */
u_int v_usecount; /* I ref count of users */
u_short v_iflag; /* i vnode flags (see below) */
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c
index 3df7bf8e8596..5598c7ba30e8 100644
--- a/sys/ufs/ffs/ffs_inode.c
+++ b/sys/ufs/ffs/ffs_inode.c
@@ -354,7 +354,7 @@ ffs_truncate(vp, length, flags, cred)
panic("ffs_truncate: read-only filesystem");
if (IS_SNAPSHOT(ip))
ffs_snapremove(vp);
- vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
+ cluster_init_vn(&ip->i_clusterw);
osize = ip->i_size;
/*
* Lengthen the size of the file. We must ensure that the
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index 540dd02c9631..762874562082 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -2011,6 +2011,7 @@ ffs_vgetf(mp, ino, flags, vpp, ffs_flags)
ip->i_nextclustercg = -1;
ip->i_flag = fs->fs_magic == FS_UFS1_MAGIC ? 0 : IN_UFS2;
ip->i_mode = 0; /* ensure error cases below throw away vnode */
+ cluster_init_vn(&ip->i_clusterw);
#ifdef DIAGNOSTIC
ufs_init_trackers(ip);
#endif
diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index 1dfdf5182a42..686bfddcb0ea 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -976,8 +976,8 @@ ffs_write(ap)
} else if (xfersize + blkoffset == fs->fs_bsize) {
if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0) {
bp->b_flags |= B_CLUSTEROK;
- cluster_write(vp, bp, ip->i_size, seqcount,
- GB_UNMAPPED);
+ cluster_write(vp, &ip->i_clusterw, bp,
+ ip->i_size, seqcount, GB_UNMAPPED);
} else {
bawrite(bp);
}
diff --git a/sys/ufs/ufs/inode.h b/sys/ufs/ufs/inode.h
index e00a89b012d0..0169d2903108 100644
--- a/sys/ufs/ufs/inode.h
+++ b/sys/ufs/ufs/inode.h
@@ -47,6 +47,7 @@
#ifdef DIAGNOSTIC
#include <sys/stack.h>
#endif
+#include <sys/buf.h>
/*
* This must agree with the definition in <ufs/ufs/dir.h>.
@@ -115,6 +116,8 @@ struct inode {
int i_nextclustercg; /* last cg searched for cluster */
+ struct vn_clusterw i_clusterw; /* Buffer clustering information */
+
/*
* Data for extended attribute modification.
*/