/* * log_read_op -- perform read operation */ static int log_read_op(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); worker_info->buf_ptr = 0; size_t chunk_size = lb->args->rand ? worker_info->rand_sizes[info->index] : lb->args->el_size; if (!lb->args->fileio) { pmemlog_walk(lb->plp, chunk_size, log_process_data, worker_info); return 0; } int ret; while ((ret = fileio_read(lb->fd, chunk_size, worker_info)) == 1) ; return ret; }
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); }
/* * task_pmemlog_read -- reads from the log in the PMEM mode */ int task_pmemlog_read(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; thread_info->buf_ptr = 0; 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; } pmemlog_walk(plp, vec_size * el_size, process_data, arg); return EXIT_SUCCESS; }
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); }
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; }
/* * do_walk -- call pmemlog_walk() & print result */ static void do_walk(PMEMlogpool *plp) { pmemlog_walk(plp, 0, try_to_store, NULL); UT_OUT("walk all at once"); }