1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _SYS_CCOMPAT_H
#define _SYS_CCOMPAT_H
#if __FreeBSD_version < 1300051
#define vm_page_valid(m) (m)->valid = VM_PAGE_BITS_ALL
#define vm_page_do_sunbusy(m)
#define vm_page_none_valid(m) ((m)->valid == 0)
#else
#define vm_page_do_sunbusy(m) vm_page_sunbusy(m)
#endif
#if __FreeBSD_version < 1300074
#define VOP_UNLOCK1(x) VOP_UNLOCK(x, 0)
#else
#define VOP_UNLOCK1(x) VOP_UNLOCK(x)
#endif
#if __FreeBSD_version < 1300064
#define VN_IS_DOOMED(vp) ((vp)->v_iflag & VI_DOOMED)
#endif
#if __FreeBSD_version < 1300068
#define VFS_VOP_VECTOR_REGISTER(x)
#endif
#if __FreeBSD_version >= 1300076
#define getnewvnode_reserve_() getnewvnode_reserve()
#else
#define getnewvnode_reserve_() getnewvnode_reserve(1)
#endif
#if __FreeBSD_version < 1300102
#define ASSERT_VOP_IN_SEQC(zp)
#define MNTK_FPLOOKUP 0
#define vn_seqc_write_begin(vp)
#define vn_seqc_write_end(vp)
#ifndef VFS_SMR_DECLARE
#define VFS_SMR_DECLARE
#endif
#ifndef VFS_SMR_ZONE_SET
#define VFS_SMR_ZONE_SET(zone)
#endif
#endif
struct hlist_node {
struct hlist_node *next, **pprev;
};
struct hlist_head {
struct hlist_node *first;
};
typedef struct {
volatile int counter;
} atomic_t;
/* BEGIN CSTYLED */
#define hlist_for_each(p, head) \
for (p = (head)->first; p; p = (p)->next)
#define hlist_entry(ptr, type, field) container_of(ptr, type, field)
#define container_of(ptr, type, member) \
({ \
const __typeof(((type *)0)->member) *__p = (ptr); \
(type *)((uintptr_t)__p - offsetof(type, member)); \
})
/* END CSTYLED */
static inline void
hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
n->next = h->first;
if (h->first != NULL)
h->first->pprev = &n->next;
WRITE_ONCE(h->first, n);
n->pprev = &h->first;
}
static inline void
hlist_del(struct hlist_node *n)
{
WRITE_ONCE(*(n->pprev), n->next);
if (n->next != NULL)
n->next->pprev = n->pprev;
}
/* BEGIN CSTYLED */
#define READ_ONCE(x) ({ \
__typeof(x) __var = ({ \
barrier(); \
ACCESS_ONCE(x); \
}); \
barrier(); \
__var; \
})
#define HLIST_HEAD_INIT { }
#define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
#define INIT_HLIST_HEAD(head) (head)->first = NULL
#define INIT_HLIST_NODE(node) \
do { \
(node)->next = NULL; \
(node)->pprev = NULL; \
} while (0)
/* END CSTYLED */
static inline int
atomic_read(const atomic_t *v)
{
return (READ_ONCE(v->counter));
}
static inline int
atomic_inc(atomic_t *v)
{
return (atomic_fetchadd_int(&v->counter, 1) + 1);
}
static inline int
atomic_dec(atomic_t *v)
{
return (atomic_fetchadd_int(&v->counter, -1) - 1);
}
#endif
|