aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/linux
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-11-11 03:20:49 +0100
committerAleksandr Nogikh <nogikh@google.com>2023-11-22 13:37:46 +0000
commit03e12510535a17bacc1346348437ae99fd98efd7 (patch)
treef595b0048eab05392def77ce871de8b403f66cb0 /pkg/subsystem/linux
parent7fd9c93a8ce52264c1c63d8ee0ea0f17c4d6fec1 (diff)
pkg/subsystem: move wireless under net
It will help keep more generic reports in "net".
Diffstat (limited to 'pkg/subsystem/linux')
-rw-r--r--pkg/subsystem/linux/names.go14
-rw-r--r--pkg/subsystem/linux/rules.go6
-rw-r--r--pkg/subsystem/linux/subsystems.go31
-rw-r--r--pkg/subsystem/linux/subsystems_test.go25
4 files changed, 64 insertions, 12 deletions
diff --git a/pkg/subsystem/linux/names.go b/pkg/subsystem/linux/names.go
index 02683755b..1fd6ddb00 100644
--- a/pkg/subsystem/linux/names.go
+++ b/pkg/subsystem/linux/names.go
@@ -14,17 +14,17 @@ import (
// setSubsystemNames assigns unique names to the presented subsystems.
// If it failed to assign a name to a subsystem, the Name field remains empty.
func setSubsystemNames(list []*subsystem.Subsystem) error {
- dups := map[string]string{}
+ dupEmails := map[string]string{}
for _, item := range list {
if item.Name == "" {
continue
}
- if dups[item.Name] != "" {
+ if _, ok := dupEmails[item.Name]; ok {
return fmt.Errorf("duplicate name: %q", item.Name)
}
- dups[item.Name] = item.Name
+ // We do not know the email.
+ dupEmails[item.Name] = ""
}
-
for _, item := range list {
if item.Name != "" {
continue
@@ -38,11 +38,11 @@ func setSubsystemNames(list []*subsystem.Subsystem) error {
if !validateName(name) {
return fmt.Errorf("failed to extract a name from %s", email)
}
- if dups[name] != "" {
- return fmt.Errorf("duplicate subsystem name: %q and %q", dups[name], email)
+ if other, ok := dupEmails[name]; ok {
+ return fmt.Errorf("duplicate subsystem name %v: emails %q and %q", name, other, email)
}
item.Name = name
- dups[name] = email
+ dupEmails[name] = email
}
return nil
}
diff --git a/pkg/subsystem/linux/rules.go b/pkg/subsystem/linux/rules.go
index b9e78a9a5..c2ed6451a 100644
--- a/pkg/subsystem/linux/rules.go
+++ b/pkg/subsystem/linux/rules.go
@@ -14,6 +14,8 @@ type customRules struct {
extraSubsystems map[string][]string
// For these subsystems we do not generate monthly reminders.
noReminders map[string]struct{}
+ // Extra child->[]parent links (on top of the inferred ones).
+ addParents map[string][]string
}
var (
@@ -98,5 +100,9 @@ var (
// in generating monthly reports for it.
"kernel": {},
},
+ addParents: map[string][]string{
+ // By MAINTAINERS, wireless is somewhat separate, but it's better to keep it as a net child.
+ "wireless": {"net"},
+ },
}
)
diff --git a/pkg/subsystem/linux/subsystems.go b/pkg/subsystem/linux/subsystems.go
index 38473c901..e5b44a02e 100644
--- a/pkg/subsystem/linux/subsystems.go
+++ b/pkg/subsystem/linux/subsystems.go
@@ -45,7 +45,9 @@ func listFromRepoInner(root fs.FS, rules *customRules) ([]*subsystem.Subsystem,
if err := setSubsystemNames(list); err != nil {
return nil, fmt.Errorf("failed to set names: %w", err)
}
- ctx.applyExtraRules(list)
+ if err := ctx.applyExtraRules(list); err != nil {
+ return nil, fmt.Errorf("failed to apply extra rules: %w", err)
+ }
// Sort subsystems by name to keep output consistent.
sort.Slice(list, func(i, j int) bool { return list[i].Name < list[j].Name })
@@ -135,14 +137,37 @@ func (ctx *linuxCtx) groupByRules() ([]*subsystem.Subsystem, error) {
return ret, nil
}
-func (ctx *linuxCtx) applyExtraRules(list []*subsystem.Subsystem) {
+func (ctx *linuxCtx) applyExtraRules(list []*subsystem.Subsystem) error {
if ctx.extraRules == nil {
- return
+ return nil
}
+ perName := map[string]*subsystem.Subsystem{}
for _, entry := range list {
entry.Syscalls = ctx.extraRules.subsystemCalls[entry.Name]
_, entry.NoReminders = ctx.extraRules.noReminders[entry.Name]
+ perName[entry.Name] = entry
+ }
+ for from, toNames := range ctx.extraRules.addParents {
+ item := perName[from]
+ if item == nil {
+ return fmt.Errorf("unknown subsystem: %q", from)
+ }
+ exists := map[string]bool{}
+ for _, p := range item.Parents {
+ exists[p.Name] = true
+ }
+ for _, toName := range toNames {
+ if exists[toName] {
+ continue
+ }
+ if perName[toName] == nil {
+ return fmt.Errorf("unknown parent subsystem: %q", toName)
+ }
+ item.Parents = append(item.Parents, perName[toName])
+ }
}
+ transitiveReduction(list)
+ return nil
}
func mergeRawRecords(records []*maintainersRecord, email string) *subsystem.Subsystem {
diff --git a/pkg/subsystem/linux/subsystems_test.go b/pkg/subsystem/linux/subsystems_test.go
index 7e6869161..a3aa79b93 100644
--- a/pkg/subsystem/linux/subsystems_test.go
+++ b/pkg/subsystem/linux/subsystems_test.go
@@ -168,14 +168,35 @@ func TestLinuxSubsystemParents(t *testing.T) {
if err != nil {
t.Fatal(err)
}
-
- expectParents := map[string][]string{
+ ensureParents(t, subsystems, map[string][]string{
"ext4": {"fs"},
"mm": {"kernel"},
"fs": {"kernel"},
"tmpfs": {"mm"},
"freevxfs": {"fs"},
+ })
+
+ // Now check that our custom parent rules work.
+ subsystems2, err := listFromRepoInner(repo, &customRules{
+ addParents: map[string][]string{
+ // Just for the sake of testing.
+ "fs": {"mm"},
+ },
+ })
+ if err != nil {
+ t.Fatal(err)
}
+ ensureParents(t, subsystems2, map[string][]string{
+ "ext4": {"fs"},
+ "mm": {"kernel"},
+ "fs": {"mm"}, // We test for this change.
+ "tmpfs": {"mm"},
+ "freevxfs": {"fs"},
+ })
+}
+
+func ensureParents(t *testing.T, subsystems []*subsystem.Subsystem,
+ expectParents map[string][]string) {
for _, s := range subsystems {
names := []string{}
for _, p := range s.Parents {