Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/cloudproxy/agent/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ package worker

import (
"context"
"net"
"runtime"
"runtime/debug"
"sync"
"time"

"github.com/vishvananda/netlink"

"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/version"
Expand Down Expand Up @@ -99,14 +98,15 @@ func (w *Worker) initProxyAgent_(ctx context.Context) error {
}

bindAddrExist := func(addr string) bool {
as, err := netlink.AddrList(nil, netlink.FAMILY_ALL)
addrs, err := net.InterfaceAddrs()
if err != nil {
log.Fatalf("list system available addresses: %v", err)
}
for _, a := range as {
ipstr := a.IPNet.IP.String()
if addr == ipstr {
return true
for _, a := range addrs {
if ipnet, ok := a.(*net.IPNet); ok {
if addr == ipnet.IP.String() {
return true
}
}
}
return false
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostimage/nbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (m *SNbdExportManager) QemuNbdStartExport(imageInfo qemuimg.SImageInfo, dis
cmdStr := strings.Join(cmd, " ")
err = procutils.NewRemoteCommandAsFarAsPossible("sh", "-c", cmdStr).Run()
if err != nil {
log.Errorf("qemu-nbd connect failed %s %s", err.Error())
log.Errorf("qemu-nbd connect failed %s %s", cmdStr, err.Error())
return -1, errors.Wrapf(err, "qemu-nbd connect failed")
}
return nbdPort, nil
Expand Down
9 changes: 9 additions & 0 deletions pkg/hostman/container/snapshot_service/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package snapshot_service

type IGuestManager interface {
GetContainerManager(serverId string) (ISnapshotContainerManager, error)
}

type ISnapshotContainerManager interface {
GetRootFsMountPath(containerId string) (string, error)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

package snapshot_service

import (
Expand Down Expand Up @@ -38,14 +41,6 @@ func StartService(guestMan IGuestManager, root string) error {
return rpc.Serve(listener)
}

type IGuestManager interface {
GetContainerManager(serverId string) (ISnapshotContainerManager, error)
}

type ISnapshotContainerManager interface {
GetRootFsMountPath(containerId string) (string, error)
}

func NewSnapshotter(guestMan IGuestManager, root string, opts ...overlay.Opt) (snapshots.Snapshotter, error) {
sn, err := overlay.NewSnapshotter(root, opts...)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/hostman/container/snapshot_service/snapshot_service_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !linux
// +build !linux

package snapshot_service

import (
"yunion.io/x/pkg/errors"
)

func StartService(guestMan IGuestManager, root string) error {
return errors.ErrNotImplemented
}
36 changes: 23 additions & 13 deletions pkg/hostman/guestman/qemu-kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2561,21 +2561,31 @@ func (s *SKVMGuestInstance) onNicChange(oldNic, newNic *desc.SGuestNetwork) erro
} else {
// bridge not changed
if oldifname == newifname {
if newvlan > 1 {
output, err := procutils.NewRemoteCommandAsFarAsPossible("ovs-vsctl", "set", "port", newifname, fmt.Sprintf("tag=%d", newvlan)).Output()
if err != nil {
return errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible change vlan tag to %d: %s", newvlan, output)
if oldNic.Bw != newNic.Bw {
log.Infof("Nic %s bw changed %d -> %d", newNic.Mac, oldNic.Bw, newNic.Bw)
if err := s.generateNicScripts(newNic); err != nil {
return errors.Wrap(err, "generateNicScripts update bandwidth")
}
} else {
// clear vlan
output, err := procutils.NewRemoteCommandAsFarAsPossible("ovs-vsctl", "get", "port", newifname, "tag").Output()
if err != nil {
return errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible get vlan tag: %s", output)
if err := s.SetNicUp(newNic); err != nil {
return errors.Wrap(err, "SetNicUp update bandwidth")
}
tagStr := strings.TrimSpace(string(output))
if tag, err := strconv.Atoi(tagStr); err == nil && tag > 1 {
if output, err := procutils.NewRemoteCommandAsFarAsPossible("ovs-vsctl", "remove", "port", newifname, "tag", tagStr).Output(); err != nil {
return errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible remove vlan tag %s: %s", tagStr, output)
} else {
if newvlan > 1 {
output, err := procutils.NewRemoteCommandAsFarAsPossible("ovs-vsctl", "set", "port", newifname, fmt.Sprintf("tag=%d", newvlan)).Output()
if err != nil {
return errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible change vlan tag to %d: %s", newvlan, output)
}
} else {
// clear vlan
output, err := procutils.NewRemoteCommandAsFarAsPossible("ovs-vsctl", "get", "port", newifname, "tag").Output()
if err != nil {
return errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible get vlan tag: %s", output)
}
tagStr := strings.TrimSpace(string(output))
if tag, err := strconv.Atoi(tagStr); err == nil && tag > 1 {
if output, err := procutils.NewRemoteCommandAsFarAsPossible("ovs-vsctl", "remove", "port", newifname, "tag", tagStr).Output(); err != nil {
return errors.Wrapf(err, "NewRemoteCommandAsFarAsPossible remove vlan tag %s: %s", tagStr, output)
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/hostman/storageman/imagecache_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ func (l *SLocalImageCache) Load() error {
if fi != nil {
desc.SizeMb = fi.Size() / 1024 / 1024
if fi.Sys() != nil {
atime := fi.Sys().(*syscall.Stat_t).Atim
desc.AccessAt = time.Unix(atime.Sec, atime.Nsec)
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
desc.AccessAt = fileutils2.GetAtim(stat)
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/hostman/storageman/remotefile/remotefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ func (r *SRemoteFile) GetInfo() (*SImageDesc, error) {

var atime time.Time
if fi.Sys() != nil {
atm := fi.Sys().(*syscall.Stat_t).Atim
atime = time.Unix(atm.Sec, atm.Nsec)
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
atime = fileutils2.GetAtim(stat)
}
}

return &SImageDesc{
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/cgrouputils/cgroupv1/cpuutils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/cgrouputils/cgroupv1/cpuutils_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/cgrouputils/cgroupv1/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/cgrouputils/cgroupv1/manager.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
57 changes: 35 additions & 22 deletions pkg/util/cgrouputils/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cgrouputils

import (
"runtime"
"strings"

"yunion.io/x/pkg/errors"
Expand Down Expand Up @@ -89,29 +90,41 @@ func Init(ioScheduler string) error {
return nil
}

cgroupPath := ""
if fileutils2.Exists(CGROUP_PATH_SYSFS) {
cgroupPath = CGROUP_PATH_SYSFS
} else if fileutils2.Exists("CGROUP_PATH_ROOT") {
cgroupPath = CGROUP_PATH_ROOT
}
if cgroupPath == "" {
return errors.Errorf("Can't detect cgroup path")
}
output, err := procutils.NewCommand("stat", "-fc", "%T", cgroupPath).Output()
if err != nil {
return errors.Wrapf(err, "stat cgroup path %s", cgroupPath)
}
cgroupfs := strings.TrimSpace(string(output))
if cgroupfs == "cgroup2fs" {
// cgroup v2
cgroupManager, err = cgroupv2.Init(cgroupPath, ioScheduler)
if runtime.GOOS == "linux" {
var cgroupPath string
if fileutils2.Exists(CGROUP_PATH_SYSFS) {
cgroupPath = CGROUP_PATH_SYSFS
} else if fileutils2.Exists("CGROUP_PATH_ROOT") {
cgroupPath = CGROUP_PATH_ROOT
}
if cgroupPath == "" {
return errors.Errorf("Can't detect cgroup path")
}

output, err := procutils.NewCommand("stat", "-fc", "%T", cgroupPath).Output()
if err != nil {
return errors.Wrapf(err, "stat cgroup path %s", cgroupPath)
}
cgroupfs := strings.TrimSpace(string(output))
var mgr ICgroupManager
if cgroupfs == "cgroup2fs" {
// cgroup v2
mgr, err = cgroupv2.Init(cgroupPath, ioScheduler)
} else {
// cgroup v1
mgr, err = cgroupv1.Init(cgroupPath, ioScheduler)
}
if err != nil {
return errors.Wrap(err, "init cgroup")
}
cgroupManager = mgr
} else {
// cgroup v1
cgroupManager, err = cgroupv1.Init(cgroupPath, ioScheduler)
}
if err != nil {
return errors.Wrap(err, "init cgroup")
// fallback for non-linux
mgr, err := cgroupv1.Init("", ioScheduler)
if err != nil {
return errors.Wrap(err, "init cgroup stub")
}
cgroupManager = mgr
}
return nil
}
13 changes: 13 additions & 0 deletions pkg/util/fileutils2/fileutils_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !linux
// +build !linux

package fileutils2

import (
"syscall"
"time"
)

func GetAtim(stat *syscall.Stat_t) time.Time {
return time.Unix(stat.Atimespec.Sec, stat.Atimespec.Nsec)
}
13 changes: 13 additions & 0 deletions pkg/util/fileutils2/fileutils_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build linux
// +build linux

package fileutils2

import (
"syscall"
"time"
)

func GetAtim(stat *syscall.Stat_t) time.Time {
return time.Unix(stat.Atim.Sec, stat.Atim.Nsec)
}
3 changes: 3 additions & 0 deletions pkg/util/iproute2/address_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
14 changes: 14 additions & 0 deletions pkg/util/iproute2/address_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ func (address *Address) Add() *Address {
}
return address
}

func (address *Address) Del() *Address {
link, ok := address.link()
if !ok {
return address
}
for _, addr := range address.addrs {
err := netlink.AddrDel(link, addr)
if err != nil {
address.addErr(err, "Del: AddrDel %s ", addr)
}
}
return address
}
3 changes: 3 additions & 0 deletions pkg/util/iproute2/address_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/iproute2/link_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
10 changes: 7 additions & 3 deletions pkg/util/netutils2/netutils_others.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !linux
// +build !linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,9 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !linux
// +build !linux

package netutils2

import (
Expand Down Expand Up @@ -42,6 +42,10 @@ func (n *SNetInterface) ClearAddrs() error {
return nil
}

func (n *SNetInterface) FlushAddrs() error {
return nil
}

func DefaultSrcIpDev() (srcIp net.IP, ifname string, err error) {
err = errors.ErrNotImplemented
return
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/netutils2/netutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package netutils2
import (
"os"
"reflect"
"runtime"
"testing"

"yunion.io/x/jsonutils"
Expand Down Expand Up @@ -97,6 +98,9 @@ func TestNewNetInterface(t *testing.T) {
}

func TestMyDefault(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("DefaultSrcIpDev not implemented on non-linux")
}
myip, err := MyIP()
if err != nil {
// Skip if it's no route to host
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/pod/cadvisor/cadvisor.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/pod/cadvisor/cadvisor_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !linux
// +build !linux

package cadvisor

import (
"yunion.io/x/pkg/errors"
)

func New(imageFsInfoProvider ImageFsInfoProvider, rootPath string, cgroupRoots []string) (Interface, error) {
return nil, errors.ErrNotImplemented
}
3 changes: 3 additions & 0 deletions pkg/util/pod/cadvisor/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build linux
// +build linux

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading