From nobody Mon Feb 9 09:09:10 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+69058+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+69058+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608158653; cv=none; d=zohomail.com; s=zohoarc; b=XWdjg/FagUgscdL0R7GTCPdJV68ecbX22jIdcrS7PhFQPlXGYrh/QEsPe6SNKqx1PfMYPcC5K7n7N6FF8ErF2omdEwBJek99iFwr4yitXOuR7iC43gHr2zs0bG681uLd1/zmjdGZOw6fnuokcE9JIhAXyd+B3umls5wVrRODCAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608158653; 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=GDKgXsLLfEpksZmu4mx6QXbPFlFmETY5bHM+hlGtZSE=; b=mTpbH+Y2FPlr7038cew+Jw2BazWH0ozy1UAdbXLnhNrxlOX/zxtU9X3eD1ISNvfE03bB8yF1/ggl5GwaIZMyWcLAax7n294KvZf9jMutEjbqOQTDLaURF/erWxgY7cb9phNyaJVALgQOmyA6iDJGj4Yq9UlDTo1/tzZ67M1wzq8= 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+69058+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 1608158653596116.24269579735142; Wed, 16 Dec 2020 14:44:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5pHrYY1788612xNd4YJDISVv; Wed, 16 Dec 2020 14:44:13 -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.web12.5082.1608158652539132251 for ; Wed, 16 Dec 2020 14:44:12 -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-261-s4poW6tuPAqI_9iaqKkCHQ-1; Wed, 16 Dec 2020 17:44:10 -0500 X-MC-Unique: s4poW6tuPAqI_9iaqKkCHQ-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 A983410054FF; Wed, 16 Dec 2020 22:44:08 +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 1D7A85D9C0; Wed, 16 Dec 2020 22:44:00 +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 44/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_SETATTR Date: Wed, 16 Dec 2020 22:11:21 +0100 Message-Id: <20201216211125.19496-45-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: iEoQNjVQn5OBntvz0thoaJ7Kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608158653; bh=GDKgXsLLfEpksZmu4mx6QXbPFlFmETY5bHM+hlGtZSE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=sphupKZbSsjVE/vpmkNofMXKpDF1RuzjWgjJ7Rw/jwOjLskmYPb3+utIXpLJeshkkHO X3wtWlPoJsLu+9dGJWWbx5Iu0hFkdYLLBxyaxbw33xrpnvasQk3iTj1MNW7OSJNBeqTey JyizphRY1ZbtRc75wjUIe9U9H4X8T7TmnT4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseSetAttr() function, for sending the FUSE_SETATTR 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 | 10 ++ OvmfPkg/VirtioFsDxe/FuseSetAttr.c | 174 ++++++++++++++++++++ 4 files changed, 219 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 0b2ed7010046..15fb28f95a28 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -97,16 +97,25 @@ typedef struct { #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 VirtioFsFuseOpSetAttr, in the VIRTIO_FS_FUSE_SETATTR_REQUEST.= Valid +// field. +// +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE BIT0 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE BIT3 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME BIT4 +#define VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME BIT5 + // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // // Flags for VirtioFsFuseOpInit. @@ -148,16 +157,17 @@ typedef struct { =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpLookup =3D 1, VirtioFsFuseOpForget =3D 2, VirtioFsFuseOpGetAttr =3D 3, + VirtioFsFuseOpSetAttr =3D 4, VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpUnlink =3D 10, VirtioFsFuseOpRmDir =3D 11, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRead =3D 15, VirtioFsFuseOpWrite =3D 16, VirtioFsFuseOpStatFs =3D 17, VirtioFsFuseOpRelease =3D 18, @@ -235,30 +245,53 @@ typedef struct { // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 // -// Headers for VirtioFsFuseOpGetAttr. +// Headers for VirtioFsFuseOpGetAttr (VIRTIO_FS_FUSE_GETATTR_RESPONSE is a= lso +// for VirtioFsFuseOpSetAttr). // typedef struct { UINT32 GetAttrFlags; UINT32 Dummy; UINT64 FileHandle; } VIRTIO_FS_FUSE_GETATTR_REQUEST; =20 typedef struct { UINT64 AttrValid; UINT32 AttrValidNsec; UINT32 Dummy; } VIRTIO_FS_FUSE_GETATTR_RESPONSE; =20 +// +// Header for VirtioFsFuseOpSetAttr. +// +typedef struct { + UINT32 Valid; + UINT32 Padding; + UINT64 FileHandle; + UINT64 Size; + UINT64 LockOwner; + UINT64 Atime; + UINT64 Mtime; + UINT64 Ctime; + UINT32 AtimeNsec; + UINT32 MtimeNsec; + UINT32 CtimeNsec; + UINT32 Mode; + UINT32 Unused4; + UINT32 Uid; + UINT32 Gid; + UINT32 Unused5; +} VIRTIO_FS_FUSE_SETATTR_REQUEST; + // // Header for VirtioFsFuseOpMkDir. // typedef struct { UINT32 Mode; UINT32 Umask; } VIRTIO_FS_FUSE_MKDIR_REQUEST; =20 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 9dccd7d6a9ef..8d962bcdc18c 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -91,16 +91,17 @@ [Sources] FuseLookup.c FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseOpenOrCreate.c FuseRead.c FuseRelease.c FuseRename.c + FuseSetAttr.c FuseStatFs.c FuseUnlink.c FuseWrite.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 a6dfac71f4a7..9e6348f9386e 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -303,16 +303,26 @@ VirtioFsFuseForget ( =20 EFI_STATUS VirtioFsFuseGetAttr ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, OUT VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr ); =20 +EFI_STATUS +VirtioFsFuseSetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 *Size OPTIONAL, + IN UINT64 *Atime OPTIONAL, + IN UINT64 *Mtime OPTIONAL, + IN UINT32 *Mode OPTIONAL + ); + EFI_STATUS VirtioFsFuseMkDir ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 ParentNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseSetAttr.c b/OvmfPkg/VirtioFsDxe/FuseSe= tAttr.c new file mode 100644 index 000000000000..dcd014172022 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseSetAttr.c @@ -0,0 +1,174 @@ +/** @file + FUSE_SETATTR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Send the FUSE_SETATTR request to the Virtio Filesystem device, for chang= ing + the attributes of an inode. + + 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_SETATTR request to. On output, the FUSE re= quest + counter "VirtioFs->RequestId" will have been + incremented. + + @param[in] NodeId The inode number representing the regular file = or + directory whose attributes should be changed. + + @param[in] Size The new size to set for the regular file. If NU= LL, + then the file size will not be changed. If Node= Id + refers to a directory, then the caller is + responsible for passing NULL as Size. + + @param[in] Atime The new last access time to set for the regular= file + or directory (seconds since the Epoch). If NULL, + then the last access time is not changed. + + @param[in] Mtime The new last modification time to set for the + regular file or directory (seconds since the Ep= och). + If NULL, then the last modification time is not + changed. + + @param[in] Mode The new file mode bits to set for the regular f= ile + or directory. If NULL, then the file mode bits = are + not changed. + + @retval EFI_SUCCESS The attributes have been updated. + + @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 +VirtioFsFuseSetAttr ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 NodeId, + IN UINT64 *Size OPTIONAL, + IN UINT64 *Atime OPTIONAL, + IN UINT64 *Mtime OPTIONAL, + IN UINT32 *Mode OPTIONAL + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_SETATTR_REQUEST AttrReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[2]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_GETATTR_RESPONSE GetAttrResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + VIRTIO_FS_IO_VECTOR RespIoVec[3]; + 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 &AttrReq; + ReqIoVec[1].Size =3D sizeof AttrReq; + 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 &GetAttrResp; + RespIoVec[1].Size =3D sizeof GetAttrResp; + RespIoVec[2].Buffer =3D &AttrResp; + RespIoVec[2].Size =3D sizeof AttrResp; + 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, + VirtioFsFuseOpSetAttr, NodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_SETATTR-specific fields. + // + AttrReq.Valid =3D 0; + AttrReq.Padding =3D 0; + AttrReq.FileHandle =3D 0; + AttrReq.Size =3D (Size =3D=3D NULL) ? 0 : *Size; + AttrReq.LockOwner =3D 0; + AttrReq.Atime =3D (Atime =3D=3D NULL) ? 0 : *Atime; + AttrReq.Mtime =3D (Mtime =3D=3D NULL) ? 0 : *Mtime; + AttrReq.Ctime =3D 0; + AttrReq.AtimeNsec =3D 0; + AttrReq.MtimeNsec =3D 0; + AttrReq.CtimeNsec =3D 0; + AttrReq.Mode =3D (Mode =3D=3D NULL) ? 0 : *Mode; + AttrReq.Unused4 =3D 0; + AttrReq.Uid =3D 0; + AttrReq.Gid =3D 0; + AttrReq.Unused5 =3D 0; + + if (Size !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_SIZE; + } + if (Atime !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_ATIME; + } + if (Mtime !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_MTIME; + } + if (Mode !=3D NULL) { + AttrReq.Valid |=3D VIRTIO_FS_FUSE_SETATTR_REQ_F_MODE; + } + + // + // 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", __FUNCTION__, + VirtioFs->Label, NodeId)); + if (Size !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Size=3D0x%Lx", *Size)); + } + if (Atime !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Atime=3D%Lu", *Atime)); + } + if (Mtime !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Mtime=3D%Lu", *Mtime)); + } + if (Mode !=3D NULL) { + DEBUG ((DEBUG_ERROR, " Mode=3D0x%x", *Mode)); // no support for octa= l :/ + } + DEBUG ((DEBUG_ERROR, " Errno=3D%d\n", 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 (#69058): https://edk2.groups.io/g/devel/message/69058 Mute This Topic: https://groups.io/mt/79024549/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-