断开连接时尝试访问使用 CIFS 挂载的远程文件夹会挂起 [英] Attempt to access remote folder mounted with CIFS hangs when disconnected

查看:35
本文介绍了断开连接时尝试访问使用 CIFS 挂载的远程文件夹会挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是那个问题的扩展.

再一次:我在 CentOS 6.0 下工作,我有一个远程 win7 文件夹,安装有:

Yet again: I'm working under CentOS 6.0 and I have a remote win7 folder, mounted with:

mount -t cifs //PC128/mnt /media/net -o "username=WORKGROUPuser,password=pwd,rw,noexec,soft,uid=user,gid=user"

当远程文件夹不可用时(例如,网络电缆被拔出)尝试访问远程文件夹会锁定我正在处理的应用程序.起初我检测到 QDir::exists() 导致锁定 20-90 秒(我仍然无法找出为什么会有这种差异),进一步我检测到任何对 stat() 函数的调用都会导致应用程序锁定.

When remote folder is not available (e.g. network cable is pulled out) an attempt to access the remote folder locks an application I'm working on. At first I detected that QDir::exists() caused locking for 20-90 seconds (I still can't find out why such difference), further I detected that any call to stat() function leads to application lock.

我遵循了上述主题中提供的建议,我将 QDir::exists() 调用(以及后来 - 对 stat() 函数的调用)移动到另一个线程,但这并没有解决问题.当连接突然丢失时,应用程序仍然挂起.Qt 跟踪显示锁在内核中的某处:

I followed an advice provided in topic above, I moved QDir::exists() call (and later - call to the stat() function) to another thread and this didn't solve the problem. The application still hangs when connection is suddenly lost. Qt trace shows that lock is somewhere in the kernel:

0   __kernel_vsyscall
1   __xstat64@GLIBC_2.1               /lib/libc.so.6
2   QFSFileEnginePrivate::doStat      stat.h

在尝试访问文件夹本身之前,我还尝试检查远程共享是否仍然挂载,但没有帮助.方法如:

I did also tried to check if remote share is still mounted before trying to access folder itself, but it didn't help. Approaches such as:

mount | grep /media/net

显示共享文件夹仍然挂载,即使没有与网络的活动连接.

show that shared folder is still mounted even is there is no active connection to the network.

检查文件夹状态差异,例如:

Checking folder status differences such as:

stat -fc%t:%T /media/net/ != stat -fc%t:%T /media/net/..

也会挂起约 20 秒.

also hangs for ~20 seconds.

所以我有几个问题:

  1. 有什么方法可以更改 CIFS 超时?我确实试图找出来,但似乎没有合适的参数,也没有 CIFS 配置.
  2. 如何检查远程文件夹是否仍然挂载且未锁定?
  3. 如何检查文件夹是否存在并且没有被锁定?

推荐答案

你的问题:一个无法访问的网络文件系统"是一个非常有名的例子,它触发了 linux hung task 这不一样僵尸进程(杀死父 PID 不会做任何事情)

Your problem: "An unreachable network filesystem" is a very well known example which trigger linux hung task which isn't the same of zombies process at all(killing the parent PID won't do anything)

挂起的任务,是触发系统调用导致内核出现问题的任务,因此系统调用永远不会返回.主要的特殊性是调度程序将任务声明为D"状态,这意味着程序处于不可中断状态.这意味着你无法阻止你的程序:你可以触发所有信号给任务,它不会响应.启动数百个 SIGTERM/SIGKILL 无济于事!

An hung task, is task which triggered a system call that cause problem in the kernel, so that the system call never return. The major particularity is that the task is declared in the "D" state by the scheduler which mean the program is in an uninterruptible state. This mean that you can do nothing to stop you program: You can trigger all signal to the task, it would not respond. Launching hundreds of SIGTERM/SIGKILL does nothing!

我的旧内核就是这种情况:当我的 nfs 服务器崩溃时,我需要重新启动客户端以终止使用文件系统的任务.我很久以前编译过它(我的硬盘上还有构建树),在配置过程中我在 lib/Kconfig.debug 中看到了这个:

This the case whith my old kernel: when my nfs server crash, I need to reboot the client to kill the tasks using the filesystem. I compiled it a long time ago (I have still the build tree on my hdd) and during the configuration I saw this in lib/Kconfig.debug:

config DETECT_HUNG_TASK
    bool "Detect Hung Tasks"
    depends on DEBUG_KERNEL
    default LOCKUP_DETECTOR
    help
      Say Y here to enable the kernel to detect "hung tasks",
      which are bugs that cause the task to be stuck in
      uninterruptible "D" state indefinitiley.

      When a hung task is detected, the kernel will print the
      current stack trace (which you should report), but the
      task will stay in uninterruptible state. If lockdep is
      enabled then all held locks will also be reported. This
      feature has negligible overhead.

它只是提议在检测时检测这种 tash 或恐慌:我没有检查最近的内核是否真的可以解决问题 (您的问题似乎是这种情况),但我认为不值得启用它.

It was only proposing to detect such tash or panic on detection: I don't checked if recent kernel actually can solve the problem (It seems to be the case with your question), but I think it didn't worth enabling it.

还有第二个问题:通常,检测发生在 120 秒后,但我也看到了一个 Konfig 选项:

There is second problem : normally, the detection occur after 120 seconds, but I saw also a Konfig option for this:

config DEFAULT_HUNG_TASK_TIMEOUT
    int "Default timeout for hung task detection (in seconds)"
    depends on DETECT_HUNG_TASK
    default 120
    help
      This option controls the default timeout (in seconds) used
      to determine when a task has become non-responsive and should
      be considered hung.

      It can be adjusted at runtime via the kernel.hung_task_timeout_secs
      sysctl or by writing a value to
      /proc/sys/kernel/hung_task_timeout_secs.

      A timeout of 0 disables the check.  The default is two minutes.
      Keeping the default should be fine in most cases.

这也适用于内核线程:例如:为 fuse 文件系统上的文件创建循环设备.然后让控制 fuse 文件系统的用户空间程序崩溃!你应该得到一个 Ktread,它的名字格式为 loopX(X 通常对应于你的回送设备号)HUNGing!

This also works with kernel threads: example: make a loop device to a file on a fuse filesystem. Then crash the userspace program controlling the fuse filesystem! You should a get a Ktread which name is in the form loopX (X correspond normally to your loopback device number) HUNGing!

网络链接:

https://unix.stackexchange.com/questions/5642/what-if-kill-9-does-not-work(看 Ultrasawblade 写的答案)

https://unix.stackexchange.com/questions/5642/what-if-kill-9-does-not-work (look at the answer written by ultrasawblade)

http://www.linuxquestions.org/questions/linux-general-1/kill-a-hung-task-when-kill-9-doesn't-help-697305/

http://www.linuxquestions.org/questions/linux-general-1/kill-a-hung-task-when-kill-9-doesn't-help-697305/

http://forums-web2.gentoo.org/viewtopic-t-811557-start-0.html

http://comments.gmane.org/gmane.linux.kernel/1189978

http://comments.gmane.org/gmane.linux.kernel.cifs/7674 (这个情况和你的差不多)

在你的三个问题的情况下:你有答案:这可能是由于 vfs linux 内核层中一个众所周知的错误!(没有 CIFS 超时)

In your case of the three question: you have the answer: This probably due to what is probably a well known bug in the vfs linux kernel layer! (There is no CIFS timeouts)

这篇关于断开连接时尝试访问使用 CIFS 挂载的远程文件夹会挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆