bufobj.h revision 136962
150477Speter/*- 2139749Simp * Copyright (c) 2004 Poul-Henning Kamp 3196008Smjacob * All rights reserved. 4167403Smjacob * 5196008Smjacob * Redistribution and use in source and binary forms, with or without 6167403Smjacob * modification, are permitted provided that the following conditions 7167403Smjacob * are met: 8167403Smjacob * 1. Redistributions of source code must retain the above copyright 9196008Smjacob * notice, this list of conditions and the following disclaimer. 10167403Smjacob * 2. Redistributions in binary form must reproduce the above copyright 11167403Smjacob * notice, this list of conditions and the following disclaimer in the 12167403Smjacob * documentation and/or other materials provided with the distribution. 13167403Smjacob * 14167403Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15196008Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16167403Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17167403Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18167403Smjacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19167403Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20167403Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21167403Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22167403Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23167403Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24167403Smjacob * SUCH DAMAGE. 25167403Smjacob * 26167403Smjacob * $FreeBSD: head/sys/sys/bufobj.h 136962 2004-10-26 06:15:39Z phk $ 27196008Smjacob */ 28167403Smjacob 29167403Smjacob/* 3035388Smjacob * Architectural notes: 3135388Smjacob * 3235388Smjacob * bufobj is a new object which is what buffers hang from in the buffer 3335388Smjacob * cache. 3435388Smjacob * 3535388Smjacob * This used to be vnodes, but we need non-vnode code to be able 3644819Smjacob * to use the buffer cache as well, specifically geom classes like gbde, 37163899Smjacob * raid3 and raid5. 3835388Smjacob * 3935388Smjacob * All vnodes will contain a bufobj initially, but down the road we may 4035388Smjacob * want to only allocate bufobjs when they are needed. There could be a 41163899Smjacob * large number of vnodes in the system which wouldn't need a bufobj during 4235388Smjacob * their lifetime. 4335388Smjacob * 4435388Smjacob * The exact relationship to the vmobject is not determined at this point, 45163899Smjacob * it may in fact bee that we find them to be two sides of the same object 4642131Smjacob * once things starts to crystalize. 4735388Smjacob */ 48155704Smjacob 49163899Smjacob#ifndef _SYS_BUFOBJ_H_ 50155704Smjacob#define _SYS_BUFOBJ_H_ 5153487Smjacob 5235388Smjacob#if defined(_KERNEL) || defined(_KVM_VNODE) 53203444Smjacob 54163899Smjacob#include <sys/queue.h> 5539235Sgibbs 5635388Smjacobstruct bufobj; 5743420Smjacobstruct buf_ops; 5835388Smjacob 59155704Smjacobextern struct buf_ops buf_ops_bio; 6035388Smjacob 61196008SmjacobTAILQ_HEAD(buflists, buf); 62163899Smjacob 63163899Smjacob/* A Buffer splay list */ 64155704Smjacobstruct bufv { 65196008Smjacob struct buflists bv_hd; /* Sorted blocklist */ 66163899Smjacob struct buf *bv_root; /* Buf splay tree */ 67155704Smjacob int bv_cnt; /* Number of buffers */ 68155704Smjacob}; 69155704Smjacob 70167821Smjacobtypedef void b_strategy_t(struct bufobj *, struct buf *); 71155704Smjacobtypedef int b_write_t(struct buf *); 72155704Smjacob 7335388Smjacobstruct buf_ops { 7435388Smjacob char *bop_name; 7564087Smjacob b_write_t *bop_write; 7664087Smjacob b_strategy_t *bop_strategy; 7764087Smjacob}; 7882689Smjacob 79196008Smjacobstruct bufobj { 80164272Smjacob struct mtx *bo_mtx; /* Mutex which protects "i" things */ 81196008Smjacob struct bufv bo_clean; /* i Clean buffers */ 8249909Smjacob struct bufv bo_dirty; /* i Dirty buffers */ 8361772Smjacob long bo_numoutput; /* i Writes in progress */ 8449909Smjacob u_int bo_flag; /* i Flags */ 8582689Smjacob struct buf_ops *bo_ops; /* - buffer operatoins */ 8664087Smjacob struct vm_object *bo_object; /* v Place to store VM object */ 8764087Smjacob}; 8853487Smjacob 8982689Smjacob#define BO_WWAIT (1 << 1) /* Wait for output to complete */ 9082689Smjacob 9153487Smjacob#define BO_LOCK(bo) \ 9253487Smjacob do { \ 9353487Smjacob KASSERT (bo->bo_mtx != NULL, ("No lock in bufobj")); \ 9453487Smjacob mtx_lock((bo)->bo_mtx); \ 9553487Smjacob } while (0) 9653487Smjacob 9753487Smjacob#define BO_UNLOCK(bo) \ 9853487Smjacob do { \ 9953487Smjacob KASSERT (bo->bo_mtx != NULL, ("No lock in bufobj")); \ 10053487Smjacob mtx_unlock((bo)->bo_mtx); \ 101196008Smjacob } while (0) 102196008Smjacob 10353487Smjacob#define BO_MTX(bo) ((bo)->bo_mtx) 104155704Smjacob#define ASSERT_BO_LOCKED(bo) mtx_assert(bo->bo_mtx, MA_OWNED) 105155704Smjacob#define ASSERT_BO_UNLOCKED(bo) mtx_assert(bo->bo_mtx, MA_NOTOWNED) 10653487Smjacob 10753487Smjacobvoid bufobj_wdrop(struct bufobj *bo); 10853487Smjacobvoid bufobj_wref(struct bufobj *bo); 10953487Smjacobint bufobj_wwait(struct bufobj *bo, int slpflag, int timeo); 11053487Smjacob 11153487Smjacob#endif /* defined(_KERNEL) || defined(_KVM_VNODE) */ 11264087Smjacob#endif /* _SYS_BUFOBJ_H_ */ 11364087Smjacob 11453487Smjacob 11553487Smjacob