Skip to content

Commit

Permalink
cpud: add an option to sleep before serving
Browse files Browse the repository at this point in the history
When cpud runs as init, and serves mDNS, it can start serving before
mDNS will work. It is still not clear why this fails, but adding a
5 second sleep before serve() resolves it for now. Such a sleep
is obviously undesirable, but the default is 0.

To set the timeout when cpud runs as init, add -- --sleepBeforeServing=5s
to the kernel command line.

This sleep is required to make mDNS work for in-flash or netbooted images.

BUT: if you have it, you don't even need a DHCP server to use it.

rminnich@pop-os:~/oreboot/linux$ sidecore . /bbin/ip a
...
2: eth0: <UP,BROADCAST,MULTICAST> mtu 1500 state UP
    link/ether 6c:cf:39:00:48:20
    inet6 fe80::6ecf:39ff:fe00:4820 scope link
       valid_lft forever preferred_lft forever

rminnich@pop-os:~/oreboot/linux$ sidecore vf2 date
Thu Jan  1 00:11:44 UTC 1970
rminnich@pop-os:~/oreboot/linux$
vf2 is in my ~/.ssh/config as
Host vf2
        HostName fe80::6ecf:39ff:fe00:4820
        IdentityFile ~/.ssh/cpu_rsa

i.e. link-local only

You can bring up a set of machines, get their link local address via mDNS, and then use link local from then on.
No DHCP server needed.

In fact this on command
sidecore . /bbin/ip l
will get the macs for ALL machines.
Note: this is why it pays to just put all the u-root commands in the image.

One such command to do this:

(p=$PWD && \
  cd ~/go/src/github.com/u-root/cpu/cmds/cpud/ && \
  GOARCH=riscv64 u-root -tags mDNS \
  -uroot-source ~/go/src/github.com/u-root/u-root/ \
  -files ~/.ssh/cpu_rsa.pub:key.pub \
  -initcmd=/bbin/cpud \
  . all)

xz --check=crc32 -9 --lzma2=dict=1MiB  \
  --stdout /tmp/initramfs.linux_riscv64.cpio  \
  | dd conv=sync bs=512    of=emb.cpio.xz

Signed-off-by: Ronald G Minnich <[email protected]>
  • Loading branch information
rminnich authored and orangecms committed Sep 23, 2023
1 parent c61842e commit ffd2fa5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmds/cpud/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var (
registerAddr = flag.String("register", "", "address and port to register with after listen on cpu server port")
registerTO = flag.Duration("registerTO", time.Duration(5*time.Second), "time.Duration for Dial address for registering")

// if we start up too quickly, mDNS won't work correctly.
// This sleep may be useful for other cases, so it is here,
// not specifically for mDNS uses.
sleepBeforeServing = flag.Duration("sleepBeforeServing", 0, "add a sleep before serving -- usually only needed if cpud runs as init with mDNS")

pid1 bool
)

Expand Down Expand Up @@ -89,9 +94,10 @@ func main() {
log.Fatal(err)
}
}
pid1 = os.Getpid() == 1
pid := os.Getpid()
pid1 = pid == 1
*runAsInit = *runAsInit || pid1
verbose("Args %v pid %d *runasinit %v *remote %v env %v", os.Args, os.Getpid(), *runAsInit, *remote, os.Environ())
verbose("Args %v pid %d *runasinit %v *remote %v env %v", os.Args, pid, *runAsInit, *remote, os.Environ())
args := flag.Args()
if *remote {
verbose("args %q, port9p %v", args, *port9p)
Expand All @@ -110,12 +116,14 @@ func main() {
log.Fatalf("CPUD(remote): %v", err)
}
} else {
log.Printf("CPUD:running as a server (a.k.a. starter of cpud's for sessions)")
log.Printf("CPUD:PID(%d):running as a server (a.k.a. starter of cpud's for sessions)", pid)
if *runAsInit {
log.Printf("CPUD:also running as init")
if err := initsetup(); err != nil {
log.Fatal(err)
}
}
time.Sleep(*sleepBeforeServing)
if err := serve(os.Args[0]); err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit ffd2fa5

Please sign in to comment.