卸载时的熔断操作
我已经用 Python-fuse 编写了一些简单的文件系统,但现在我想做一些在 pydoc 和我找到的示例脚本中都找不到的事情:当使用 fusermount 卸载文件系统时-u,我想捕获该操作,执行卸载,然后 rmdir 由我的程序初始化脚本创建的安装目录。如果有可能的话,捕获 umount 操作的魔法咒语是什么?
我可以看到这很容易变成无限循环,但我希望能够弄清楚如何在第一次遇到 umount 陷阱时禁用它。
Update: I found
destroy
at http://omake.metaprl.org/prerelease/omake-dll-fuse.html#htoc582 and added the method, but it doesn't seem to be called.I've written some simple filesystems with Python-fuse, but now I'm wanting to do something that I can't find in the pydoc nor in the sample scripts I've found: when the filesystem is unmounted with fusermount -u
, I want to trap that action, perform the umount, and then rmdir the mount directory created by my program's initialization script. If it is even possible, what's the magic incantation to trap the umount action?
I can see how that could easily turn into an endless loop, but I can hopefully figure out how to disable the umount trap the first time it's hit.
Update: I found
destroy
at http://omake.metaprl.org/prerelease/omake-dll-fuse.html#htoc582 and added the method, but it doesn't seem to be called.如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了!它是 Python-fuse 中的 fsdestroy()。找到它的方式:
我使用的是:
不知道数据参数是否必要,但不会造成伤害。显然,它是在 umount 之后调用的,所以我不必担心如何处理它。
found it! it's fsdestroy() in Python-fuse. located it by:
What I used was:
Don't know if the data parameter is necessary or not, but doesn't hurt. And apparently, it's called after the umount, so I didn't have to worry about handling that.
另一个解决方案(虽然不具体且未在 Python 下测试)是使用
-f
开关防止 FUSE“守护进程”。在这种情况下,
fuse_main
方法将阻塞,直到文件系统卸载,之后您将重新获得控制权。如果您确实需要守护程序行为,您可以在挂载之前自行重新实现它。
Another solution, though not specific and not tested under Python, is prevent FUSE from "daemonizing" with the
-f
switch.In this case, the
fuse_main
method will block until the filesystem in unmounted, and you will get the control back afterwards.If you do need the deamon behavior, you can reimplement it yourself before mounting.