Skip to content

Commit

Permalink
Add uas to the list of default modules
Browse files Browse the repository at this point in the history
Introduce an idea of quirks for modaliases. Some modules do not report
aliases they use. So we just add all registered modaliases to the
booster image.

Closes #121
  • Loading branch information
anatol committed Jan 15, 2022
1 parent 900e9d2 commit c34f823
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var defaultModulesList = []string{
"kernel/drivers/hid/",
"hid_generic", "sd_mod", "ahci",
"sdhci", "sdhci_acpi", "sdhci_pci", "mmc_block", // mmc
"nvme", "usb_storage",
"nvme", "usb_storage", "uas",
"virtio_pci", "virtio_blk", "virtio_scsi", "virtio_crypto",
}

Expand Down
72 changes: 44 additions & 28 deletions generator/kmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,37 +589,59 @@ func (k *Kmod) filterAliasesForRequiredModules(conf *generatorConfig) ([]alias,
}
}

if !k.universal {
devAliases, err := conf.readDeviceAliases() // list of current host aliases as reported by /sys/devices
if k.universal {
return filteredAliases, nil
}

// for a non-universal mode filter out only aliases known to kernel
uniqAliases := make(map[alias]bool)

devAliases, err := conf.readDeviceAliases() // list of current host aliases as reported by /sys/devices
if err != nil {
return nil, err
}
for a := range devAliases {
matched, err := matchAlias(a, filteredAliases)
if err != nil {
return nil, err
}
if len(matched) == 0 {
debug("no matches found for a device alias '%s'", a)
continue
}

// filter out only aliases known to kernel
var newFilteredAliases []alias // aliases for the given devices
uniqAliases := make(map[alias]bool)
for a := range devAliases {
matched, err := matchAlias(a, filteredAliases)
if err != nil {
return nil, err
}
if len(matched) == 0 {
debug("no matches found for a device alias '%s'", a)
continue
}
for _, m := range matched {
uniqAliases[m] = true
}
}

for _, m := range matched {
if _, exists := uniqAliases[m]; exists {
continue
}
uniqAliases[m] = true
newFilteredAliases = append(newFilteredAliases, m)
// quirk: some modules do not report modaliases they use at /sysfs so we just add all aliases for specified modules.
addAllAliasesForModules := []string{
// mmc bus sends an udev event modalias 'mmc:block' (see Linux drivers/mmc/core/bus.c)
// but it seems that this modalias is not reported anywhere under /sys/devices, see https://github.com/anatol/booster/issues/90
"mmc_block",
// uas does not report alias for its USB_PR_BULK interface https://github.com/anatol/booster/issues/121
"uas",
}
for _, m := range addAllAliasesForModules {
if !k.requiredModules[m] {
continue
}

for _, a := range filteredAliases {
if a.module != m {
continue
}
uniqAliases[a] = true
}
filteredAliases = newFilteredAliases
}

return filteredAliases, nil
newFilteredAliases := make([]alias, 0, len(uniqAliases)) // aliases for the given devices
for a := range uniqAliases {
newFilteredAliases = append(newFilteredAliases, a)
}

return newFilteredAliases, nil
}

func readDeviceAliases() (set, error) {
Expand Down Expand Up @@ -650,12 +672,6 @@ func readDeviceAliases() (set, error) {
return nil
})

// Buses might have associated modaliases e.g. mmc bus sends an udev event modalias 'mmc:block' (see Linux drivers/mmc/core/bus.c)
// But it seems that this modalias is not reported anywhere under /sys/devices, see https://github.com/anatol/booster/issues/90

// insert implicit modaliases. TODO: find a more straightforward way to detect all buses modaliases
aliases["mmc:block"] = true

return aliases, err
}

Expand Down

0 comments on commit c34f823

Please sign in to comment.