blob: ec70d9b7bb95ad5f1a77e3c3d71c2a4ac1f73ec0 [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
robbiew24e30ab2003-01-07 20:53:21 +000021/*
22 * NAME
23 * ftest02.c -- test inode things (ported from SPIE section2, filesuite, by Airong Zhang)
24 *
25 * CALLS
26 * open, close, read, write, lseek,
27 * unlink, chdir
subrata_modakbdbaec52009-02-26 12:14:51 +000028 *
robbiew24e30ab2003-01-07 20:53:21 +000029 *
30 * ALGORITHM
31 *
32 *
33 * ftest02 [-f tmpdirname] nchild iterations [partition]
34 *
35 * This forks some child processes, they do some random operations
36 * which use lots of directory operations.
37 *
38 * RESTRICTIONS
39 * Runs a long time with default args - can take others on input
40 * line. Use with "term mode".
41 * If run on vax the ftruncate will not be random - will always go to
42 * start of file. NOTE: produces a very high load average!!
43 *
44 */
45
subrata_modakf17ac842009-09-07 09:06:31 +000046#include <stdio.h>
robbiew24e30ab2003-01-07 20:53:21 +000047#include <sys/types.h>
48#include <sys/param.h>
49#include <sys/wait.h>
50#include <fcntl.h>
51#include <sys/stat.h>
vapierf81795e2006-02-15 06:28:58 +000052#include <errno.h>
robbiew24e30ab2003-01-07 20:53:21 +000053#include <sys/mount.h>
subrata_modakf17ac842009-09-07 09:06:31 +000054#include <signal.h>
robbiew24e30ab2003-01-07 20:53:21 +000055#include <unistd.h>
subrata_modak04f47a12009-09-18 17:44:08 +000056#include "test.h"
subrata_modak04f47a12009-09-18 17:44:08 +000057#include "libftest.h"
robbiew24e30ab2003-01-07 20:53:21 +000058
subrata_modakf17ac842009-09-07 09:06:31 +000059#define MAXCHILD 25
robbiew24e30ab2003-01-07 20:53:21 +000060#define K_1 1024
61#define K_2 2048
62#define K_4 4096
63
robbiew24e30ab2003-01-07 20:53:21 +000064char *TCID = "ftest02";
65int TST_TOTAL = 1;
robbiew24e30ab2003-01-07 20:53:21 +000066
67#define PASSED 1
68#define FAILED 0
69
subrata_modakf17ac842009-09-07 09:06:31 +000070static void crfile(int, int);
71static void unlfile(int, int);
72static void fussdir(int, int);
73static void dotest(int, int);
Wanlong Gao354ebb42012-12-07 10:10:04 +080074static void dowarn(int, char *, char *);
subrata_modakf17ac842009-09-07 09:06:31 +000075static void term(int sig);
76static void cleanup(void);
robbiew24e30ab2003-01-07 20:53:21 +000077
78#define M (1024*1024)
robbiew24e30ab2003-01-07 20:53:21 +000079
subrata_modak04f47a12009-09-18 17:44:08 +000080static int iterations;
81static int nchild;
82static int parent_pid;
83static int pidlist[MAXCHILD];
robbiew24e30ab2003-01-07 20:53:21 +000084
subrata_modak04f47a12009-09-18 17:44:08 +000085static char homedir[MAXPATHLEN];
86static char dirname[MAXPATHLEN];
87static char tmpname[MAXPATHLEN];
88static int dirlen;
89static int mnt = 0;
90static char startdir[MAXPATHLEN], mntpoint[MAXPATHLEN];
91static char *partition;
92static char *cwd;
93static char *fstyp;
94static int local_flag;
robbiew24e30ab2003-01-07 20:53:21 +000095
subrata_modak04f47a12009-09-18 17:44:08 +000096int main(void)
robbiew24e30ab2003-01-07 20:53:21 +000097{
subrata_modakf17ac842009-09-07 09:06:31 +000098 int k, j, pid, child, status, count;
99 char name[128];
robbiew24e30ab2003-01-07 20:53:21 +0000100
101 /*
102 * Default values for run conditions.
103 */
robbiew24e30ab2003-01-07 20:53:21 +0000104 iterations = 50;
105 nchild = 5;
106
subrata_modakf17ac842009-09-07 09:06:31 +0000107 if (signal(SIGTERM, term) == SIG_ERR) {
robbiew24e30ab2003-01-07 20:53:21 +0000108 tst_resm(TFAIL, "first signal failed");
Garrett Cooper2c282152010-12-16 00:55:50 -0800109
robbiew24e30ab2003-01-07 20:53:21 +0000110 }
111
112 /*
113 * Make a directory to do this in; ignore error if already exists.
114 */
robbiew24e30ab2003-01-07 20:53:21 +0000115 local_flag = PASSED;
116 parent_pid = getpid();
117 tst_tmpdir();
118
119 if (!startdir[0]) {
120 if (getcwd(startdir, MAXPATHLEN) == NULL) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 tst_resm(TBROK, "getcwd failed");
Garrett Cooper2c282152010-12-16 00:55:50 -0800122
robbiew24e30ab2003-01-07 20:53:21 +0000123 }
124 }
125 cwd = startdir;
126 strcat(dirname, cwd);
127 sprintf(tmpname, "/ftest02.%d", getpid());
128 strcat(dirname, tmpname);
129 strcat(homedir, cwd);
130 sprintf(tmpname, "/ftest02h.%d", getpid());
131 strcat(homedir, tmpname);
132
133 mkdir(dirname, 0755);
134 mkdir(homedir, 0755);
135 if (chdir(dirname) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800136 tst_resm(TBROK, "\tCan't chdir(%s), error %d.", dirname, errno);
robbiew24e30ab2003-01-07 20:53:21 +0000137 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800138
robbiew24e30ab2003-01-07 20:53:21 +0000139 }
140 dirlen = strlen(dirname);
141 if (chdir(homedir) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800142 tst_resm(TBROK, "\tCan't chdir(%s), error %d.", homedir, errno);
robbiew24e30ab2003-01-07 20:53:21 +0000143 cleanup();
robbiew24e30ab2003-01-07 20:53:21 +0000144
Garrett Cooper2c282152010-12-16 00:55:50 -0800145 }
robbiew24e30ab2003-01-07 20:53:21 +0000146
subrata_modak04f47a12009-09-18 17:44:08 +0000147 for (k = 0; k < nchild; k++) {
subrata_modakf17ac842009-09-07 09:06:31 +0000148 if ((child = fork()) == 0) {
149 dotest(k, iterations);
robbiew24e30ab2003-01-07 20:53:21 +0000150 exit(0);
151 }
152 if (child < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800153 tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000154 }
155 pidlist[k] = child;
subrata_modakf17ac842009-09-07 09:06:31 +0000156 }
robbiew24e30ab2003-01-07 20:53:21 +0000157
subrata_modakf17ac842009-09-07 09:06:31 +0000158 /*
159 * Wait for children to finish.
robbiew24e30ab2003-01-07 20:53:21 +0000160 */
robbiew24e30ab2003-01-07 20:53:21 +0000161 count = 0;
subrata_modak04f47a12009-09-18 17:44:08 +0000162 while ((child = wait(&status)) > 0) {
vapieraf64a872006-02-15 06:47:36 +0000163 //tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status);
164 //tst_resm(TINFO,"status is %d",status);
robbiew24e30ab2003-01-07 20:53:21 +0000165 if (status) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 tst_resm(TFAIL, "Test{%d} failed, expected 0 exit.",
167 child);
robbiew24e30ab2003-01-07 20:53:21 +0000168 local_flag = FAILED;
169 }
170 ++count;
171 }
172
173 /*
174 * Should have collected all children.
175 */
robbiew24e30ab2003-01-07 20:53:21 +0000176 if (count != nchild) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800177 tst_resm(TFAIL, "Wrong # children waited on, count = %d",
178 count);
robbiew24e30ab2003-01-07 20:53:21 +0000179 local_flag = FAILED;
180 }
181
subrata_modakf17ac842009-09-07 09:06:31 +0000182 if (local_flag == FAILED)
vapieraf64a872006-02-15 06:47:36 +0000183 tst_resm(TFAIL, "Test failed in fork-wait part.");
subrata_modakf17ac842009-09-07 09:06:31 +0000184 else
vapieraf64a872006-02-15 06:47:36 +0000185 tst_resm(TPASS, "Test passed in fork-wait part.");
robbiew24e30ab2003-01-07 20:53:21 +0000186
187 if (iterations > 26)
188 iterations = 26;
subrata_modakf17ac842009-09-07 09:06:31 +0000189
190 for (k = 0; k < nchild; k++)
191 for (j = 0; j < iterations + 1; j++) {
subrata_modak04f47a12009-09-18 17:44:08 +0000192 ft_mkname(name, dirname, k, j);
robbiew24e30ab2003-01-07 20:53:21 +0000193 rmdir(name);
194 unlink(name);
195 }
196
197 chdir(startdir);
198
199 pid = fork();
subrata_modakf17ac842009-09-07 09:06:31 +0000200
robbiew24e30ab2003-01-07 20:53:21 +0000201 if (pid < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800202 tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000203 }
subrata_modakf17ac842009-09-07 09:06:31 +0000204
robbiew24e30ab2003-01-07 20:53:21 +0000205 if (pid == 0) {
robbiew7fdd5142005-02-07 19:39:54 +0000206 execl("/bin/rm", "rm", "-rf", homedir, NULL);
robbiew24e30ab2003-01-07 20:53:21 +0000207 exit(1);
208 } else
209 wait(&status);
subrata_modakf17ac842009-09-07 09:06:31 +0000210
robbiew24e30ab2003-01-07 20:53:21 +0000211 if (status)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800212 tst_resm(TINFO,
213 "CAUTION - ftest02, '%s' may not have been removed.",
214 homedir);
robbiew24e30ab2003-01-07 20:53:21 +0000215
216 pid = fork();
subrata_modakf17ac842009-09-07 09:06:31 +0000217
robbiew24e30ab2003-01-07 20:53:21 +0000218 if (pid < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800219 tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
robbiew24e30ab2003-01-07 20:53:21 +0000220 }
subrata_modakf17ac842009-09-07 09:06:31 +0000221
robbiew24e30ab2003-01-07 20:53:21 +0000222 if (pid == 0) {
robbiew7fdd5142005-02-07 19:39:54 +0000223 execl("/bin/rm", "rm", "-rf", dirname, NULL);
robbiew24e30ab2003-01-07 20:53:21 +0000224 exit(1);
225 } else
226 wait(&status);
subrata_modakf17ac842009-09-07 09:06:31 +0000227
robbiew24e30ab2003-01-07 20:53:21 +0000228 if (status) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800229 tst_resm(TINFO,
230 "CAUTION - ftest02, '%s' may not have been removed.",
231 dirname);
robbiew24e30ab2003-01-07 20:53:21 +0000232 }
233
subrata_modakf17ac842009-09-07 09:06:31 +0000234 sync();
robbiew24e30ab2003-01-07 20:53:21 +0000235
236 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800237
Garrett Cooper7d716be2010-12-19 07:44:35 -0800238 tst_exit();
robbiew24e30ab2003-01-07 20:53:21 +0000239}
240
subrata_modakf17ac842009-09-07 09:06:31 +0000241#define warn(val,m1,m2) if ((val) < 0) dowarn(me,m1,m2)
robbiew24e30ab2003-01-07 20:53:21 +0000242
243/*
244 * crfile()
245 * Create a file and write something into it.
246 */
247
Wanlong Gao354ebb42012-12-07 10:10:04 +0800248char crmsg[] = "Gee, let's write something in the file!\n";
robbiew24e30ab2003-01-07 20:53:21 +0000249
subrata_modakf17ac842009-09-07 09:06:31 +0000250static void crfile(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000251{
subrata_modak04f47a12009-09-18 17:44:08 +0000252 int fd, val;
Garrett Cooperfde57722010-08-16 23:37:16 -0700253 char fname[MAXPATHLEN], buf[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000254
subrata_modak04f47a12009-09-18 17:44:08 +0000255 ft_mkname(fname, dirname, me, count);
robbiew24e30ab2003-01-07 20:53:21 +0000256
Wanlong Gao354ebb42012-12-07 10:10:04 +0800257 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
robbiew24e30ab2003-01-07 20:53:21 +0000258 if (fd < 0 && errno == EISDIR) {
259 val = rmdir(fname);
subrata_modakf17ac842009-09-07 09:06:31 +0000260 warn(val, "rmdir", fname);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800261 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
robbiew24e30ab2003-01-07 20:53:21 +0000262 }
263 warn(fd, "creating", fname);
264
265 val = lseek(fd, (rand() % M), 0);
266 warn(val, "lseek", 0);
267
Wanlong Gao354ebb42012-12-07 10:10:04 +0800268 val = write(fd, crmsg, sizeof(crmsg) - 1);
robbiew24e30ab2003-01-07 20:53:21 +0000269 warn(val, "write", 0);
270
Wanlong Gao354ebb42012-12-07 10:10:04 +0800271 val = lseek(fd, -(sizeof(crmsg) - 1), 1);
robbiew24e30ab2003-01-07 20:53:21 +0000272 warn(val, "lseek", 0);
273
Wanlong Gao354ebb42012-12-07 10:10:04 +0800274 val = read(fd, buf, sizeof(crmsg) - 1);
robbiew24e30ab2003-01-07 20:53:21 +0000275 warn(val, "read", 0);
276
Wanlong Gao354ebb42012-12-07 10:10:04 +0800277 if (strncmp(crmsg, buf, sizeof(crmsg) - 1))
subrata_modakf17ac842009-09-07 09:06:31 +0000278 dowarn(me, "compare", 0);
robbiew24e30ab2003-01-07 20:53:21 +0000279
280 val = close(fd);
281 warn(val, "close", 0);
282}
283
284/*
285 * unlfile()
286 * Unlink some of the files.
287 */
subrata_modakf17ac842009-09-07 09:06:31 +0000288static void unlfile(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000289{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800290 int i;
291 int val;
292 char fname[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000293
294 i = count - 10;
subrata_modakf17ac842009-09-07 09:06:31 +0000295
robbiew24e30ab2003-01-07 20:53:21 +0000296 if (i < 0)
297 i = 0;
subrata_modakf17ac842009-09-07 09:06:31 +0000298
subrata_modak04f47a12009-09-18 17:44:08 +0000299 for (; i < count; i++) {
300 ft_mkname(fname, dirname, me, i);
robbiew24e30ab2003-01-07 20:53:21 +0000301 val = rmdir(fname);
Garrett Cooper8fb1cdb2010-11-28 22:56:35 -0800302 if (val < 0)
robbiew24e30ab2003-01-07 20:53:21 +0000303 val = unlink(fname);
304 if (val == 0 || errno == ENOENT)
305 continue;
subrata_modakf17ac842009-09-07 09:06:31 +0000306 dowarn(me, "unlink", fname);
robbiew24e30ab2003-01-07 20:53:21 +0000307 }
308}
309
310/*
311 * fussdir()
312 * Make a directory, put stuff in it, remove it, and remove directory.
313 *
314 * Randomly leave the directory there.
315 */
subrata_modakf17ac842009-09-07 09:06:31 +0000316static void fussdir(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000317{
subrata_modak04f47a12009-09-18 17:44:08 +0000318 int val;
Garrett Cooperfde57722010-08-16 23:37:16 -0700319 char dir[MAXPATHLEN], fname[MAXPATHLEN], savedir[MAXPATHLEN];
robbiew24e30ab2003-01-07 20:53:21 +0000320
subrata_modak04f47a12009-09-18 17:44:08 +0000321 ft_mkname(dir, dirname, me, count);
322 rmdir(dir);
323 unlink(dir);
robbiew24e30ab2003-01-07 20:53:21 +0000324
325 val = mkdir(dir, 0755);
326 warn(val, "mkdir", dir);
327
328 /*
329 * Arrange to create files in the directory.
330 */
robbiew24e30ab2003-01-07 20:53:21 +0000331 strcpy(savedir, dirname);
332 strcpy(dirname, "");
333
334 val = chdir(dir);
335 warn(val, "chdir", dir);
336
337 crfile(me, count);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800338 crfile(me, count + 1);
robbiew24e30ab2003-01-07 20:53:21 +0000339
340 val = chdir("..");
341 warn(val, "chdir", "..");
342
343 val = rmdir(dir);
subrata_modak04f47a12009-09-18 17:44:08 +0000344
robbiew24e30ab2003-01-07 20:53:21 +0000345 if (val >= 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100346 tst_brkm(TFAIL, NULL,
347 "Test[%d]: rmdir of non-empty %s succeeds!", me,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800348 dir);
robbiew24e30ab2003-01-07 20:53:21 +0000349 }
350
351 val = chdir(dir);
352 warn(val, "chdir", dir);
353
subrata_modak04f47a12009-09-18 17:44:08 +0000354 ft_mkname(fname, dirname, me, count);
robbiew24e30ab2003-01-07 20:53:21 +0000355 val = unlink(fname);
356 warn(val, "unlink", fname);
357
Wanlong Gao354ebb42012-12-07 10:10:04 +0800358 ft_mkname(fname, dirname, me, count + 1);
robbiew24e30ab2003-01-07 20:53:21 +0000359 val = unlink(fname);
360 warn(val, "unlink", fname);
361
362 val = chdir(homedir);
363 warn(val, "chdir", homedir);
364
365 if (rand() & 0x01) {
366 val = rmdir(dir);
367 warn(val, "rmdir", dir);
368 }
369
370 strcpy(dirname, savedir);
371}
372
robbiew24e30ab2003-01-07 20:53:21 +0000373/*
374 * dotest()
375 * Children execute this.
376 *
377 * Randomly do an inode thing; loop for # iterations.
378 */
robbiew24e30ab2003-01-07 20:53:21 +0000379#define THING(p) {p, "p"}
380
Wanlong Gao354ebb42012-12-07 10:10:04 +0800381struct ino_thing {
382 void (*it_proc) ();
383 char *it_name;
384} ino_thing[] = {
385THING(crfile), THING(unlfile), THING(fussdir), THING(sync),};
robbiew24e30ab2003-01-07 20:53:21 +0000386
387#define NTHING (sizeof(ino_thing) / sizeof(ino_thing[0]))
388
Wanlong Gao354ebb42012-12-07 10:10:04 +0800389int thing_cnt[NTHING];
390int thing_last[NTHING];
robbiew24e30ab2003-01-07 20:53:21 +0000391
subrata_modakf17ac842009-09-07 09:06:31 +0000392static void dotest(int me, int count)
robbiew24e30ab2003-01-07 20:53:21 +0000393{
subrata_modakf17ac842009-09-07 09:06:31 +0000394 int i, thing;
robbiew24e30ab2003-01-07 20:53:21 +0000395
vapieraf64a872006-02-15 06:47:36 +0000396 //tst_resm(TINFO,"Test %d pid %d starting.", me, getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000397
398 srand(getpid());
subrata_modak04f47a12009-09-18 17:44:08 +0000399
400 for (i = 0; i < count; i++) {
robbiew24e30ab2003-01-07 20:53:21 +0000401 thing = (rand() >> 3) % NTHING;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800402 (*ino_thing[thing].it_proc) (me, i, ino_thing[thing].it_name);
robbiew24e30ab2003-01-07 20:53:21 +0000403 ++thing_cnt[thing];
404 }
405
vapieraf64a872006-02-15 06:47:36 +0000406 //tst_resm(TINFO,"Test %d pid %d exiting.", me, getpid());
robbiew24e30ab2003-01-07 20:53:21 +0000407}
408
subrata_modakf17ac842009-09-07 09:06:31 +0000409static void dowarn(int me, char *m1, char *m2)
robbiew24e30ab2003-01-07 20:53:21 +0000410{
subrata_modakf17ac842009-09-07 09:06:31 +0000411 int err = errno;
robbiew24e30ab2003-01-07 20:53:21 +0000412
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100413 tst_brkm(TBROK, NULL, "Test[%d]: error %d on %s %s",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800414 me, err, m1, (m2 ? m2 : ""));
robbiew24e30ab2003-01-07 20:53:21 +0000415}
416
subrata_modakf17ac842009-09-07 09:06:31 +0000417/*
418 * SIGTERM signal handler.
robbiew24e30ab2003-01-07 20:53:21 +0000419 */
subrata_modak04f47a12009-09-18 17:44:08 +0000420static void term(int sig LTP_ATTRIBUTE_UNUSED)
robbiew24e30ab2003-01-07 20:53:21 +0000421{
subrata_modakf17ac842009-09-07 09:06:31 +0000422 int i;
subrata_modakbdbaec52009-02-26 12:14:51 +0000423
robbiew24e30ab2003-01-07 20:53:21 +0000424 if (parent_pid == getpid()) {
subrata_modakf17ac842009-09-07 09:06:31 +0000425 for (i = 0; i < nchild; i++)
426 if (pidlist[i])
robbiew24e30ab2003-01-07 20:53:21 +0000427 kill(pidlist[i], SIGTERM);
subrata_modakf17ac842009-09-07 09:06:31 +0000428 return;
robbiew24e30ab2003-01-07 20:53:21 +0000429 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000430
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100431 tst_brkm(TBROK, NULL, "Child process exiting.");
robbiew24e30ab2003-01-07 20:53:21 +0000432}
433
subrata_modakf17ac842009-09-07 09:06:31 +0000434static void cleanup(void)
robbiew24e30ab2003-01-07 20:53:21 +0000435{
436 char mount_buffer[1024];
437
438 if (mnt == 1) {
subrata_modakf17ac842009-09-07 09:06:31 +0000439
440 if (chdir(startdir) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800441 tst_resm(TBROK, "Could not change to %s ", startdir);
subrata_modakf17ac842009-09-07 09:06:31 +0000442
robbiew24e30ab2003-01-07 20:53:21 +0000443 if (!strcmp(fstyp, "cfs")) {
subrata_modakf17ac842009-09-07 09:06:31 +0000444
445 sprintf(mount_buffer, "/bin/umount %s", partition);
446
robbiew24e30ab2003-01-07 20:53:21 +0000447 if (system(mount_buffer) != 0) {
subrata_modakf17ac842009-09-07 09:06:31 +0000448
Wanlong Gao354ebb42012-12-07 10:10:04 +0800449 tst_resm(TBROK, "Unable to unmount %s from %s ",
450 partition, mntpoint);
subrata_modakf17ac842009-09-07 09:06:31 +0000451
452 if (umount(partition))
Wanlong Gao354ebb42012-12-07 10:10:04 +0800453 tst_resm(TBROK,
454 "Unable to unmount %s from %s ",
455 partition, mntpoint);
subrata_modakf17ac842009-09-07 09:06:31 +0000456 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800457 tst_resm(TINFO,
458 "Forced umount for %s, /etc/mtab now dirty",
459 partition);
robbiew24e30ab2003-01-07 20:53:21 +0000460 }
subrata_modakf17ac842009-09-07 09:06:31 +0000461
Wanlong Gao354ebb42012-12-07 10:10:04 +0800462 } else if (umount(partition))
463 tst_resm(TBROK, "Unable to unmount %s from %s ",
464 partition, mntpoint);
subrata_modakf17ac842009-09-07 09:06:31 +0000465
466 if (rmdir(mntpoint) != 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800467 tst_resm(TBROK, "Unable to rmdir %s ", mntpoint);
subrata_modakf17ac842009-09-07 09:06:31 +0000468
robbiew24e30ab2003-01-07 20:53:21 +0000469 }
subrata_modakf17ac842009-09-07 09:06:31 +0000470
robbiew24e30ab2003-01-07 20:53:21 +0000471 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700472}