fileobj.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 <fcntl.h>
#include <pthread.h>
#include <errno.h>
#ifdef HAVE_UTILITY_H
#include <utility.h>
#endif
#include "vars.h"
#include "filebench.h"
#include "fileobj.h"
/*
* File objects, of type fileobj_t, are entities which contain
* information about filebench files, one file per fileobj. The
* information includes the file's name, its pathname, its size, and
* a set of attributes indicating whether to create, preallocate,
* allocate in parallel, reuse, and cache the file or not. All fileobj
* are kept on a global linked list in shared memory.
*/
/*
* Prints syntax for specifying file object parameters.
*/
void
{
"define file name=<name>,path=<pathname>,size=<size>\n");
}
/*
* Frees up memory mapped file region of supplied size.
* The file descriptor "fd" indicates which memory mapped
* file. If successful, returns 0. Otherwise returns -1 if
* "size" is zero, or -1 times the number of times msync()
* failed.
*/
static int
{
int ret = -1;
}
return (ret);
}
/*
* Creates the file associated with a fileobj (file object)
* and writes fo_size bytes to it. The bytes are written
* FILE_ALLOC_BLOCK bytes at a time. However, if the file
* already exists, is full size, and the fo_reuse flag is
* set, then the file is just left alone.
*/
static int
{
int fd;
char *buf;
int exists;
char name[MAXPATHLEN];
return (-1);
}
"Failed to find file %s for pre-allocation: %s",
return (-1);
}
/* If it's a raw device */
#ifdef RAW
return (0);
#endif
return (0);
/* reuse, but too large */
"Truncating & Re-using file %s", name);
return (0);
}
}
return (-1);
}
int ret = 0;
/* Write FILE_ALLOC_BLOCK's worth except on last write */
"Failed to pre-allocate file %s: %s",
return (-1);
}
}
"Pre-allocated file %s", name);
return (0);
}
/*
* Creates the file portion of a fileobj (file object) and
* leaves it empty. If the file already exists and the fo_reuse
* flag is set, the file will be retained, otherwise any
* existing file will first be deleted, and then a new
* (empty) file will be created.
*/
static int
{
int fd;
int exists;
char name[MAXPATHLEN];
return (-1);
}
/* If it's a raw device */
#ifdef RAW
return (0);
#endif
/*
* If we are re-using the file, then just free up the cache and
* return
*/
return (fd < 0);
}
"Failed to create file %s: %s",
return (-1);
}
return (fd < 0);
}
/*
* Creates and optionally preallocates the actual file
* portions of all fileobjs found on the filelist maintained
* in shared memory. If fo_paralloc is set, a thread will
* be spawned to preallocate the fileobj in parallel with
* that of other fileobjs. The routine waits for all such
* threads to finish before exiting.
*/
int
{
int nthreads = 0;
int ret = 0;
"Creating/pre-allocating files");
while (fileobj) {
/* Create files */
/* Preallocate files */
continue;
}
(void *(*)(void*))fileobj_prealloc,
fileobj) != 0) {
"File prealloc thread create failed");
} else {
nthreads++;
}
}
}
/* Wait for allocations to finish */
if (nthreads) {
"Waiting for preallocation threads to complete...");
while (fileobj) {
}
}
return (ret);
}
/*
* Allocates a fileobj (file object) in shared memory, sets
* it's name to "name" and places it on the shared filelist.
* It also returns a pointer to the fileobj.
*/
fileobj_define(char *name)
{
return (NULL);
/* allocate a fileobj from shared memory */
"fileobj_define: Can't malloc fileobj");
return (NULL);
}
/* Add fileobj to global list */
} else {
}
/* name the new fileobj */
return (fileobj);
}
/*
* Opens the file associated with a fileobj. The "attrs"
* integer supplies optional attributes to the open64 call
* used to actually open the file. The file is opened in
* if FLOW_ATTR_DSYNC is set in "attrs", and be set to
* DIRECTIO_ON if FLOW_ATTR_DIRECTIO is set in "attrs".
* The file descriptor integer returned by open64 is
* returned to the caller.
*/
int
{
int open_attrs = 0;
int fd;
char name[MAXPATHLEN];
return (-1);
}
if (attrs & FLOW_ATTR_DSYNC) {
#ifdef sun
open_attrs |= O_DSYNC;
#else
open_attrs |= O_FSYNC;
#endif
}
if (fd < 0) {
"Failed to open %s: %s",
name,
}
/* if running on Solaris, decide whether to use buffered io or not */
#ifdef sun
if (attrs & FLOW_ATTR_DIRECTIO)
else
#endif
return (fd);
}
/*
* Searches the shared "filelist" for the named filobj.
* Returns a pointer to the fileobj if found, otherwise NULL.
*/
fileobj_find(char *name)
{
while (fileobj) {
return (fileobj);
}
}
return (NULL);
}
/*
* Iterates over all the file objects in the filelist,
* executing the supplied command "*cmd()" on them. Also
* indicates to the executed command if it is the first
* time the command has been executed since the current
* call to fileobj_iter.
*/
void
{
int count = 0;
while (fileobj) {
count++;
}
}
/*
* Prints information to the filebench log about the file
* object. Also prints a header on the first call.
*/
int
{
if (first) {
"File Name",
"Path Name",
"Size");
}
return (0);
}