Skip to content
This repository has been archived by the owner on Mar 28, 2018. It is now read-only.

Commit

Permalink
mounts: Factorise the pod function for bind-mouting rootfs
Browse files Browse the repository at this point in the history
We will be using this to bind-mount the rootfs of regular
container to a hyperstart shared directory.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Jun 18, 2017
1 parent 4e96669 commit e9ddabc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 35 deletions.
58 changes: 58 additions & 0 deletions src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,64 @@ cc_handle_mounts(struct cc_oci_config *config, GSList *mounts, gboolean volume)
return true;
}

/*!
* Return a rootfs bind mount for container.
*
* \param config \ref cc_oci_config.
*
* \return \c cc_oci_mount on success, else \c NULL.
*/
struct cc_oci_mount*
rootfs_bind_mount(struct cc_oci_config *config)
{
struct cc_oci_mount *m;

if (! config ) {
return false;
}

m = g_malloc0 (sizeof (struct cc_oci_mount));
if (! m) {
goto error;
}

m->flags = MS_BIND;

/* Destination */
m->mnt.mnt_dir = g_malloc0(PATH_MAX);
if (! m->mnt.mnt_dir) {
goto error;
}

g_snprintf(m->mnt.mnt_dir, PATH_MAX, "/%s/rootfs",
config->optarg_container_id);

/* Source */
m->mnt.mnt_fsname = g_strdup(config->oci.root.path);
if (! m->mnt.mnt_fsname) {
goto error;
}

/* Type */
m->mnt.mnt_type = g_strdup("bind");
if (! m->mnt.mnt_type) {
goto error;
}

g_warning("Rootfs bind mounting done");
return m;

error:
if (m) {
g_free_if_set(m->mnt.mnt_dir);
g_free_if_set(m->mnt.mnt_fsname);
g_free_if_set(m->mnt.mnt_type);
g_free_if_set(m);
}

return NULL;
}

/*!
* Setup required OCI mounts.
*
Expand Down
2 changes: 2 additions & 0 deletions src/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ gboolean cc_pod_handle_mounts (struct cc_oci_config *config);
gboolean cc_oci_handle_unmounts (const struct cc_oci_config *config);
gboolean cc_pod_handle_unmounts (const struct cc_oci_config *config);

struct cc_oci_mount* rootfs_bind_mount(struct cc_oci_config *config);

void cc_oci_mounts_free_all (GSList *mounts);
void cc_oci_mount_free (struct cc_oci_mount *m);

Expand Down
38 changes: 3 additions & 35 deletions src/pod.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "process.h"
#include "proxy.h"
#include "state.h"
#include "mount.h"

/* Sandbox rootfs */
#define CC_POD_SANDBOX_ROOTFS "workloads"
Expand Down Expand Up @@ -76,48 +77,15 @@ add_container_mount(struct cc_oci_config *config) {
return false;
}

m = g_malloc0 (sizeof (struct cc_oci_mount));
m = rootfs_bind_mount(config);
if (! m) {
goto error;
}

m->flags = MS_BIND;

/* Destination */
m->mnt.mnt_dir = g_malloc0(PATH_MAX);
if (! m->mnt.mnt_dir) {
goto error;
}

g_snprintf(m->mnt.mnt_dir, PATH_MAX, "/%s/rootfs",
config->optarg_container_id);

/* Source */
m->mnt.mnt_fsname = g_strdup(config->oci.root.path);
if (! m->mnt.mnt_fsname) {
goto error;
}

/* Type */
m->mnt.mnt_type = g_strdup("bind");
if (! m->mnt.mnt_type) {
goto error;
return false;
}

/* Add our pod container rootfs mount to the pod mount points */
config->pod->rootfs_mounts = g_slist_append(config->pod->rootfs_mounts, m);

return true;

error:
if (m) {
g_free_if_set(m->mnt.mnt_dir);
g_free_if_set(m->mnt.mnt_fsname);
g_free_if_set(m->mnt.mnt_type);
g_free_if_set(m);
}

return false;
}

/**
Expand Down

0 comments on commit e9ddabc

Please sign in to comment.