"Zhijian Li (Fujitsu)" <lizhijian@xxxxxxxxxxx> writes: > On 17/10/2023 16:01, Markus Armbruster wrote: >> Li Zhijian <lizhijian@xxxxxxxxxxx> writes: >> >>> 'errno' is being widely used by applications when ibv_reg_mr returns NULL. >>> They all believe errno indicates the error on failure, so let's document >>> it explicitly. >> >> Similar issue with ibv_open_device() . Possibly more. > > You are right, ibv_open_device()'s call chains are more complicated, > I have not figured out if it ought to set errno though QEMU relies on it. I think a question to answer is for what purposes callers need errno. The only callers I know are in QEMU. There are three: * qemu_rdma_reg_whole_ram_blocks() and qemu_rdma_register_and_get_keys() When ibv_reg_mr() fails, maybe try again with IBV_ACCESS_ON_DEMAND added to the protection attributes. "Maybe": if errno is ENOTSUP, and ibv_query_device_ex() reports IBV_ODP_SUPPORT. * qemu_rdma_broken_ipv6_kernel() This function appears to probe the devices returned by ibv_get_device_list(). For each device in the list, in order: try to ibv_open_device(). If it fails: ignore the device if errno is EPERM, else return failure. I'm not familiar with RDMA, and I can't say whether any of this makes sense. If it doesn't, we need to talk about what problem the QEMU code is trying to solve, and how to solve it properly. If it does, we have legitimate uses of errno, and we need to talk how to make errno usable safely, or else how to replace its use in QEMU.