Ext4

“強化”嵌入式 ext4 文件伺服器以防止意外斷電的最佳方法?

  • March 18, 2010

首先,介紹一點背景知識:我的公司生產一種音頻流設備,它是一種無頭、機架安裝的 Linux 機器,帶有一個固態 e-SATA 驅動器。該驅動器使用 ext4 格式化。使用者可以使用 Samba/CIFS 連接到系統以上傳新的音頻文件或訪問現有的文件。還有用於通過網路流式傳輸音頻的自定義軟體。

這一切都很好。唯一的問題是使用者是音頻人員,而不是電腦人員,並且將系統視為“黑匣子”,而不是電腦。這意味著在一天結束時,他們不會 ssh 進入盒子並輸入“/sbin/shutdown -h”;他們只是要切斷機架的電源並離開,並期望第二天仍能正常工作。

由於 ext4 有日誌、日誌校驗和等,所以這主要是有效的。唯一不起作用的情況是有人通過 Samba 上傳新文件,然後在上傳的數據完全刷新到磁碟之前切斷系統電源。在這種情況下,他們第二天來,發現他們的新文件被截斷或完全失去,並且很不高興。

我的問題是,避免這個問題的最佳方法是什麼?有沒有辦法讓 smbd 在每次上傳結束時呼叫“同步”?(上傳性能並不那麼重要,因為它們只是偶爾發生)。或者有沒有辦法告訴 ext4 在對文件進行任何更改後的幾秒鐘內自動刷新?(再次,為了安全,可以犧牲性能)我應該設置特定的寫入順序模式,啟動屏障等嗎?

使用 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

引用自:https://serverfault.com/questions/123957