From nobody Mon Feb 9 19:52:24 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+69034+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+69034+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155630; cv=none; d=zohomail.com; s=zohoarc; b=RjRqFOr5LpXhpkm7DQlJg69hZq5nkGFAhEWUJdqDXgjW8AHPlsWp/qKzO7xn0H+J9XdUcvQU7elHSF7KzPBvxQ6HREGcA6B2sFyTtdH1puxEgMQFEWefGQgUwt68IzkXPW0KsVQUmzimg/QiHyFaC3/qiiBjIKn49H+jHkRK08o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155630; 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=SPiyeWRUxzVmpbFzxk8/pG6/krjJybkKWm45k3YPsJ4=; b=HVibbFxBYE7HOdGyMXurwQ9QC4n/odZ7ViCoCJmylLxce7Qw1gcpmJmACG04LB15rDr+No3naRl1rzFjPFjYqE4xLh3N/iRucIwKH0uU1DNRePVTCo495VmZg6aZ9lLNNruGcy/p/nhB77bxiCAV4zJvgb3/sfhioEiJ86hzIj4= 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+69034+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 1608155630299980.8521597267653; Wed, 16 Dec 2020 13:53:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id o7w6YY1788612xrQka10qniP; Wed, 16 Dec 2020 13:53:49 -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.4017.1608155624147552000 for ; Wed, 16 Dec 2020 13:53:44 -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-470-f8goCZPdOL6hhzyxTkNEAA-1; Wed, 16 Dec 2020 16:53:39 -0500 X-MC-Unique: f8goCZPdOL6hhzyxTkNEAA-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D561107ACE6; Wed, 16 Dec 2020 21:53:38 +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 8F00A5D9C0; Wed, 16 Dec 2020 21:53:33 +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 20/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_CREATE Date: Wed, 16 Dec 2020 22:10:57 +0100 Message-Id: <20201216211125.19496-21-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.14 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: vGheoPozePXtUAaEgHTk71Jsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155629; bh=SPiyeWRUxzVmpbFzxk8/pG6/krjJybkKWm45k3YPsJ4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=C+4ifVdcuF0aSEY3N5haaEwO/txkFw70LR0SjPnO67kbWewtJ0hUcX5qvG4QvRiDztK 1BKZVyy0bM7tYW6VnVpgO8+qGL16fzpBuDdJLZhwB44YAAS1gYlcOHtZx9s4P5UoevIDw we2glThvM7tWMQYH9EOty/njVdRikvPZ5oQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseOpenOrCreate() function, for sending the FUSE_CREATE 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 | 17 +++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 9 ++ OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c | 155 ++++++++++++++++++++ 4 files changed, 182 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 9ffeb9c8c954..63aced229e9b 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -80,18 +80,24 @@ typedef struct { // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 // // File mode bitmasks. // #define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u +#define VIRTIO_FS_FUSE_MODE_PERM_RUSR 0000400u +#define VIRTIO_FS_FUSE_MODE_PERM_WUSR 0000200u #define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u +#define VIRTIO_FS_FUSE_MODE_PERM_RGRP 0000040u +#define VIRTIO_FS_FUSE_MODE_PERM_WGRP 0000020u #define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u +#define VIRTIO_FS_FUSE_MODE_PERM_ROTH 0000004u +#define VIRTIO_FS_FUSE_MODE_PERM_WOTH 0000002u =20 // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // @@ -103,16 +109,17 @@ typedef enum { VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, + VirtioFsFuseOpCreate =3D 35, } VIRTIO_FS_FUSE_OPCODE; =20 #pragma pack (1) // // Request-response headers common to all request types. // typedef struct { UINT32 Len; @@ -246,11 +253,21 @@ typedef struct { UINT16 MaxBackground; UINT16 CongestionThreshold; UINT32 MaxWrite; UINT32 TimeGran; UINT16 MaxPages; UINT16 MapAlignment; UINT32 Unused[8]; } VIRTIO_FS_FUSE_INIT_RESPONSE; + +// +// Header for VirtioFsFuseOpCreate. +// +typedef struct { + UINT32 Flags; + UINT32 Mode; + UINT32 Umask; + UINT32 Padding; +} VIRTIO_FS_FUSE_CREATE_REQUEST; #pragma pack () =20 #endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index eebb86f7c275..b942baa4a772 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -84,16 +84,17 @@ [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c FuseMkDir.c FuseOpen.c FuseOpenDir.c + FuseOpenOrCreate.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c SimpleFsGetPosition.c SimpleFsOpen.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index 8fd56bdbf6e1..795cf4ee5d7d 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -281,16 +281,25 @@ VirtioFsFuseInitSession ( =20 EFI_STATUS VirtioFsFuseOpenDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT UINT64 *FuseHandle ); =20 +EFI_STATUS +VirtioFsFuseOpenOrCreate ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c b/OvmfPkg/VirtioFsDxe/F= useOpenOrCreate.c new file mode 100644 index 000000000000..60ab002bcd99 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseOpenOrCreate.c @@ -0,0 +1,155 @@ +/** @file + FUSE_CREATE wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_CREATE request to the Virtio Filesystem device, for opening a + regular file with (O_RDWR | O_CREAT) semantics. + + 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_C= REATE + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] ParentNodeId The inode number of the direct parent directory= of + the regular file to open or create. + + @param[in] Name The single-component filename of the regular fi= le to + open or create, under the parent directory + identified by ParentNodeId. + + @param[out] NodeId The inode number of the regular file, returned = by + the Virtio Filesystem device. + + @param[out] FuseHandle The open file handle returned by the Virtio + Filesystem device. + + @retval EFI_SUCCESS The regular file has been opened, and (if necessary) + created. + + @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 +VirtioFsFuseOpenOrCreate ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId, + OUT UINT64 *FuseHandle + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_CREATE_REQUEST CreateReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + VIRTIO_FS_FUSE_OPEN_RESPONSE OpenResp; + VIRTIO_FS_IO_VECTOR RespIoVec[4]; + 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 &CreateReq; + ReqIoVec[1].Size =3D sizeof CreateReq; + ReqIoVec[2].Buffer =3D Name; + ReqIoVec[2].Size =3D AsciiStrSize (Name); + 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 &NodeResp; + RespIoVec[1].Size =3D sizeof NodeResp; + RespIoVec[2].Buffer =3D &AttrResp; + RespIoVec[2].Size =3D sizeof AttrResp; + RespIoVec[3].Buffer =3D &OpenResp; + RespIoVec[3].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, + VirtioFsFuseOpCreate, ParentNodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_CREATE-specific fields. + // + // VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR is why this request can never open a + // directory (EISDIR). And VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR is consistent = with + // the only OpenMode of EFI_FILE_PROTOCOL.Open() that enables filesystem + // object creation -- that is, Create/Read/Write. + // + CreateReq.Flags =3D VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR; + CreateReq.Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RUSR | + VIRTIO_FS_FUSE_MODE_PERM_WUSR | + VIRTIO_FS_FUSE_MODE_PERM_RGRP | + VIRTIO_FS_FUSE_MODE_PERM_WGRP | + VIRTIO_FS_FUSE_MODE_PERM_ROTH | + VIRTIO_FS_FUSE_MODE_PERM_WOTH); + CreateReq.Umask =3D 0; + CreateReq.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 (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" ParentNodeId=3D%Lu Name=3D\= "%a\" " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the NodeId of the (possibly new) regular file. Also output the= open + // file handle. + // + *NodeId =3D NodeResp.NodeId; + *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 (#69034): https://edk2.groups.io/g/devel/message/69034 Mute This Topic: https://groups.io/mt/79023402/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-