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