Commit acceca8d authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

selftests: bpf: log direct file writes

Recent changes to netdevsim moved creating and destroying
devices from netlink to sysfs. The sysfs writes have been
implemented as direct writes, without shelling out. This
is faster, but leaves no trace in the logs. Add explicit
logs to make debugging possible.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bfcccfe7
...@@ -335,13 +335,22 @@ class NetdevSimDev: ...@@ -335,13 +335,22 @@ class NetdevSimDev:
""" """
Class for netdevsim bus device and its attributes. Class for netdevsim bus device and its attributes.
""" """
@staticmethod
def ctrl_write(path, val):
fullpath = os.path.join("/sys/bus/netdevsim/", path)
try:
with open(fullpath, "w") as f:
f.write(val)
except OSError as e:
log("WRITE %s: %r" % (fullpath, val), -e.errno)
raise e
log("WRITE %s: %r" % (fullpath, val), 0)
def __init__(self, port_count=1): def __init__(self, port_count=1):
addr = 0 addr = 0
while True: while True:
try: try:
with open("/sys/bus/netdevsim/new_device", "w") as f: self.ctrl_write("new_device", "%u %u" % (addr, port_count))
f.write("%u %u" % (addr, port_count))
except OSError as e: except OSError as e:
if e.errno == errno.ENOSPC: if e.errno == errno.ENOSPC:
addr += 1 addr += 1
...@@ -403,14 +412,13 @@ class NetdevSimDev: ...@@ -403,14 +412,13 @@ class NetdevSimDev:
return progs return progs
def remove(self): def remove(self):
with open("/sys/bus/netdevsim/del_device", "w") as f: self.ctrl_write("del_device", "%u" % (self.addr, ))
f.write("%u" % self.addr)
devs.remove(self) devs.remove(self)
def remove_nsim(self, nsim): def remove_nsim(self, nsim):
self.nsims.remove(nsim) self.nsims.remove(nsim)
with open("/sys/bus/netdevsim/devices/netdevsim%u/del_port" % self.addr ,"w") as f: self.ctrl_write("devices/netdevsim%u/del_port" % (self.addr, ),
f.write("%u" % nsim.port_index) "%u" % (nsim.port_index, ))
class NetdevSim: class NetdevSim:
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment