lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130930163159.GA14242@tucsk.piliscsaba.szeredi.hu>
Date:	Mon, 30 Sep 2013 18:31:59 +0200
From:	Miklos Szeredi <miklos@...redi.hu>
To:	Ric Wheeler <rwheeler@...hat.com>
Cc:	"J. Bruce Fields" <bfields@...ldses.org>,
	"Myklebust, Trond" <Trond.Myklebust@...app.com>,
	Zach Brown <zab@...hat.com>,
	Anna Schumaker <schumaker.anna@...il.com>,
	Kernel Mailing List <linux-kernel@...r.kernel.org>,
	Linux-Fsdevel <linux-fsdevel@...r.kernel.org>,
	"linux-nfs@...r.kernel.org" <linux-nfs@...r.kernel.org>,
	"Schumaker, Bryan" <Bryan.Schumaker@...app.com>,
	"Martin K. Petersen" <mkp@....net>, Jens Axboe <axboe@...nel.dk>,
	Mark Fasheh <mfasheh@...e.com>,
	Joel Becker <jlbec@...lplan.org>,
	Eric Wong <normalperson@...t.net>
Subject: Re: [RFC] extending splice for copy offloading

Here's an example "cp" app using direct splice (and without fallback to
non-splice, which is obviously required unless the kernel is known to support
direct splice).

Untested, but trivial enough...

The important part is, I think, that the app must not assume that the kernel can
complete the request in one go.

Thanks,
Miklos

----
#define _GNU_SOURCE

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <sys/stat.h>
#include <err.h>

#ifndef SPLICE_F_DIRECT
#define SPLICE_F_DIRECT        (0x10)  /* neither splice fd is a pipe */
#endif

int main(int argc, char *argv[])
{
	struct stat stbuf;
	int in_fd;
	int out_fd;
	int res;
	off_t off;

	if (argc != 3)
		errx(1, "usage: %s from to", argv[0]);

	in_fd = open(argv[1], O_RDONLY);
	if (in_fd == -1)
		err(1, "opening %s", argv[1]);

	res = fstat(in_fd, &stbuf);
	if (res == -1)
		err(1, "fstat");

	out_fd = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, stbuf.st_mode);
	if (out_fd == -1)
		err(1, "opening %s", argv[2]);

	do {
		off_t in_off = off, out_off = off;
		ssize_t rres;

		rres = splice(in_fd, &in_off, out_fd, &out_off, SSIZE_MAX,
			     SPLICE_F_DIRECT);
		if (rres == -1)
			err(1, "splice");
		if (rres == 0)
			break;

		off += rres;
	} while (off < stbuf.st_size);

	res = close(in_fd);
	if (res == -1)
		err(1, "close");

	res = fsync(out_fd);
	if (res == -1)
		err(1, "fsync");

	res = close(out_fd);
	if (res == -1)
		err(1, "close");

	return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ