Skip to content

Commit

Permalink
fix: only count hard-links once when calculating filesystem usage (pt…
Browse files Browse the repository at this point in the history
…erodactyl#181)

docker: add option to NOT create IPV6 interface in the network used by servers

Logging to check if this is working

Properly disabling ipv6
  • Loading branch information
EpicPlayerA10 authored and paulohgodinho committed Jul 7, 2024
1 parent 934bf24 commit 719ded5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
17 changes: 9 additions & 8 deletions config/config_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ type DockerNetworkConfiguration struct {
// The name of the network to use. If this network already exists it will not
// be created. If it is not found, a new network will be created using the interface
// defined.
Name string `default:"pterodactyl_nw"`
ISPN bool `default:"false" yaml:"ispn"`
Driver string `default:"bridge"`
Mode string `default:"pterodactyl_nw" yaml:"network_mode"`
IsInternal bool `default:"false" yaml:"is_internal"`
EnableICC bool `default:"true" yaml:"enable_icc"`
NetworkMTU int64 `default:"1500" yaml:"network_mtu"`
Interfaces dockerNetworkInterfaces `yaml:"interfaces"`
Name string `default:"pterodactyl_nw"`
ISPN bool `default:"false" yaml:"ispn"`
Driver string `default:"bridge"`
Mode string `default:"pterodactyl_nw" yaml:"network_mode"`
IsInternal bool `default:"false" yaml:"is_internal"`
EnableICC bool `default:"true" yaml:"enable_icc"`
NetworkMTU int64 `default:"1500" yaml:"network_mtu"`
Interfaces dockerNetworkInterfaces `yaml:"interfaces"`
DisableIPv6InterfaceCreation bool `default:"false" yaml:"disable_ipv6_interface_creation"`
}

// DockerConfiguration defines the docker configuration used by the daemon when
Expand Down
28 changes: 20 additions & 8 deletions environment/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,30 @@ func ConfigureDocker(ctx context.Context) error {
// Creates a new network on the machine if one does not exist already.
func createDockerNetwork(ctx context.Context, cli *client.Client) error {
nw := config.Get().Docker.Network

ipamConfig := []network.IPAMConfig{{
Subnet: nw.Interfaces.V4.Subnet,
Gateway: nw.Interfaces.V4.Gateway,
}}

if nw.DisableIPv6InterfaceCreation == false {
log.Info("Creating IPv6 interface, 'DisableIPv6InterfaceCreation' is false")
ipV6 := network.IPAMConfig{
Subnet: nw.Interfaces.V6.Subnet,
Gateway: nw.Interfaces.V6.Gateway,
}

ipamConfig = append(ipamConfig, ipV6)
} else {
log.Info("Not creating IPv6 interface, 'DisableIPv6InterfaceCreation' is true")
}

_, err := cli.NetworkCreate(ctx, nw.Name, types.NetworkCreate{
Driver: nw.Driver,
EnableIPv6: true,
EnableIPv6: !nw.DisableIPv6InterfaceCreation,
Internal: nw.IsInternal,
IPAM: &network.IPAM{
Config: []network.IPAMConfig{{
Subnet: nw.Interfaces.V4.Subnet,
Gateway: nw.Interfaces.V4.Gateway,
}, {
Subnet: nw.Interfaces.V6.Subnet,
Gateway: nw.Interfaces.V6.Gateway,
}},
Config: ipamConfig,
},
Options: map[string]string{
"encryption": "false",
Expand Down
16 changes: 14 additions & 2 deletions server/filesystem/disk_space.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package filesystem

import (
"golang.org/x/sys/unix"
"slices"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -164,6 +166,8 @@ func (fs *Filesystem) DirectorySize(root string) (int64, error) {
return 0, err
}

var hardLinks []uint64

var size atomic.Int64
err = fs.unixFS.WalkDirat(dirfd, name, func(dirfd int, name, _ string, d ufs.DirEntry, err error) error {
if err != nil {
Expand All @@ -180,8 +184,16 @@ func (fs *Filesystem) DirectorySize(root string) (int64, error) {
return errors.Wrap(err, "lstatat err")
}

// TODO: detect if info is a hard-link and de-duplicate it.
// ref; https://github.com/pterodactyl/wings/pull/181/files
var sysFileInfo = info.Sys().(*unix.Stat_t)
if sysFileInfo.Nlink > 1 {
// Hard links have the same inode number
if slices.Contains(hardLinks, sysFileInfo.Ino) {
// Don't add hard links size twice
return nil
} else {
hardLinks = append(hardLinks, sysFileInfo.Ino)
}
}

size.Add(info.Size())
return nil
Expand Down

0 comments on commit 719ded5

Please sign in to comment.