Commit b47bf5c9 authored by Rob Latham's avatar Rob Latham

break out pmem pool setup into separate function

parent 1da145eb
......@@ -28,4 +28,16 @@ void bake_server_register(
PMEMobjpool *bb_pmem_pool,
struct bake_bulk_root *bb_pmem_root);
/**
* Convienence function to set up a PMEM backend.
*
* @param[in] poolname path to pmem backend file
* @param[inout] pmem_pool libpmem pool to use for the bake storage service
* @param[inout] bb_mem_root libpmem root for the bake pool
*
* returns 0 on sucess, -1 if anything goes wrong
*/
int bake_server_makepool(
char *poolname, PMEMobjpool **bb_pmem_pool,
struct bake_bulk_root *bb_pmem_root);
#endif /* __BAKE_BULK_SERVER_H */
......@@ -16,10 +16,8 @@ int main(int argc, char **argv)
{
int ret;
margo_instance_id mid;
char target_string[64];
PMEMoid root_oid;
PMEMobjpool *bb_pmem_pool = NULL;
struct bake_bulk_root *bb_pmem_root = NULL;
struct bake_bulk_root bb_pmem_root;
if(argc != 3)
{
......@@ -28,24 +26,7 @@ int main(int argc, char **argv)
return(-1);
}
/* open pmem pool */
bb_pmem_pool = pmemobj_open(argv[2], NULL);
if(!bb_pmem_pool)
{
fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg());
return(-1);
}
/* find root */
root_oid = pmemobj_root(bb_pmem_pool, sizeof(*bb_pmem_root));
bb_pmem_root = pmemobj_direct(root_oid);
if(uuid_is_null(bb_pmem_root->target_id.id))
{
uuid_generate(bb_pmem_root->target_id.id);
pmemobj_persist(bb_pmem_pool, bb_pmem_root, sizeof(*bb_pmem_root));
}
uuid_unparse(bb_pmem_root->target_id.id, target_string);
fprintf(stderr, "BAKE target ID: %s\n", target_string);
ret = bake_server_makepool(argv[2], &bb_pmem_pool, &bb_pmem_root);
/* start margo */
/* use the main xstream for driving progress and executing rpc handlers */
......@@ -53,7 +34,7 @@ int main(int argc, char **argv)
assert(mid);
/* register the bake bulk server */
bake_server_register(mid, bb_pmem_pool, bb_pmem_root);
bake_server_register(mid, bb_pmem_pool, &bb_pmem_root);
/* NOTE: at this point this server ULT has two options. It can wait on
* whatever mechanism it wants to (however long the daemon should run and
......
......@@ -21,6 +21,35 @@ typedef struct {
static PMEMobjpool *g_pmem_pool = NULL;
static struct bake_bulk_root *g_pmem_root = NULL;
int bake_server_makepool(
char *poolname, PMEMobjpool **bb_pmem_pool,
struct bake_bulk_root *bb_pmem_root)
{
PMEMoid root_oid;
char target_string[64];
/* open pmem pool */
*bb_pmem_pool = pmemobj_open(poolname, NULL);
if(!bb_pmem_pool)
{
fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg());
return(-1);
}
/* find root */
root_oid = pmemobj_root(*bb_pmem_pool, sizeof(*bb_pmem_root));
bb_pmem_root = pmemobj_direct(root_oid);
if(uuid_is_null(bb_pmem_root->target_id.id))
{
uuid_generate(bb_pmem_root->target_id.id);
pmemobj_persist(*bb_pmem_pool, bb_pmem_root, sizeof(*bb_pmem_root));
}
uuid_unparse(bb_pmem_root->target_id.id, target_string);
fprintf(stderr, "BAKE target ID: %s\n", target_string);
return 0;
}
void bake_server_register(margo_instance_id mid, PMEMobjpool *bb_pmem_pool,
struct bake_bulk_root *bb_pmem_root)
......
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