Module is equivalent to [LoadKernelModuleSpec], except that repeated calls do not copy the spec. All modules also share the return value of [Kernel] as their base.
(name string)
| 188 | // |
| 189 | // All modules also share the return value of [Kernel] as their base. |
| 190 | func (c *Cache) Module(name string) (*Spec, error) { |
| 191 | c.mu.RLock() |
| 192 | if spec := c.moduleTypes[name]; spec != nil { |
| 193 | c.mu.RUnlock() |
| 194 | return spec, nil |
| 195 | } |
| 196 | c.mu.RUnlock() |
| 197 | |
| 198 | c.mu.Lock() |
| 199 | defer c.mu.Unlock() |
| 200 | |
| 201 | if spec := c.moduleTypes[name]; spec != nil { |
| 202 | return spec, nil |
| 203 | } |
| 204 | |
| 205 | if c.moduleTypes == nil { |
| 206 | c.moduleTypes = make(map[string]*Spec) |
| 207 | } |
| 208 | |
| 209 | base, err := c.kernel() |
| 210 | if err != nil { |
| 211 | return nil, err |
| 212 | } |
| 213 | |
| 214 | spec, err := loadKernelModuleSpec(name, base) |
| 215 | if err != nil { |
| 216 | return nil, err |
| 217 | } |
| 218 | |
| 219 | c.moduleTypes[name] = spec |
| 220 | return spec, nil |
| 221 | } |
| 222 | |
| 223 | // Modules returns a sorted list of all loaded modules. |
| 224 | func (c *Cache) Modules() ([]string, error) { |