From b17fa998394f4eab9c9dfa88b09f52b2e4fca622 Mon Sep 17 00:00:00 2001 From: Ashraf Fouda Date: Tue, 24 Feb 2026 15:21:20 +0200 Subject: [PATCH] fixes mycelium issues(ifc conflict, corrupted flist, myc issue) Signed-off-by: Ashraf Fouda --- pkg/network/ifaceutil/interface.go | 16 +++++++++++++++- pkg/network/qsfs.go | 17 +++++++++++++++++ pkg/qsfsd/qsfs.go | 15 +++++++++++++-- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/pkg/network/ifaceutil/interface.go b/pkg/network/ifaceutil/interface.go index 7b362d88..5e50f433 100644 --- a/pkg/network/ifaceutil/interface.go +++ b/pkg/network/ifaceutil/interface.go @@ -156,7 +156,21 @@ func MakeVethPair(name, master string, mtu int, netNs ns.NetNS) error { } } - peerName := fmt.Sprintf("p-%s", name) + peerPrefix := "p" + if netNs != nil { + nsName := filepath.Base(netNs.Path()) + + // Use last 4 characters of namespace name, or full name if less than 4 + peerPrefix = nsName + if len(nsName) >= 4 { + peerPrefix = nsName[len(nsName)-4:] + } + + } + peerName := fmt.Sprintf("%s-%s", peerPrefix, name) + if len(peerName) > 15 { + peerName = peerName[0:15] + } if _, err = netlink.LinkByName(peerName); err == nil { return fmt.Errorf("peer already exists %q", peerName) } diff --git a/pkg/network/qsfs.go b/pkg/network/qsfs.go index bd312155..9856f016 100644 --- a/pkg/network/qsfs.go +++ b/pkg/network/qsfs.go @@ -4,11 +4,13 @@ import ( "fmt" "strings" + "github.com/containernetworking/plugins/pkg/ns" "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/threefoldtech/zosbase/pkg/netbase/nft" "github.com/threefoldtech/zosbase/pkg/network/ifaceutil" "github.com/threefoldtech/zosbase/pkg/network/namespace" + "github.com/vishvananda/netlink" ) var _nft = ` @@ -88,6 +90,12 @@ func (n networker) QSFSPrepare(id string) (string, string, error) { return "", "", err } + if n.mycelium != nil { + if _, err := n.attachMycelium(id, netNs); err != nil { + return "", "", errors.Wrap(err, "failed to attach mycelium to qsfs namespace") + } + } + return netNSName, ip.IP.String(), err } @@ -108,5 +116,14 @@ func (n networker) QSFSDestroy(id string) error { // log and continue cleaning up log.Error().Err(err).Msg("couldn't detach ygg interface") } + if err := netNs.Do(func(_ ns.NetNS) error { + link, err := netlink.LinkByName(ZDBMyceliumIface) + if err != nil { + return err + } + return netlink.LinkDel(link) + }); err != nil { + log.Error().Err(err).Msg("couldn't detach mycelium interface") + } return n.destroy(netNSName) } diff --git a/pkg/qsfsd/qsfs.go b/pkg/qsfsd/qsfs.go index e4107e27..af4a0004 100644 --- a/pkg/qsfsd/qsfs.go +++ b/pkg/qsfsd/qsfs.go @@ -125,7 +125,7 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err } env := environment.MustGet() - qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc2.flist") + qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc1.flist") if err != nil { err = errors.Wrap(err, "failed to construct url") return @@ -142,6 +142,10 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err err = errors.Wrap(lerr, "couldn't write qsfs config") return } + if lerr := q.writeHosts(flistPath); lerr != nil { + err = errors.Wrap(lerr, "couldn't write /etc/hosts") + return + } mountPath := q.mountPath(wlID) err = q.prepareMountPath(mountPath) if err != nil { @@ -308,9 +312,16 @@ func (q *QSFS) prepareMountPath(path string) error { return nil } +// for some reason hosts file was corrupted in the flist, we need to rewrite it for zstor to be able to resolve localhost +func (q *QSFS) writeHosts(root string) error { + hostsPath := filepath.Join(root, "etc/hosts") + const hosts = "127.0.0.1\tlocalhost\n::1\t\tlocalhost ip6-localhost ip6-loopback\n" + return os.WriteFile(hostsPath, []byte(hosts), 0644) +} + func (q *QSFS) writeQSFSConfig(root string, cfg zstorConfig) error { cfgPath := filepath.Join(root, "data/zstor.toml") - f, err := os.OpenFile(cfgPath, os.O_WRONLY|os.O_CREATE, 0644) + f, err := os.OpenFile(cfgPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return errors.Wrap(err, "couldn't open zstor config file") }