int main(int argc, char *argv[]) { START(argc, argv, "obj_check"); if (argc < 2) { UT_FATAL("usage: obj_check file"); } const char *path = argv[1]; int ret = pmemobj_check(path, NULL); switch (ret) { case 1: UT_OUT("consistent"); break; case 0: UT_OUT("not consistent: %s", pmemobj_errormsg()); break; default: UT_OUT("error: %s", pmemobj_errormsg()); break; } DONE(NULL); }
int main(int argc, char *argv[]) { START(argc, argv, "obj_check"); if (argc < 2 || argc > 5) UT_FATAL("usage: obj_check <file> [-l <layout>] [-o]"); const char *path = argv[1]; const char *layout = NULL; PMEMobjpool *pop = NULL; int open = 0; for (int i = 2; i < argc; ++i) { if (strcmp(argv[i], "-o") == 0) open = 1; else if (strcmp(argv[i], "-l") == 0) { layout = argv[i + 1]; i++; } else UT_FATAL("Unrecognized argument: %s", argv[i]); } if (open) { pop = pmemobj_open(path, layout); if (pop == NULL) UT_OUT("!%s: pmemobj_open", path); else UT_OUT("%s: pmemobj_open: Success", path); } int ret = pmemobj_check(path, layout); switch (ret) { case 1: UT_OUT("consistent"); break; case 0: UT_OUT("not consistent: %s", pmemobj_errormsg()); break; default: UT_OUT("error: %s", pmemobj_errormsg()); break; } if (pop != NULL) pmemobj_close(pop); DONE(NULL); }
static void pool_create(const char *path, const char *layout, size_t poolsize, unsigned mode) { PMEMobjpool *pop = pmemobj_create(path, layout, poolsize, mode); if (pop == NULL) UT_OUT("!%s: pmemobj_create: %s", path, pmemobj_errormsg()); else { os_stat_t stbuf; STAT(path, &stbuf); UT_OUT("%s: file size %zu mode 0%o", path, stbuf.st_size, stbuf.st_mode & 0777); pmemobj_close(pop); int result = pmemobj_check(path, layout); if (result < 0) UT_OUT("!%s: pmemobj_check", path); else if (result == 0) UT_OUT("%s: pmemobj_check: not consistent", path); } }
int main(int argc, char *argv[]) { if (argc < 3 || argc > 4) { printf("usage: %s hashmap_tx|hashmap_atomic|ctree|btree|rbtree" " file-name [<seed>]\n", argv[0]); return 1; } const struct map_ops *ops = NULL; const char *path = argv[2]; const char *type = argv[1]; if (strcmp(type, "hashmap_tx") == 0) { ops = MAP_HASHMAP_TX; } else if (strcmp(type, "hashmap_atomic") == 0) { ops = MAP_HASHMAP_ATOMIC; } else if (strcmp(type, "ctree") == 0) { ops = MAP_CTREE; } else if (strcmp(type, "btree") == 0) { ops = MAP_BTREE; } else if (strcmp(type, "rbtree") == 0) { ops = MAP_RBTREE; } else { fprintf(stderr, "invalid hasmap type -- '%s'\n", type); return 1; } if (access(path, F_OK) != 0) { pop = pmemobj_create(path, POBJ_LAYOUT_NAME(map), PM_HASHSET_POOL_SIZE, S_IRUSR | S_IWUSR); if (pop == NULL) { fprintf(stderr, "failed to create pool: %s\n", pmemobj_errormsg()); return 1; } struct hashmap_args args; if (argc > 3) args.seed = atoi(argv[3]); else args.seed = time(NULL); srand(args.seed); mapc = map_ctx_init(ops, pop); if (!mapc) { pmemobj_close(pop); perror("map_ctx_init"); return 1; } root = POBJ_ROOT(pop, struct root); printf("seed: %u\n", args.seed); map_new(mapc, &D_RW(root)->map, &args); map = D_RO(root)->map; } else {
static void pool_open(const char *path, const char *layout) { PMEMobjpool *pop = pmemobj_open(path, layout); if (pop == NULL) UT_OUT("!%s: pmemobj_open: %s", path, pmemobj_errormsg()); else { UT_OUT("%s: pmemobj_open: Success", path); pmemobj_close(pop); } }
static void print_errors(const char *msg) { UT_OUT("%s", msg); UT_OUT("PMEM: %s", pmem_errormsg()); UT_OUT("PMEMOBJ: %s", pmemobj_errormsg()); UT_OUT("PMEMLOG: %s", pmemlog_errormsg()); UT_OUT("PMEMBLK: %s", pmemblk_errormsg()); UT_OUT("VMEM: %s", vmem_errormsg()); UT_OUT("PMEMPOOL: %s", pmempool_errormsg()); }
static void check_errors(int ver) { int ret; int err_need; int err_found; ret = sscanf(pmem_errormsg(), "libpmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEM_MAJOR_VERSION); ret = sscanf(pmemobj_errormsg(), "libpmemobj major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMOBJ_MAJOR_VERSION); ret = sscanf(pmemlog_errormsg(), "libpmemlog major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMLOG_MAJOR_VERSION); ret = sscanf(pmemblk_errormsg(), "libpmemblk major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION); #ifndef _WIN32 /* XXX - vmem not implemented in windows yet */ ret = sscanf(vmem_errormsg(), "libvmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, VMEM_MAJOR_VERSION); #endif ret = sscanf(pmempool_errormsg(), "libpmempool major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION); }
static void print_errors(const char *msg) { UT_OUT("%s", msg); UT_OUT("PMEM: %s", pmem_errormsg()); UT_OUT("PMEMOBJ: %s", pmemobj_errormsg()); UT_OUT("PMEMLOG: %s", pmemlog_errormsg()); UT_OUT("PMEMBLK: %s", pmemblk_errormsg()); #ifndef _WIN32 /* XXX - vmem not implemented in windows yet */ UT_OUT("VMEM: %s", vmem_errormsg()); #endif UT_OUT("PMEMPOOL: %s", pmempool_errormsg()); }
static void check_errors(int ver) { int ret; int err_need; int err_found; ret = sscanf(pmem_errormsg(), "libpmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEM_MAJOR_VERSION); ret = sscanf(pmemobj_errormsg(), "libpmemobj major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMOBJ_MAJOR_VERSION); ret = sscanf(pmemlog_errormsg(), "libpmemlog major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMLOG_MAJOR_VERSION); ret = sscanf(pmemblk_errormsg(), "libpmemblk major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION); ret = sscanf(vmem_errormsg(), "libvmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, VMEM_MAJOR_VERSION); ret = sscanf(pmempool_errormsg(), "libpmempool major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION); }
/* * pocli_alloc -- allocate main context */ static struct pocli * pocli_alloc(FILE *input, const char *fname, const struct pocli_cmd *cmds, size_t ncmds, size_t inbuf_len) { assert(inbuf_len < INT_MAX); struct pocli_opts opts; if (pocli_read_opts(&opts)) return NULL; struct pocli *pcli = calloc(1, sizeof (*pcli)); if (!pcli) return NULL; memcpy(&pcli->opts, &opts, sizeof (pcli->opts)); pcli->in = input; pcli->istty = isatty(fileno(pcli->in)); pcli->cmds = cmds; pcli->ncmds = ncmds; pcli->ctx.pocli = pcli; pcli->ctx.err = stderr; pcli->ctx.out = stdout; pcli->ctx.pop = pmemobj_open(fname, NULL); if (!pcli->ctx.pop) { fprintf(stderr, "%s: %s\n", fname, pmemobj_errormsg()); goto err_free_pcli; } size_t root_size = pmemobj_root_size(pcli->ctx.pop); if (root_size) pcli->ctx.root = pmemobj_root(pcli->ctx.pop, root_size); pcli->inbuf_len = inbuf_len; pcli->inbuf = malloc(inbuf_len); if (!pcli->inbuf) goto err_close_pool; return pcli; err_close_pool: pmemobj_close(pcli->ctx.pop); err_free_pcli: free(pcli); return NULL; }
int main(int argc, char *argv[]) { #ifdef _WIN32 wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc); for (int i = 0; i < argc; i++) { argv[i] = util_toUTF8(wargv[i]); if (argv[i] == NULL) { for (i--; i >= 0; i--) free(argv[i]); fprintf(stderr, "Error during arguments conversion\n"); return 1; } } #endif int opt; int tmpi; long long tmpl; int ret = 0; size_t size = 0; size_t root_size = 0; unsigned type_num = 0; char exit_at = '\0'; int do_set = 0; int do_free = 0; if (argc < 2) { USAGE(); ret = 1; goto end; } while ((opt = getopt(argc, argv, "r:o:t:e:sf")) != -1) { switch (opt) { case 'r': tmpl = atoll(optarg); if (tmpl < 0) { USAGE(); ret = 1; goto end; } root_size = (size_t)tmpl; break; case 'o': tmpl = atoll(optarg); if (tmpl < 0) { USAGE(); ret = 1; goto end; } size = (size_t)tmpl; break; case 't': tmpi = atoi(optarg); if (tmpi < 0) { USAGE(); ret = 1; goto end; } type_num = (unsigned)tmpi; break; case 'e': exit_at = optarg[0]; break; case 's': do_set = 1; break; case 'f': do_free = 1; break; default: USAGE(); ret = 1; goto end; } } char *file = argv[optind]; PMEMobjpool *pop; if ((pop = pmemobj_open(file, NULL)) == NULL) { fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg()); ret = 1; goto end; } if (root_size) { PMEMoid oid = pmemobj_root(pop, root_size); if (OID_IS_NULL(oid)) { fprintf(stderr, "pmemobj_root: %s\n", pmemobj_errormsg()); ret = 1; goto end; } } if (size) { PMEMoid oid; TX_BEGIN(pop) { oid = pmemobj_tx_alloc(size, type_num); if (exit_at == 'a') exit(1); } TX_END if (OID_IS_NULL(oid)) { fprintf(stderr, "pmemobj_tx_alloc: %s\n", pmemobj_errormsg()); ret = 1; goto end; } if (do_set) { TX_BEGIN(pop) { pmemobj_tx_add_range(oid, 0, size); if (exit_at == 's') exit(1); } TX_END } if (do_free) { TX_BEGIN(pop) { pmemobj_tx_free(oid); if (exit_at == 'f') exit(1); } TX_END } } pmemobj_close(pop); end: #ifdef _WIN32 for (int i = argc; i > 0; i--) free(argv[i - 1]); #endif return ret; }
/* * pobj_init - common part of the benchmark initialization functions. * Parses command line arguments, set variables and creates persistent pools. */ static int pobj_init(struct benchmark *bench, struct benchmark_args *args) { unsigned i = 0; size_t psize; size_t n_objs; assert(bench != nullptr); assert(args != nullptr); enum file_type type = util_file_get_type(args->fname); if (type == OTHER_ERROR) { fprintf(stderr, "could not check type of file %s\n", args->fname); return -1; } auto *bench_priv = (struct pobj_bench *)malloc(sizeof(struct pobj_bench)); if (bench_priv == nullptr) { perror("malloc"); return -1; } assert(args->opts != nullptr); bench_priv->args_priv = (struct pobj_args *)args->opts; bench_priv->args_priv->obj_size = args->dsize; bench_priv->args_priv->range = bench_priv->args_priv->min_size > 0 ? true : false; bench_priv->n_pools = !bench_priv->args_priv->one_pool ? args->n_threads : 1; bench_priv->pool = bench_priv->n_pools > 1 ? diff_num : one_num; bench_priv->obj = !bench_priv->args_priv->one_obj ? diff_num : one_num; if ((args->is_poolset || type == TYPE_DEVDAX) && bench_priv->n_pools > 1) { fprintf(stderr, "cannot use poolset nor device dax for multiple pools," " please use -P|--one-pool option instead"); goto free_bench_priv; } /* * Multiplication by FACTOR prevents from out of memory error * as the actual size of the allocated persistent objects * is always larger than requested. */ n_objs = bench_priv->args_priv->n_objs; if (bench_priv->n_pools == 1) n_objs *= args->n_threads; psize = PMEMOBJ_MIN_POOL + n_objs * args->dsize * args->n_threads * FACTOR; /* assign type_number determining function */ bench_priv->type_mode = parse_type_mode(bench_priv->args_priv->type_num); switch (bench_priv->type_mode) { case MAX_TYPE_MODE: fprintf(stderr, "unknown type mode"); goto free_bench_priv; case TYPE_MODE_RAND: if (random_types(bench_priv, args)) goto free_bench_priv; break; default: bench_priv->random_types = nullptr; } bench_priv->fn_type_num = type_mode_func[bench_priv->type_mode]; /* assign size determining function */ bench_priv->fn_size = bench_priv->args_priv->range ? range_size : static_size; bench_priv->rand_sizes = nullptr; if (bench_priv->args_priv->range) { if (bench_priv->args_priv->min_size > args->dsize) { fprintf(stderr, "Invalid allocation size"); goto free_random_types; } bench_priv->rand_sizes = rand_sizes(bench_priv->args_priv->min_size, bench_priv->args_priv->obj_size, bench_priv->args_priv->n_objs); if (bench_priv->rand_sizes == nullptr) goto free_random_types; } assert(bench_priv->n_pools > 0); bench_priv->pop = (PMEMobjpool **)calloc(bench_priv->n_pools, sizeof(PMEMobjpool *)); if (bench_priv->pop == nullptr) { perror("calloc"); goto free_random_sizes; } bench_priv->sets = (const char **)calloc(bench_priv->n_pools, sizeof(const char *)); if (bench_priv->sets == nullptr) { perror("calloc"); goto free_pop; } if (bench_priv->n_pools > 1) { assert(!args->is_poolset); if (util_file_mkdir(args->fname, DIR_MODE) != 0) { fprintf(stderr, "cannot create directory\n"); goto free_sets; } size_t path_len = (strlen(PART_NAME) + strlen(args->fname)) + MAX_DIGITS + 1; for (i = 0; i < bench_priv->n_pools; i++) { bench_priv->sets[i] = (char *)malloc(path_len * sizeof(char)); if (bench_priv->sets[i] == nullptr) { perror("malloc"); goto free_sets; } int ret = snprintf((char *)bench_priv->sets[i], path_len, "%s%s%02x", args->fname, PART_NAME, i); if (ret < 0 || ret >= (int)path_len) { perror("snprintf"); goto free_sets; } bench_priv->pop[i] = pmemobj_create(bench_priv->sets[i], LAYOUT_NAME, psize, FILE_MODE); if (bench_priv->pop[i] == nullptr) { perror(pmemobj_errormsg()); goto free_sets; } } } else { if (args->is_poolset || type == TYPE_DEVDAX) { if (args->fsize < psize) { fprintf(stderr, "file size too large\n"); goto free_pools; } psize = 0; } bench_priv->sets[0] = args->fname; bench_priv->pop[0] = pmemobj_create( bench_priv->sets[0], LAYOUT_NAME, psize, FILE_MODE); if (bench_priv->pop[0] == nullptr) { perror(pmemobj_errormsg()); goto free_pools; } } pmembench_set_priv(bench, bench_priv); return 0; free_sets: for (; i > 0; i--) { pmemobj_close(bench_priv->pop[i - 1]); free((char *)bench_priv->sets[i - 1]); } free_pools: free(bench_priv->sets); free_pop: free(bench_priv->pop); free_random_sizes: free(bench_priv->rand_sizes); free_random_types: free(bench_priv->random_types); free_bench_priv: free(bench_priv); return -1; }
int main(int argc, char *argv[]) { int opt; int tmpi; long long tmpl; size_t size = 0; size_t root_size = 0; unsigned int type_num = 0; char exit_at = '\0'; int do_set = 0; int do_free = 0; if (argc < 2) { USAGE(); return -1; } while ((opt = getopt(argc, argv, "r:o:t:e:sf")) != -1) { switch (opt) { case 'r': tmpl = atoll(optarg); if (tmpl < 0) { USAGE(); return -1; } root_size = (size_t)tmpl; break; case 'o': tmpl = atoll(optarg); if (tmpl < 0) { USAGE(); return -1; } size = (size_t)tmpl; break; case 't': tmpi = atoi(optarg); if (tmpi < 0) { USAGE(); return -1; } type_num = (unsigned)tmpi; break; case 'e': exit_at = optarg[0]; break; case 's': do_set = 1; break; case 'f': do_free = 1; break; default: USAGE(); return -1; } } char *file = argv[optind]; PMEMobjpool *pop; if ((pop = pmemobj_open(file, NULL)) == NULL) { fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg()); return -1; } if (root_size) { PMEMoid oid = pmemobj_root(pop, root_size); if (OID_IS_NULL(oid)) { fprintf(stderr, "pmemobj_root: %s\n", pmemobj_errormsg()); return -1; } } if (size) { PMEMoid oid; TX_BEGIN(pop) { oid = pmemobj_tx_alloc(size, type_num); if (exit_at == 'a') exit(1); } TX_END if (OID_IS_NULL(oid)) { fprintf(stderr, "pmemobj_tx_alloc: %s\n", pmemobj_errormsg()); return -1; } if (do_set) { TX_BEGIN(pop) { pmemobj_tx_add_range(oid, 0, size); if (exit_at == 's') exit(1); } TX_END } if (do_free) { TX_BEGIN(pop) { pmemobj_tx_free(oid); if (exit_at == 'f') exit(1); } TX_END } } pmemobj_close(pop); return 0; }