Skip to content

Commit

Permalink
Attempt harder to obtain config-drive.
Browse files Browse the repository at this point in the history
There are some cases where a config-drive is on the system, but
not initially detected early at boot. One such case is when the
cdrom subsystem isn't builtin to the kernel but enabled as a module.

We can try and catch this issue. It will slow down boot a bit, so
this only waits 1 second total for now. But modprobing `sr_mod` which
depends on `cdrom` is a good start here, and covers obtaining the
`meda_data.json` file in case a VM is booted with the -native or
other non-kvm kernels.
  • Loading branch information
ahkok committed Dec 18, 2019
1 parent ca976ef commit 533c9a0
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/datasources/openstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,26 @@ bool openstack_init() {

data_source = SOURCE_NONE;

if (disk_by_label("config-2", &device)) {
data_source = SOURCE_CONFIG_DRIVE;
g_strlcpy(config_drive_disk, device, PATH_MAX);
g_free(device);
return true;
for (int tries = 0; tries < 8; tries++) {
if (disk_by_label("config-2", &device)) {
data_source = SOURCE_CONFIG_DRIVE;
g_strlcpy(config_drive_disk, device, PATH_MAX);
g_free(device);
return true;
}

/*
* In case of a VM image with module for cdrom+sr_mod,
* trigger modprobe to reveal config drive, once.
*/
if (tries == 0) {
system("/sbin/modprobe sr_mod");
}

usleep((1 << tries) * 4000);

if (tries > 8)
break;
}

LOG(MOD "config drive was not found\n");
Expand Down

0 comments on commit 533c9a0

Please sign in to comment.