It's better to build it with C, not C++
parent
ee6cd9ef9f
commit
c2e9136111
4
Makefile
4
Makefile
|
@ -2,5 +2,5 @@ CXXFLAGS := -g -O3 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-po
|
||||||
all: libfio_fileserver.so
|
all: libfio_fileserver.so
|
||||||
clean:
|
clean:
|
||||||
rm libfio_fileserver.so
|
rm libfio_fileserver.so
|
||||||
libfio_fileserver.so: fio_fileserver.cpp
|
libfio_fileserver.so: fio_fileserver.c
|
||||||
g++ $(CXXFLAGS) -shared -o $@ $<
|
gcc $(CXXFLAGS) -shared -o $@ $<
|
||||||
|
|
|
@ -4,36 +4,33 @@
|
||||||
// USAGE: fio -name=test -ioengine=./libfio_fileserver.so -chunk_size=256K \
|
// USAGE: fio -name=test -ioengine=./libfio_fileserver.so -chunk_size=256K \
|
||||||
// -directory=/home/bench -size=10G [-direct=1] [-fsync_on_close=1] [-sync=1] [-dir_levels=2] [-subdirs_per_dir=64]
|
// -directory=/home/bench -size=10G [-direct=1] [-fsync_on_close=1] [-sync=1] [-dir_levels=2] [-subdirs_per_dir=64]
|
||||||
|
|
||||||
#ifndef _LARGEFILE64_SOURCE
|
|
||||||
#define _LARGEFILE64_SOURCE
|
#define _LARGEFILE64_SOURCE
|
||||||
#endif
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#define CONFIG_HAVE_GETTID
|
#define CONFIG_HAVE_GETTID
|
||||||
|
#define CONFIG_SYNC_FILE_RANGE
|
||||||
#define CONFIG_PWRITEV2
|
#define CONFIG_PWRITEV2
|
||||||
#include "fio/fio.h"
|
#include "fio/fio.h"
|
||||||
#include "fio/optgroup.h"
|
#include "fio/optgroup.h"
|
||||||
}
|
|
||||||
|
|
||||||
struct sec_data
|
struct sec_data
|
||||||
{
|
{
|
||||||
int __pad;
|
int __pad[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sec_options
|
struct sec_options
|
||||||
{
|
{
|
||||||
int __pad;
|
int __pad;
|
||||||
int __pad2;
|
int __pad2;
|
||||||
int dir_levels = 2;
|
int dir_levels;
|
||||||
int subdirs_per_dir = 64;
|
int subdirs_per_dir;
|
||||||
int chunk_size = 262144;
|
int chunk_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct fio_option options[] = {
|
static struct fio_option options[] = {
|
||||||
|
@ -72,11 +69,19 @@ static struct fio_option options[] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sec_setup(struct thread_data *td)
|
static int sec_init(struct thread_data *td)
|
||||||
{
|
{
|
||||||
sec_data *bsd;
|
struct sec_data *bsd;
|
||||||
|
|
||||||
bsd = new sec_data;
|
struct sec_options *opt = (struct sec_options*)td->eo;
|
||||||
|
if (!td->o.directory || opt->chunk_size <= 0 || opt->dir_levels > 0 && opt->subdirs_per_dir <= 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "USAGE: fio -name=test -ioengine=./libfio_fileserver.so"
|
||||||
|
" -chunk_size=256K -directory=/home/bench -size=10G [-direct=1] [-fsync_on_close=1] [-sync=1] [-dir_levels=2] [-subdirs_per_dir=64]\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bsd = malloc(sizeof(struct sec_data));
|
||||||
if (!bsd)
|
if (!bsd)
|
||||||
{
|
{
|
||||||
td_verror(td, errno, "calloc");
|
td_verror(td, errno, "calloc");
|
||||||
|
@ -96,80 +101,74 @@ static int sec_setup(struct thread_data *td)
|
||||||
|
|
||||||
static void sec_cleanup(struct thread_data *td)
|
static void sec_cleanup(struct thread_data *td)
|
||||||
{
|
{
|
||||||
sec_data *bsd = (sec_data*)td->io_ops_data;
|
struct sec_data *bsd = (struct sec_data*)td->io_ops_data;
|
||||||
if (bsd)
|
if (bsd)
|
||||||
{
|
{
|
||||||
delete bsd;
|
free(bsd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sec_init(struct thread_data *td)
|
|
||||||
{
|
|
||||||
sec_options *opt = (sec_options*)td->eo;
|
|
||||||
if (!td->o.directory || opt->chunk_size <= 0 || opt->dir_levels > 0 && opt->subdirs_per_dir <= 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "USAGE: fio -name=test -ioengine=./libfio_fileserver.so"
|
|
||||||
" -chunk_size=256K -directory=/home/bench -size=10G [-direct=1] [-fsync_on_close=1] [-sync=1] [-dir_levels=2] [-subdirs_per_dir=64]\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Begin read or write request. */
|
/* Begin read or write request. */
|
||||||
static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io)
|
static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io)
|
||||||
{
|
{
|
||||||
sec_options *opt = (sec_options*)td->eo;
|
struct sec_options *opt = (struct sec_options*)td->eo;
|
||||||
sec_data *bsd = (sec_data*)td->io_ops_data;
|
struct sec_data *bsd = (struct sec_data*)td->io_ops_data;
|
||||||
int r;
|
int i, r, pos;
|
||||||
|
int dirname_len, filename_buf;
|
||||||
|
char *file_name;
|
||||||
|
struct stat statbuf;
|
||||||
|
uint64_t file_idx;
|
||||||
|
|
||||||
fio_ro_check(td, io);
|
fio_ro_check(td, io);
|
||||||
|
|
||||||
io->engine_data = bsd;
|
io->engine_data = bsd;
|
||||||
|
|
||||||
uint64_t file_num = io->offset / opt->chunk_size;
|
file_idx = io->offset / opt->chunk_size;
|
||||||
struct stat statbuf;
|
dirname_len = strlen(td->o.directory);
|
||||||
std::string file_name(td->o.directory);
|
filename_buf = dirname_len + opt->subdirs_per_dir * 3 + 256;
|
||||||
char buf[128];
|
file_name = malloc(filename_buf);
|
||||||
uint64_t file_idx = file_num;
|
if (!file_name)
|
||||||
for (int i = 0; i < opt->dir_levels; i++)
|
exit(1);
|
||||||
|
strncpy(file_name, td->o.directory, filename_buf);
|
||||||
|
pos = dirname_len;
|
||||||
|
for (i = 0; i < opt->dir_levels; i++)
|
||||||
{
|
{
|
||||||
int subdir = file_idx % opt->subdirs_per_dir;
|
int subdir = file_idx % opt->subdirs_per_dir;
|
||||||
file_idx /= opt->subdirs_per_dir;
|
file_idx /= opt->subdirs_per_dir;
|
||||||
snprintf(buf, sizeof(buf), "%02x", subdir);
|
pos += snprintf(file_name + pos, filename_buf - pos - 1, "/%02x", subdir);
|
||||||
file_name += "/"+std::string(buf);
|
r = stat(file_name, &statbuf);
|
||||||
r = stat(file_name.c_str(), &statbuf);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
{
|
{
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
{
|
{
|
||||||
if (io->ddir == DDIR_WRITE)
|
if (io->ddir == DDIR_WRITE)
|
||||||
{
|
{
|
||||||
r = mkdir(file_name.c_str(), 0777);
|
r = mkdir(file_name, 0777);
|
||||||
if (r < 0 && errno != EEXIST)
|
if (r < 0 && errno != EEXIST)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error mkdir(%s): %d (%s)\n", file_name.c_str(), errno, strerror(errno));
|
fprintf(stderr, "Error mkdir(%s): %d (%s)\n", file_name, errno, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error stat(%s): %d (%s)\n", file_name.c_str(), errno, strerror(errno));
|
fprintf(stderr, "Error stat(%s): %d (%s)\n", file_name, errno, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf(buf, sizeof(buf), "%02lx", file_idx);
|
pos += snprintf(file_name + pos, filename_buf - pos - 1, "/%02lx", file_idx);
|
||||||
file_name += "/"+std::string(buf);
|
file_name[pos] = 0;
|
||||||
|
|
||||||
int fd = open(file_name.c_str(),
|
int fd = open(file_name,
|
||||||
(io->ddir == DDIR_WRITE ? (O_CREAT|O_RDWR) : O_RDONLY)
|
(io->ddir == DDIR_WRITE ? (O_CREAT|O_RDWR) : O_RDONLY)
|
||||||
| (td->o.sync_io ? O_SYNC : 0)
|
| (td->o.sync_io ? O_SYNC : 0)
|
||||||
| (td->o.odirect ? O_DIRECT : 0)
|
| (td->o.odirect ? O_DIRECT : 0)
|
||||||
);
|
);
|
||||||
if (fd < 0 && errno != ENOENT)
|
if (fd < 0 && errno != ENOENT)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error open(%s): %d (%s)\n", file_name.c_str(), errno, strerror(errno));
|
fprintf(stderr, "Error open(%s): %d (%s)\n", file_name, errno, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (io->ddir == DDIR_READ)
|
if (io->ddir == DDIR_READ)
|
||||||
|
@ -201,6 +200,7 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io)
|
||||||
io->error = EINVAL;
|
io->error = EINVAL;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
free(file_name);
|
||||||
return FIO_Q_COMPLETED;
|
return FIO_Q_COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,6 @@ struct ioengine_ops ioengine = {
|
||||||
.name = "fileserver",
|
.name = "fileserver",
|
||||||
.version = FIO_IOOPS_VERSION,
|
.version = FIO_IOOPS_VERSION,
|
||||||
.flags = FIO_MEMALIGN | FIO_DISKLESSIO | FIO_NOEXTEND,
|
.flags = FIO_MEMALIGN | FIO_DISKLESSIO | FIO_NOEXTEND,
|
||||||
.setup = sec_setup,
|
|
||||||
.init = sec_init,
|
.init = sec_init,
|
||||||
.queue = sec_queue,
|
.queue = sec_queue,
|
||||||
.getevents = sec_getevents,
|
.getevents = sec_getevents,
|
Loading…
Reference in New Issue