From nobody Mon Feb 9 04:59:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69032+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69032+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155375; cv=none; d=zohomail.com; s=zohoarc; b=D9OuQVWzpqRGkNh/2LhYlMLacDjGouuwUdKJqIi6FCGxpOrM9BDb43VF7VRZ7gFLi5Yez6+JpKWStRsAHiTech9eXfaYazK6EHal+J9LB2C1Q4hEDu4yUHuYSfHQFT3o0aUjWj4LXgtdUUOgEp6Q0K/2GD0eao3QWos4sOnIYWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155375; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=pDErOue0oNYxc75Zul7c5IlfwumznqeZudbruxIJX8I=; b=KZ5hmZebEWfjGCm1NN3AcwIelmvZl0mwxmf4b7AaSIUucOJbzJvzzIVdJhAob4209SxWYEXxmXaE4I2wgjTexE108YnFACn509knpFy3AVINjJcZjqDEb8BppY8LvgYfLWqz26R20sXDPbi1c+5c4MrB/GUOKZ8DHO+Pu6g0Azs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69032+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155375845830.8174089531832; Wed, 16 Dec 2020 13:49:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jXl3YY1788612xv2kloAg2sP; Wed, 16 Dec 2020 13:49:35 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web09.3941.1608155369949877993 for ; Wed, 16 Dec 2020 13:49:30 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-105-87Hy5rmqOA6y4dMuUuJS6A-1; Wed, 16 Dec 2020 16:49:27 -0500 X-MC-Unique: 87Hy5rmqOA6y4dMuUuJS6A-1 X-Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 498F81842141; Wed, 16 Dec 2020 21:49:26 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9536F1754A; Wed, 16 Dec 2020 21:49:18 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 18/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPEN Date: Wed, 16 Dec 2020 22:10:55 +0100 Message-Id: <20201216211125.19496-19-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: oWiTvCMqGvc5M66o5Kf3UvrFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155375; bh=pDErOue0oNYxc75Zul7c5IlfwumznqeZudbruxIJX8I=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XqxrIB7z+HuhlzmIusFKOFVthaJ4T+H2IAWW4fMUTFiYC6V23QAjddeNOf1lanssrYa eM+fcs01uXNrAv7NMjrzhr/gwCvwYUUgOItAot5j10Pb0m68+m6uf++8vwGB38YRrZqcc HGq47CSbZYNAx2kGWlMtHoV3sZfMUykzNSI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseOpen() function, for sending the FUSE_OPEN command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 35 +++--- OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseOpen.c | 126 ++++++++++++++++++++ 4 files changed, 156 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index fec2f4be531f..7b6f30335577 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -76,21 +76,28 @@ typedef struct { #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 +// +// Flags for VirtioFsFuseOpOpen. +// +#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 +#define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 + // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, + VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, } VIRTIO_FS_FUSE_OPCODE; @@ -118,16 +125,30 @@ typedef struct { =20 // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 +// +// Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir. +// +typedef struct { + UINT32 Flags; + UINT32 Unused; +} VIRTIO_FS_FUSE_OPEN_REQUEST; + +typedef struct { + UINT64 FileHandle; + UINT32 OpenFlags; + UINT32 Padding; +} VIRTIO_FS_FUSE_OPEN_RESPONSE; + // // Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner; @@ -170,25 +191,11 @@ typedef struct { UINT16 MaxBackground; UINT16 CongestionThreshold; UINT32 MaxWrite; UINT32 TimeGran; UINT16 MaxPages; UINT16 MapAlignment; UINT32 Unused[8]; } VIRTIO_FS_FUSE_INIT_RESPONSE; - -// -// Headers for VirtioFsFuseOpOpenDir. -// -typedef struct { - UINT32 Flags; - UINT32 Unused; -} VIRTIO_FS_FUSE_OPEN_REQUEST; - -typedef struct { - UINT64 FileHandle; - UINT32 OpenFlags; - UINT32 Padding; -} VIRTIO_FS_FUSE_OPEN_RESPONSE; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 0c92bccdac86..dc9a12820f3d 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,16 +81,17 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseOpen.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 487d215c7f38..c13258a2e08f 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -230,16 +230,24 @@ VirtioFsAppendPath ( // =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); =20 +EFI_STATUS +VirtioFsFuseOpen ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN BOOLEAN ReadWrite, + OUT UINT64 *FuseHandle + ); + EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseOpen.c b/OvmfPkg/VirtioFsDxe/FuseOpen.c new file mode 100644 index 000000000000..b731580729b6 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseOpen.c @@ -0,0 +1,126 @@ +/** @file + FUSE_OPEN wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_OPEN request to the Virtio Filesystem device, for opening a + regular file. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_O= PEN + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the regular file to open. + + @param[in] ReadWrite If TRUE, open the regular file in read-write mo= de. + If FALSE, open the regular file in read-only mo= de. + + @param[out] FuseHandle The open handle to the regular file, returned b= y the + Virtio Filesystem device. + + @retval EFI_SUCCESS The regular file has been opened. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseOpen ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN BOOLEAN ReadWrite, + OUT UINT64 *FuseHandle + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_OPEN_REQUEST OpenReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp; + VIRTIO_FS_IO_VECTOR RespIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &OpenReq; + ReqIoVec[1].Size =3D sizeof OpenReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &OpenResp; + RespIoVec[1].Size =3D sizeof OpenResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpOpen, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_OPEN-specific fields. + // + OpenReq.Flags =3D (ReadWrite ? + VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR : + VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY); + OpenReq.Unused =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu ReadWrite=3D%d= " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, NodeId, ReadWrite, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the open handle. + // + *FuseHandle =3D OpenResp.FileHandle; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69032): https://edk2.groups.io/g/devel/message/69032 Mute This Topic: https://groups.io/mt/79023292/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-