1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2022 Tomohiro Kusumi <tkusumi@netbsd.org>
5 * Copyright (c) 2011-2022 The DragonFly Project. All rights reserved.
6 *
7 * This code is derived from software contributed to The DragonFly Project
8 * by Matthew Dillon <dillon@dragonflybsd.org>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * 3. Neither the name of The DragonFly Project nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific, prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 #ifndef _HAMMER2_HAMMER2_COMPAT_H
39 #define _HAMMER2_HAMMER2_COMPAT_H
40
41 #include <sys/statvfs.h>
42 #include <sys/spinlock.h>
43 #include <sys/uio.h> /* struct iovec */
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <util.h> /* ecalloc */
49 #include <assert.h>
50 #include <err.h>
51
52 #include "ffs/buf.h"
53
54 #define INVARIANTS
55
56 #define MALLOC_DECLARE(type) struct __hack
57 #define MALLOC_DEFINE(type, shortdesc, longdesc) struct __hack
58
59 #define SYSCTL_NODE(parent, nbr, name, access, handler, descr) struct __hack
60 #define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) struct __hack
61 #define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) struct __hack
62
63 #define VFS_SET(vfsops, fsname, flags) struct __hack
64
65 #define MODULE_VERSION(module, version) struct __hack
66
67 #define VOP_FSYNC(vp, waitfor, flags) (0)
68
69 #define kprintf(s, ...) printf(s, ## __VA_ARGS__)
70 #define krateprintf(r, X, ...) kprintf(X, ## __VA_ARGS__)
71 #define ksnprintf(s, n, ...) snprintf(s, n, ## __VA_ARGS__)
72 #define kstrdup(str, type) strdup(str)
73
74 #define kmalloc_create(typep, descr) do{}while(0)
75 #define kmalloc_destroy(typep) do{}while(0)
76 #define kmalloc(size, type, flags) ecalloc(1, size)
77 #define krealloc(addr, size, type, flags) realloc(addr, size)
78 #define kfree(addr, type) free(addr)
79
80 #define kmalloc_create_obj(typep, descr, objsize) do{}while(0)
81 #define kmalloc_destroy_obj(type) do{}while(0)
82 #define kmalloc_obj(size, type, flags) ecalloc(1, size)
83 #define kfree_obj(addr, type) free(addr)
84
85 #define kmalloc_raise_limit(typep, bytes) do{}while(0)
86
87 #define KASSERT(exp, msg) do { if (!(exp)) panic msg; } while(0)
88 //#define KASSERT(exp, msg) assert(exp)
89 #define KKASSERT(exp) assert(exp)
90
91 #define __debugvar
92
93 #define panic(s, ...) errx(1, s, ## __VA_ARGS__)
94
95 #define ERESTART (-1)
96
97 #define LK_SHARED 0x00000001
98 #define LK_EXCLUSIVE 0x00000002
99 #define LK_RELEASE 0x00000006
100 #define LK_NOWAIT 0x00000010
101 #define LK_RETRY 0x00020000
102 #define LK_PCATCH 0x04000000
103
104 #define MTX_EXCLUSIVE 0x80000000
105 #define MTX_MASK 0x0FFFFFFF
106
107 #define IO_APPEND 0x0002
108 #define IO_SYNC 0x0004
109 #define IO_ASYNC 0x0080
110 #define IO_DIRECT 0x0100
111 #define IO_RECURSE 0x0200
112
113 #define IO_SEQMAX 0x7F
114 #define IO_SEQSHIFT 16
115
116 #define VROOT 0x00000001
117 #define VKVABIO 0x00000040
118 #define VLASTWRITETS 0x00080000
119
120 #define VNOVAL (-1)
121
122 #define FORCECLOSE 0x0002
123
124 #define GETBLK_BHEAVY 0x0002
125 #define GETBLK_KVABIO 0x0010
126
127 #define NOOFFSET (-1LL)
128
129 #define KNOTE(list, hint)
130
131 #define NOTE_DELETE 0x0001
132 #define NOTE_WRITE 0x0002
133 #define NOTE_EXTEND 0x0004
134 #define NOTE_LINK 0x0010
135
136 extern int hz;
137 extern int ticks;
138 extern int64_t vnode_count;
139
140 struct thread {
141 void *td_proc;
142 };
143
144 typedef struct thread *thread_t;
145 extern struct thread *curthread;
146
147 struct lwkt_token {
148 };
149
150 typedef struct lwkt_token *lwkt_token_t;
151
152 struct mount {
153 int mnt_flag;
154 int mnt_kern_flag;
155 struct statfs mnt_stat;
156 struct statvfs mnt_vstat;
157 qaddr_t mnt_data;
158 unsigned int mnt_iosize_max;
159 };
160
161 struct bio {
162 struct m_buf *bio_buf;
163 off_t bio_offset;
164 };
165
166 struct bio_track {
167 };
168
169 struct namecache {
170 u_char nc_nlen;
171 char *nc_name;
172 };
173
174 struct nchandle {
175 struct namecache *ncp;
176 };
177
178 struct vop_generic_args {
179 int a_reserved[4];
180 };
181
182 struct vop_open_args {
183 struct m_vnode *a_vp;
184 int a_mode;
185 struct ucred *a_cred;
186 struct file **a_fpp;
187 };
188
189 struct vop_close_args {
190 struct m_vnode *a_vp;
191 int a_fflag;
192 struct file *a_fp;
193 };
194
195 struct vop_access_args {
196 struct m_vnode *a_vp;
197 int a_mode;
198 int a_flags;
199 struct ucred *a_cred;
200 };
201
202 struct vop_getattr_args {
203 struct m_vnode *a_vp;
204 struct vattr *a_vap;
205 };
206
207 struct vop_getattr_lite_args {
208 struct m_vnode *a_vp;
209 struct vattr_lite *a_lvap;
210 };
211
212 struct vop_setattr_args {
213 struct m_vnode *a_vp;
214 struct vattr *a_vap;
215 struct ucred *a_cred;
216 };
217
218 struct vop_read_args {
219 struct m_vnode *a_vp;
220 struct uio *a_uio;
221 int a_ioflag;
222 struct ucred *a_cred;
223 };
224
225 struct vop_write_args {
226 struct m_vnode *a_vp;
227 struct uio *a_uio;
228 int a_ioflag;
229 struct ucred *a_cred;
230 };
231
232 struct vop_ioctl_args {
233 struct m_vnode *a_vp;
234 u_long a_command;
235 caddr_t a_data;
236 int a_fflag;
237 struct ucred *a_cred;
238 struct sysmsg *a_sysmsg;
239 };
240
241 struct vop_kqfilter_args {
242 struct m_vnode *a_vp;
243 struct knote *a_kn;
244 };
245
246 struct vop_fsync_args {
247 struct m_vnode *a_vp;
248 int a_waitfor;
249 int a_flags;
250 };
251
252 struct vop_readdir_args {
253 struct m_vnode *a_vp;
254 struct uio *a_uio;
255 struct ucred *a_cred;
256 int *a_eofflag;
257 int *a_ncookies;
258 off_t **a_cookies;
259 int *a_ndirent; /* makefs */
260 };
261
262 struct vop_readlink_args {
263 struct m_vnode *a_vp;
264 struct uio *a_uio;
265 struct ucred *a_cred;
266 };
267
268 struct vop_inactive_args {
269 struct m_vnode *a_vp;
270 };
271
272 struct vop_reclaim_args {
273 struct m_vnode *a_vp;
274 };
275
276 struct vop_bmap_args {
277 struct m_vnode *a_vp;
278 off_t a_loffset;
279 off_t *a_doffsetp;
280 int *a_runp;
281 int *a_runb;
282 buf_cmd_t a_cmd;
283 };
284
285 struct vop_strategy_args {
286 struct m_vnode *a_vp;
287 struct bio *a_bio;
288 };
289
290 struct vop_advlock_args {
291 struct m_vnode *a_vp;
292 caddr_t a_id;
293 int a_op;
294 struct flock *a_fl;
295 int a_flags;
296 };
297
298 struct vop_getpages_args {
299 struct m_vnode *a_vp;
300 int a_count;
301 int a_reqpage;
302 //vm_ooffset_t a_offset;
303 int a_seqaccess;
304 };
305
306 struct vop_putpages_args {
307 struct m_vnode *a_vp;
308 int a_count;
309 int a_flags;
310 int *a_rtvals;
311 //vm_ooffset_t a_offset;
312 };
313
314 struct vop_mountctl_args {
315 int a_op;
316 struct file *a_fp;
317 const void *a_ctl;
318 int a_ctllen;
319 void *a_buf;
320 int a_buflen;
321 int *a_res;
322 struct m_vnode *a_vp;
323 };
324
325 struct vop_markatime_args {
326 int a_op;
327 struct m_vnode *a_vp;
328 struct ucred *a_cred;
329 };
330
331 struct vop_nresolve_args {
332 struct nchandle *a_nch;
333 struct m_vnode *a_dvp;
334 struct ucred *a_cred;
335 struct m_vnode **a_vpp; /* makefs */
336 };
337
338 struct vop_nlookupdotdot_args {
339 struct m_vnode *a_dvp;
340 struct m_vnode **a_vpp;
341 struct ucred *a_cred;
342 char **a_fakename;
343 };
344
345 struct vop_ncreate_args {
346 struct nchandle *a_nch;
347 struct m_vnode *a_dvp;
348 struct m_vnode **a_vpp;
349 struct ucred *a_cred;
350 struct vattr *a_vap;
351 };
352
353 struct vop_nmkdir_args {
354 struct nchandle *a_nch;
355 struct m_vnode *a_dvp;
356 struct m_vnode **a_vpp;
357 struct ucred *a_cred;
358 struct vattr *a_vap;
359 };
360
361 struct vop_nmknod_args {
362 struct nchandle *a_nch;
363 struct m_vnode *a_dvp;
364 struct m_vnode **a_vpp;
365 struct ucred *a_cred;
366 struct vattr *a_vap;
367 };
368
369 struct vop_nlink_args {
370 struct nchandle *a_nch;
371 struct m_vnode *a_dvp;
372 struct m_vnode *a_vp;
373 struct ucred *a_cred;
374 };
375
376 struct vop_nsymlink_args {
377 struct nchandle *a_nch;
378 struct m_vnode *a_dvp;
379 struct m_vnode **a_vpp;
380 struct ucred *a_cred;
381 struct vattr *a_vap;
382 char *a_target;
383 };
384
385 struct vop_nremove_args {
386 struct nchandle *a_nch;
387 struct m_vnode *a_dvp;
388 struct ucred *a_cred;
389 };
390
391 struct vop_nrmdir_args {
392 struct nchandle *a_nch;
393 struct m_vnode *a_dvp;
394 struct ucred *a_cred;
395 };
396
397 struct vop_nrename_args {
398 struct nchandle *a_fnch;
399 struct nchandle *a_tnch;
400 struct m_vnode *a_fdvp;
401 struct m_vnode *a_tdvp;
402 struct ucred *a_cred;
403 };
404
405 #define vop_defaultop NULL
406 #define vop_stdgetpages NULL
407 #define vop_stdputpages NULL
408 #define vop_stdnoread NULL
409 #define vop_stdnowrite NULL
410 #define fifo_vnoperate NULL
411
412 struct vop_ops {
413 int (*vop_default)(struct vop_generic_args *);
414 int (*vop_open)(struct vop_open_args *);
415 int (*vop_close)(struct vop_close_args *);
416 int (*vop_access)(struct vop_access_args *);
417 int (*vop_getattr)(struct vop_getattr_args *);
418 int (*vop_getattr_lite)(struct vop_getattr_lite_args *);
419 int (*vop_setattr)(struct vop_setattr_args *);
420 int (*vop_read)(struct vop_read_args *);
421 int (*vop_write)(struct vop_write_args *);
422 int (*vop_ioctl)(struct vop_ioctl_args *);
423 int (*vop_kqfilter)(struct vop_kqfilter_args *);
424 int (*vop_fsync)(struct vop_fsync_args *);
425 int (*vop_readdir)(struct vop_readdir_args *);
426 int (*vop_readlink)(struct vop_readlink_args *);
427 int (*vop_inactive)(struct vop_inactive_args *);
428 int (*vop_reclaim)(struct vop_reclaim_args *);
429 int (*vop_bmap)(struct vop_bmap_args *);
430 int (*vop_strategy)(struct vop_strategy_args *);
431 int (*vop_advlock)(struct vop_advlock_args *);
432 int (*vop_getpages)(struct vop_getpages_args *);
433 int (*vop_putpages)(struct vop_putpages_args *);
434 int (*vop_mountctl)(struct vop_mountctl_args *);
435 int (*vop_markatime)(struct vop_markatime_args *);
436 int (*vop_nresolve)(struct vop_nresolve_args *);
437 int (*vop_nlookupdotdot)(struct vop_nlookupdotdot_args *);
438 int (*vop_ncreate)(struct vop_ncreate_args *);
439 int (*vop_nmkdir)(struct vop_nmkdir_args *);
440 int (*vop_nmknod)(struct vop_nmknod_args *);
441 int (*vop_nlink)(struct vop_nlink_args *);
442 int (*vop_nsymlink)(struct vop_nsymlink_args *);
443 int (*vop_nremove)(struct vop_nremove_args *);
444 int (*vop_nrmdir)(struct vop_nrmdir_args *);
445 int (*vop_nrename)(struct vop_nrename_args *);
446 };
447
448 enum uio_seg {
449 UIO_USERSPACE,
450 UIO_SYSSPACE,
451 UIO_NOCOPY,
452 };
453
454 enum uio_rw {
455 UIO_READ,
456 UIO_WRITE
457 };
458
459 struct uio {
460 struct iovec *uio_iov;
461 int uio_iovcnt;
462 off_t uio_offset;
463 size_t uio_resid;
464 enum uio_seg uio_segflg;
465 enum uio_rw uio_rw;
466 struct thread *uio_td;
467 };
468
469 /*
470 * Since makefs(8) is a single thread program, there should never be any
471 * lock contention. Therefore, lock(9)/mutex(9)/spinlock(9) emulation always
472 * succeed. Similarly, tsleep(9) should never be called.
473 */
474 struct lock {
475 int reserved;
476 };
477
478 typedef struct {
479 unsigned int mtx_lock;
480 } mtx_t;
481
482 typedef mtx_t hammer2_mtx_t;
483
484 typedef u_int mtx_state_t;
485 typedef mtx_state_t hammer2_mtx_state_t;
486
487 typedef struct spinlock hammer2_spin_t;
488
489 static __inline
490 void
cpu_pause(void)491 cpu_pause(void)
492 {
493 }
494
495 static __inline
496 void
cpu_mfence(void)497 cpu_mfence(void)
498 {
499 }
500
501 static __inline
502 void
cpu_lfence(void)503 cpu_lfence(void)
504 {
505 }
506
507 static __inline
508 void
cpu_sfence(void)509 cpu_sfence(void)
510 {
511 }
512
513 static __inline
514 void
cpu_ccfence(void)515 cpu_ccfence(void)
516 {
517 }
518
519 static __inline
520 void
trigger_syncer(struct mount * mp)521 trigger_syncer(struct mount *mp)
522 {
523 }
524
525 static __inline
526 void
trigger_syncer_start(struct mount * mp)527 trigger_syncer_start(struct mount *mp)
528 {
529 }
530
531 static __inline
532 void
trigger_syncer_stop(struct mount * mp)533 trigger_syncer_stop(struct mount *mp)
534 {
535 }
536
537 static __inline
538 int
vfs_mountedon(struct m_vnode * vp)539 vfs_mountedon(struct m_vnode *vp)
540 {
541 return (0);
542 }
543
544 static __inline
545 uid_t
vop_helper_create_uid(struct mount * mp,mode_t dmode,uid_t duid,struct ucred * cred,mode_t * modep)546 vop_helper_create_uid(struct mount *mp, mode_t dmode, uid_t duid,
547 struct ucred *cred, mode_t *modep)
548 {
549 return (getuid());
550 }
551
552 static __inline
553 int
vinitvmio(struct m_vnode * vp,off_t filesize,int blksize,int boff)554 vinitvmio(struct m_vnode *vp, off_t filesize, int blksize, int boff)
555 {
556 return (0);
557 }
558
559 static __inline
560 int
getnewvnode(enum vtagtype tag,struct mount * mp,struct m_vnode ** vpp,int lktimeout,int lkflags)561 getnewvnode(enum vtagtype tag, struct mount *mp, struct m_vnode **vpp,
562 int lktimeout, int lkflags)
563 {
564 struct m_vnode *vp;
565
566 vp = ecalloc(1, sizeof(*vp));
567 vp->v_logical = 1;
568 vp->v_malloced = 1;
569 *vpp = vp;
570
571 vnode_count++;
572
573 return (0);
574 }
575
576 /* not freesomevnodes() */
577 static __inline
578 void
freevnode(struct m_vnode * vp)579 freevnode(struct m_vnode *vp)
580 {
581 assert(vp->v_malloced);
582 free(vp);
583
584 vnode_count--;
585 }
586
587 static __inline
588 int
vn_lock(struct m_vnode * vp,int flags)589 vn_lock(struct m_vnode *vp, int flags)
590 {
591 return (0);
592 }
593
594 static __inline
595 void
vn_unlock(struct m_vnode * vp)596 vn_unlock(struct m_vnode *vp)
597 {
598 }
599
600 static __inline
601 int
vget(struct m_vnode * vp,int flags)602 vget(struct m_vnode *vp, int flags)
603 {
604 return (0);
605 }
606
607 static __inline
608 void
vput(struct m_vnode * vp)609 vput(struct m_vnode *vp)
610 {
611 }
612
613 static __inline
614 void
vrele(struct m_vnode * vp)615 vrele(struct m_vnode *vp)
616 {
617 }
618
619 static __inline
620 void
vhold(struct m_vnode * vp)621 vhold(struct m_vnode *vp)
622 {
623 }
624
625 static __inline
626 void
vdrop(struct m_vnode * vp)627 vdrop(struct m_vnode *vp)
628 {
629 }
630
631 static __inline
632 void
vx_put(struct m_vnode * vp)633 vx_put(struct m_vnode *vp)
634 {
635 }
636
637 static __inline
638 void
vx_downgrade(struct m_vnode * vp)639 vx_downgrade(struct m_vnode *vp)
640 {
641 }
642
643 static __inline
644 void
vfinalize(struct m_vnode * vp)645 vfinalize(struct m_vnode *vp)
646 {
647 }
648
649 static __inline
650 void
vsetflags(struct m_vnode * vp,int flags)651 vsetflags(struct m_vnode *vp, int flags)
652 {
653 }
654
655 static __inline
656 void
vclrflags(struct m_vnode * vp,int flags)657 vclrflags(struct m_vnode *vp, int flags)
658 {
659 }
660
661 static __inline
662 void
vsetisdirty(struct m_vnode * vp)663 vsetisdirty(struct m_vnode *vp)
664 {
665 }
666
667 static __inline
668 void
vclrisdirty(struct m_vnode * vp)669 vclrisdirty(struct m_vnode *vp)
670 {
671 }
672
673 static __inline
674 int
vfsync(struct m_vnode * vp,int waitfor,int passes,int (* checkdef)(struct m_buf *),int (* waitoutput)(struct m_vnode *,struct thread *))675 vfsync(struct m_vnode *vp, int waitfor, int passes,
676 int (*checkdef)(struct m_buf *),
677 int (*waitoutput)(struct m_vnode *, struct thread *))
678 {
679 return (0);
680 }
681
682 static __inline
683 int
nvtruncbuf(struct m_vnode * vp,off_t length,int blksize,int boff,int flags)684 nvtruncbuf(struct m_vnode *vp, off_t length, int blksize, int boff, int flags)
685 {
686 return (0);
687 }
688
689 static __inline
690 int
nvextendbuf(struct m_vnode * vp,off_t olength,off_t nlength,int oblksize,int nblksize,int oboff,int nboff,int flags)691 nvextendbuf(struct m_vnode *vp, off_t olength, off_t nlength, int oblksize,
692 int nblksize, int oboff, int nboff, int flags)
693 {
694 return (0);
695 }
696
697 static __inline
698 void
addaliasu(struct m_vnode * vp,int x,int y)699 addaliasu(struct m_vnode *vp, int x, int y)
700 {
701 }
702
703 static __inline
704 void
bheavy(struct m_buf * bp)705 bheavy(struct m_buf *bp)
706 {
707 }
708
709 static __inline
710 void
bkvasync(struct m_buf * bp)711 bkvasync(struct m_buf *bp)
712 {
713 }
714
715 static __inline
716 void
bwillwrite(int bytes)717 bwillwrite(int bytes)
718 {
719 }
720
721 static __inline
722 void
BUF_KERNPROC(struct m_buf * bp)723 BUF_KERNPROC(struct m_buf *bp)
724 {
725 }
726
727 static __inline
728 int
bio_track_wait(struct bio_track * track,int slp_flags,int slp_timo)729 bio_track_wait(struct bio_track *track, int slp_flags, int slp_timo)
730 {
731 return (0);
732 }
733
734 static __inline
735 void
cache_setvp(struct nchandle * nch,struct m_vnode * vp)736 cache_setvp(struct nchandle *nch, struct m_vnode *vp)
737 {
738 }
739
740 static __inline
741 void
cache_setunresolved(struct nchandle * nch)742 cache_setunresolved(struct nchandle *nch)
743 {
744 }
745
746 static __inline
747 void
lockinit(struct lock * lkp,const char * wmesg,int timo,int flags)748 lockinit(struct lock *lkp, const char *wmesg, int timo, int flags)
749 {
750 }
751
752 static __inline
753 int
lockmgr(struct lock * lkp,uint32_t flags)754 lockmgr(struct lock *lkp, uint32_t flags)
755 {
756 return (0);
757 }
758
759 static __inline
760 int
hammer2_mtx_ex(hammer2_mtx_t * mtx)761 hammer2_mtx_ex(hammer2_mtx_t *mtx)
762 {
763 mtx->mtx_lock |= MTX_EXCLUSIVE;
764 mtx->mtx_lock++;
765 return (0);
766 }
767
768 static __inline
769 int
hammer2_mtx_ex_try(hammer2_mtx_t * mtx)770 hammer2_mtx_ex_try(hammer2_mtx_t *mtx)
771 {
772 mtx->mtx_lock |= MTX_EXCLUSIVE;
773 mtx->mtx_lock++;
774 return (0);
775 }
776
777 static __inline
778 int
hammer2_mtx_sh(hammer2_mtx_t * mtx)779 hammer2_mtx_sh(hammer2_mtx_t *mtx)
780 {
781 mtx->mtx_lock |= MTX_EXCLUSIVE;
782 mtx->mtx_lock++;
783 return (0);
784 }
785
786 static __inline
787 void
hammer2_mtx_sh_again(hammer2_mtx_t * mtx)788 hammer2_mtx_sh_again(hammer2_mtx_t *mtx)
789 {
790 mtx->mtx_lock |= MTX_EXCLUSIVE;
791 mtx->mtx_lock++;
792 }
793
794 static __inline
795 int
hammer2_mtx_sh_try(hammer2_mtx_t * mtx)796 hammer2_mtx_sh_try(hammer2_mtx_t *mtx)
797 {
798 mtx->mtx_lock |= MTX_EXCLUSIVE;
799 mtx->mtx_lock++;
800 return (0);
801 }
802
803 static __inline
804 void
hammer2_mtx_unlock(hammer2_mtx_t * mtx)805 hammer2_mtx_unlock(hammer2_mtx_t *mtx)
806 {
807 mtx->mtx_lock &= ~MTX_EXCLUSIVE;
808 mtx->mtx_lock--;
809 }
810
811 static __inline
812 int
hammer2_mtx_upgrade_try(hammer2_mtx_t * mtx)813 hammer2_mtx_upgrade_try(hammer2_mtx_t *mtx)
814 {
815 return (0);
816 }
817
818 static __inline
819 int
hammer2_mtx_downgrade(hammer2_mtx_t * mtx)820 hammer2_mtx_downgrade(hammer2_mtx_t *mtx)
821 {
822 return (0);
823 }
824
825 static __inline
826 int
hammer2_mtx_owned(hammer2_mtx_t * mtx)827 hammer2_mtx_owned(hammer2_mtx_t *mtx)
828 {
829 return (1); /* XXX for asserts */
830 }
831
832 static __inline
833 void
hammer2_mtx_init(hammer2_mtx_t * mtx,const char * ident)834 hammer2_mtx_init(hammer2_mtx_t *mtx, const char *ident)
835 {
836 mtx->mtx_lock = 0;
837 }
838
839 static __inline
840 hammer2_mtx_state_t
hammer2_mtx_temp_release(hammer2_mtx_t * mtx)841 hammer2_mtx_temp_release(hammer2_mtx_t *mtx)
842 {
843 return (0);
844 }
845
846 static __inline
847 void
hammer2_mtx_temp_restore(hammer2_mtx_t * mtx,hammer2_mtx_state_t state)848 hammer2_mtx_temp_restore(hammer2_mtx_t *mtx, hammer2_mtx_state_t state)
849 {
850 }
851
852 static __inline
853 int
hammer2_mtx_refs(hammer2_mtx_t * mtx)854 hammer2_mtx_refs(hammer2_mtx_t *mtx)
855 {
856 return (mtx->mtx_lock & MTX_MASK);
857 }
858
859 static __inline
860 void
hammer2_spin_init(hammer2_spin_t * mtx,const char * ident)861 hammer2_spin_init(hammer2_spin_t *mtx, const char *ident)
862 {
863 mtx->lock = 0;
864 }
865
866 static __inline
867 void
hammer2_spin_sh(hammer2_spin_t * mtx)868 hammer2_spin_sh(hammer2_spin_t *mtx)
869 {
870 mtx->lock++;
871 }
872
873 static __inline
874 void
hammer2_spin_ex(hammer2_spin_t * mtx)875 hammer2_spin_ex(hammer2_spin_t *mtx)
876 {
877 mtx->lock++;
878 }
879
880 static __inline
881 void
hammer2_spin_unsh(hammer2_spin_t * mtx)882 hammer2_spin_unsh(hammer2_spin_t *mtx)
883 {
884 mtx->lock--;
885 }
886
887 static __inline
888 void
hammer2_spin_unex(hammer2_spin_t * mtx)889 hammer2_spin_unex(hammer2_spin_t *mtx)
890 {
891 mtx->lock--;
892 }
893
894 static __inline
895 void
lwkt_gettoken(lwkt_token_t tok)896 lwkt_gettoken(lwkt_token_t tok)
897 {
898 }
899
900 static __inline
901 void
lwkt_reltoken(lwkt_token_t tok)902 lwkt_reltoken(lwkt_token_t tok)
903 {
904 }
905
906 static __inline
907 void
lwkt_yield(void)908 lwkt_yield(void)
909 {
910 }
911
912 static __inline
913 int
tsleep(const volatile void * ident,int flags,const char * wmesg,int timo)914 tsleep(const volatile void *ident, int flags, const char *wmesg, int timo)
915 {
916 assert(0);
917 }
918
919 static __inline
920 void
tsleep_interlock(const volatile void * ident,int flags)921 tsleep_interlock(const volatile void *ident, int flags)
922 {
923 assert(0);
924 }
925
926 static __inline
927 void
wakeup(const volatile void * ident)928 wakeup(const volatile void *ident)
929 {
930 assert(0);
931 }
932
933 static __inline
934 void
print_backtrace(int count)935 print_backtrace(int count)
936 {
937 }
938
939 static __inline
940 void
Debugger(const char * msg)941 Debugger(const char *msg)
942 {
943 panic("%s: %s", __func__, msg);
944 }
945
946 #endif /* _HAMMER2_HAMMER2_COMPAT_H */
947