Skip to content

Commit

Permalink
Use BPF_FS_MAGIC from go sys lib instead of hardcoded
Browse files Browse the repository at this point in the history
This also avoids overflow during conversion. 0xCAFE4A11 is bigger than
the max of int32, so doing int32(uint32(0xCAFE4A11)) (will not compile
directly unless done over two lines) will result in -0x3501b5ef.

Due to some strange errors[0] in the types in "unix.Statfs_t" for 32 bits
systems, we have to explicitly convert to uint to support those (eg.
armv7). If we only need support for 64 bit systems, we can remove the
uint conversion as well.

[0]: For 32bits systems "fsdata.Type" should be uint32 instead of the
current int32, as it is in the linux kernel. This is due to the types in
glibc that the go types are generated from. For 64 bit systems the type
is correctly set to int64.
  • Loading branch information
odinuge committed Feb 28, 2020
1 parent c4f6ad0 commit d03c4a3
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions nodeup/pkg/model/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ func (b *NetworkBuilder) Build(c *fi.ModelBuilderContext) error {
}

// systemd v238 includes the bpffs mount by default; and gives an error "has a bad unit file setting" if we try to mount it again (see mount_point_is_api)
var alreadyMounted bool
// bpffs magic number. See https://github.com/torvalds/linux/blob/v4.8/include/uapi/linux/magic.h#L80
magic := uint32(0xCAFE4A11)

alreadyMounted = int32(magic) == int32(fsdata.Type)
alreadyMounted := uint32(fsdata.Type) == uint32(unix.BPF_FS_MAGIC)

if !alreadyMounted {
unit := s(`
Expand Down

0 comments on commit d03c4a3

Please sign in to comment.