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

Jer*_*ner 6 ext4 data-protection

首先,介绍一下背景知识:我的公司制造了一个音频流设备,它是一个无头的机架安装式 Linux 机器,并连接了一个固态 e-SATA 驱动器。驱动器格式化为 ext4。用户可以使用 Samba/CIFS 连接到系统以上传新的音频文件或访问现有的音频文件。还有用于通过网络流式传输音频的自定义软件。

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

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

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

War*_*ner 3

使用 fstab 中指定的方式挂载文件系统sync可能会有所帮助。我怀疑有人会提出更适合您特定应用的建议。

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

编辑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
Run Code Online (Sandbox Code Playgroud)