Skip to contentSkip to conversation

Add splice02 as a new syscall test in LTP [LKML Subject: nfs: add support for splice writes]

PATCH In review Manas K Nayak 2 participants 2 messages Apr 13, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Add splice02 as a new syscall test in LTP [LKML Subject: nfs: add support for splice writes]

Hi Suresh,

Quoted 47 lines

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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#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;
}
Quoted 4 lines

Compile with -D _GNU_SOURCE and do something like:
echo "some stuff" | ./splice-out <outfile>

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 <[email protected]> Ported-To-LTP:By: Manas K Nayak <[email protected]>
---

testcases/kernel/syscalls/splice/splice02.c +145 -0
@@ -0,0 +1,145 @@
+/******************************************************************************/
+/* Copyright (c) Suresh Jayaraman <[email protected]>, 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:  <for command-line>                                                 */
+/* echo "Test splice()" > <outfile>; splice02 <outfile>                       */
+/*                                                                            */
+/* Total Tests: 1                                                             */
+/*                                                                            */
+/* Test Name:   splice02                                             */
+/* History:     Porting from Crackerjack to LTP is done by                    */
+/*              Manas Kumar Nayak [email protected]>                        */
+/******************************************************************************/
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+
+/* 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();
+}
+
runtest/syscalls +2 -0
@@ -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

A message that is not in the archive (sent off-list or not yet received): 20090413122703.21185.41993.sendpatchset-NRFfyExJdYpgXGGE5LP+UZlqa2bBAFbm0E9HWUfgJXw@public.gmane.org

#2 lore raw
Quoted 49 lines · Manas K Nayak

Hi Suresh,

Quoted 47 lines

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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#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;
}
Quoted 8 lines
Quoted 4 lines

Compile with -D _GNU_SOURCE and do something like:
echo "some stuff" | ./splice-out <outfile>

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.

Well, it's orginally from Jens Axboe <[email protected]>. You actually have to ask him :)

Quoted 168 lines

Original-Author: Suresh Jayaraman <[email protected]> Ported-To-LTP:By: Manas K Nayak <[email protected]>
---

testcases/kernel/syscalls/splice/splice02.c +145 -0
@@ -0,0 +1,145 @@
+/******************************************************************************/
+/* Copyright (c) Suresh Jayaraman <[email protected]>, 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:  <for command-line>                                                 */
+/* echo "Test splice()" > <outfile>; splice02 <outfile>                       */
+/*                                                                            */
+/* Total Tests: 1                                                             */
+/*                                                                            */
+/* Test Name:   splice02                                             */
+/* History:     Porting from Crackerjack to LTP is done by                    */
+/*              Manas Kumar Nayak [email protected]>                        */
+/******************************************************************************/
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+
+/* 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();
+}
+
runtest/syscalls +2 -1
@@ -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

Signature · 1 line
Suresh Jayaraman