当 ZFS 无法提供未损坏的数据时,程序会看到什么?

发布于 2024-08-11 04:40:11 字数 191 浏览 6 评论 0原文

假设我的程序尝试读取 ZFS 文件系统上的文件中的一个字节。 ZFS 可以找到必要块的副本,但无法找到具有有效校验和的任何副本(它们都已损坏,或者唯一存在的磁盘具有损坏的副本)。就读取的返回值以及它尝试读取的字节而言,我的程序看到了什么?是否有一种方法可以影响行为(在 Solaris 或任何其他实现 ZFS 的操作系统下),即强制失败或强制成功,并可能导致数据损坏?

Say my program attempts a read of a byte in a file on a ZFS filesystem. ZFS can locate a copy of the necessary block, but cannot locate any copy with a valid checksum (they're all corrupted, or the only disks present have corrupted copies). What does my program see, in terms of the return value from the read, and the byte it tried to read? And is there a way to influence the behavior (under Solaris, or any other ZFS-implementing OS), that is, force failure, or force success, with potentially corrupt data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苍风燃霜 2024-08-18 04:40:11

EIO 确实是当前 ZFS 实现的唯一答案。

一个开放的 ZFS“bug”需要某种方法来读取损坏的数据:
http://bugs.opensolaris.org/bugdatabase/printableBug.do?bug_id=6186106

我相信使用未记录但开源的 zdb 实用程序已经可以做到这一点。
看看 http://www.cuddletech.com/blog/pivot /entry.php?id=980 有关如何使用 zdb -R 选项和“r”标志转储文件内容的说明。

EIO is indeed the only answer with current ZFS implementations.

An open ZFS "bug" asks for some way to read corrupted data:
http://bugs.opensolaris.org/bugdatabase/printableBug.do?bug_id=6186106

I believe this is already doable using the undocumented but open source zdb utility.
Have a look at http://www.cuddletech.com/blog/pivot/entry.php?id=980 for explanations about how to dump a file content using zdb -R option and "r" flag.

素年丶 2024-08-18 04:40:11

Solaris 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, [...]

您必须导出/导入测试池,否则,由于文件仍将缓存在操作系统内存中,因此将错过直接覆盖(池损坏)。

不,目前 ZFS 将拒绝向您提供损坏的数据。正如它应该的那样。

Solaris 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, [...]

You must export/import the test pool because, if not, the direct overwrite (pool corruption) will be missed since the file will still be cached in OS memory.

And no, currently ZFS will refuse to give you corrupted data. As it should.

月下伊人醉 2024-08-18 04:40:11

read() 返回除 EIO 错误之外的任何内容在文件系统特定的低级数据救援实用程序之外如何有意义?

低级数据救援实用程序需要使用操作系统和文件系统特定的 API,而不是打开/读/写/关闭来访问文件。它需要的语义与读取普通文件根本不同,因此它需要专门的 API。

How would returning anything but an EIO error from read() make sense outside a file system specific low level data rescue utility?

The low level data rescue utility would need to use an OS and FS specific API other than open/read/write/close to to access the file. The semantics it would need are fundamentally different from reading normal files, so it would need a specialized API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文