MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cluster_read

Function cluster_read

freebsd/kern/vfs_cluster.c:101–343  ·  view source on GitHub ↗

* Read data to a buf, including read-ahead if we find this to be beneficial. * cluster_read replaces bread. */

Source from the content-addressed store, hash-verified

99 * cluster_read replaces bread.
100 */
101int
102cluster_read(struct vnode *vp, u_quad_t filesize, daddr_t lblkno, long size,
103 struct ucred *cred, long totread, int seqcount, int gbflags,
104 struct buf **bpp)
105{
106 struct buf *bp, *rbp, *reqbp;
107 struct bufobj *bo;
108 struct thread *td;
109 daddr_t blkno, origblkno;
110 int maxra, racluster;
111 int error, ncontig;
112 int i;
113
114 error = 0;
115 td = curthread;
116 bo = &vp->v_bufobj;
117 if (!unmapped_buf_allowed)
118 gbflags &= ~GB_UNMAPPED;
119
120 /*
121 * Try to limit the amount of read-ahead by a few
122 * ad-hoc parameters. This needs work!!!
123 */
124 racluster = vp->v_mount->mnt_iosize_max / size;
125 maxra = seqcount;
126 maxra = min(read_max, maxra);
127 maxra = min(nbuf/8, maxra);
128 if (((u_quad_t)(lblkno + maxra + 1) * size) > filesize)
129 maxra = (filesize / size) - lblkno;
130
131 /*
132 * get the requested block
133 */
134 error = getblkx(vp, lblkno, lblkno, size, 0, 0, gbflags, &bp);
135 if (error != 0) {
136 *bpp = NULL;
137 return (error);
138 }
139 gbflags &= ~GB_NOSPARSE;
140 origblkno = lblkno;
141 *bpp = reqbp = bp;
142
143 /*
144 * if it is in the cache, then check to see if the reads have been
145 * sequential. If they have, then try some read-ahead, otherwise
146 * back-off on prospective read-aheads.
147 */
148 if (bp->b_flags & B_CACHE) {
149 if (!seqcount) {
150 return 0;
151 } else if ((bp->b_flags & B_RAM) == 0) {
152 return 0;
153 } else {
154 bp->b_flags &= ~B_RAM;
155 BO_RLOCK(bo);
156 for (i = 1; i < maxra; i++) {
157 /*
158 * Stop if the buffer does not exist or it

Callers

nothing calls this directly

Calls 11

minFunction · 0.85
getblkxFunction · 0.85
gbincoreFunction · 0.85
cluster_rbuildFunction · 0.85
vfs_busy_pagesFunction · 0.85
bstrategyFunction · 0.85
racct_add_bufFunction · 0.85
bqrelseFunction · 0.85
getblkFunction · 0.85
bufwaitFunction · 0.85
brelseFunction · 0.85

Tested by

no test coverage detected