From: Jens Axboe Date: Fri, 8 Jun 2007 07:44:06 +0000 (+0200) Subject: Work around glibc weirdness X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=13b72067ece97664d2e6ec8a30f69228dc0a059a;p=splice.git Work around glibc weirdness Some newer glibc seem to badly mangle the splice system call so that nothing works. Work around this bug by using our private splice/vmsplice/tee system calls, prefix them with 's'. Signed-off-by: Jens Axboe --- diff --git a/ktee-net.c b/ktee-net.c index 7f2653b..48e86db 100644 --- a/ktee-net.c +++ b/ktee-net.c @@ -19,7 +19,7 @@ static int do_splice(int infd, int outfd, unsigned int len, char *msg) { while (len) { - int written = splice(infd, NULL, outfd, NULL, len, 0); + int written = ssplice(infd, NULL, outfd, NULL, len, 0); if (written <= 0) return error(msg); @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) return error("connect"); do { - int tee_len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, 0); + int tee_len = stee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, 0); if (tee_len < 0) { if (errno == EAGAIN) { diff --git a/ktee.c b/ktee.c index 06a1e4c..a477671 100644 --- a/ktee.c +++ b/ktee.c @@ -20,7 +20,7 @@ static int splice_flags; static int do_splice(int infd, int outfd, unsigned int len, char *msg) { while (len) { - int written = splice(infd, NULL, outfd, NULL, len, splice_flags); + int written = ssplice(infd, NULL, outfd, NULL, len, splice_flags); if (written <= 0) return error(msg); @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) return error("open output"); do { - int tee_len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, 0); + int tee_len = stee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, 0); if (tee_len < 0) { if (errno == EAGAIN) { diff --git a/splice-bench.c b/splice-bench.c index 9ceae50..c4f6950 100644 --- a/splice-bench.c +++ b/splice-bench.c @@ -329,7 +329,7 @@ again: off = 0; do { - int ret = splice(fd, &off, pfd[1], NULL, min(size, (unsigned long long) splice_size), 0); + int ret = ssplice(fd, &off, pfd[1], NULL, min(size, (unsigned long long) splice_size), 0); if (ret <= 0) return error("splice-in"); @@ -337,7 +337,7 @@ again: size -= ret; while (ret > 0) { int flags = size ? SPLICE_F_MORE : 0; - int written = splice(pfd[0], NULL, out_fd, NULL, ret, flags); + int written = ssplice(pfd[0], NULL, out_fd, NULL, ret, flags); if (written <= 0) return error("splice-out"); diff --git a/splice-cp.c b/splice-cp.c index 58452e8..022622f 100644 --- a/splice-cp.c +++ b/splice-cp.c @@ -64,14 +64,14 @@ int main(int argc, char *argv[]) do { int this_len = min((off_t) BS, sb.st_size); - int ret = splice(in_fd, NULL, pfds[1], NULL, this_len, 0); + int ret = ssplice(in_fd, NULL, pfds[1], NULL, this_len, 0); if (ret <= 0) return error("splice-in"); sb.st_size -= ret; while (ret > 0) { - int written = splice(pfds[0], NULL, out_fd, NULL, ret, splice_flags); + int written = ssplice(pfds[0], NULL, out_fd, NULL, ret, splice_flags); if (written <= 0) return error("splice-out"); ret -= written; diff --git a/splice-fromnet.c b/splice-fromnet.c index 6a7adc4..d50014b 100644 --- a/splice-fromnet.c +++ b/splice-fromnet.c @@ -41,7 +41,7 @@ static int splice_from_net(int fd) if (!(pfd.revents & POLLIN)) continue; - ret = splice(fd, NULL, STDOUT_FILENO, NULL, SPLICE_SIZE, 0); + ret = ssplice(fd, NULL, STDOUT_FILENO, NULL, SPLICE_SIZE, 0); if (ret < 0) return error("splice"); diff --git a/splice-in.c b/splice-in.c index 3c01cc3..91835f5 100644 --- a/splice-in.c +++ b/splice-in.c @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) return isize; while (isize) { - int ret = splice(fd, NULL, STDOUT_FILENO, NULL, isize, 0); + int ret = ssplice(fd, NULL, STDOUT_FILENO, NULL, isize, 0); if (ret < 0) return error("splice"); diff --git a/splice-out.c b/splice-out.c index c96c5c3..88223e8 100644 --- a/splice-out.c +++ b/splice-out.c @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) return error("open"); do { - int ret = splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, splice_flags); + int ret = ssplice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, splice_flags); if (ret < 0) return error("splice"); diff --git a/splice-test4c.c b/splice-test4c.c index 4176a6e..1d10602 100644 --- a/splice-test4c.c +++ b/splice-test4c.c @@ -201,13 +201,13 @@ splice_pipe_again: i = NR*BUFSIZE; off = 0; do { - int ret = splice(fd, &off, pipefd[1], NULL, min(i, BUFSIZE), SPLICE_F_NONBLOCK); + int ret = ssplice(fd, &off, pipefd[1], NULL, min(i, BUFSIZE), SPLICE_F_NONBLOCK); if (ret <= 0) return error("splice-pipe-in"); i -= ret; while (ret > 0) { int flags = i ? SPLICE_F_MORE : 0; - int written = splice(pipefd[0], NULL, sk, NULL, ret, flags); + int written = ssplice(pipefd[0], NULL, sk, NULL, ret, flags); if (written <= 0) return error("splice-pipe-out"); ret -= written; @@ -243,7 +243,7 @@ splice_again: int flags = BUFSIZE < i ? SPLICE_F_MORE : 0; int ret; - ret = splice(fd, &off, sk, NULL, min(i, BUFSIZE), flags); + ret = ssplice(fd, &off, sk, NULL, min(i, BUFSIZE), flags); if (ret <= 0) return error("splice"); diff --git a/splice-tonet.c b/splice-tonet.c index 2c117d9..4314fa8 100644 --- a/splice-tonet.c +++ b/splice-tonet.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) return error("connect"); do { - ret = splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, SPLICE_F_NONBLOCK); + ret = ssplice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, SPLICE_F_NONBLOCK); if (ret < 0) { if (errno == EAGAIN) { usleep(100); diff --git a/splice.h b/splice.h index fdcd915..3f85eda 100644 --- a/splice.h +++ b/splice.h @@ -35,26 +35,26 @@ #define SPLICE_F_MORE (0x04) /* expect more data */ #define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */ -static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out, - size_t len, unsigned long flags) +#endif /* SPLICE_F_MOVE defined */ + +static inline int ssplice(int fdin, loff_t *off_in, int fdout, loff_t *off_out, + size_t len, unsigned long flags) { return syscall(__NR_sys_splice, fdin, off_in, fdout, off_out, len, flags); } -static inline int tee(int fdin, int fdout, size_t len, unsigned int flags) +static inline int stee(int fdin, int fdout, size_t len, unsigned int flags) { return syscall(__NR_sys_tee, fdin, fdout, len, flags); } -static inline int vmsplice(int fd, const struct iovec *iov, - unsigned long nr_segs, unsigned int flags) +static inline int svmsplice(int fd, const struct iovec *iov, + unsigned long nr_segs, unsigned int flags) { return syscall(__NR_sys_vmsplice, fd, iov, nr_segs, flags); } -#endif /* SPLICE_F_MOVE defined */ - #define SPLICE_SIZE (64*1024) #define BUG_ON(c) assert(!(c)) diff --git a/vmsplice-touser.c b/vmsplice-touser.c index 7cbc1a0..c085a09 100644 --- a/vmsplice-touser.c +++ b/vmsplice-touser.c @@ -36,7 +36,7 @@ int do_vmsplice(int fd, void *buf, int len) if (poll(&pfd, 1, -1) < 0) return error("poll"); - written = vmsplice(fd, &iov, 1, splice_flags); + written = svmsplice(fd, &iov, 1, splice_flags); if (written < 0) return error("vmsplice"); diff --git a/vmsplice.c b/vmsplice.c index 73871eb..2cfe6b2 100644 --- a/vmsplice.c +++ b/vmsplice.c @@ -45,7 +45,7 @@ int do_vmsplice(int fd, void *b1, void *b2, int len) if (poll(&pfd, 1, -1) < 0) return error("poll"); - written = vmsplice(fd, &iov[idx], 2 - idx, splice_flags); + written = svmsplice(fd, &iov[idx], 2 - idx, splice_flags); if (written <= 0) return error("vmsplice"); diff --git a/vmsplice2.c b/vmsplice2.c index 54e76e2..82cd6c4 100644 --- a/vmsplice2.c +++ b/vmsplice2.c @@ -36,7 +36,7 @@ int do_vmsplice(int fd, struct iovec *iov, unsigned long nr_vecs) if (poll(&pfd, 1, -1) < 0) return error("poll"); - written = vmsplice(fd, iov, nr_vecs, gift ? SPLICE_F_GIFT : 0); + written = svmsplice(fd, iov, nr_vecs, gift ? SPLICE_F_GIFT : 0); if (written <= 0) return error("vmsplice");