From: Manas K Nayak Subject: [PATCH 01/03] Add splice02 as a new syscall test in LTP [LKML Subject: nfs: add support for splice writes] Date: Mon, 13 Apr 2009 17:57:05 +0530 Message-ID: <20090413122703.21185.41993.sendpatchset@subratamodak.linux.ibm.com> Cc: Manas K Nayak , ltp-list , linux-nfs@vger.kernel.org, "Deepakraj B. Himavantharaj" To: Suresh Jayaraman Return-path: Received: from e3.ny.us.ibm.com ([32.97.182.143]:51305 "EHLO e3.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbZDMM1R (ORCPT ); Mon, 13 Apr 2009 08:27:17 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e3.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n3DCNjVO028930 for ; Mon, 13 Apr 2009 08:23:45 -0400 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n3DCRGa7154210 for ; Mon, 13 Apr 2009 08:27:16 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n3DCRFi3013572 for ; Mon, 13 Apr 2009 08:27:16 -0400 Sender: linux-nfs-owner@vger.kernel.org List-ID: Hi Suresh, >This patch attempts to add splice writes support. In essence, it just >calls generic_file_splice_write() after doing a little sanity check. >This would allow LTTng users that are using NFS to store trace data. >There could be more applications that could be benefitted too. > >I have tested this using the Jens' test program and have found no >real issues. The test program is inlined below: > >/* > * splice-out.c: Splice stdout to file > */ >#include >#include >#include >#include > >#define SPLICE_SIZE (64*1024) > >int main(int argc, char *argv[]) >{ > int fd; > > if (argc < 2) { > printf("%s: outfile\n", argv[0]); > return 1; > } > > fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644); > if (fd < 0) { > perror("open"); > return 1; > } > > do { > int ret = splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, 0); > > if (ret < 0) { > perror("splice"); > break; > } else if (ret < SPLICE_SIZE) > break; > } while (1); > > close(fd); > return 0; >} > >Compile with -D _GNU_SOURCE and do something like: > echo "some stuff" | ./splice-out > > I picked up this test program written by you and ported this to LTP under GPL. If you do not have any objection(s), can we contribute this to LTP ? The following patch will do exactly that. Original-Author: Suresh Jayaraman Ported-To-LTP:By: Manas K Nayak --- --- ltp-full-20090331.orig/testcases/kernel/syscalls/splice/splice02.c 1970-01-01 05:30:00.000000000 +0530 +++ ltp-full-20090331/testcases/kernel/syscalls/splice/splice02.c 2009-04-13 16:04:21.000000000 +0530 @@ -0,0 +1,145 @@ +/******************************************************************************/ +/* Copyright (c) Suresh Jayaraman , 2009 */ +/* */ +/* LKML Reference: http://lkml.org/lkml/2009/4/2/55 */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ +/* the GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/******************************************************************************/ +/******************************************************************************/ +/* */ +/* File: splice02.c */ +/* */ +/* Description: This tests the splice() syscall */ +/* */ +/* Usage: */ +/* echo "Test splice()" > ; splice02 */ +/* */ +/* Total Tests: 1 */ +/* */ +/* Test Name: splice02 */ +/* History: Porting from Crackerjack to LTP is done by */ +/* Manas Kumar Nayak maknayak@in.ibm.com> */ +/******************************************************************************/ +#define _GNU_SOURCE +#include +#include +#include +#include + + +/* Harness Specific Include Files. */ +#include "test.h" +#include "usctest.h" +#include "linux_syscall_numbers.h" + +/* Extern Global Variables */ +extern int Tst_count; /* counter for tst_xxx routines. */ +extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */ + +/* Global Variables */ +char *TCID = "splice02"; /* Test program identifier.*/ +int testno; +int TST_TOTAL = 1; /* total number of tests in this file. */ + +/* Extern Global Functions */ +/******************************************************************************/ +/* */ +/* Function: cleanup */ +/* */ +/* Description: Performs all one time clean up for this test on successful */ +/* completion, premature exit or failure. Closes all temporary */ +/* files, removes all temporary directories exits the test with */ +/* appropriate return code by calling tst_exit() function. */ +/* */ +/* Input: None. */ +/* */ +/* Output: None. */ +/* */ +/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ +/* On success - Exits calling tst_exit(). With '0' return code. */ +/* */ +/******************************************************************************/ +extern void cleanup() { + /* Remove tmp dir and all files in it */ + TEST_CLEANUP; + tst_rmdir(); + + /* Exit with appropriate return code. */ + tst_exit(); +} + +/* Local Functions */ +/******************************************************************************/ +/* */ +/* Function: setup */ +/* */ +/* Description: Performs all one time setup for this test. This function is */ +/* typically used to capture signals, create temporary dirs */ +/* and temporary files that may be used in the course of this */ +/* test. */ +/* */ +/* Input: None. */ +/* */ +/* Output: None. */ +/* */ +/* Return: On failure - Exits by calling cleanup(). */ +/* On success - returns 0. */ +/* */ +/******************************************************************************/ +void setup() { + /* Capture signals if any */ + /* Create temporary directories */ + TEST_PAUSE; + tst_tmpdir(); +} + +#define SPLICE_SIZE (64*1024) + +int main(int ac, char **av) { + int fd = 0; + int ret = 0; + + setup(); + + if (ac < 2 ) { + tst_resm(TFAIL, "%s failed - Usage: %s outfile", TCID, av[0]); + tst_exit(); + } + fd=open(av[1], O_WRONLY | O_CREAT | O_TRUNC, 0644); + if(fd < 0 ) { + tst_resm(TFAIL, "%s failed - errno = %d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); + cleanup(); + tst_exit(); + } + + do { + ret = splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, 0); + if (ret < 0) { + tst_resm(TFAIL, "%s failed - errno = %d : %s",TCID, TEST_ERRNO, strerror(TEST_ERRNO)); + cleanup(); + tst_exit(); + } else + if (ret < SPLICE_SIZE){ + cleanup(); + tst_exit(); + } + } while(1); + + close(fd); + tst_resm(TPASS, "splice() system call Passed"); + tst_exit(); +} + --- ltp-full-20090331.orig/runtest/syscalls 2009-04-13 15:12:15.000000000 +0530 +++ ltp-full-20090331/runtest/syscalls 2009-04-13 16:10:26.000000000 +0530 @@ -1030,6 +1030,8 @@ sockioctl01 sockioctl01 #splice test splice01 splice01 +splice02 echo "Test splice02()" > splice02-temp; splice02 splice02-temp + tee01 tee01 stat01 stat01 --- Regards-- Manas