【问题标题】:Attempt to access remote folder mounted with CIFS hangs when disconnected断开连接时尝试访问使用 CIFS 挂载的远程文件夹会挂起
【发布时间】:2013-08-07 19:05:35
【问题描述】:

此问题是that question 的扩展。

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

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

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

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

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

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

mount | grep /media/net

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

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

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

也会挂起约 20 秒。

所以我有几个问题:

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

【问题讨论】:

  • 到目前为止我提出的唯一非挂起解决方案是在尝试访问远程主机安装的共享文件夹之前 ping 远程主机。它有效,但它不是一个完美的解决方案恕我直言。

标签: centos share mount samba cifs


【解决方案1】:

经过多次尝试和错误,我找到了一个持续存在的解决方案。

# vim /etc/fstab

//192.168.1.122/myshare /mnt/share cifs username=user,password=password,_netdev 0  0

_netdev 选项很重要,因为我们正在安装网络设备。如果系统遇到网络问题,客户端可能会在启动过程中挂起。

https://www.redhat.com/sysadmin/samba-windows-linux

【讨论】:

    【解决方案2】:

    您的问题:“无法访问的网络文件系统”是一个众所周知的例子,它触发了 linux hung task,这与僵尸进程完全不同(杀死父 PID 是不行的任何东西)

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

    我的旧内核就是这种情况:当我的 nfs 服务器崩溃时,我需要重新启动客户端以终止使用文件系统的任务。我很久以前编译过它(我的硬盘上还有构建树),在配置过程中我在 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 或恐慌:我没有检查最近的内核是否真的可以解决问题 (您的问题似乎是这种情况),但我认为不值得启用它。

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

    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!

    网络链接:

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

    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 超时)

    【讨论】:

    • @Nati 我知道我的回答使这个问题适合 serverfault 而不是 stackoverflow,但你不知道它涉及什么
    • 很难相信所有的大脑都会在linux上工作,这种cifs锁定的情况在2017年仍然存在......
    • @reukiodo :这是设计使然。
    • @reukiodo 2018 已经 - 100% 同意 - 这是 EPIC 可悲的。什么样的设计让这种情况发生?让我知道谁是设计师,我会给他/她写一封他/她一生都不会忘记的信。我们有工作要做,只是解决问题!
    • 另外,我认为这属于评论,而不是答案。虽然它对于为什么进程挂起提供了很多信息,但它没有回答如何解决这个问题。
    猜你喜欢
    • 2013-07-29
    • 1970-01-01
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 2015-09-28
    相关资源
    最近更新 更多