X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffb-direct.c;h=b82faa9157a05aabcdca4c373ba658316df5d629;hb=1386442ebc5b681b0ded431880198e3beb6da483;hp=32f17be828423169ec3ce3b05bc4c28f288d41fb;hpb=f3625d622964cf99300ceb7e499b99ebbce9fe69;p=libucw.git diff --git a/lib/fb-direct.c b/lib/fb-direct.c index 32f17be8..b82faa91 100644 --- a/lib/fb-direct.c +++ b/lib/fb-direct.c @@ -37,17 +37,11 @@ #include #include -static uns fbdir_cheat; -static uns fbdir_buffer_size = 65536; -static uns fbdir_read_ahead = 1; -static uns fbdir_write_back = 1; +uns fbdir_cheat; static struct cf_section fbdir_cf = { CF_ITEMS { CF_UNS("Cheat", &fbdir_cheat), - CF_UNS("BufferSize", &fbdir_buffer_size), - CF_UNS("ReadAhead", &fbdir_read_ahead), - CF_UNS("WriteBack", &fbdir_write_back), CF_END } }; @@ -195,7 +189,7 @@ fbdir_spout(struct fastbuf *f) r->len = ALIGN_TO(r->len, FBDIR_ALIGN); asio_submit(r); asio_sync(F->io_queue); - DBG("FB-DIRECT: Truncating at %Ld", (long long)f->pos); + DBG("FB-DIRECT: Truncating at %llu", (long long)f->pos); if (sh_ftruncate(F->fd, f->pos) < 0) die("Error truncating %s: %m", f->name); } @@ -213,7 +207,7 @@ fbdir_spout(struct fastbuf *f) static int fbdir_seek(struct fastbuf *f, sh_off_t pos, int whence) { - DBG("FB-DIRECT: Seek %Ld %d", (long long)pos, whence); + DBG("FB-DIRECT: Seek %llu %d", (long long)pos, whence); if (whence == SEEK_SET && pos == f->pos) return 1; @@ -227,15 +221,15 @@ fbdir_seek(struct fastbuf *f, sh_off_t pos, int whence) } static struct asio_queue * -fbdir_get_io_queue(void) +fbdir_get_io_queue(uns buffer_size, uns write_back) { struct ucwlib_context *ctx = ucwlib_thread_context(); struct asio_queue *q = ctx->io_queue; if (!q) { q = xmalloc_zero(sizeof(struct asio_queue)); - q->buffer_size = fbdir_buffer_size; - q->max_writebacks = fbdir_write_back; + q->buffer_size = buffer_size; + q->max_writebacks = write_back; asio_init_queue(q); ctx->io_queue = q; } @@ -295,8 +289,8 @@ fbdir_config(struct fastbuf *f, uns item, int value) } } -static struct fastbuf * -fbdir_open_internal(byte *name, int fd, struct asio_queue *q) +struct fastbuf * +fbdir_open_fd_internal(int fd, byte *name, struct asio_queue *q, uns buffer_size, uns read_ahead UNUSED, uns write_back) { int namelen = strlen(name) + 1; struct fb_direct *F = xmalloc(sizeof(struct fb_direct) + namelen); @@ -310,7 +304,7 @@ fbdir_open_internal(byte *name, int fd, struct asio_queue *q) if (q) F->io_queue = F->user_queue = q; else - F->io_queue = fbdir_get_io_queue(); + F->io_queue = fbdir_get_io_queue(buffer_size, write_back); f->refill = fbdir_refill; f->spout = fbdir_spout; f->seek = fbdir_seek; @@ -320,53 +314,6 @@ fbdir_open_internal(byte *name, int fd, struct asio_queue *q) return f; } -struct fastbuf * -fbdir_open_try(byte *name, uns mode, struct asio_queue *q) -{ - if (!fbdir_cheat) - mode |= O_DIRECT; - int fd = sh_open(name, mode, 0666); - if (fd < 0) - return NULL; - struct fastbuf *b = fbdir_open_internal(name, fd, q); - if (mode & O_APPEND) - fbdir_seek(b, 0, SEEK_END); - return b; -} - -struct fastbuf * -fbdir_open(byte *name, uns mode, struct asio_queue *q) -{ - struct fastbuf *b = fbdir_open_try(name, mode, q); - if (!b) - die("Unable to %s file %s: %m", - (mode & O_CREAT) ? "create" : "open", name); - return b; -} - -struct fastbuf * -fbdir_open_fd(int fd, struct asio_queue *q) -{ - byte x[32]; - - sprintf(x, "fd%d", fd); - if (!fbdir_cheat && fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_DIRECT) < 0) - log(L_WARN, "Cannot set O_DIRECT on fd %d: %m", fd); - return fbdir_open_internal(x, fd, q); -} - -struct fastbuf * -fbdir_open_tmp(struct asio_queue *q) -{ - byte buf[TEMP_FILE_NAME_LEN]; - struct fastbuf *f; - - temp_file_name(buf); - f = fbdir_open(buf, O_RDWR | O_CREAT | O_TRUNC, q); - bconfig(f, BCONFIG_IS_TEMP_FILE, 1); - return f; -} - #ifdef TEST #include "lib/getopt.h"