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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
|
/**
* FIO engine for DAOS File System (dfs).
*
* (C) Copyright 2020-2021 Intel Corporation.
*/
#include <fio.h>
#include <optgroup.h>
#include <daos.h>
#include <daos_fs.h>
static bool daos_initialized;
static int num_threads;
static pthread_mutex_t daos_mutex = PTHREAD_MUTEX_INITIALIZER;
daos_handle_t poh; /* pool handle */
daos_handle_t coh; /* container handle */
daos_oclass_id_t cid = OC_UNKNOWN; /* object class */
dfs_t *daosfs; /* dfs mount reference */
struct daos_iou {
struct io_u *io_u;
daos_event_t ev;
d_sg_list_t sgl;
d_iov_t iov;
daos_size_t size;
bool complete;
};
struct daos_data {
daos_handle_t eqh;
dfs_obj_t *obj;
struct io_u **io_us;
int queued;
int num_ios;
};
struct daos_fio_options {
void *pad;
char *pool; /* Pool UUID */
char *cont; /* Container UUID */
daos_size_t chsz; /* Chunk size */
char *oclass; /* object class */
#if !defined(DAOS_API_VERSION_MAJOR) || DAOS_API_VERSION_MAJOR < 1
char *svcl; /* service replica list, deprecated */
#endif
};
static struct fio_option options[] = {
{
.name = "pool",
.lname = "pool uuid or label",
.type = FIO_OPT_STR_STORE,
.off1 = offsetof(struct daos_fio_options, pool),
.help = "DAOS pool uuid or label",
.category = FIO_OPT_C_ENGINE,
.group = FIO_OPT_G_DFS,
},
{
.name = "cont",
.lname = "container uuid or label",
.type = FIO_OPT_STR_STORE,
.off1 = offsetof(struct daos_fio_options, cont),
.help = "DAOS container uuid or label",
.category = FIO_OPT_C_ENGINE,
.group = FIO_OPT_G_DFS,
},
{
.name = "chunk_size",
.lname = "DFS chunk size",
.type = FIO_OPT_ULL,
.off1 = offsetof(struct daos_fio_options, chsz),
.help = "DFS chunk size in bytes",
.def = "0", /* use container default */
.category = FIO_OPT_C_ENGINE,
.group = FIO_OPT_G_DFS,
},
{
.name = "object_class",
.lname = "object class",
.type = FIO_OPT_STR_STORE,
.off1 = offsetof(struct daos_fio_options, oclass),
.help = "DAOS object class",
.category = FIO_OPT_C_ENGINE,
.group = FIO_OPT_G_DFS,
},
#if !defined(DAOS_API_VERSION_MAJOR) || DAOS_API_VERSION_MAJOR < 1
{
.name = "svcl",
.lname = "List of service ranks",
.type = FIO_OPT_STR_STORE,
.off1 = offsetof(struct daos_fio_options, svcl),
.help = "List of pool replicated service ranks",
.category = FIO_OPT_C_ENGINE,
.group = FIO_OPT_G_DFS,
},
#endif
{
.name = NULL,
},
};
static int daos_fio_global_init(struct thread_data *td)
{
struct daos_fio_options *eo = td->eo;
daos_pool_info_t pool_info;
daos_cont_info_t co_info;
int rc = 0;
#if !defined(DAOS_API_VERSION_MAJOR) || DAOS_API_VERSION_MAJOR < 1
if (!eo->pool || !eo->cont || !eo->svcl) {
#else
if (!eo->pool || !eo->cont) {
#endif
log_err("Missing required DAOS options\n");
return EINVAL;
}
rc = daos_init();
if (rc != -DER_ALREADY && rc) {
log_err("Failed to initialize daos %d\n", rc);
td_verror(td, rc, "daos_init");
return rc;
}
#if !defined(DAOS_API_VERSION_MAJOR) || \
(DAOS_API_VERSION_MAJOR == 1 && DAOS_API_VERSION_MINOR < 3)
uuid_t pool_uuid, co_uuid;
rc = uuid_parse(eo->pool, pool_uuid);
if (rc) {
log_err("Failed to parse 'Pool uuid': %s\n", eo->pool);
td_verror(td, EINVAL, "uuid_parse(eo->pool)");
return EINVAL;
}
rc = uuid_parse(eo->cont, co_uuid);
if (rc) {
log_err("Failed to parse 'Cont uuid': %s\n", eo->cont);
td_verror(td, EINVAL, "uuid_parse(eo->cont)");
return EINVAL;
}
#endif
/* Connect to the DAOS pool */
#if !defined(DAOS_API_VERSION_MAJOR) || DAOS_API_VERSION_MAJOR < 1
d_rank_list_t *svcl = NULL;
svcl = daos_rank_list_parse(eo->svcl, ":");
if (svcl == NULL) {
log_err("Failed to parse svcl\n");
td_verror(td, EINVAL, "daos_rank_list_parse");
return EINVAL;
}
rc = daos_pool_connect(pool_uuid, NULL, svcl, DAOS_PC_RW,
&poh, &pool_info, NULL);
d_rank_list_free(svcl);
#elif (DAOS_API_VERSION_MAJOR == 1 && DAOS_API_VERSION_MINOR < 3)
rc = daos_pool_connect(pool_uuid, NULL, DAOS_PC_RW, &poh, &pool_info,
NULL);
#else
rc = daos_pool_connect(eo->pool, NULL, DAOS_PC_RW, &poh, &pool_info,
NULL);
#endif
if (rc) {
log_err("Failed to connect to pool %d\n", rc);
td_verror(td, rc, "daos_pool_connect");
return rc;
}
/* Open the DAOS container */
#if !defined(DAOS_API_VERSION_MAJOR) || \
(DAOS_API_VERSION_MAJOR == 1 && DAOS_API_VERSION_MINOR < 3)
rc = daos_cont_open(poh, co_uuid, DAOS_COO_RW, &coh, &co_info, NULL);
#else
rc = daos_cont_open(poh, eo->cont, DAOS_COO_RW, &coh, &co_info, NULL);
#endif
if (rc) {
log_err("Failed to open container: %d\n", rc);
td_verror(td, rc, "daos_cont_open");
(void)daos_pool_disconnect(poh, NULL);
return rc;
}
/* Mount encapsulated filesystem */
rc = dfs_mount(poh, coh, O_RDWR, &daosfs);
if (rc) {
log_err("Failed to mount DFS namespace: %d\n", rc);
td_verror(td, rc, "dfs_mount");
(void)daos_pool_disconnect(poh, NULL);
(void)daos_cont_close(coh, NULL);
return rc;
}
/* Retrieve object class to use, if specified */
if (eo->oclass)
cid = daos_oclass_name2id(eo->oclass);
return 0;
}
static int daos_fio_global_cleanup()
{
int rc;
int ret = 0;
rc = dfs_umount(daosfs);
if (rc) {
log_err("failed to umount dfs: %d\n", rc);
ret = rc;
}
rc = daos_cont_close(coh, NULL);
if (rc) {
log_err("failed to close container: %d\n", rc);
if (ret == 0)
ret = rc;
}
rc = daos_pool_disconnect(poh, NULL);
if (rc) {
log_err("failed to disconnect pool: %d\n", rc);
if (ret == 0)
ret = rc;
}
rc = daos_fini();
if (rc) {
log_err("failed to finalize daos: %d\n", rc);
if (ret == 0)
ret = rc;
}
return ret;
}
static int daos_fio_setup(struct thread_data *td)
{
return 0;
}
static int daos_fio_init(struct thread_data *td)
{
struct daos_data *dd;
int rc = 0;
pthread_mutex_lock(&daos_mutex);
dd = malloc(sizeof(*dd));
if (dd == NULL) {
log_err("Failed to allocate DAOS-private data\n");
rc = ENOMEM;
goto out;
}
dd->queued = 0;
dd->num_ios = td->o.iodepth;
dd->io_us = calloc(dd->num_ios, sizeof(struct io_u *));
if (dd->io_us == NULL) {
log_err("Failed to allocate IO queue\n");
rc = ENOMEM;
goto out;
}
/* initialize DAOS stack if not already up */
if (!daos_initialized) {
rc = daos_fio_global_init(td);
if (rc)
goto out;
daos_initialized = true;
}
rc = daos_eq_create(&dd->eqh);
if (rc) {
log_err("Failed to create event queue: %d\n", rc);
td_verror(td, rc, "daos_eq_create");
goto out;
}
td->io_ops_data = dd;
num_threads++;
out:
if (rc) {
if (dd) {
free(dd->io_us);
free(dd);
}
if (num_threads == 0 && daos_initialized) {
/* don't clobber error return value */
(void)daos_fio_global_cleanup();
daos_initialized = false;
}
}
pthread_mutex_unlock(&daos_mutex);
return rc;
}
static void daos_fio_cleanup(struct thread_data *td)
{
struct daos_data *dd = td->io_ops_data;
int rc;
if (dd == NULL)
return;
rc = daos_eq_destroy(dd->eqh, DAOS_EQ_DESTROY_FORCE);
if (rc < 0) {
log_err("failed to destroy event queue: %d\n", rc);
td_verror(td, rc, "daos_eq_destroy");
}
free(dd->io_us);
free(dd);
pthread_mutex_lock(&daos_mutex);
num_threads--;
if (daos_initialized && num_threads == 0) {
int ret;
ret = daos_fio_global_cleanup();
if (ret < 0 && rc == 0) {
log_err("failed to clean up: %d\n", ret);
td_verror(td, ret, "daos_fio_global_cleanup");
}
daos_initialized = false;
}
pthread_mutex_unlock(&daos_mutex);
}
static int daos_fio_get_file_size(struct thread_data *td, struct fio_file *f)
{
char *file_name = f->file_name;
struct stat stbuf = {0};
int rc;
dprint(FD_FILE, "dfs stat %s\n", f->file_name);
if (!daos_initialized)
return 0;
rc = dfs_stat(daosfs, NULL, file_name, &stbuf);
if (rc) {
log_err("Failed to stat %s: %d\n", f->file_name, rc);
td_verror(td, rc, "dfs_stat");
return rc;
}
f->real_file_size = stbuf.st_size;
return 0;
}
static int daos_fio_close(struct thread_data *td, struct fio_file *f)
{
struct daos_data *dd = td->io_ops_data;
int rc;
dprint(FD_FILE, "dfs release %s\n", f->file_name);
rc = dfs_release(dd->obj);
if (rc) {
log_err("Failed to release %s: %d\n", f->file_name, rc);
td_verror(td, rc, "dfs_release");
return rc;
}
return 0;
}
static int daos_fio_open(struct thread_data *td, struct fio_file *f)
{
struct daos_data *dd = td->io_ops_data;
struct daos_fio_options *eo = td->eo;
int flags = 0;
int rc;
dprint(FD_FILE, "dfs open %s (%s/%d/%d)\n",
f->file_name, td_write(td) & !read_only ? "rw" : "r",
td->o.create_on_open, td->o.allow_create);
if (td->o.create_on_open && td->o.allow_create)
flags |= O_CREAT;
if (td_write(td)) {
if (!read_only)
flags |= O_RDWR;
if (td->o.allow_create)
flags |= O_CREAT;
} else if (td_read(td)) {
flags |= O_RDONLY;
}
rc = dfs_open(daosfs, NULL, f->file_name,
S_IFREG | S_IRUSR | S_IWUSR,
flags, cid, eo->chsz, NULL, &dd->obj);
if (rc) {
log_err("Failed to open %s: %d\n", f->file_name, rc);
td_verror(td, rc, "dfs_open");
return rc;
}
return 0;
}
static int daos_fio_unlink(struct thread_data *td, struct fio_file *f)
{
int rc;
dprint(FD_FILE, "dfs remove %s\n", f->file_name);
rc = dfs_remove(daosfs, NULL, f->file_name, false, NULL);
if (rc) {
log_err("Failed to remove %s: %d\n", f->file_name, rc);
td_verror(td, rc, "dfs_remove");
return rc;
}
return 0;
}
static int daos_fio_invalidate(struct thread_data *td, struct fio_file *f)
{
dprint(FD_FILE, "dfs invalidate %s\n", f->file_name);
return 0;
}
static void daos_fio_io_u_free(struct thread_data *td, struct io_u *io_u)
{
struct daos_iou *io = io_u->engine_data;
if (io) {
io_u->engine_data = NULL;
free(io);
}
}
static int daos_fio_io_u_init(struct thread_data *td, struct io_u *io_u)
{
struct daos_iou *io;
io = malloc(sizeof(struct daos_iou));
if (!io) {
td_verror(td, ENOMEM, "malloc");
return ENOMEM;
}
io->io_u = io_u;
io_u->engine_data = io;
return 0;
}
static struct io_u * daos_fio_event(struct thread_data *td, int event)
{
struct daos_data *dd = td->io_ops_data;
return dd->io_us[event];
}
static int daos_fio_getevents(struct thread_data *td, unsigned int min,
unsigned int max, const struct timespec *t)
{
struct daos_data *dd = td->io_ops_data;
daos_event_t *evp[max];
unsigned int events = 0;
int i;
int rc;
while (events < min) {
rc = daos_eq_poll(dd->eqh, 0, DAOS_EQ_NOWAIT, max, evp);
if (rc < 0) {
log_err("Event poll failed: %d\n", rc);
td_verror(td, rc, "daos_eq_poll");
return events;
}
for (i = 0; i < rc; i++) {
struct daos_iou *io;
struct io_u *io_u;
io = container_of(evp[i], struct daos_iou, ev);
if (io->complete)
log_err("Completion on already completed I/O\n");
io_u = io->io_u;
if (io->ev.ev_error)
io_u->error = io->ev.ev_error;
else
io_u->resid = 0;
dd->io_us[events] = io_u;
dd->queued--;
daos_event_fini(&io->ev);
io->complete = true;
events++;
}
}
dprint(FD_IO, "dfs eq_pool returning %d (%u/%u)\n", events, min, max);
return events;
}
static enum fio_q_status daos_fio_queue(struct thread_data *td,
struct io_u *io_u)
{
struct daos_data *dd = td->io_ops_data;
struct daos_iou *io = io_u->engine_data;
daos_off_t offset = io_u->offset;
int rc;
if (dd->queued == td->o.iodepth)
return FIO_Q_BUSY;
io->sgl.sg_nr = 1;
io->sgl.sg_nr_out = 0;
d_iov_set(&io->iov, io_u->xfer_buf, io_u->xfer_buflen);
io->sgl.sg_iovs = &io->iov;
io->size = io_u->xfer_buflen;
io->complete = false;
rc = daos_event_init(&io->ev, dd->eqh, NULL);
if (rc) {
log_err("Event init failed: %d\n", rc);
io_u->error = rc;
return FIO_Q_COMPLETED;
}
switch (io_u->ddir) {
case DDIR_WRITE:
rc = dfs_write(daosfs, dd->obj, &io->sgl, offset, &io->ev);
if (rc) {
log_err("dfs_write failed: %d\n", rc);
io_u->error = rc;
return FIO_Q_COMPLETED;
}
break;
case DDIR_READ:
rc = dfs_read(daosfs, dd->obj, &io->sgl, offset, &io->size,
&io->ev);
if (rc) {
log_err("dfs_read failed: %d\n", rc);
io_u->error = rc;
return FIO_Q_COMPLETED;
}
break;
case DDIR_SYNC:
io_u->error = 0;
return FIO_Q_COMPLETED;
default:
dprint(FD_IO, "Invalid IO type: %d\n", io_u->ddir);
io_u->error = -DER_INVAL;
return FIO_Q_COMPLETED;
}
dd->queued++;
return FIO_Q_QUEUED;
}
static int daos_fio_prep(struct thread_data fio_unused *td, struct io_u *io_u)
{
return 0;
}
/* ioengine_ops for get_ioengine() */
FIO_STATIC struct ioengine_ops ioengine = {
.name = "dfs",
.version = FIO_IOOPS_VERSION,
.flags = FIO_DISKLESSIO | FIO_NODISKUTIL,
.setup = daos_fio_setup,
.init = daos_fio_init,
.prep = daos_fio_prep,
.cleanup = daos_fio_cleanup,
.open_file = daos_fio_open,
.invalidate = daos_fio_invalidate,
.get_file_size = daos_fio_get_file_size,
.close_file = daos_fio_close,
.unlink_file = daos_fio_unlink,
.queue = daos_fio_queue,
.getevents = daos_fio_getevents,
.event = daos_fio_event,
.io_u_init = daos_fio_io_u_init,
.io_u_free = daos_fio_io_u_free,
.option_struct_size = sizeof(struct daos_fio_options),
.options = options,
};
static void fio_init fio_dfs_register(void)
{
register_ioengine(&ioengine);
}
static void fio_exit fio_dfs_unregister(void)
{
unregister_ioengine(&ioengine);
}
|