diff --git a/go.mod b/go.mod index 71a48f40..ee8aff9a 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/golang/protobuf v1.5.4 github.com/gorilla/mux v1.8.1 github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9 - github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d + github.com/longhorn/go-common-libs v0.0.0-20240926084818-3a320d860af4 github.com/longhorn/longhorn-engine v1.8.0-dev-20240922 github.com/longhorn/sparse-tools v0.0.0-20240907135423-37af3c64d59d - github.com/longhorn/types v0.0.0-20240902072916-1bf23d310acb + github.com/longhorn/types v0.0.0-20240925015253-4dae7c529d85 github.com/pkg/errors v0.9.1 github.com/rancher/go-fibmap v0.0.0-20160418233256-5fc9f8c1ed47 github.com/sirupsen/logrus v1.9.3 diff --git a/go.sum b/go.sum index ccce1d57..4103b343 100644 --- a/go.sum +++ b/go.sum @@ -76,16 +76,16 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9 h1:ua4PCfArX2TyPVnldF+m7I9c2eGi+TcP8pcPPx2wp0w= github.com/longhorn/backupstore v0.0.0-20240922062439-e33cb1230db9/go.mod h1:UTONYTgRryrw0RgDZbxwU+r1s4PeKQ+v0Z8Pb6jUWn4= -github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d h1:MXJlzyXLptspJEc1UC7ee2eBIYksTl0RT2bXUAXU+8Q= -github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d/go.mod h1:L8QlyY7cqL84FcxnJ8HK6DaQ1Ej9JiZtZ94OW5W+Yyw= +github.com/longhorn/go-common-libs v0.0.0-20240926084818-3a320d860af4 h1:XIVowDtBbw8kAEf0JCCFx5eMyUkuDBhAhpM3WtUAN0U= +github.com/longhorn/go-common-libs v0.0.0-20240926084818-3a320d860af4/go.mod h1:L8QlyY7cqL84FcxnJ8HK6DaQ1Ej9JiZtZ94OW5W+Yyw= github.com/longhorn/go-iscsi-helper v0.0.0-20240921050131-ea564c4f8688 h1:y9icgNMNnDk/mTmgQutXcgirWWtsdZl5fRLKRm44mWg= github.com/longhorn/go-iscsi-helper v0.0.0-20240921050131-ea564c4f8688/go.mod h1:OvkJ/xLpiCScu6SDVZ2y4F70DHxpenMyrHN+wA06nu4= github.com/longhorn/longhorn-engine v1.8.0-dev-20240922 h1:sV9UfurVeEuWx0jaNndtvBJnOR6ZYmrJU3f7pObfLhA= github.com/longhorn/longhorn-engine v1.8.0-dev-20240922/go.mod h1:d5+LbCuwivslvz0Qp0drZ5vyuT+s1NR+v9clerORT58= github.com/longhorn/sparse-tools v0.0.0-20240907135423-37af3c64d59d h1:iNrrGcE9TLcaayQgOkdEZDvlzKCWMNhXXJD2d2K4Wyo= github.com/longhorn/sparse-tools v0.0.0-20240907135423-37af3c64d59d/go.mod h1:iUJCZtOKG/9xv2rfrUAYZntFTzP5dZtvy4Kwe6dMcUc= -github.com/longhorn/types v0.0.0-20240902072916-1bf23d310acb h1:8CoW5YYn+SC43o5zFR+wscOd3SgF6rQZjrkXOkJfZPM= -github.com/longhorn/types v0.0.0-20240902072916-1bf23d310acb/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w= +github.com/longhorn/types v0.0.0-20240925015253-4dae7c529d85 h1:8WJ4HBvbTtF7ge/BBupC/gK/BjOghdY7AHEp7xAq+KQ= +github.com/longhorn/types v0.0.0-20240925015253-4dae7c529d85/go.mod h1:KlJuZB8NfHchWshYxYgV9pPIxBKC04Vq05G2TfgMf7w= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= diff --git a/vendor/github.com/longhorn/go-common-libs/io/file.go b/vendor/github.com/longhorn/go-common-libs/io/file.go index d4ad1c00..aea7fd4b 100644 --- a/vendor/github.com/longhorn/go-common-libs/io/file.go +++ b/vendor/github.com/longhorn/go-common-libs/io/file.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" "github.com/shirou/gopsutil/v3/disk" "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" "github.com/longhorn/go-common-libs/types" ) @@ -227,8 +228,8 @@ func GetDiskStat(path string) (diskStat types.DiskStat, err error) { err = errors.Wrapf(err, "failed to get fs stat for %v", path) }() - var statfs syscall.Statfs_t - if err := syscall.Statfs(path, &statfs); err != nil { + var statfs unix.Statfs_t + if err := unix.Statfs(path, &statfs); err != nil { return diskStat, err } @@ -239,7 +240,7 @@ func GetDiskStat(path string) (diskStat types.DiskStat, err error) { // Convert the FSID components to a single uint64 FSID value var fsidValue uint64 - for _, component := range statfs.Fsid.X__val { + for _, component := range statfs.Fsid.Val { // Combine components using bit manipulation fsidValue = (fsidValue << 32) | uint64(uint32(component)) } @@ -254,9 +255,9 @@ func GetDiskStat(path string) (diskStat types.DiskStat, err error) { Driver: types.DiskDriverNone, FreeBlocks: int64(statfs.Bfree), TotalBlocks: int64(statfs.Blocks), - BlockSize: statfs.Bsize, - StorageMaximum: int64(statfs.Blocks) * statfs.Bsize, - StorageAvailable: int64(statfs.Bfree) * statfs.Bsize, + BlockSize: int64(statfs.Bsize), + StorageMaximum: int64(statfs.Blocks) * int64(statfs.Bsize), + StorageAvailable: int64(statfs.Bfree) * int64(statfs.Bsize), }, nil } diff --git a/vendor/github.com/longhorn/go-common-libs/ns/joiner.go b/vendor/github.com/longhorn/go-common-libs/ns/joiner.go index b62e9c9b..09c7ace1 100644 --- a/vendor/github.com/longhorn/go-common-libs/ns/joiner.go +++ b/vendor/github.com/longhorn/go-common-libs/ns/joiner.go @@ -46,31 +46,6 @@ func (joiners *Joiners) JoinReverse() (err error) { return joiners.Join() } -// Join joins all the namespaces in the Joiners. -func (joiners *Joiners) Join() (err error) { - for _, joiner := range *joiners { - if joiner.isJoined { - logrus.Tracef("Already joined namespace: %s", joiner.namespace) - continue - } - - if joiner.namespace == types.NamespaceMnt { - err := unix.Unshare(unix.CLONE_NEWNS) - if err != nil { - return errors.Wrapf(err, "failed to unshare namespace: %+s", joiner.namespace) - } - } - - if err := unix.Setns(joiner.fd, 0); err != nil { - return errors.Wrapf(err, "failed to set namespace: %+s", joiner.namespace) - } - - joiner.isJoined = true - logrus.Tracef("Joined namespace: %v", joiner.namespace) - } - return nil -} - // Reset resets all the Joiners. func (joiners *Joiners) Reset() (err error) { for _, joiner := range *joiners { @@ -214,7 +189,7 @@ func (jd *JoinerDescriptor) openAndRecordNamespaceFiles(namespace types.Namespac // The original namespace file is the namespace file of the process thread that is // executing the joiner (e.g. /proc/1/task/2/ns/mnt) func (jd *JoinerDescriptor) openAndRecordOriginalNamespaceFile(ns string, namespace types.Namespace) error { - pthreadFile := filepath.Join("/proc", fmt.Sprint(os.Getpid()), "task", fmt.Sprint(unix.Gettid()), "ns", ns) + pthreadFile := filepath.Join("/proc", fmt.Sprint(os.Getpid()), "task", fmt.Sprint(Gettid()), "ns", ns) originFd, err := jd.origin.OpenFile(pthreadFile) if err != nil { return errors.Wrapf(err, "failed to open process thread file %v", pthreadFile) diff --git a/vendor/github.com/longhorn/go-common-libs/ns/joiner_darwin.go b/vendor/github.com/longhorn/go-common-libs/ns/joiner_darwin.go new file mode 100644 index 00000000..4a2a2e05 --- /dev/null +++ b/vendor/github.com/longhorn/go-common-libs/ns/joiner_darwin.go @@ -0,0 +1,10 @@ +package ns + +// Join joins all the namespaces in the Joiners. +func (joiners *Joiners) Join() (err error) { + return nil +} + +func Gettid() int { + return 0 +} diff --git a/vendor/github.com/longhorn/go-common-libs/ns/joiner_linux.go b/vendor/github.com/longhorn/go-common-libs/ns/joiner_linux.go new file mode 100644 index 00000000..a05ce801 --- /dev/null +++ b/vendor/github.com/longhorn/go-common-libs/ns/joiner_linux.go @@ -0,0 +1,38 @@ +package ns + +import ( + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" + + "github.com/longhorn/go-common-libs/types" +) + +// Join joins all the namespaces in the Joiners. +func (joiners *Joiners) Join() (err error) { + for _, joiner := range *joiners { + if joiner.isJoined { + logrus.Tracef("Already joined namespace: %s", joiner.namespace) + continue + } + + if joiner.namespace == types.NamespaceMnt { + err := unix.Unshare(unix.CLONE_NEWNS) + if err != nil { + return errors.Wrapf(err, "failed to unshare namespace: %+s", joiner.namespace) + } + } + + if err := unix.Setns(joiner.fd, 0); err != nil { + return errors.Wrapf(err, "failed to set namespace: %+s", joiner.namespace) + } + + joiner.isJoined = true + logrus.Tracef("Joined namespace: %v", joiner.namespace) + } + return nil +} + +func Gettid() int { + return unix.Gettid() +} diff --git a/vendor/github.com/longhorn/go-common-libs/sys/sys.go b/vendor/github.com/longhorn/go-common-libs/sys/sys.go index e4e23a30..076d3dcc 100644 --- a/vendor/github.com/longhorn/go-common-libs/sys/sys.go +++ b/vendor/github.com/longhorn/go-common-libs/sys/sys.go @@ -6,18 +6,18 @@ import ( "path/filepath" "strconv" "strings" - "syscall" "github.com/pkg/errors" "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" "github.com/longhorn/go-common-libs/types" ) // GetKernelRelease returns the kernel release string. func GetKernelRelease() (string, error) { - utsname := &syscall.Utsname{} - if err := syscall.Uname(utsname); err != nil { + utsname := &unix.Utsname{} + if err := unix.Uname(utsname); err != nil { logrus.WithError(err).Warn("Failed to get kernel release") return "", err } diff --git a/vendor/github.com/longhorn/go-common-libs/types/namespace.go b/vendor/github.com/longhorn/go-common-libs/types/namespace.go index 7358a407..b0c56623 100644 --- a/vendor/github.com/longhorn/go-common-libs/types/namespace.go +++ b/vendor/github.com/longhorn/go-common-libs/types/namespace.go @@ -2,8 +2,6 @@ package types import ( "time" - - "golang.org/x/sys/unix" ) const ( @@ -28,15 +26,6 @@ const ( NamespaceNet = Namespace("net") ) -func (ns Namespace) Flag() uintptr { - switch ns { - case NamespaceNet: - return unix.CLONE_NEWNET - default: - return 0 - } -} - func (ns Namespace) String() string { return string(ns) } diff --git a/vendor/github.com/longhorn/go-common-libs/types/namespace_darwin.go b/vendor/github.com/longhorn/go-common-libs/types/namespace_darwin.go new file mode 100644 index 00000000..baf5465f --- /dev/null +++ b/vendor/github.com/longhorn/go-common-libs/types/namespace_darwin.go @@ -0,0 +1,5 @@ +package types + +func (ns Namespace) Flag() uintptr { + return 0 +} diff --git a/vendor/github.com/longhorn/go-common-libs/types/namespace_linux.go b/vendor/github.com/longhorn/go-common-libs/types/namespace_linux.go new file mode 100644 index 00000000..a0c18fd2 --- /dev/null +++ b/vendor/github.com/longhorn/go-common-libs/types/namespace_linux.go @@ -0,0 +1,14 @@ +package types + +import ( + "golang.org/x/sys/unix" +) + +func (ns Namespace) Flag() uintptr { + switch ns { + case NamespaceNet: + return unix.CLONE_NEWNET + default: + return 0 + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7d2aebd7..1c785ebc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -172,7 +172,7 @@ github.com/longhorn/backupstore/s3 github.com/longhorn/backupstore/types github.com/longhorn/backupstore/util github.com/longhorn/backupstore/vfs -# github.com/longhorn/go-common-libs v0.0.0-20240921050101-797b589b669d +# github.com/longhorn/go-common-libs v0.0.0-20240926084818-3a320d860af4 ## explicit; go 1.22.0 github.com/longhorn/go-common-libs/backup github.com/longhorn/go-common-libs/bitmap @@ -204,7 +204,7 @@ github.com/longhorn/sparse-tools/sparse github.com/longhorn/sparse-tools/sparse/rest github.com/longhorn/sparse-tools/types github.com/longhorn/sparse-tools/util -# github.com/longhorn/types v0.0.0-20240902072916-1bf23d310acb +# github.com/longhorn/types v0.0.0-20240925015253-4dae7c529d85 ## explicit; go 1.21 github.com/longhorn/types/pkg/generated/bimrpc github.com/longhorn/types/pkg/generated/enginerpc