Re: [PATCH v3 0/5] iov_iter: Adjust styling/location of new splice functions

From: David Howells
Date: Tue Feb 14 2023 - 10:50:31 EST


Jens Axboe <axboe@xxxxxxxxx> wrote:

> That is indeed the question, and unanswered so far... Let's turn it into
> one clean series, and get it stuffed into for-next and most likely
> target 6.4 for inclusion at this point.

I was waiting to see if the patch worked for Daniel (which it does) and
Guenter (no answer yet) before answering. It appears to fix shmem - I've
tested it with:

dd if=/dev/zero of=/tmp/sparse count=1 seek=401 bs=4096
just-splice /tmp/sparse 11234000 | sha1sum

where just-splice.c is attached (note that piping the output into another
program is important to make the splice work).

Meanwhile, I'm working on working the changes into my patchset at appropriate
points.

David
---
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#include <sys/wait.h>

static char *prog;

int main(int argc, char *argv[])
{
unsigned int iflags = 0;
ssize_t spliced, remain;
int in, out;

prog = argv[0];
if (argc > 1 && strcmp(argv[1], "-d") == 0) {
iflags |= O_DIRECT;
argv++;
argc--;
}

if (argc != 3 || !argv[1][0] || !argv[2][0]) {
fprintf(stderr, "Usage: %s <file> <amount>\n", prog);
exit(2);
}

in = open(argv[1], O_RDONLY | O_NOFOLLOW | iflags);
if (in < 0) {
perror("open");
exit(1);
}

remain = strtoul(argv[2], NULL, 0);
while (remain > 0) {
spliced = splice(in, NULL, 1, NULL, remain, 0);
if (spliced < 0) {
perror("splice");
exit(1);
}
if (spliced == 0)
break;
remain -= spliced;
}

exit(0);
}