Commit c69ec981 authored by Shane Snyder's avatar Shane Snyder

add new bake mkpool utility

parent 081a52d7
......@@ -5,9 +5,11 @@ src_libbake_bulk_server_la_SOURCES += \
src/bake-bulk-server.c
src_bake_bulk_server_daemon_LDADD = src/libbake-bulk-server.la
src_bake_bulk_mkpool_LDADD = src/libbake-bulk-server.la
bin_PROGRAMS += \
src/bake-bulk-server-daemon \
src/bake-bulk-mkpool \
src/bb-shutdown \
src/bb-copy-to \
src/bb-copy-from \
......
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libpmemobj.h>
#include <bake-bulk-server.h>
struct options
{
char *pmem_pool;
size_t pool_size;
mode_t pool_mode;
};
void usage(int argc, char *argv[])
{
fprintf(stderr, "Usage: bake-bulk-mkpool [OPTIONS] <pmem_pool>\n");
fprintf(stderr, " pmem_pool is the path to the pmemobj pool to create\n");
fprintf(stderr, " [-s size] is the desired size of the pool (%lu is default)\n", PMEMOBJ_MIN_POOL);
fprintf(stderr, "Example: ./bake-bulk-mkpool /dev/shm/foo.dat\n");
return;
}
int parse_size(char *str, size_t *size_out)
{
const char *suffixes[] = { "B", "K", "M", "G", "T", "P" };
size_t size_mults[] = { 1ULL, 1ULL << 10, 1ULL << 20, 1ULL << 30, 1ULL << 40, 1ULL << 50 };
size_t size;
char suff[2] = {0};
int i;
int ret;
ret = sscanf(str, "%zu%2s", &size, suff);
if(ret == 1)
{
*size_out = size;
return(0);
}
else if(ret == 2)
{
for(i = 0; i < 6; i++)
{
if(strcmp(suffixes[i], suff) == 0)
{
*size_out = (size * size_mults[i]);
return(0);
}
}
}
return(-1);
}
void parse_args(int argc, char *argv[], struct options *opts)
{
int opt;
int ret;
/* set default options */
memset(opts, 0, sizeof(*opts));
opts->pool_size = PMEMOBJ_MIN_POOL;
opts->pool_mode = 0664;
/* get options */
while((opt = getopt(argc, argv, "s:")) != -1)
{
switch(opt)
{
case 's':
ret = parse_size(optarg, &opts->pool_size);
if(ret != 0)
{
usage(argc, argv);
exit(EXIT_FAILURE);
}
break;
default:
usage(argc, argv);
exit(EXIT_FAILURE);
}
}
/* get required arguments after options */
if((argc - optind) != 1)
{
usage(argc, argv);
exit(EXIT_FAILURE);
}
opts->pmem_pool = argv[optind++];
return;
}
int main(int argc, char *argv[])
{
struct options opts;
int ret;
parse_args(argc, argv, &opts);
ret = bake_server_makepool(opts.pmem_pool, opts.pool_size, opts.pool_mode);
return(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment