Skip to content

Commit

Permalink
state: Store the workload dir and rootfs mount to state.
Browse files Browse the repository at this point in the history
These will be needed to unmount the rootfs while stopping
the container.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Jun 21, 2017
1 parent 53dc5ff commit 0af8583
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,23 @@ cc_oci_mounts_to_json (const struct cc_oci_config *config)
return cc_mounts_to_json(config->oci.mounts);
}

/*!
* Convert container rootfs mount to a JSON array.
*
* \param config \ref cc_oci_config.
*
* \return \c JsonArray on success, else \c NULL.
*/
JsonArray *
cc_oci_rootfs_mount_to_json (const struct cc_oci_config *config)
{
if (!config || config->pod) {
return NULL;
}

return cc_mounts_to_json(config->rootfs_mount);
}

/*!
* Convert the list of pod mounts to a JSON array.
*
Expand Down
1 change: 1 addition & 0 deletions src/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void cc_oci_mounts_free_all (GSList *mounts);
void cc_oci_mount_free (struct cc_oci_mount *m);

JsonArray *cc_oci_mounts_to_json (const struct cc_oci_config *config);
JsonArray *cc_oci_rootfs_mount_to_json (const struct cc_oci_config *config);
JsonArray *cc_pod_mounts_to_json (const struct cc_oci_config *config);

#endif /* _CC_OCI_MOUNT_H */
10 changes: 10 additions & 0 deletions src/oci.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ struct oci_state {
gchar *bundle_path;
gchar *comms_path;

gchar *workload_dir;

/** path to the process socket, used to determine when the VM
* has shut down.
*/
Expand All @@ -432,6 +434,14 @@ struct oci_state {
*/
GSList *mounts;

/** List containing a single entry of \ref cc_oci_mount
*
* This is the bind mount for the container rootfs in the hyperstart
* shared directory.
*
*/
GSList *rootfs_mount;

/** List of \ref oci_cfg_annotation annotations.
*
*/
Expand Down
66 changes: 66 additions & 0 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ static void handle_state_pid_section(GNode*, struct handler_data*);
static void handle_state_bundlePath_section(GNode*, struct handler_data*);
static void handle_state_commsPath_section(GNode*, struct handler_data*);
static void handle_state_processPath_section(GNode*, struct handler_data*);
static void handle_state_workloadDir_section(GNode*, struct handler_data*);
static void handle_state_status_section(GNode*, struct handler_data*);
static void handle_state_created_section(GNode*, struct handler_data*);
static void handle_state_mounts_section(GNode*, struct handler_data*);
static void handle_state_rootfsMount_section(GNode* node, struct handler_data* data);
static void handle_state_namespaces_section(GNode*, struct handler_data*);
static void handle_state_console_section(GNode*, struct handler_data*);
static void handle_state_vm_section(GNode*, struct handler_data*);
Expand Down Expand Up @@ -89,9 +91,11 @@ static struct state_handler {
{ "bundlePath" , handle_state_bundlePath_section , 1 , 0 },
{ "commsPath" , handle_state_commsPath_section , 1 , 0 },
{ "processPath" , handle_state_processPath_section , 1 , 0 },
{ "workloadDir" , handle_state_workloadDir_section , 1 , 0 },
{ "status" , handle_state_status_section , 1 , 0 },
{ "created" , handle_state_created_section , 1 , 0 },
{ "mounts" , handle_state_mounts_section , 0 , 0 },
{ "rootfsMount" , handle_state_rootfsMount_section , 0 , 0 },
{ "console" , handle_state_console_section , 0 , 0 },
{ "vm" , handle_state_vm_section , 6 , 0 },
{ "proxy" , handle_state_proxy_section , 2 , 0 },
Expand Down Expand Up @@ -228,6 +232,17 @@ handle_state_processPath_section (GNode* node, struct handler_data* data) {
update_subelements_and_strdup(node, data, procsock_path);
}

/*!
* handler for workloadDir section
*
* \param node \c GNode.
* \param data \ref handler_data.
*/
static void
handle_state_workloadDir_section (GNode* node, struct handler_data* data) {
update_subelements_and_strdup(node, data, workload_dir);
}

/*!
* handler for status section
*
Expand Down Expand Up @@ -298,6 +313,38 @@ handle_state_mounts_section(GNode* node, struct handler_data* data) {
}
}

/*!
* handler for rootfsMount section
*
* \param node \c GNode.
* \param data \ref handler_data.
*/
static void
handle_state_rootfsMount_section(GNode* node, struct handler_data* data) {
struct cc_oci_mount* m;

if (! (node && node->data)) {
return;
}
if (! (node->children && node->children->data)) {
g_critical("%s missing value", (char*)node->data);
return;
}

if (! g_strcmp0(node->data, "destination")) {
m = g_new0 (struct cc_oci_mount, 1);
g_strlcpy (m->dest, (char*)node->children->data, sizeof (m->dest));
m->ignore_mount = false;
data->state->rootfs_mount = g_slist_append(data->state->rootfs_mount, m);
} else if (! g_strcmp0(node->data, "directory_created")) {
GSList *l = g_slist_last(data->state->rootfs_mount);
if (l) {
m = (struct cc_oci_mount*)l->data;
m->directory_created = g_strdup((char*)node->children->data);
}
}
}

/*!
* handler for namespaces section
*
Expand Down Expand Up @@ -766,6 +813,7 @@ cc_oci_state_free (struct oci_state *state)
g_free_if_set (state->bundle_path);
g_free_if_set (state->comms_path);
g_free_if_set (state->procsock_path);
g_free_if_set (state->workload_dir);
g_free_if_set (state->create_time);
g_free_if_set (state->console);

Expand All @@ -785,6 +833,10 @@ cc_oci_state_free (struct oci_state *state)
cc_oci_mounts_free_all (state->mounts);
}

if (state->rootfs_mount) {
cc_oci_mounts_free_all (state->rootfs_mount);
}

if (state->namespaces) {
g_slist_free_full(state->namespaces,
(GDestroyNotify)cc_oci_ns_free);
Expand Down Expand Up @@ -837,6 +889,7 @@ cc_oci_state_file_create (struct cc_oci_config *config,
JsonObject *proxy = NULL;
JsonObject *annotation_obj = NULL;
JsonArray *mounts = NULL;
JsonArray *rootfs_mount = NULL;
JsonArray *namespaces = NULL;
JsonObject *process = NULL;
JsonObject *pod = NULL;
Expand Down Expand Up @@ -868,6 +921,9 @@ cc_oci_state_file_create (struct cc_oci_config *config,
if ( ! config->state.procsock_path[0]) {
return false;
}
if ( ! config->workload_dir[0]) {
return false;
}
if (! config->vm) {
return false;
}
Expand Down Expand Up @@ -909,6 +965,9 @@ cc_oci_state_file_create (struct cc_oci_config *config,
json_object_set_string_member (obj, "processPath",
config->state.procsock_path);

json_object_set_string_member (obj, "workloadDir",
config->workload_dir);

status = cc_oci_status_get (config);
if (! status) {
goto out;
Expand All @@ -928,6 +987,13 @@ cc_oci_state_file_create (struct cc_oci_config *config,

json_object_set_array_member (obj, "mounts", mounts);

rootfs_mount = cc_oci_rootfs_mount_to_json (config);
if (! rootfs_mount) {
goto out;
}

json_object_set_array_member (obj, "rootfsMount", rootfs_mount);

/* Add an array of namespaces to allow join to them and
* umount or clear all resources
*/
Expand Down

0 comments on commit 0af8583

Please sign in to comment.