Skip to content

Commit b0706fb

Browse files
author
Yan Lan
committed
feat: support zondafs
1 parent de3d5e6 commit b0706fb

File tree

5 files changed

+345
-0
lines changed

5 files changed

+345
-0
lines changed

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ ifdef CONFIG_DFS
150150
dfs_LIBS = -luuid -ldaos -ldfs
151151
ENGINES += dfs
152152
endif
153+
ifdef CONFIG_ZONDAFS
154+
zondafs_SRCS = engines/zondafs.c
155+
zondafs_LIBS = $(FIO_ZONDAFS_PATH)/deps/file_client/lib/libfile_client.a \
156+
$(FIO_ZONDAFS_PATH)/deps/brpc/lib/libbrpc.a \
157+
$(FIO_ZONDAFS_PATH)/deps/fmt/lib/libfmt.a \
158+
$(FIO_ZONDAFS_PATH)/deps/isal/lib/libisal.a \
159+
$(FIO_ZONDAFS_PATH)/deps/gflags/lib/libgflags.a \
160+
-lprotobuf -lrt -lcrypto -lssl -lleveldb
161+
zondafs_CFLAGS = -I$(FIO_ZONDAFS_PATH)/deps/brpc/include \
162+
-I$(FIO_ZONDAFS_PATH)/deps/file_client/include \
163+
-I$(FIO_ZONDAFS_PATH)/deps/fmt/include \
164+
-I$(FIO_ZONDAFS_PATH)/deps/isal/include \
165+
-I$(FIO_ZONDAFS_PATH)/deps/gflags/include \
166+
-I$(FIO_ZONDAFS_PATH)
167+
ENGINES += zondafs
168+
endif
153169
SOURCE += oslib/asprintf.c
154170
ifndef CONFIG_STRSEP
155171
SOURCE += oslib/strsep.c

configure

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ isal64=""
195195
libblkio=""
196196
libzbc=""
197197
dfs=""
198+
zondafs=""
198199
seed_buckets=""
199200
dynamic_engines="no"
200201
prefix=/usr/local
@@ -283,6 +284,10 @@ for opt do
283284
;;
284285
--disable-dfs) dfs="no"
285286
;;
287+
--enable-zondafs) zondafs="yes"
288+
;;
289+
--disable-zondafs) zondafs="no"
290+
;;
286291
--enable-asan) asan="yes"
287292
;;
288293
--seed-buckets=*) seed_buckets="$optarg"
@@ -338,6 +343,8 @@ if test "$show_help" = "yes" ; then
338343
echo "--disable-tcmalloc Disable tcmalloc support"
339344
echo "--dynamic-libengines Lib-based ioengines as dynamic libraries"
340345
echo "--disable-dfs Disable DAOS File System support even if found"
346+
echo "--enable-zondafs Enable zondafs (Zonda2 File System) support"
347+
echo "--disable-zondafs Disable zondafs support even if found"
341348
echo "--enable-asan Enable address sanitizer"
342349
echo "--seed-buckets= Number of seed buckets for the refill-buffer"
343350
echo "--disable-tls Disable __thread local storage"
@@ -2343,6 +2350,68 @@ EOF
23432350
fi
23442351
print_config "DAOS File System (dfs) Engine" "$dfs"
23452352

2353+
##########################################
2354+
# check for zondafs (Zonda2 File System)
2355+
if test "$zondafs" != "no" ; then
2356+
if test "$FIO_ZONDAFS_PATH" = "" ; then
2357+
FIO_ZONDAFS_PATH="/home/lanyan/zonda2"
2358+
fi
2359+
2360+
zondafs_base_path="$FIO_ZONDAFS_PATH"
2361+
zondafs_lib_path="$zondafs_base_path/deps"
2362+
zondafs_include_path="$zondafs_base_path/deps/file_client/include"
2363+
2364+
# Check if required library files exist
2365+
if test ! -f "$zondafs_lib_path/file_client/lib/libfile_client.a" ; then
2366+
if test "$zondafs" = "yes" ; then
2367+
feature_not_found "zondafs" "libfile_client.a not found at $zondafs_lib_path/file_client/lib/"
2368+
fi
2369+
zondafs="no"
2370+
elif test ! -f "$zondafs_lib_path/brpc/lib/libbrpc.a" ; then
2371+
if test "$zondafs" = "yes" ; then
2372+
feature_not_found "zondafs" "libbrpc.a not found at $zondafs_lib_path/brpc/lib/"
2373+
fi
2374+
zondafs="no"
2375+
elif test ! -d "$zondafs_include_path" ; then
2376+
if test "$zondafs" = "yes" ; then
2377+
feature_not_found "zondafs" "include directory not found at $zondafs_include_path"
2378+
fi
2379+
zondafs="no"
2380+
else
2381+
# Try to compile a test program
2382+
cat > $TMPC << EOF
2383+
#include <zonda_fs.h>
2384+
2385+
int main(int argc, char **argv)
2386+
{
2387+
zonda_fs_client_t *client = NULL;
2388+
zonda_fs_conn_config_t config = {0};
2389+
zonda_error_code_t code;
2390+
2391+
code = zonda_fs_client_new(&config, &client);
2392+
if (code == 0 && client != NULL) {
2393+
zonda_fs_client_destroy(client);
2394+
}
2395+
2396+
return 0;
2397+
}
2398+
EOF
2399+
zondafs_cflags="-I$zondafs_base_path/deps/brpc/include -I$zondafs_base_path/deps/file_client/include -I$zondafs_base_path/deps/fmt/include -I$zondafs_base_path/deps/isal/include -I$zondafs_base_path/deps/gflags/include -I$zondafs_base_path"
2400+
zondafs_ldflags="$zondafs_lib_path/file_client/lib/libfile_client.a $zondafs_lib_path/brpc/lib/libbrpc.a $zondafs_lib_path/fmt/lib/libfmt.a $zondafs_lib_path/isal/lib/libisal.a $zondafs_lib_path/gflags/lib/libgflags.a -lprotobuf -lrt -lcrypto -lssl -lleveldb"
2401+
2402+
if compile_prog "$zondafs_cflags" "$zondafs_ldflags" "zondafs"; then
2403+
zondafs="yes"
2404+
FIO_ZONDAFS_PATH="$zondafs_base_path"
2405+
else
2406+
if test "$zondafs" = "yes" ; then
2407+
feature_not_found "zondafs" "compilation test failed"
2408+
fi
2409+
zondafs="no"
2410+
fi
2411+
fi
2412+
fi
2413+
print_config "Zonda2 File System (zondafs) Engine" "$zondafs"
2414+
23462415
##########################################
23472416
# Check if we have libnfs (for userspace nfs support).
23482417
if test "$libnfs" != "no" ; then
@@ -3310,6 +3379,10 @@ fi
33103379
if test "$dfs" = "yes" ; then
33113380
output_sym "CONFIG_DFS"
33123381
fi
3382+
if test "$zondafs" = "yes" ; then
3383+
output_sym "CONFIG_ZONDAFS"
3384+
echo "FIO_ZONDAFS_PATH=$FIO_ZONDAFS_PATH" >> $config_host_mak
3385+
fi
33133386
if test "$march_set" = "no" && test "$build_native" = "yes" ; then
33143387
output_sym "CONFIG_BUILD_NATIVE"
33153388
fi

engines/zondafs.c

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
#include <stddef.h>
2+
#include <math.h>
3+
4+
#include "../fio.h"
5+
#include "../optgroup.h"
6+
7+
/* zonda_fs client headers */
8+
#include "zonda_fs_c.h"
9+
10+
struct zondafsio_data {
11+
zonda_fs_client_t* client;
12+
zonda_fs_file_t* file;
13+
};
14+
15+
struct zondafsio_options {
16+
char *master;
17+
char *cluster;
18+
char *client;
19+
char *fence_dir;
20+
char *log_path;
21+
char *role;
22+
char *ip;
23+
};
24+
25+
static struct fio_option options[] = {
26+
{
27+
.name = "master",
28+
.lname = "zonda2 fs master addr",
29+
.type = FIO_OPT_STR_STORE,
30+
.off1 = offsetof(struct zondafsio_options, master),
31+
.def = "",
32+
.help = "Master addr of the zonda2 fs",
33+
.category = FIO_OPT_C_ENGINE,
34+
.group = FIO_OPT_G_ZONDAFS,
35+
},
36+
{
37+
.name = "cluster",
38+
.lname = "zonda2 cluster id",
39+
.type = FIO_OPT_STR_STORE,
40+
.off1 = offsetof(struct zondafsio_options, cluster),
41+
.def = "",
42+
.help = "Cluster id of the zonda2 fs",
43+
.category = FIO_OPT_C_ENGINE,
44+
.group = FIO_OPT_G_ZONDAFS,
45+
},
46+
{
47+
.name = "client",
48+
.lname = "zonda2 client id",
49+
.type = FIO_OPT_STR_STORE,
50+
.off1 = offsetof(struct zondafsio_options, client),
51+
.def = "fio_client",
52+
.help = "Client id of the zonda2 fs",
53+
.category = FIO_OPT_C_ENGINE,
54+
.group = FIO_OPT_G_ZONDAFS,
55+
},
56+
{
57+
.name = "fence_dir",
58+
.lname = "zonda2 read/write fence_dir",
59+
.type = FIO_OPT_STR_STORE,
60+
.off1 = offsetof(struct zondafsio_options, fence_dir),
61+
.def = "",
62+
.help = "Fence dir id of the zonda2 fs",
63+
.category = FIO_OPT_C_ENGINE,
64+
.group = FIO_OPT_G_ZONDAFS,
65+
},
66+
{
67+
.name = "log_path",
68+
.lname = "zonda2 cpp client log path",
69+
.type = FIO_OPT_STR_STORE,
70+
.off1 = offsetof(struct zondafsio_options, log_path),
71+
.def = "./logs",
72+
.help = "Log path of the zonda2 fs",
73+
.category = FIO_OPT_C_ENGINE,
74+
.group = FIO_OPT_G_ZONDAFS,
75+
},
76+
{
77+
.name = "role",
78+
.lname = "zonda2 cpp client role",
79+
.type = FIO_OPT_STR_STORE,
80+
.off1 = offsetof(struct zondafsio_options, role),
81+
.def = "fio_role",
82+
.help = "Role of the zonda2 fs",
83+
.category = FIO_OPT_C_ENGINE,
84+
.group = FIO_OPT_G_ZONDAFS,
85+
},
86+
{
87+
.name = "ip",
88+
.lname = "zonda2 ip used by io fence",
89+
.type = FIO_OPT_STR_STORE,
90+
.off1 = offsetof(struct zondafsio_options, ip),
91+
.def = "127.0.0.1",
92+
.help = "The host ip of the zonda2 fence",
93+
.category = FIO_OPT_C_ENGINE,
94+
.group = FIO_OPT_G_ZONDAFS,
95+
},
96+
{
97+
.name = NULL,
98+
},
99+
};
100+
101+
static enum fio_q_status fio_zondafs_queue(struct thread_data *td,
102+
struct io_u *io_u)
103+
{
104+
struct zondafsio_data *zd = td->io_ops_data;
105+
zonda_fs_file_t* file = NULL;
106+
zonda_error_code_t code;
107+
int ret;
108+
unsigned long offset;
109+
unsigned long bytes_written = 0, bytes_read = 0;
110+
file = zd->file;
111+
112+
if (io_u->ddir == DDIR_READ) {
113+
code = zonda_fs_file_read_at(file, io_u->xfer_buflen, io_u->offset, io_u->xfer_buflen, &bytes_read);
114+
if(code != 0 && code != 23014) {
115+
io_u->error = EIO;
116+
return FIO_Q_COMPLETED;
117+
}
118+
if(bytes_read != io_u->xfer_buflen) {
119+
if(code != 23014) {
120+
io_u->error = EIO;
121+
}
122+
}
123+
} else if (io_u->ddir == DDIR_WRITE) {
124+
code = zonda_fs_file_append(file, io_u->xfer_buflen, io_u->xfer_buf, &bytes_written);
125+
if(code != 0 || bytes_written != io_u->xfer_buflen) {
126+
io_u->error = EIO;
127+
}
128+
} else {
129+
log_err("zondafs: Invalid I/O Operation: %d\n", io_u->ddir);
130+
io_u->error = EINVAL;
131+
}
132+
if (io_u->error)
133+
td_verror(td, io_u->error, "xfer");
134+
135+
return FIO_Q_COMPLETED;
136+
}
137+
138+
int fio_zondafs_open_file(struct thread_data *td, struct fio_file *f)
139+
{
140+
struct zondafsio_data *zd = td->io_ops_data;
141+
142+
zonda_fs_file_t* file = NULL;
143+
zonda_error_code_t code;
144+
145+
uint32_t flags = ZONDA_FS_OPEN_FLAGS_RDWR | ZONDA_FS_OPEN_FLAGS_CREAT;
146+
code = zonda_fs_client_open(zd->client, f->file_name, flags, &file);
147+
if(code != 0) {
148+
log_err("zondafs: unable to open");
149+
return code;
150+
}
151+
zd->file = file;
152+
return 0;
153+
}
154+
155+
int fio_zondafs_close_file(struct thread_data *td, struct fio_file *f)
156+
{
157+
struct zondafsio_data *zd = td->io_ops_data;
158+
159+
zonda_fs_file_close(zd->file);
160+
zonda_fs_file_destroy(zd->file);
161+
zonda_fs_client_destroy(zd->client);
162+
return 0;
163+
}
164+
165+
static int fio_zondafs_setup(struct thread_data *td)
166+
{
167+
struct zondafsio_data *zd;
168+
struct fio_file *f;
169+
int i;
170+
uint64_t file_size, total_file_size;
171+
172+
if (!td->io_ops_data) {
173+
zd = calloc(1, sizeof(*zd));
174+
td->io_ops_data = zd;
175+
}
176+
177+
total_file_size = 0;
178+
file_size = 0;
179+
180+
for_each_file(td, f, i) {
181+
if(!td->o.file_size_low) {
182+
file_size = floor(td->o.size / td->o.nr_files);
183+
total_file_size += file_size;
184+
}
185+
else if (td->o.file_size_low == td->o.file_size_high)
186+
file_size = td->o.file_size_low;
187+
else {
188+
file_size = get_rand_file_size(td);
189+
}
190+
f->real_file_size = file_size;
191+
}
192+
return 0;
193+
}
194+
195+
static int fio_zondafs_init(struct thread_data *td)
196+
{
197+
struct zondafsio_data *zd = td->io_ops_data;
198+
struct zondafsio_options *option = td->eo;
199+
200+
zonda_fs_client_t* client = NULL;
201+
zonda_error_code_t code;
202+
203+
zonda_fs_conn_config_t config = {
204+
.master_addr = option->master,
205+
.cluster_id = option->cluster,
206+
.client_id = option->client,
207+
.fence_dir = option->fence_dir,
208+
.log_path = option->log_path,
209+
.role = option->role,
210+
.ip = option->ip,
211+
};
212+
213+
code = zonda_fs_client_new(&config, &client);
214+
if(code != 0) {
215+
log_err("zondafs: unable to new client\n");
216+
return EINVAL;
217+
}
218+
zd->client = client;
219+
220+
code = zonda_fs_client_fence_directory(client, option->fence_dir);
221+
if(code != 0) {
222+
log_err("zondafs: unable to fence dir\n");
223+
return EINVAL;
224+
}
225+
return 0;
226+
}
227+
228+
FIO_STATIC struct ioengine_ops ioengine = {
229+
.name = "zondafs",
230+
.version = FIO_IOOPS_VERSION,
231+
.flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NODISKUTIL,
232+
.setup = fio_zondafs_setup,
233+
.init = fio_zondafs_init,
234+
.queue = fio_zondafs_queue,
235+
.open_file = fio_zondafs_open_file,
236+
.close_file = fio_zondafs_close_file,
237+
.option_struct_size = sizeof(struct zondafsio_options),
238+
.options = options,
239+
};
240+
241+
static void fio_init fio_zondafs_register(void)
242+
{
243+
register_ioengine(&ioengine);
244+
}
245+
246+
static void fio_exit fio_zondafs_unregister(void)
247+
{
248+
unregister_ioengine(&ioengine);
249+
}

optgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum opt_category_group {
7373
__FIO_OPT_G_WINDOWSAIO,
7474
__FIO_OPT_G_XNVME,
7575
__FIO_OPT_G_LIBBLKIO,
76+
__FIO_OPT_G_ZONDAFS,
7677

7778
FIO_OPT_G_RATE = (1ULL << __FIO_OPT_G_RATE),
7879
FIO_OPT_G_ZONE = (1ULL << __FIO_OPT_G_ZONE),
@@ -120,6 +121,7 @@ enum opt_category_group {
120121
FIO_OPT_G_WINDOWSAIO = (1ULL << __FIO_OPT_G_WINDOWSAIO),
121122
FIO_OPT_G_XNVME = (1ULL << __FIO_OPT_G_XNVME),
122123
FIO_OPT_G_LIBBLKIO = (1ULL << __FIO_OPT_G_LIBBLKIO),
124+
FIO_OPT_G_ZONDAFS = (1ULL << __FIO_OPT_G_ZONDAFS),
123125
};
124126

125127
extern const struct opt_group *opt_group_from_mask(uint64_t *mask);

0 commit comments

Comments
 (0)