flowop_library.c revision f2fc321be9b4df7748e8c31a5edd154b0177b139
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "config.h"
#ifdef HAVE_SYS_ASYNCH_H
#endif
#include <inttypes.h>
#include <fcntl.h>
#ifdef HAVE_UTILITY_H
#include <utility.h>
#endif /* HAVE_UTILITY_H */
#ifdef HAVE_AIO
#include <aio.h>
#endif /* HAVE_AIO */
#ifdef HAVE_LIBAIO_H
#include <libaio.h>
#endif /* HAVE_LIBAIO_H */
#ifdef HAVE_SYS_ASYNC_H
#endif /* HAVE_SYS_ASYNC_H */
#ifdef HAVE_AIO_H
#include <aio.h>
#endif /* HAVE_AIO_H */
#ifndef HAVE_UINT_T
#define uint_t unsigned int
#endif /* HAVE_UINT_T */
#ifndef HAVE_AIOCB64_T
#endif /* HAVE_AIOCB64_T */
#ifndef HAVE_SYSV_SEM
#include <semaphore.h>
#endif /* HAVE_SYSV_SEM */
#include "filebench.h"
#include "flowop.h"
#include "fileset.h"
/*
* These routines implement the flowops from the f language. Each
* flowop has has a name such as "read", and a set of function pointers
* to call for initialization, execution and destruction of the flowop.
* The table flowoplib_funcs[] contains a flowoplib struct for each
* implemented flowop. Most flowops use a generic initialization function
* and all currently use a generic destruction function. All flowop
* functions referenced from the table are in this file, though, of
* course, they often call functions from other files.
*
* The flowop_init() routine uses the flowoplib_funcs[] table to
* create an initial set of "instance 0" flowops, one for each type of
* flowop, from which all other flowops are derived. These "instance 0"
* flowops are initialized with information from the table including
* pointers for their fo_init, fo_func and fo_destroy functions. When
* a flowop definition is encountered in an f language script, the
* "type" of flowop, such as "read" is used to search for the
* "instance 0" flowop named "read", then a new flowop is allocated
* which inherits its function pointers and other initial properties
* from the instance 0 flowop, and is given a new name as specified
* by the "name=" attribute.
*/
#ifdef HAVE_AIO
#endif
typedef struct flowoplib {
int fl_type;
int fl_attrs;
char *fl_name;
int (*fl_init)();
int (*fl_func)();
void (*fl_destruct)();
} flowoplib_t;
static flowoplib_t flowoplib_funcs[] = {
#ifdef HAVE_AIO
#endif
};
/*
* Loops through the master list of flowops defined in this
* module, and creates and initializes a flowop for each one
* by calling flowop_define. As a side effect of calling
* flowop define, the created flowops are placed on the
* master flowop list. All created flowops are set to
* instance "0".
*/
void
{
int i;
for (i = 0; i < nops; i++) {
fl = &flowoplib_funcs[i];
"failed to create flowop %s\n",
}
}
}
static int
{
return (0);
}
/* ARGSUSED */
static void
{
}
/*
* Generates a file attribute from flags in the supplied flowop.
*/
static int
{
int attrs = 0;
if (*flowop->fo_directio)
attrs |= FLOW_ATTR_DSYNC;
return (attrs);
}
/*
* Searches for a file descriptor. Tries the flowop's
* fo_fdnumber first and returns with it if it has been
* explicitly set (greater than 0). It next checks to
* see if a rotating file descriptor policy is in effect,
* and if not returns the fdnumber regardless of what
* it is. (note that if it is 0, it just selects to the
* default file descriptor in the threadflow's tf_fd
* array). If the rotating fd policy is in effect, it
* cycles from the end of the tf_fd array to one location
* beyond the maximum needed by the number of entries in
* the associated fileset on each invocation, then starts
* over from the end.
*
* The routine returns an index into the threadflow's
* tf_fd table where the actual file descriptor will be
* found. Note: the calling routine must not call this
* routine if the flowop does not have a fileset, and the
* flowop's fo_fdnumber is zero and fo_rotatefd is
* asserted, or an addressing fault may occur.
*/
int
{
/* If the script sets the fd explicitly */
if (flowop->fo_fdnumber > 0)
return (flowop->fo_fdnumber);
/* If the flowop defaults to persistent fd */
return (flowop->fo_fdnumber);
/* Rotate the fd on each flowop invocation */
return (-1);
}
/* First time around */
if (threadflow->tf_fdrotor == 0)
/* One fd for every file in the set */
threadflow->tf_fdrotor--;
return (threadflow->tf_fdrotor);
}
/*
* Emulate posix read / pread. If the flowop has a fileset,
* a file descriptor number index is fetched, otherwise a
* supplied fileobj file is used. In either case the specified
* file will be opened if not already open. If the flowop has
* neither a fileset or fileobj, an error is logged and -1
* returned.
*
* The actual read is done to a random offset in the
* threadflow's thread memory (tf_mem), with a size set by
* fo_iosize and at either a random disk offset within the
* working set size, or at the next sequential location. If
* any errors are encountered, -1 is returned, if successful,
* 0 is returned.
*/
static int
{
int filedesc;
int ret;
if (fd == -1)
return (-1);
(void) flowoplib_openfile_common(threadflow,
}
else
} else {
return (-1);
}
return (-1);
}
else
}
return (-1);
}
"tf_memsize smaller than IO size for thread %s",
return (-1);
}
"file size smaller than IO size for thread %s",
return (-1);
}
"read file %s failed, offset %lld "
"memoffset %zd: %s",
return (-1);
}
if ((ret == 0))
} else {
"read file %s failed, memoffset %zd: %s",
return (-1);
}
if ((ret == 0))
}
return (0);
}
#ifdef HAVE_AIO
/*
* Asynchronous write section. An Asynchronous IO element
* (aiolist_t) is used to associate the asynchronous write request with
* its subsequent completion. This element includes a aiocb64 struct
* that is used by posix aio_xxx calls to track the asynchronous writes.
* The flowops aiowrite and aiowait result in calls to these posix
* aio_xxx system routines to do the actual asynchronous write IO
* operations.
*/
/*
* Allocates an asynchronous I/O list (aio, of type
* aiolist_t) element. Adds it to the flowop thread's
* threadflow aio list. Returns a pointer to the element.
*/
static aiolist_t *
{
}
/* Add to list */
} else {
}
return (aiolist);
}
/*
* Searches for the aiolist element that has a matching
* completion block, aiocb. If none found returns -1. If
* found, removes the aiolist element from flowop thread's
* list and returns 0.
*/
static int
{
return (0);
}
while (aiolist) {
break;
}
}
return (-1);
/* Remove from the list */
if (previous)
else
return (0);
}
/*
* Emulate posix aiowrite(). Determines which file to use,
* either one file of a fileset, or the file associated
* with a fileobj, allocates and fills an aiolist_t element
* for the write, and issues the asynchronous write. This
* operation is only valid for random IO, and returns an
* error if the flowop is set for sequential IO. Returns 0
* on success, -1 on any encountered error.
*/
static int
{
int filedesc;
if (fd == -1)
return (-1);
(void) flowoplib_openfile_common(threadflow,
"writefile opened file %s",
}
else
} else {
return (-1);
}
return (-1);
}
else
}
return (-1);
}
/* Select memory offset for IO */
"tf_memsize smaller than IO size for thread %s",
return (-1);
}
"file size smaller than IO size for thread %s",
return (-1);
}
aiocb->aio_reqprio = 0;
"aio fd=%d, bytes=%lld, offset=%lld",
if (aio_write64(aiocb) < 0) {
}
} else {
return (-1);
}
return (0);
}
#define MAXREAP 4096
/*
* Emulate posix aiowait(). Waits for the completion of half the
* outstanding asynchronous IOs, or a single IO, which ever is
* larger. The routine will return after a sufficient number of
* completed calls issued by any thread in the procflow have
* completed, or a 1 second timout elapses. All completed
* IO operations are deleted from the thread's aiolist.
*/
static int
{
int uncompleted = 0;
/* Count the list of pending aios */
while (aio) {
uncompleted++;
}
do {
uint_t ncompleted = 0;
int inprogress;
int i;
/* Wait for half of the outstanding requests */
if (uncompleted > MAXREAP)
else
if (todo == 0)
todo = 1;
#ifdef HAVE_AIOWAITN
"aiowait failed: %s, outstanding = %d, "
"ncompleted = %d ",
}
ncompleted = todo;
inprogress = 0;
for (i = 0; i < ncompleted; i++) {
(errno == EINPROGRESS)) {
inprogress++;
continue;
}
"aio from list ");
return (-1);
}
}
#else
for (ncompleted = 0, inprogress = 0,
if (result == EINPROGRESS) {
inprogress++;
continue;
}
continue;
}
ncompleted++;
"from list ");
return (-1);
}
}
#endif
"aio2 completed %d ios, uncompleted = %d, inprogress = %d",
} while (uncompleted > MAXREAP);
return (0);
}
#endif /* HAVE_AIO */
/*
* Initializes a "flowop_block" flowop. Specifically, it
* initializes the flowop's fo_cv and unlocks the fo_lock.
*/
static int
{
return (0);
}
/*
* Blocks the threadflow until woken up by flowoplib_wakeup.
* The routine blocks on the flowop's fo_cv condition variable.
*/
static int
{
return (0);
}
/*
* Wakes up one or more target blocking flowops.
* Sends broadcasts on the fo_cv condition variables of all
* flowops on the target list, except those that are
* FLOW_MASTER flowops. The target list consists of all
* flowops whose name matches this flowop's "fo_targetname"
* attribute. The target list is generated on the first
* invocation, and the run will be shutdown if no targets
* are found. Otherwise the routine always returns 0.
*/
static int
{
/* if this is the first wakeup, create the wakeup list */
"wakeup: could not find op %s for thread %s",
}
while (result) {
}
}
/* wakeup the targets */
while (target) {
continue;
}
"wakeup flow %s-%d at address %zx",
}
return (0);
}
/*
* "think time" routines. the "hog" routine consumes cpu cycles as
* it "thinks", while the "delay" flowop simply calls sleep() to delay
* for a given number of seconds without consuming cpu cycles.
*/
/*
* Consumes CPU cycles and memory bandwidth by looping for
* flowop->fo_value times. With each loop sets memory location
* threadflow->tf_mem to 1.
*/
static int
{
int i;
for (i = 0; i < value; i++)
return (0);
}
/*
* Delays for fo_value seconds.
*/
static int
{
return (0);
}
/*
* Rate limiting routines. This is the event consuming half of the
* event system. Each of the four following routines will limit the rate
* to one unit of either calls, issued I/O operations, issued filebench
* operations, or I/O bandwidth. Since there is only one event generator,
* the events will be divided amoung multiple instances of an event
* consumer, and further divided among different consumers if more than
* one has been defined. There is no mechanism to enforce equal sharing
* of events.
*/
/*
* Completes one invocation per posted event. If eventgen_q
* has an event count greater than zero, one will be removed
* (count decremented), otherwise the calling thread will
* block until another event has been posted. Always returns 0
*/
static int
{
if (filebench_shm->eventgen_hz == 0)
return (0);
if (flowop->fo_initted == 0) {
}
while (filebench_shm->eventgen_hz) {
if (filebench_shm->eventgen_q > 0) {
break;
}
}
return (0);
}
/*
* Blocks the calling thread if the number of issued I/O
* operations exceeds the number of posted events, thus
* limiting the average I/O operation rate to the rate
* specified by eventgen_hz. Always returns 0.
*/
static int
{
int events;
if (filebench_shm->eventgen_hz == 0)
return (0);
if (flowop->fo_initted == 0) {
}
/* Is this the first time around */
if (flowop->fo_tputlast == 0) {
return (0);
}
/* No need to block if the q isn't empty */
return (0);
}
while (filebench_shm->eventgen_hz) {
break;
}
}
return (0);
}
/*
* Blocks the calling thread if the number of issued filebench
* operations exceeds the number of posted events, thus limiting
* the average filebench operation rate to the rate specified by
* eventgen_hz. Always returns 0.
*/
static int
{
int events;
if (filebench_shm->eventgen_hz == 0)
return (0);
if (flowop->fo_initted == 0) {
}
/* Is this the first time around */
if (flowop->fo_tputlast == 0) {
return (0);
}
/* No need to block if the q isn't empty */
return (0);
}
while (filebench_shm->eventgen_hz) {
break;
}
}
return (0);
}
/*
* Blocks the calling thread if the number of bytes of I/O
* issued exceeds one megabyte times the number of posted
* events, thus limiting the average I/O byte rate to one
* megabyte times the event rate as set by eventgen_hz.
* Always retuns 0.
*/
static int
{
int events;
if (filebench_shm->eventgen_hz == 0)
return (0);
if (flowop->fo_initted == 0) {
}
/* Is this the first time around */
if (flowop->fo_tputlast == 0) {
return (0);
}
/* No need to block if the q isn't empty */
return (0);
}
while (filebench_shm->eventgen_hz) {
break;
}
}
return (0);
}
/*
* These flowops terminate a benchmark run when either the specified
* number of bytes of I/O (flowoplib_finishonbytes) or the specified
* number of I/O operations (flowoplib_finishoncount) have been generated.
*/
/*
* Stop filebench run when specified number of I/O bytes have been
* transferred. Compares controlstats.fs_bytes with *flowop->value,
* and if greater returns 1, stopping the run, if not, returns 0
* to continue running.
*/
static int
{
uint64_t b;
b = controlstats.fs_bytes;
if (b > bytes) {
return (1);
}
return (0);
}
/*
* Stop filebench run when specified number of I/O operations have
* been performed. Compares controlstats.fs_count with *flowop->value,
* and if greater returns 1, stopping the run, if not, returns 0 to
* continue running.
*/
static int
{
return (1);
}
return (0);
}
/*
* Semaphore synchronization using either System V semaphores or
* posix semaphores. If System V semaphores are available, they will be
* used, otherwise posix semaphores will be used.
*/
/*
* Initializes the filebench "block on semaphore" flowop.
* If System V semaphores are implemented, the routine
* initializes the System V semaphore subsystem if it hasn't
* already been initialized, also allocates a pair of semids
* and initializes the highwater System V semaphore.
* If no System V semaphores, then does nothing special.
* Returns -1 if it cannot acquire a set of System V semphores
* or if the initial post to the semaphore set fails. Returns 0
* on success.
*/
static int
{
#ifdef HAVE_SYSV_SEM
int semid;
int highwater;
ipc_seminit();
/*
* Raise the number of the hw queue, causing the posting side to
* block if queue is > 2 x blocking value
*/
return (-1);
}
return (-1);
}
#else
"flow %s-%d semblock init with posix semaphore",
#endif /* HAVE_SYSV_SEM */
if (!(*flowop->fo_blocking))
return (0);
}
/*
* Releases the semids for the System V semaphore allocated
* to this flowop. If not using System V semaphores, then
* it is effectively just a no-op. Always returns 0.
*/
static void
{
#ifdef HAVE_SYSV_SEM
#else
#endif /* HAVE_SYSV_SEM */
}
/*
* Attempts to pass a System V or posix semaphore as appropriate,
* and blocks if necessary. Returns -1 if a set of System V
* semphores is not available or cannot be acquired, or if the initial
* post to the semaphore set fails. Returns 0 on success.
*/
static int
{
#ifdef HAVE_SYSV_SEM
int semid;
return (-1);
}
"flow %s-%d sem blocking on id %x num %x value %d",
/* Post, decrement the increment the hw queue */
if (*flowop->fo_blocking)
#ifdef HAVE_SEMTIMEDOP
#else
#endif /* HAVE_SEMTIMEDOP */
if (*flowop->fo_blocking)
#else
int i;
"flow %s-%d sem blocking on posix semaphore",
/* Decrement sem by value */
for (i = 0; i < value; i++) {
return (-1);
}
}
#endif /* HAVE_SYSV_SEM */
return (0);
}
/*
* Calls ipc_seminit(), and does so whether System V semaphores
* are available or not. Hence it will cause ipc_seminit to log errors
* if they are not. Always returns 0.
*/
/* ARGSUSED */
static int
{
#ifdef HAVE_SYSV_SEM
ipc_seminit();
#endif /* HAVE_SYSV_SEM */
return (0);
}
/*
* Post to a System V or posix semaphore as appropriate.
* On the first call for a given flowop instance, this routine
* will use the fo_targetname attribute to locate all semblock
* flowops that are expecting posts from this flowop. All
* target flowops on this list will have a post operation done
* to their semaphores on each call.
*/
static int
{
"sempost flow %s-%d",
/* if this is the first post, create the post list */
"sempost: could not find op %s for thread %s",
}
while (result) {
}
}
/* post to the targets */
while (target) {
#ifdef HAVE_SYSV_SEM
int semid;
int blocking;
#else
int i;
#endif /* HAVE_SYSV_SEM */
continue;
}
#ifdef HAVE_SYSV_SEM
"sempost flow %s-%d num %x",
/* ipc_mutex_lock(&target->fo_lock); */
FILEBENCH_NSEMS, 0)) == -1) {
"lookup semop %x failed: %s",
/* ipc_mutex_unlock(&target->fo_lock); */
return (-1);
}
if (*flowop->fo_blocking)
blocking = 1;
else
blocking = 0;
#ifdef HAVE_SEMTIMEDOP
#else
#endif /* HAVE_SEMTIMEDOP */
/* ipc_mutex_unlock(&target->fo_lock); */
return (-1);
}
"flow %s-%d finished posting",
#else
"sempost flow %s-%d to posix semaphore",
/* Increment sem by value */
for (i = 0; i < value; i++) {
/* ipc_mutex_unlock(&target->fo_lock); */
return (-1);
}
}
#endif /* HAVE_SYSV_SEM */
}
return (0);
}
/*
* Section for exercising create / open / close / delete operations
* on files within a fileset. For proper operation, the flowop attribute
* "fd", which sets the fo_fdnumber field in the flowop, must be used
* so that the same file is opened and later closed. "fd" is an index
* into a pair of arrays maintained by threadflows, one of which
* contains the operating system assigned file descriptors and the other
* a pointer to the filesetentry whose file the file descriptor
* references. An openfile flowop defined without fd being set will use
* the default (0) fd or, if specified, rotate through fd indices, but
* createfile and closefile must use the default or a specified fd.
* Meanwhile deletefile picks and arbitrary file to delete, regardless
* of fd attribute.
*/
/*
* XXX Making file selection more consistent among the flowops might good
*/
/*
* Emulates (and actually does) file open. Obtains a file descriptor
* index, then calls flowoplib_openfile_common() to open. Returns -1
* if not file descriptor is found or flowoplib_openfile_common
* encounters an error, otherwise 0.
*/
static int
{
if (fd == -1)
return (-1);
}
/*
* Common file opening code for filesets. Uses the supplied
* file descriptor index to determine the tf_fd entry to use.
* If the entry is empty (0) and the fileset exists, fileset
* pick is called to select a fileset entry to use. The file
* specified in the filesetentry is opened, and the returned
* operating system file descriptor and a pointer to the
* filesetentry are stored in tf_fd[fd] and tf_fse[fd],
* respectively. Returns -1 on error, 0 on success.
*/
static int
{
int tid = 0;
/*
* If the flowop doesn't default to persistent fd
* then get unique thread ID for use by fileset_pick
*/
"flowop %s attempted to open without closing on fd %d",
return (-1);
}
return (-1);
}
"flowop %s failed to pick file from %s on fd %d",
return (-1);
}
return (-1);
}
"flowop %s: opened %s fd[%d] = %d",
return (0);
}
/*
* Emulate create of a file. Uses the flowop's fdnumber to select
* tf_fd and tf_fse array locations to put the created file's file
* descriptor and filesetentry respectively. Uses fileset_pick()
* to select a specific filesetentry whose file does not currently
* exist for the file create operation. Then calls
* fileset_openfile() with the O_CREATE flag set to create the
* file. Returns -1 if the array index specified by fdnumber is
* already in use, the flowop has no associated fileset, or
* the create call fails. Returns 1 if a filesetentry with a
* nonexistent file cannot be found. Returns 0 on success.
*/
static int
{
"flowop %s attempted to create without closing on fd %d",
return (-1);
}
return (-1);
}
FILESET_PICKNOEXIST, 0)) == NULL) {
return (1);
}
return (-1);
}
"flowop %s: created %s fd[%d] = %d",
return (0);
}
/*
* Emulates delete of a file. Picks an arbitrary filesetentry
* whose file exists and uses unlink() to delete it. Clears
* the FSE_EXISTS flag for the filesetentry. Returns -1 if the
* flowop has no associated fileset. Returns 1 if an appropriate
* filesetentry cannot be found, and 0 on success.
*/
static int
{
char path[MAXPATHLEN];
char *pathtmp;
return (-1);
}
FILESET_PICKEXISTS, 0)) == NULL) {
return (1);
}
*path = 0;
return (0);
}
/*
* Emulates fsync of a file. Obtains the file descriptor index
* from the flowop, obtains the actual file descriptor from
* the threadflow's table, checks to be sure it is still an
* open file, then does an fsync operation on it. Returns -1
* if the file no longer is open, 0 otherwise.
*/
static int
{
"flowop %s attempted to fsync a closed fd %d",
return (-1);
}
/* Measure time to fsync */
return (0);
}
/*
* Emulate fsync of an entire fileset. Search through the
* threadflow's file descriptor array, doing fsync() on each
* open file that belongs to the flowop's fileset. Always
* returns 0.
*/
static int
{
int fd;
/* Match the file set to fsync */
continue;
/* Measure time to fsync */
}
return (0);
}
/*
* Emulate close of a file. Obtains the file descriptor index
* from the flowop, obtains the actual file descriptor from the
* threadflow's table, checks to be sure it is still an open
* file, then does a close operation on it. Then sets the
* threadflow file descriptor table entry to 0, and the file set
* entry pointer to NULL. Returns -1 if the file was not open,
* 0 otherwise.
*/
static int
{
"flowop %s attempted to close an already closed fd %d",
return (-1);
}
/* Measure time to close */
return (0);
}
/*
* Emulate stat of a file. Picks an arbitrary filesetentry with
* an existing file from the flowop's fileset, then performs a
* stat() operation on it. Returns -1 if the flowop has no
* associated fileset. Returns 1 if an appropriate filesetentry
* cannot be found, and 0 on success.
*/
static int
{
char path[MAXPATHLEN];
char *pathtmp;
return (-1);
}
FILESET_PICKEXISTS, 0)) == NULL) {
return (1);
}
*path = 0;
return (0);
}
/*
* Additional reads and writes. Read and write whole files, write
* and append to files. Some of these work with both fileobjs and
* filesets, others only with filesets. The flowoplib_write routine
* writes from thread memory, while the others read or write using
* fo_buf memory. Note that both flowoplib_read() and
* flowoplib_aiowrite() use thread memory as well.
*/
/*
* Emulate a read of a whole file. The file must be open
* with file descriptor and filesetentry stored at the
* locations indexed by the flowop's fdnumber. It then seeks
* to the beginning of the associated file, and reads
* FILE_ALLOC_BLOCK bytes at a time until the end of the
* file. Returns -1 on error, 0 on success.
*/
static int
{
int ret;
"flowop %s attempted to read a closed fd %d",
return (-1);
}
return (-1);
return (-1);
}
"tf_memsize smaller than IO size for thread %s",
return (-1);
}
/* Measure time to read bytes */
FILE_ALLOC_BLOCK)) > 0)
if (ret < 0) {
"Failed to read fd %d: %s",
return (-1);
}
return (0);
}
/*
* Emulate a write to a file of size fo_iosize. Will write
* to a file from a fileset if the flowop's fo_fileset field
* specifies one or its fdnumber is non zero. Otherwise it
* will write to a fileobj file, if one exists. If the file
* is not currently open, the routine will attempt to open
* it. The flowop's fo_wss parameter will be used to set the
* maximum file size if it is non-zero, otherwise the
* filesetentry's fse_size will be used. A random memory
* buffer offset is calculated, and, if fo_random is TRUE,
* a random file offset is used for the write. Otherwise the
* write is to the next sequential location. Returns 1 on
* errors, 0 on success.
*/
static int
{
int filedesc;
if (fd == -1)
return (-1);
(void) flowoplib_openfile_common(threadflow,
}
else
} else {
return (-1);
}
return (-1);
}
else
}
return (-1);
}
return (-1);
}
/* Select memory offset for IO */
"tf_memsize smaller than IO size for thread %s",
return (-1);
}
"file size smaller than IO size for thread %s",
return (-1);
}
"offset %lld memoffset %zd: %s",
return (-1);
}
} else {
"write failed, memoffset %zd: %s",
return (-1);
}
}
return (0);
}
/*
* Emulate a write of a whole file. The size of the file
* is taken from a filesetentry identified by fo_srcfdnumber,
* while the file descriptor used is identified by
* fo_fdnumber. Does multiple writes of FILE_ALLOC_BLOCK
* length until full file has been written. Returns -1 on
* error, 0 on success and sets flowop->fo_iosize to the
* number of bytes actually written.
*/
static int
{
int wsize;
int ret;
"flowop %s attempted to write a closed fd %d",
return (-1);
}
return (-1);
}
"tf_memsize smaller than IO size for thread %s",
}
return (-1);
}
/* Measure time to write bytes */
"Failed to write %d bytes on fd %d: %s",
return (-1);
}
}
return (0);
}
/*
* Emulate a fixed size append to a file. Will append data to
* a file chosen from a fileset if the flowop's fo_fileset
* field specifies one or if its fdnumber is non zero.
* Otherwise it will write to a fileobj file, if one exists.
* The flowop's fo_wss parameter will be used to set the
* maximum file size if it is non-zero, otherwise the
* filesetentry's fse_size will be used. A random memory
* buffer offset is calculated, then a logical seek to the
* end of file is done followed by a write of fo_iosize
* bytes. Writes are actually done from fo_buf, rather than
* tf_mem as is done with flowoplib_write(), and no check
* is made to see if fo_iosize exceeds the size of fo_buf.
* Returns -1 on error, 0 on success.
*/
static int
{
long memsize;
/* LINTED E_FUNC_SET_NOT_USED */
int ret;
if (fd == -1)
return (-1);
(void) flowoplib_openfile_common(threadflow,
}
else
} else {
return (-1);
}
return (-1);
}
else
}
/* XXX wss is not being used */
return (-1);
}
"tf_memsize smaller than IO size for thread %s",
return (-1);
}
/* Measure time to write bytes */
"Failed to write %d bytes on fd %d: %s",
return (-1);
}
return (0);
}
/*
* Emulate a random size append to a file. Will append data
* to a file chosen from a fileset if the flowop's fo_fileset
* field specifies one or if its fdnumber is non zero. Otherwise
* it will write to a fileobj file, if one exists. The flowop's
* fo_wss parameter will be used to set the maximum file size
* if it is non-zero, otherwise the filesetentry's fse_size
* will be used. A random transfer size (but at most fo_iosize
* bytes) and a random memory offset are calculated. A logical
* seek to the end of file is done, then writes of up to
* FILE_ALLOC_BLOCK in size are done until the full transfer
* size has been written. Writes are actually done from fo_buf,
* rather than tf_mem as is done with flowoplib_write().
* Returns -1 on error, 0 on success.
*/
static int
{
/* LINTED E_FUNC_SET_NOT_USED */
if (fd == -1)
return (-1);
(void) flowoplib_openfile_common(threadflow,
}
else
} else {
return (-1);
}
return (-1);
}
else
}
/* XXX wss is not being used */
return (-1);
}
return (-1);
}
return (-1);
}
/* Measure time to write bytes */
int ret = 0;
"Failed to write %d bytes on fd %d: %s",
return (-1);
}
}
return (0);
}
/*
* Prints usage information for flowop operations.
*/
void
{
"flowop [openfile|createfile] name=<name>,fileset=<fname>\n");
" [,fd=<file desc num>]\n");
"flowop closefile name=<name>,fd=<file desc num>]\n");
" [,fd=<file desc num>]\n");
" [,fd=<file desc num>]\n");
"flowop fsync name=<name>,fd=<file desc num>]\n");
"flowop fsyncset name=<name>,fileset=<fname>]\n");
" filename|fileset=<fname>,\n");
"flowop [appendfile|appendfilerand] name=<name>, \n");
" filename|fileset=<fname>,\n");
"flowop [readwholefile|writewholefile] name=<name>, \n");
" filename|fileset=<fname>,\n");
"<aiowrite-flowop>\n");
"target=<semblock-flowop>,\n");
" value=<increment-to-post>\n");
"<decrement-to-receive>,\n");
"<inbound-queue-max>\n");
"flowop wakeup name=<name>,target=<block-flowop>,\n");
"flowop hog name=<name>,value=<number-of-mem-ops>\n");
"flowop delay name=<name>,value=<number-of-seconds>\n");
"flowop finishoncount name=<name>,value=<ops/s>\n");
"flowop finishonbytes name=<name>,value=<bytes>\n");
}