Exemplo n.º 1
0
static void
test_reopen(const char *path)
{
	PMEMlogpool *log1 = pmemlog_create(path, PMEMLOG_MIN_POOL,
			S_IWUSR | S_IRUSR);
	if (!log1)
		FATAL("!create");

	PMEMlogpool *log2 = pmemlog_open(path);
	if (log2)
		FATAL("pmemlog_open should not succeed");

	if (errno != EWOULDBLOCK)
		FATAL("!pmemlog_open failed but for unexpected reason");

	pmemlog_close(log1);

	log2 = pmemlog_open(path);
	if (!log2)
		FATAL("pmemlog_open should succeed after close");

	pmemlog_close(log2);

	UNLINK(path);
}
Exemplo n.º 2
0
static void
pool_create(const wchar_t *path, size_t poolsize, unsigned mode)
{
	char *upath = ut_toUTF8(path);
	PMEMlogpool *plp = pmemlog_createW(path, poolsize, mode);

	if (plp == NULL)
		UT_OUT("!%s: pmemlog_create", upath);
	else {
		os_stat_t stbuf;
		STATW(path, &stbuf);

		UT_OUT("%s: file size %zu usable space %zu mode 0%o",
			upath, stbuf.st_size,
				pmemlog_nbyte(plp),
				stbuf.st_mode & 0777);

		pmemlog_close(plp);

		int result = pmemlog_checkW(path);

		if (result < 0)
			UT_OUT("!%s: pmemlog_check", upath);
		else if (result == 0)
			UT_OUT("%s: pmemlog_check: not consistent", upath);
	}
	free(upath);
}
Exemplo n.º 3
0
Arquivo: log.c Projeto: harrybaa/nvml
/*
 * pmemlog_check -- log memory pool consistency check
 *
 * Returns true if consistent, zero if inconsistent, -1/error if checking
 * cannot happen due to other errors.
 */
int
pmemlog_check(const char *path)
{
    LOG(3, "path \"%s\"", path);

    size_t poolsize = 0;
    int fd;

    if ((fd = util_pool_open(path, &poolsize, PMEMLOG_MIN_POOL)) == -1)
        return -1;	/* errno set by util_pool_open() */

    /* map the pool read-only */
    PMEMlogpool *plp = pmemlog_map_common(fd, poolsize, 1, 0);

    if (plp == NULL)
        return -1;	/* errno set by pmemlog_map_common() */

    int consistent = 1;

    /* validate pool descriptor */
    uint64_t hdr_start = le64toh(plp->start_offset);
    uint64_t hdr_end = le64toh(plp->end_offset);
    uint64_t hdr_write = le64toh(plp->write_offset);

    if (hdr_start != roundup(sizeof (*plp), LOG_FORMAT_DATA_ALIGN)) {
        ERR("wrong value of start_offset");
        consistent = 0;
    }

    if (hdr_end != plp->size) {
        ERR("wrong value of end_offset");
        consistent = 0;
    }

    if (hdr_start > hdr_end) {
        ERR("start_offset greater than end_offset");
        consistent = 0;
    }

    if (hdr_start > hdr_write) {
        ERR("start_offset greater than write_offset");
        consistent = 0;
    }

    if (hdr_write > hdr_end) {
        ERR("write_offset greater than end_offset");
        consistent = 0;
    }

    pmemlog_close(plp);

    if (consistent)
        LOG(4, "pool consistency check OK");

    return consistent;
}
Exemplo n.º 4
0
static void
pool_open(const wchar_t *path)
{
	char *upath = ut_toUTF8(path);

	PMEMlogpool *plp = pmemlog_openW(path);
	if (plp == NULL)
		UT_OUT("!%s: pmemlog_open", upath);
	else {
		UT_OUT("%s: pmemlog_open: Success", upath);
		pmemlog_close(plp);
	}
	free(upath);
}
Exemplo n.º 5
0
Arquivo: log.cpp Projeto: ChandKV/nvml
/*
 * log_exit -- cleanup benchmark
 */
static int
log_exit(struct benchmark *bench, struct benchmark_args *args)
{
	struct log_bench *lb = (struct log_bench *)pmembench_get_priv(bench);

	if (!lb->args->fileio)
		pmemlog_close(lb->plp);
	else
		close(lb->fd);

	free(lb);

	return 0;
}
Exemplo n.º 6
0
/*
 * pmemlog_check -- log memory pool consistency check
 *
 * Returns true if consistent, zero if inconsistent, -1/error if checking
 * cannot happen due to other errors.
 */
int
pmemlog_check(const char *path)
{
    LOG(3, "path \"%s\"", path);

    PMEMlogpool *plp = pmemlog_open_common(path, 1);
    if (plp == NULL)
        return -1;	/* errno set by pmemlog_open_common() */

    int consistent = 1;

    /* validate pool descriptor */
    uint64_t hdr_start = le64toh(plp->start_offset);
    uint64_t hdr_end = le64toh(plp->end_offset);
    uint64_t hdr_write = le64toh(plp->write_offset);

    if (hdr_start != roundup(sizeof(*plp), LOG_FORMAT_DATA_ALIGN)) {
        ERR("wrong value of start_offset");
        consistent = 0;
    }

    if (hdr_end != plp->size) {
        ERR("wrong value of end_offset");
        consistent = 0;
    }

    if (hdr_start > hdr_end) {
        ERR("start_offset greater than end_offset");
        consistent = 0;
    }

    if (hdr_start > hdr_write) {
        ERR("start_offset greater than write_offset");
        consistent = 0;
    }

    if (hdr_write > hdr_end) {
        ERR("write_offset greater than end_offset");
        consistent = 0;
    }

    pmemlog_close(plp);

    if (consistent)
        LOG(4, "pool consistency check OK");

    return consistent;
}
Exemplo n.º 7
0
static void
test_open_in_different_process(const char *path, int sleep)
{
	pid_t pid = fork();
	PMEMlogpool *log;

	if (pid < 0)
		FATAL("fork failed");

	if (pid == 0) {
		/* child */
		if (sleep)
			usleep(sleep);
		while (access(path, R_OK))
			usleep(100 * 1000);

		log = pmemlog_open(path);
		if (log)
			FATAL("pmemlog_open after fork should not succeed");

		if (errno != EWOULDBLOCK)
			FATAL("!pmemlog_open after fork failed but for "
				"unexpected reason");

		exit(0);
	}

	log = pmemlog_create(path, PMEMLOG_MIN_POOL, S_IWUSR | S_IRUSR);
	if (!log)
		FATAL("!create");

	int status;

	if (waitpid(pid, &status, 0) < 0)
		FATAL("!waitpid failed");

	if (!WIFEXITED(status))
		FATAL("child process failed");

	pmemlog_close(log);

	UNLINK(path);
}
Exemplo n.º 8
0
int
main(int argc, char *argv[])
{
	PMEMlogpool *plp;

	START(argc, argv, "log_walker");

	if (argc != 2)
		UT_FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	int fd = OPEN(path, O_RDWR);

	/* pre-allocate 2MB of persistent memory */
	errno = posix_fallocate(fd, (off_t)0, (size_t)(2 * 1024 * 1024));
	if (errno != 0)
		UT_FATAL("!posix_fallocate");

	CLOSE(fd);

	if ((plp = pmemlog_create(path, 0, S_IWUSR | S_IRUSR)) == NULL)
		UT_FATAL("!pmemlog_create: %s", path);

	/* append some data */
	do_append(plp);

	/* arrange to catch SEGV */
	struct sigaction v;
	sigemptyset(&v.sa_mask);
	v.sa_flags = 0;
	v.sa_handler = signal_handler;
	SIGACTION(SIGSEGV, &v, NULL);

	if (!sigsetjmp(Jmp, 1)) {
		do_walk(plp);
	}

	pmemlog_close(plp);

	DONE(NULL);
}
Exemplo n.º 9
0
int
main(int argc, char *argv[])
{
	const char path[] = "/pmem-fs/myfile";
	PMEMlogpool *plp;
	size_t nbyte;
	char *str;

	/* create the pmemlog pool or open it if it already exists */
	plp = pmemlog_create(path, POOL_SIZE, 0666);

	if (plp == NULL)
	    plp = pmemlog_open(path);

	if (plp == NULL) {
		perror(path);
		exit(1);
	}

	/* how many bytes does the log hold? */
	nbyte = pmemlog_nbyte(plp);
	printf("log holds %zu bytes\n", nbyte);

	/* append to the log... */
	str = "This is the first string appended\n";
	if (pmemlog_append(plp, str, strlen(str)) < 0) {
		perror("pmemlog_append");
		exit(1);
	}
	str = "This is the second string appended\n";
	if (pmemlog_append(plp, str, strlen(str)) < 0) {
		perror("pmemlog_append");
		exit(1);
	}

	/* print the log contents */
	printf("log contains:\n");
	pmemlog_walk(plp, 0, printit, NULL);

	pmemlog_close(plp);
}
Exemplo n.º 10
0
int
main(int argc, char *argv[])
{
	int opt;
	int tflag = 0;
	PMEMlogpool *plp;

	while ((opt = getopt(argc, argv, "t")) != -1)
		switch (opt) {
		case 't':
			tflag = 1;
			break;

		default:
			fprintf(stderr, "usage: %s [-t] file\n", argv[0]);
			exit(1);
		}

	if (optind >= argc) {
		fprintf(stderr, "usage: %s [-t] file\n", argv[0]);
		exit(1);
	}

	const char *path = argv[optind];

	if ((plp = pmemlog_open(path)) == NULL) {
		perror(path);
		exit(1);
	}

	/* the rest of the work happens in printlog() above */
	pmemlog_walk(plp, 0, printlog, NULL);

	if (tflag)
		pmemlog_rewind(plp);

	pmemlog_close(plp);
}
Exemplo n.º 11
0
int
main(int argc, char *argv[])
{
	PMEMlogpool *plp;
	struct logentry header;
	struct iovec *iovp;
	struct iovec *next_iovp;
	int iovcnt;

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

	const char *path = argv[1];

	/* create the log in the given file, or open it if already created */
	if ((plp = pmemlog_create(path, 0, S_IWUSR | S_IRUSR)) == NULL &&
	    (plp = pmemlog_open(path)) == NULL) {
		perror(path);
		exit(1);
	}

	/* fill in the header */
	time(&header.timestamp);
	header.pid = getpid();

	/*
	 * Create an iov for pmemlog_appendv().  For each argument given,
	 * allocate two entries (one for the string, one for the newline
	 * appended to the string).  Allocate 1 additional entry for the
	 * header that gets prepended to the entry.
	 */
	iovcnt = (argc - 2) * 2 + 1;
	if ((iovp = malloc(sizeof (*iovp) * iovcnt)) == NULL) {
		perror("malloc");
		exit(1);
	}
	next_iovp = iovp;

	/* put the header into iov first */
	next_iovp->iov_base = &header;
	next_iovp->iov_len = sizeof (header);
	next_iovp++;

	/*
	 * Now put each arg in, following it with the string "\n".
	 * Calculate a total character count in header.len along the way.
	 */
	header.len = 0;
	for (int arg = 2; arg < argc; arg++) {
		/* add the string given */
		next_iovp->iov_base = argv[arg];
		next_iovp->iov_len = strlen(argv[arg]);
		header.len += next_iovp->iov_len;
		next_iovp++;

		/* add the newline */
		next_iovp->iov_base = "\n";
		next_iovp->iov_len = 1;
		header.len += 1;
		next_iovp++;
	}

	/* atomically add it all to the log */
	if (pmemlog_appendv(plp, iovp, iovcnt) < 0) {
		perror("pmemlog_appendv");
		exit(1);
	}

	pmemlog_close(plp);
}
Exemplo n.º 12
0
int
main(int argc, char *argv[])
{

	if (argc < 2) {
		fprintf(stderr, "usage: %s [o,c] file [val...]", argv[0]);
		return 1;
	}

	PMEMlogpool *plp;
	if (strncmp(argv[1], "c", 1) == 0) {
		plp = pmemlog_create(argv[2], POOL_SIZE, S_IRUSR | S_IWUSR);
	} else if (strncmp(argv[1], "o", 1) == 0) {
		plp = pmemlog_open(argv[2]);
	} else {
		fprintf(stderr, "usage: %s [o,c] file [val...]", argv[0]);
		return 1;
	}

	if (plp == NULL) {
		perror("pmemlog_create/pmemlog_open");
		return 1;
	}

	/* process the command line arguments */
	for (int i = 3; i < argc; i++) {
		switch (*argv[i]) {
			case 'a': {
				printf("append: %s\n", argv[i] + 2);
				pmemlog_append(plp, argv[i] + 2,
					strlen(argv[i] + 2));
				break;
			}
			case 'v': {
				printf("appendv: %s\n", argv[i] + 2);
				int count = count_iovec(argv[i] + 2);
				struct iovec *iov = malloc(count
						* sizeof (struct iovec));
				fill_iovec(iov, argv[i] + 2);
				pmemlog_appendv(plp, iov, count);
				free(iov);
				break;
			}
			case 'r': {
				printf("rewind\n");
				pmemlog_rewind(plp);
				break;
			}
			case 'w': {
				printf("walk\n");
				pmemlog_walk(plp, 0, process_chunk, NULL);
				break;
			}
			case 'n': {
				printf("nbytes: %zu\n", pmemlog_nbyte(plp));
				break;
			}
			case 't': {
				printf("offset: %ld\n", pmemlog_tell(plp));
				break;
			}
			default: {
				fprintf(stderr, "unrecognized command %s\n",
					argv[i]);
				break;
			}
		};
	}

	/* all done */
	pmemlog_close(plp);

	return 0;
}
Exemplo n.º 13
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "out_err_mt");

	if (argc != 5)
		UT_FATAL("usage: %s filename1 filename2 filename3 dir",
				argv[0]);

	PMEMobjpool *pop = pmemobj_create(argv[1], "test",
		PMEMOBJ_MIN_POOL, 0666);
	PMEMlogpool *plp = pmemlog_create(argv[2],
		PMEMLOG_MIN_POOL, 0666);
	PMEMblkpool *pbp = pmemblk_create(argv[3],
		128, PMEMBLK_MIN_POOL, 0666);
#ifndef _WIN32
	/* XXX - vmem not implemented in windows yet */
	VMEM *vmp = vmem_create(argv[4], VMEM_MIN_POOL);
#endif

	util_init();

	pmem_check_version(10000, 0);
	pmemobj_check_version(10001, 0);
	pmemlog_check_version(10002, 0);
	pmemblk_check_version(10003, 0);
#ifndef _WIN32
	/* XXX - vmem not implemented in windows yet */
	vmem_check_version(10004, 0);
#endif
	pmempool_check_version(10005, 0);
	print_errors("version check");

	void *ptr = NULL;
	/*
	 * We are testing library error reporting and we don't want this test
	 * to fail under memcheck.
	 */
	VALGRIND_DO_DISABLE_ERROR_REPORTING;
	pmem_msync(ptr, 1);
	VALGRIND_DO_ENABLE_ERROR_REPORTING;
	print_errors("pmem_msync");

	pmemlog_append(plp, NULL, PMEMLOG_MIN_POOL);
	print_errors("pmemlog_append");

	size_t nblock = pmemblk_nblock(pbp);
	pmemblk_set_error(pbp, nblock + 1);
	print_errors("pmemblk_set_error");

#ifndef _WIN32
	/* XXX - vmem not implemented in windows yet */
	VMEM *vmp2 = vmem_create_in_region(NULL, 1);
	UT_ASSERTeq(vmp2, NULL);
	print_errors("vmem_create_in_region");
#endif

	run_mt_test(do_test);

	pmemobj_close(pop);
	pmemlog_close(plp);
	pmemblk_close(pbp);
#ifndef _WIN32
	/* XXX - vmem not implemented in windows yet */
	vmem_delete(vmp);
#endif

	PMEMpoolcheck *ppc;
	struct pmempool_check_args args = {0, };
	ppc = pmempool_check_init(&args, sizeof(args) / 2);
	UT_ASSERTeq(ppc, NULL);
	print_errors("pmempool_check_init");

	DONE(NULL);
}
Exemplo n.º 14
0
Arquivo: log.cpp Projeto: ChandKV/nvml
/*
 * log_init -- benchmark initialization function
 */
static int
log_init(struct benchmark *bench, struct benchmark_args *args)
{
	int ret = 0;
	assert(bench);
	assert(args != NULL);
	assert(args->opts != NULL);
	struct benchmark_info *bench_info;
	struct log_bench *lb =
		(struct log_bench *)malloc(sizeof(struct log_bench));

	if (!lb) {
		perror("malloc");
		return -1;
	}

	lb->args = (struct prog_args *)args->opts;
	lb->args->el_size = args->dsize;

	if (lb->args->vec_size == 0)
		lb->args->vec_size = 1;

	if (lb->args->rand && lb->args->min_size > lb->args->el_size) {
		errno = EINVAL;
		ret = -1;
		goto err_free_lb;
	}

	if (lb->args->rand && lb->args->min_size == lb->args->el_size)
		lb->args->rand = false;

	/* align pool size to ensure that we have enough usable space */
	lb->psize =
		MMAP_ALIGN_UP(POOL_HDR_SIZE +
			      args->n_ops_per_thread * args->n_threads *
				      lb->args->vec_size * lb->args->el_size);

	/* calculate a required pool size */
	if (lb->psize < PMEMLOG_MIN_POOL)
		lb->psize = PMEMLOG_MIN_POOL;

	if (args->is_poolset) {
		if (lb->psize > args->fsize) {
			fprintf(stderr, "insufficient size of poolset\n");
			ret = -1;
			goto err_free_lb;
		}

		lb->psize = 0;
	}

	bench_info = pmembench_get_info(bench);

	if (!lb->args->fileio) {
		if ((lb->plp = pmemlog_create(args->fname, lb->psize,
					      args->fmode)) == NULL) {
			perror("pmemlog_create");
			ret = -1;
			goto err_free_lb;
		}

		bench_info->operation =
			(lb->args->vec_size > 1) ? log_appendv : log_append;
	} else {
		int flags = O_CREAT | O_RDWR | O_SYNC;

		/* Create a file if it does not exist. */
		if ((lb->fd = open(args->fname, flags, args->fmode)) < 0) {
			perror(args->fname);
			ret = -1;
			goto err_free_lb;
		}

		/* allocate the pmem */
		if ((errno = posix_fallocate(lb->fd, 0, lb->psize)) != 0) {
			perror("posix_fallocate");
			ret = -1;
			goto err_close;
		}
		bench_info->operation = (lb->args->vec_size > 1)
			? fileio_appendv
			: fileio_append;
	}

	if (!lb->args->no_warmup) {
		size_t warmup_nops = args->n_threads * args->n_ops_per_thread;
		if (do_warmup(lb, warmup_nops)) {
			fprintf(stderr, "warmup failed\n");
			ret = -1;
			goto err_close;
		}
	}

	pmembench_set_priv(bench, lb);

	return 0;

err_close:
	if (lb->args->fileio)
		close(lb->fd);
	else
		pmemlog_close(lb->plp);
err_free_lb:
	free(lb);

	return ret;
}