Commit f16e168d authored by Philip Carns's avatar Philip Carns
Browse files

ability to create targets

parent f68f76f1
......@@ -68,6 +68,22 @@ int bake_provider_attach_target(bake_provider_t provider,
const char* target_name,
bake_target_id_t* target_id);
/**
* Create a new target that did not yet exist and begin managing it.
*
* @param provider Bake provider
* @param target_name path to pmem target
* @param[in] size size of the created target (may be ignored for target
* types that can be extended or use a fixed size physical device)
* @param target_id resulting id identifying the target
*
* @return BAKE_SUCCESS or BAKE_ERR*
*/
int bake_provider_create_target(bake_provider_t provider,
const char* target_name,
size_t size,
bake_target_id_t* target_id);
/**
* Makes the provider stop managing a target.
*
......
......@@ -334,6 +334,23 @@ int bake_provider_deregister(bake_provider_t provider)
return BAKE_SUCCESS;
}
int bake_provider_create_target(bake_provider_t provider,
const char* target_name,
size_t size,
bake_target_id_t* target_id)
{
int ret;
/* create the actual target */
ret = bake_create_raw_target(target_name, size);
if (ret < 0) return (ret);
/* begin managing it */
ret = bake_provider_attach_target(provider, target_name, target_id);
return (ret);
}
int bake_provider_attach_target(bake_provider_t provider,
const char* target_name,
bake_target_id_t* target_id)
......@@ -1102,11 +1119,14 @@ static int attach_targets(bake_provider_t provider,
for (i = 0; i < target_names_count; i++) {
ret = bake_provider_attach_target(provider, target_names[i], &tid);
if (ret == BAKE_ERR_NOENT) {
/* TODO: target does not exist; try to create it */
assert(0);
} else if (ret != BAKE_SUCCESS) {
goto error;
/* doesn't exist; attempt to create */
/* TODO: need a way to determine file size here. Maybe a
* default initial size specified in the provider json?
*/
ret = bake_provider_create_target(provider, target_names[i], 0,
&tid);
}
if (ret != BAKE_SUCCESS) { goto error; }
BAKE_INFO(provider->mid, "attached target %s", target_names[i]);
free(target_names[i]);
}
......
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