私のプログラムが ZFS ファイルシステム上のファイルのバイトを読み取ろうとしたとします。ZFS は必要なブロックのコピーを見つけることができますが、有効なチェックサムを持つコピーを見つけることができません (それらはすべて破損しているか、存在するディスクのみに破損したコピーがあります)。読み取りからの戻り値と読み取りを試みたバイトに関して、私のプログラムは何を見ますか? また、(Solaris またはその他の ZFS を実装する OS の下で) 動作に影響を与える方法、つまり、データが破損している可能性がある状態で強制的に失敗するか強制的に成功する方法はありますか?
3 に答える
EIO は、現在の ZFS 実装での唯一の答えです。
Open ZFS の「バグ」は、破損したデータを読み取る何らかの方法を要求します: http://bugs.opensolaris.org/bugdatabase/printableBug.do?bug_id=6186106
これは、文書化されていないがオープンソースの zdb ユーティリティを使用してすでに実行可能であると思います。zdb -R オプションと "r" フラグを使用してファイルの内容をダンプする方法については、http: //www.cuddletech.com/blog/pivot/entry.php?id=980 を参照してください。
ソラリス 10:
# Create a test pool
[root@tesalia z]# cd /tmp
[root@tesalia tmp]# mkfile 100M zz
[root@tesalia tmp]# zpool create prueba /tmp/zz
# Fill the pool
[root@tesalia /]# dd if=/dev/zero of=/prueba/dummy_file
dd: writing to `/prueba/dummy_file': No space left on device
129537+0 records in
129536+0 records out
66322432 bytes (66 MB) copied, 1.6093 s, 41.2 MB/s
# Umount the pool
[root@tesalia /]# zpool export prueba
# Corrupt the pool on purpose
[root@tesalia /]# dd if=/dev/urandom of=/tmp/zz seek=100000 count=1 conv=notrunc
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.0715209 s, 7.2 kB/s
# Mount the pool again
zpool import -d /tmp prueba
# Try to read the corrupted data
[root@tesalia tmp]# md5sum /prueba/dummy_file
md5sum: /prueba/dummy_file: I/O error
# Read the manual
[root@tesalia tmp]# man -s2 read
[...]
RETURN VALUES
Upon successful completion, read() and readv() return a
non-negative integer indicating the number of bytes actually
read. Otherwise, the functions return -1 and set errno to
indicate the error.
ERRORS
The read(), readv(), and pread() functions will fail if:
[...]
EIO A physical I/O error has occurred, [...]
テスト プールをエクスポート/インポートする必要があります。そうしないと、ファイルがまだ OS メモリにキャッシュされているため、直接上書き (プールの破損) が見逃されます。
いいえ、現在、ZFS は破損したデータの提供を拒否しています。当然のことです。
ファイル システム固有の低レベル データ レスキュー ユーティリティ以外では、意味のあるEIO
エラー以外を返すにはどうすればよいでしょうか。read()
低レベルのデータ レスキュー ユーティリティは、ファイルにアクセスするために、open/read/write/close 以外の OS および FS 固有の API を使用する必要があります。必要なセマンティクスは、通常のファイルの読み取りとは根本的に異なるため、専用の API が必要になります。