robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 4 | * Copyright (c) Cyril Hrubis chrubis@suse.cz 2009 |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | * the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * NAME |
| 23 | * ftest06.c -- test inode things (ported from SPIE section2/filesuite/ftest7.c, by Airong Zhang) |
| 24 | * |
| 25 | * this is the same as ftest2, except that it uses lseek64 |
| 26 | * |
| 27 | * CALLS |
| 28 | * open, close, read, write, llseek, |
| 29 | * unlink, chdir |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 30 | * |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 31 | * |
| 32 | * ALGORITHM |
| 33 | * |
| 34 | * This was tino.c by rbk. Moved to test suites by dale. |
| 35 | * |
| 36 | * ftest06 [-f tmpdirname] nchild iterations [partition] |
| 37 | * |
| 38 | * This forks some child processes, they do some random operations |
| 39 | * which use lots of directory operations. |
| 40 | * |
| 41 | * RESTRICTIONS |
| 42 | * Runs a long time with default args - can take others on input |
| 43 | * line. Use with "term mode". |
| 44 | * If run on vax the ftruncate will not be random - will always go to |
| 45 | * start of file. NOTE: produces a very high load average!! |
| 46 | * |
| 47 | */ |
| 48 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 49 | #define _LARGEFILE64_SOURCE 1 |
| 50 | #include <stdio.h> |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 51 | #include <sys/types.h> |
| 52 | #include <sys/param.h> |
| 53 | #include <fcntl.h> |
| 54 | #include <sys/stat.h> |
| 55 | #include <sys/mount.h> |
| 56 | #include <sys/wait.h> |
vapier | f81795e | 2006-02-15 06:28:58 +0000 | [diff] [blame] | 57 | #include <errno.h> |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 58 | #include <signal.h> |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 59 | #include <unistd.h> |
| 60 | #include "test.h" |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 61 | #include "libftest.h" |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 62 | |
| 63 | char *TCID = "ftest06"; |
| 64 | int TST_TOTAL = 1; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 65 | |
| 66 | #define PASSED 1 |
| 67 | #define FAILED 0 |
| 68 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 69 | static void crfile(int, int); |
| 70 | static void unlfile(int, int); |
| 71 | static void fussdir(int, int); |
| 72 | static void dotest(int, int); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 73 | static void dowarn(int, char *, char *); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 74 | static void term(int sig); |
| 75 | static void cleanup(void); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 76 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 77 | #define MAXCHILD 25 |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 78 | #define K_1 1024 |
| 79 | #define K_2 2048 |
| 80 | #define K_4 4096 |
| 81 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 82 | static int local_flag; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 83 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 84 | #define M (1024*1024) |
| 85 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 86 | static int iterations; |
| 87 | static int nchild; |
| 88 | static int parent_pid; |
| 89 | static int pidlist[MAXCHILD]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 90 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 91 | static char homedir[MAXPATHLEN]; |
| 92 | static char dirname[MAXPATHLEN]; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 93 | static int dirlen; |
| 94 | static int mnt = 0; |
| 95 | static char startdir[MAXPATHLEN], mntpoint[MAXPATHLEN]; |
| 96 | static char *partition; |
| 97 | static char *cwd; |
| 98 | static char *fstyp; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 99 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 100 | int main(int ac, char *av[]) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 101 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 102 | int pid, child, status, count, k, j; |
| 103 | char name[3]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 104 | |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 105 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 106 | const char *msg; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 107 | |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 108 | /* |
| 109 | * parse standard options |
| 110 | */ |
Garrett Cooper | 0ff96ab | 2011-03-15 05:16:05 -0700 | [diff] [blame] | 111 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 112 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 113 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Default values for run conditions. |
| 116 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 117 | iterations = 50; |
| 118 | nchild = 5; |
| 119 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 120 | if (signal(SIGTERM, term) == SIG_ERR) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | tst_resm(TBROK, "first signal failed"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 122 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* use the default values for run conditions */ |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 126 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 127 | |
| 128 | local_flag = PASSED; |
| 129 | /* |
| 130 | * Make a directory to do this in; ignore error if already exists. |
| 131 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 132 | parent_pid = getpid(); |
| 133 | tst_tmpdir(); |
| 134 | |
| 135 | if (!startdir[0]) { |
| 136 | if (getcwd(startdir, MAXPATHLEN) == NULL) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | tst_brkm(TFAIL | TERRNO, NULL, "getcwd failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 138 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 139 | } |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 140 | cwd = startdir; |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 141 | |
Cyril Hrubis | a33bc18 | 2011-03-16 14:41:10 +0100 | [diff] [blame] | 142 | snprintf(dirname, ARRAY_SIZE(dirname), |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 143 | "%s/ftest06.%d", cwd, getpid()); |
Cyril Hrubis | a33bc18 | 2011-03-16 14:41:10 +0100 | [diff] [blame] | 144 | snprintf(homedir, ARRAY_SIZE(homedir), |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | "%s/ftest06h.%d", cwd, getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 146 | |
| 147 | mkdir(dirname, 0755); |
| 148 | mkdir(homedir, 0755); |
Cyril Hrubis | a33bc18 | 2011-03-16 14:41:10 +0100 | [diff] [blame] | 149 | |
| 150 | if (chdir(dirname) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 151 | tst_brkm(TFAIL | TERRNO, cleanup, "\tCan't chdir(%s)", |
| 152 | dirname); |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 153 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 154 | dirlen = strlen(dirname); |
Cyril Hrubis | a33bc18 | 2011-03-16 14:41:10 +0100 | [diff] [blame] | 155 | |
| 156 | if (chdir(homedir) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 157 | tst_brkm(TFAIL | TERRNO, cleanup, "\tCan't chdir(%s)", |
| 158 | homedir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 159 | |
| 160 | /* enter block */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 161 | for (k = 0; k < nchild; k++) { |
| 162 | if ((child = fork()) == 0) { |
| 163 | dotest(k, iterations); |
Garrett Cooper | 0ff96ab | 2011-03-15 05:16:05 -0700 | [diff] [blame] | 164 | tst_exit(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 165 | } |
| 166 | if (child < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 167 | tst_brkm(TBROK | TERRNO, cleanup, |
| 168 | "fork failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 169 | } |
| 170 | pidlist[k] = child; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Wait for children to finish. |
| 175 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 176 | count = 0; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 177 | while ((child = wait(&status)) > 0) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 178 | //tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status); |
| 179 | //fprintf(stdout, "status is %d",status); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 180 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 181 | tst_resm(TFAIL, |
| 182 | "Test{%d} failed, expected 0 exit.", |
| 183 | child); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 184 | local_flag = FAILED; |
| 185 | } |
| 186 | ++count; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Should have collected all children. |
| 191 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 192 | if (count != nchild) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 193 | tst_resm(TFAIL, |
| 194 | "Wrong # children waited on, count = %d", |
| 195 | count); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 196 | local_flag = FAILED; |
| 197 | } |
| 198 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 199 | if (local_flag == PASSED) |
| 200 | tst_resm(TPASS, "Test passed."); |
| 201 | else |
| 202 | tst_resm(TFAIL, "Test failed."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 203 | |
| 204 | if (iterations > 26) |
| 205 | iterations = 26; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 206 | |
| 207 | for (k = 0; k < nchild; k++) |
| 208 | for (j = 0; j < iterations + 1; j++) { |
| 209 | ft_mkname(name, dirname, k, j); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 210 | rmdir(name); |
| 211 | unlink(name); |
| 212 | } |
| 213 | |
Cyril Hrubis | a33bc18 | 2011-03-16 14:41:10 +0100 | [diff] [blame] | 214 | if (chdir(startdir) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 215 | tst_brkm(TFAIL | TERRNO, cleanup, "Can't chdir(%s)", |
| 216 | startdir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 217 | |
| 218 | pid = fork(); |
| 219 | if (pid < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 220 | tst_brkm(TBROK | TERRNO, NULL, "fork failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 221 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 222 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 223 | if (pid == 0) { |
robbiew | 7fdd514 | 2005-02-07 19:39:54 +0000 | [diff] [blame] | 224 | execl("/bin/rm", "rm", "-rf", homedir, NULL); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 225 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 226 | } else |
| 227 | wait(&status); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 228 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 229 | if (status) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 230 | tst_resm(TINFO, |
| 231 | "CAUTION - ftest06, '%s' may not have been removed.", |
| 232 | homedir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 233 | |
| 234 | pid = fork(); |
| 235 | if (pid < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 236 | tst_brkm(TBROK | TERRNO, NULL, "fork failed"); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 237 | } |
| 238 | if (pid == 0) { |
robbiew | 7fdd514 | 2005-02-07 19:39:54 +0000 | [diff] [blame] | 239 | execl("/bin/rm", "rm", "-rf", dirname, NULL); |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 240 | exit(1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 241 | } else |
| 242 | wait(&status); |
| 243 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 244 | tst_resm(TWARN, |
| 245 | "CAUTION - ftest06, '%s' may not have been removed.", |
| 246 | dirname); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 247 | } |
| 248 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 249 | sync(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 250 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | if (local_flag == FAILED) |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 254 | tst_resm(TFAIL, "Test failed."); |
| 255 | else |
| 256 | tst_resm(TPASS, "Test passed."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 257 | |
| 258 | cleanup(); |
Garrett Cooper | b0a973a | 2011-01-21 01:15:32 -0800 | [diff] [blame] | 259 | tst_exit(); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 260 | } |
| 261 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 262 | #define warn(val,m1,m2) if ((val) < 0) dowarn(me,m1,m2) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * crfile() |
| 266 | * Create a file and write something into it. |
| 267 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 268 | static char crmsg[] = "Gee, let's write something in the file!\n"; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 269 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 270 | static void crfile(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 271 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 272 | int fd; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 273 | off64_t seekval; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 274 | int val; |
| 275 | char fname[MAXPATHLEN]; |
| 276 | char buf[MAXPATHLEN]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 277 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 278 | ft_mkname(fname, dirname, me, count); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 279 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 280 | fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 281 | if (fd < 0 && errno == EISDIR) { |
| 282 | val = rmdir(fname); |
| 283 | warn(val, "rmdir", fname); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 284 | fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 285 | } |
| 286 | warn(fd, "creating", fname); |
| 287 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 288 | seekval = lseek64(fd, (off64_t) (rand() % M), 0); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 289 | warn(seekval, "lseek64", 0); |
| 290 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 291 | val = write(fd, crmsg, sizeof(crmsg) - 1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 292 | warn(val, "write", 0); |
| 293 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 294 | seekval = lseek(fd, -((off64_t) sizeof(crmsg) - 1), 1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 295 | warn(seekval, "lseek64", 0); |
| 296 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 297 | val = read(fd, buf, sizeof(crmsg) - 1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 298 | warn(val, "read", 0); |
| 299 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 300 | if (strncmp(crmsg, buf, sizeof(crmsg) - 1)) |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 301 | dowarn(me, "compare", 0); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 302 | |
| 303 | val = close(fd); |
| 304 | warn(val, "close", 0); |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * unlfile() |
| 309 | * Unlink some of the files. |
| 310 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 311 | static void unlfile(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 312 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 313 | int val, i; |
Garrett Cooper | fde5772 | 2010-08-16 23:37:16 -0700 | [diff] [blame] | 314 | char fname[MAXPATHLEN]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 315 | |
| 316 | i = count - 10; |
| 317 | if (i < 0) |
| 318 | i = 0; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 319 | for (; i < count; i++) { |
| 320 | ft_mkname(fname, dirname, me, i); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 321 | val = rmdir(fname); |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 322 | if (val < 0) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 323 | val = unlink(fname); |
| 324 | if (val == 0 || errno == ENOENT) |
| 325 | continue; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 326 | dowarn(me, "unlink", fname); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * fussdir() |
| 332 | * Make a directory, put stuff in it, remove it, and remove directory. |
| 333 | * |
| 334 | * Randomly leave the directory there. |
| 335 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 336 | static void fussdir(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 337 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 338 | int val; |
Garrett Cooper | fde5772 | 2010-08-16 23:37:16 -0700 | [diff] [blame] | 339 | char dir[MAXPATHLEN], fname[MAXPATHLEN], savedir[MAXPATHLEN]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 340 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 341 | ft_mkname(dir, dirname, me, count); |
| 342 | rmdir(dir); |
| 343 | unlink(dir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 344 | |
| 345 | val = mkdir(dir, 0755); |
| 346 | warn(val, "mkdir", dir); |
| 347 | |
| 348 | /* |
| 349 | * Arrange to create files in the directory. |
| 350 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 351 | strcpy(savedir, dirname); |
| 352 | strcpy(dirname, ""); |
| 353 | |
| 354 | val = chdir(dir); |
| 355 | warn(val, "chdir", dir); |
| 356 | |
| 357 | crfile(me, count); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 358 | crfile(me, count + 1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 359 | |
| 360 | val = chdir(".."); |
| 361 | warn(val, "chdir", ".."); |
| 362 | |
| 363 | val = rmdir(dir); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 364 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 365 | if (val >= 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 366 | tst_brkm(TFAIL, NULL, |
| 367 | "Test[%d]: rmdir of non-empty %s succeeds!", me, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 368 | dir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | val = chdir(dir); |
| 372 | warn(val, "chdir", dir); |
| 373 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 374 | ft_mkname(fname, dirname, me, count); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 375 | val = unlink(fname); |
| 376 | warn(val, "unlink", fname); |
| 377 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 378 | ft_mkname(fname, dirname, me, count + 1); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 379 | val = unlink(fname); |
| 380 | warn(val, "unlink", fname); |
| 381 | |
| 382 | val = chdir(homedir); |
| 383 | warn(val, "chdir", homedir); |
| 384 | |
| 385 | if (rand() & 0x01) { |
| 386 | val = rmdir(dir); |
| 387 | warn(val, "rmdir", dir); |
| 388 | } |
| 389 | |
| 390 | strcpy(dirname, savedir); |
| 391 | } |
| 392 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 393 | /* |
| 394 | * dotest() |
| 395 | * Children execute this. |
| 396 | * |
| 397 | * Randomly do an inode thing; loop for # iterations. |
| 398 | */ |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 399 | #define THING(p) {p, "p"} |
| 400 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 401 | struct ino_thing { |
| 402 | void (*it_proc) (); |
| 403 | char *it_name; |
| 404 | } ino_thing[] = { |
| 405 | THING(crfile), THING(unlfile), THING(fussdir), THING(sync),}; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 406 | |
| 407 | #define NTHING (sizeof(ino_thing) / sizeof(ino_thing[0])) |
| 408 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 409 | int thing_cnt[NTHING]; |
| 410 | int thing_last[NTHING]; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 411 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 412 | static void dotest(int me, int count) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 413 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 414 | int thing, i; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 415 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 416 | //tst_resm(TINFO,"Test %d pid %d starting.", me, getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 417 | |
| 418 | srand(getpid()); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 419 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 420 | for (i = 0; i < count; i++) { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 421 | thing = (rand() >> 3) % NTHING; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 422 | (*ino_thing[thing].it_proc) (me, i, ino_thing[thing].it_name); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 423 | ++thing_cnt[thing]; |
| 424 | } |
| 425 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 426 | //tst_resm(TINFO,"Test %d pid %d exiting.", me, getpid()); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 427 | } |
| 428 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 429 | static void dowarn(int me, char *m1, char *m2) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 430 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 431 | int err = errno; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 432 | |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 433 | tst_brkm(TFAIL, NULL, "Test[%d]: error %d on %s %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 434 | me, err, m1, (m2 ? m2 : "")); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 435 | } |
| 436 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 437 | static void term(int sig LTP_ATTRIBUTE_UNUSED) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 438 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 439 | int i; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 440 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 441 | tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid()); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 442 | |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 443 | if (parent_pid == getpid()) { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 444 | for (i = 0; i < nchild; i++) |
| 445 | if (pidlist[i]) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 446 | kill(pidlist[i], SIGTERM); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 447 | return; |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 448 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 449 | |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 450 | tst_brkm(TBROK, NULL, "Term: Child process exiting."); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 451 | } |
| 452 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 453 | static void cleanup(void) |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 454 | { |
| 455 | char mount_buffer[1024]; |
| 456 | |
| 457 | if (mnt == 1) { |
| 458 | if (chdir(startdir) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 459 | tst_resm(TINFO, "Could not change to %s ", startdir); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 460 | } |
| 461 | if (!strcmp(fstyp, "cfs")) { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 462 | sprintf(mount_buffer, "/bin/umount %s", partition); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 463 | if (system(mount_buffer) != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 464 | tst_resm(TINFO, "Unable to unmount %s from %s ", |
| 465 | partition, mntpoint); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 466 | if (umount(partition)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 467 | tst_resm(TINFO, |
| 468 | "Unable to unmount %s from %s ", |
| 469 | partition, mntpoint); |
| 470 | } else { |
| 471 | tst_resm(TINFO, |
| 472 | "Forced umount for %s, /etc/mtab now dirty", |
| 473 | partition); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 476 | } else { |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 477 | if (umount(partition)) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 478 | tst_resm(TINFO, "Unable to unmount %s from %s ", |
| 479 | partition, mntpoint); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | if (rmdir(mntpoint) != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 483 | tst_resm(TINFO, "Unable to rmdir %s ", mntpoint); |
robbiew | 24e30ab | 2003-01-07 20:53:21 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | tst_rmdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 487 | |
Garrett Cooper | b0a973a | 2011-01-21 01:15:32 -0800 | [diff] [blame] | 488 | } |