Commit fb93034e authored by Rob Latham's avatar Rob Latham
Browse files

Create struct to handle pmem entities

A bit cleaner to create and pass around a struct.
parent b47bf5c9
...@@ -16,6 +16,12 @@ struct bake_bulk_root ...@@ -16,6 +16,12 @@ struct bake_bulk_root
bake_target_id_t target_id; bake_target_id_t target_id;
}; };
struct bake_pool_info
{
PMEMobjpool *bb_pmem_pool;
struct bake_bulk_root *bb_pmem_root;
};
/** /**
* Register a bake server instance for a given Margo instance. * Register a bake server instance for a given Margo instance.
* *
...@@ -25,19 +31,16 @@ struct bake_bulk_root ...@@ -25,19 +31,16 @@ struct bake_bulk_root
*/ */
void bake_server_register( void bake_server_register(
margo_instance_id mid, margo_instance_id mid,
PMEMobjpool *bb_pmem_pool, struct bake_pool_info *pool_info);
struct bake_bulk_root *bb_pmem_root);
/** /**
* Convienence function to set up a PMEM backend. * Convienence function to set up a PMEM backend.
* *
* @param[in] poolname path to pmem backend file * @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 * returns a pointer to an initialized `struct bake_pool_info` on sucess,
* NULL if anything goes wrong
*/ */
int bake_server_makepool( struct bake_pool_info *bake_server_makepool(
char *poolname, PMEMobjpool **bb_pmem_pool, char *poolname);
struct bake_bulk_root *bb_pmem_root);
#endif /* __BAKE_BULK_SERVER_H */ #endif /* __BAKE_BULK_SERVER_H */
...@@ -16,8 +16,7 @@ int main(int argc, char **argv) ...@@ -16,8 +16,7 @@ int main(int argc, char **argv)
{ {
int ret; int ret;
margo_instance_id mid; margo_instance_id mid;
PMEMobjpool *bb_pmem_pool = NULL; struct bake_pool_info * pool_info;
struct bake_bulk_root bb_pmem_root;
if(argc != 3) if(argc != 3)
{ {
...@@ -26,7 +25,7 @@ int main(int argc, char **argv) ...@@ -26,7 +25,7 @@ int main(int argc, char **argv)
return(-1); return(-1);
} }
ret = bake_server_makepool(argv[2], &bb_pmem_pool, &bb_pmem_root); pool_info = bake_server_makepool(argv[2]);
/* start margo */ /* start margo */
/* use the main xstream for driving progress and executing rpc handlers */ /* use the main xstream for driving progress and executing rpc handlers */
...@@ -34,7 +33,7 @@ int main(int argc, char **argv) ...@@ -34,7 +33,7 @@ int main(int argc, char **argv)
assert(mid); assert(mid);
/* register the bake bulk server */ /* register the bake bulk server */
bake_server_register(mid, bb_pmem_pool, &bb_pmem_root); bake_server_register(mid, pool_info);
/* NOTE: at this point this server ULT has two options. It can wait on /* 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 * whatever mechanism it wants to (however long the daemon should run and
...@@ -52,7 +51,7 @@ int main(int argc, char **argv) ...@@ -52,7 +51,7 @@ int main(int argc, char **argv)
*/ */
margo_wait_for_finalize(mid); margo_wait_for_finalize(mid);
pmemobj_close(bb_pmem_pool); pmemobj_close(pool_info->bb_pmem_pool);
return(0); return(0);
} }
......
...@@ -21,38 +21,42 @@ typedef struct { ...@@ -21,38 +21,42 @@ typedef struct {
static PMEMobjpool *g_pmem_pool = NULL; static PMEMobjpool *g_pmem_pool = NULL;
static struct bake_bulk_root *g_pmem_root = NULL; static struct bake_bulk_root *g_pmem_root = NULL;
int bake_server_makepool( struct bake_pool_info * bake_server_makepool(
char *poolname, PMEMobjpool **bb_pmem_pool, char *poolname)
struct bake_bulk_root *bb_pmem_root)
{ {
PMEMoid root_oid; PMEMoid root_oid;
char target_string[64]; char target_string[64];
struct bake_pool_info *pool_info;
pool_info = malloc(sizeof(*pool_info));
/* open pmem pool */ /* open pmem pool */
*bb_pmem_pool = pmemobj_open(poolname, NULL); pool_info->bb_pmem_pool = pmemobj_open(poolname, NULL);
if(!bb_pmem_pool) if(!pool_info->bb_pmem_pool)
{ {
fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg()); fprintf(stderr, "pmemobj_open: %s\n", pmemobj_errormsg());
return(-1); return(NULL);
} }
/* find root */ /* find root */
root_oid = pmemobj_root(*bb_pmem_pool, sizeof(*bb_pmem_root)); root_oid = pmemobj_root(pool_info->bb_pmem_pool,
bb_pmem_root = pmemobj_direct(root_oid); sizeof(*(pool_info->bb_pmem_root)) );
if(uuid_is_null(bb_pmem_root->target_id.id)) pool_info->bb_pmem_root = pmemobj_direct(root_oid);
if(uuid_is_null(pool_info->bb_pmem_root->target_id.id))
{ {
uuid_generate(bb_pmem_root->target_id.id); uuid_generate(pool_info->bb_pmem_root->target_id.id);
pmemobj_persist(*bb_pmem_pool, bb_pmem_root, sizeof(*bb_pmem_root)); pmemobj_persist(pool_info->bb_pmem_pool,
pool_info->bb_pmem_root, sizeof(*(pool_info->bb_pmem_root)) );
} }
uuid_unparse(bb_pmem_root->target_id.id, target_string); uuid_unparse(pool_info->bb_pmem_root->target_id.id, target_string);
fprintf(stderr, "BAKE target ID: %s\n", target_string); fprintf(stderr, "BAKE target ID: %s\n", target_string);
return 0; return pool_info;
} }
void bake_server_register(margo_instance_id mid, PMEMobjpool *bb_pmem_pool, void bake_server_register(margo_instance_id mid,
struct bake_bulk_root *bb_pmem_root) struct bake_pool_info *pool_info)
{ {
/* register RPCs */ /* register RPCs */
MARGO_REGISTER(mid, "bake_bulk_shutdown_rpc", void, void, MARGO_REGISTER(mid, "bake_bulk_shutdown_rpc", void, void,
...@@ -86,8 +90,8 @@ void bake_server_register(margo_instance_id mid, PMEMobjpool *bb_pmem_pool, ...@@ -86,8 +90,8 @@ void bake_server_register(margo_instance_id mid, PMEMobjpool *bb_pmem_pool,
bake_bulk_noop_ult); bake_bulk_noop_ult);
/* set global pmem variables needed by the bake server */ /* set global pmem variables needed by the bake server */
g_pmem_pool = bb_pmem_pool; g_pmem_pool = pool_info->bb_pmem_pool;
g_pmem_root = bb_pmem_root; g_pmem_root = pool_info->bb_pmem_root;
return; return;
} }
......
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