卸载时的熔断操作

发布于 2024-11-04 08:59:22 字数 487 浏览 0 评论 0原文

我已经用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断肠人 2024-11-11 08:59:22

找到了!它是 Python-fuse 中的 fsdestroy()。找到它的方式:

jcomeau@intrepid:/usr/src/google-desktop/api$ cat /usr/lib/python2.6/dist-packages/fuseparts/* | strings | grep destroy
fsdestroy

我使用的是:

def fsdestroy(self, data = None):
  syslog.syslog(syslog.LOG_INFO, 'destroy %s: %s' % (self.mountpoint, data))
  os.rmdir(self.mountpoint)

不知道数据参数是否必要,但不会造成伤害。显然,它是在 umount 之后调用的,所以我不必担心如何处理它。

found it! it's fsdestroy() in Python-fuse. located it by:

jcomeau@intrepid:/usr/src/google-desktop/api$ cat /usr/lib/python2.6/dist-packages/fuseparts/* | strings | grep destroy
fsdestroy

What I used was:

def fsdestroy(self, data = None):
  syslog.syslog(syslog.LOG_INFO, 'destroy %s: %s' % (self.mountpoint, data))
  os.rmdir(self.mountpoint)

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.

铁憨憨 2024-11-11 08:59:22

另一个解决方案(虽然不具体且未在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文