-
Notifications
You must be signed in to change notification settings - Fork 24
/
blkio.h
161 lines (116 loc) · 3.56 KB
/
blkio.h
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
154
155
156
157
158
159
160
161
/*
* Copyright (c) 2016--2021 Wu, Xingbo <[email protected]>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#pragma once
#include "lib.h"
#if defined(LIBURING)
#include <liburing.h>
#endif // LIBURING
#ifdef __cplusplus
extern "C" {
#endif
// wring {{{
struct wring;
// iosz: fixed write size; must be a multiple of PGSZ
extern struct wring *
wring_create(const int fd, const u32 iosz, const u32 depth);
extern void
wring_update_fd(struct wring * const wring, const int fd);
extern void
wring_destroy(struct wring * const wring);
extern void *
wring_acquire(struct wring * const wring);
// write part of the buf
extern void
wring_write_partial(struct wring * const wring, const off_t off,
void * const buf, const size_t buf_off, const u32 size);
extern void
wring_write(struct wring * const wring, const off_t off, void * const buf);
// flush the queue and wait for completion
extern void
wring_flush(struct wring * const wring);
// send an fsync but does not wait for completion
extern void
wring_fsync(struct wring * const wring);
// }}} wring
// coq {{{
struct coq;
typedef bool (*cowq_func) (void * priv);
extern struct coq *
coq_create(void);
extern void
coq_destroy(struct coq * const coq);
// prefer io_uring on Linux; fall back to POSIX AIO
extern struct coq *
coq_create_auto(const u32 depth);
extern void
coq_destroy_auto(struct coq * const coq);
extern u32
corq_enqueue(struct coq * const q, struct co * const co);
extern u32
cowq_enqueue(struct coq * const q, cowq_func exec, void * const priv);
extern void
cowq_remove(struct coq * const q, const u32 i);
extern void
coq_yield(struct coq * const q);
extern void
coq_idle(struct coq * const q);
extern void
coq_run(struct coq * const q);
extern void
coq_install(struct coq * const q);
extern void
coq_uninstall(void);
extern struct coq *
coq_current(void);
extern ssize_t
coq_pread_aio(struct coq * const q, const int fd, void * const buf, const size_t count, const off_t offset);
extern ssize_t
coq_pwrite_aio(struct coq * const q, const int fd, const void * const buf, const size_t count, const off_t offset);
#if defined(LIBURING)
// io_uring-specific
extern struct io_uring *
coq_uring_create(const u32 depth);
// use ring==NULL in pread_uring and pwrite_uring
extern struct coq *
coq_uring_create_pair(const u32 depth);
extern void
coq_uring_destroy(struct io_uring * const ring);
extern void
coq_uring_destroy_pair(struct coq * const coq);
extern ssize_t
coq_pread_uring(struct coq * const q, struct io_uring * const ring,
const int fd, void * const buf, const size_t count, const off_t offset);
extern ssize_t
coq_pwrite_uring(struct coq * const q, struct io_uring * const ring,
const int fd, const void * const buf, const size_t count, const off_t offset);
#endif // LIBURING
// }}} coq
// rcache {{{
extern struct rcache *
rcache_create(const u64 size_mb, const u32 fd_bits);
extern void
rcache_destroy(struct rcache * const c);
extern void
rcache_close_lazy(struct rcache * const c, const int fd);
extern u64
rcache_close_flush(struct rcache * const c);
extern void
rcache_close(struct rcache * const c, const int fd);
extern void *
rcache_acquire(struct rcache * const c, const int fd, const u32 pageid);
extern void
rcache_retain(struct rcache * const c, const void * const buf);
extern void
rcache_release(struct rcache * const c, const void * const buf);
extern void
rcache_thread_stat_reset(void);
extern u64
rcache_thread_stat_reads(void);
// }}} rcache
#ifdef __cplusplus
}
#endif
// vim:fdm=marker