'强化'嵌入式 ext4 文件服务器以防止意外断电的最佳方法是什么?

'强化'嵌入式 ext4 文件服务器以防止意外断电的最佳方法是什么?

首先介绍一下背景:我的公司生产一种音频流设备,它是一种无头、机架式 Linux 盒,附带一个固态 e-SATA 驱动器。该驱动器采用 ext4 格式。用户可以使用 Samba/CIFS 连接到系统,以上传新的音频文件或访问现有文件。还有用于通过网络流式传输音频的定制软件。

这一切都很好。唯一的问题是,用户是音频人员,而不是计算机人员,他们将系统视为“黑匣子”,而不是计算机。这意味着,到最后,他们不会通过 ssh 进入盒子并输入“/sbin/shutdown -h”;他们只会切断机架的电源然后离开,并期望第二天一切仍能正常工作。

由于 ext4 具有日志记录、日志校验和等功能,因此这种方法通常有效。唯一不起作用的情况是,有人通过 Samba 上传新文件,然后在上传的数据完全刷新到磁盘之前切断系统电源。在这种情况下,他们第二天回来发现他们的新文件已被截断或完全丢失,并且很不高兴。

我的问题是,避免这个问题的最佳方法是什么?有没有办法让 smbd 在每次上传结束时调用“sync”?(上传的性能并不那么重要,因为它们只是偶尔发生)。或者有没有办法告诉 ext4 在文件发生任何更改后的几秒钟内自动刷新?(同样,这里可以牺牲性能来换取安全性)我应该设置特定的写入排序模式、激活屏障等吗?

答案1

使用 fstab 中指定的文件系统挂载sync可能会有所帮助。我想有人会给出更适合您特定应用程序的建议。

我开始初步研究使用闪存的文件系统,因为我想定制一台家庭影院电脑作为设备。您可能会找到更适合您的设备的其他存储解决方案。不幸的是,我还没有找到我喜欢的东西,所以我没有详细的推荐。

编辑1

根据 smb.conf(5) 手册页,它支持 SAMBA 内的立即同步:

   strict sync (S)
          Many Windows applications (including the Windows 98
          explorer  shell)  seem  to  confuse flushing buffer
          contents to disk with doing a sync to  disk.  Under
          UNIX,  a  sync  call  forces the process to be sus-
          pended until the kernel has ensured that  all  out-
          standing  data  in  kernel  disk  buffers  has been
          safely stored onto stable  storage.  This  is  very
          slow  and  should only be done rarely. Setting this
          parameter to no (the default)  means  that  smbd(8)
          ignores  the  Windows  applications  requests for a
          sync call. There is only a  possibility  of  losing
          data  if  the operating system itself that Samba is
          running on crashes, so there is  little  danger  in
          this  default setting. In addition, this fixes many
          performance problems that people have reported with
          the new Windows98 explorer shell file copies.

          Default: strict sync = no

   sync always (S)
          This  is  a boolean parameter that controls whether
          writes will always be  written  to  stable  storage
          before  the  write call returns. If this is no then
          the server will be guided by the  client's  request
          in  each write call (clients can set a bit indicat-
          ing that a particular write should be synchronous).
          If this is yes then every write will be followed by
          a fsync()  call to ensure the data  is  written  to
          disk.  Note  that the strict sync parameter must be
          set to yes in order for this parameter to have  any
          affect.

          Default: sync always = no

答案2

是的,我也遇到过同样的问题。如果您禁用系统中的任何类型的写入缓存,则所有数据都会尽快写入磁盘。

您将会损失性能,但会获得更好的数据完整性。

磁盘上的数据与操作系统认为在磁盘上的数据(但实际上缓存在内存中)之间的差异将明显较小。

如果您不能使用 UPS 来解决问题,或者不能使用某种硬件解决方案在交流电断电时正常关闭机器,那么您将不得不使用这样的黑客技术。

一个好主意可能是使用更简单的文件系统来存储媒体,并从 ramdisk 启动操作系统。这样可以避免损坏机器的启动/根分区。

总结一下,

使用同步挂载文件系统,您将损失性能,但是所有写入都不会被缓存。

关闭硬件磁盘写入缓存,您将再次失去性能。

您应该对这篇文章感兴趣

http://sr5tech.com/write_back_cache_experiments.htm

答案3

既然您提到贵公司制造这些产品,我建议您从硬件角度考虑。我见过在驱动器控制器上配备电池备份的服务器,以便缓存的数据在断电后能够继续存在。如果您的工程师内置了一个小型电池,以保持系统运行足够长的时间,直到完全关闭,会怎么样?它不需要是一个大型的独立 UPS,它可以是内部的,并设置为在交流电源断电时立即关闭系统。这可能会增加几美元的成本,但它也可能是一个营销点。

相关内容