subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 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 */ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 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 */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 17 | /* */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 20 | /* */ |
| 21 | /* File: bdflush01.c */ |
| 22 | /* */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 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, */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 28 | /* then bdflush() enters the daemon code and never returns. */ |
| 29 | /* */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 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.*/ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 34 | /* */ |
| 35 | /* If func is 3 or more and is odd (low bit is 1), then data is */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 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 */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 46 | /* error. */ |
| 47 | /* */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 48 | /* Errors: */ |
| 49 | /* EBUSY */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 50 | /* An attempt was made to enter the daemon code after*/ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 51 | /* another process has already entered. */ |
| 52 | /* EFAULT */ |
| 53 | /* address points outside your accessible address */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 54 | /* space. */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 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. */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 59 | /* EPERM */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 60 | /* Caller does not have the CAP_SYS_ADMIN capability.*/ |
| 61 | /* */ |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 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@in.ibm.com> */ |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 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 | #include <sys/kdaemon.h> |
| 85 | |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 86 | #include "test.h" |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 87 | #include "linux_syscall_numbers.h" |
| 88 | |
Garrett Cooper | af83ae0 | 2010-12-17 13:47:54 -0800 | [diff] [blame] | 89 | char *TCID = "bdflush01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 90 | int testno; |
| 91 | int TST_TOTAL = 1; |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 92 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 93 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 94 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | tst_rmdir(); |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 98 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 100 | TEST_PAUSE; |
| 101 | tst_tmpdir(); |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 104 | int main(int ac, char **av) |
| 105 | { |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 106 | long data; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 107 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 108 | |
Garrett Cooper | e1f008e | 2010-12-14 00:21:59 -0800 | [diff] [blame] | 109 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
| 110 | tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 111 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 112 | setup(); |
subrata_modak | 34bcffb | 2009-05-21 18:12:51 +0000 | [diff] [blame] | 113 | |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 114 | /* |
Garrett Cooper | af83ae0 | 2010-12-17 13:47:54 -0800 | [diff] [blame] | 115 | * TODO (garrcoop): add more functional testcases; there are a ton |
| 116 | * missing. |
| 117 | */ |
| 118 | data = 0; |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 119 | tst_count = 1; |
Garrett Cooper | 1ef323e | 2010-11-23 08:55:55 -0800 | [diff] [blame] | 120 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 121 | TEST(ltp_syscall(__NR_bdflush, 3, data)); |
Garrett Cooper | af83ae0 | 2010-12-17 13:47:54 -0800 | [diff] [blame] | 122 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | tst_brkm(TFAIL | TTERRNO, cleanup, "bdflush failed"); |
Garrett Cooper | af83ae0 | 2010-12-17 13:47:54 -0800 | [diff] [blame] | 124 | else |
Garrett Cooper | e1f008e | 2010-12-14 00:21:59 -0800 | [diff] [blame] | 125 | tst_resm(TPASS, "bdflush() = %ld", TEST_RETURN); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 126 | } |
Garrett Cooper | c5f81ca | 2010-11-23 08:51:12 -0800 | [diff] [blame] | 127 | cleanup(); |
| 128 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 129 | } |