Work around glibc weirdness
authorJens Axboe <jens.axboe@oracle.com>
Fri, 8 Jun 2007 07:44:06 +0000 (09:44 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 8 Jun 2007 07:44:06 +0000 (09:44 +0200)
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 <jens.axboe@oracle.com>
13 files changed:
ktee-net.c
ktee.c
splice-bench.c
splice-cp.c
splice-fromnet.c
splice-in.c
splice-out.c
splice-test4c.c
splice-tonet.c
splice.h
vmsplice-touser.c
vmsplice.c
vmsplice2.c

index 7f2653b8f4ff925b88fb3b3ae22dede7c5974468..48e86db3117bd77ef508112074878c046c198b75 100644 (file)
@@ -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 06a1e4c26e0f3d0f2e35020ca9fb3ea76be8f499..a477671148d802bc224946ed4baf7b6d6888afde 100644 (file)
--- 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) {
index 9ceae5048da5eeb48a763666e61547ea56474fb2..c4f6950e85d8913180d349e0340ce62021283a87 100644 (file)
@@ -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");
index 58452e84de48204f121ea33826a8de29bd7187b8..022622fba0b77e9929ed390f5309d660559e1b9f 100644 (file)
@@ -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;
index 6a7adc4eaad1e03fd24b230089ffd332b2b77e86..d50014b7f13ab6f9d6c1a4dd3054d454bb418b71 100644 (file)
@@ -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");
index 3c01cc367e9f9ac3616bbafd24e4ef440e96129f..91835f55c3d8972b510d92ff31ccf69481f84308 100644 (file)
@@ -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");
index c96c5c3c3dde9f5e48819bcf44d0226dfd31d4ee..88223e81911ae9fb2cfa3965341d66628e8c20b9 100644 (file)
@@ -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");
index 4176a6ec0bdedc3e2fb3da2523095657d5f4b701..1d10602a53a33bff3d88740a2f6d50cc7e198279 100644 (file)
@@ -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");
index 2c117d9d379d7f6205becfcba693302b7cb7442d..4314fa83de65a222e8db599a341abc8e77604bfa 100644 (file)
@@ -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);
index fdcd915647df660b82eaccb7f83f44a4a706eb20..3f85edabe58a2696f06713611a54c267e2bf8796 100644 (file)
--- a/splice.h
+++ b/splice.h
 #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))
index 7cbc1a0a7e42bae9de90ae3933cf2fb40ec9d7fa..c085a092ba3b06d8c7a0801100f59a41dd893700 100644 (file)
@@ -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");
index 73871eb47cfb9ad9b283b6be507b78e55666b6f0..2cfe6b29b1e544b609aec6b4d27a34320043fa7e 100644 (file)
@@ -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");
index 54e76e21b07eb90c6c4e21c850754322a0ae2902..82cd6c4f9132a006682f5448c50c0b6c0a62fd26 100644 (file)
@@ -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");