Skip to content

Commit

Permalink
Merge pull request #79 from containers/bootfs_hint
Browse files Browse the repository at this point in the history
Add support for bootfs_hint during installation
  • Loading branch information
ericcurtin authored Mar 15, 2024
2 parents 8de95f1 + 12492c7 commit f482483
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
6 changes: 4 additions & 2 deletions bin/initoverlayfs-install
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ fi
detect_path_initramfs

if ! [ -e "$INITOVERLAYFS_CONF" ] || ! grep -q '[^[:space:]]' "$INITOVERLAYFS_CONF"; then
boot_partition=$(< /etc/fstab grep "${INITRAMFS_DIR}.*ext4" | awk '{print $1}')
boot_partition=$(grep "${INITRAMFS_DIR}.*ext4" /etc/fstab | awk '{print $1}')
boot_partition_hint=$(blkid -t $boot_partition | awk -F: '{print $1}')

printf "%s\n%s\n%s\n%s" \
printf "%s\n%s\n%s\n%s\n" \
"bootfs $boot_partition" \
"bootfs_hint $boot_partition_hint" \
"bootfstype ext4" \
"initoverlayfs_builder dracut -M -o \"initoverlayfs fcoe\"" > $INITOVERLAYFS_CONF

Expand Down
15 changes: 12 additions & 3 deletions config-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ static inline bool is_line_key(const str* line, const str* key) {
static inline int conf_construct(conf* c) {
c->bootfs.val = (str*)calloc(1, sizeof(str));
c->bootfs.scoped = (str*)calloc(1, sizeof(str));
c->bootfs_hint.val = (str*)calloc(1, sizeof(str));
c->bootfs_hint.scoped = (str*)calloc(1, sizeof(str));
c->bootfstype.val = (str*)calloc(1, sizeof(str));
c->bootfstype.scoped = (str*)calloc(1, sizeof(str));
c->fs.val = (str*)calloc(1, sizeof(str));
c->fs.scoped = (str*)calloc(1, sizeof(str));
c->fstype.val = (str*)calloc(1, sizeof(str));
c->fstype.scoped = (str*)calloc(1, sizeof(str));
return !c->bootfs.val || !c->bootfs.scoped || !c->bootfstype.val ||
return !c->bootfs.val || !c->bootfs.scoped || !c->bootfs_hint.val ||
!c->bootfs_hint.scoped || !c->bootfstype.val ||
!c->bootfstype.scoped || !c->fs.val || !c->fs.scoped ||
!c->fstype.val || !c->fstype.scoped;
}
Expand All @@ -32,13 +35,17 @@ static inline void set_conf(pair* conf, str** line, const size_t key_len) {

static inline void conf_set_pick(conf* c, str** line) {
const str bootfs_str = {.c_str = "bootfs", .len = sizeof("bootfs") - 1};
const str bootfs_hint_str = {.c_str = "bootfs_hint",
.len = sizeof("bootfs_hint") - 1};
const str bootfstype_str = {.c_str = "bootfstype",
.len = sizeof("bootfstype") - 1};
const str fs_str = {.c_str = "fs", .len = sizeof("fs") - 1};
const str fstype_str = {.c_str = "fstype", .len = sizeof("fstype") - 1};

if (is_line_key(*line, &bootfs_str))
set_conf(&c->bootfs, line, bootfs_str.len);
else if (is_line_key(*line, &bootfs_hint_str))
set_conf(&c->bootfs_hint, line, bootfs_hint_str.len);
else if (is_line_key(*line, &bootfstype_str))
set_conf(&c->bootfstype, line, bootfstype_str.len);
else if (is_line_key(*line, &fs_str))
Expand All @@ -50,9 +57,11 @@ static inline void conf_set_pick(conf* c, str** line) {
static inline conf* conf_print(conf* c) {
#ifdef DEBUG
printd(
"bootfs: {\"%s\", \"%s\"}, bootfstype: {\"%s\", \"%s\"}, fs: {\"%s\", "
"bootfs: {\"%s\", \"%s\"}, bootfs_hint: {\"%s\", \"%s\"}, bootfstype: "
"{\"%s\", \"%s\"}, fs: {\"%s\", "
"\"%s\"}, fstype: {\"%s\", \"%s\"}\n",
c->bootfs.val->c_str, c->bootfs.scoped->c_str, c->bootfstype.val->c_str,
c->bootfs.val->c_str, c->bootfs.scoped->c_str, c->bootfs_hint.val->c_str,
c->bootfs_hint.scoped->c_str, c->bootfstype.val->c_str,
c->bootfstype.scoped->c_str, c->fs.val->c_str, c->fs.scoped->c_str,
c->fstype.val->c_str, c->fstype.scoped->c_str);
#endif
Expand Down
30 changes: 19 additions & 11 deletions initoverlayfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,22 @@ static bool convert_bootfs(conf* c, const bool systemd) {

// Open the cache
if (blkid_get_cache(&cache, read))
print("blkid_get_cache(%p, \"%s\")\n", &cache, read ? read : NULL);

if (blkid_probe_all(cache))
print("blkid_probe_all(%p)\n", &cache);
print("blkid_get_cache(?, \"%s\")\n", read ? read : "NULL");

const char* type = strtok(c->bootfs.val->c_str, "=");
const char* value = strtok(NULL, "=");

const blkid_dev b_dev = blkid_find_dev_with_tag(cache, type, value);
if (asprintf(&bootfs_tmp, "%s", blkid_dev_devname(b_dev)) < 0)
return false;
if (c->bootfs_hint.val->c_str && c->bootfs_hint.val->c_str[0] &&
!strcmp(value,
blkid_get_tag_value(cache, type, c->bootfs_hint.val->c_str))) {
bootfs_tmp = strdup(c->bootfs_hint.val->c_str);
} else {
if (blkid_probe_all(cache))
print("blkid_probe_all()\n");

const blkid_dev b_dev = blkid_find_dev_with_tag(cache, type, value);
if (asprintf(&bootfs_tmp, "%s", blkid_dev_devname(b_dev)) < 0)
return false;
}

blkid_put_cache(cache);
}
Expand Down Expand Up @@ -577,16 +582,19 @@ int main(int argc, char* argv[]) {
if (!systemd) {
mount_proc_sys_dev();
log_open_kmsg();
kmsg_f = kmsg_f_scoped;
kmsg_f_scoped = kmsg_f;
}

pid_t loop_pid = 0;
if (systemd) {
fork_execl_no_wait(loop_pid, "/usr/sbin/modprobe", "loop");
}

autofree_conf conf conf = {
.bootfs = {0, 0}, .bootfstype = {0, 0}, .fs = {0, 0}, .fstype = {0, 0}};
autofree_conf conf conf = {.bootfs = {0, 0},
.bootfs_hint = {0, 0},
.bootfstype = {0, 0},
.fs = {0, 0},
.fstype = {0, 0}};
if (conf_construct(&conf))
return 0;

Expand Down
5 changes: 5 additions & 0 deletions initoverlayfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef struct pair {

typedef struct conf {
pair bootfs;
pair bootfs_hint;
pair bootfstype;
pair fs;
pair fstype;
Expand All @@ -68,6 +69,8 @@ typedef struct conf {
static inline void cleanup_free_conf(conf* p) {
if (p->bootfs.scoped)
free(p->bootfs.scoped->c_str);
if (p->bootfs_hint.scoped)
free(p->bootfs_hint.scoped->c_str);
if (p->bootfstype.scoped)
free(p->bootfstype.scoped->c_str);
if (p->fs.scoped)
Expand All @@ -76,10 +79,12 @@ static inline void cleanup_free_conf(conf* p) {
free(p->fstype.scoped->c_str);

free(p->bootfs.scoped);
free(p->bootfs_hint.scoped);
free(p->bootfstype.scoped);
free(p->fs.scoped);
free(p->fstype.scoped);
free(p->bootfs.val);
free(p->bootfs_hint.val);
free(p->bootfstype.val);
free(p->fs.val);
free(p->fstype.val);
Expand Down

0 comments on commit f482483

Please sign in to comment.