如何使用 targetcli 禁用 iSCSI 写入缓存

如何使用 targetcli 禁用 iSCSI 写入缓存

我已将单个磁盘导出为targetcliLinux 主机上的 iSCSI 目标。在远程计算机上,我已连接到该设备,并在其上放置了一个 ZFS 卷(作为复制目标zrepl)。

但是,每次我重新启动 iSCSI 目标计算机时,运行 ZFS 的启动器计算机都会因写入错误而失败。经过一番研究,这种类型的故障仅发生在 ZFS 向设备发送写入时,它被告知写入已成功完成,但随后写入丢失。

这意味着 iSCSI 目标必须在实际写入磁盘之前缓存写入并返回成功,并且当机器重新启动时,这些缓存的写入并不总是被刷新。

有没有办法targetcli禁用此写入缓存,以便写入直到实际写入物理磁盘后才会返回成功?

我尝试将物理磁盘导出为pscsi后台存储,但这只会在访问磁盘时导致 iSCSI 目标内核崩溃。(没有使用虚拟机,只有两台本机 Linux 服务器,因此不应使用不常见的 SCSI 命令。)

/> ls
o- / .............................................................................................. [...]
  o- backstores ................................................................................... [...]
  | o- block ....................................................................... [Storage Objects: 1]
  | | o- ar0 .......... [/dev/disk/by-id/ata-ST22000NT001-3LS101_ZX20XTYG (20.0TiB) write-thru activated]
  | |   o- alua ........................................................................ [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ............................................ [ALUA state: Active/optimized]
  | o- fileio ...................................................................... [Storage Objects: 0]
  | o- pscsi ....................................................................... [Storage Objects: 0]
  | o- ramdisk ..................................................................... [Storage Objects: 0]
  o- iscsi ................................................................................. [Targets: 1]
  | o- iqn.2023-07.com.example.host:sn.zx20xtyg ............................................... [TPGs: 1]
  |   o- tpg1 .................................................................... [no-gen-acls, no-auth]
  |     o- acls ............................................................................... [ACLs: 1]
  |     | o- iqn.2023-07.com.example.client:783af16f240 ................................ [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ........................................................ [lun0 block/ar0 (rw)]
  |     o- luns ............................................................................... [LUNs: 1]
  |     | o- lun0 ..... [block/ar0 (/dev/disk/by-id/ata-ST22000NT001-3LS101_ZX20XTYG) (default_tg_pt_gp)]
  |     o- portals ......................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 .......................................................................... [OK]
  o- loopback .............................................................................. [Targets: 0]
  o- vhost ................................................................................. [Targets: 0]
  o- xen-pvscsi ............................................................................ [Targets: 0]
  pool: iscsi
 state: ONLINE
status: One or more devices are faulted in response to IO failures.
action: Make sure the affected devices are connected, then run 'zpool clear'.
   see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-JQ
config: 
        
        NAME                                      STATE     READ WRITE CKSUM
        iscsi                                     ONLINE       0     0     0
          wwn-0x60014050b85f5b1d12d4875bdb68f41a  ONLINE       3   153     0
errors: List of errors unavailable: pool I/O is currently suspended

$ zpool clear iscsu
$ zpool status -v
  pool: iscsi
 state: ONLINE
status: One or more devices has experienced an error resulting in data
        corruption.  Applications may be affected.
action: Restore the file in question if possible.  Otherwise restore the
        entire pool from backup.
   see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-8A
  scan: resilvered 360K in 00:00:02 with 0 errors on Fri Jul 28 12:58:10 2023
config:

        NAME                                      STATE     READ WRITE CKSUM
        iscsi                                     ONLINE       0     0     0
          wwn-0x60014050b85f5b1d12d4875bdb68f41a  ONLINE       0     0     0

errors: Permanent errors have been detected in the following files:

        <metadata>:<0x0>
        <metadata>:<0x101>
        <metadata>:<0x104>
        <metadata>:<0x105>
        <metadata>:<0x33>
        <metadata>:<0x34>
        <metadata>:<0x3d>
        <metadata>:<0xe8d>
        <metadata>:<0x1e1f9>
        <metadata>:<0x1e1fb>

答案1

您需要使用 iSCSI 目标发送设置了 FUA(强制单元注意)标志的写入,或者在写入提交后发出“同步缓存”,然后再向调用者发送写入确认。如果您“映射”整个物理磁盘原始数据。

相关内容