Skip to content

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 <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Jun 21, 2017
1 parent 5249cb4 commit fb9f94e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 35 deletions.
59 changes: 59 additions & 0 deletions src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,65 @@ 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 NULL;
}

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_debug("Created rootfs bind mount object for container %s",
config->optarg_container_id);
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 @@ -28,6 +28,7 @@
#include <gio/gunixconnection.h>

#include "common.h"
#include "mount.h"
#include "pod.h"
#include "process.h"
#include "proxy.h"
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 fb9f94e

Please sign in to comment.