| 1 | /* $NetBSD: bufq_impl.h,v 1.10 2016/11/16 00:46:46 pgoyette Exp $ */ |
| 2 | /* NetBSD: bufq.h,v 1.3 2005/03/31 11:28:53 yamt Exp */ |
| 3 | /* NetBSD: buf.h,v 1.75 2004/09/18 16:40:11 yamt Exp */ |
| 4 | |
| 5 | /*- |
| 6 | * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * This code is derived from software contributed to The NetBSD Foundation |
| 10 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, |
| 11 | * NASA Ames Research Center. |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or without |
| 14 | * modification, are permitted provided that the following conditions |
| 15 | * are met: |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 23 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 24 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 32 | * POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
| 35 | /* |
| 36 | * Copyright (c) 1982, 1986, 1989, 1993 |
| 37 | * The Regents of the University of California. All rights reserved. |
| 38 | * (c) UNIX System Laboratories, Inc. |
| 39 | * All or some portions of this file are derived from material licensed |
| 40 | * to the University of California by American Telephone and Telegraph |
| 41 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with |
| 42 | * the permission of UNIX System Laboratories, Inc. |
| 43 | * |
| 44 | * Redistribution and use in source and binary forms, with or without |
| 45 | * modification, are permitted provided that the following conditions |
| 46 | * are met: |
| 47 | * 1. Redistributions of source code must retain the above copyright |
| 48 | * notice, this list of conditions and the following disclaimer. |
| 49 | * 2. Redistributions in binary form must reproduce the above copyright |
| 50 | * notice, this list of conditions and the following disclaimer in the |
| 51 | * documentation and/or other materials provided with the distribution. |
| 52 | * 3. Neither the name of the University nor the names of its contributors |
| 53 | * may be used to endorse or promote products derived from this software |
| 54 | * without specific prior written permission. |
| 55 | * |
| 56 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 57 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 58 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 59 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 60 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 61 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 62 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 63 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 64 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 65 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 66 | * SUCH DAMAGE. |
| 67 | * |
| 68 | * @(#)buf.h 8.9 (Berkeley) 3/30/95 |
| 69 | */ |
| 70 | |
| 71 | #if !defined(_KERNEL) |
| 72 | #error not supposed to be exposed to userland. |
| 73 | #endif |
| 74 | |
| 75 | struct bufq_strat; |
| 76 | |
| 77 | /* |
| 78 | * Device driver buffer queue. |
| 79 | */ |
| 80 | struct bufq_state { |
| 81 | void (*bq_put)(struct bufq_state *, struct buf *); |
| 82 | struct buf *(*bq_get)(struct bufq_state *, int); |
| 83 | struct buf *(*bq_cancel)(struct bufq_state *, struct buf *); |
| 84 | void (*bq_fini)(struct bufq_state *); |
| 85 | void *bq_private; |
| 86 | int bq_flags; /* Flags from bufq_alloc() */ |
| 87 | struct bufq_strat *bq_strat; |
| 88 | }; |
| 89 | |
| 90 | static __inline void *bufq_private(const struct bufq_state *) __unused; |
| 91 | static __inline bool buf_inorder(const struct buf *, const struct buf *, int) |
| 92 | __unused; |
| 93 | |
| 94 | #include <sys/null.h> /* for NULL */ |
| 95 | |
| 96 | static __inline void * |
| 97 | bufq_private(const struct bufq_state *bufq) |
| 98 | { |
| 99 | |
| 100 | return bufq->bq_private; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Check if two buf's are in ascending order. |
| 105 | * |
| 106 | * this function consider a NULL buf is after any non-NULL buf. |
| 107 | * |
| 108 | * this function returns false if two are "same". |
| 109 | */ |
| 110 | static __inline bool |
| 111 | buf_inorder(const struct buf *bp, const struct buf *bq, int sortby) |
| 112 | { |
| 113 | |
| 114 | KASSERT(bp != NULL || bq != NULL); |
| 115 | if (bp == NULL || bq == NULL) |
| 116 | return (bq == NULL); |
| 117 | |
| 118 | if (sortby == BUFQ_SORT_CYLINDER) { |
| 119 | if (bp->b_cylinder != bq->b_cylinder) |
| 120 | return bp->b_cylinder < bq->b_cylinder; |
| 121 | else |
| 122 | return bp->b_rawblkno < bq->b_rawblkno; |
| 123 | } else |
| 124 | return bp->b_rawblkno < bq->b_rawblkno; |
| 125 | } |
| 126 | |
| 127 | struct bufq_strat { |
| 128 | const char *bs_name; |
| 129 | void (*bs_initfn)(struct bufq_state *); |
| 130 | int bs_prio; |
| 131 | int bs_refcnt; |
| 132 | SLIST_ENTRY(bufq_strat) bs_next; |
| 133 | }; |
| 134 | |
| 135 | #define BUFQ_DEFINE(name, prio, initfn) \ |
| 136 | static struct bufq_strat bufq_strat_##name = { \ |
| 137 | .bs_name = #name, \ |
| 138 | .bs_prio = prio, \ |
| 139 | .bs_initfn = initfn, \ |
| 140 | .bs_refcnt = 0 \ |
| 141 | }; |
| 142 | |
| 143 | int bufq_register(struct bufq_strat *); |
| 144 | int bufq_unregister(struct bufq_strat *); |
| 145 | |