robbiew | 176cb5c | 2003-01-07 20:55:22 +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 | 176cb5c | 2003-01-07 20:55:22 +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 | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * NAME |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 23 | * ftest07.c -- test file I/O with readv and writev (ported from SPIE, |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 24 | * section2/filesuite/ftest9.c |
| 25 | * |
| 26 | * this is the same as ftest4, except that it uses lseek64 |
| 27 | * |
| 28 | * CALLS |
| 29 | * lseek64, readv, writev, |
| 30 | * truncate, ftruncate, fsync, sync, fstat |
| 31 | * |
| 32 | * ALGORITHM |
| 33 | * A bitmap is used to map pieces of a file. |
| 34 | * Loop: pick a random piece of the file |
| 35 | * if we haven't seen it before make sure it is zero, |
| 36 | * write pattern |
| 37 | * if we have seen it before make sure correct pattern. |
| 38 | * |
| 39 | * This was originally written by rbk - was program tfio.c |
| 40 | * Modified by dale to integrate with test suites. |
| 41 | * Modified by G. Stevens to use readv and writev. |
| 42 | * Modofied by K. Hakim to integrate with SPIES. |
| 43 | * |
| 44 | * RESTRICTIONS |
| 45 | * 1. Runs a long time with default args - can take others on input |
| 46 | * line. Use with "term mode". |
| 47 | * If run on vax the ftruncate will not be random - will always go to |
| 48 | * start of file. NOTE: produces a very high load average!! |
| 49 | * |
| 50 | * 2. The "csize" argument must be evenly divisible by MAXIOVCNT. |
| 51 | * |
| 52 | * CAUTION!! |
| 53 | * If a file is supplied to this program with the "-f" option |
| 54 | * it will be removed with a system("rm -rf filename") call. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 55 | * |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 56 | * |
| 57 | */ |
| 58 | |
| 59 | #define _XOPEN_SOURCE 500 |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 60 | #define _LARGEFILE64_SOURCE 1 |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 61 | #include <sys/types.h> |
| 62 | #include <sys/param.h> |
| 63 | #include <sys/wait.h> |
| 64 | #include <sys/stat.h> |
vapier | f81795e | 2006-02-15 06:28:58 +0000 | [diff] [blame] | 65 | #include <errno.h> |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 66 | #include <sys/uio.h> |
| 67 | #include <fcntl.h> |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 68 | #include <signal.h> |
| 69 | #include <stdio.h> |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 70 | #include <unistd.h> |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 71 | #include <inttypes.h> |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 72 | #include "test.h" |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 73 | #include "libftest.h" |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 74 | |
| 75 | char *TCID = "ftest07"; |
| 76 | int TST_TOTAL = 1; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 77 | |
| 78 | #define PASSED 1 |
| 79 | #define FAILED 0 |
| 80 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 81 | #define MAXCHILD 25 |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 82 | #define K_1 1024 |
| 83 | #define K_2 2048 |
| 84 | #define K_4 4096 |
| 85 | #define MAXIOVCNT 16 |
| 86 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 87 | static void setup(void); |
| 88 | static void runtest(void); |
| 89 | static void dotest(int, int, int); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 90 | static void domisc(int, int, char *); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 91 | static void term(int sig); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 92 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 93 | static int csize; /* chunk size */ |
| 94 | static int iterations; /* # total iterations */ |
| 95 | static off64_t max_size; /* max file size */ |
| 96 | static int misc_intvl; /* for doing misc things; 0 ==> no */ |
| 97 | static int nchild; /* how many children */ |
| 98 | static int fd; /* file descriptor used by child */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 99 | static int parent_pid; |
| 100 | static int pidlist[MAXCHILD]; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 101 | static char test_name[2]; /* childs test directory name */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 102 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | static char fuss[MAXPATHLEN]; /* directory to do this in */ |
| 104 | static char homedir[MAXPATHLEN]; /* where we started */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 105 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 106 | static int local_flag; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 107 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 108 | int main(int ac, char *av[]) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 109 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 110 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 111 | const char *msg; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 112 | |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 113 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Cyril Hrubis | ee7667e | 2014-09-24 13:14:56 +0200 | [diff] [blame] | 114 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 115 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 116 | setup(); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 117 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 118 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 119 | |
| 120 | local_flag = PASSED; |
| 121 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 122 | runtest(); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 123 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 124 | if (local_flag == PASSED) |
| 125 | tst_resm(TPASS, "Test passed."); |
| 126 | else |
| 127 | tst_resm(TFAIL, "Test failed."); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 128 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 129 | tst_rmdir(); |
| 130 | tst_exit(); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 131 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 134 | tst_exit(); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 135 | } |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 136 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 137 | static void setup(void) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 138 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 139 | char wdbuf[MAXPATHLEN], *cwd; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * Make a directory to do this in; ignore error if already exists. |
| 143 | * Save starting directory. |
| 144 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | if ((cwd = getcwd(homedir, sizeof(homedir))) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 146 | tst_brkm(TBROK, NULL, "Failed to get corrent directory"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | parent_pid = getpid(); |
| 150 | tst_tmpdir(); |
| 151 | if (!fuss[0]) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 152 | sprintf(fuss, "%s/ftest07.%d", getcwd(wdbuf, sizeof(wdbuf)), |
| 153 | getpid()); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 154 | |
| 155 | mkdir(fuss, 0755); |
| 156 | |
| 157 | if (chdir(fuss) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 158 | tst_brkm(TBROK, NULL, "\tCan't chdir(%s), error %d.", fuss, |
| 159 | errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Default values for run conditions. |
| 164 | */ |
| 165 | |
| 166 | iterations = 10; |
| 167 | nchild = 5; |
| 168 | csize = K_2; /* should run with 1, 2, and 4 K sizes */ |
| 169 | max_size = K_1 * K_1; |
| 170 | misc_intvl = 10; |
| 171 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 172 | if (sigset(SIGTERM, term) == SIG_ERR) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 173 | tst_brkm(TBROK | TERRNO, NULL, "sigset (signo=SIGTERM) failed"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | } |
| 177 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 178 | static void runtest(void) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 179 | { |
Garrett Cooper | 7a73eab | 2010-11-09 22:45:42 -0800 | [diff] [blame] | 180 | pid_t pid; |
| 181 | int child, count, i, nwait, status; |
| 182 | |
| 183 | nwait = 0; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 184 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 185 | for (i = 0; i < nchild; i++) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 186 | test_name[0] = 'a' + i; |
| 187 | test_name[1] = '\0'; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 188 | fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 189 | if (fd < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 190 | tst_brkm(TBROK, NULL, "\tError %d creating %s/%s.", |
| 191 | errno, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 192 | fuss, test_name); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 193 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 194 | |
| 195 | if ((child = fork()) == 0) { |
| 196 | dotest(nchild, i, fd); |
| 197 | tst_exit(); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | close(fd); |
| 201 | |
| 202 | if (child < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 203 | tst_brkm(TBROK | TERRNO, NULL, "fork failed"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 204 | } else { |
| 205 | pidlist[i] = child; |
| 206 | nwait++; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Wait for children to finish. |
| 212 | */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 213 | count = 0; |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 214 | while (1) { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 215 | if ((child = wait(&status)) >= 0) { |
| 216 | //tst_resm(TINFO, "\tTest{%d} exited status = 0x%x", child, status); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 217 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 218 | tst_resm(TFAIL, |
| 219 | "\tTest{%d} failed, expected 0 exit.", |
| 220 | child); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 221 | local_flag = FAILED; |
| 222 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 223 | ++count; |
| 224 | } else { |
| 225 | if (errno != EINTR) |
| 226 | break; |
| 227 | } |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Should have collected all children. |
| 232 | */ |
| 233 | |
| 234 | if (count != nwait) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 235 | tst_resm(TFAIL, "\tWrong # children waited on, count = %d", |
| 236 | count); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 237 | local_flag = FAILED; |
| 238 | } |
| 239 | |
| 240 | chdir(homedir); |
| 241 | |
| 242 | pid = fork(); |
| 243 | if (pid < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 244 | tst_brkm(TBROK | TERRNO, NULL, "fork failed"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | if (pid == 0) { |
robbiew | 7fdd514 | 2005-02-07 19:39:54 +0000 | [diff] [blame] | 248 | execl("/bin/rm", "rm", "-rf", fuss, NULL); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 249 | exit(1); |
| 250 | } else |
| 251 | wait(&status); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 252 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 253 | tst_resm(TINFO, "CAUTION - ftest07, '%s' may not be removed", |
| 254 | fuss); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 255 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 256 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 257 | sync(); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* |
| 261 | * dotest() |
| 262 | * Children execute this. |
| 263 | * |
| 264 | * Randomly read/mod/write chunks with known pattern and check. |
| 265 | * When fill sectors, iterate. |
| 266 | */ |
| 267 | |
| 268 | #define NMISC 4 |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 269 | enum m_type { m_fsync, m_trunc, m_sync, m_fstat }; |
| 270 | char *m_str[] = { "fsync", "trunc", "sync", "fstat" }; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 271 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 272 | int misc_cnt[NMISC]; /* counts # of each kind of misc */ |
| 273 | int file_max; /* file-max size */ |
| 274 | int nchunks; |
| 275 | int last_trunc = -1; |
| 276 | int tr_flag; |
| 277 | enum m_type type = m_fsync; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 278 | |
| 279 | #define CHUNK(i) (((off64_t)i) * csize) |
| 280 | #define NEXTMISC ((rand() % misc_intvl) + 5) |
| 281 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 282 | static void dotest(int testers, int me, int fd) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 283 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 284 | char *bits, *hold_bits; |
| 285 | char val; |
| 286 | int count, collide, chunk, whenmisc, xfr, i; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 287 | |
| 288 | /* Stuff for the readv call */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 289 | struct iovec r_iovec[MAXIOVCNT]; |
| 290 | int r_ioveclen; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 291 | |
| 292 | /* Stuff for the writev call */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 293 | struct iovec val_iovec[MAXIOVCNT]; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 294 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 295 | struct iovec zero_iovec[MAXIOVCNT]; |
| 296 | int w_ioveclen; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 297 | |
| 298 | nchunks = max_size / csize; |
Garrett Cooper | f01306b | 2010-11-05 11:14:08 -0700 | [diff] [blame] | 299 | whenmisc = 0; |
| 300 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 301 | if ((bits = malloc((nchunks + 7) / 8)) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 302 | tst_brkm(TBROK, NULL, "\tmalloc failed(bits)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 303 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 304 | if ((hold_bits = malloc((nchunks + 7) / 8)) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 305 | tst_brkm(TBROK, NULL, "\tmalloc failed(hlod_bits)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /*Allocate memory for the iovec buffers and init the iovec arrays |
| 309 | */ |
| 310 | r_ioveclen = w_ioveclen = csize / MAXIOVCNT; |
| 311 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 312 | /* Please note that the above statement implies that csize |
| 313 | * be evenly divisible by MAXIOVCNT. |
| 314 | */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 315 | |
| 316 | for (i = 0; i < MAXIOVCNT; i++) { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 317 | if ((r_iovec[i].iov_base = calloc(r_ioveclen, 1)) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 318 | tst_brkm(TFAIL, NULL, |
| 319 | "\tmalloc failed(r_iovec[i].iov_base)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 320 | } |
| 321 | r_iovec[i].iov_len = r_ioveclen; |
| 322 | |
| 323 | /* Allocate unused memory areas between all the buffers to |
| 324 | * make things more diffult for the OS. |
| 325 | */ |
| 326 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 327 | if (malloc((i + 1) * 8) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 328 | tst_brkm(TBROK, NULL, "\tmalloc failed((i+1)*8)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 329 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 330 | if ((val_iovec[i].iov_base = calloc(w_ioveclen, 1)) == NULL) { |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 331 | tst_resm(TBROK, "\tmalloc failed(val_iovec[i]"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 332 | exit(1); |
| 333 | } |
| 334 | val_iovec[i].iov_len = w_ioveclen; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 335 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 336 | if (malloc((i + 1) * 8) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 337 | tst_brkm(TBROK, NULL, "\tmalloc failed((i+1)*8)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 338 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 339 | if ((zero_iovec[i].iov_base = calloc(w_ioveclen, 1)) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 340 | tst_brkm(TBROK, NULL, "\tmalloc failed(zero_iover)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 341 | } |
| 342 | zero_iovec[i].iov_len = w_ioveclen; |
| 343 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 344 | if (malloc((i + 1) * 8) == NULL) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 345 | tst_brkm(TBROK, NULL, "\tmalloc failed((i+1)*8)"); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | /* |
| 349 | * No init sectors; allow file to be sparse. |
| 350 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 351 | val = (64 / testers) * me + 1; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 352 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 353 | /* |
| 354 | * For each iteration: |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 355 | * zap bits array |
| 356 | * loop |
| 357 | * pick random chunk, read it. |
| 358 | * if corresponding bit off { |
| 359 | * verify = 0. (sparse file) |
| 360 | * ++count; |
| 361 | * } else |
| 362 | * verify = val. |
| 363 | * write "val" on it. |
| 364 | * repeat unitl count = nchunks. |
| 365 | * ++val. |
| 366 | */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 367 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 368 | srand(getpid()); |
| 369 | if (misc_intvl) |
| 370 | whenmisc = NEXTMISC; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 371 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 372 | while (iterations-- > 0) { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 373 | for (i = 0; i < NMISC; i++) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 374 | misc_cnt[i] = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 375 | ftruncate(fd, 0); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 376 | file_max = 0; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 377 | memset(bits, 0, (nchunks + 7) / 8); |
| 378 | memset(hold_bits, 0, (nchunks + 7) / 8); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 379 | |
| 380 | /* Have to fill the val and zero iov buffers in a different manner |
| 381 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 382 | for (i = 0; i < MAXIOVCNT; i++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 383 | memset(val_iovec[i].iov_base, val, |
| 384 | val_iovec[i].iov_len); |
| 385 | memset(zero_iovec[i].iov_base, 0, |
| 386 | zero_iovec[i].iov_len); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 387 | |
| 388 | } |
| 389 | count = 0; |
| 390 | collide = 0; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 391 | while (count < nchunks) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 392 | chunk = rand() % nchunks; |
| 393 | /* |
| 394 | * Read it. |
| 395 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 396 | if (lseek64(fd, CHUNK(chunk), 0) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 397 | tst_brkm(TFAIL, |
| 398 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 399 | "\tTest[%d]: lseek64(0) fail at %Lx, errno = %d.", |
| 400 | me, CHUNK(chunk), errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 401 | } |
| 402 | if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 403 | tst_brkm(TFAIL, |
| 404 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 405 | "\tTest[%d]: readv fail at %Lx, errno = %d.", |
| 406 | me, CHUNK(chunk), errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 407 | } |
| 408 | /* |
| 409 | * If chunk beyond EOF just write on it. |
| 410 | * Else if bit off, haven't seen it yet. |
| 411 | * Else, have. Verify values. |
| 412 | */ |
| 413 | if (CHUNK(chunk) >= file_max) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 414 | bits[chunk / 8] |= (1 << (chunk % 8)); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 415 | ++count; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 416 | } else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 417 | if (xfr != csize) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 418 | tst_brkm(TFAIL, |
| 419 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 420 | "\tTest[%d]: xfr=%d != %d, zero read.", |
| 421 | me, xfr, csize); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 422 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 423 | for (i = 0; i < MAXIOVCNT; i++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 424 | if (memcmp |
| 425 | (r_iovec[i].iov_base, |
| 426 | zero_iovec[i].iov_base, |
| 427 | r_iovec[i].iov_len)) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 428 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 429 | "\tTest[%d] bad verify @ 0x%Lx for val %d count %d xfr %d file_max 0x%x, should be 0.", |
| 430 | me, CHUNK(chunk), val, |
| 431 | count, xfr, file_max); |
| 432 | tst_resm(TINFO, |
| 433 | "\tTest[%d]: last_trunc = 0x%x.", |
| 434 | me, last_trunc); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 435 | sync(); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 436 | ft_dumpiov(&r_iovec[i]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 437 | ft_dumpbits(bits, |
| 438 | (nchunks + 7) / 8); |
| 439 | ft_orbits(hold_bits, bits, |
| 440 | (nchunks + 7) / 8); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 441 | tst_resm(TINFO, "\tHold "); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 442 | ft_dumpbits(hold_bits, |
| 443 | (nchunks + 7) / 8); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 444 | tst_exit(); |
| 445 | } |
| 446 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 447 | bits[chunk / 8] |= (1 << (chunk % 8)); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 448 | ++count; |
| 449 | } else { |
| 450 | if (xfr != csize) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 451 | tst_brkm(TFAIL, |
| 452 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 453 | "\tTest[%d]: xfr=%d != %d, val read.", |
| 454 | me, xfr, csize); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 455 | } |
| 456 | ++collide; |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 457 | for (i = 0; i < MAXIOVCNT; i++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 458 | if (memcmp |
| 459 | (r_iovec[i].iov_base, |
| 460 | val_iovec[i].iov_base, |
| 461 | r_iovec[i].iov_len)) { |
| 462 | tst_resm(TFAIL, |
| 463 | "\tTest[%d] bad verify @ 0x%Lx for val %d count %d xfr %d file_max 0x%x.", |
| 464 | me, CHUNK(chunk), val, |
| 465 | count, xfr, file_max); |
| 466 | tst_resm(TINFO, |
| 467 | "\tTest[%d]: last_trunc = 0x%x.", |
| 468 | me, last_trunc); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 469 | sync(); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 470 | ft_dumpiov(&r_iovec[i]); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 471 | ft_dumpbits(bits, |
| 472 | (nchunks + 7) / 8); |
| 473 | ft_orbits(hold_bits, bits, |
| 474 | (nchunks + 7) / 8); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 475 | tst_resm(TINFO, "\tHold "); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 476 | ft_dumpbits(hold_bits, |
| 477 | (nchunks + 7) / 8); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 478 | tst_exit(); |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | /* |
| 483 | * Writev it. |
| 484 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 485 | if (lseek64(fd, -((off64_t) xfr), 1) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 486 | tst_brkm(TFAIL, |
| 487 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 488 | "\tTest[%d]: lseek64(1) fail at %Lx, errno = %d.", |
| 489 | me, CHUNK(chunk), errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 490 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 491 | if ((xfr = |
| 492 | writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 493 | if (errno == ENOSPC) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 494 | tst_resm(TFAIL, |
| 495 | "\tTest[%d]: no space, exiting.", |
| 496 | me); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 497 | fsync(fd); |
| 498 | tst_exit(); |
| 499 | } |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 500 | tst_brkm(TFAIL, |
| 501 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 502 | "\tTest[%d]: writev fail at %Lx xfr %d, errno = %d.", |
| 503 | me, CHUNK(chunk), xfr, errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 504 | } |
| 505 | if (CHUNK(chunk) + csize > file_max) |
| 506 | file_max = CHUNK(chunk) + csize; |
| 507 | /* |
| 508 | * If hit "misc" interval, do it. |
| 509 | */ |
| 510 | if (misc_intvl && --whenmisc <= 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 511 | ft_orbits(hold_bits, bits, (nchunks + 7) / 8); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 512 | domisc(me, fd, bits); |
| 513 | whenmisc = NEXTMISC; |
| 514 | } |
| 515 | if (count + collide > 2 * nchunks) |
| 516 | break; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * End of iteration, maybe before doing all chunks. |
| 521 | */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 522 | fsync(fd); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 523 | ++misc_cnt[m_fsync]; |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 524 | //tst_resm(TINFO, "\tTest{%d} val %d done, count = %d, collide = {%d}", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 525 | // me, val, count, collide); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 526 | //for (i = 0; i < NMISC; i++) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 527 | // tst_resm(TINFO, "\t\tTest{%d}: {%d} %s's.", me, misc_cnt[i], m_str[i]); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 528 | ++val; |
| 529 | } |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* |
| 533 | * domisc() |
| 534 | * Inject misc syscalls into the thing. |
| 535 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 536 | static void domisc(int me, int fd, char *bits) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 537 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 538 | int chunk; |
| 539 | struct stat sb; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 540 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 541 | if (type > m_fstat) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 542 | type = m_fsync; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 543 | switch (type) { |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 544 | case m_fsync: |
| 545 | if (fsync(fd) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 546 | tst_brkm(TFAIL, NULL, "\tTest[%d]: fsync error %d.", |
| 547 | me, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 548 | errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 549 | } |
| 550 | break; |
| 551 | case m_trunc: |
| 552 | chunk = rand() % (file_max / csize); |
| 553 | file_max = CHUNK(chunk); |
| 554 | last_trunc = file_max; |
| 555 | if (tr_flag) { |
| 556 | if (ftruncate(fd, file_max) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 557 | tst_brkm(TFAIL, |
| 558 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 559 | "\tTest[%d]: ftruncate error %d @ 0x%x.", |
| 560 | me, errno, file_max); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 561 | } |
| 562 | tr_flag = 0; |
| 563 | } else { |
| 564 | if (truncate(test_name, file_max) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 565 | tst_brkm(TFAIL, |
| 566 | NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 567 | "\tTest[%d]: truncate error %d @ 0x%x.", |
| 568 | me, errno, file_max); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 569 | } |
| 570 | tr_flag = 1; |
| 571 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 572 | for (; chunk % 8 != 0; chunk++) |
| 573 | bits[chunk / 8] &= ~(1 << (chunk % 8)); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 574 | for (; chunk < nchunks; chunk += 8) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 575 | bits[chunk / 8] = 0; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 576 | break; |
| 577 | case m_sync: |
| 578 | sync(); |
| 579 | break; |
| 580 | case m_fstat: |
| 581 | if (fstat(fd, &sb) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 582 | tst_brkm(TFAIL, NULL, "\tTest[%d]: fstat() error %d.", |
| 583 | me, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 584 | errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 585 | } |
| 586 | if (sb.st_size != file_max) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 587 | tst_brkm(TFAIL, |
| 588 | NULL, "\tTest[%d]: fstat() mismatch; st_size=%" |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 589 | PRIx64 ",file_max=%x.", me, |
| 590 | (int64_t) sb.st_size, file_max); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 591 | } |
| 592 | break; |
| 593 | } |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 594 | |
| 595 | ++misc_cnt[type]; |
| 596 | ++type; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 597 | } |
| 598 | |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 599 | /* term() |
| 600 | * |
| 601 | * This is called when a SIGTERM signal arrives. |
| 602 | */ |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 603 | static void term(int sig LTP_ATTRIBUTE_UNUSED) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 604 | { |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 605 | int i; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 606 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 607 | tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid()); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 608 | |
| 609 | /* |
| 610 | * If run by hand we like to have the parent send the signal to |
| 611 | * the child processes. This makes life easy. |
| 612 | */ |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 613 | if (parent_pid == getpid()) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 614 | for (i = 0; i < nchild; i++) |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 615 | if (pidlist[i]) |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 616 | kill(pidlist[i], SIGTERM); |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 617 | return; |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 618 | } |
| 619 | |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 620 | tst_resm(TINFO, "\tunlinking '%s'", test_name); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 621 | |
| 622 | close(fd); |
| 623 | if (unlink(test_name)) |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 624 | tst_resm(TBROK, "Unlink of '%s' failed, errno = %d.", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 625 | test_name, errno); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 626 | else |
vapier | af64a87 | 2006-02-15 06:47:36 +0000 | [diff] [blame] | 627 | tst_resm(TINFO, "Unlink of '%s' successful.", test_name); |
robbiew | 176cb5c | 2003-01-07 20:55:22 +0000 | [diff] [blame] | 628 | |
subrata_modak | 04f47a1 | 2009-09-18 17:44:08 +0000 | [diff] [blame] | 629 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 630 | } |