blob: 31f3e104abdda266497e363602c2db47ee6a9100 [file] [log] [blame]
robbiew24e30ab2003-01-07 20:53:21 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2002
subrata_modak04f47a12009-09-18 17:44:08 +00004 * Copyright (c) Cyril Hrubis chrubis@suse.cz 2009
robbiew24e30ab2003-01-07 20:53:21 +00005 *
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 Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew24e30ab2003-01-07 20:53:21 +000019 */
20
21/*
22 * NAME
23 * ftest04.c -- test single file io (tsfio.c by rbk) (ported from SPIE, section2/filesuite/ftest5.c, by Airong Zhang)
24 *
25 * CALLS
26 * fsync, sync, lseek, read, write
subrata_modakbdbaec52009-02-26 12:14:51 +000027 *
robbiew24e30ab2003-01-07 20:53:21 +000028 *
29 * ALGORITHM
30 * Several child processes doing random seeks, read/write
31 * operations on the same file.
32 *
33 *
34 * RESTRICTIONS
35 * Runs a long time with default args - can take others on input
36 * line. Use with "term mode".
subrata_modakbdbaec52009-02-26 12:14:51 +000037 *
robbiew24e30ab2003-01-07 20:53:21 +000038 */
39#define _XOPEN_SOURCE 500
subrata_modak04f47a12009-09-18 17:44:08 +000040#include <stdio.h>
robbiew24e30ab2003-01-07 20:53:21 +000041#include <sys/types.h>
42#include <sys/param.h>
43#include <sys/wait.h>
44#include <sys/file.h>
45#include <sys/fcntl.h>
46#include <sys/stat.h>
47#include <sys/uio.h>
vapierf81795e2006-02-15 06:28:58 +000048#include <errno.h>
subrata_modak04f47a12009-09-18 17:44:08 +000049#include <signal.h>
robbiew24e30ab2003-01-07 20:53:21 +000050#include "test.h"
subrata_modak04f47a12009-09-18 17:44:08 +000051#include "libftest.h"
robbiew24e30ab2003-01-07 20:53:21 +000052
53char *TCID = "ftest04";
54int TST_TOTAL = 1;
robbiew24e30ab2003-01-07 20:53:21 +000055
subrata_modak04f47a12009-09-18 17:44:08 +000056static void setup(void);
57static void runtest(void);
58static void dotest(int, int, int);
59static void domisc(int, int);
60static void term(int sig);
robbiew24e30ab2003-01-07 20:53:21 +000061
62#define PASSED 1
63#define FAILED 0
64
subrata_modak04f47a12009-09-18 17:44:08 +000065#define MAXCHILD 25
robbiew24e30ab2003-01-07 20:53:21 +000066#define K_1 1024
67#define K_2 2048
68#define K_4 4096
69#define MAXIOVCNT 16
70
Wanlong Gao354ebb42012-12-07 10:10:04 +080071static int csize; /* chunk size */
72static int iterations; /* # total iterations */
73static int max_size; /* max file size */
74static int misc_intvl; /* for doing misc things; 0 ==> no */
75static int nchild; /* number of child processes */
subrata_modak04f47a12009-09-18 17:44:08 +000076static int parent_pid;
77static int pidlist[MAXCHILD];
robbiew24e30ab2003-01-07 20:53:21 +000078
Garrett Cooperfde57722010-08-16 23:37:16 -070079static char filename[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +000080
subrata_modak04f47a12009-09-18 17:44:08 +000081static int local_flag;
robbiew24e30ab2003-01-07 20:53:21 +000082
subrata_modak04f47a12009-09-18 17:44:08 +000083int main(int ac, char *av[])
robbiew24e30ab2003-01-07 20:53:21 +000084{
subrata_modak04f47a12009-09-18 17:44:08 +000085 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020086 const char *msg;
robbiew24e30ab2003-01-07 20:53:21 +000087
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020088 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Cyril Hrubisee7667e2014-09-24 13:14:56 +020089 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew24e30ab2003-01-07 20:53:21 +000090
Wanlong Gao354ebb42012-12-07 10:10:04 +080091 setup();
robbiew24e30ab2003-01-07 20:53:21 +000092
Wanlong Gao354ebb42012-12-07 10:10:04 +080093 for (lc = 0; TEST_LOOPING(lc); lc++) {
robbiew24e30ab2003-01-07 20:53:21 +000094
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 runtest();
robbiew24e30ab2003-01-07 20:53:21 +000096
Wanlong Gao354ebb42012-12-07 10:10:04 +080097 if (local_flag == PASSED)
98 tst_resm(TPASS, "Test passed.");
99 else
100 tst_resm(TFAIL, "Test failed.");
subrata_modak04f47a12009-09-18 17:44:08 +0000101
102 /* ??? only one loop ??? */
robbiew24e30ab2003-01-07 20:53:21 +0000103 tst_rmdir();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800104 tst_exit();
subrata_modak04f47a12009-09-18 17:44:08 +0000105 }
106
Garrett Cooper2c282152010-12-16 00:55:50 -0800107 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000108}
109
subrata_modak04f47a12009-09-18 17:44:08 +0000110static void setup(void)
robbiew24e30ab2003-01-07 20:53:21 +0000111{
112 int fd;
113 char wdbuf[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000114
115 parent_pid = getpid();
116
117 /*
118 * Make a filename for the test.
119 */
120 tst_tmpdir();
121 if (!filename[0])
Wanlong Gao354ebb42012-12-07 10:10:04 +0800122 sprintf(filename, "%s/ftest04.%d", getcwd(wdbuf, MAXPATHLEN),
123 getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000124
Wanlong Gao354ebb42012-12-07 10:10:04 +0800125 fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
robbiew24e30ab2003-01-07 20:53:21 +0000126 if (fd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100127 tst_brkm(TBROK, NULL, "Error %d creating file %s", errno,
128 filename);
robbiew24e30ab2003-01-07 20:53:21 +0000129 }
130 close(fd);
131
robbiew24e30ab2003-01-07 20:53:21 +0000132 /*
133 * Default values for run conditions.
134 */
robbiew24e30ab2003-01-07 20:53:21 +0000135 iterations = 10;
136 nchild = 5;
137 csize = K_2; /* should run with 1, 2, and 4 K sizes */
138 max_size = K_1 * K_1;
139 misc_intvl = 10;
140
subrata_modak04f47a12009-09-18 17:44:08 +0000141 if (sigset(SIGTERM, term) == SIG_ERR) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100142 tst_brkm(TFAIL, NULL, "first sigset failed");
robbiew24e30ab2003-01-07 20:53:21 +0000143 }
144
145 local_flag = PASSED;
146}
147
subrata_modak04f47a12009-09-18 17:44:08 +0000148static void runtest(void)
robbiew24e30ab2003-01-07 20:53:21 +0000149{
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800150 int count, child, fd, i, nwait, status;
151
152 nwait = 0;
robbiew24e30ab2003-01-07 20:53:21 +0000153
subrata_modak04f47a12009-09-18 17:44:08 +0000154 for (i = 0; i < nchild; i++) {
155 if ((child = fork()) == 0) {
robbiew24e30ab2003-01-07 20:53:21 +0000156 fd = open(filename, O_RDWR);
157 if (fd < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100158 tst_brkm(TBROK,
159 NULL,
160 "\tTest[%d]: error %d openning %s.",
161 i,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800162 errno, filename);
robbiew24e30ab2003-01-07 20:53:21 +0000163 }
subrata_modak04f47a12009-09-18 17:44:08 +0000164 dotest(nchild, i, fd);
subrata_modak2f5be082008-08-27 11:28:24 +0000165 close(fd);
subrata_modak04f47a12009-09-18 17:44:08 +0000166 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000167 }
robbiew24e30ab2003-01-07 20:53:21 +0000168 if (child < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800169 tst_brkm(TBROK | TERRNO, NULL, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000170 } else {
171 pidlist[i] = child;
172 nwait++;
173 }
174 }
175
176 /*
177 * Wait for children to finish.
178 */
robbiew24e30ab2003-01-07 20:53:21 +0000179 count = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000180 while ((child = wait(&status)) != -1 || errno == EINTR) {
181 if (child > 0) {
vapieraf64a872006-02-15 06:47:36 +0000182 //tst_resm(TINFO, "\tTest{%d} exited status = 0x%x", child, status);
robbiew24e30ab2003-01-07 20:53:21 +0000183 if (status) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800184 tst_resm(TFAIL,
185 "\tExpected 0 exit status - failed.");
robbiew24e30ab2003-01-07 20:53:21 +0000186 local_flag = FAILED;
187 }
188 ++count;
189 }
190 }
191
192 /*
193 * Should have collected all children.
194 */
robbiew24e30ab2003-01-07 20:53:21 +0000195 if (count != nwait) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800196 tst_resm(TFAIL, "\tWrong # children waited on, count = %d",
197 count);
robbiew24e30ab2003-01-07 20:53:21 +0000198 local_flag = FAILED;
199 }
200
201 unlink(filename);
subrata_modak04f47a12009-09-18 17:44:08 +0000202 sync();
robbiew24e30ab2003-01-07 20:53:21 +0000203}
204
205/*
206 * dotest()
207 * Children execute this.
208 *
209 * Randomly read/mod/write chunks with known pattern and check.
210 * When fill sectors, iterate.
211 */
robbiew24e30ab2003-01-07 20:53:21 +0000212#define NMISC 2
Wanlong Gao354ebb42012-12-07 10:10:04 +0800213enum m_type { m_fsync, m_sync };
214char *m_str[] = { "fsync", "sync" };
robbiew24e30ab2003-01-07 20:53:21 +0000215
Wanlong Gao354ebb42012-12-07 10:10:04 +0800216int misc_cnt[NMISC]; /* counts # of each kind of misc */
217int misc_flag;
218int nchunks;
robbiew24e30ab2003-01-07 20:53:21 +0000219
220#define CHUNK(i) (((i) * testers + me) * csize)
221#define NEXTMISC ((rand() % misc_intvl) + 5)
222
subrata_modak04f47a12009-09-18 17:44:08 +0000223static void dotest(int testers, int me, int fd)
robbiew24e30ab2003-01-07 20:53:21 +0000224{
Cyril Hrubis82ddd5f2013-06-04 19:33:07 +0200225 char *bits;
subrata_modak04f47a12009-09-18 17:44:08 +0000226 char val, val0;
227 int count, collide, chunk, whenmisc, xfr, i;
robbiew24e30ab2003-01-07 20:53:21 +0000228
229 /* Stuff for the readv call */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800230 struct iovec r_iovec[MAXIOVCNT];
231 int r_ioveclen;
robbiew24e30ab2003-01-07 20:53:21 +0000232
233 /* Stuff for the writev call */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800234 struct iovec val0_iovec[MAXIOVCNT];
235 struct iovec val_iovec[MAXIOVCNT];
236 int w_ioveclen;
robbiew24e30ab2003-01-07 20:53:21 +0000237
238 nchunks = max_size / (testers * csize);
Garrett Cooperf01306b2010-11-05 11:14:08 -0700239 whenmisc = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000240
Wanlong Gao354ebb42012-12-07 10:10:04 +0800241 if ((bits = malloc((nchunks + 7) / 8)) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100242 tst_brkm(TBROK, NULL, "\tmalloc failed(bits)");
robbiew24e30ab2003-01-07 20:53:21 +0000243 }
subrata_modak04f47a12009-09-18 17:44:08 +0000244
robbiew24e30ab2003-01-07 20:53:21 +0000245 /*Allocate memory for the iovec buffers and init the iovec arrays
246 */
247 r_ioveclen = w_ioveclen = csize / MAXIOVCNT;
248
subrata_modak04f47a12009-09-18 17:44:08 +0000249 /* Please note that the above statement implies that csize
250 * be evenly divisible by MAXIOVCNT.
251 */
robbiew24e30ab2003-01-07 20:53:21 +0000252
253 for (i = 0; i < MAXIOVCNT; i++) {
subrata_modak04f47a12009-09-18 17:44:08 +0000254 if ((r_iovec[i].iov_base = malloc(r_ioveclen)) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100255 tst_brkm(TBROK, NULL, "\tmalloc failed(r_iovec[])");
robbiew24e30ab2003-01-07 20:53:21 +0000256 }
257 r_iovec[i].iov_len = r_ioveclen;
258
259 /* Allocate unused memory areas between all the buffers to
260 * make things more diffult for the OS.
261 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800262 if (malloc((i + 1) * 8) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100263 tst_brkm(TBROK, NULL, "\tmalloc failed");
robbiew24e30ab2003-01-07 20:53:21 +0000264 }
subrata_modak04f47a12009-09-18 17:44:08 +0000265
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800266 if ((val0_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100267 tst_brkm(TBROK, NULL, "\tmalloc failed(val0_iovec[])");
robbiew24e30ab2003-01-07 20:53:21 +0000268 }
subrata_modak04f47a12009-09-18 17:44:08 +0000269
robbiew24e30ab2003-01-07 20:53:21 +0000270 val0_iovec[i].iov_len = w_ioveclen;
Garrett Cooper2c282152010-12-16 00:55:50 -0800271
Wanlong Gao354ebb42012-12-07 10:10:04 +0800272 if (malloc((i + 1) * 8) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100273 tst_brkm(TBROK, NULL, "\tmalloc failed");
robbiew24e30ab2003-01-07 20:53:21 +0000274 }
subrata_modak04f47a12009-09-18 17:44:08 +0000275
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800276 if ((val_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100277 tst_brkm(TBROK, NULL, "\tmalloc failed(iov_base)");
robbiew24e30ab2003-01-07 20:53:21 +0000278 }
subrata_modak04f47a12009-09-18 17:44:08 +0000279
robbiew24e30ab2003-01-07 20:53:21 +0000280 val_iovec[i].iov_len = w_ioveclen;
281
Wanlong Gao354ebb42012-12-07 10:10:04 +0800282 if (malloc((i + 1) * 8) == NULL) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100283 tst_brkm(TBROK, NULL, "\tmalloc failed");
robbiew24e30ab2003-01-07 20:53:21 +0000284 }
285 }
286
287 /*
288 * No init sectors; file-sys makes 0 to start.
289 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800290 val = (64 / testers) * me + 1;
robbiew24e30ab2003-01-07 20:53:21 +0000291 val0 = 0;
292
293 /*
294 * For each iteration:
Wanlong Gao354ebb42012-12-07 10:10:04 +0800295 * zap bits array
296 * loop:
297 * pick random chunk, read it.
298 * if corresponding bit off {
299 * verify == 0. (sparse file)
300 * ++count;
301 * } else
302 * verify == val.
303 * write "val" on it.
304 * repeat until count = nchunks.
305 * ++val.
robbiew24e30ab2003-01-07 20:53:21 +0000306 */
robbiew24e30ab2003-01-07 20:53:21 +0000307 srand(getpid());
subrata_modak04f47a12009-09-18 17:44:08 +0000308
309 if (misc_intvl)
310 whenmisc = NEXTMISC;
311
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800312 while (iterations-- > 0) {
313 for (i = 0; i < NMISC; i++)
robbiew24e30ab2003-01-07 20:53:21 +0000314 misc_cnt[i] = 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800315 memset(bits, 0, (nchunks + 7) / 8);
subrata_modak04f47a12009-09-18 17:44:08 +0000316 /* Have to fill the val0 and val iov buffers in a different manner */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800317 for (i = 0; i < MAXIOVCNT; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800318 memset(val0_iovec[i].iov_base, val0,
319 val0_iovec[i].iov_len);
320 memset(val_iovec[i].iov_base, val,
321 val_iovec[i].iov_len);
robbiew24e30ab2003-01-07 20:53:21 +0000322
323 }
324 count = 0;
325 collide = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000326 while (count < nchunks) {
robbiew24e30ab2003-01-07 20:53:21 +0000327 chunk = rand() % nchunks;
328 /*
329 * Read it.
330 */
subrata_modak04f47a12009-09-18 17:44:08 +0000331 if (lseek(fd, CHUNK(chunk), 0) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100332 tst_brkm(TFAIL,
333 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800334 "\tTest[%d]: lseek(0) fail at %x, errno = %d.",
335 me, CHUNK(chunk), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000336 }
337 if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100338 tst_brkm(TFAIL,
339 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800340 "\tTest[%d]: readv fail at %x, errno = %d.",
341 me, CHUNK(chunk), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000342 }
343 /*
344 * If chunk beyond EOF just write on it.
345 * Else if bit off, haven't seen it yet.
346 * Else, have. Verify values.
347 */
348 if (xfr == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800349 bits[chunk / 8] |= (1 << (chunk % 8));
350 } else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) {
robbiew24e30ab2003-01-07 20:53:21 +0000351 if (xfr != csize) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100352 tst_brkm(TFAIL,
353 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800354 "\tTest[%d]: xfr=%d != %d, zero read.",
355 me, xfr, csize);
robbiew24e30ab2003-01-07 20:53:21 +0000356 }
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800357 for (i = 0; i < MAXIOVCNT; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800358 if (memcmp
359 (r_iovec[i].iov_base,
360 val0_iovec[i].iov_base,
361 r_iovec[i].iov_len)) {
362 tst_resm(TFAIL,
363 "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d.",
364 me, CHUNK(chunk), val0,
365 count, xfr);
subrata_modak04f47a12009-09-18 17:44:08 +0000366 ft_dumpiov(&r_iovec[i]);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800367 ft_dumpbits(bits,
368 (nchunks + 7) / 8);
robbiew24e30ab2003-01-07 20:53:21 +0000369 tst_exit();
370 }
371 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800372 bits[chunk / 8] |= (1 << (chunk % 8));
robbiew24e30ab2003-01-07 20:53:21 +0000373 ++count;
374 } else {
375 if (xfr != csize) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100376 tst_brkm(TFAIL,
377 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800378 "\tTest[%d]: xfr=%d != %d, val read.",
379 me, xfr, csize);
robbiew24e30ab2003-01-07 20:53:21 +0000380 }
381 ++collide;
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800382 for (i = 0; i < MAXIOVCNT; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800383 if (memcmp
384 (r_iovec[i].iov_base,
385 val_iovec[i].iov_base,
386 r_iovec[i].iov_len)) {
387 tst_resm(TFAIL,
388 "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d.",
389 me, CHUNK(chunk), val,
390 count, xfr);
subrata_modak04f47a12009-09-18 17:44:08 +0000391 ft_dumpiov(&r_iovec[i]);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800392 ft_dumpbits(bits,
393 (nchunks + 7) / 8);
robbiew24e30ab2003-01-07 20:53:21 +0000394 tst_exit();
395 }
396 }
397 }
398 /*
399 * Write it.
400 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800401 if (lseek(fd, -xfr, 1) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100402 tst_brkm(TFAIL,
403 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800404 "\tTest[%d]: lseek(1) fail at %x, errno = %d.",
405 me, CHUNK(chunk), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000406 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800407 if ((xfr =
408 writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) {
robbiew24e30ab2003-01-07 20:53:21 +0000409 if (errno == ENOSPC) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800410 tst_resm(TFAIL,
411 "\tTest[%d]: no space, exiting.",
412 me);
robbiew24e30ab2003-01-07 20:53:21 +0000413 fsync(fd);
414 tst_exit();
415 }
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100416 tst_brkm(TFAIL,
417 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800418 "\tTest[%d]: writev fail at %x xfr %d, errno = %d.",
419 me, CHUNK(chunk), xfr, errno);
robbiew24e30ab2003-01-07 20:53:21 +0000420 }
421 /*
422 * If hit "misc" interval, do it.
423 */
424 if (misc_intvl && --whenmisc <= 0) {
subrata_modak04f47a12009-09-18 17:44:08 +0000425 domisc(me, fd);
robbiew24e30ab2003-01-07 20:53:21 +0000426 whenmisc = NEXTMISC;
427 }
428 if (count + collide > 2 * nchunks)
429 break;
430 }
431
432 /*
433 * End of iteration, maybe before doing all chunks.
434 */
435
436 if (count < nchunks) {
vapieraf64a872006-02-15 06:47:36 +0000437 //tst_resm(TINFO, "\tTest{%d} val %d stopping @ %d, collide = {%d}.",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800438 // me, val, count, collide);
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800439 for (i = 0; i < nchunks; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800440 if ((bits[i / 8] & (1 << (i % 8))) == 0) {
subrata_modak04f47a12009-09-18 17:44:08 +0000441 if (lseek(fd, CHUNK(i), 0) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100442 tst_brkm(TFAIL,
443 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800444 "\tTest[%d]: lseek fail at %x, errno = %d.",
445 me, CHUNK(i), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000446 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800447 if (writev(fd, &val_iovec[0], MAXIOVCNT)
448 != csize) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100449 tst_brkm(TFAIL,
450 NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800451 "\tTest[%d]: writev fail at %x, errno = %d.",
452 me, CHUNK(i), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000453 }
454 }
455 }
456 }
457
458 fsync(fd);
subrata_modak04f47a12009-09-18 17:44:08 +0000459 ++misc_cnt[m_fsync];
vapieraf64a872006-02-15 06:47:36 +0000460 //tst_resm(TINFO, "\tTest[%d] val %d done, count = %d, collide = %d.",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800461 // me, val, count, collide);
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800462 //for (i = 0; i < NMISC; i++)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800463 // tst_resm(TINFO, "\t\tTest[%d]: %d %s's.", me, misc_cnt[i], m_str[i]);
robbiew24e30ab2003-01-07 20:53:21 +0000464 val0 = val++;
465 }
robbiew24e30ab2003-01-07 20:53:21 +0000466}
467
468/*
469 * domisc()
470 * Inject misc syscalls into the thing.
471 */
subrata_modak04f47a12009-09-18 17:44:08 +0000472static void domisc(int me, int fd)
robbiew24e30ab2003-01-07 20:53:21 +0000473{
robbiew24e30ab2003-01-07 20:53:21 +0000474 if (fsync(fd) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100475 tst_brkm(TFAIL, NULL, "\tTest[%d]: fsync error %d.", me,
476 errno);
robbiew24e30ab2003-01-07 20:53:21 +0000477 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000478
subrata_modak04f47a12009-09-18 17:44:08 +0000479 ++misc_cnt[1];
robbiew24e30ab2003-01-07 20:53:21 +0000480}
481
subrata_modak04f47a12009-09-18 17:44:08 +0000482static void term(int sig LTP_ATTRIBUTE_UNUSED)
robbiew24e30ab2003-01-07 20:53:21 +0000483{
subrata_modak04f47a12009-09-18 17:44:08 +0000484 int i;
robbiew24e30ab2003-01-07 20:53:21 +0000485
vapieraf64a872006-02-15 06:47:36 +0000486 tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000487
488 if (parent_pid == getpid()) {
subrata_modak04f47a12009-09-18 17:44:08 +0000489 for (i = 0; i < nchild; i++)
490 if (pidlist[i])
robbiew24e30ab2003-01-07 20:53:21 +0000491 kill(pidlist[i], SIGTERM);
robbiew24e30ab2003-01-07 20:53:21 +0000492 }
493
494 exit(0);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700495}