Skip to content

Commit f0509fc

Browse files
authored
fixes mycelium issues(ifc conflict, corrupted flist, myc issue) (#99)
Signed-off-by: Ashraf Fouda <ashraf.m.fouda@gmail.com>
1 parent b508541 commit f0509fc

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

pkg/network/ifaceutil/interface.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,21 @@ func MakeVethPair(name, master string, mtu int, netNs ns.NetNS) error {
156156
}
157157
}
158158

159-
peerName := fmt.Sprintf("p-%s", name)
159+
peerPrefix := "p"
160+
if netNs != nil {
161+
nsName := filepath.Base(netNs.Path())
162+
163+
// Use last 4 characters of namespace name, or full name if less than 4
164+
peerPrefix = nsName
165+
if len(nsName) >= 4 {
166+
peerPrefix = nsName[len(nsName)-4:]
167+
}
168+
169+
}
170+
peerName := fmt.Sprintf("%s-%s", peerPrefix, name)
171+
if len(peerName) > 15 {
172+
peerName = peerName[0:15]
173+
}
160174
if _, err = netlink.LinkByName(peerName); err == nil {
161175
return fmt.Errorf("peer already exists %q", peerName)
162176
}

pkg/network/qsfs.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/containernetworking/plugins/pkg/ns"
78
"github.com/pkg/errors"
89
"github.com/rs/zerolog/log"
910
"github.com/threefoldtech/zosbase/pkg/netbase/nft"
1011
"github.com/threefoldtech/zosbase/pkg/network/ifaceutil"
1112
"github.com/threefoldtech/zosbase/pkg/network/namespace"
13+
"github.com/vishvananda/netlink"
1214
)
1315

1416
var _nft = `
@@ -88,6 +90,12 @@ func (n networker) QSFSPrepare(id string) (string, string, error) {
8890
return "", "", err
8991
}
9092

93+
if n.mycelium != nil {
94+
if _, err := n.attachMycelium(id, netNs); err != nil {
95+
return "", "", errors.Wrap(err, "failed to attach mycelium to qsfs namespace")
96+
}
97+
}
98+
9199
return netNSName, ip.IP.String(), err
92100
}
93101

@@ -108,5 +116,14 @@ func (n networker) QSFSDestroy(id string) error {
108116
// log and continue cleaning up
109117
log.Error().Err(err).Msg("couldn't detach ygg interface")
110118
}
119+
if err := netNs.Do(func(_ ns.NetNS) error {
120+
link, err := netlink.LinkByName(ZDBMyceliumIface)
121+
if err != nil {
122+
return err
123+
}
124+
return netlink.LinkDel(link)
125+
}); err != nil {
126+
log.Error().Err(err).Msg("couldn't detach mycelium interface")
127+
}
111128
return n.destroy(netNSName)
112129
}

pkg/qsfsd/qsfs.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err
125125
}
126126

127127
env := environment.MustGet()
128-
qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc2.flist")
128+
qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc1.flist")
129129
if err != nil {
130130
err = errors.Wrap(err, "failed to construct url")
131131
return
@@ -142,6 +142,10 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err
142142
err = errors.Wrap(lerr, "couldn't write qsfs config")
143143
return
144144
}
145+
if lerr := q.writeHosts(flistPath); lerr != nil {
146+
err = errors.Wrap(lerr, "couldn't write /etc/hosts")
147+
return
148+
}
145149
mountPath := q.mountPath(wlID)
146150
err = q.prepareMountPath(mountPath)
147151
if err != nil {
@@ -308,9 +312,16 @@ func (q *QSFS) prepareMountPath(path string) error {
308312
return nil
309313
}
310314

315+
// for some reason hosts file was corrupted in the flist, we need to rewrite it for zstor to be able to resolve localhost
316+
func (q *QSFS) writeHosts(root string) error {
317+
hostsPath := filepath.Join(root, "etc/hosts")
318+
const hosts = "127.0.0.1\tlocalhost\n::1\t\tlocalhost ip6-localhost ip6-loopback\n"
319+
return os.WriteFile(hostsPath, []byte(hosts), 0644)
320+
}
321+
311322
func (q *QSFS) writeQSFSConfig(root string, cfg zstorConfig) error {
312323
cfgPath := filepath.Join(root, "data/zstor.toml")
313-
f, err := os.OpenFile(cfgPath, os.O_WRONLY|os.O_CREATE, 0644)
324+
f, err := os.OpenFile(cfgPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
314325
if err != nil {
315326
return errors.Wrap(err, "couldn't open zstor config file")
316327
}

0 commit comments

Comments
 (0)