X-Git-Url: http://git.apps.os.sepia.ceph.com/?p=xfstests-dev.git;a=blobdiff_plain;f=ltp%2Fgrowfiles.c;h=7ac44aba0bede0f5e0ddf7ee8c47c46b0fd47bf3;hp=a987b5a8aaa870c0226a4821076e84d332997e1b;hb=fb72f6f547d7f2ecb97f33858193e58119bb5a4d;hpb=d259454b195c43497bcdaac6bb83a0f2e81afc36 diff --git a/ltp/growfiles.c b/ltp/growfiles.c index a987b5a8..7ac44aba 100644 --- a/ltp/growfiles.c +++ b/ltp/growfiles.c @@ -1,19 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2000 Silicon Graphics, Inc. * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * This program will grow a list of files. @@ -62,36 +50,30 @@ #include "dataascii.h" #include "random_range.h" #include "databin.h" - - -extern char *openflags2symbols(); - -extern int parse_open_flags(); -extern int background(); -extern int forker(); -extern int datapidgen(); -extern void databingen(); -extern int datapidchk(); -extern int databinchk(); -extern int file_lock(); - -int file_size(); -int check_write(); -int shrinkfile(); -int check_file(); -int growfile(); +#include "open_flags.h" +#include "forker.h" +#include "file_lock.h" + +extern int datapidgen(int pid, unsigned char *buffer, int bsize, int offset); +extern void databingen(int mode, unsigned char *buffer, int bsize, int offset); +extern int datapidchk(int pid, char *buffer, int bsize, int offset, char **errmsg); +extern int databinchk(int mode, char *buffer, int bsize, int offset, char **errmsg); + +int file_size(int fd); +int check_write(int fd, int cf_inter, char *filename, int mode); +int shrinkfile(int fd, char *filename, int trunc_incr, int trunc_inter, int just_trunc); +int check_file(int fd, int cf_inter, char *filename, int no_file_check); +int growfile(int fd, char *file, int grow_incr, unsigned char *buf); int cleanup(); int handle_error(); -int lkfile(); +int lkfile(int fd, int operation, int lklevel); void usage(); void help(); -void prt_examples(); +void prt_examples(FILE *stream); int set_sig(); void sig_handler(); static void notify_others(); -#ifndef NO_XFS -int pre_alloc(); -#endif +int pre_alloc(char *file, int fd, int size); #define NEWIO 1 /* Use the tlibio.c functions */ @@ -168,11 +150,7 @@ int mult_size=1; /* when random iosz, iosz must be mult of mult_size */ /* the *_lseek variables are only used when radon lseek option (-R) is used */ int min_lseek=0; /* also set in option parsing */ int max_lseek=-1; /* -1 means size of file */ -#ifdef CRAY -int Pattern=PATTERN_OFFSET; /* This pattern is 64 bit word based */ -#else int Pattern=PATTERN_ASCII; -#endif int Seed=-1; /* random number seed, < 0 == uninitialized */ int Nseeds=0; /* Number of seed specified by the user */ int *Seeds; /* malloc'ed arrary of ints holding user spec seeds */ @@ -229,32 +207,6 @@ struct fileinfo_t { * to use. */ int Open_flags[] = { -#ifdef CRAY - O_RDWR|O_CREAT, - O_RDWR|O_CREAT|O_RAW, - O_RDWR|O_CREAT|O_BIG, - O_RDWR|O_CREAT|O_APPEND, - O_RDWR|O_CREAT|O_NDELAY, - O_RDWR|O_CREAT|O_PLACE, - O_RDWR|O_CREAT|O_SYNC, - O_RDWR|O_CREAT|O_RAW|O_SYNC, - O_RDWR|O_CREAT|O_NDELAY|O_SYNC, - O_RDWR|O_CREAT|O_NDELAY|O_SYNC|O_BIG, - O_RDWR|O_CREAT|O_RAW, - O_RDWR|O_CREAT|O_RAW|O_APPEND, - O_RDWR|O_CREAT|O_RAW|O_BIG, - O_RDWR|O_CREAT|O_RAW|O_APPEND|O_BIG, -/*** - * O_WELLFORMED makes -o random require well formed i/o - ***/ -#if ALLOW_O_WELLFORMED -#if O_PARALLEL - O_RDWR|O_CREAT|O_PARALLEL|O_WELLFORMED|O_RAW, - O_RDWR|O_CREAT|O_PARALLEL|O_WELLFORMED|O_RAW|O_TRUNC, -#endif /* O_PARALLEL */ -#endif - -#else /* CRAY */ O_RDWR|O_CREAT, O_RDWR|O_CREAT|O_APPEND, O_RDWR|O_CREAT|O_NDELAY, @@ -262,7 +214,6 @@ int Open_flags[] = { O_RDWR|O_CREAT|O_SYNC|O_NDELAY, O_RDWR|O_CREAT|O_APPEND|O_NDELAY, -#endif /* CRAY */ }; #define REXEC_INIT 0 /* don't do re-exec of childern */ @@ -270,11 +221,7 @@ int Open_flags[] = { #define REXEC_DONE 2 /* We've already been re-exec'ed */ #ifndef BSIZE -#ifdef CRAY -#define BSIZE 1024 -#else #define BSIZE 512 -#endif /* CRAY */ #endif /* BSIZE */ #define USECS_PER_SEC 1000000 /* microseconds per second */ @@ -328,9 +275,7 @@ int tmp; char chr; int ret; int pre_alloc_space = 0; -#ifndef NO_XFS int total_grow_value = 0; /* used in pre-allocations */ -#endif int backgrnd = 1; /* return control to user */ struct stat statbuf; int time_iterval = -1; @@ -428,9 +373,6 @@ extern int Forker_npids; /* num of forked pid, defined in forker.c */ case 'd': auto_dir=optarg; -#ifdef CRAY - unsetenv("TMPDIR"); /* force the use of auto_dir */ -#endif if ( stat(auto_dir, &statbuf) == -1 ) { if ( mkdir(auto_dir, 0777) == -1 ) { if ( errno != EEXIST ) { @@ -602,28 +544,15 @@ extern int Forker_npids; /* num of forked pid, defined in forker.c */ case 'p' : /* pre allocate space */ -#ifdef NO_XFS printf("%s%s: --p is illegal option on this system\n", Progname, TagName); exit(1); -#else - pre_alloc_space++; -#endif break; case 'P': -#ifdef CRAY - if (strcmp(optarg, "PANIC") != 0 ) { - fprintf(stderr, "%s%s: --P arg must be PANIC\n", Progname, TagName); - exit(1); - } - Upanic_on_error++; - printf("%s: Will call upanic after writes\n"); -#else printf("%s%s: --P is illegal option on non-cray system\n", Progname, TagName); exit(1); -#endif break; case 'q': /* file content or pattern */ @@ -853,7 +782,7 @@ extern int Forker_npids; /* num of forked pid, defined in forker.c */ break; case 'W': - sprintf( TagName, "(%.39s)", optarg ); + sprintf( TagName, "(%.37s)", optarg ); break; case 'y': @@ -904,11 +833,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); background(Progname); /* give user their prompt back */ } -#if CRAY - if ( Sync_with_others ) - setpgrp(); -#endif - if ( Debug > 3 ) { #if NEWIO lio_set_debug(Debug-3); @@ -1162,10 +1086,9 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); /* * construct auto filename and insert them into filenames space */ - for(ind=0;ind 3 ) { printf("%s: %d DEBUG3 %s/%d: %d Open filename = %s, open flags = %#o %s\n", Progname, Pid, __FILE__, __LINE__, Iter_cnt, filename, ret, - openflags2symbols(ret, ",", NULL)); + openflags2symbols(ret, ",", 0)); } else if ( Debug > 2 ) { printf("%s: %d DEBUG3 %s/%d: %d filename = %s, open flags = %#o\n", Progname, Pid, __FILE__, __LINE__, Iter_cnt, filename, ret); @@ -1316,7 +1228,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); lkfile(fd, LOCK_EX, LKLVL1); /* lock if lockfile is LKLVL1 */ -#ifndef NO_XFS /* * preallocation is only done once, if specified. */ @@ -1334,7 +1245,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); Iter_cnt=0; /* reset outside loop to restart from one */ continue; } -#endif /* * grow file by desired amount. @@ -1343,7 +1253,7 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); * if we are dealing with a FIFO file. */ - if (growfile(fd, filename, grow_incr, Buffer) != 0 ) { + if (growfile(fd, filename, grow_incr, (unsigned char *)Buffer) != 0 ) { handle_error(); lkfile(fd, LOCK_UN, LKLVL1); /* release lock */ close(fd); @@ -1399,13 +1309,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); if ( delaytime ) { int ct, end; -#ifdef CRAY - ct=_rtc(); - end=ct+delaytime; - while ( ct < end ) { - ct = _rtc(); - } -#else struct timeval curtime; gettimeofday(&curtime, NULL); ct=curtime.tv_sec*USECS_PER_SEC + curtime.tv_usec; @@ -1415,10 +1318,8 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); gettimeofday(&curtime, NULL); ct=curtime.tv_sec*USECS_PER_SEC + curtime.tv_usec; } -#endif } } -#ifndef NO_XFS /* * if Iter_cnt == 0, then we pre allocated space to all files * and we are starting outside loop over. Set pre_alloc_space @@ -1427,9 +1328,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid()); if ( Iter_cnt == 0 ) { pre_alloc_space=0; } -#endif - - } /* end iteration for loop */ @@ -1473,26 +1371,17 @@ set_sig() case SIGKILL: case SIGSTOP: case SIGCONT: -#ifdef CRAY - case SIGINFO: - case SIGRECOVERY: -#endif /* CRAY */ #ifdef SIGCKPT case SIGCKPT: #endif /* SIGCKPT */ #ifdef SIGRESTART case SIGRESTART: #endif /* SIGRESTART */ - case SIGCLD: + case SIGCHLD: break; default: -#ifdef sgi - sigset( sig, sig_handler ); -#else -/* linux and cray */ signal(sig, sig_handler); -#endif break; } } /* endfor */ @@ -1513,9 +1402,7 @@ int sig; if ( sig == SIGUSR2 ) { fprintf(stdout, "%s%s: %d %s/%d: received SIGUSR2 (%d) - stopping.\n", Progname, TagName, Pid, __FILE__, __LINE__, sig); -#ifndef sgi signal(sig, sig_handler); /* allow us to get this signal more than once */ -#endif } else if( sig == SIGINT ){ /* The user has told us to cleanup, don't pretend it's an error. */ @@ -1553,23 +1440,16 @@ notify_others() if ( Sync_with_others && send_signals == 0 ) { -#if CRAY - send_signals=1; /* only send signals once */ - if ( Debug > 1 ) - printf("%s%s: %d DEBUG2 %s/%d: Sending SIGUSR2 to pgrp\n", - Progname, TagName, Pid, __FILE__, __LINE__); - killm(C_PGRP, getpgrp(), SIGUSR2); -#else send_signals=1; /* only send signals once */ for (ind=0; ind< Forker_npids; ind++) { - if ( Forker_pids[ind] != Pid ) + if ( Forker_pids[ind] != Pid ) { if ( Debug > 1 ) printf("%s%s: %d DEBUG2 %s/%d: Sending SIGUSR2 to pid %d\n", Progname, TagName, Pid, __FILE__, __LINE__, Forker_pids[ind]); kill(Forker_pids[ind], SIGUSR2); + } } -#endif } } @@ -1584,12 +1464,6 @@ handle_error() { Errors++; -#ifdef CRAY - if ( Errors & Upanic_on_error ) { - upanic(PA_PANIC); - } -#endif - if ( Maxerrs && Errors >= Maxerrs ) { printf("%s%s: %d %s/%d: %d Hit max errors value of %d\n", Progname, TagName, Pid, __FILE__, __LINE__, Iter_cnt, Maxerrs); @@ -2031,25 +1905,6 @@ unsigned char *buf; Progname, TagName, __FILE__, __LINE__, errno, strerror(errno) ); return -1; } -#if NEWIO -#ifdef sgi - /* If this is POSIX I/O and it is via aio_{read,write} - * or lio_listio then after completion of the I/O the - * value of the file offset for the file is - * unspecified--which means we cannot trust what - * tell() told us. Fudge it here. - */ - if( (io_type & LIO_IO_ASYNC_TYPES) || (io_type & LIO_RANDOM) ){ - if( tmp != Woffset + grow_incr ){ - if( Debug > 5 ){ - printf("%s: %d DEBUG6 %s/%d: posix fudge, forcing tmp (%d) to match Woffset+grow_incr (%d)\n", - Progname, Pid, __FILE__, __LINE__, tmp, Woffset+grow_incr); - } - tmp = Woffset + grow_incr; - } - } -#endif -#endif } lkfile(fd, LOCK_UN, LKLVL0); @@ -2141,9 +1996,6 @@ int just_trunc; /* lseek has already been done for you */ int cur_offset; int new_offset; int ret; -#ifdef CRAY - int offset; -#endif shrink_cnt++; @@ -2185,19 +2037,6 @@ int just_trunc; /* lseek has already been done for you */ else { new_offset=random_range(min_lseek, max_lseek, 1, NULL); } - -#ifdef CRAY - if ((offset=lseek(fd, new_offset, SEEK_SET)) == -1 ) { - fprintf(stderr, "%s%s: %d %s/%d: lseek(%d, %d, SEEK_SET) l3 failed: %s\n", - Progname, TagName, Pid, __FILE__, __LINE__, fd, new_offset, strerror(errno)); - lkfile(fd, LOCK_UN, LKLVL0); - return -1; - } - else if ( Debug > 3 ) - printf("%s: %d DEBUG4 %s/%d: lseeked to random offset %d\n", - Progname, Pid, __FILE__, __LINE__, offset); - -#endif } else { /* remove trunc_incr from file */ @@ -2206,41 +2045,19 @@ int just_trunc; /* lseek has already been done for you */ if ( new_offset < 0 ) new_offset=0; - -#ifdef CRAY - if ( lseek(fd, new_offset, SEEK_SET) == -1 ) { - fprintf(stderr, "%s%s: %d %s/%d: lseek(fd, %d, SEEK_SET) l4 failed: %s\n", - Progname, TagName, Pid, __FILE__, __LINE__, new_offset, strerror(errno)); - lkfile(fd, LOCK_UN, LKLVL0); - return -1; - } - else if ( Debug > 3 ) - printf("%s: %d DEBUG4 %s/%d: lseeked to offset %d, %d bytes from end\n", - Progname, Pid, __FILE__, __LINE__, new_offset, trunc_incr); -#endif } - -#ifdef CRAY - ret=trunc(fd); -#else ret=ftruncate(fd, new_offset ); if( (ret == 0) && (Debug > 3) ){ printf("%s: %d DEBUG4 %s/%d: ftruncated to offset %d, %d bytes from end\n", Progname, Pid, __FILE__, __LINE__, new_offset, trunc_incr); } -#endif lkfile(fd, LOCK_UN, LKLVL0); if ( ret == -1 ) { -#ifdef CRAY - fprintf(stderr, "%s%s: %d %s/%d: trunc failed: %s\n", - Progname, TagName, Pid, __FILE__, __LINE__, strerror(errno)); -#else fprintf(stderr, "%s%s: %d %s/%d: ftruncate failed: %s\n", Progname, TagName, Pid, __FILE__, __LINE__, strerror(errno)); -#endif return -1; } @@ -2431,7 +2248,7 @@ int mode; /* write mode */ if ( Debug > 0 ) printf("%s%s: %d DEBUG1 %s/%d: **fd:%d, lk:%d, offset:%d, sz:%d open flags:%#o %s\n", Progname, TagName, Pid, __FILE__, __LINE__, fd, lockfile, - Woffset, Grow_incr, Fileinfo.openflags, openflags2symbols(Fileinfo.openflags, ",", NULL)); + Woffset, Grow_incr, Fileinfo.openflags, openflags2symbols(Fileinfo.openflags, ",", 0)); fflush(stderr); return 1; @@ -2746,7 +2563,6 @@ lkfile(int fd, int operation, int lklevel) return 0; } -#ifndef NO_XFS /*********************************************************************** * ***********************************************************************/ @@ -2757,18 +2573,6 @@ int fd; int size; { -#ifdef CRAY - long avl; - - if ( ialloc(fd, size, IA_CONT, &avl) == -1 ) { - fprintf(stderr, "%s%s %s/%d: Unable to pre-alloc space: ialloc failed: %d %s\n", - Progname, TagName, - __FILE__, __LINE__, errno, strerror(errno)); - return -1; - } -#endif - -#ifndef NO_XFS #ifdef XFS_IOC_RESVSP struct xfs_flock64 f; @@ -2797,9 +2601,7 @@ int size; __FILE__, __LINE__, errno, strerror(errno)); return -1; } -#endif #endif return 0; } -#endif