示例#1
0
/*
 * task_pmemlog_append -- appends to the log in the PMEM mode
 */
int
task_pmemlog_append(void *arg)
{
	int32_t rand_number;
	struct thread_info *thread_info = arg;
	size_t vec_size = thread_info->vec_size;
	size_t el_size = thread_info->el_size;
	PMEMlog *plp = (PMEMlog *)thread_info->hndl;

	if (thread_info->rand_state != NULL) {
		random_r(thread_info->rand_state, &rand_number);
		vec_size = rand_number % vec_size + MIN_VEC_SIZE;
		el_size = rand_number % el_size + MIN_EL_SIZE;
	};

	/* check vector size */
	if (vec_size > 1) {
		for (int i = 0; i < vec_size; ++i) {
			thread_info->iov[i].iov_base =
					&thread_info->buf[i * el_size];
			thread_info->iov[i].iov_len = el_size;
		}

		if (pmemlog_appendv(plp, thread_info->iov, vec_size) < 0) {
			return EXIT_FAILURE;
		}
	} else {
		if (pmemlog_append(plp, thread_info->buf, el_size) < 0) {
			return EXIT_FAILURE;
		}
	}

	return EXIT_SUCCESS;
}
示例#2
0
文件: log.cpp 项目: ChandKV/nvml
/*
 * log_appendv -- performs pmemlog_appendv operation
 */
static int
log_appendv(struct benchmark *bench, struct operation_info *info)
{
	struct log_bench *lb = (struct log_bench *)pmembench_get_priv(bench);
	assert(lb);

	struct log_worker_info *worker_info =
		(struct log_worker_info *)info->worker->priv;

	assert(worker_info);

	struct iovec *iov = &worker_info->iov[info->index * lb->args->vec_size];

	if (pmemlog_appendv(lb->plp, iov, lb->args->vec_size) < 0) {
		perror("pmemlog_appendv");
		return -1;
	}

	return 0;
}
示例#3
0
文件: addlog.c 项目: harrybaa/nvml
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);
}
示例#4
0
        },
        {
            .iov_base = "7th test string\n",
            .iov_len = 16
        },
        {
            .iov_base = "8th test string\n",
            .iov_len = 16
        },
        {
            .iov_base = "9th test string\n",
            .iov_len = 16
        }
    };

    int rv = pmemlog_appendv(plp, iov, 9);
    switch (rv) {
    case 0:
        OUT("appendv");
        break;
    case -1:
        OUT("!appendv");
        break;
    default:
        OUT("!appendv: wrong return value");
        break;
    }
}

/*
 * do_tell -- call pmemlog_tell() & print result
示例#5
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;
}