From e0650e53ca9df6e86272efb0a2e2587e42f24a53 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Wed, 10 Jun 2009 07:00:26 +0000 Subject: booster: implement sendfile. Signed-off-by: Anand V. Avati --- booster/src/booster.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/booster/src/booster.c b/booster/src/booster.c index 5137e8e2f..2453e3b8d 100644 --- a/booster/src/booster.c +++ b/booster/src/booster.c @@ -203,6 +203,11 @@ static void (*real_rewinddir) (DIR *dirp); static void (*real_seekdir) (DIR *dirp, off_t offset); static off_t (*real_telldir) (DIR *dirp); +static ssize_t (*real_sendfile) (int out_fd, int in_fd, off_t *offset, + size_t count); +static ssize_t (*real_sendfile64) (int out_fd, int in_fd, off_t *offset, + size_t count); + #define RESOLVE(sym) do { \ if (!real_##sym) \ real_##sym = dlsym (RTLD_NEXT, #sym); \ @@ -2005,6 +2010,57 @@ fork (void) return pid; } +ssize_t +sendfile (int out_fd, int in_fd, off_t *offset, size_t count) +{ + glusterfs_file_t in_fh = NULL; + ssize_t ret = -1; + + /* + * handle sendfile in booster only if in_fd corresponds to a glusterfs + * file handle + */ + in_fh = booster_get_glfs_fd (booster_glfs_fdtable, in_fd); + if (!in_fh) { + if (real_sendfile == NULL) { + errno = ENOSYS; + ret = -1; + } else { + ret = real_sendfile (out_fd, in_fd, offset, count); + } + } else { + ret = glusterfs_sendfile (out_fd, in_fh, offset, count); + booster_put_glfs_fd (in_fh); + } + + return ret; +} + +ssize_t +sendfile64 (int out_fd, int in_fd, off_t *offset, size_t count) +{ + glusterfs_file_t in_fh = NULL; + ssize_t ret = -1; + + /* + * handle sendfile in booster only if in_fd corresponds to a glusterfs + * file handle + */ + in_fh = booster_get_glfs_fd (booster_glfs_fdtable, in_fd); + if (!in_fh) { + if (real_sendfile64 == NULL) { + errno = ENOSYS; + ret = -1; + } else { + ret = real_sendfile64 (out_fd, in_fd, offset, count); + } + } else { + ret = glusterfs_sendfile (out_fd, in_fh, offset, count); + booster_put_glfs_fd (in_fh); + } + + return ret; +} void _init (void) @@ -2077,6 +2133,8 @@ _init (void) RESOLVE (rewinddir); RESOLVE (seekdir); RESOLVE (telldir); + RESOLVE (sendfile); + RESOLVE (sendfile64); /* This must be called after resolving real functions * above so that the socket based IO calls in libglusterfsclient -- cgit