From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913957; cv=none; d=zohomail.com; s=zohoarc; b=Nv2nmYojH914UgBG8dz+UUaqSRcW0dhDJZk3zCwQMp85ggs8JI9YIMgTKkHBeqLxtZVlqFUFIKhiwAC9qaCtoZM/LfQy4JDy1XeCyCT9nVsUH6Z43XOGjOp4UCjbj7ySjHrtlia0fHJlpz3TesPImQAtxd5uGqpq5Y2sev3v8mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913957; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DjsZaSOIcJ6iFahsf84mXvc0XkEk+3Mf01A/EmIC1Ic=; b=E8Y1f0dyKoy0pGjj7jC7NxuSH0pwhKSxkUbHUMKd03TxIfNnHrGzRr6z8mirdE6ThyWRHmDH1nPQ7geT8HLNStXoSHIrHh44+vFZ7mwf4Dy+fjMA9Zpqh501oGQm8+aOsmoqWtJF4sLLBjO9Qw1TR0FKsuTjNr6rz51TvXhujRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913957723707.459350238489; Tue, 11 Jan 2022 07:12:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255864.438718 (Exim 4.92) (envelope-from ) id 1n7Iou-0002XO-Ed; Tue, 11 Jan 2022 15:12:20 +0000 Received: by outflank-mailman (output) from mailman id 255864.438718; Tue, 11 Jan 2022 15:12:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iou-0002Wr-7K; Tue, 11 Jan 2022 15:12:20 +0000 Received: by outflank-mailman (input) for mailman id 255864; Tue, 11 Jan 2022 15:12:19 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iot-0002Fw-CB for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:19 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dd43726e-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:17 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 258AF212C2; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F1B0F1404B; Tue, 11 Jan 2022 15:12:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QOfQOVCe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dd43726e-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DjsZaSOIcJ6iFahsf84mXvc0XkEk+3Mf01A/EmIC1Ic=; b=SunZVRlMBMQ3pF24OyRoCstzJwKxSJCyqCjGXv45rBsLO5hncikrQd1hFjeYQYTbe65f1b j7YVDhEm4/KrPjfX5hXdCXlxftCzURRb4u6dYwLVS9XUGgcpmowd7zp4zR7njak382zbOJ m9iIHn/cRS6SIi26mR9kVwyOPi5SfBA= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 01/12] mini-os: remove event channel specific struct file definitions Date: Tue, 11 Jan 2022 16:12:04 +0100 Message-Id: <20220111151215.22955-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913959047100005 Content-Type: text/plain; charset="utf-8" The event channel specific union member in struct file is no longer needed, so remove it together with the associated structure definitions. The event channel file type and its associated handling can be removed, too, as libxenevtchn is now supplying a struct file_ops via a call of alloc_file_type(). This removes all contents of CONFIG_LIBXENEVTCHN guarded sections, so this config option can be removed. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- Config.mk | 1 - arch/x86/testbuild/all-no | 1 - arch/x86/testbuild/all-yes | 1 - arch/x86/testbuild/newxen-yes | 1 - include/lib.h | 15 +-------------- lib/sys.c | 7 ------- 6 files changed, 1 insertion(+), 25 deletions(-) diff --git a/Config.mk b/Config.mk index 1e08388..c244adc 100644 --- a/Config.mk +++ b/Config.mk @@ -197,7 +197,6 @@ CONFIG-n +=3D CONFIG_PARAVIRT endif # Support legacy CONFIG_XC value CONFIG_XC ?=3D $(libc) -CONFIG-$(CONFIG_XC) +=3D CONFIG_LIBXENEVTCHN CONFIG-$(CONFIG_XC) +=3D CONFIG_LIBXENGNTTAB =20 CONFIG-$(lwip) +=3D CONFIG_LWIP diff --git a/arch/x86/testbuild/all-no b/arch/x86/testbuild/all-no index d6fc260..202c317 100644 --- a/arch/x86/testbuild/all-no +++ b/arch/x86/testbuild/all-no @@ -13,7 +13,6 @@ CONFIG_FBFRONT =3D n CONFIG_KBDFRONT =3D n CONFIG_CONSFRONT =3D n CONFIG_XENBUS =3D n -CONFIG_LIBXENEVTCHN =3D n CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n CONFIG_BALLOON =3D n diff --git a/arch/x86/testbuild/all-yes b/arch/x86/testbuild/all-yes index 98bbfeb..eb495a4 100644 --- a/arch/x86/testbuild/all-yes +++ b/arch/x86/testbuild/all-yes @@ -16,6 +16,5 @@ CONFIG_XENBUS =3D y CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y # The following are special: they need support from outside -CONFIG_LIBXENEVTCHN =3D n CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n diff --git a/arch/x86/testbuild/newxen-yes b/arch/x86/testbuild/newxen-yes index 0603200..bf25ace 100644 --- a/arch/x86/testbuild/newxen-yes +++ b/arch/x86/testbuild/newxen-yes @@ -17,6 +17,5 @@ CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y XEN_INTERFACE_VERSION=3D__XEN_LATEST_INTERFACE_VERSION__ # The following are special: they need support from outside -CONFIG_LIBXENEVTCHN =3D n CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n diff --git a/include/lib.h b/include/lib.h index 4892320..df972ef 100644 --- a/include/lib.h +++ b/include/lib.h @@ -169,8 +169,7 @@ void sanity_check(void); #define FTYPE_TPM_TIS 11 #define FTYPE_XENBUS 12 #define FTYPE_GNTMAP 13 -#define FTYPE_EVTCHN 14 -#define FTYPE_N 15 +#define FTYPE_N 14 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); @@ -199,15 +198,6 @@ off_t lseek_default(int fd, off_t offset, int whence); bool select_yes(int fd); bool select_read_flag(int fd); =20 -LIST_HEAD(evtchn_port_list, evtchn_port_info); - -struct evtchn_port_info { - LIST_ENTRY(evtchn_port_info) list; - evtchn_port_t port; - unsigned long pending; - int bound; -}; - struct file { unsigned int type; bool read; /* maybe available for read */ @@ -215,9 +205,6 @@ struct file { union { int fd; /* Any fd from an upper layer. */ void *dev; - struct { - struct evtchn_port_list ports; - } evtchn; struct gntmap gntmap; }; }; diff --git a/lib/sys.c b/lib/sys.c index 52876e0..8fa1fee 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -505,11 +505,6 @@ int close(int fd) res =3D lwip_close(files[fd].fd); break; #endif -#ifdef CONFIG_LIBXENEVTCHN - case FTYPE_EVTCHN: - minios_evtchn_close_fd(fd); - break; -#endif #ifdef CONFIG_LIBXENGNTTAB case FTYPE_GNTMAP: minios_gnttab_close_fd(fd); @@ -723,7 +718,6 @@ static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", [FTYPE_CONSOLE] =3D "console", [FTYPE_XENBUS] =3D "xenbus", - [FTYPE_EVTCHN] =3D "evtchn", [FTYPE_SOCKET] =3D "socket", [FTYPE_TAP] =3D "net", [FTYPE_BLK] =3D "blk", @@ -915,7 +909,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_se= t *writefds, fd_set *exce FD_CLR(i, exceptfds); break; #endif - case FTYPE_EVTCHN: case FTYPE_TAP: case FTYPE_BLK: case FTYPE_KBD: --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913955; cv=none; d=zohomail.com; s=zohoarc; b=W6uYNf2GtrtKWQ+HlAgKCuMrIEPxGPtwqsYI5CC4bQPCNtl52Emonx/a4E0aYqo+ri74ETckm6g1tfh/nI4oAcwhOWVMbxaUve3dSmM7iAjvp1P0zVLwxPXlIvUrlzZYAjuM8zfbrFWParR467gWOSZX4mkBVZk/cIVCONW8yDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913955; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w1Lvr7st24bBGrZRxVwRlwFD2dxAwXVMl1+mfqeQNHE=; b=Uj9HZvSjuMVaxvhxvKT1+x3Plu3U+RvoDmUFchMbhIVj0M1PlciDUjsSdKFvtE40jVbITeb/ECARAKhO3/fRA4yJnpG/66hhduo5C4y+sVXSwQ86o6zi6gtv8G0IKN8yXAzREjQV2JKQveBa2Z0NkeVNGkPgZJkoUSsU17Jl5pI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 164191395590799.42803005231747; Tue, 11 Jan 2022 07:12:35 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255868.438743 (Exim 4.92) (envelope-from ) id 1n7Iox-00031A-Ck; Tue, 11 Jan 2022 15:12:23 +0000 Received: by outflank-mailman (output) from mailman id 255868.438743; Tue, 11 Jan 2022 15:12:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iox-00030L-2C; Tue, 11 Jan 2022 15:12:23 +0000 Received: by outflank-mailman (input) for mailman id 255868; Tue, 11 Jan 2022 15:12:21 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iov-0002Fw-Cj for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:21 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dd5d2c65-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:17 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 517B51F3B1; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2BB1213DDD; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OI96CVGe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dd5d2c65-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w1Lvr7st24bBGrZRxVwRlwFD2dxAwXVMl1+mfqeQNHE=; b=OZ0R2DCXa0L+ZUY2zZfTfxLjFTERlfqtPNXSkOfG19TQKIHgl69CgBeKlUz6peY6TRp2/G DFHQsTIY9bhNip/NE8/MESgTTBB1SQru9Acq+eimfagktjBzkoKmoURGNK5bA/9TJzkK3f k/Ids5H5XRPG9IpqldgDlUCVIH5LkCs= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 02/12] mini-os: remove gnttab specific member from struct file Date: Tue, 11 Jan 2022 16:12:05 +0100 Message-Id: <20220111151215.22955-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913958116100001 Content-Type: text/plain; charset="utf-8" The event channel specific union member in struct file is no longer needed, so remove it. The gnttab file type and its associated handling can be removed, too, as libxengnttab is now supplying a struct file_ops via a call of alloc_file_type(). This removes all contents of CONFIG_LIBXENGNTTAB guarded sections, so this config option can be removed. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- Config.mk | 1 - arch/x86/testbuild/all-no | 1 - arch/x86/testbuild/all-yes | 1 - arch/x86/testbuild/newxen-yes | 1 - gntmap.c | 2 +- include/lib.h | 4 +--- lib/sys.c | 5 ----- 7 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Config.mk b/Config.mk index c244adc..eb84515 100644 --- a/Config.mk +++ b/Config.mk @@ -197,7 +197,6 @@ CONFIG-n +=3D CONFIG_PARAVIRT endif # Support legacy CONFIG_XC value CONFIG_XC ?=3D $(libc) -CONFIG-$(CONFIG_XC) +=3D CONFIG_LIBXENGNTTAB =20 CONFIG-$(lwip) +=3D CONFIG_LWIP =20 diff --git a/arch/x86/testbuild/all-no b/arch/x86/testbuild/all-no index 202c317..c429354 100644 --- a/arch/x86/testbuild/all-no +++ b/arch/x86/testbuild/all-no @@ -13,7 +13,6 @@ CONFIG_FBFRONT =3D n CONFIG_KBDFRONT =3D n CONFIG_CONSFRONT =3D n CONFIG_XENBUS =3D n -CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n CONFIG_BALLOON =3D n CONFIG_USE_XEN_CONSOLE =3D n diff --git a/arch/x86/testbuild/all-yes b/arch/x86/testbuild/all-yes index eb495a4..6c6096b 100644 --- a/arch/x86/testbuild/all-yes +++ b/arch/x86/testbuild/all-yes @@ -16,5 +16,4 @@ CONFIG_XENBUS =3D y CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y # The following are special: they need support from outside -CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n diff --git a/arch/x86/testbuild/newxen-yes b/arch/x86/testbuild/newxen-yes index bf25ace..88094fc 100644 --- a/arch/x86/testbuild/newxen-yes +++ b/arch/x86/testbuild/newxen-yes @@ -17,5 +17,4 @@ CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y XEN_INTERFACE_VERSION=3D__XEN_LATEST_INTERFACE_VERSION__ # The following are special: they need support from outside -CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n diff --git a/gntmap.c b/gntmap.c index 6fa1dac..3422ab2 100644 --- a/gntmap.c +++ b/gntmap.c @@ -3,7 +3,7 @@ * * Diego Ongaro , July 2008 * - * Files of type FTYPE_GNTMAP contain a gntmap, which is an array of + * Files of libxengnttab contain a gntmap, which is an array of * (host address, grant handle) pairs. Grant handles come from a hyperviso= r map * operation and are needed for the corresponding unmap. * diff --git a/include/lib.h b/include/lib.h index df972ef..283abb8 100644 --- a/include/lib.h +++ b/include/lib.h @@ -168,8 +168,7 @@ void sanity_check(void); #define FTYPE_TPMFRONT 10 #define FTYPE_TPM_TIS 11 #define FTYPE_XENBUS 12 -#define FTYPE_GNTMAP 13 -#define FTYPE_N 14 +#define FTYPE_N 13 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); @@ -205,7 +204,6 @@ struct file { union { int fd; /* Any fd from an upper layer. */ void *dev; - struct gntmap gntmap; }; }; =20 diff --git a/lib/sys.c b/lib/sys.c index 8fa1fee..9540410 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -505,11 +505,6 @@ int close(int fd) res =3D lwip_close(files[fd].fd); break; #endif -#ifdef CONFIG_LIBXENGNTTAB - case FTYPE_GNTMAP: - minios_gnttab_close_fd(fd); - break; -#endif #ifdef CONFIG_NETFRONT case FTYPE_TAP: shutdown_netfront(files[fd].dev); --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913960; cv=none; d=zohomail.com; s=zohoarc; b=Jt6YFJd2V0E4QAWmh8n1/68rtqegNuKbXCRxrdtKoPvtwsHlDSnk9GEsfuuzGO6MJ7imX8IUYyuVW5qjPKLibaf9hA9Ovp6YuHzEax8XKymWp+dIvAc9513yeA+LperkyNCD/+OGqL+g4cjyyc/gXIA05pSrPnXfDFuyGrwqwdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913960; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gTPeNHy0AVh7duIevs+xqjLxKhkGSrZIz5TiPB1taxY=; b=WcE3PCSq2jUZYKFA2MXSrTRx2yr8sj0Bi7WJQ0kgOTKPFMn7CBKZKfI+dgOHeMcTrxxZMPzVZlam8wcmhSYGmDMpsZsjGb7SoyYOWan/cZa+9ztVAnZmuUD176u4yehqbmNDUwtOtTI+7/5Sa82EtBL+sriplnReae6DQ69EMxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913960232307.55089590170496; Tue, 11 Jan 2022 07:12:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255867.438738 (Exim 4.92) (envelope-from ) id 1n7Iow-0002yC-T3; Tue, 11 Jan 2022 15:12:22 +0000 Received: by outflank-mailman (output) from mailman id 255867.438738; Tue, 11 Jan 2022 15:12:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iow-0002y3-P5; Tue, 11 Jan 2022 15:12:22 +0000 Received: by outflank-mailman (input) for mailman id 255867; Tue, 11 Jan 2022 15:12:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iou-0002Fv-VK for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:21 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dd8042dd-72f0-11ec-9ce5-af14b9085ebd; Tue, 11 Jan 2022 16:12:17 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7BC961F3B8; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5665A13DDD; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UNUCFFGe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dd8042dd-72f0-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTPeNHy0AVh7duIevs+xqjLxKhkGSrZIz5TiPB1taxY=; b=IRkL3v6k2KUYC2e1crbEs0Lw5Izu4d+fHlophfX9cPw76G/pbv0YqXKfbEwbqEysaBI8xa Q3Fo82RyLoSralVP088j9JE1wfo/qBNlvFtKyVN6d2H2Bhtkk/28Xo3pLB6EP57ilJhV0p 4p7xRiGRrlwFAt+8mBeLO3eHtsG1gLM= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 03/12] mini-os: use alloc_file_type() and get_file_from_fd() in xs Date: Tue, 11 Jan 2022 16:12:06 +0100 Message-Id: <20220111151215.22955-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913961357100011 Content-Type: text/plain; charset="utf-8" Allocate the needed file type via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 3 +-- lib/sys.c | 18 -------------- lib/xs.c | 64 +++++++++++++++++++++++++++++++++++++------------ xenbus/xenbus.c | 1 + 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/include/lib.h b/include/lib.h index 283abb8..05c7de5 100644 --- a/include/lib.h +++ b/include/lib.h @@ -167,8 +167,7 @@ void sanity_check(void); #define FTYPE_BLK 9 #define FTYPE_TPMFRONT 10 #define FTYPE_TPM_TIS 11 -#define FTYPE_XENBUS 12 -#define FTYPE_N 13 +#define FTYPE_N 12 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index 9540410..d213ae5 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -495,11 +495,6 @@ int close(int fd) switch (files[fd].type) { default: break; -#ifdef CONFIG_XENBUS - case FTYPE_XENBUS: - xs_daemon_close((void*)(intptr_t) fd); - break; -#endif #ifdef HAVE_LWIP case FTYPE_SOCKET: res =3D lwip_close(files[fd].fd); @@ -712,7 +707,6 @@ int closedir(DIR *dir) static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", [FTYPE_CONSOLE] =3D "console", - [FTYPE_XENBUS] =3D "xenbus", [FTYPE_SOCKET] =3D "socket", [FTYPE_TAP] =3D "net", [FTYPE_BLK] =3D "blk", @@ -892,18 +886,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_s= et *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; -#ifdef CONFIG_XENBUS - case FTYPE_XENBUS: - if (FD_ISSET(i, readfds)) { - if (files[i].dev) - n++; - else - FD_CLR(i, readfds); - } - FD_CLR(i, writefds); - FD_CLR(i, exceptfds); - break; -#endif case FTYPE_TAP: case FTYPE_BLK: case FTYPE_KBD: diff --git a/lib/xs.c b/lib/xs.c index 4af0f96..ac830d2 100644 --- a/lib/xs.c +++ b/lib/xs.c @@ -18,23 +18,55 @@ static inline int _xs_fileno(struct xs_handle *h) { return (intptr_t) h; } =20 +static int xs_close_fd(int fd) +{ + struct xenbus_event *event, *next; + struct file *file =3D get_file_from_fd(fd); + + for (event =3D file->dev; event; event =3D next) + { + next =3D event->next; + free(event); + } + + return 0; +} + +static bool xs_can_read(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + return file && file->dev; +} + +static struct file_ops xenbus_ops =3D { + .name =3D "xenbus", + .close =3D xs_close_fd, + .select_rd =3D xs_can_read, +}; + struct xs_handle *xs_daemon_open() { - int fd =3D alloc_fd(FTYPE_XENBUS); - files[fd].dev =3D NULL; - printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].dev); + int fd; + struct file *file; + static unsigned int ftype_xenbus; + + if ( !ftype_xenbus ) + ftype_xenbus =3D alloc_file_type(&xenbus_ops); + + fd =3D alloc_fd(ftype_xenbus); + file =3D get_file_from_fd(fd); + if ( !file ) + return NULL; + + file->dev =3D NULL; + printk("xs_daemon_open -> %d, %p\n", fd, &file->dev); return (void*)(intptr_t) fd; } =20 void xs_daemon_close(struct xs_handle *h) { - int fd =3D _xs_fileno(h); - struct xenbus_event *event, *next; - for (event =3D files[fd].dev; event; event =3D next) - { - next =3D event->next; - free(event); - } + close(_xs_fileno(h)); } =20 int xs_fileno(struct xs_handle *h) @@ -169,18 +201,20 @@ char **xs_directory(struct xs_handle *h, xs_transacti= on_t t, =20 bool xs_watch(struct xs_handle *h, const char *path, const char *token) { - int fd =3D _xs_fileno(h); + struct file *file =3D get_file_from_fd(_xs_fileno(h)); + printk("xs_watch(%s, %s)\n", path, token); return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token, - (xenbus_event_queue *)&files[fd].dev)); + (xenbus_event_queue *)&file->dev)); } =20 char **xs_read_watch(struct xs_handle *h, unsigned int *num) { - int fd =3D _xs_fileno(h); struct xenbus_event *event; - event =3D files[fd].dev; - files[fd].dev =3D event->next; + struct file *file =3D get_file_from_fd(_xs_fileno(h)); + + event =3D file->dev; + file->dev =3D event->next; printk("xs_read_watch() -> %s %s\n", event->path, event->token); *num =3D 2; return (char **) &event->path; diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c index b687678..785389f 100644 --- a/xenbus/xenbus.c +++ b/xenbus/xenbus.c @@ -393,6 +393,7 @@ static int allocate_xenbus_id(void) void init_xenbus(void) { int err; + DEBUG("init_xenbus called.\n"); create_thread("xenstore", xenbus_thread_func, NULL); DEBUG("buf at %p.\n", xenstore_buf); --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913958; cv=none; d=zohomail.com; s=zohoarc; b=CZAMGCgu7EgB06unYJSZJ4S2h0LJuS40QfwArhZeI7jzHF/C6dmNml8C5TzLVAnnHHoys9vEaHDwhCJ6T6AdC7fb7CACWD6nRWe5IEqUtA3izfcLKVH0x+DIilAdEHmI4uJsCNPCJVZ27Hj7rNdlC0NDEaTTSLbtWZIuHYM8b0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913958; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eq4fsjhW0m7VHOVVZWDwPf/Gn+LXzVDVgJADrNIM91s=; b=jygJ4QLa3qri8NZz8+PpegQ9rdDRGPleaN+90Uswqzr9jbDp54ZO/S9F/RbRT8NDQwFp+gU8uyet5/ITed5ozUyUak8PTdCxGkOKp/sGpjzm/5fhvlIsUYJf+os9FlTJtQj7e1YcNomQ4J7BGJM+3LFx3pcHSvnSg2bYidjk2/k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913958115431.64294209114814; Tue, 11 Jan 2022 07:12:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255872.438767 (Exim 4.92) (envelope-from ) id 1n7Ioz-0003YB-Js; Tue, 11 Jan 2022 15:12:25 +0000 Received: by outflank-mailman (output) from mailman id 255872.438767; Tue, 11 Jan 2022 15:12:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ioz-0003WD-8b; Tue, 11 Jan 2022 15:12:25 +0000 Received: by outflank-mailman (input) for mailman id 255872; Tue, 11 Jan 2022 15:12:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iox-0002Fw-DE for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:23 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dd9e2654-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:17 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AD0541F3B9; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8267513DDD; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SDGkHlGe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dd9e2654-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eq4fsjhW0m7VHOVVZWDwPf/Gn+LXzVDVgJADrNIM91s=; b=FDtBICD7vyqfzoRiSbB6nV7XftvZkWYIFMeuVc5+9fV3rGDtUgTfeYw006aodWNadVzBmS XJoOBBnYPvbG12gledkxWBAfdK5nM52NyosKVH1RQst5dGnd4frHMDvRf9wqLogqzRsGqY d/a9+2dSa8rnH6xP6Oj6M3P0xZGoI10= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 04/12] mini-os: use alloc_file_type() and get_file_from_fd() in tpm_tis Date: Tue, 11 Jan 2022 16:12:07 +0100 Message-Id: <20220111151215.22955-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913959022100004 Content-Type: text/plain; charset="utf-8" Allocate a file type dynamically via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Make some now local functions static and modify their prototypes to match the file_ops requirements. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 3 +- include/tpm_tis.h | 6 --- lib/sys.c | 23 --------- tpm_tis.c | 120 ++++++++++++++++++++++++++++++---------------- 4 files changed, 80 insertions(+), 72 deletions(-) diff --git a/include/lib.h b/include/lib.h index 05c7de5..d94d142 100644 --- a/include/lib.h +++ b/include/lib.h @@ -166,8 +166,7 @@ void sanity_check(void); #define FTYPE_TAP 8 #define FTYPE_BLK 9 #define FTYPE_TPMFRONT 10 -#define FTYPE_TPM_TIS 11 -#define FTYPE_N 12 +#define FTYPE_N 11 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/include/tpm_tis.h b/include/tpm_tis.h index 86e83f1..2af974d 100644 --- a/include/tpm_tis.h +++ b/include/tpm_tis.h @@ -37,14 +37,11 @@ struct tpm_chip; =20 struct tpm_chip* init_tpm_tis(unsigned long baseaddr, int localities, unsi= gned int irq); struct tpm_chip* init_tpm2_tis(unsigned long baseaddr, int localities, uns= igned int irq); -void shutdown_tpm_tis(struct tpm_chip* tpm); =20 int tpm_tis_request_locality(struct tpm_chip* tpm, int locality); int tpm_tis_cmd(struct tpm_chip* tpm, uint8_t* req, size_t reqlen, uint8_t= ** resp, size_t* resplen); =20 #ifdef HAVE_LIBC -#include -#include /* POSIX IO functions: * use tpm_tis_open() to get a file descriptor to the tpm device * use write() on the fd to send a command to the backend. You must @@ -53,9 +50,6 @@ int tpm_tis_cmd(struct tpm_chip* tpm, uint8_t* req, size_= t reqlen, uint8_t** res * fstat() to get the size of the response and lseek() to seek on it. */ int tpm_tis_open(struct tpm_chip* tpm); -int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count); -int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count); -int tpm_tis_posix_fstat(int fd, struct stat* buf); #endif =20 #endif diff --git a/lib/sys.c b/lib/sys.c index d213ae5..4060b42 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -349,11 +348,6 @@ int read(int fd, void *buf, size_t nbytes) case FTYPE_TPMFRONT: { return tpmfront_posix_read(fd, buf, nbytes); } -#endif -#ifdef CONFIG_TPM_TIS - case FTYPE_TPM_TIS: { - return tpm_tis_posix_read(fd, buf, nbytes); - } #endif default: break; @@ -399,10 +393,6 @@ int write(int fd, const void *buf, size_t nbytes) #ifdef CONFIG_TPMFRONT case FTYPE_TPMFRONT: return tpmfront_posix_write(fd, buf, nbytes); -#endif -#ifdef CONFIG_TPM_TIS - case FTYPE_TPM_TIS: - return tpm_tis_posix_write(fd, buf, nbytes); #endif default: break; @@ -459,10 +449,6 @@ off_t lseek(int fd, off_t offset, int whence) #ifdef CONFIG_TPMFRONT case FTYPE_TPMFRONT: break; -#endif -#ifdef CONFIG_TPM_TIS - case FTYPE_TPM_TIS: - break; #endif case FTYPE_FILE: break; @@ -515,11 +501,6 @@ int close(int fd) shutdown_tpmfront(files[fd].dev); break; #endif -#ifdef CONFIG_TPM_TIS - case FTYPE_TPM_TIS: - shutdown_tpm_tis(files[fd].dev); - break; -#endif #ifdef CONFIG_KBDFRONT case FTYPE_KBD: shutdown_kbdfront(files[fd].dev); @@ -599,10 +580,6 @@ int fstat(int fd, struct stat *buf) #ifdef CONFIG_TPMFRONT case FTYPE_TPMFRONT: return tpmfront_posix_fstat(fd, buf); -#endif -#ifdef CONFIG_TPM_TIS - case FTYPE_TPM_TIS: - return tpm_tis_posix_fstat(fd, buf); #endif default: break; diff --git a/tpm_tis.c b/tpm_tis.c index 477f555..abea7a1 100644 --- a/tpm_tis.c +++ b/tpm_tis.c @@ -792,6 +792,9 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, si= ze_t len) { int status, burstcnt =3D 0; int count =3D 0; uint32_t ordinal; +#ifdef HAVE_LIBC + struct file *file =3D get_file_from_fd(tpm->fd); +#endif =20 if(tpm_tis_request_locality(tpm, tpm->locality) < 0) { return -EBUSY; @@ -844,9 +847,10 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, s= ize_t len) { } } #ifdef HAVE_LIBC - if(tpm->fd >=3D 0) { - files[tpm->fd].read =3D false; - files[tpm->fd].offset =3D 0; + if ( file ) + { + file->read =3D false; + file->offset =3D 0; } #endif return len; @@ -1093,6 +1097,23 @@ ssize_t tpm_getcap(struct tpm_chip *chip, uint32_t s= ubcap_id, cap_t *cap, return rc; } =20 +static void shutdown_tpm_tis(struct tpm_chip* tpm){ + int i; + + printk("Shutting down tpm_tis device\n"); + + iowrite32(TPM_INT_ENABLE(tpm, tpm->locality), ~TPM_GLOBAL_INT_ENABLE); + + /*Unmap all of the mmio pages */ + for(i =3D 0; i < 5; ++i) { + if(tpm->pages[i] !=3D NULL) { + iounmap(tpm->pages[i], PAGE_SIZE); + tpm->pages[i] =3D NULL; + } + } + free(tpm); + return; +} =20 struct tpm_chip* init_tpm_tis(unsigned long baseaddr, int localities, unsi= gned int irq) { @@ -1242,25 +1263,6 @@ abort_egress: return NULL; } =20 -void shutdown_tpm_tis(struct tpm_chip* tpm){ - int i; - - printk("Shutting down tpm_tis device\n"); - - iowrite32(TPM_INT_ENABLE(tpm, tpm->locality), ~TPM_GLOBAL_INT_ENABLE); - - /*Unmap all of the mmio pages */ - for(i =3D 0; i < 5; ++i) { - if(tpm->pages[i] !=3D NULL) { - iounmap(tpm->pages[i], PAGE_SIZE); - tpm->pages[i] =3D NULL; - } - } - free(tpm); - return; -} - - int tpm_tis_cmd(struct tpm_chip* tpm, uint8_t* req, size_t reqlen, uint8_t= ** resp, size_t* resplen) { if(tpm->locality < 0) { @@ -1279,23 +1281,24 @@ int tpm_tis_cmd(struct tpm_chip* tpm, uint8_t* req,= size_t reqlen, uint8_t** res } =20 #ifdef HAVE_LIBC -int tpm_tis_open(struct tpm_chip* tpm) +#include +#include + +static int tpm_tis_close(int fd) { - /* Silently prevent multiple opens */ - if(tpm->fd !=3D -1) { - return tpm->fd; - } + struct file *file =3D get_file_from_fd(fd); =20 - tpm->fd =3D alloc_fd(FTYPE_TPM_TIS); - printk("tpm_tis_open() -> %d\n", tpm->fd); - files[tpm->fd].dev =3D tpm; - return tpm->fd; + shutdown_tpm_tis(file->dev); + + return 0; } =20 -int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count) +static int tpm_tis_posix_write(int fd, const void *buf, size_t count) { struct tpm_chip* tpm; - tpm =3D files[fd].dev; + struct file *file =3D get_file_from_fd(fd); + + tpm =3D file->dev; =20 if(tpm->locality < 0) { printk("tpm_tis_posix_write() failed! locality not set!\n"); @@ -1319,11 +1322,13 @@ int tpm_tis_posix_write(int fd, const uint8_t* buf,= size_t count) return count; } =20 -int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count) +static int tpm_tis_posix_read(int fd, void *buf, size_t count) { int rc; struct tpm_chip* tpm; - tpm =3D files[fd].dev; + struct file *file =3D get_file_from_fd(fd); + + tpm =3D file->dev; =20 if(count =3D=3D 0) { return 0; @@ -1337,20 +1342,24 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t= count) =20 =20 /* Handle EOF case */ - if(files[fd].offset >=3D tpm->data_len) { + if ( file->offset >=3D tpm->data_len ) + { rc =3D 0; } else { - rc =3D min(tpm->data_len - files[fd].offset, count); - memcpy(buf, tpm->data_buffer + files[fd].offset, rc); + rc =3D min(tpm->data_len - file->offset, count); + memcpy(buf, tpm->data_buffer + file->offset, rc); } - files[fd].offset +=3D rc; + file->offset +=3D rc; /* Reset the data pending flag */ return rc; } -int tpm_tis_posix_fstat(int fd, struct stat* buf) + +static int tpm_tis_posix_fstat(int fd, struct stat *buf) { struct tpm_chip* tpm; - tpm =3D files[fd].dev; + struct file *file =3D get_file_from_fd(fd); + + tpm =3D file->dev; =20 buf->st_mode =3D O_RDWR; buf->st_uid =3D 0; @@ -1360,6 +1369,35 @@ int tpm_tis_posix_fstat(int fd, struct stat* buf) return 0; } =20 +static struct file_ops tpm_tis_ops =3D { + .name =3D "tpm_tis", + .read =3D tpm_tis_posix_read, + .write =3D tpm_tis_posix_write, + .lseek =3D lseek_default, + .close =3D tpm_tis_close, + .fstat =3D tpm_tis_posix_fstat, +}; + +int tpm_tis_open(struct tpm_chip* tpm) +{ + struct file *file; + static unsigned int ftype_tis; + + /* Silently prevent multiple opens */ + if(tpm->fd !=3D -1) { + return tpm->fd; + } + + if ( !ftype_tis ) + ftype_tis =3D alloc_file_type(&tpm_tis_ops); + + tpm->fd =3D alloc_fd(ftype_tis); + printk("tpm_tis_open() -> %d\n", tpm->fd); + file =3D get_file_from_fd(tpm->fd); + file->dev =3D tpm; + return tpm->fd; +} + /* TPM 2.0 */ =20 /*TPM2.0 Selftest*/ --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913958; cv=none; d=zohomail.com; s=zohoarc; b=WczNZNElhFazkaKl2bAH3Ap6SQEIdbzL31ocih+T1eSJJiFHjKp/j5DuoUA2QN8d/Ms9Y394jNH7ytgsfT6S9Hk5VJ1QiRizQGPU5wjqx7to7wG1tBUIoKG1m1bnxRDGkwcZ1sEWwt3vR4mnXdDoSntanSaNMcGcHWDDC9FNW88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913958; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HfQh4OZ9az0A9qjPS5wm3iwxm7DBwhvFq6/vq3hHx4c=; b=m6XEypFs+0aOPeLKOHjqG4+Ja6cPqLOF9xFq3/fHuoLqAkJ46G0+6hgdyu37Mw52BJjTJXK3+J50AloPRRdvrWbAxl4IiaJcYd3j4/4bgi0N3B5hLDG5PBurUoWLN44CtLsA2TNbhhpd6WZ7MLsT3j+KlC+eAOaBA4lkSA7Sf8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913958749410.99779447099945; Tue, 11 Jan 2022 07:12:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255871.438763 (Exim 4.92) (envelope-from ) id 1n7Ioz-0003SH-4C; Tue, 11 Jan 2022 15:12:25 +0000 Received: by outflank-mailman (output) from mailman id 255871.438763; Tue, 11 Jan 2022 15:12:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ioy-0003RD-Qw; Tue, 11 Jan 2022 15:12:24 +0000 Received: by outflank-mailman (input) for mailman id 255871; Tue, 11 Jan 2022 15:12:23 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iow-0002Fv-VQ for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:23 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ddbbbb2d-72f0-11ec-9ce5-af14b9085ebd; Tue, 11 Jan 2022 16:12:18 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D9E20212C5; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B24D913DDD; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4LNQKlGe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ddbbbb2d-72f0-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HfQh4OZ9az0A9qjPS5wm3iwxm7DBwhvFq6/vq3hHx4c=; b=d+2fCrxpZ86Dc+7cN3OiQiG9EGz1BKXAhrYJF71rPwQ8i4kjMPvAVxGZPTUl9n/L3qsiRc wTEby7tMgtDOedTFArOZVMMsYt9vYyotw7EhP2R9SzKXvUrXb54IPu2U/kIppdSeUkwYlQ Lj19uGCFkMYW8wXcigeeSEVUDLbad6Y= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 05/12] mini-os: use alloc_file_type() and get_file_from_fd() in tpmfront Date: Tue, 11 Jan 2022 16:12:08 +0100 Message-Id: <20220111151215.22955-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913961035100009 Content-Type: text/plain; charset="utf-8" Allocate a file type dynamically via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 3 +- include/tpmfront.h | 5 --- lib/sys.c | 23 ----------- tpmfront.c | 100 ++++++++++++++++++++++++++++++++------------- 4 files changed, 72 insertions(+), 59 deletions(-) diff --git a/include/lib.h b/include/lib.h index d94d142..f6478de 100644 --- a/include/lib.h +++ b/include/lib.h @@ -165,8 +165,7 @@ void sanity_check(void); #define FTYPE_KBD 7 #define FTYPE_TAP 8 #define FTYPE_BLK 9 -#define FTYPE_TPMFRONT 10 -#define FTYPE_N 11 +#define FTYPE_N 10 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/include/tpmfront.h b/include/tpmfront.h index b7da50e..a527371 100644 --- a/include/tpmfront.h +++ b/include/tpmfront.h @@ -81,7 +81,6 @@ int tpmfront_cmd(struct tpmfront_dev* dev, uint8_t* req, = size_t reqlen, uint8_t* int tpmfront_set_locality(struct tpmfront_dev* dev, int locality); =20 #ifdef HAVE_LIBC -#include /* POSIX IO functions: * use tpmfront_open() to get a file descriptor to the tpm device * use write() on the fd to send a command to the backend. You must @@ -90,10 +89,6 @@ int tpmfront_set_locality(struct tpmfront_dev* dev, int = locality); * fstat() to get the size of the response and lseek() to seek on it. */ int tpmfront_open(struct tpmfront_dev* dev); -int tpmfront_posix_read(int fd, uint8_t* buf, size_t count); -int tpmfront_posix_write(int fd, const uint8_t* buf, size_t count); -int tpmfront_posix_fstat(int fd, struct stat* buf); #endif =20 - #endif diff --git a/lib/sys.c b/lib/sys.c index 4060b42..ff6be52 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -343,11 +342,6 @@ int read(int fd, void *buf, size_t nbytes) case FTYPE_BLK: { return blkfront_posix_read(fd, buf, nbytes); } -#endif -#ifdef CONFIG_TPMFRONT - case FTYPE_TPMFRONT: { - return tpmfront_posix_read(fd, buf, nbytes); - } #endif default: break; @@ -389,10 +383,6 @@ int write(int fd, const void *buf, size_t nbytes) #ifdef CONFIG_BLKFRONT case FTYPE_BLK: return blkfront_posix_write(fd, buf, nbytes); -#endif -#ifdef CONFIG_TPMFRONT - case FTYPE_TPMFRONT: - return tpmfront_posix_write(fd, buf, nbytes); #endif default: break; @@ -445,10 +435,6 @@ off_t lseek(int fd, off_t offset, int whence) #ifdef CONFIG_BLKFRONT case FTYPE_BLK: break; -#endif -#ifdef CONFIG_TPMFRONT - case FTYPE_TPMFRONT: - break; #endif case FTYPE_FILE: break; @@ -496,11 +482,6 @@ int close(int fd) shutdown_blkfront(files[fd].dev); break; #endif -#ifdef CONFIG_TPMFRONT - case FTYPE_TPMFRONT: - shutdown_tpmfront(files[fd].dev); - break; -#endif #ifdef CONFIG_KBDFRONT case FTYPE_KBD: shutdown_kbdfront(files[fd].dev); @@ -576,10 +557,6 @@ int fstat(int fd, struct stat *buf) #ifdef CONFIG_BLKFRONT case FTYPE_BLK: return blkfront_posix_fstat(fd, buf); -#endif -#ifdef CONFIG_TPMFRONT - case FTYPE_TPMFRONT: - return tpmfront_posix_fstat(fd, buf); #endif default: break; diff --git a/tpmfront.c b/tpmfront.c index 0a2fefc..a19a052 100644 --- a/tpmfront.c +++ b/tpmfront.c @@ -49,6 +49,10 @@ void tpmfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data= ) { struct tpmfront_dev* dev =3D (struct tpmfront_dev*) data; tpmif_shared_page_t *shr =3D dev->page; +#ifdef HAVE_LIBC + struct file *file =3D get_file_from_fd(dev->fd); +#endif + /*If we get a response when we didnt make a request, just ignore it */ if(!dev->waiting) { return; @@ -65,8 +69,9 @@ void tpmfront_handler(evtchn_port_t port, struct pt_regs = *regs, void *data) { =20 dev->waiting =3D 0; #ifdef HAVE_LIBC - if(dev->fd >=3D 0) { - files[dev->fd].read =3D true; + if ( file ) + { + file->read =3D true; } #endif wake_up(&dev->waitq); @@ -405,6 +410,10 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint= 8_t* msg, size_t length) #ifdef TPMFRONT_PRINT_DEBUG int i; #endif +#ifdef HAVE_LIBC + struct file *file =3D dev ? get_file_from_fd(dev->fd) : NULL; +#endif + /* Error Checking */ if(dev =3D=3D NULL || dev->state !=3D XenbusStateConnected) { TPMFRONT_ERR("Tried to send message through disconnected frontend\n"= ); @@ -437,9 +446,10 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint= 8_t* msg, size_t length) dev->waiting =3D 1; dev->resplen =3D 0; #ifdef HAVE_LIBC - if(dev->fd >=3D 0) { - files[dev->fd].read =3D false; - files[dev->fd].offset =3D 0; + if ( file ) + { + file->read =3D false; + file->offset =3D 0; dev->respgot =3D false; } #endif @@ -529,25 +539,14 @@ int tpmfront_set_locality(struct tpmfront_dev* dev, i= nt locality) =20 #ifdef HAVE_LIBC #include -int tpmfront_open(struct tpmfront_dev* dev) -{ - /* Silently prevent multiple opens */ - if(dev->fd !=3D -1) { - return dev->fd; - } =20 - dev->fd =3D alloc_fd(FTYPE_TPMFRONT); - printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd); - files[dev->fd].dev =3D dev; - dev->respgot =3D false; - return dev->fd; -} - -int tpmfront_posix_write(int fd, const uint8_t* buf, size_t count) +static int tpmfront_posix_write(int fd, const void *buf, size_t count) { int rc; struct tpmfront_dev* dev; - dev =3D files[fd].dev; + struct file *file =3D get_file_from_fd(fd); + + dev =3D file->dev; =20 if(count =3D=3D 0) { return 0; @@ -566,14 +565,15 @@ int tpmfront_posix_write(int fd, const uint8_t* buf, = size_t count) return count; } =20 -int tpmfront_posix_read(int fd, uint8_t* buf, size_t count) +static int tpmfront_posix_read(int fd, void *buf, size_t count) { int rc; uint8_t* dummybuf; size_t dummysz; struct tpmfront_dev* dev; + struct file *file =3D get_file_from_fd(fd); =20 - dev =3D files[fd].dev; + dev =3D file->dev; =20 if(count =3D=3D 0) { return 0; @@ -588,29 +588,33 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t = count) } =20 /* handle EOF case */ - if(files[dev->fd].offset >=3D dev->resplen) { + if ( file->offset >=3D dev->resplen ) + { return 0; } =20 /* Compute the number of bytes and do the copy operation */ - if((rc =3D min(count, dev->resplen - files[dev->fd].offset)) !=3D 0) { - memcpy(buf, dev->respbuf + files[dev->fd].offset, rc); - files[dev->fd].offset +=3D rc; + if ( (rc =3D min(count, dev->resplen - file->offset)) !=3D 0 ) + { + memcpy(buf, dev->respbuf + file->offset, rc); + file->offset +=3D rc; } =20 return rc; } =20 -int tpmfront_posix_fstat(int fd, struct stat* buf) +static int tpmfront_posix_fstat(int fd, struct stat *buf) { uint8_t* dummybuf; size_t dummysz; int rc; - struct tpmfront_dev* dev =3D files[fd].dev; + struct file *file =3D get_file_from_fd(fd); + struct tpmfront_dev* dev =3D file->dev; =20 /* If we have a response waiting, then read it now from the backend * so we can get its length*/ - if(dev->waiting || (files[dev->fd].read && !dev->respgot)) { + if ( dev->waiting || (file->read && !dev->respgot) ) + { if ((rc =3D tpmfront_recv(dev, &dummybuf, &dummysz)) !=3D 0) { errno =3D EIO; return -1; @@ -626,5 +630,43 @@ int tpmfront_posix_fstat(int fd, struct stat* buf) return 0; } =20 +static int tpmfront_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_tpmfront(file->dev); + + return 0; +} + +static struct file_ops tpmfront_ops =3D { + .name =3D "tpmfront", + .read =3D tpmfront_posix_read, + .write =3D tpmfront_posix_write, + .lseek =3D lseek_default, + .close =3D tpmfront_close_fd, + .fstat =3D tpmfront_posix_fstat, +}; + +int tpmfront_open(struct tpmfront_dev* dev) +{ + struct file *file; + static unsigned int ftype_tpmfront; + + /* Silently prevent multiple opens */ + if(dev->fd !=3D -1) { + return dev->fd; + } + + if ( !ftype_tpmfront ) + ftype_tpmfront =3D alloc_file_type(&tpmfront_ops); + + dev->fd =3D alloc_fd(ftype_tpmfront); + printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd); + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; + dev->respgot =3D false; + return dev->fd; +} =20 #endif --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913965; cv=none; d=zohomail.com; s=zohoarc; b=lAs4NonO3epnxn+je5AF2LZG3dffcqg6G2V0oe0k0XugK7Gevm9eTx7L3pQFphzD8j/jSHfjhW3TfzA1z0vr0gPsuLrC0umEDcg0awLAxkY5Dx3LcU2rPWBbQDUJQI2RbeYQ3XydURpRZv6M8jliqfapymrv4Y5KmtooAfIzQTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913965; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=THtUtk0c0qdaxelPl/C+8VH9LB692eb/zBc/uFOuwwQ=; b=iDNjJv2hS54XNpQ44NVDGC4msCKVBxaGDeB80GUyZKNR7ET+SmM1BMwFh2j3QUBvREbdztgQ6GS4Rux5MRcYybK+ZuCAdDQWIC8DWxY60Yrq/fcAk1UJKOc3eX7vEVdl3WRx8IThAxOQar0rvkAIZ0XmYxm7aESo/Qjv9kmxQTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913965663783.4778758876887; Tue, 11 Jan 2022 07:12:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255880.438818 (Exim 4.92) (envelope-from ) id 1n7Ip7-0004yz-44; Tue, 11 Jan 2022 15:12:33 +0000 Received: by outflank-mailman (output) from mailman id 255880.438818; Tue, 11 Jan 2022 15:12:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip6-0004rz-JQ; Tue, 11 Jan 2022 15:12:32 +0000 Received: by outflank-mailman (input) for mailman id 255880; Tue, 11 Jan 2022 15:12:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip1-0002Fw-Dw for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:27 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ddce9212-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:18 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 10C69212CA; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DECFF13DDD; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0FpANVGe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ddce9212-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=THtUtk0c0qdaxelPl/C+8VH9LB692eb/zBc/uFOuwwQ=; b=vKJEN28JIArVqpWVZTeqYRy4g4OU9gH+pS+WPLnZmfXn4JtfTQnaXR4xV1gx1rOmKlrH7j mQBXhesIVlqrukqW5u5OqsQpmcAF9tRbuQ6CqiRH7FtEKMPRc6L0+MF+1ED1KtsJ1BFNpB /0SYyHP/lOWL8f4N6KqIurpds9GOLqg= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 06/12] mini-os: use alloc_file_type() and get_file_from_fd() in blkfront Date: Tue, 11 Jan 2022 16:12:09 +0100 Message-Id: <20220111151215.22955-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913967283100003 Content-Type: text/plain; charset="utf-8" Allocate the file type dynamically via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- blkfront.c | 92 ++++++++++++++++++++++++++++++++++------------ include/blkfront.h | 5 --- include/lib.h | 3 +- lib/sys.c | 24 ------------ 4 files changed, 69 insertions(+), 55 deletions(-) diff --git a/blkfront.c b/blkfront.c index e3f42be..b7ea1d7 100644 --- a/blkfront.c +++ b/blkfront.c @@ -59,10 +59,10 @@ void blkfront_handler(evtchn_port_t port, struct pt_reg= s *regs, void *data) { #ifdef HAVE_LIBC struct blkfront_dev *dev =3D data; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; #endif wake_up(&blkfront_queue); } @@ -483,9 +483,13 @@ int blkfront_aio_poll(struct blkfront_dev *dev) =20 moretodo: #ifdef HAVE_LIBC - if (dev->fd !=3D -1) { - files[dev->fd].read =3D false; - mb(); /* Make sure to let the handler set read to 1 before we star= t looking at the ring */ + { + struct file *file =3D get_file_from_fd(dev->fd); + + if ( file ) { + file->read =3D false; + mb(); /* Make sure to let the handler set read to 1 before we = start looking at the ring */ + } } #endif =20 @@ -554,22 +558,11 @@ moretodo: } =20 #ifdef HAVE_LIBC -int blkfront_open(struct blkfront_dev *dev) -{ - /* Silently prevent multiple opens */ - if(dev->fd !=3D -1) { - return dev->fd; - } - dev->fd =3D alloc_fd(FTYPE_BLK); - printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd); - files[dev->fd].dev =3D dev; - return dev->fd; -} - -int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write) +static int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int wri= te) { - struct blkfront_dev* dev =3D files[fd].dev; - off_t offset =3D files[fd].offset; + struct file *file =3D get_file_from_fd(fd); + struct blkfront_dev* dev =3D file->dev; + off_t offset =3D file->offset; struct blkfront_aiocb aiocb; unsigned long long disksize =3D dev->info.sectors * dev->info.sector_si= ze; unsigned int blocksize =3D dev->info.sector_size; @@ -711,14 +704,25 @@ int blkfront_posix_rwop(int fd, uint8_t* buf, size_t = count, int write) } =20 free(copybuf); - files[fd].offset +=3D rc; + file->offset +=3D rc; return rc; =20 } =20 -int blkfront_posix_fstat(int fd, struct stat* buf) +static int blkfront_posix_read(int fd, void *buf, size_t nbytes) +{ + return blkfront_posix_rwop(fd, buf, nbytes, 0); +} + +static int blkfront_posix_write(int fd, const void *buf, size_t nbytes) { - struct blkfront_dev* dev =3D files[fd].dev; + return blkfront_posix_rwop(fd, (void *)buf, nbytes, 1); +} + +static int blkfront_posix_fstat(int fd, struct stat *buf) +{ + struct file *file =3D get_file_from_fd(fd); + struct blkfront_dev* dev =3D file->dev; =20 buf->st_mode =3D dev->info.mode; buf->st_uid =3D 0; @@ -728,4 +732,44 @@ int blkfront_posix_fstat(int fd, struct stat* buf) =20 return 0; } + +static int blkfront_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_blkfront(file->dev); + + return 0; +} + +static struct file_ops blk_ops =3D { + .name =3D "blk", + .read =3D blkfront_posix_read, + .write =3D blkfront_posix_write, + .lseek =3D lseek_default, + .close =3D blkfront_close_fd, + .fstat =3D blkfront_posix_fstat, + .select_rd =3D select_read_flag, +}; + +int blkfront_open(struct blkfront_dev *dev) +{ + struct file *file; + static unsigned int ftype_blk; + + /* Silently prevent multiple opens */ + if(dev->fd !=3D -1) { + return dev->fd; + } + + if ( !ftype_blk ) + ftype_blk =3D alloc_file_type(&blk_ops); + + dev->fd =3D alloc_fd(ftype_blk); + printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd); + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; + + return dev->fd; +} #endif diff --git a/include/blkfront.h b/include/blkfront.h index 3528af9..7f84a0a 100644 --- a/include/blkfront.h +++ b/include/blkfront.h @@ -28,17 +28,12 @@ struct blkfront_info }; struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *i= nfo); #ifdef HAVE_LIBC -#include /* POSIX IO functions: * use blkfront_open() to get a file descriptor to the block device * Don't use the other blkfront posix functions here directly, instead use * read(), write(), lseek() and fstat() on the file descriptor */ int blkfront_open(struct blkfront_dev *dev); -int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write); -#define blkfront_posix_write(fd, buf, count) blkfront_posix_rwop(fd, (uint= 8_t*)buf, count, 1) -#define blkfront_posix_read(fd, buf, count) blkfront_posix_rwop(fd, (uint8= _t*)buf, count, 0) -int blkfront_posix_fstat(int fd, struct stat* buf); #endif void blkfront_aio(struct blkfront_aiocb *aiocbp, int write); #define blkfront_aio_read(aiocbp) blkfront_aio(aiocbp, 0) diff --git a/include/lib.h b/include/lib.h index f6478de..05f5083 100644 --- a/include/lib.h +++ b/include/lib.h @@ -164,8 +164,7 @@ void sanity_check(void); #define FTYPE_FB 6 #define FTYPE_KBD 7 #define FTYPE_TAP 8 -#define FTYPE_BLK 9 -#define FTYPE_N 10 +#define FTYPE_N 9 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index ff6be52..f84fedd 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -337,11 +337,6 @@ int read(int fd, void *buf, size_t nbytes) } return ret * sizeof(union xenfb_in_event); } -#endif -#ifdef CONFIG_BLKFRONT - case FTYPE_BLK: { - return blkfront_posix_read(fd, buf, nbytes); - } #endif default: break; @@ -379,10 +374,6 @@ int write(int fd, const void *buf, size_t nbytes) case FTYPE_TAP: netfront_xmit(files[fd].dev, (void*) buf, nbytes); return nbytes; -#endif -#ifdef CONFIG_BLKFRONT - case FTYPE_BLK: - return blkfront_posix_write(fd, buf, nbytes); #endif default: break; @@ -432,10 +423,6 @@ off_t lseek(int fd, off_t offset, int whence) return ops->lseek(fd, offset, whence); =20 switch(files[fd].type) { -#ifdef CONFIG_BLKFRONT - case FTYPE_BLK: - break; -#endif case FTYPE_FILE: break; default: @@ -477,11 +464,6 @@ int close(int fd) shutdown_netfront(files[fd].dev); break; #endif -#ifdef CONFIG_BLKFRONT - case FTYPE_BLK: - shutdown_blkfront(files[fd].dev); - break; -#endif #ifdef CONFIG_KBDFRONT case FTYPE_KBD: shutdown_kbdfront(files[fd].dev); @@ -554,10 +536,6 @@ int fstat(int fd, struct stat *buf) buf->st_ctime =3D time(NULL); return 0; } -#ifdef CONFIG_BLKFRONT - case FTYPE_BLK: - return blkfront_posix_fstat(fd, buf); -#endif default: break; } @@ -663,7 +641,6 @@ static const char *file_types[] =3D { [FTYPE_CONSOLE] =3D "console", [FTYPE_SOCKET] =3D "socket", [FTYPE_TAP] =3D "net", - [FTYPE_BLK] =3D "blk", [FTYPE_KBD] =3D "kbd", [FTYPE_FB] =3D "fb", }; @@ -841,7 +818,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_se= t *writefds, fd_set *exce FD_CLR(i, exceptfds); break; case FTYPE_TAP: - case FTYPE_BLK: case FTYPE_KBD: case FTYPE_FB: if (FD_ISSET(i, readfds)) { --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913962; cv=none; d=zohomail.com; s=zohoarc; b=bJNAMQOK+xOUWBTLhRk9GrtYE5Hh6dL7M9MDwGEBsuPXtwuvW1q7cbaf0v37IK6FFTJaQGfPrzG/TT6K5RRVqupezSivlUhb1YOM8yOFRronYjUkCvd8srDcG6aGUmkuYym/M5GEdzLmwwpfqreuF3gwwnnQmLH5Xcz9OyzE1rA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913962; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jVhuzq1ru9rCdLBgGyz4Ec9Qdw5HVMOj866c/uvvnJ8=; b=CNdXGrhPOz3OztAmoygm3siKsUNOHGRYJfqEO4decAAL4q8/P8RvA/UQUpnHw7aGaEGeYgWrF74eNthuyRK67wpFKXq+MEUldqZQ4d7i36f8Nnlt35ipcAs0MxC0qikqCv+q9oJUgJK76GISj0UxcT8iy+v/eoidULA5smrNqZk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913962592971.0011268087685; Tue, 11 Jan 2022 07:12:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255876.438796 (Exim 4.92) (envelope-from ) id 1n7Ip3-0004AF-FM; Tue, 11 Jan 2022 15:12:29 +0000 Received: by outflank-mailman (output) from mailman id 255876.438796; Tue, 11 Jan 2022 15:12:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip2-00045B-H8; Tue, 11 Jan 2022 15:12:28 +0000 Received: by outflank-mailman (input) for mailman id 255876; Tue, 11 Jan 2022 15:12:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ioz-0002Fw-DT for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:25 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ddef8a1b-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:18 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 43AEB1F3B1; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1886213DDD; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EL60BFKe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ddef8a1b-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jVhuzq1ru9rCdLBgGyz4Ec9Qdw5HVMOj866c/uvvnJ8=; b=fyJ4xFFUjaB4MnesIRmrqRCUyyfsdRLZi/4jAokXUD4t39jqDelNiYROsMocP1Jn8duNF5 3aXoFY79DAEDfznK9s5FKTjKbNTmsAm4DM/K6s+zw14+ofdru7KNAIy+Y4wnFdCIr+Zlo6 tgL1v0m2i/UlH2Hrb05Ko68zCifDARI= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 07/12] mini-os: use get_file_from_fd() in netfront Date: Tue, 11 Jan 2022 16:12:10 +0100 Message-Id: <20220111151215.22955-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913963822100001 Content-Type: text/plain; charset="utf-8" Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 3 +-- lib/sys.c | 23 ------------------ netfront.c | 64 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/include/lib.h b/include/lib.h index 05f5083..aa8036e 100644 --- a/include/lib.h +++ b/include/lib.h @@ -163,8 +163,7 @@ void sanity_check(void); #define FTYPE_SAVEFILE 5 #define FTYPE_FB 6 #define FTYPE_KBD 7 -#define FTYPE_TAP 8 -#define FTYPE_N 9 +#define FTYPE_N 8 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index f84fedd..7f2e11f 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -303,17 +303,6 @@ int read(int fd, void *buf, size_t nbytes) case FTYPE_SOCKET: return lwip_read(files[fd].fd, buf, nbytes); #endif -#ifdef CONFIG_NETFRONT - case FTYPE_TAP: { - ssize_t ret; - ret =3D netfront_receive(files[fd].dev, buf, nbytes); - if (ret <=3D 0) { - errno =3D EAGAIN; - return -1; - } - return ret; - } -#endif #ifdef CONFIG_KBDFRONT case FTYPE_KBD: { int ret, n; @@ -369,11 +358,6 @@ int write(int fd, const void *buf, size_t nbytes) #ifdef HAVE_LWIP case FTYPE_SOCKET: return lwip_write(files[fd].fd, (void*) buf, nbytes); -#endif -#ifdef CONFIG_NETFRONT - case FTYPE_TAP: - netfront_xmit(files[fd].dev, (void*) buf, nbytes); - return nbytes; #endif default: break; @@ -459,11 +443,6 @@ int close(int fd) res =3D lwip_close(files[fd].fd); break; #endif -#ifdef CONFIG_NETFRONT - case FTYPE_TAP: - shutdown_netfront(files[fd].dev); - break; -#endif #ifdef CONFIG_KBDFRONT case FTYPE_KBD: shutdown_kbdfront(files[fd].dev); @@ -640,7 +619,6 @@ static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", [FTYPE_CONSOLE] =3D "console", [FTYPE_SOCKET] =3D "socket", - [FTYPE_TAP] =3D "net", [FTYPE_KBD] =3D "kbd", [FTYPE_FB] =3D "fb", }; @@ -817,7 +795,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_se= t *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; - case FTYPE_TAP: case FTYPE_KBD: case FTYPE_FB: if (FD_ISSET(i, readfds)) { diff --git a/netfront.c b/netfront.c index 7696451..f86c6a2 100644 --- a/netfront.c +++ b/netfront.c @@ -248,14 +248,14 @@ void netfront_select_handler(evtchn_port_t port, stru= ct pt_regs *regs, void *dat { int flags; struct netfront_dev *dev =3D data; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); =20 local_irq_save(flags); network_tx_buf_gc(dev); local_irq_restore(flags); =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; wake_up(&netfront_queue); } #endif @@ -565,8 +565,54 @@ error: } =20 #ifdef HAVE_LIBC +static int netfront_read(int fd, void *buf, size_t nbytes) +{ + ssize_t ret; + struct file *file =3D get_file_from_fd(fd); + + ret =3D netfront_receive(file->dev, buf, nbytes); + if ( ret <=3D 0 ) + { + errno =3D EAGAIN; + return -1; + } + + return ret; +} + +static int netfront_write(int fd, const void *buf, size_t nbytes) +{ + struct file *file =3D get_file_from_fd(fd); + + netfront_xmit(file->dev, (void *)buf, nbytes); + + return nbytes; +} + +static int netfront_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_netfront(file->dev); + + return 0; +} + +static struct file_ops netfront_ops =3D { + .name =3D "net", + .read =3D netfront_read, + .write =3D netfront_write, + .close =3D netfront_close_fd, + .select_rd =3D select_read_flag, +}; + int netfront_tap_open(char *nodename) { struct netfront_dev *dev; + struct file *file; + static unsigned int ftype_netfront; + + if ( !ftype_netfront ) + ftype_netfront =3D alloc_file_type(&netfront_ops); =20 dev =3D init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL); if (!dev) { @@ -574,9 +620,10 @@ int netfront_tap_open(char *nodename) { errno =3D EIO; return -1; } - dev->fd =3D alloc_fd(FTYPE_TAP); + dev->fd =3D alloc_fd(ftype_netfront); printk("tap_open(%s) -> %d\n", nodename, dev->fd); - files[dev->fd].dev =3D dev; + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; return dev->fd; } #endif @@ -772,7 +819,8 @@ void netfront_xmit(struct netfront_dev *dev, unsigned c= har* data,int len) ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, si= ze_t len) { unsigned long flags; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); + ASSERT(current =3D=3D main_thread); =20 dev->rlen =3D 0; @@ -781,9 +829,9 @@ ssize_t netfront_receive(struct netfront_dev *dev, unsi= gned char *data, size_t l =20 local_irq_save(flags); network_rx(dev); - if (!dev->rlen && fd !=3D -1) + if ( !dev->rlen && file ) /* No data for us, make select stop returning */ - files[fd].read =3D false; + file->read =3D false; /* Before re-enabling the interrupts, in case a packet just arrived in= the * meanwhile. */ local_irq_restore(flags); --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641914447; cv=none; d=zohomail.com; s=zohoarc; b=aKSD4I1ICcTPZsCFDJp9KZn7BoVhcmbR1Wy8kOQmg2LWYffBQJVqdbzRQfR9lHDK5YQq7bYnzUL/nrBSOP7H7rflDcUoyMWD+8nJsAzC/zl0qwyxGzlwiU+EpHJHwp5SGADys+6+D4SsvrnoCRMxwfQW96Flc1WCdWvnOmisxgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641914447; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5MnAj8jgvGSVnTnQHkjtzzsrohe+jN87xvuOdqS22Ok=; b=QuA6Lo+nbL8jInZVJKY8MyDHq5g1nnulOqFUqc3Uqf5yzkNA5gcpaS45jzkQo8k4VYXZ20VdFfNBtECZdIOQzj7OJvzTJ7GevS1BbdfcSoAElLCEArj4a436t18WJx6eqkoY/8zRQY9sNATshw5PEA9cts//UJYyEHjVylrUHwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641914447753165.71070730483348; Tue, 11 Jan 2022 07:20:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255906.438905 (Exim 4.92) (envelope-from ) id 1n7IwZ-0003QX-RL; Tue, 11 Jan 2022 15:20:15 +0000 Received: by outflank-mailman (output) from mailman id 255906.438905; Tue, 11 Jan 2022 15:20:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7IwZ-0003QQ-NK; Tue, 11 Jan 2022 15:20:15 +0000 Received: by outflank-mailman (input) for mailman id 255906; Tue, 11 Jan 2022 15:20:14 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip3-0002Fw-EO for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:29 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id de12afa8-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:18 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7E4B521112; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 46D881404B; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oA8dEFKe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: de12afa8-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5MnAj8jgvGSVnTnQHkjtzzsrohe+jN87xvuOdqS22Ok=; b=KcLdTKRrhcktZcEEJ6Esn2gpSF88MuhbhNCD6QM3AustEX6MZ7SEVx4suCWZ3nVunF2TwJ lxSkdKdsjnuM5NTc9Zgmuhr9S0Rhgc05Q5hLhJr7xTTLOyvHJNM6p5tOqwd8dtMKnbXjwr /ARKUb/i+ujsZCsXg4NZTT7DQITZ2YM= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 08/12] mini-os: use alloc_file_type() and get_file_from_fd() in fbfront Date: Tue, 11 Jan 2022 16:12:11 +0100 Message-Id: <20220111151215.22955-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641914451973100001 Content-Type: text/plain; charset="utf-8" Allocate file types dynamically via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- fbfront.c | 125 ++++++++++++++++++++++++++++++++++++++++++-------- include/lib.h | 4 +- lib/sys.c | 47 ------------------- 3 files changed, 106 insertions(+), 70 deletions(-) diff --git a/fbfront.c b/fbfront.c index 1e055fb..9c96963 100644 --- a/fbfront.c +++ b/fbfront.c @@ -14,6 +14,9 @@ #include #include #include +#ifdef HAVE_LIBC +#include +#endif =20 DECLARE_WAIT_QUEUE_HEAD(kbdfront_queue); =20 @@ -42,10 +45,10 @@ void kbdfront_handler(evtchn_port_t port, struct pt_reg= s *regs, void *data) { #ifdef HAVE_LIBC struct kbdfront_dev *dev =3D data; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; #endif wake_up(&kbdfront_queue); } @@ -204,10 +207,12 @@ int kbdfront_receive(struct kbdfront_dev *dev, union = xenkbd_in_event *buf, int n struct xenkbd_page *page =3D dev->page; uint32_t prod, cons; int i; - #ifdef HAVE_LIBC - if (dev->fd !=3D -1) { - files[dev->fd].read =3D false; + struct file *file =3D get_file_from_fd(dev->fd); + + if ( file ) + { + file->read =3D false; mb(); /* Make sure to let the handler set read to 1 before we star= t looking at the ring */ } #endif @@ -227,9 +232,9 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xe= nkbd_in_event *buf, int n notify_remote_via_evtchn(dev->evtchn); =20 #ifdef HAVE_LIBC - if (cons !=3D prod && dev->fd !=3D -1) + if ( cons !=3D prod && file ) /* still some events to read */ - files[dev->fd].read =3D true; + file->read =3D true; #endif =20 return i; @@ -298,11 +303,50 @@ close_kbdfront: } =20 #ifdef HAVE_LIBC +static int kbd_read(int fd, void *buf, size_t nbytes) +{ + struct file *file =3D get_file_from_fd(fd); + int ret, n; + + n =3D nbytes / sizeof(union xenkbd_in_event); + ret =3D kbdfront_receive(file->dev, buf, n); + if ( ret <=3D 0 ) + { + errno =3D EAGAIN; + return -1; + } + + return ret * sizeof(union xenkbd_in_event); +} + +static int kbd_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_kbdfront(file->dev); + + return 0; +} + +static struct file_ops kbd_ops =3D { + .name =3D "kbd", + .read =3D kbd_read, + .close =3D kbd_close_fd, + .select_rd =3D select_read_flag, +}; + int kbdfront_open(struct kbdfront_dev *dev) { - dev->fd =3D alloc_fd(FTYPE_KBD); + struct file *file; + static unsigned int ftype_kbd; + + if ( !ftype_kbd ) + ftype_kbd =3D alloc_file_type(&kbd_ops); + + dev->fd =3D alloc_fd(ftype_kbd); printk("kbd_open(%s) -> %d\n", dev->nodename, dev->fd); - files[dev->fd].dev =3D dev; + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; return dev->fd; } #endif @@ -346,10 +390,10 @@ void fbfront_handler(evtchn_port_t port, struct pt_re= gs *regs, void *data) { #ifdef HAVE_LIBC struct fbfront_dev *dev =3D data; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; #endif wake_up(&fbfront_queue); } @@ -373,10 +417,12 @@ int fbfront_receive(struct fbfront_dev *dev, union xe= nfb_in_event *buf, int n) struct xenfb_page *page =3D dev->page; uint32_t prod, cons; int i; - #ifdef HAVE_LIBC - if (dev->fd !=3D -1) { - files[dev->fd].read =3D false; + struct file *file =3D get_file_from_fd(dev->fd); + + if ( file ) + { + file->read =3D false; mb(); /* Make sure to let the handler set read to 1 before we star= t looking at the ring */ } #endif @@ -396,9 +442,9 @@ int fbfront_receive(struct fbfront_dev *dev, union xenf= b_in_event *buf, int n) notify_remote_via_evtchn(dev->evtchn); =20 #ifdef HAVE_LIBC - if (cons !=3D prod && dev->fd !=3D -1) + if ( cons !=3D prod && file ) /* still some events to read */ - files[dev->fd].read =3D true; + file->read =3D true; #endif =20 return i; @@ -699,11 +745,50 @@ close_fbfront: } =20 #ifdef HAVE_LIBC +static int fbfront_read(int fd, void *buf, size_t nbytes) +{ + struct file *file =3D get_file_from_fd(fd); + int ret, n; + + n =3D nbytes / sizeof(union xenfb_in_event); + ret =3D fbfront_receive(file->dev, buf, n); + if ( ret <=3D 0 ) + { + errno =3D EAGAIN; + return -1; + } + + return ret * sizeof(union xenfb_in_event); +} + +static int fbfront_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_fbfront(file->dev); + + return 0; +} + +static struct file_ops fb_ops =3D { + .name =3D ".fb", + .read =3D fbfront_read, + .close =3D fbfront_close_fd, + .select_rd =3D select_read_flag, +}; + int fbfront_open(struct fbfront_dev *dev) { - dev->fd =3D alloc_fd(FTYPE_FB); + struct file *file; + static unsigned int ftype_fb; + + if ( !ftype_fb ) + ftype_fb =3D alloc_file_type(&fb_ops); + + dev->fd =3D alloc_fd(ftype_fb); printk("fb_open(%s) -> %d\n", dev->nodename, dev->fd); - files[dev->fd].dev =3D dev; + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; return dev->fd; } #endif diff --git a/include/lib.h b/include/lib.h index aa8036e..653a16e 100644 --- a/include/lib.h +++ b/include/lib.h @@ -161,9 +161,7 @@ void sanity_check(void); #define FTYPE_SOCKET 3 #define FTYPE_MEM 4 #define FTYPE_SAVEFILE 5 -#define FTYPE_FB 6 -#define FTYPE_KBD 7 -#define FTYPE_N 8 +#define FTYPE_N 6 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index 7f2e11f..4fb844f 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -302,30 +302,6 @@ int read(int fd, void *buf, size_t nbytes) #ifdef HAVE_LWIP case FTYPE_SOCKET: return lwip_read(files[fd].fd, buf, nbytes); -#endif -#ifdef CONFIG_KBDFRONT - case FTYPE_KBD: { - int ret, n; - n =3D nbytes / sizeof(union xenkbd_in_event); - ret =3D kbdfront_receive(files[fd].dev, buf, n); - if (ret <=3D 0) { - errno =3D EAGAIN; - return -1; - } - return ret * sizeof(union xenkbd_in_event); - } -#endif -#ifdef CONFIG_FBFRONT - case FTYPE_FB: { - int ret, n; - n =3D nbytes / sizeof(union xenfb_in_event); - ret =3D fbfront_receive(files[fd].dev, buf, n); - if (ret <=3D 0) { - errno =3D EAGAIN; - return -1; - } - return ret * sizeof(union xenfb_in_event); - } #endif default: break; @@ -443,16 +419,6 @@ int close(int fd) res =3D lwip_close(files[fd].fd); break; #endif -#ifdef CONFIG_KBDFRONT - case FTYPE_KBD: - shutdown_kbdfront(files[fd].dev); - break; -#endif -#ifdef CONFIG_FBFRONT - case FTYPE_FB: - shutdown_fbfront(files[fd].dev); - break; -#endif #ifdef CONFIG_CONSFRONT case FTYPE_SAVEFILE: case FTYPE_CONSOLE: @@ -619,8 +585,6 @@ static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", [FTYPE_CONSOLE] =3D "console", [FTYPE_SOCKET] =3D "socket", - [FTYPE_KBD] =3D "kbd", - [FTYPE_FB] =3D "fb", }; =20 static char *get_type_name(unsigned int type) @@ -795,17 +759,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_s= et *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; - case FTYPE_KBD: - case FTYPE_FB: - if (FD_ISSET(i, readfds)) { - if (files[i].read) - n++; - else - FD_CLR(i, readfds); - } - FD_CLR(i, writefds); - FD_CLR(i, exceptfds); - break; #ifdef HAVE_LWIP case FTYPE_SOCKET: if (FD_ISSET(i, readfds)) { --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913962; cv=none; d=zohomail.com; s=zohoarc; b=HCPHHGUe82FVe55LxWRXWgSrLqki6Uyg7I1liCyRwW6xXkv+tawgaiLk7gfJJFZX4gbpcgZhXE6pJz7NVl9itPm4TpqaiPw9KQWbh+HSFqLyh0u05k2wRZ/nZUXTLsyrb7CfWu+r9c9v5Qr+6P8eXy5Z8rWhHQlUvFSqoTEmXXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913962; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=akdaLVPdVVzqXtx9FHY3lThrxd9OOCJ2dYlEWLvAp9o=; b=habv9cc9aJqBEDT+NjLihdM5fy4yDR3YXcmMcDtgJymmlz+pXR0lpRv27X0nE1RHYBkf+sLolDe+m2i+IfAUA0PHrTU6qw2pv4Bul5CTWgQxRAolU12k4qq6lDwIg/HhqKEoepdWP73CbBKAOXq0BgcBhdSJdNilW8XcR8fX7AI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913962775469.175315588314; Tue, 11 Jan 2022 07:12:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255875.438789 (Exim 4.92) (envelope-from ) id 1n7Ip2-0003x7-QO; Tue, 11 Jan 2022 15:12:28 +0000 Received: by outflank-mailman (output) from mailman id 255875.438789; Tue, 11 Jan 2022 15:12:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip1-0003uY-D1; Tue, 11 Jan 2022 15:12:27 +0000 Received: by outflank-mailman (input) for mailman id 255875; Tue, 11 Jan 2022 15:12:25 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ioy-0002Fv-Vq for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:25 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id de399b05-72f0-11ec-9ce5-af14b9085ebd; Tue, 11 Jan 2022 16:12:18 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ACD45212C2; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 83AD913DDD; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0D8NH1Ke3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: de399b05-72f0-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=akdaLVPdVVzqXtx9FHY3lThrxd9OOCJ2dYlEWLvAp9o=; b=hFWZo2ZPpBfkt/xOEsSkJtcF45r7YhT6Rwk/zWLc48g4sHIdpaPaCyAx8tdwLIjRWoL/WN 3Ygu1RZv/8rkWLAhHWwddGdUynqq1UgVcWpOUPU8dKMXbNMjUt/HsUVLkN9HmQ3xKO476k 2Gzy8RBUEXvdKHhTx48Ecxrvk/6ZxxA= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 09/12] mini-os: use file_ops and get_file_from_fd() for console Date: Tue, 11 Jan 2022 16:12:12 +0100 Message-Id: <20220111151215.22955-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913963935100002 Content-Type: text/plain; charset="utf-8" Add struct file_ops for the console related file types (FTYPE_CONSOLE and savefile). FTYPE_CONSOLE remains statically defined, as it is used to statically init stdin, stdout and stderr. Instead of directly accessing the files[] array use get_file_from_fd(). With CONSOLE now handled via file_ops the bogus file descriptor case in select_poll() now needs to be handled more explicit instead of dropping into console handling, assuming that this case was basically meant to cover SAVEFILE. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- console/xenbus.c | 125 +++++++++++++++++++++++++++++++++++++++++ console/xencons_ring.c | 6 +- include/console.h | 5 ++ include/lib.h | 3 +- lib/sys.c | 87 +++++++--------------------- 5 files changed, 155 insertions(+), 71 deletions(-) diff --git a/console/xenbus.c b/console/xenbus.c index 05fc31c..b856c84 100644 --- a/console/xenbus.c +++ b/console/xenbus.c @@ -192,3 +192,128 @@ void fini_consfront(struct consfront_dev *dev) { if (dev) free_consfront(dev); } + +#ifdef HAVE_LIBC +static int consfront_read(int fd, void *buf, size_t nbytes) +{ + int ret; + struct file *file =3D get_file_from_fd(fd); + DEFINE_WAIT(w); + + while ( 1 ) + { + add_waiter(w, console_queue); + ret =3D xencons_ring_recv(file->dev, buf, nbytes); + if ( ret ) + break; + schedule(); + } + + remove_waiter(w, console_queue); + + return ret; +} + +static int savefile_write(int fd, const void *buf, size_t nbytes) +{ + int ret =3D 0, tot =3D nbytes; + struct file *file =3D get_file_from_fd(fd); + + while ( nbytes > 0 ) + { + ret =3D xencons_ring_send(file->dev, (char *)buf, nbytes); + nbytes -=3D ret; + buf =3D (char *)buf + ret; + } + + return tot - nbytes; +} + +static int console_write(int fd, const void *buf, size_t nbytes) +{ + struct file *file =3D get_file_from_fd(fd); + + console_print(file->dev, (char *)buf, nbytes); + + return nbytes; +} + +static int consfront_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + fini_consfront(file->dev); + + return 0; +} + +static int consfront_fstat(int fd, struct stat *buf) +{ + struct file *file =3D get_file_from_fd(fd); + + buf->st_mode =3D S_IRUSR | S_IWUSR; + buf->st_mode |=3D (file->type =3D=3D FTYPE_CONSOLE) ? S_IFCHR : S_IFRE= G; + buf->st_atime =3D buf->st_mtime =3D buf->st_ctime =3D time(NULL); + + return 0; +} + +static bool consfront_select_rd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + return xencons_ring_avail(file->dev); +} + +static struct file_ops savefile_ops =3D { + .name =3D "savefile", + .read =3D consfront_read, + .write =3D savefile_write, + .close =3D consfront_close_fd, + .fstat =3D consfront_fstat, + .select_rd =3D consfront_select_rd, + .select_wr =3D select_yes, +}; + +struct file_ops console_ops =3D { + .name =3D "console", + .read =3D consfront_read, + .write =3D console_write, + .close =3D consfront_close_fd, + .fstat =3D consfront_fstat, + .select_rd =3D consfront_select_rd, + .select_wr =3D select_yes, +}; + +int open_consfront(char *nodename) +{ + struct consfront_dev *dev; + static unsigned int ftype_savefile; + unsigned int ftype; + struct file *file; + + dev =3D init_consfront(nodename); + if ( !dev ) + return -1; + + if ( nodename ) + { + if ( !ftype_savefile ) + ftype_savefile =3D alloc_file_type(&savefile_ops); + ftype =3D ftype_savefile; + } + else + ftype =3D FTYPE_CONSOLE; + + dev->fd =3D alloc_fd(ftype); + file =3D get_file_from_fd(dev->fd); + if ( !file ) + { + fini_consfront(dev); + return -1; + } + file->dev =3D dev; + + return dev->fd; +} +#endif diff --git a/console/xencons_ring.c b/console/xencons_ring.c index c348f3c..efedf46 100644 --- a/console/xencons_ring.c +++ b/console/xencons_ring.c @@ -99,10 +99,10 @@ void console_handle_input(evtchn_port_t port, struct pt= _regs *regs, void *data) { struct consfront_dev *dev =3D (struct consfront_dev *) data; #ifdef HAVE_LIBC - int fd =3D dev ? dev->fd : -1; + struct file *file =3D dev ? get_file_from_fd(dev->fd) : NULL; =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; =20 wake_up(&console_queue); #else diff --git a/include/console.h b/include/console.h index 0d7bf07..8c615d0 100644 --- a/include/console.h +++ b/include/console.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -93,5 +94,9 @@ int xencons_ring_send_no_notify(struct consfront_dev *dev= , const char *data, uns int xencons_ring_avail(struct consfront_dev *dev); int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len); void free_consfront(struct consfront_dev *dev); +#ifdef HAVE_LIBC +extern struct file_ops console_ops; +int open_consfront(char *nodename); +#endif =20 #endif /* _LIB_CONSOLE_H_ */ diff --git a/include/lib.h b/include/lib.h index 653a16e..c171fe8 100644 --- a/include/lib.h +++ b/include/lib.h @@ -160,8 +160,7 @@ void sanity_check(void); #define FTYPE_FILE 2 #define FTYPE_SOCKET 3 #define FTYPE_MEM 4 -#define FTYPE_SAVEFILE 5 -#define FTYPE_N 6 +#define FTYPE_N 5 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index 4fb844f..3a8aa68 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -101,6 +101,9 @@ static struct file_ops file_ops_none =3D { =20 static struct file_ops *file_ops[FTYPE_N + FTYPE_SPARE] =3D { [FTYPE_NONE] =3D &file_ops_none, +#ifdef CONFIG_CONSFRONT + [FTYPE_CONSOLE] =3D &console_ops, +#endif }; =20 unsigned int alloc_file_type(struct file_ops *ops) @@ -211,31 +214,26 @@ int mkdir(const char *pathname, mode_t mode) #ifdef CONFIG_CONSFRONT int posix_openpt(int flags) { - struct consfront_dev *dev; + int fd; =20 /* Ignore flags */ + fd =3D open_consfront(NULL); + printk("fd(%d) =3D posix_openpt\n", fd); =20 - dev =3D init_consfront(NULL); - dev->fd =3D alloc_fd(FTYPE_CONSOLE); - files[dev->fd].dev =3D dev; - - printk("fd(%d) =3D posix_openpt\n", dev->fd); - return(dev->fd); + return fd; } =20 int open_savefile(const char *path, int save) { - struct consfront_dev *dev; + int fd; char nodename[64]; =20 snprintf(nodename, sizeof(nodename), "device/console/%d", save ? SAVE_= CONSOLE : RESTORE_CONSOLE); =20 - dev =3D init_consfront(nodename); - dev->fd =3D alloc_fd(FTYPE_SAVEFILE); - files[dev->fd].dev =3D dev; + fd =3D open_consfront(nodename); + printk("fd(%d) =3D open_savefile\n", fd); =20 - printk("fd(%d) =3D open_savefile\n", dev->fd); - return(dev->fd); + return fd; } #else int posix_openpt(int flags) @@ -285,20 +283,6 @@ int read(int fd, void *buf, size_t nbytes) return ops->read(fd, buf, nbytes); =20 switch (files[fd].type) { - case FTYPE_SAVEFILE: - case FTYPE_CONSOLE: { - int ret; - DEFINE_WAIT(w); - while(1) { - add_waiter(w, console_queue); - ret =3D xencons_ring_recv(files[fd].dev, buf, nbytes); - if (ret) - break; - schedule(); - } - remove_waiter(w, console_queue); - return ret; - } #ifdef HAVE_LWIP case FTYPE_SOCKET: return lwip_read(files[fd].fd, buf, nbytes); @@ -319,18 +303,6 @@ int write(int fd, const void *buf, size_t nbytes) return ops->write(fd, buf, nbytes); =20 switch (files[fd].type) { - case FTYPE_SAVEFILE: { - int ret =3D 0, tot =3D nbytes; - while (nbytes > 0) { - ret =3D xencons_ring_send(files[fd].dev, (char *)buf, = nbytes); - nbytes -=3D ret; - buf =3D (char *)buf + ret; - } - return tot - nbytes; - } - case FTYPE_CONSOLE: - console_print(files[fd].dev, (char *)buf, nbytes); - return nbytes; #ifdef HAVE_LWIP case FTYPE_SOCKET: return lwip_write(files[fd].fd, (void*) buf, nbytes); @@ -418,12 +390,6 @@ int close(int fd) case FTYPE_SOCKET: res =3D lwip_close(files[fd].fd); break; -#endif -#ifdef CONFIG_CONSFRONT - case FTYPE_SAVEFILE: - case FTYPE_CONSOLE: - fini_consfront(files[fd].dev); - break; #endif case FTYPE_NONE: printk("close(%d): Bad descriptor\n", fd); @@ -464,15 +430,8 @@ int fstat(int fd, struct stat *buf) return ops->fstat(fd, buf); =20 switch (files[fd].type) { - case FTYPE_SAVEFILE: - case FTYPE_CONSOLE: case FTYPE_SOCKET: { - if (files[fd].type =3D=3D FTYPE_CONSOLE) - buf->st_mode =3D S_IFCHR|S_IRUSR|S_IWUSR; - else if (files[fd].type =3D=3D FTYPE_SOCKET) - buf->st_mode =3D S_IFSOCK|S_IRUSR|S_IWUSR; - else if (files[fd].type =3D=3D FTYPE_SAVEFILE) - buf->st_mode =3D S_IFREG|S_IRUSR|S_IWUSR; + buf->st_mode =3D S_IFSOCK|S_IRUSR|S_IWUSR; buf->st_uid =3D 0; buf->st_gid =3D 0; buf->st_size =3D 0; @@ -583,7 +542,6 @@ int closedir(DIR *dir) #if defined(LIBC_DEBUG) || defined(LIBC_VERBOSE) static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", - [FTYPE_CONSOLE] =3D "console", [FTYPE_SOCKET] =3D "socket", }; =20 @@ -744,21 +702,18 @@ static int select_poll(int nfds, fd_set *readfds, fd_= set *writefds, fd_set *exce } =20 if (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, exce= ptfds)) + { printk("bogus fd %d in select\n", i); - /* Fallthrough. */ - } - - case FTYPE_CONSOLE: - if (FD_ISSET(i, readfds)) { - if (xencons_ring_avail(files[i].dev)) - n++; - else - FD_CLR(i, readfds); + if ( FD_ISSET(i, readfds) ) + FD_CLR(i, readfds); + if ( FD_ISSET(i, writefds) ) + FD_CLR(i, writefds); + if ( FD_ISSET(i, exceptfds) ) + FD_CLR(i, exceptfds); } - if (FD_ISSET(i, writefds)) - n++; - FD_CLR(i, exceptfds); break; + } + #ifdef HAVE_LWIP case FTYPE_SOCKET: if (FD_ISSET(i, readfds)) { --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641914432; cv=none; d=zohomail.com; s=zohoarc; b=D4iqT6N01L6VtclngNmm9JDmu+ViB8zX+6GJlB/vVPOd2lea1XORuRHgIeDFAa/fUxNaXOWTd1FLg33+6EAAqQAvsDsPN+IeuRX3/mcSGYj+F4zXlmqHPGN3omP+WgOrWHMrIIhQnMPz5o2zfs5ibMQvF92TtBnA+2tIabUhe/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641914432; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/J7Pbzy4bEMLs1Zfn02zqrQKoe12Kbt0uIHiCf5rrSk=; b=QejbL1jXWYC45ON3W0EWrsI7WfpYcgEEfWLfOFUqkWXTDkzur9SSbllxnbwRml+SEDMLLXcm7XgP+IlJUt6ftlWvEtQzCN11oxU+fzYVWvQ8VMSKAq3vhwacBZ9K4OJe4WtFoJDzPq2ILx6Lf/VUh6eqsr8GcH93C7OdNcYKq4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16419144324093.6342035753658593; Tue, 11 Jan 2022 07:20:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255905.438894 (Exim 4.92) (envelope-from ) id 1n7IwT-00035h-HU; Tue, 11 Jan 2022 15:20:09 +0000 Received: by outflank-mailman (output) from mailman id 255905.438894; Tue, 11 Jan 2022 15:20:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7IwT-00035a-EC; Tue, 11 Jan 2022 15:20:09 +0000 Received: by outflank-mailman (input) for mailman id 255905; Tue, 11 Jan 2022 15:20:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip5-0002Fw-FD for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:31 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id de4d45f5-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:19 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DBC7B1F3B8; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B2E1813DDD; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SOJ9KlKe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: de4d45f5-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/J7Pbzy4bEMLs1Zfn02zqrQKoe12Kbt0uIHiCf5rrSk=; b=jRefBonpoL7Y3znlLNWa9M4TFpzlRZgE9MInSr2UJlJjav+cOsfGIENNqmwfxbIwkiCE0f grByPAHUcFc8WpgtefmOUQnilaHoq3aZTTO/yd163GJ7UfkwpckSX0VxO6mgoSJ/mNwO0A b4Tc4nZMc0y/ZgNUEgjRMXOdYxelxYU= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 10/12] mini-os: add struct file_ops for file type socket Date: Tue, 11 Jan 2022 16:12:13 +0100 Message-Id: <20220111151215.22955-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641914434985100001 Content-Type: text/plain; charset="utf-8" Even with some special handling needed in select_poll(), add a struct file_ops for FTYPE_SOCKET. Due to the need of the special handling it isn't possible to use a dynamically allocated file type. Most functions calling the file_ops methods can be simplified a lot now that no file type specific handling is left. Same applies to the file type name printing in debug/verbose mode. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- lib/sys.c | 153 +++++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 83 deletions(-) diff --git a/lib/sys.c b/lib/sys.c index 3a8aa68..12deaed 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -99,11 +99,70 @@ static struct file_ops file_ops_none =3D { .name =3D "none", }; =20 +#ifdef HAVE_LWIP +static int socket_read(int fd, void *buf, size_t nbytes) +{ + return lwip_read(fd, buf, nbytes); +} + +static int socket_write(int fd, const void *buf, size_t nbytes) +{ + return lwip_write(fd, (void *)buf, nbytes); +} + +static int close_socket_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + return lwip_close(file->fd); +} + +static int socket_fstat(int fd, struct stat *buf) +{ + buf->st_mode =3D S_IFSOCK | S_IRUSR | S_IWUSR; + buf->st_atime =3D buf->st_mtime =3D buf->st_ctime =3D time(NULL); + + return 0; +} + +static int socket_fcntl(int fd, int cmd, va_list args) +{ + long arg; + struct file *file =3D get_file_from_fd(fd); + + arg =3D va_arg(args, long); + + if ( cmd =3D=3D F_SETFL && !(arg & ~O_NONBLOCK) ) + { + /* Only flag supported: non-blocking mode */ + uint32_t nblock =3D !!(arg & O_NONBLOCK); + + return lwip_ioctl(file->fd, FIONBIO, &nblock); + } + + printk("fcntl(%d, %d, %lx/%lo)\n", fd, cmd, arg, arg); + errno =3D ENOSYS; + return -1; +} + +static struct file_ops socket_ops =3D { + .name =3D "socket", + .read =3D socket_read, + .write =3D socket_write, + .close =3D close_socket_fd, + .fstat =3D socket_fstat, + .fcntl =3D socket_fcntl, +}; +#endif + static struct file_ops *file_ops[FTYPE_N + FTYPE_SPARE] =3D { [FTYPE_NONE] =3D &file_ops_none, #ifdef CONFIG_CONSFRONT [FTYPE_CONSOLE] =3D &console_ops, #endif +#ifdef HAVE_LWIP + [FTYPE_SOCKET] =3D &socket_ops, +#endif }; =20 unsigned int alloc_file_type(struct file_ops *ops) @@ -282,14 +341,6 @@ int read(int fd, void *buf, size_t nbytes) if ( ops->read ) return ops->read(fd, buf, nbytes); =20 - switch (files[fd].type) { -#ifdef HAVE_LWIP - case FTYPE_SOCKET: - return lwip_read(files[fd].fd, buf, nbytes); -#endif - default: - break; - } printk("read(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; @@ -302,14 +353,6 @@ int write(int fd, const void *buf, size_t nbytes) if ( ops->write ) return ops->write(fd, buf, nbytes); =20 - switch (files[fd].type) { -#ifdef HAVE_LWIP - case FTYPE_SOCKET: - return lwip_write(files[fd].fd, (void*) buf, nbytes); -#endif - default: - break; - } printk("write(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; @@ -378,26 +421,14 @@ int close(int fd) =20 printk("close(%d)\n", fd); if ( ops->close ) - { res =3D ops->close(fd); - goto out; - } - - switch (files[fd].type) { - default: - break; -#ifdef HAVE_LWIP - case FTYPE_SOCKET: - res =3D lwip_close(files[fd].fd); - break; -#endif - case FTYPE_NONE: - printk("close(%d): Bad descriptor\n", fd); - errno =3D EBADF; - return -1; + else if ( files[fd].type =3D=3D FTYPE_NONE ) + { + printk("close(%d): Bad descriptor\n", fd); + errno =3D EBADF; + return -1; } =20 - out: memset(files + fd, 0, sizeof(struct file)); files[fd].type =3D FTYPE_NONE; return res; @@ -429,21 +460,6 @@ int fstat(int fd, struct stat *buf) if ( ops->fstat ) return ops->fstat(fd, buf); =20 - switch (files[fd].type) { - case FTYPE_SOCKET: { - buf->st_mode =3D S_IFSOCK|S_IRUSR|S_IWUSR; - buf->st_uid =3D 0; - buf->st_gid =3D 0; - buf->st_size =3D 0; - buf->st_atime =3D=20 - buf->st_mtime =3D=20 - buf->st_ctime =3D time(NULL); - return 0; - } - default: - break; - } - printk("statf(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; @@ -491,21 +507,9 @@ int fcntl(int fd, int cmd, ...) arg =3D va_arg(ap, long); va_end(ap); =20 - switch (cmd) { -#ifdef HAVE_LWIP - case F_SETFL: - if (files[fd].type =3D=3D FTYPE_SOCKET && !(arg & ~O_NONBLOCK)) { - /* Only flag supported: non-blocking mode */ - uint32_t nblock =3D !!(arg & O_NONBLOCK); - return lwip_ioctl(files[fd].fd, FIONBIO, &nblock); - } - /* Fallthrough */ -#endif - default: - printk("fcntl(%d, %d, %lx/%lo)\n", fd, cmd, arg, arg); - errno =3D ENOSYS; - return -1; - } + printk("fcntl(%d, %d, %lx/%lo)\n", fd, cmd, arg, arg); + errno =3D ENOSYS; + return -1; } =20 DIR *opendir(const char *name) @@ -539,23 +543,6 @@ int closedir(DIR *dir) =20 /* We assume that only the main thread calls select(). */ =20 -#if defined(LIBC_DEBUG) || defined(LIBC_VERBOSE) -static const char *file_types[] =3D { - [FTYPE_NONE] =3D "none", - [FTYPE_SOCKET] =3D "socket", -}; - -static char *get_type_name(unsigned int type) -{ - if ( type < ARRAY_SIZE(file_ops) && file_ops[type] ) - return file_ops[type]->name; - - if ( type < ARRAY_SIZE(file_types) && file_types[type] ) - return file_types[type]; - - return "none"; -} -#endif #ifdef LIBC_DEBUG static void dump_set(int nfds, fd_set *readfds, fd_set *writefds, fd_set *= exceptfds, struct timeval *timeout) { @@ -566,7 +553,7 @@ static void dump_set(int nfds, fd_set *readfds, fd_set = *writefds, fd_set *except if (FD_ISSET(i, set)) { \ if (comma) \ printk(", "); \ - printk("%d(%s)", i, get_type_name(files[i].type)); \ + printk("%d(%s)", i, get_file_ops(files[i].type)->name); \ comma =3D 1; \ } \ } \ @@ -600,7 +587,7 @@ static void dump_pollfds(struct pollfd *pfd, int nfds, = int timeout) fd =3D pfd[i].fd; if (comma) printk(", "); - printk("%d(%s)/%02x", fd, get_type_name(files[fd].type), + printk("%d(%s)/%02x", fd, get_file_ops(files[fd].type)->name, pfd[i].events); comma =3D 1; } @@ -754,7 +741,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_se= t *writefds, fd_set *exce printk("%d(%d): ", nb, sock_n); for (i =3D 0; i < nfds; i++) { if (nbread[i] || nbwrite[i] || nbexcept[i]) - printk(" %d(%c):", i, get_type_name(files[i].type)); + printk(" %d(%c):", i, get_file_ops(files[i].type)->name); if (nbread[i]) printk(" %dR", nbread[i]); if (nbwrite[i]) --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913964; cv=none; d=zohomail.com; s=zohoarc; b=WjQgnB8PsNnjUZzrOoYUghKmnTzHDyJWD5sXXl8uV4Gp0Bvh/19rz61WpZwITLBNOPUXgxo7hsFn3uXDlPy67rj0cTqOJ09sUrWsq/UQQKzVGWzfBsmQ0UzW+/kU39px1bWR/vacTTYOug6CGwTdo35BhUW4vDI1A6qUy3B2EDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913964; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LT7y4F0rIJkzgfg3Wqk+kFvoECYDkYG0U0o/MY4F4aI=; b=RAW520mInSs9XjlwnHbCYkcOXvMVxTH4DI8/wwSqm3DYtoL6ARZXzUR/EVTRtt6BvylsLpwTC4F8GcMFo7lJnWDMRzRimQDpx7eGHzzFlR+a4w8H+bM/QJ9Bm17wKo1BcOePKYIPjsO2R3NgR/E2hk/5j2kcTmWNuCNG4j6o0nQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913964955491.0555046057008; Tue, 11 Jan 2022 07:12:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255879.438812 (Exim 4.92) (envelope-from ) id 1n7Ip5-0004e9-Uu; Tue, 11 Jan 2022 15:12:31 +0000 Received: by outflank-mailman (output) from mailman id 255879.438812; Tue, 11 Jan 2022 15:12:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip5-0004Zj-1W; Tue, 11 Jan 2022 15:12:31 +0000 Received: by outflank-mailman (input) for mailman id 255879; Tue, 11 Jan 2022 15:12:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip0-0002Fv-W8 for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:26 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id de7324e1-72f0-11ec-9ce5-af14b9085ebd; Tue, 11 Jan 2022 16:12:19 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1802F1F3B9; Tue, 11 Jan 2022 15:12:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E27A913DDD; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MH/eNVKe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: de7324e1-72f0-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913939; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LT7y4F0rIJkzgfg3Wqk+kFvoECYDkYG0U0o/MY4F4aI=; b=J3Y9NA+QaK3CF8Btdh7yERlbdXYM4SHcMGD4DBHtgKs4C1sRKVE81UI0g2nNwB9bek+8ly Gx+PHio0I06zucoyCKZq/DjGp0OJMqhiLm1Ei/YJVqbBkKTwIFK8d7ACGJ6G5qp147LkSC 2znecvy9nwsbg1LkPq6Hmb1Ni3fLgtw= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 11/12] mini-os: add struct file_ops for FTYPE_FILE Date: Tue, 11 Jan 2022 16:12:14 +0100 Message-Id: <20220111151215.22955-12-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913966888100001 Content-Type: text/plain; charset="utf-8" FTYPE_FILE is the last relevant file type without a struct file_ops. Add it. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- lib/sys.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/sys.c b/lib/sys.c index 12deaed..0f42e97 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -99,6 +99,11 @@ static struct file_ops file_ops_none =3D { .name =3D "none", }; =20 +static struct file_ops file_file_ops =3D { + .name =3D "file", + .lseek =3D lseek_default, +}; + #ifdef HAVE_LWIP static int socket_read(int fd, void *buf, size_t nbytes) { @@ -160,6 +165,7 @@ static struct file_ops *file_ops[FTYPE_N + FTYPE_SPARE]= =3D { #ifdef CONFIG_CONSFRONT [FTYPE_CONSOLE] =3D &console_ops, #endif + [FTYPE_FILE] =3D &file_file_ops, #ifdef HAVE_LWIP [FTYPE_SOCKET] =3D &socket_ops, #endif @@ -397,16 +403,9 @@ off_t lseek(int fd, off_t offset, int whence) if ( ops->lseek ) return ops->lseek(fd, offset, whence); =20 - switch(files[fd].type) { - case FTYPE_FILE: - break; - default: - /* Not implemented for this filetype */ - errno =3D ESPIPE; - return (off_t) -1; - } - - return lseek_default(fd, offset, whence); + /* Not implemented for this filetype */ + errno =3D ESPIPE; + return (off_t) -1; } =20 int fsync(int fd) { --=20 2.26.2 From nobody Tue Apr 23 15:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641914262; cv=none; d=zohomail.com; s=zohoarc; b=m0MlzNBP7PO6lnHW0yB60GEC6lMyGXD7UG4T8PvCrsNm9gB2qnz2wDZG4qmpQ/YjDG8h7+EBkYgtbQSD/PtYrJpECU87oQJGPM/tmaORFXdLrAYmf8DQ11/8WVMPAa22NJbTUNdeoIpJgs+h4yaAD1fQOzDe1cxsmfsECq86yyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641914262; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cFwpD60ZcJNKwT6VpP/TNivSPE9GLBBs9qy9595IhG4=; b=V12xotrAOuFomAdcXyWLfFVEc4K4bT2xzpUM2nggYaN9k2C/EABd7Z60XByHvnCjp9AaayjxWGyMZ0rcabJgalxvY0cydsQAEJjHv/RI4VO8OZL3gVyo3gbjCvz8s1shZnq9fHuWmb+er6BwtW03CP5DG1ikWHXFiUniXS9lL34= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641914262274649.9338248129923; Tue, 11 Jan 2022 07:17:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255894.438850 (Exim 4.92) (envelope-from ) id 1n7Itb-0000YE-A1; Tue, 11 Jan 2022 15:17:11 +0000 Received: by outflank-mailman (output) from mailman id 255894.438850; Tue, 11 Jan 2022 15:17:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Itb-0000Y7-6g; Tue, 11 Jan 2022 15:17:11 +0000 Received: by outflank-mailman (input) for mailman id 255894; Tue, 11 Jan 2022 15:17:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip7-0002Fw-FX for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:33 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id de878388-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:19 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 466151F3BA; Tue, 11 Jan 2022 15:12:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1F80B13DDD; Tue, 11 Jan 2022 15:12:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6JqoBlOe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: de878388-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913939; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cFwpD60ZcJNKwT6VpP/TNivSPE9GLBBs9qy9595IhG4=; b=Zl160vCEssZCDKXNooVkVMdF+ZGxizKNsTLHQIHyHoirX1qQQpo57vSIKxqXGstRXLF0FM 4nabICwSmWFWby2PVJnme7m2SpFZJrFSM/4KnosLnIoyDCWZoToEhmpqN1jLOfs/xTUeqU 2WRjo1La8bfIpj1bKgVtvaVaq7nswWc= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 12/12] mini-os: make files array private to sys.c Date: Tue, 11 Jan 2022 16:12:15 +0100 Message-Id: <20220111151215.22955-13-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641914264489100001 Content-Type: text/plain; charset="utf-8" There is no user of the files[] array outside of lib/sys.c left, so it can be made static. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 2 -- lib/sys.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/lib.h b/include/lib.h index c171fe8..80e804b 100644 --- a/include/lib.h +++ b/include/lib.h @@ -199,8 +199,6 @@ struct file { }; }; =20 -extern struct file files[]; - struct file *get_file_from_fd(int fd); int alloc_fd(unsigned int type); void close_all_files(void); diff --git a/lib/sys.c b/lib/sys.c index 0f42e97..c0cad87 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -89,7 +89,7 @@ extern void minios_evtchn_close_fd(int fd); extern void minios_gnttab_close_fd(int fd); =20 pthread_mutex_t fd_lock =3D PTHREAD_MUTEX_INITIALIZER; -struct file files[NOFILE] =3D { +static struct file files[NOFILE] =3D { { .type =3D FTYPE_CONSOLE }, /* stdin */ { .type =3D FTYPE_CONSOLE }, /* stdout */ { .type =3D FTYPE_CONSOLE }, /* stderr */ --=20 2.26.2