From nobody Mon Feb 9 07:06:00 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+69027+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+69027+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154739; cv=none; d=zohomail.com; s=zohoarc; b=jnzNfgDSa300eRWttm+sj9vssgp9JJOuDvPwzKs4Bdsk+CupYLv4kVMDhJdkNExa1us6pB5xkdGJuTldVOHY4m6irtoWqTU0GXO/eY1HxkpUuyUEpY5TmsfPFVvg5aUppHxQONzmM+Fk6n4p+uFyZHfgHjUA+MNDe2wf+jhZiGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154739; 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=cCvsPd5UAXdEUbk8RLnxJppe2O0OanczctWK8RXoTzU=; b=gIaKrapqpRQajXx1kezvOgRxdspKLXp6Ls3f+OzMOXFNyJwUiP195ChHIldUbeOB1ktA5b26NydCQPMx0gliRPyMgHNl5w5jyCM24CcNgH8lD/p9XZ+wn5099AEXOia38a9nxbxmR7Y5m79KU44ItPdDRxpeAZn5xeLxsVuCIAU= 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+69027+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 1608154739017582.529942879904; Wed, 16 Dec 2020 13:38:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id N3iFYY1788612xreJgAn82rA; Wed, 16 Dec 2020 13:38:58 -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.web08.3936.1608154737860626420 for ; Wed, 16 Dec 2020 13:38:58 -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-321-9T45EBEAMRCPUmoD4cq_Lg-1; Wed, 16 Dec 2020 16:38:53 -0500 X-MC-Unique: 9T45EBEAMRCPUmoD4cq_Lg-1 X-Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE0D4180A087; Wed, 16 Dec 2020 21:38:51 +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 3566460C9C; Wed, 16 Dec 2020 21:38:47 +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 13/48] OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_FSYNC / FUSE_FSYNCDIR Date: Wed, 16 Dec 2020 22:10:50 +0100 Message-Id: <20201216211125.19496-14-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.13 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: UUQXtf4aGERJMt7HEx0DVhzJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154738; bh=cCvsPd5UAXdEUbk8RLnxJppe2O0OanczctWK8RXoTzU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=oXNq755jz1J3NFxNLEMI2Y+IGpWUprKnyENYPJxi1kqZUyNhQjLVrGXNKNv6PjAKGMF wmsWFbK8k0W+313M7P4d2hmhhR1fwzWUXVj4sMm2SyeK7Z9wtLqT2sTYZY/4rEhD8zYT7 F2RUenRCtiW4jUFNppCym9qpv9r2N0xTe6k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The FUSE_FSYNC and FUSE_FSYNCDIR commands only differ in the opcode. Add a common function for wrapping both. 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 | 11 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseFsync.c | 121 ++++++++++++++++++++ 4 files changed, 141 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 0241daf1e8d6..797d94a39a39 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -82,19 +82,21 @@ typedef struct { #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpRelease =3D 18, + VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, + VirtioFsFuseOpFsyncDir =3D 30, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -125,16 +127,25 @@ typedef struct { // typedef struct { UINT64 FileHandle; UINT32 Flags; UINT32 ReleaseFlags; UINT64 LockOwner; } VIRTIO_FS_FUSE_RELEASE_REQUEST; =20 +// +// Header for VirtioFsFuseOpFsync and VirtioFsFuseOpFsyncDir. +// +typedef struct { + UINT64 FileHandle; + UINT32 FsyncFlags; + UINT32 Padding; +} VIRTIO_FS_FUSE_FSYNC_REQUEST; + // // Headers for VirtioFsFuseOpInit. // typedef struct { UINT32 Major; UINT32 Minor; UINT32 MaxReadahead; UINT32 Flags; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index baeb741be18f..839660a0f904 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -78,16 +78,17 @@ [Defines] =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseForget.c + FuseFsync.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 68ed6cd7e6a1..ac1fb8965472 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -204,16 +204,24 @@ VirtioFsFuseForget ( EFI_STATUS VirtioFsFuseReleaseFileOrDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir ); =20 +EFI_STATUS +VirtioFsFuseFsyncFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ); + EFI_STATUS VirtioFsFuseInitSession ( IN OUT VIRTIO_FS *VirtioFs ); =20 EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, diff --git a/OvmfPkg/VirtioFsDxe/FuseFsync.c b/OvmfPkg/VirtioFsDxe/FuseFsyn= c.c new file mode 100644 index 000000000000..ea1463cd8073 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseFsync.c @@ -0,0 +1,121 @@ +/** @file + FUSE_FSYNC / FUSE_FSYNCDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Synchronize the in-core state of a regular file or a directory with the + storage device on the host, by sending the FUSE_FSYNC or FUSE_FSYNCDIR + request to the Virtio Filesystem device. + + 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_F= SYNC + / FUSE_FSYNCDIR request to. On output, the FUSE + request counter "VirtioFs->RequestId" will have= been + incremented. + + @param[in] NodeId The inode number of the file or directory to sy= nc. + + @param[in] FuseHandle The open handle to the file or directory to syn= c. + + @param[in] IsDir TRUE if NodeId and FuseHandle refer to a direct= ory, + FALSE if NodeId and FuseHandle refer to a regul= ar + file. + + @retval EFI_SUCCESS The file or directory has been synchronized. + + @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 +VirtioFsFuseFsyncFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_FSYNC_REQUEST FsyncReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_IO_VECTOR RespIoVec[1]; + 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 &FsyncReq; + ReqIoVec[1].Size =3D sizeof FsyncReq; + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + 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.TotalSize, + IsDir ? VirtioFsFuseOpFsyncDir : VirtioFsFuseOpFsync, + NodeId + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_FSYNC- / FUSE_FSYNCDIR-specific fields. + // + FsyncReq.FileHandle =3D FuseHandle; + FsyncReq.FsyncFlags =3D 0; + FsyncReq.Padding =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 (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" NodeId=3D%Lu FuseHandle=3D%Lu= " + "IsDir=3D%d Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, NodeId, Fu= seHandle, + IsDir, CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; +} --=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 (#69027): https://edk2.groups.io/g/devel/message/69027 Mute This Topic: https://groups.io/mt/79023053/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-