예제 #1
0
static void createdir(struct benchfiles *dirs, randdata_t *rd)
{
	struct ffsb_file *newdir;

	newdir = add_file(dirs, 0, rd);
	if (mkdir(newdir->name, S_IRWXU) < 0) {
		perror("mkdir");
		exit(1);
	}
	unlock_file_writer(newdir);
}
예제 #2
0
static void removedir(struct benchfiles *dirs, randdata_t *rd)
{
	struct ffsb_file *deldir;

	deldir = choose_file_writer(dirs, rd);
	remove_file(dirs, deldir);

	if (rmdir(deldir->name) < 0) {
		perror("rmdir");
		exit(1);
	}
	unlock_file_writer(deldir);
}
예제 #3
0
void ffsb_createdir(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum)
{
	struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum);
	struct ffsb_file *newdir;
	randdata_t *rd = ft_get_randdata(ft);

	newdir = add_dir(bf, 0, rd);
	if (mkdir(newdir->name, S_IRWXU) < 0) {
		perror("mkdir");
		exit(1);
	}
	unlock_file_writer(newdir);

	ft_incr_op(ft, opnum, 1, 0);
}
예제 #4
0
파일: fileops.c 프로젝트: ystk/debian-ltp
static unsigned ffsb_createfile_core(ffsb_thread_t *ft, ffsb_fs_t *fs,
				     unsigned opnum, uint64_t *filesize_ret,
				     int fsync_file)
{
	struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum);
	struct ffsb_file *newfile = NULL;

	int fd;
	uint64_t size;

	char *buf = ft_getbuf(ft);
	uint32_t write_blocksize = ft_get_write_blocksize(ft);
	struct randdata *rd = ft_get_randdata(ft);
	unsigned iterations = 0;

	if (fs->num_weights) {
		int num = 1 + getrandom(rd, fs->sum_weights);
		int curop = 0;

		while (fs->size_weights[curop].weight < num) {
			num -= fs->size_weights[curop].weight;
			curop++;
		}
		size = fs->size_weights[curop].size;
	}
	else {
		uint64_t range = fs_get_max_filesize(fs) - fs_get_min_filesize(fs);
		size = fs_get_min_filesize(fs);
		if (range != 0)
			size += getllrandom(rd, range);
	}

	newfile = add_file(bf, size, rd);
	fd = fhopencreate(newfile->name, ft, fs);
	iterations = writefile_helper(fd, size, write_blocksize, buf, ft, fs);

	if (fsync_file)
 		if (fsync(fd)) {
 			perror("fsync");
 			printf("aborting\n");
 			exit(1);
 		}

	fhclose(fd, ft, fs);
	unlock_file_writer(newfile);
 	*filesize_ret = size;
	return iterations;
}
예제 #5
0
static void renamedir(struct benchfiles *dirs, randdata_t *rd)
{
	struct ffsb_file *dir;
	char *oldname;

	dir = choose_file_writer(dirs, rd);
	oldname = dir->name;
	rename_file(dir);

	if (rename(oldname, dir->name) < 0) {
		perror("rename");
		exit(1);
	}
	unlock_file_writer(dir);
	free(oldname);
}
예제 #6
0
파일: filelist.c 프로젝트: Mellanox/arc_ltp
/* Do all the dirty work of recursing through a directory structure
 * check everything for validitiy and update everything properly.
 * Note it does not check filesizes !!!, it doesn't know anything
 * about them
 */
static int add_dir_to_filelist(struct benchfiles *bf, DIR *subdir,
			       char *subdir_path, fl_validation_func_t vfunc,
			       void *vf_data)
{
	int retval = 0;
	struct dirent *d_ent = NULL;

	while ((d_ent = readdir(subdir)) != NULL) {
		DIR *tmp = NULL;
		char filename_buf[FILENAME_MAX*2];

		if (FILENAME_MAX < snprintf(filename_buf, FILENAME_MAX, "%s/%s",
					    subdir_path, d_ent->d_name)) {
			printf("filename \"%s\" too long aborting\n",
			       filename_buf);
			return -1;
		}
		tmp = opendir(filename_buf);
		if (tmp == NULL) {
			struct ffsb_file *ffsb_file = NULL;

			if (validate_filename(bf, d_ent->d_name) < 0) {
				printf("filename \"%s\" is invalid aborting\n",
				       d_ent->d_name);
				return -1;
			}
			/* Verify size/other attributes via callback  */
			if (vfunc(bf, filename_buf, vf_data)) {
				printf("filename \"%s\" didn't pass "
				       "validation\n", d_ent->d_name);
				return -1;
			}
			/* Add file to data structure */
			ffsb_file = add_file_named(bf, ffsb_get_filesize(filename_buf),
				       filename_buf);
			unlock_file_writer(ffsb_file);
		} else {
			/* Check for the usual suspects and skip them */
			if ((0 == strcmp(".", d_ent->d_name)) ||
			    (0 == strcmp("..", d_ent->d_name))) {
				closedir(tmp);
				continue;
			}
			if (validate_dirname(bf, d_ent->d_name) < 0) {
				printf("dirname \"%s\" is invalid aborting\n",
				       d_ent->d_name);
				closedir(tmp);
				return -1;
			}
			if (vfunc(bf, filename_buf, vf_data)) {
				printf("dir \"%s\" didn't pass validation\n",
				       d_ent->d_name);
				closedir(tmp);
				return -1;
			}
			/* Update filelist */
			bf->numsubdirs++;

			/* recurse */
			retval += add_dir_to_filelist(bf, tmp, filename_buf,
						      vfunc, vf_data);

			/* clean up */
			closedir(tmp);
		}
	}
	return retval;
}