LoadPinnedMap opens a Map from a pin (file) on the BPF virtual filesystem. Requires at least Linux 4.5.
(fileName string, opts *LoadPinOptions)
| 1729 | // |
| 1730 | // Requires at least Linux 4.5. |
| 1731 | func LoadPinnedMap(fileName string, opts *LoadPinOptions) (*Map, error) { |
| 1732 | fd, typ, err := sys.ObjGetTyped(&sys.ObjGetAttr{ |
| 1733 | Pathname: sys.NewStringPointer(fileName), |
| 1734 | FileFlags: opts.Marshal(), |
| 1735 | }) |
| 1736 | if err != nil { |
| 1737 | return nil, err |
| 1738 | } |
| 1739 | |
| 1740 | if typ != sys.BPF_TYPE_MAP { |
| 1741 | _ = fd.Close() |
| 1742 | return nil, fmt.Errorf("%s is not a Map", fileName) |
| 1743 | } |
| 1744 | |
| 1745 | m, err := newMapFromFD(fd) |
| 1746 | if err == nil { |
| 1747 | m.pinnedPath = fileName |
| 1748 | } |
| 1749 | |
| 1750 | return m, err |
| 1751 | } |
| 1752 | |
| 1753 | // unmarshalMap creates a map from a map ID encoded in host endianness. |
| 1754 | func unmarshalMap(buf sysenc.Buffer) (*Map, error) { |
searching dependent graphs…