Home | History | Annotate | Download | only in bdflush
      1 /******************************************************************************/
      2 /* Copyright (c) Crackerjack Project., 2007				   */
      3 /*									    */
      4 /* This program is free software;  you can redistribute it and/or modify      */
      5 /* it under the terms of the GNU General Public License as published by       */
      6 /* the Free Software Foundation; either version 2 of the License, or	  */
      7 /* (at your option) any later version.					*/
      8 /*									    */
      9 /* This program is distributed in the hope that it will be useful,	    */
     10 /* but WITHOUT ANY WARRANTY;  without even the implied warranty of	    */
     11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See		  */
     12 /* the GNU General Public License for more details.			   */
     13 /*									    */
     14 /* You should have received a copy of the GNU General Public License	  */
     15 /* along with this program;  if not, write to the Free Software	       */
     16 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
     17 /*									    */
     18 /******************************************************************************/
     19 /******************************************************************************/
     20 /*									    */
     21 /* File:	bdflush01.c					    */
     22 /*									    */
     23 /* Description: bdflush() starts, flushes, or tunes the buffer-dirty-flush    */
     24 /*		daemon. Only a privileged process (one with the CAP_SYS_ADMIN */
     25 /*		capability) may call bdflush().				      */
     26 /*									      */
     27 /*		If func is negative or 0, and no daemon has been started,     */
     28 /*		then bdflush() enters the daemon code and never returns.      */
     29 /*									      */
     30 /*		If func is 1, some dirty buffers are written to disk.	      */
     31 /*		If func is 2 or more and is even (low bit is 0), then address */
     32 /*		is the address of a long word, and the tuning parameter       */
     33 /*		numbered (func-2)/2 is returned to the caller in that address.*/
     34 /*									      */
     35 /*		If func is 3 or more and is odd (low bit is 1), then data is  */
     36 /*		a long word, and the kernel sets tuning parameter numbered    */
     37 /*		(func-3)/2 to that value.				      */
     38 /*		    							      */
     39 /*		The set of parameters, their values, and their legal ranges   */
     40 /*		are defined in the kernel source file fs/buffer.c. 	      */
     41 /*									      */
     42 /*		Return Value:						      */
     43 /*		If func is negative or 0 and the daemon successfully starts,  */
     44 /*		bdflush() never returns. Otherwise, the return value is 0 on  */
     45 /*		success and -1 on failure, with errno set to indicate the     */
     46 /*		error.							      */
     47 /*									      */
     48 /*		Errors:							      */
     49 /*			EBUSY						      */
     50 /*			    An attempt was made to enter the daemon code after*/
     51 /*			    another process has already entered. 	      */
     52 /*			EFAULT						      */
     53 /*			   address points outside your accessible address     */
     54 /*			   space. 					      */
     55 /*			EINVAL						      */
     56 /*			    An attempt was made to read or write an invalid   */
     57 /*			    parameter number, or to write an invalid value to */
     58 /*			    a parameter. 				      */
     59 /*			EPERM						      */
     60 /*			    Caller does not have the CAP_SYS_ADMIN capability.*/
     61 /*									      */
     62 /* Usage:  <for command-line>						 */
     63 /* bdflush01 [-c n] [-e][-i n] [-I x] [-p x] [-t]		      */
     64 /*      where,  -c n : Run n copies concurrently.			     */
     65 /*	      -e   : Turn on errno logging.				 */
     66 /*	      -i n : Execute test n times.				  */
     67 /*	      -I x : Execute test for x seconds.			    */
     68 /*	      -P x : Pause for x seconds between iterations.		*/
     69 /*	      -t   : Turn on syscall timing.				*/
     70 /*									    */
     71 /* Total Tests: 1							     */
     72 /*									    */
     73 /* Test Name:   bdflush01					      */
     74 /* History:     Porting from Crackerjack to LTP is done by		    */
     75 /*	      Manas Kumar Nayak maknayak (at) in.ibm.com>			*/
     76 /******************************************************************************/
     77 #include <stdio.h>
     78 #include <stdlib.h>
     79 #include <sys/wait.h>
     80 #include <sys/types.h>
     81 #include <unistd.h>
     82 #include <errno.h>
     83 #include <sys/stat.h>
     84 
     85 #include "test.h"
     86 #include "lapi/syscalls.h"
     87 
     88 char *TCID = "bdflush01";
     89 int testno;
     90 int TST_TOTAL = 1;
     91 
     92 void cleanup(void)
     93 {
     94 	tst_rmdir();
     95 }
     96 
     97 void setup(void)
     98 {
     99 	TEST_PAUSE;
    100 	tst_tmpdir();
    101 }
    102 
    103 int main(int ac, char **av)
    104 {
    105 	long data;
    106 
    107 	tst_parse_opts(ac, av, NULL, NULL);
    108 
    109 	setup();
    110 
    111 	/*
    112 	 * TODO (garrcoop): add more functional testcases; there are a ton
    113 	 * missing.
    114 	 */
    115 	data = 0;
    116 	tst_count = 1;
    117 	for (testno = 0; testno < TST_TOTAL; ++testno) {
    118 		TEST(ltp_syscall(__NR_bdflush, 3, data));
    119 		if (TEST_RETURN == -1)
    120 			tst_brkm(TFAIL | TTERRNO, cleanup, "bdflush failed");
    121 		else
    122 			tst_resm(TPASS, "bdflush() = %ld", TEST_RETURN);
    123 	}
    124 	cleanup();
    125 	tst_exit();
    126 }
    127