+// 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 version 2 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.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like. Any license provided herein, whether implied or
- * otherwise, applies only to this software file. Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA 94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ * Copyright (c) 2000 Silicon Graphics, Inc.
+ * All Rights Reserved.
*/
/*
* This program will grow a list of files.
* Author: Richard Logan
*
*/
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <time.h>
-#include <sys/file.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/param.h>
-#include <sys/signal.h>
-#include <errno.h>
-#include <string.h>
-#include "dataascii.h"
-#include "random_range.h"
-#include "databin.h"
-#ifndef NO_XFS
-#include <xfs/libxfs.h>
-#endif
+#include "global.h"
-#ifdef CRAY
-#include <sys/panic.h>
-#include <sys/category.h>
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
#endif
-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 "dataascii.h"
+#include "random_range.h"
+#include "databin.h"
+#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 */
/* 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 */
* 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,
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 */
#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 */
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;
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 ) {
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 */
break;
case 'W':
- sprintf( TagName, "(%.39s)", optarg );
+ sprintf( TagName, "(%.37s)", optarg );
break;
case 'y':
no_file_check=1;
if ( write_check_inter || file_check_inter )
printf("%s%s: %d Using random pattern - no data checking will be performed!\n",
- Progname, TagName, getpid());
+ Progname, TagName, (int)getpid());
}
else if ( max_lseek == LSK_EOFPLUSGROW || Mode & MODE_GROW_BY_LSEEK ) {
no_file_check=1;
if ( file_check_inter )
printf("%s%s: %d Using random lseek beyond EOF or lseek grow,\n\
-no whole file checking will be performed!\n", Progname, TagName, getpid());
+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);
/*
* construct auto filename and insert them into filenames space
*/
-
for(ind=0;ind<num_auto_files; ind++, num++) {
- sprintf((char *)filenames+(num*PATH_MAX), "%s.%d",
- tempnam(auto_dir, auto_file), ind );
+ sprintf((char *)filenames+(num*PATH_MAX), "%s/%s.%d",
+ auto_dir, auto_file, ind);
}
/*
Progname, Pid, num_files);
}
-#ifndef NO_XFS
if ( pre_alloc_space ) {
if ( iterations == 0 ) {
fprintf(stderr, "%s%s: %d %s/%d: can NOT pre-alloc and grow forever\n",
total_grow_value=bytes_to_consume;
}
}
-#endif
/*
* If delaying between iterations, get amount time to
* delaysecs in clocks or usecs.
- * If on the CRAY, delaytime is in clocks since
- * _rtc() will be used, which does not have the overhead
- * of gettimeofday(2).
*/
if ( delaysecs ) {
-#if CRAY
- int hz;
- hz=sysconf(_SC_CLK_TCK);
- delaytime=(int)((float)hz * delaysecs);
-#else
delaytime=(int)((float)USECS_PER_SEC * delaysecs);
-#endif
}
/*
if ( Debug > 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);
lkfile(fd, LOCK_EX, LKLVL1); /* lock if lockfile is LKLVL1 */
-#ifndef NO_XFS
/*
* preallocation is only done once, if specified.
*/
Iter_cnt=0; /* reset outside loop to restart from one */
continue;
}
-#endif
/*
* grow file by desired amount.
* 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);
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;
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
if ( Iter_cnt == 0 ) {
pre_alloc_space=0;
}
-#endif
-
-
} /* end iteration for loop */
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 */
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. */
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
}
}
{
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);
int fd;
char *file;
int grow_incr;
-char *buf;
+unsigned char *buf;
{
int noffset;
int ret;
+ /* REFERENCED */
int cur_offset;
char *errmsg;
int fsize; /* current size of file */
else if ( Pattern == PATTERN_PID )
datapidgen(Pid, buf, grow_incr, Woffset);
else if ( Pattern == PATTERN_ASCII )
- dataasciigen(NULL, buf, grow_incr, Woffset);
+ dataasciigen(NULL, (char *)buf, grow_incr, Woffset);
else if ( Pattern == PATTERN_RANDOM )
databingen('r', buf, grow_incr, Woffset);
else if ( Pattern == PATTERN_ALT )
else if ( Pattern == PATTERN_ONES )
databingen('o', buf, grow_incr, Woffset);
else
- dataasciigen(NULL, buf, grow_incr, Woffset);
+ dataasciigen(NULL, (char *)buf, grow_incr, Woffset);
if ( Debug > 2 )
printf("%s: %d DEBUG3 %s/%d: attempting to write %d bytes\n",
*****/
#if NEWIO
- ret=lio_write_buffer(fd, io_type, buf, grow_incr,
+ ret=lio_write_buffer(fd, io_type, (char *)buf, grow_incr,
SIGUSR1, &errmsg,0);
#else
ret=write_buffer(fd, io_type, buf, grow_incr, 0, &errmsg);
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);
int cur_offset;
int new_offset;
int ret;
-#ifdef CRAY
- int offset;
-#endif
shrink_cnt++;
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 */
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;
}
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;
return 0;
}
-#ifndef NO_XFS
/***********************************************************************
*
***********************************************************************/
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;
f.l_whence = 0;
__FILE__, __LINE__, errno, strerror(errno));
return -1;
}
+#else
+ struct flock64 f;
+
+ f.l_whence = 0;
+ f.l_start = 0;
+ f.l_len = size;
+ /* non-zeroing reservation */
+ if( fcntl( fd, F_RESVSP64, &f ) == -1 ){
+ fprintf(stderr, "%s%s %s/%d: Unable to pre-alloc space: fcntl(F_RESVSP) failed: %d %s\n",
+ Progname, TagName,
+ __FILE__, __LINE__, errno, strerror(errno));
+ return -1;
+ }
#endif
return 0;
}
-#endif