Skip to content

Commit

Permalink
skip fallocate on Mac, olcf#23
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang2 committed Aug 30, 2018
1 parent fb10428 commit ccafd5b
Showing 1 changed file with 33 additions and 46 deletions.
79 changes: 33 additions & 46 deletions lib/posix.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#include "lcio.h"

Expand All @@ -12,7 +12,7 @@
* 'void register_ioengine(lcio_job_t*)' function
*/

void* posix_create(char* fn, lcio_job_t* job){
void* posix_create(char* fn, lcio_job_t* job) {
int* fd;
unsigned int flags = O_CREAT | O_RDWR | O_TRUNC;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
Expand All @@ -22,7 +22,7 @@ void* posix_create(char* fn, lcio_job_t* job){
return (void*)fd;
}

void* posix_open(char* fn, lcio_job_t* job){
void* posix_open(char* fn, lcio_job_t* job) {
int* fd;
int flags = O_CREAT | O_APPEND | O_RDWR;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
Expand All @@ -31,88 +31,75 @@ void* posix_open(char* fn, lcio_job_t* job){
return (void*)fd;
}

void posix_close(void* fdes, lcio_job_t* job){

void posix_close(void* fdes, lcio_job_t* job) {
close(*(int*)fdes);
free(fdes);
}

void posix_delete(char* fn, lcio_job_t* job){
unlink(fn);
}
void posix_delete(char* fn, lcio_job_t* job) { unlink(fn); }

void *posix_write(void *fdes, lcio_job_t *job, off_t flag) {
ssize_t *rv;
void* posix_write(void* fdes, lcio_job_t* job, off_t flag) {
ssize_t* rv;
unsigned long long i;
rv = malloc(sizeof(ssize_t));
*rv = 0;

if(job->ftrunc){
#ifdef HAVE_POSIX_FALLOCATE
if (job->ftrunc) {
*rv = posix_fallocate(*(int*)fdes, 0, flag);
return rv;
}
#endif

if(flag == 0) {
if (flag == 0) {
for (i = 0; i < job->blk_sz; i += job->buf_sz) {
*rv += write(*(int *) fdes, job->buffer, job->buf_sz);
*rv += write(*(int*)fdes, job->buffer, job->buf_sz);
}
}
else {
} else {
unsigned long long count = flag / job->buf_sz;
unsigned long long rem = flag % job->buf_sz;
for(i = 0; i < count; i += 1) {
*rv += write(*(int *) fdes, job->buffer, job->buf_sz);
for (i = 0; i < count; i += 1) {
*rv += write(*(int*)fdes, job->buffer, job->buf_sz);
}
*rv += write(*(int *) fdes, job->buffer, rem);
*rv += write(*(int*)fdes, job->buffer, rem);
}

return (void*)rv;
}

void* posix_read(void* fdes, lcio_job_t* job){
ssize_t *rv;
void* posix_read(void* fdes, lcio_job_t* job) {
ssize_t* rv;
unsigned long long i;
rv = malloc(sizeof(ssize_t));
*rv = 0;
for (i = 0; i < job->blk_sz; i += job->buf_sz) {
*rv += read(*(int *) fdes, job->buffer, job->buf_sz);
*rv += read(*(int*)fdes, job->buffer, job->buf_sz);
}
return (void*)rv;
}

void* posix_stat(void* fn, lcio_job_t* job){
void* posix_stat(void* fn, lcio_job_t* job) {
struct stat statbuf;
int* err;

err = malloc(sizeof(int));
*err = stat((char*)fn, &statbuf);
//if(statbuf.st_size != job->blk_sz && job->mode == 'U'){
// if(statbuf.st_size != job->blk_sz && job->mode == 'U'){
// FILE_WARN((char*)fn, statbuf.st_size , job->blk_sz);
//}
return (void*)err;
}

void posix_fsync(void* fdes, lcio_job_t* job){
fsync(*(int*)fdes);
}


static lcio_engine_t posix_ioengine = {
.name = "POSIX",
.create = posix_create,
.open = posix_open,
.close = posix_close,
.remove = posix_delete,
.write = posix_write,
.read = posix_read,
.fsync = posix_fsync,
.stat = posix_stat
};

void register_ioengine(lcio_job_t *job){
job->ioengine = &posix_ioengine;
}


void posix_fsync(void* fdes, lcio_job_t* job) { fsync(*(int*)fdes); }

static lcio_engine_t posix_ioengine = {.name = "POSIX",
.create = posix_create,
.open = posix_open,
.close = posix_close,
.remove = posix_delete,
.write = posix_write,
.read = posix_read,
.fsync = posix_fsync,
.stat = posix_stat};

void register_ioengine(lcio_job_t* job) { job->ioengine = &posix_ioengine; }

0 comments on commit ccafd5b

Please sign in to comment.