Deleted Added
full compact
vdev_cache.c (258632) vdev_cache.c (260150)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 246 unchanged lines hidden (view full) ---

255
256 if (fio->io_error || ve->ve_missed_update)
257 vdev_cache_evict(vc, ve);
258
259 mutex_exit(&vc->vc_lock);
260}
261
262/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 246 unchanged lines hidden (view full) ---

255
256 if (fio->io_error || ve->ve_missed_update)
257 vdev_cache_evict(vc, ve);
258
259 mutex_exit(&vc->vc_lock);
260}
261
262/*
263 * Read data from the cache. Returns 0 on cache hit, errno on a miss.
263 * Read data from the cache. Returns B_TRUE cache hit, B_FALSE on miss.
264 */
264 */
265int
265boolean_t
266vdev_cache_read(zio_t *zio)
267{
268 vdev_cache_t *vc = &zio->io_vd->vdev_cache;
269 vdev_cache_entry_t *ve, ve_search;
270 uint64_t cache_offset = P2ALIGN(zio->io_offset, VCBS);
271 uint64_t cache_phase = P2PHASE(zio->io_offset, VCBS);
272 zio_t *fio;
273
274 ASSERT(zio->io_type == ZIO_TYPE_READ);
275
276 if (zio->io_flags & ZIO_FLAG_DONT_CACHE)
266vdev_cache_read(zio_t *zio)
267{
268 vdev_cache_t *vc = &zio->io_vd->vdev_cache;
269 vdev_cache_entry_t *ve, ve_search;
270 uint64_t cache_offset = P2ALIGN(zio->io_offset, VCBS);
271 uint64_t cache_phase = P2PHASE(zio->io_offset, VCBS);
272 zio_t *fio;
273
274 ASSERT(zio->io_type == ZIO_TYPE_READ);
275
276 if (zio->io_flags & ZIO_FLAG_DONT_CACHE)
277 return (SET_ERROR(EINVAL));
277 return (B_FALSE);
278
279 if (zio->io_size > zfs_vdev_cache_max)
278
279 if (zio->io_size > zfs_vdev_cache_max)
280 return (SET_ERROR(EOVERFLOW));
280 return (B_FALSE);
281
282 /*
283 * If the I/O straddles two or more cache blocks, don't cache it.
284 */
285 if (P2BOUNDARY(zio->io_offset, zio->io_size, VCBS))
281
282 /*
283 * If the I/O straddles two or more cache blocks, don't cache it.
284 */
285 if (P2BOUNDARY(zio->io_offset, zio->io_size, VCBS))
286 return (SET_ERROR(EXDEV));
286 return (B_FALSE);
287
288 ASSERT(cache_phase + zio->io_size <= VCBS);
289
290 mutex_enter(&vc->vc_lock);
291
292 ve_search.ve_offset = cache_offset;
293 ve = avl_find(&vc->vc_offset_tree, &ve_search, NULL);
294
295 if (ve != NULL) {
296 if (ve->ve_missed_update) {
297 mutex_exit(&vc->vc_lock);
287
288 ASSERT(cache_phase + zio->io_size <= VCBS);
289
290 mutex_enter(&vc->vc_lock);
291
292 ve_search.ve_offset = cache_offset;
293 ve = avl_find(&vc->vc_offset_tree, &ve_search, NULL);
294
295 if (ve != NULL) {
296 if (ve->ve_missed_update) {
297 mutex_exit(&vc->vc_lock);
298 return (SET_ERROR(ESTALE));
298 return (B_FALSE);
299 }
300
301 if ((fio = ve->ve_fill_io) != NULL) {
302 zio_vdev_io_bypass(zio);
303 zio_add_child(zio, fio);
304 mutex_exit(&vc->vc_lock);
305 VDCSTAT_BUMP(vdc_stat_delegations);
299 }
300
301 if ((fio = ve->ve_fill_io) != NULL) {
302 zio_vdev_io_bypass(zio);
303 zio_add_child(zio, fio);
304 mutex_exit(&vc->vc_lock);
305 VDCSTAT_BUMP(vdc_stat_delegations);
306 return (0);
306 return (B_TRUE);
307 }
308
309 vdev_cache_hit(vc, ve, zio);
310 zio_vdev_io_bypass(zio);
311
312 mutex_exit(&vc->vc_lock);
313 VDCSTAT_BUMP(vdc_stat_hits);
307 }
308
309 vdev_cache_hit(vc, ve, zio);
310 zio_vdev_io_bypass(zio);
311
312 mutex_exit(&vc->vc_lock);
313 VDCSTAT_BUMP(vdc_stat_hits);
314 return (0);
314 return (B_TRUE);
315 }
316
317 ve = vdev_cache_allocate(zio);
318
319 if (ve == NULL) {
320 mutex_exit(&vc->vc_lock);
315 }
316
317 ve = vdev_cache_allocate(zio);
318
319 if (ve == NULL) {
320 mutex_exit(&vc->vc_lock);
321 return (SET_ERROR(ENOMEM));
321 return (B_FALSE);
322 }
323
324 fio = zio_vdev_delegated_io(zio->io_vd, cache_offset,
325 ve->ve_data, VCBS, ZIO_TYPE_READ, ZIO_PRIORITY_NOW,
326 ZIO_FLAG_DONT_CACHE, vdev_cache_fill, ve);
327
328 ve->ve_fill_io = fio;
329 zio_vdev_io_bypass(zio);
330 zio_add_child(zio, fio);
331
332 mutex_exit(&vc->vc_lock);
333 zio_nowait(fio);
334 VDCSTAT_BUMP(vdc_stat_misses);
335
322 }
323
324 fio = zio_vdev_delegated_io(zio->io_vd, cache_offset,
325 ve->ve_data, VCBS, ZIO_TYPE_READ, ZIO_PRIORITY_NOW,
326 ZIO_FLAG_DONT_CACHE, vdev_cache_fill, ve);
327
328 ve->ve_fill_io = fio;
329 zio_vdev_io_bypass(zio);
330 zio_add_child(zio, fio);
331
332 mutex_exit(&vc->vc_lock);
333 zio_nowait(fio);
334 VDCSTAT_BUMP(vdc_stat_misses);
335
336 return (0);
336 return (B_TRUE);
337}
338
339/*
340 * Update cache contents upon write completion.
341 */
342void
343vdev_cache_write(zio_t *zio)
344{

--- 94 unchanged lines hidden ---
337}
338
339/*
340 * Update cache contents upon write completion.
341 */
342void
343vdev_cache_write(zio_t *zio)
344{

--- 94 unchanged lines hidden ---