예제 #1
0
파일: blk_pool.c 프로젝트: dardevelin/nvml
static void
pool_open(const char *path, size_t bsize)
{
	PMEMblkpool *pbp = pmemblk_open(path, bsize);
	if (pbp == NULL)
		UT_OUT("!%s: pmemblk_open", path);
	else {
		UT_OUT("%s: pmemblk_open: Success", path);
		pmemblk_close(pbp);
	}
}
예제 #2
0
int
main(int argc, char *argv[])
{
	PMEMblkpool *pbp;
	struct asset asset;
	int assetid;

	if (argc < 4) {
		fprintf(stderr, "usage: %s assetdb asset-ID name\n", argv[0]);
		exit(1);
	}

	const char *path = argv[1];
	assetid = atoi(argv[2]);

	/* open an array of atomically writable elements */
	if ((pbp = pmemblk_open(path, sizeof (struct asset))) == NULL) {
		perror("pmemblk_open");
		exit(1);
	}

	/* read a required element in */
	if (pmemblk_read(pbp, &asset, (off_t)assetid) < 0) {
		perror("pmemblk_read");
		exit(1);
	}

	/* check if it contains any data */
	if ((asset.state != ASSET_FREE) &&
		(asset.state != ASSET_CHECKED_OUT)) {
		fprintf(stderr, "Asset ID %d not found", assetid);
		exit(1);
	}

	if (asset.state == ASSET_CHECKED_OUT) {
		fprintf(stderr, "Asset ID %d already checked out\n", assetid);
		exit(1);
	}

	/* update user name, set checked out state, and take timestamp */
	strncpy(asset.user, argv[3], ASSET_USER_NAME_MAX - 1);
	asset.user[ASSET_USER_NAME_MAX - 1] = '\0';
	asset.state = ASSET_CHECKED_OUT;
	time(&asset.time);

	/* put it back in the block */
	if (pmemblk_write(pbp, &asset, assetid) < 0) {
		perror("pmemblk_write");
		exit(1);
	}

	pmemblk_close(pbp);
}
예제 #3
0
파일: asset_list.c 프로젝트: ChandKV/nvml
int
main(int argc, char *argv[])
{
	PMEMblkpool *pbp;
	int assetid;
	size_t nelements;
	struct asset asset;

	if (argc < 2) {
		fprintf(stderr, "usage: %s assetdb\n", argv[0]);
		exit(1);
	}

	const char *path = argv[1];

	/* open an array of atomically writable elements */
	if ((pbp = pmemblk_open(path, sizeof(struct asset))) == NULL) {
		perror(path);
		exit(1);
	}

	/* how many elements do we have? */
	nelements = pmemblk_nblock(pbp);

	/* print out all the elements that contain assets data */
	for (assetid = 0; assetid < nelements; ++assetid) {
		if (pmemblk_read(pbp, &asset, assetid) < 0) {
			perror("pmemblk_read");
			exit(1);
		}

		if ((asset.state != ASSET_FREE) &&
			(asset.state != ASSET_CHECKED_OUT)) {
			break;
		}

		printf("Asset ID: %d\n", assetid);
		if (asset.state == ASSET_FREE)
			printf("   State: Free\n");
		else {
			printf("   State: Checked out\n");
			printf("    User: %s\n", asset.user);
			printf("    Time: %s", ctime(&asset.time));
		}
		printf("    Name: %s\n", asset.name);
	}

	pmemblk_close(pbp);
}
예제 #4
0
int
main(int argc, char *argv[])
{
	PMEMblkpool *pbp;
	struct asset asset;
	int assetid;

	if (argc < 3) {
		fprintf(stderr, "usage: %s assetdb asset-ID\n", argv[0]);
		exit(1);
	}

	const char *path = argv[1];
	assetid = atoi(argv[2]);
	assert(assetid > 0);

	/* open an array of atomically writable elements */
	if ((pbp = pmemblk_open(path, sizeof(struct asset))) == NULL) {
		perror("pmemblk_open");
		exit(1);
	}

	/* read a required element in */
	if (pmemblk_read(pbp, &asset, assetid) < 0) {
		perror("pmemblk_read");
		exit(1);
	}

	/* check if it contains any data */
	if ((asset.state != ASSET_FREE) &&
		(asset.state != ASSET_CHECKED_OUT)) {
		fprintf(stderr, "Asset ID %d not found\n", assetid);
		exit(1);
	}

	/* change state to free, clear user name and timestamp */
	asset.state = ASSET_FREE;
	asset.user[0] = '\0';
	asset.time = 0;

	if (pmemblk_write(pbp, &asset, assetid) < 0) {
		perror("pmemblk_write");
		exit(1);
	}

	pmemblk_close(pbp);
}
예제 #5
0
파일: blk_nblock.c 프로젝트: Neuvenen/nvml
int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_nblock");

	if (argc < 2)
		FATAL("usage: %s bsize:file...", argv[0]);

	/* map each file argument with the given map type */
	for (int arg = 1; arg < argc; arg++) {
		char *fname;
		size_t bsize = strtoul(argv[arg], &fname, 0);
		if (*fname != ':')
			FATAL("usage: %s bsize:file...", argv[0]);
		fname++;

		PMEMblkpool *handle;
		handle = pmemblk_create(fname, bsize, 0, S_IWUSR | S_IRUSR);
		if (handle == NULL) {
			OUT("!%s: pmemblk_create", fname);
		} else {
			OUT("%s: block size %zu usable blocks: %zu",
					fname, bsize, pmemblk_nblock(handle));
			ASSERTeq(pmemblk_bsize(handle), bsize);
			pmemblk_close(handle);
			int result = pmemblk_check(fname, bsize);
			if (result < 0)
				OUT("!%s: pmemblk_check", fname);
			else if (result == 0)
				OUT("%s: pmemblk_check: not consistent", fname);
			else {
				ASSERTeq(pmemblk_check(fname, bsize + 1), -1);
				ASSERTeq(pmemblk_check(fname, 0), 1);

				handle = pmemblk_open(fname, 0);
				ASSERTeq(pmemblk_bsize(handle), bsize);
				pmemblk_close(handle);
			}
		}
	}

	DONE(NULL);
}
예제 #6
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_non_zero");

	if (argc < 5)
		UT_FATAL("usage: %s bsize file func [file_size] op:lba...",
				argv[0]);

	int read_arg = 1;

	Bsize = strtoul(argv[read_arg++], NULL, 0);

	const char *path = argv[read_arg++];

	PMEMblkpool *handle = NULL;
	switch (*argv[read_arg++]) {
		case 'c': {
			size_t fsize = strtoul(argv[read_arg++], NULL, 0);
			handle = pmemblk_create(path, Bsize, fsize,
					S_IRUSR | S_IWUSR);
			if (handle == NULL)
				UT_FATAL("!%s: pmemblk_create", path);
			break;
		}
		case 'o':
			handle = pmemblk_open(path, Bsize);
			if (handle == NULL)
				UT_FATAL("!%s: pmemblk_open", path);
			break;
		default:
			UT_FATAL("unrecognized command %s", argv[read_arg - 1]);
	}

	UT_OUT("%s block size %zu usable blocks %zu",
			argv[1], Bsize, pmemblk_nblock(handle));

	UT_OUT("is zeroed:\t%d", is_zeroed(path));

	/* map each file argument with the given map type */
	for (; read_arg < argc; read_arg++) {
		if (strchr("rwze", argv[read_arg][0]) == NULL ||
				argv[read_arg][1] != ':')
			UT_FATAL("op must be r: or w: or z: or e:");
		off_t lba = strtoul(&argv[read_arg][2], NULL, 0);

		unsigned char buf[Bsize];

		switch (argv[read_arg][0]) {
		case 'r':
			if (pmemblk_read(handle, buf, lba) < 0)
				UT_OUT("!read      lba %zu", lba);
			else
				UT_OUT("read      lba %zu: %s", lba,
						ident(buf));
			break;

		case 'w':
			construct(buf);
			if (pmemblk_write(handle, buf, lba) < 0)
				UT_OUT("!write     lba %zu", lba);
			else
				UT_OUT("write     lba %zu: %s", lba,
						ident(buf));
			break;

		case 'z':
			if (pmemblk_set_zero(handle, lba) < 0)
				UT_OUT("!set_zero  lba %zu", lba);
			else
				UT_OUT("set_zero  lba %zu", lba);
			break;

		case 'e':
			if (pmemblk_set_error(handle, lba) < 0)
				UT_OUT("!set_error lba %zu", lba);
			else
				UT_OUT("set_error lba %zu", lba);
			break;
		}
	}

	pmemblk_close(handle);

	int result = pmemblk_check(path, Bsize);
	if (result < 0)
		UT_OUT("!%s: pmemblk_check", path);
	else if (result == 0)
		UT_OUT("%s: pmemblk_check: not consistent", path);

	DONE(NULL);
}
예제 #7
0
파일: pmemblk.c 프로젝트: cronburg/fio
static fio_pmemblk_file_t pmb_open(const char *pathspec, int flags)
{
	fio_pmemblk_file_t pmb;
	char *path = NULL;
	uint64_t bsize = 0;
	uint64_t fsize = 0;

	pmb_parse_path(pathspec, &path, &bsize, &fsize);
	if (!path)
		return NULL;

	pthread_mutex_lock(&CacheLock);

	pmb = fio_pmemblk_cache_lookup(path);
	if (!pmb) {
		/* load libpmemblk if needed */
		if (!pmemblk_open)
			if (load_libpmemblk(getenv("FIO_PMEMBLK_LIB")))
				goto error;

		pmb = malloc(sizeof(*pmb));
		if (!pmb)
			goto error;

		/* try opening existing first, create it if needed */
		pmb->pmb_pool = pmemblk_open(path, bsize);
		if (!pmb->pmb_pool && (errno == ENOENT) &&
		    (flags & PMB_CREATE) && (0 < fsize) && (0 < bsize)) {
			pmb->pmb_pool =
			    pmemblk_create(path, bsize, fsize, 0644);
		}
		if (!pmb->pmb_pool) {
			log_err
			    ("fio: enable to open pmemblk pool file (errno %d)\n",
			     errno);
			goto error;
		}

		pmb->pmb_filename = path;
		pmb->pmb_next = NULL;
		pmb->pmb_refcnt = 0;
		pmb->pmb_bsize = pmemblk_bsize(pmb->pmb_pool);
		pmb->pmb_nblocks = pmemblk_nblock(pmb->pmb_pool);

		fio_pmemblk_cache_insert(pmb);
	}

	pmb->pmb_refcnt += 1;

	pthread_mutex_unlock(&CacheLock);

	return pmb;

error:
	if (pmb) {
		if (pmb->pmb_pool)
			pmemblk_close(pmb->pmb_pool);
		pmb->pmb_pool = NULL;
		pmb->pmb_filename = NULL;
		free(pmb);
	}
	if (path)
		free(path);

	pthread_mutex_unlock(&CacheLock);
	return NULL;
}
예제 #8
0
파일: blk_rw.c 프로젝트: Skyprophet/peloton
int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_rw");

	if (argc < 5)
		FATAL("usage: %s bsize file func op:lba...", argv[0]);

	Bsize = strtoul(argv[1], NULL, 0);

	const char *path = argv[2];

	PMEMblkpool *handle;
	switch (*argv[3]) {
		case 'c':
			handle = pmemblk_create(path, Bsize, 0,
					S_IWUSR | S_IRUSR);
			if (handle == NULL)
				FATAL("!%s: pmemblk_create", path);
			break;
		case 'o':
			handle = pmemblk_open(path, Bsize);
			if (handle == NULL)
				FATAL("!%s: pmemblk_open", path);
			break;
	}

	OUT("%s block size %zu usable blocks %zu",
			argv[1], Bsize, pmemblk_nblock(handle));

	/* map each file argument with the given map type */
	for (int arg = 4; arg < argc; arg++) {
		if (strchr("rwze", argv[arg][0]) == NULL || argv[arg][1] != ':')
			FATAL("op must be r: or w: or z: or e:");
		off_t lba = strtol(&argv[arg][2], NULL, 0);

		unsigned char buf[Bsize];

		switch (argv[arg][0]) {
		case 'r':
			if (pmemblk_read(handle, buf, lba) < 0)
				OUT("!read      lba %jd", lba);
			else
				OUT("read      lba %jd: %s", lba, ident(buf));
			break;

		case 'w':
			construct(buf);
			if (pmemblk_write(handle, buf, lba) < 0)
				OUT("!write     lba %jd", lba);
			else
				OUT("write     lba %jd: %s", lba, ident(buf));
			break;

		case 'z':
			if (pmemblk_set_zero(handle, lba) < 0)
				OUT("!set_zero  lba %jd", lba);
			else
				OUT("set_zero  lba %jd", lba);
			break;

		case 'e':
			if (pmemblk_set_error(handle, lba) < 0)
				OUT("!set_error lba %jd", lba);
			else
				OUT("set_error lba %jd", lba);
			break;
		}
	}

	pmemblk_close(handle);

	int result = pmemblk_check(path, Bsize);
	if (result < 0)
		OUT("!%s: pmemblk_check", path);
	else if (result == 0)
		OUT("%s: pmemblk_check: not consistent", path);

	DONE(NULL);
}
예제 #9
0
파일: blk_mt.c 프로젝트: KaiZhang666/nvml
int
main(int argc, char *argv[])
{
	struct blk_arguments arguments;

	/* set the random seed value */
	srand(time(NULL));

	/* set default values */
	memset(&arguments, 0, sizeof (struct blk_arguments));
	arguments.block_size = 512;
	arguments.num_ops = 100;
	arguments.file_size = (PMEMBLK_MIN_POOL / 1024) / 1024;

	if (argp_parse(&argp, argc, argv, 0, 0, &arguments) != 0) {
		exit(1);
	}

	struct worker_info worker_params[arguments.thread_count];
	memset(worker_params, 0, sizeof (struct worker_info));

	/* set common values */
	worker_params[0].block_size = arguments.block_size;
	worker_params[0].num_ops = arguments.num_ops;
	worker_params[0].file_lanes = arguments.thread_count;

	/* file_size is provided in MB */
	unsigned long long file_size_bytes = arguments.file_size * 1024 * 1024;

	worker *thread_workers = NULL;

	/* prepare parameters specific for file/pmem */
	if (arguments.file_io) {
		/* prepare open flags */
		int flags = O_RDWR | O_CREAT | O_SYNC;
		/* create file on PMEM-aware file system */
		if ((worker_params[0].file_desc = open(arguments.file_path,
			flags, FILE_MODE)) < 0) {
			perror(arguments.file_path);
			exit(1);
		}

		/* pre-allocate file_size MB of persistent memory */
		if ((errno = posix_fallocate(worker_params[0].file_desc,
			(off_t)0, (off_t)file_size_bytes)) != 0) {
			warn("posix_fallocate");
			close(worker_params[0].file_desc);
			exit(1);
		}

		worker_params[0].num_blocks = file_size_bytes
				/ worker_params[0].block_size;
		thread_workers = file_workers;
	} else {
		worker_params[0].file_desc = -1;
		if (arguments.prep_blk_file) {
			if ((worker_params[0].handle = pmemblk_create(
				arguments.file_path,
				worker_params[0].block_size,
				(off_t)file_size_bytes, FILE_MODE)) == NULL) {
				err(1, "%s: pmemblk_open", argv[2]);
			}
		} else {
			if ((worker_params[0].handle = pmemblk_open(
					arguments.file_path,
					worker_params[0].block_size)) == NULL) {
				err(1, "%s: pmemblk_open", argv[2]);
			}

		}
		worker_params[0].num_blocks = pmemblk_nblock(
				worker_params[0].handle);
		thread_workers = pmem_workers;
	}

	/* propagate params to each info_t */
	for (int i = 1; i < arguments.thread_count; ++i) {
		memcpy(&worker_params[i], &worker_params[0],
				sizeof (struct worker_info));
		worker_params[i].thread_index = i;
		worker_params[i].seed = rand();
	}

	/* The blk mode file prep */
	if (arguments.prep_blk_file) {
		if (worker_params[0].file_desc >= 0)
			close(worker_params[0].file_desc);
		return run_threads(prep_worker, arguments.thread_count,
				worker_params);
	}

	struct measurements perf_meas;
	perf_meas.total_ops = arguments.thread_count
			* worker_params[0].num_ops;

	/* perform PMEMBLK warmup */
	if (!arguments.file_io) {
		if (run_threads(warmup_worker, arguments.thread_count,
				worker_params) != 0) {
			if (worker_params[0].file_desc >= 0)
				close(worker_params[0].file_desc);
			exit(1);
		}
	}

	for (int i = 0; i < WORKER_COUNT_MAX; ++i) {
		clock_gettime(CLOCK_MONOTONIC, &perf_meas.start_time);
		if (run_threads(thread_workers[i], arguments.thread_count,
				worker_params) != 0) {
			if (worker_params[0].file_desc >= 0)
				close(worker_params[0].file_desc);
			exit(1);
		}
		clock_gettime(CLOCK_MONOTONIC, &perf_meas.stop_time);

		calculate_stats(&perf_meas);
		printf("%f;%f;", perf_meas.total_run_time,
				perf_meas.ops_per_second);
	}

	printf("\n");

	if (worker_params[0].file_desc >= 0)
		close(worker_params[0].file_desc);

	/* cleanup and check pmem file */
	if (!arguments.file_io) {
		pmemblk_close(worker_params[0].handle);

		/* not really necessary, but check consistency */
		int result = pmemblk_check(arguments.file_path);
		if (result < 0) {
			warn("%s: pmemblk_check",
					arguments.file_path);
		} else if (result == 0) {
			warnx("%s: pmemblk_check: not consistent",
					arguments.file_path);
		}
	}

	exit(0);
}