blob: de5ca04dc36c17ad637c6022e29c703bc9428eba [file] [log] [blame]
subrata_modak34bcffb2009-05-21 18:12:51 +00001/******************************************************************************/
Garrett Cooper43088e12010-12-13 23:30:59 -08002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modak34bcffb2009-05-21 18:12:51 +00004/* 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 */
Garrett Cooper43088e12010-12-13 23:30:59 -08006/* 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 */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
Garrett Cooper43088e12010-12-13 23:30:59 -080017/* */
subrata_modak34bcffb2009-05-21 18:12:51 +000018/******************************************************************************/
19/******************************************************************************/
Garrett Cooper43088e12010-12-13 23:30:59 -080020/* */
21/* File: bdflush01.c */
22/* */
subrata_modak34bcffb2009-05-21 18:12:51 +000023/* 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, */
Garrett Cooper2c282152010-12-16 00:55:50 -080028/* then bdflush() enters the daemon code and never returns. */
29/* */
subrata_modak34bcffb2009-05-21 18:12:51 +000030/* 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.*/
Garrett Cooper2c282152010-12-16 00:55:50 -080034/* */
35/* If func is 3 or more and is odd (low bit is 1), then data is */
subrata_modak34bcffb2009-05-21 18:12:51 +000036/* 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 */
Garrett Cooper2c282152010-12-16 00:55:50 -080046/* error. */
47/* */
subrata_modak34bcffb2009-05-21 18:12:51 +000048/* Errors: */
49/* EBUSY */
Garrett Cooper2c282152010-12-16 00:55:50 -080050/* An attempt was made to enter the daemon code after*/
subrata_modak34bcffb2009-05-21 18:12:51 +000051/* another process has already entered. */
52/* EFAULT */
53/* address points outside your accessible address */
Garrett Cooper2c282152010-12-16 00:55:50 -080054/* space. */
subrata_modak34bcffb2009-05-21 18:12:51 +000055/* 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. */
Garrett Cooper2c282152010-12-16 00:55:50 -080059/* EPERM */
subrata_modak34bcffb2009-05-21 18:12:51 +000060/* Caller does not have the CAP_SYS_ADMIN capability.*/
61/* */
Garrett Cooper43088e12010-12-13 23:30:59 -080062/* 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@in.ibm.com> */
subrata_modak34bcffb2009-05-21 18:12:51 +000076/******************************************************************************/
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#include <sys/kdaemon.h>
85
subrata_modak34bcffb2009-05-21 18:12:51 +000086#include "test.h"
subrata_modak34bcffb2009-05-21 18:12:51 +000087#include "linux_syscall_numbers.h"
88
Garrett Cooperaf83ae02010-12-17 13:47:54 -080089char *TCID = "bdflush01";
Wanlong Gao354ebb42012-12-07 10:10:04 +080090int testno;
91int TST_TOTAL = 1;
subrata_modak34bcffb2009-05-21 18:12:51 +000092
Mike Frysingerc57fba52014-04-09 18:56:30 -040093void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080094{
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 tst_rmdir();
subrata_modak34bcffb2009-05-21 18:12:51 +000096}
97
Mike Frysingerc57fba52014-04-09 18:56:30 -040098void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080099{
Garrett Cooper43088e12010-12-13 23:30:59 -0800100 TEST_PAUSE;
101 tst_tmpdir();
subrata_modak34bcffb2009-05-21 18:12:51 +0000102}
103
Wanlong Gao354ebb42012-12-07 10:10:04 +0800104int main(int ac, char **av)
105{
subrata_modak34bcffb2009-05-21 18:12:51 +0000106 long data;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200107 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800108
Garrett Coopere1f008e2010-12-14 00:21:59 -0800109 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
110 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
subrata_modak34bcffb2009-05-21 18:12:51 +0000111
Garrett Cooper43088e12010-12-13 23:30:59 -0800112 setup();
subrata_modak34bcffb2009-05-21 18:12:51 +0000113
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800114 /*
Garrett Cooperaf83ae02010-12-17 13:47:54 -0800115 * TODO (garrcoop): add more functional testcases; there are a ton
116 * missing.
117 */
118 data = 0;
Caspar Zhangd59a6592013-03-07 14:59:12 +0800119 tst_count = 1;
Garrett Cooper1ef323e2010-11-23 08:55:55 -0800120 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100121 TEST(ltp_syscall(__NR_bdflush, 3, data));
Garrett Cooperaf83ae02010-12-17 13:47:54 -0800122 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123 tst_brkm(TFAIL | TTERRNO, cleanup, "bdflush failed");
Garrett Cooperaf83ae02010-12-17 13:47:54 -0800124 else
Garrett Coopere1f008e2010-12-14 00:21:59 -0800125 tst_resm(TPASS, "bdflush() = %ld", TEST_RETURN);
Garrett Cooper43088e12010-12-13 23:30:59 -0800126 }
Garrett Cooperc5f81ca2010-11-23 08:51:12 -0800127 cleanup();
128 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700129}