vpelletier / python-functionfs

Pythonic API for linux's functionfs
GNU General Public License v3.0
40 stars 13 forks source link

functionfs not cleaned up properly after exiting #27

Closed wchill closed 1 year ago

wchill commented 1 year ago

Not sure what I'm doing wrong here, but when I hit Ctrl+C to interrupt the process, functionfs remains loaded and I have to reboot in order to use functionfs again.

This is what I get when rerunning:

(venv) root@raspberrypi:/home/wchill/test# python testbench.py
Traceback (most recent call last):
  File "/home/wchill/test/testbench.py", line 60, in <module>
    with FunctionFsUsbSink() as sink:
  File "/home/wchill/test/sinks/function_fs_sink.py", line 396, in __enter__
    gadget = self.subprocess_manager.__enter__()
  File "/home/wchill/test/venv/lib/python3.9/site-packages/functionfs-0.9.1-py3.9.egg/functionfs/gadget.py", line 564, in __enter__
  File "/home/wchill/test/venv/lib/python3.9/site-packages/functionfs-0.9.1-py3.9.egg/functionfs/gadget.py", line 264, in __enter__
  File "/home/wchill/test/venv/lib/python3.9/site-packages/functionfs-0.9.1-py3.9.egg/functionfs/gadget.py", line 340, in __enter
  File "/home/wchill/test/venv/lib/python3.9/site-packages/functionfs-0.9.1-py3.9.egg/functionfs/gadget.py", line 277, in mkdir
OSError: [Errno 16] Device or resource busy: '/sys/kernel/config/usb_gadget/g_xt02ah4u/functions/ffs.usb0'

I'm not able to unload the functionfs/libcomposite modules since they are in use:

(venv) root@raspberrypi:~# lsmod
Module                  Size  Used by
usb_f_fs               45056  3
libcomposite           69632  10 usb_f_fs

After unmounting the usb0 functionfs mount:

(venv) root@raspberrypi:~# lsmod
Module                  Size  Used by
usb_f_fs               45056  2
libcomposite           69632  10 usb_f_fs

Any ideas on what to do here? Rebooting every time I need to rerun my code is a huge issue.

vpelletier commented 1 year ago

Hello.

My appologies for missing this issue entirely. I just noticed the most recent pair of notifications from this repository.

The teardown of a usb gadget is rather involved and contains some rather unusual commands (rmdir of a non-empty folder being one of the sneakier ones). I am surprised though that a ^C during __enter__ is enough to cause issues: it is supposed to attempt a teardown. Seeing the other outstanding kernel-side issues, maybe there is more ? Especially, how representative for __enter__ to get interrupted on the mkdir step ?

wchill commented 1 year ago

Honestly, I don't know why but this kinda resolved itself. This issue is unrelated to the issues I'm seeing on the RK3588 though.