...

Package kmod

import "github.com/pmorjan/kmod"
Overview
Index

Overview ▾

Package kmod provides functions to load and unload Linux kernel modules.

Module dependencies are loaded / unloaded automatically according to <mod_dir>/modules.dep. Compressed module files can be loaded via a custom InitFunc provided by the caller. See SetInitFunc and cmd/modprobe for details.

Variables

ErrModuleInUse is the error resulting if a module can't be unloaded because it is in use.

var ErrModuleInUse = errors.New("module is in use")

ErrModuleNotFound is the error resulting if a module can't be found.

var ErrModuleNotFound = errors.New("module not found")

type InitFunc

InitFunc provides a hook to load a kernel module into the kernel.

type InitFunc func(filename string, params string, flags int) error

type Kmod

Kmod represents internal configuration

type Kmod struct {
    // contains filtered or unexported fields
}

func New

func New(opts ...Option) (*Kmod, error)

New returns a new Kmod.

func (*Kmod) Dependencies

func (k *Kmod) Dependencies(name string) ([]string, error)

Dependencies returns a list of module dependencies.

func (*Kmod) Load

func (k *Kmod) Load(name, params string, flags int) error

Load loads a kernel module. If the module depends on other modules Load will try to load all dependencies first.

func (*Kmod) Unload

func (k *Kmod) Unload(name string) error

Unload unloads a module from the kernel. Unload also tries to unload all module dependencies that are no longer in use.

type Option

Option configures Kmod.

type Option func(*Kmod)

func SetConfigFile

func SetConfigFile(path string) Option

SetConfigFile returns an Option that specifies the (optional) configuration file for modules, default: /etc/modprobe.conf. The config file is used only for module parameters. options <name> parameter [parameter]...

func SetDryrun

func SetDryrun() Option

SetDryrun returns an Option that specifies to do everything but actually load or unload.

func SetIgnoreAlias

func SetIgnoreAlias() Option

SetIgnoreAlias returns an Option that specifies not to consult modules.alias to resolve aliases.

func SetIgnoreBuiltin

func SetIgnoreBuiltin() Option

SetIgnoreBuiltin returns an Option that specifies not to consult modules.builtin to find built-in modules.

func SetIgnoreStatus

func SetIgnoreStatus() Option

SetIgnoreStatus returns an Option that specifies not to consult /proc/modules to get the current status of a module.

func SetInitFunc

func SetInitFunc(fn InitFunc) Option

SetInitFunc returns an Option that sets fn to be used for loading module files into the kernel. The default function tries to use finit_module(2) first and if that failes init_module(2). To support compressed module files see the example cmd/modprobe.

func SetRootDir

func SetRootDir(dir string) Option

SetRootDir returns an Option that sets dir as root directory for modules, default: /lib/modules

func SetVerbose

func SetVerbose() Option

SetVerbose returns an Option that specifies to log info messages about what's going on.