blob: 05d1160b0efb3c0ec83fef1c780f9dc361b0f7f5 [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"
51#include "usctest.h"
subrata_modak04f47a12009-09-18 17:44:08 +000052#include "libftest.h"
robbiew24e30ab2003-01-07 20:53:21 +000053
54char *TCID = "ftest04";
55int TST_TOTAL = 1;
robbiew24e30ab2003-01-07 20:53:21 +000056
subrata_modak04f47a12009-09-18 17:44:08 +000057static void setup(void);
58static void runtest(void);
59static void dotest(int, int, int);
60static void domisc(int, int);
61static void term(int sig);
robbiew24e30ab2003-01-07 20:53:21 +000062
63#define PASSED 1
64#define FAILED 0
65
subrata_modak04f47a12009-09-18 17:44:08 +000066#define MAXCHILD 25
robbiew24e30ab2003-01-07 20:53:21 +000067#define K_1 1024
68#define K_2 2048
69#define K_4 4096
70#define MAXIOVCNT 16
71
Wanlong Gao354ebb42012-12-07 10:10:04 +080072static int csize; /* chunk size */
73static int iterations; /* # total iterations */
74static int max_size; /* max file size */
75static int misc_intvl; /* for doing misc things; 0 ==> no */
76static int nchild; /* number of child processes */
subrata_modak04f47a12009-09-18 17:44:08 +000077static int parent_pid;
78static int pidlist[MAXCHILD];
robbiew24e30ab2003-01-07 20:53:21 +000079
Garrett Cooperfde57722010-08-16 23:37:16 -070080static char filename[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +000081
subrata_modak04f47a12009-09-18 17:44:08 +000082static int local_flag;
robbiew24e30ab2003-01-07 20:53:21 +000083
subrata_modak04f47a12009-09-18 17:44:08 +000084int main(int ac, char *av[])
robbiew24e30ab2003-01-07 20:53:21 +000085{
subrata_modak04f47a12009-09-18 17:44:08 +000086 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020087 const char *msg;
robbiew24e30ab2003-01-07 20:53:21 +000088
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020089 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
90 tst_brkm(TBROK, "OPTION PARSING ERROR - %s", msg);
robbiew24e30ab2003-01-07 20:53:21 +000091
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 setup();
robbiew24e30ab2003-01-07 20:53:21 +000093
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 for (lc = 0; TEST_LOOPING(lc); lc++) {
robbiew24e30ab2003-01-07 20:53:21 +000095
Wanlong Gao354ebb42012-12-07 10:10:04 +080096 runtest();
robbiew24e30ab2003-01-07 20:53:21 +000097
Wanlong Gao354ebb42012-12-07 10:10:04 +080098 if (local_flag == PASSED)
99 tst_resm(TPASS, "Test passed.");
100 else
101 tst_resm(TFAIL, "Test failed.");
subrata_modak04f47a12009-09-18 17:44:08 +0000102
103 /* ??? only one loop ??? */
robbiew24e30ab2003-01-07 20:53:21 +0000104 tst_rmdir();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800105 tst_exit();
subrata_modak04f47a12009-09-18 17:44:08 +0000106 }
107
Garrett Cooper2c282152010-12-16 00:55:50 -0800108 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000109}
110
subrata_modak04f47a12009-09-18 17:44:08 +0000111static void setup(void)
robbiew24e30ab2003-01-07 20:53:21 +0000112{
113 int fd;
114 char wdbuf[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000115
116 parent_pid = getpid();
117
118 /*
119 * Make a filename for the test.
120 */
121 tst_tmpdir();
122 if (!filename[0])
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123 sprintf(filename, "%s/ftest04.%d", getcwd(wdbuf, MAXPATHLEN),
124 getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000125
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126 fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
robbiew24e30ab2003-01-07 20:53:21 +0000127 if (fd < 0) {
vapieraf64a872006-02-15 06:47:36 +0000128 tst_resm(TBROK, "Error %d creating file %s", errno, filename);
robbiew24e30ab2003-01-07 20:53:21 +0000129 tst_exit();
130 }
131 close(fd);
132
robbiew24e30ab2003-01-07 20:53:21 +0000133 /*
134 * Default values for run conditions.
135 */
robbiew24e30ab2003-01-07 20:53:21 +0000136 iterations = 10;
137 nchild = 5;
138 csize = K_2; /* should run with 1, 2, and 4 K sizes */
139 max_size = K_1 * K_1;
140 misc_intvl = 10;
141
subrata_modak04f47a12009-09-18 17:44:08 +0000142 if (sigset(SIGTERM, term) == SIG_ERR) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800143 tst_resm(TFAIL, "first sigset failed");
robbiew24e30ab2003-01-07 20:53:21 +0000144 tst_exit();
145 }
146
147 local_flag = PASSED;
148}
149
subrata_modak04f47a12009-09-18 17:44:08 +0000150static void runtest(void)
robbiew24e30ab2003-01-07 20:53:21 +0000151{
Garrett Cooper7a73eab2010-11-09 22:45:42 -0800152 int count, child, fd, i, nwait, status;
153
154 nwait = 0;
robbiew24e30ab2003-01-07 20:53:21 +0000155
subrata_modak04f47a12009-09-18 17:44:08 +0000156 for (i = 0; i < nchild; i++) {
157 if ((child = fork()) == 0) {
robbiew24e30ab2003-01-07 20:53:21 +0000158 fd = open(filename, O_RDWR);
159 if (fd < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800160 tst_resm(TBROK,
161 "\tTest[%d]: error %d openning %s.", i,
162 errno, filename);
robbiew24e30ab2003-01-07 20:53:21 +0000163 tst_exit();
164 }
subrata_modak04f47a12009-09-18 17:44:08 +0000165 dotest(nchild, i, fd);
subrata_modak2f5be082008-08-27 11:28:24 +0000166 close(fd);
subrata_modak04f47a12009-09-18 17:44:08 +0000167 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000168 }
robbiew24e30ab2003-01-07 20:53:21 +0000169 if (child < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800170 tst_brkm(TBROK | TERRNO, NULL, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000171 } else {
172 pidlist[i] = child;
173 nwait++;
174 }
175 }
176
177 /*
178 * Wait for children to finish.
179 */
robbiew24e30ab2003-01-07 20:53:21 +0000180 count = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000181 while ((child = wait(&status)) != -1 || errno == EINTR) {
182 if (child > 0) {
vapieraf64a872006-02-15 06:47:36 +0000183 //tst_resm(TINFO, "\tTest{%d} exited status = 0x%x", child, status);
robbiew24e30ab2003-01-07 20:53:21 +0000184 if (status) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800185 tst_resm(TFAIL,
186 "\tExpected 0 exit status - failed.");
robbiew24e30ab2003-01-07 20:53:21 +0000187 local_flag = FAILED;
188 }
189 ++count;
190 }
191 }
192
193 /*
194 * Should have collected all children.
195 */
robbiew24e30ab2003-01-07 20:53:21 +0000196 if (count != nwait) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800197 tst_resm(TFAIL, "\tWrong # children waited on, count = %d",
198 count);
robbiew24e30ab2003-01-07 20:53:21 +0000199 local_flag = FAILED;
200 }
201
202 unlink(filename);
subrata_modak04f47a12009-09-18 17:44:08 +0000203 sync();
robbiew24e30ab2003-01-07 20:53:21 +0000204}
205
206/*
207 * dotest()
208 * Children execute this.
209 *
210 * Randomly read/mod/write chunks with known pattern and check.
211 * When fill sectors, iterate.
212 */
robbiew24e30ab2003-01-07 20:53:21 +0000213#define NMISC 2
Wanlong Gao354ebb42012-12-07 10:10:04 +0800214enum m_type { m_fsync, m_sync };
215char *m_str[] = { "fsync", "sync" };
robbiew24e30ab2003-01-07 20:53:21 +0000216
Wanlong Gao354ebb42012-12-07 10:10:04 +0800217int misc_cnt[NMISC]; /* counts # of each kind of misc */
218int misc_flag;
219int nchunks;
robbiew24e30ab2003-01-07 20:53:21 +0000220
221#define CHUNK(i) (((i) * testers + me) * csize)
222#define NEXTMISC ((rand() % misc_intvl) + 5)
223
subrata_modak04f47a12009-09-18 17:44:08 +0000224static void dotest(int testers, int me, int fd)
robbiew24e30ab2003-01-07 20:53:21 +0000225{
Cyril Hrubis82ddd5f2013-06-04 19:33:07 +0200226 char *bits;
subrata_modak04f47a12009-09-18 17:44:08 +0000227 char val, val0;
228 int count, collide, chunk, whenmisc, xfr, i;
robbiew24e30ab2003-01-07 20:53:21 +0000229
230 /* Stuff for the readv call */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800231 struct iovec r_iovec[MAXIOVCNT];
232 int r_ioveclen;
robbiew24e30ab2003-01-07 20:53:21 +0000233
234 /* Stuff for the writev call */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800235 struct iovec val0_iovec[MAXIOVCNT];
236 struct iovec val_iovec[MAXIOVCNT];
237 int w_ioveclen;
robbiew24e30ab2003-01-07 20:53:21 +0000238
239 nchunks = max_size / (testers * csize);
Garrett Cooperf01306b2010-11-05 11:14:08 -0700240 whenmisc = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000241
Wanlong Gao354ebb42012-12-07 10:10:04 +0800242 if ((bits = malloc((nchunks + 7) / 8)) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000243 tst_resm(TBROK, "\tmalloc failed(bits)");
robbiew24e30ab2003-01-07 20:53:21 +0000244 tst_exit();
245 }
subrata_modak04f47a12009-09-18 17:44:08 +0000246
robbiew24e30ab2003-01-07 20:53:21 +0000247 /*Allocate memory for the iovec buffers and init the iovec arrays
248 */
249 r_ioveclen = w_ioveclen = csize / MAXIOVCNT;
250
subrata_modak04f47a12009-09-18 17:44:08 +0000251 /* Please note that the above statement implies that csize
252 * be evenly divisible by MAXIOVCNT.
253 */
robbiew24e30ab2003-01-07 20:53:21 +0000254
255 for (i = 0; i < MAXIOVCNT; i++) {
subrata_modak04f47a12009-09-18 17:44:08 +0000256 if ((r_iovec[i].iov_base = malloc(r_ioveclen)) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000257 tst_resm(TBROK, "\tmalloc failed(r_iovec[])");
robbiew24e30ab2003-01-07 20:53:21 +0000258 tst_exit();
259 }
260 r_iovec[i].iov_len = r_ioveclen;
261
262 /* Allocate unused memory areas between all the buffers to
263 * make things more diffult for the OS.
264 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800265 if (malloc((i + 1) * 8) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000266 tst_resm(TBROK, "\tmalloc failed");
robbiew24e30ab2003-01-07 20:53:21 +0000267 tst_exit();
268 }
subrata_modak04f47a12009-09-18 17:44:08 +0000269
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800270 if ((val0_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000271 tst_resm(TBROK, "\tmalloc failed(val0_iovec[])");
robbiew24e30ab2003-01-07 20:53:21 +0000272 tst_exit();
273 }
subrata_modak04f47a12009-09-18 17:44:08 +0000274
robbiew24e30ab2003-01-07 20:53:21 +0000275 val0_iovec[i].iov_len = w_ioveclen;
Garrett Cooper2c282152010-12-16 00:55:50 -0800276
Wanlong Gao354ebb42012-12-07 10:10:04 +0800277 if (malloc((i + 1) * 8) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000278 tst_resm(TBROK, "\tmalloc failed");
robbiew24e30ab2003-01-07 20:53:21 +0000279 tst_exit();
280 }
subrata_modak04f47a12009-09-18 17:44:08 +0000281
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800282 if ((val_iovec[i].iov_base = malloc(w_ioveclen)) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000283 tst_resm(TBROK, "\tmalloc failed(iov_base)");
robbiew24e30ab2003-01-07 20:53:21 +0000284 tst_exit();
285 }
subrata_modak04f47a12009-09-18 17:44:08 +0000286
robbiew24e30ab2003-01-07 20:53:21 +0000287 val_iovec[i].iov_len = w_ioveclen;
288
Wanlong Gao354ebb42012-12-07 10:10:04 +0800289 if (malloc((i + 1) * 8) == NULL) {
vapieraf64a872006-02-15 06:47:36 +0000290 tst_resm(TBROK, "\tmalloc failed");
robbiew24e30ab2003-01-07 20:53:21 +0000291 tst_exit();
292 }
293 }
294
295 /*
296 * No init sectors; file-sys makes 0 to start.
297 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800298 val = (64 / testers) * me + 1;
robbiew24e30ab2003-01-07 20:53:21 +0000299 val0 = 0;
300
301 /*
302 * For each iteration:
Wanlong Gao354ebb42012-12-07 10:10:04 +0800303 * zap bits array
304 * loop:
305 * pick random chunk, read it.
306 * if corresponding bit off {
307 * verify == 0. (sparse file)
308 * ++count;
309 * } else
310 * verify == val.
311 * write "val" on it.
312 * repeat until count = nchunks.
313 * ++val.
robbiew24e30ab2003-01-07 20:53:21 +0000314 */
robbiew24e30ab2003-01-07 20:53:21 +0000315 srand(getpid());
subrata_modak04f47a12009-09-18 17:44:08 +0000316
317 if (misc_intvl)
318 whenmisc = NEXTMISC;
319
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800320 while (iterations-- > 0) {
321 for (i = 0; i < NMISC; i++)
robbiew24e30ab2003-01-07 20:53:21 +0000322 misc_cnt[i] = 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800323 memset(bits, 0, (nchunks + 7) / 8);
subrata_modak04f47a12009-09-18 17:44:08 +0000324 /* Have to fill the val0 and val iov buffers in a different manner */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800325 for (i = 0; i < MAXIOVCNT; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800326 memset(val0_iovec[i].iov_base, val0,
327 val0_iovec[i].iov_len);
328 memset(val_iovec[i].iov_base, val,
329 val_iovec[i].iov_len);
robbiew24e30ab2003-01-07 20:53:21 +0000330
331 }
332 count = 0;
333 collide = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000334 while (count < nchunks) {
robbiew24e30ab2003-01-07 20:53:21 +0000335 chunk = rand() % nchunks;
336 /*
337 * Read it.
338 */
subrata_modak04f47a12009-09-18 17:44:08 +0000339 if (lseek(fd, CHUNK(chunk), 0) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800340 tst_resm(TFAIL,
341 "\tTest[%d]: lseek(0) fail at %x, errno = %d.",
342 me, CHUNK(chunk), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000343 tst_exit();
344 }
345 if ((xfr = readv(fd, &r_iovec[0], MAXIOVCNT)) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800346 tst_resm(TFAIL,
347 "\tTest[%d]: readv fail at %x, errno = %d.",
348 me, CHUNK(chunk), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000349 tst_exit();
350 }
351 /*
352 * If chunk beyond EOF just write on it.
353 * Else if bit off, haven't seen it yet.
354 * Else, have. Verify values.
355 */
356 if (xfr == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800357 bits[chunk / 8] |= (1 << (chunk % 8));
358 } else if ((bits[chunk / 8] & (1 << (chunk % 8))) == 0) {
robbiew24e30ab2003-01-07 20:53:21 +0000359 if (xfr != csize) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800360 tst_resm(TFAIL,
361 "\tTest[%d]: xfr=%d != %d, zero read.",
362 me, xfr, csize);
robbiew24e30ab2003-01-07 20:53:21 +0000363 tst_exit();
364 }
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800365 for (i = 0; i < MAXIOVCNT; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800366 if (memcmp
367 (r_iovec[i].iov_base,
368 val0_iovec[i].iov_base,
369 r_iovec[i].iov_len)) {
370 tst_resm(TFAIL,
371 "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d.",
372 me, CHUNK(chunk), val0,
373 count, xfr);
subrata_modak04f47a12009-09-18 17:44:08 +0000374 ft_dumpiov(&r_iovec[i]);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800375 ft_dumpbits(bits,
376 (nchunks + 7) / 8);
robbiew24e30ab2003-01-07 20:53:21 +0000377 tst_exit();
378 }
379 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800380 bits[chunk / 8] |= (1 << (chunk % 8));
robbiew24e30ab2003-01-07 20:53:21 +0000381 ++count;
382 } else {
383 if (xfr != csize) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800384 tst_resm(TFAIL,
385 "\tTest[%d]: xfr=%d != %d, val read.",
386 me, xfr, csize);
robbiew24e30ab2003-01-07 20:53:21 +0000387 tst_exit();
388 }
389 ++collide;
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800390 for (i = 0; i < MAXIOVCNT; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800391 if (memcmp
392 (r_iovec[i].iov_base,
393 val_iovec[i].iov_base,
394 r_iovec[i].iov_len)) {
395 tst_resm(TFAIL,
396 "\tTest[%d] bad verify @ 0x%x for val %d count %d xfr %d.",
397 me, CHUNK(chunk), val,
398 count, xfr);
subrata_modak04f47a12009-09-18 17:44:08 +0000399 ft_dumpiov(&r_iovec[i]);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800400 ft_dumpbits(bits,
401 (nchunks + 7) / 8);
robbiew24e30ab2003-01-07 20:53:21 +0000402 tst_exit();
403 }
404 }
405 }
406 /*
407 * Write it.
408 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800409 if (lseek(fd, -xfr, 1) < 0) {
410 tst_resm(TFAIL,
411 "\tTest[%d]: lseek(1) fail at %x, errno = %d.",
412 me, CHUNK(chunk), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000413 tst_exit();
414 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800415 if ((xfr =
416 writev(fd, &val_iovec[0], MAXIOVCNT)) < csize) {
robbiew24e30ab2003-01-07 20:53:21 +0000417 if (errno == ENOSPC) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800418 tst_resm(TFAIL,
419 "\tTest[%d]: no space, exiting.",
420 me);
robbiew24e30ab2003-01-07 20:53:21 +0000421 fsync(fd);
422 tst_exit();
423 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800424 tst_resm(TFAIL,
425 "\tTest[%d]: writev fail at %x xfr %d, errno = %d.",
426 me, CHUNK(chunk), xfr, errno);
robbiew24e30ab2003-01-07 20:53:21 +0000427 tst_exit();
428 }
429 /*
430 * If hit "misc" interval, do it.
431 */
432 if (misc_intvl && --whenmisc <= 0) {
subrata_modak04f47a12009-09-18 17:44:08 +0000433 domisc(me, fd);
robbiew24e30ab2003-01-07 20:53:21 +0000434 whenmisc = NEXTMISC;
435 }
436 if (count + collide > 2 * nchunks)
437 break;
438 }
439
440 /*
441 * End of iteration, maybe before doing all chunks.
442 */
443
444 if (count < nchunks) {
vapieraf64a872006-02-15 06:47:36 +0000445 //tst_resm(TINFO, "\tTest{%d} val %d stopping @ %d, collide = {%d}.",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800446 // me, val, count, collide);
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800447 for (i = 0; i < nchunks; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800448 if ((bits[i / 8] & (1 << (i % 8))) == 0) {
subrata_modak04f47a12009-09-18 17:44:08 +0000449 if (lseek(fd, CHUNK(i), 0) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800450 tst_resm(TFAIL,
451 "\tTest[%d]: lseek fail at %x, errno = %d.",
452 me, CHUNK(i), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000453 tst_exit();
454 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800455 if (writev(fd, &val_iovec[0], MAXIOVCNT)
456 != csize) {
457 tst_resm(TFAIL,
458 "\tTest[%d]: writev fail at %x, errno = %d.",
459 me, CHUNK(i), errno);
robbiew24e30ab2003-01-07 20:53:21 +0000460 tst_exit();
461 }
462 }
463 }
464 }
465
466 fsync(fd);
subrata_modak04f47a12009-09-18 17:44:08 +0000467 ++misc_cnt[m_fsync];
vapieraf64a872006-02-15 06:47:36 +0000468 //tst_resm(TINFO, "\tTest[%d] val %d done, count = %d, collide = %d.",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800469 // me, val, count, collide);
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800470 //for (i = 0; i < NMISC; i++)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800471 // tst_resm(TINFO, "\t\tTest[%d]: %d %s's.", me, misc_cnt[i], m_str[i]);
robbiew24e30ab2003-01-07 20:53:21 +0000472 val0 = val++;
473 }
robbiew24e30ab2003-01-07 20:53:21 +0000474}
475
476/*
477 * domisc()
478 * Inject misc syscalls into the thing.
479 */
subrata_modak04f47a12009-09-18 17:44:08 +0000480static void domisc(int me, int fd)
robbiew24e30ab2003-01-07 20:53:21 +0000481{
robbiew24e30ab2003-01-07 20:53:21 +0000482 if (fsync(fd) < 0) {
vapieraf64a872006-02-15 06:47:36 +0000483 tst_resm(TFAIL, "\tTest[%d]: fsync error %d.", me, errno);
robbiew24e30ab2003-01-07 20:53:21 +0000484 tst_exit();
485 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000486
subrata_modak04f47a12009-09-18 17:44:08 +0000487 ++misc_cnt[1];
robbiew24e30ab2003-01-07 20:53:21 +0000488}
489
subrata_modak04f47a12009-09-18 17:44:08 +0000490static void term(int sig LTP_ATTRIBUTE_UNUSED)
robbiew24e30ab2003-01-07 20:53:21 +0000491{
subrata_modak04f47a12009-09-18 17:44:08 +0000492 int i;
robbiew24e30ab2003-01-07 20:53:21 +0000493
vapieraf64a872006-02-15 06:47:36 +0000494 tst_resm(TINFO, "\tterm -[%d]- got sig term.", getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000495
496 if (parent_pid == getpid()) {
subrata_modak04f47a12009-09-18 17:44:08 +0000497 for (i = 0; i < nchild; i++)
498 if (pidlist[i])
robbiew24e30ab2003-01-07 20:53:21 +0000499 kill(pidlist[i], SIGTERM);
robbiew24e30ab2003-01-07 20:53:21 +0000500 }
501
502 exit(0);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700503}