Skip to content

Commit

Permalink
storage: Pass drive name to hyperstart with the newcontainer command
Browse files Browse the repository at this point in the history
For hyperstart to use the drive passed on qemu command line,
we pass the drive name and the file system type of the block
device. The drive name needs to be passed as image field
in the newcontainer json.
The drive name is deduced based on the index at which the drive is
passed to qemu.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Jun 21, 2017
1 parent dd13e32 commit 97922b5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ cc_proxy_run_hyper_new_container (struct cc_oci_config *config,
JsonArray *additional_gids = NULL;
gchar *uid_str = NULL;
gchar *gid_str = NULL;
gchar *drive_name = NULL;

/* json stanza for NEWCONTAINER*/
/*
Expand Down Expand Up @@ -1378,9 +1379,20 @@ cc_proxy_run_hyper_new_container (struct cc_oci_config *config,

json_object_set_array_member (newcontainer_payload, "fsmap", cc_get_hyper_fsmap(config));

json_object_set_string_member (newcontainer_payload, "rootfs", rootfs);
if (config->state.block_fstype) {
drive_name = cc_get_virtio_drive_name(config->state.block_index);
if (! drive_name) {
return false;
}

json_object_set_string_member (newcontainer_payload, "image", drive_name);
json_object_set_string_member (newcontainer_payload, "fstype", config->state.block_fstype);
json_object_set_string_member (newcontainer_payload, "rootfs", "rootfs");
} else {
json_object_set_string_member (newcontainer_payload, "rootfs", rootfs);
json_object_set_string_member (newcontainer_payload, "image", image);
}

json_object_set_string_member (newcontainer_payload, "image", image);
/*json_object_set_string_member (newcontainer_payload, "image",
config->optarg_container_id);
*/
Expand Down Expand Up @@ -1479,6 +1491,7 @@ cc_proxy_run_hyper_new_container (struct cc_oci_config *config,
return false;
}

g_free_if_set(drive_name);
return true;
}

Expand Down
64 changes: 64 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#include "util.h"
#include "config.h"

/* Length for virtio disk name
* Ref: https://github.com/torvalds/linux/blob/08c521a2011ff492490aa9ed6cc574be4235ce2b/include/linux/genhd.h#L61
*/
#define DISK_NAME_LEN 32

/** Full path to \c rm(1) command. */
#define CC_OCI_RM_CMD "/bin/rm"

Expand Down Expand Up @@ -741,6 +746,65 @@ get_random_bytes(uint num) {
return buf;
}

// Legacy naming scheme for virtio block devices
// Reference : https://github.com/torvalds/linux/blob/master/drivers/block/virtio_blk.c @c0aa3e0916d7e531e69b02e426f7162dfb1c6c0f
static int
virtblk_name_format(char *prefix, int index, char *buf, int buflen)
{
char *p;
int unit;

if (! (prefix && buf)) {
return -1;
}

const int base = 'z' - 'a' + 1;
char *begin = buf + strlen(prefix);
char *end = buf + buflen;

p = end - 1;
*p = '\0';
unit = base;

do {
if (p == begin) {
return -EINVAL;
}

*--p = (char)('a' + (index % unit));
index = (index / unit) - 1;
} while (index >= 0);

memmove(begin, p, (size_t)(end - p));
memcpy(buf, prefix, strlen(prefix));

return 0;
}

/*!
* Get the name of a virtio-block drive
*
* \param buf Buffer storing the big endian value
*
* \return \c guint32 in big endian order.
*/

gchar *
cc_get_virtio_drive_name(int index)
{
char disk_name[DISK_NAME_LEN];

if (index < 0) {
return NULL;
}

if (virtblk_name_format("vd", index, disk_name, DISK_NAME_LEN) != 0) {
return NULL;
}

return strdup(disk_name);
}

#ifdef DEBUG
static gboolean
cc_oci_node_dump_aux(GNode* node, gpointer data) {
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ gboolean cc_oci_enable_networking (void);
guint32 cc_oci_get_big_endian_32(const guint8 *buf);
gboolean cc_oci_handle_signals (void);
gboolean dup_over_stdio(int *fdp);
gchar *cc_get_virtio_drive_name(int index);
uint8_t *get_random_bytes(uint size);

#endif /* _CC_OCI_UTIL_H */

0 comments on commit 97922b5

Please sign in to comment.