Skip to content

Commit

Permalink
storage: Add function to check the storage for container rootfs
Browse files Browse the repository at this point in the history
If a block device is found, we store the device name of the block
device found. We also store the file system type and index.
We are currently using an incrementing counter for the index.
When we add support for CRIO with hot plugging drives, so that
containers with block drives can be added after the VM is started,
we should store the global index in a file and retrieve
it from there.

The index is needed to derive the drive name that we pass to qemu.
We need to pass the drive name and file system type to hyperstart.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Jun 21, 2017
1 parent e05e368 commit 2d783ae
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#include "namespace.h"
#include "pod.h"

/* This incrementing index is used for deriving the drive name.
* Drives passed to qemu are assigned names in the order that they are
* passed
*/
static int block_index = 0;

/** Mounts that will be ignored.
*
* These are standard mounts that will be created within the VM
Expand Down Expand Up @@ -875,3 +881,62 @@ cc_get_device_and_fstype(gchar *mount_point, gchar **device_name, gchar **fstype
endmntent(file);
return ret;
}

/*!
* Check for block storage device for container rootfs.
* If block device is detected, set the
* config->device_name to the device found.
*
* \param config \ref cc_oci_config.
*
* \return \c true on success, else \c false.
*/
gboolean
cc_oci_rootfs_is_block_device(struct cc_oci_config *config)
{
uint major, minor;
char *fstype = NULL;

if (! config) {
return false;
}

gchar *container_root = config->oci.root.path;

if (! cc_device_for_path(container_root, &major, &minor)) {
g_critical("Could not get the underlying device for rootfs");
return false;
}

if (! cc_is_blockdevice(major, minor)) {
return false;
}

g_debug("Devicemapper block device detected for container %s",
config->optarg_container_id);

gchar *mount_pnt = cc_mount_point_for_path(container_root);
if ( ! mount_pnt) {
g_critical("Could not get mount point for %s\n",
container_root);
return false;
}

if (! cc_get_device_and_fstype(mount_pnt, &(config->device_name), &fstype)) {
g_critical("Could not get device name for mountpoint %s",
mount_pnt);
g_free(mount_pnt);
return false;
}

g_debug("Device name, fstype fetched for container %s: %s, %s",
config->optarg_container_id,
config->device_name, fstype);

config->state.block_fstype = fstype;
config->state.block_index = block_index;
block_index++;

g_free(mount_pnt);
return true;
}
2 changes: 2 additions & 0 deletions src/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ 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);

gboolean cc_oci_rootfs_is_block_device(struct cc_oci_config *config);

#endif /* _CC_OCI_MOUNT_H */
17 changes: 17 additions & 0 deletions src/oci.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ struct oci_state {

/* Needed by start to create a new container workload */
struct oci_cfg_process *process;

gchar *block_fstype;
int block_index;
};

/** clr-specific state fields. */
Expand Down Expand Up @@ -497,6 +500,14 @@ struct cc_oci_container_state {

/** OCI status of container. */
enum oci_status status;

/* File system of the block device mount if the container rootfs
* is a block device, NULL otherwise.
*/
gchar *block_fstype;

/* Index of the drive/block device passed to the hypervisor */
int block_index;
};

/** clr-specific mount details. */
Expand Down Expand Up @@ -651,6 +662,12 @@ struct cc_oci_config {
*
*/
GSList *rootfs_mount;

/** Name of the underlying block device for the container rootfs if
* present
*/
gchar *device_name;

};

gchar *cc_oci_config_file_path (const gchar *bundle_path);
Expand Down

0 comments on commit 2d783ae

Please sign in to comment.