Correct debugfs file removal pattern

From: Chiappero, Marco
Date: Tue Jan 19 2021 - 16:29:36 EST


Hi,

I'm looking to expose some information through a debugfs file, however I'm not entirely clear with the correct steps for file removal upon module unloading. I'm asking this because I would expect debugfs_remove() to wait until every open file has been closed when using debugfs_create_file (not debugfs_create_file_unsafe), as per debugfs_file_put() documentation:

* Up to a matching call to debugfs_file_put(), any successive call
* into the file removing functions debugfs_remove() and
* debugfs_remove_recursive() will block.

Unfortunately it's not what I'm seeing when removing the module with one file kept open (leading to a page fault when eventually closing the file). So, is this the expected behaviour? If so, what is the right approach for waiting, inotify or fsnotify? Any suggestion on what the best pattern would be?

Thank you,
Marco

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263