From nobody Mon Feb 9 14:33:59 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+69024+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+69024+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154360; cv=none; d=zohomail.com; s=zohoarc; b=Vkug68h7mM9/YZ9kMOlt/jTxP0TEerMJOQZyWqor3vDCFQD6o0Hosvp/XAwzxnyMUJtEHW7cT2XNGfXlfM5Dx0ecab4uLynNBUhSV5mAV8w+3KEVypmlkjgKRcgkrxixuniRBgHot4fDASlg2BK6+yT0SUtkBl2qrGU3cDqQJKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154360; 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=YhddnC2ayftX733qFE3xnNkI+H57PAVlKj9Zpa9tNK4=; b=Jph+XYsadFw7TDSVi3699gJyGGeTZ44ANuMVdz6ED5j/UMyIZ7SZFR+xifGTB2AoShaZRbRB09YGw4MWZZCcVsgngEsuxnldyJ9O1LMK1uxF+5mrrNOBn268tl553fAzMPvHXxsJFCjH7WD+lI0xUSH+RR99cXwUeXC9oKVA4Zk= 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+69024+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 1608154360507362.22200937887897; Wed, 16 Dec 2020 13:32:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id X03hYY1788612xvwQ0Sk91Te; Wed, 16 Dec 2020 13:32:40 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.3685.1608154359536031779 for ; Wed, 16 Dec 2020 13:32:39 -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-462-qwsZ_4XdPpOCUb3RRBPX2A-1; Wed, 16 Dec 2020 16:32:34 -0500 X-MC-Unique: qwsZ_4XdPpOCUb3RRBPX2A-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7748E801B12; Wed, 16 Dec 2020 21:32:33 +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 68AA219CBD; Wed, 16 Dec 2020 21:32:28 +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 10/48] OvmfPkg/VirtioFsDxe: add shared wrapper for FUSE_RELEASE / FUSE_RELEASEDIR Date: Wed, 16 Dec 2020 22:10:47 +0100 Message-Id: <20201216211125.19496-11-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.11 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: ngiEDe29klcoKgUnXgCdkRfJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154360; bh=YhddnC2ayftX733qFE3xnNkI+H57PAVlKj9Zpa9tNK4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bEvmZtU/zFb8McNsYaRnLsNRn6dQOWBvnWaLHUzOH6ot6J3mYCFvoTQ1MkP6NqhKpZp p87CgxIbt/V4ZFdUjsqkfvqpor7TttrlLtqhZNWk7D+FqqulqfZhgWETxTIp13ydtuGSF isfYPbRGf1JWBi9x7oGPjB6xsN3p3JFhUos= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The FUSE_RELEASE and FUSE_RELEASEDIR commands only differ in the opcode. Add a common function called VirtioFsFuseReleaseFileOrDir() for sending either command. 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 | 12 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseRelease.c | 121 ++++++++++++++++++++ 4 files changed, 142 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index c48105325515..c17a43c160e3 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -75,18 +75,20 @@ typedef struct { // #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // FUSE operation codes. // typedef enum { + VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, + VirtioFsFuseOpReleaseDir =3D 29, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -100,16 +102,26 @@ typedef struct { } VIRTIO_FS_FUSE_REQUEST; =20 typedef struct { UINT32 Len; INT32 Error; UINT64 Unique; } VIRTIO_FS_FUSE_RESPONSE; =20 +// +// Header for VirtioFsFuseOpRelease and VirtioFsFuseOpReleaseDir. +// +typedef struct { + UINT64 FileHandle; + UINT32 Flags; + UINT32 ReleaseFlags; + UINT64 LockOwner; +} VIRTIO_FS_FUSE_RELEASE_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 051acbdd7199..95b1a5a8f60a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -79,16 +79,17 @@ [Defines] [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseInit.c FuseOpenDir.c + FuseRelease.c Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 9c47454435ae..a99625d0473a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -153,16 +153,24 @@ EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32 Errno ); =20 // // Wrapper functions for FUSE commands (primitives). // =20 +EFI_STATUS +VirtioFsFuseReleaseFileOrDir ( + 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/FuseRelease.c b/OvmfPkg/VirtioFsDxe/FuseRe= lease.c new file mode 100644 index 000000000000..dd45c7864fc8 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseRelease.c @@ -0,0 +1,121 @@ +/** @file + FUSE_RELEASE / FUSE_RELEASEDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Close a regular file or a directory that is open, by sending the FUSE_RE= LEASE + or FUSE_RELEASEDIR 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_RELEASE / FUSE_RELEASEDIR request to. On + output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] NodeId The inode number of the file or directory to cl= ose. + + @param[in] FuseHandle The open handle to the file or directory to clo= se. + + @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 closed. + + @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 +VirtioFsFuseReleaseFileOrDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 FuseHandle, + IN BOOLEAN IsDir + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_RELEASE_REQUEST ReleaseReq; + 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 &ReleaseReq; + ReqIoVec[1].Size =3D sizeof ReleaseReq; + 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 ? VirtioFsFuseOpReleaseDir : VirtioFsFuseOpRelease, + NodeId + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_RELEASE- / FUSE_RELEASEDIR-specific fields. + // + ReleaseReq.FileHandle =3D FuseHandle; + ReleaseReq.Flags =3D 0; + ReleaseReq.ReleaseFlags =3D 0; + ReleaseReq.LockOwner =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 (#69024): https://edk2.groups.io/g/devel/message/69024 Mute This Topic: https://groups.io/mt/79022927/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-