From nobody Sun May 5 09:56:36 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=1642322037; cv=none; d=zohomail.com; s=zohoarc; b=Q5dF2bkRRMDo/RSA3ZxUEGsZWUHPcVL8SlKzNpikDQ3vTUGiVk6VVo8EfSQ0vbnzqzm6pTtNtuxKU8Vz2Cerfea4E1SnUOLhw4mADQJyHLNLi24UcVmamOHoeA4itrGwZen9D5OeNM8KjsiaczwZU6ABOVqxzzWreRcdiS5MP94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322037; 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=xMC2cVvglpwHtHj58DJ+I44rqFmTlB+K2cTWldEOzOc=; b=dkF1BikYwypMkD6CR8haLTetNGj0gb9QjD0nXHONGuYa9l8jBOlyWwYL7JU4hxhRCNr3UojmgQAkPgQiikSby7x4rzaNRC2AMMJsfK5D957fAGJYY2ObrCvwjciYVXN/cgq4x3F30jyzCiFCqlG9vYmphVMPmLjbqfK2qZW7YaA= 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 1642322037122523.7162513843932; Sun, 16 Jan 2022 00:33:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257820.443179 (Exim 4.92) (envelope-from ) id 1n90yk-0008Oy-6M; Sun, 16 Jan 2022 08:33:34 +0000 Received: by outflank-mailman (output) from mailman id 257820.443179; Sun, 16 Jan 2022 08:33:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90yk-0008OQ-0k; Sun, 16 Jan 2022 08:33:34 +0000 Received: by outflank-mailman (input) for mailman id 257820; Sun, 16 Jan 2022 08:33:33 +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 1n90yi-0008IQ-UV for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:33 +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 fbdcf1d2-76a6-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:33:30 +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 B8B4B1F3B3; Sun, 16 Jan 2022 08:33:30 +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 8EBD813AB5; Sun, 16 Jan 2022 08:33:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ICuiIVrY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:30 +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: fbdcf1d2-76a6-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322010; 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=xMC2cVvglpwHtHj58DJ+I44rqFmTlB+K2cTWldEOzOc=; b=Z8BC/NvAOFa5H57kZB92bNQ6WlKFk3IuPrew6E4KfZN1ovw1oeBoQjyQgkNIioIqRzGK1A SJwPi+08i71eetf7eN6D54DfhGrY6P0BJWC61wBt8u/Jx5iwSNGOv5eQUaVritwbgzsub2 4sLRrt8Cp3NThPxtOON3N+eG1KacYFw= 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: [MINIOS PATCH v3 01/12] remove event channel specific struct file definitions Date: Sun, 16 Jan 2022 09:33:17 +0100 Message-Id: <20220116083328.26524-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322039495100005 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. Add an extern declaration for event_queue as it is used by libxenevtchn. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V3: - add extern declaration for event_queue (Andrew Cooper) --- Config.mk | 1 - arch/x86/testbuild/all-no | 1 - arch/x86/testbuild/all-yes | 1 - arch/x86/testbuild/newxen-yes | 1 - include/lib.h | 17 +++-------------- lib/sys.c | 7 ------- 6 files changed, 3 insertions(+), 25 deletions(-) diff --git a/Config.mk b/Config.mk index 03023033..52eb26d8 100644 --- a/Config.mk +++ b/Config.mk @@ -200,7 +200,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 46f974de..15c954ff 100644 --- a/arch/x86/testbuild/all-no +++ b/arch/x86/testbuild/all-no @@ -14,7 +14,6 @@ CONFIG_KBDFRONT =3D n CONFIG_CONSFRONT =3D n CONFIG_XENBUS =3D n CONFIG_LIBXS =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 3ead12f1..9964d42f 100644 --- a/arch/x86/testbuild/all-yes +++ b/arch/x86/testbuild/all-yes @@ -17,6 +17,5 @@ CONFIG_LIBXS =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 5c0b3c80..c2519938 100644 --- a/arch/x86/testbuild/newxen-yes +++ b/arch/x86/testbuild/newxen-yes @@ -18,6 +18,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 44696806..5f24be5d 100644 --- a/include/lib.h +++ b/include/lib.h @@ -155,6 +155,8 @@ do { = \ void sanity_check(void); =20 #ifdef HAVE_LIBC +extern struct wait_queue_head event_queue; + #define FTYPE_NONE 0 #define FTYPE_CONSOLE 1 #define FTYPE_FILE 2 @@ -169,19 +171,9 @@ 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 -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 */ @@ -189,9 +181,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 e0ac5099..34f0193d 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -533,11 +533,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); @@ -770,7 +765,6 @@ static const char *const 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", @@ -970,7 +964,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 Sun May 5 09:56:36 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=1642322039; cv=none; d=zohomail.com; s=zohoarc; b=MyqoKjW/MoQn/3lrMEYvxVoUMArHtXYOj+aaFpAvQ7rSJ2poKWPM4SxIOUJqL7J4U4IZzt/DA2TEELJ3qRlxnG4Z4R4ovibs+0TYHFOolCVmaqUPXtO/ad3lbTg7KSIOUMUAvZgpY2R/fTCSicgt60S4vdvPZ/7Oa/NozsnnoZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322039; 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=qdHeJugvWS+GzJaTnlBhH4gNO7kfbGMjcepHl4bCr44=; b=ZBM+B3yKKOC3PIwfcAUIkfym4ds2p2xyAaw27+/Z760ACh1Hf9Bjw1CuDMcnTX/MJmioKnIcDVyKwlSqE7/0T0kOpTy+kX0rFNoZlS7EBDpqXHlP4mrIj7Bp6tXzQJSZMSrWgHVVi1MiB3dXn3PG06cYK+finSeDzuwsl0gzWZ4= 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 1642322039207869.601156039359; Sun, 16 Jan 2022 00:33:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257823.443205 (Exim 4.92) (envelope-from ) id 1n90ym-0000YA-Lu; Sun, 16 Jan 2022 08:33:36 +0000 Received: by outflank-mailman (output) from mailman id 257823.443205; Sun, 16 Jan 2022 08:33:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90ym-0000Y3-H8; Sun, 16 Jan 2022 08:33:36 +0000 Received: by outflank-mailman (input) for mailman id 257823; Sun, 16 Jan 2022 08:33:34 +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 1n90yk-0008IP-OX for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:34 +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 fc3fcfa4-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:31 +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 E9384219A8; Sun, 16 Jan 2022 08:33:30 +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 BF0691346A; Sun, 16 Jan 2022 08:33:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KKZoLVrY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:30 +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: fc3fcfa4-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322010; 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=qdHeJugvWS+GzJaTnlBhH4gNO7kfbGMjcepHl4bCr44=; b=NMXCYAVn3u48qz/nj5DiauAFFiSxg6SiVsgRSmzrrMeo41l5GGj4hKFz3UgACcl9kuH1qI PrZMTnIYatgYIgsZTiJOhz5ntI/xmkt8/0ITGZ9kNlFm4joLLK647eohlZkxocMw5P7rcW MXgVM7w2VUdrNRtyx2OmTa/txOY6OEg= 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: [MINIOS PATCH v3 02/12] remove gnttab specific member from struct file Date: Sun, 16 Jan 2022 09:33:18 +0100 Message-Id: <20220116083328.26524-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322041094100013 Content-Type: text/plain; charset="utf-8" The gnttab 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 52eb26d8..1a24b30e 100644 --- a/Config.mk +++ b/Config.mk @@ -200,7 +200,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 15c954ff..f79a1012 100644 --- a/arch/x86/testbuild/all-no +++ b/arch/x86/testbuild/all-no @@ -14,7 +14,6 @@ CONFIG_KBDFRONT =3D n CONFIG_CONSFRONT =3D n CONFIG_XENBUS =3D n CONFIG_LIBXS =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 9964d42f..faa3af32 100644 --- a/arch/x86/testbuild/all-yes +++ b/arch/x86/testbuild/all-yes @@ -17,5 +17,4 @@ CONFIG_LIBXS =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 c2519938..dc83e670 100644 --- a/arch/x86/testbuild/newxen-yes +++ b/arch/x86/testbuild/newxen-yes @@ -18,5 +18,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 6fa1dac1..3422ab23 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 5f24be5d..5838b0d4 100644 --- a/include/lib.h +++ b/include/lib.h @@ -170,8 +170,7 @@ extern struct wait_queue_head event_queue; #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 struct file { @@ -181,7 +180,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 34f0193d..6ba26294 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -533,11 +533,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 Sun May 5 09:56:36 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=1642322037; cv=none; d=zohomail.com; s=zohoarc; b=amDkKqcSTJFH3Km1vWJHIhoZA1BCx+4wkKmwoppdUpk1NyZdSsswJpyDQoVlgEqzkl8ub5ChXdxy8De+ywDm1jfU4zlZgE+icjtAz+vodeo4a87vD+27UgK6vsZYh11f+5vhGTYbO1OXLyKY8L703qoIILXFJOt3jhc4IgmlzyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322037; 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=BA1FXffCj1pRX9eT2SPzxm7/juZIBKAdcFoxvIMicZM=; b=AaQoN5DiKWc575nMwHl6u1RZTBmmLE7nNoSWHZ2YNHlComPS8aLbRnf7XlLRGTb7vkGULEzI/BvIskMShIST0nZ7kYNp0aiMC7FarFw8iNfIhs6WJm9Aa4vqY2W8uWhpm7oCyh+xTCx0nFW8q+/uK7r8QB56vkjpGsCxk3e2tms= 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 164232203756519.237187283425442; Sun, 16 Jan 2022 00:33:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257827.443232 (Exim 4.92) (envelope-from ) id 1n90yp-00015C-8j; Sun, 16 Jan 2022 08:33:39 +0000 Received: by outflank-mailman (output) from mailman id 257827.443232; Sun, 16 Jan 2022 08:33:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90yo-000145-VA; Sun, 16 Jan 2022 08:33:38 +0000 Received: by outflank-mailman (input) for mailman id 257827; Sun, 16 Jan 2022 08:33:36 +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 1n90ym-0008IP-Ot for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:36 +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 fc5c7437-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:31 +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 24AED219C7; Sun, 16 Jan 2022 08:33:31 +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 EEDB31346A; Sun, 16 Jan 2022 08:33:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gFAeOVrY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:30 +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: fc5c7437-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322011; 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=BA1FXffCj1pRX9eT2SPzxm7/juZIBKAdcFoxvIMicZM=; b=p2M7YRDOPXHlt5FZ7r0mAq2b0Nt69Rb574mg1OrScenyE0vv73xEFn8qZ2lnkAwV6L9w4o NPamkQW6L776NZGmgt628jaUlrzJ6T+R49bG1iL7Hda0EqkYGGc+tOItb56DTjAmx2N7Im J8urN7vxH3savtG1N9kPKesKhVjNwj4= 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: [MINIOS PATCH v3 03/12] use alloc_file_type() and get_file_from_fd() in xs Date: Sun, 16 Jan 2022 09:33:19 +0100 Message-Id: <20220116083328.26524-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322039494100004 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) --- include/lib.h | 3 +-- lib/sys.c | 18 -------------- lib/xs.c | 65 +++++++++++++++++++++++++++++++++++++------------ xenbus/xenbus.c | 1 + 4 files changed, 52 insertions(+), 35 deletions(-) diff --git a/include/lib.h b/include/lib.h index 5838b0d4..c5e47786 100644 --- a/include/lib.h +++ b/include/lib.h @@ -169,8 +169,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/lib/sys.c b/lib/sys.c index 6ba26294..53870aa4 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -523,11 +523,6 @@ int close(int fd) switch (file->type) { default: break; -#ifdef CONFIG_LIBXS - 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); @@ -759,7 +754,6 @@ int closedir(DIR *dir) static const char *const 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", @@ -947,18 +941,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_LIBXS - 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 4af0f960..c12341aa 100644 --- a/lib/xs.c +++ b/lib/xs.c @@ -18,23 +18,56 @@ static inline int _xs_fileno(struct xs_handle *h) { return (intptr_t) h; } =20 +static int xs_close_fd(struct file *file) +{ + struct xenbus_event *event, *next; + + for (event =3D file->dev; event; event =3D next) + { + next =3D event->next; + free(event); + } + + return 0; +} + +static bool xs_can_read(struct file *file) +{ + return file && file->dev; +} + +static const struct file_ops xenbus_ops =3D { + .name =3D "xenbus", + .close =3D xs_close_fd, + .select_rd =3D xs_can_read, +}; + +static unsigned int ftype_xenbus; + +__attribute__((constructor)) +static void xs_initialize(void) +{ + ftype_xenbus =3D alloc_file_type(&xenbus_ops); +} + 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; + + 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 +202,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 b687678f..785389fb 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 Sun May 5 09:56:36 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=1642322039; cv=none; d=zohomail.com; s=zohoarc; b=ZSvlXG0k3WxfcyfnJwHdwGlgE+4Fkwre7Y7Ofi67rl+Vu2Rnv6iz/QowWprrlH8arK9vzhMWjwNIGQTJjRL+B3Ey3NFo2BS7hr7w3QmwaVV4G99jJ9PzbcRXi3Gfltixy2sMqqlfCSHHaKUsEvHbhtInBEKRyRSzLbv9MclIIm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322039; 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=z5ZEOSnl4Zm8BpIud/3/sxMgQuEGzQWgZcmgMQmThgA=; b=VKQRqcb+67ylnJtemZMGO6SfesSrITDsDaRtsXNVzP0XfmuoBdaOVnWyCUZ0mKylCKGeVRAL8TK9NoWht2wuTBt2gwmIIeiiF5P0M7ALjJ0glsRzJPwUSMioqRSAQYaYnaNPKjImWJAHWHCsaDp5mFcdJj0QQU+o0EvQqEr/tnI= 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 164232203920534.25132335107958; Sun, 16 Jan 2022 00:33:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257832.443254 (Exim 4.92) (envelope-from ) id 1n90yr-0001V0-Th; Sun, 16 Jan 2022 08:33:41 +0000 Received: by outflank-mailman (output) from mailman id 257832.443254; Sun, 16 Jan 2022 08:33:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90yr-0001Sh-7c; Sun, 16 Jan 2022 08:33:41 +0000 Received: by outflank-mailman (input) for mailman id 257832; Sun, 16 Jan 2022 08:33:39 +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 1n90yo-0008IP-PG for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:38 +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 fc7d0c98-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:31 +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 575631F3B4; Sun, 16 Jan 2022 08:33:31 +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 2AF791346A; Sun, 16 Jan 2022 08:33:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0Dc/CVvY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:31 +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: fc7d0c98-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322011; 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=z5ZEOSnl4Zm8BpIud/3/sxMgQuEGzQWgZcmgMQmThgA=; b=ta1KHt3mzpfTtqE/kK0s7Nq6GcCZ9DhxscohOKSJKKR4HZGpCUC5gtscn6x05/+MQfLiOr noUHikursRXc+lnUIl1rLfXai2fiBhdO82FHfX0VTD4MzDW3GF7tKvc1K4Ps5ZB0yn9oCb sGx7gjigrhbi4xQJEcIlnh3lr3PGzgY= 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: [MINIOS PATCH v3 04/12] use alloc_file_type() and get_file_from_fd() in tpm_tis Date: Sun, 16 Jan 2022 09:33:20 +0100 Message-Id: <20220116083328.26524-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322942888100001 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) --- include/lib.h | 3 +- include/tpm_tis.h | 6 --- lib/sys.c | 23 --------- tpm_tis.c | 121 +++++++++++++++++++++++++++++----------------- 4 files changed, 78 insertions(+), 75 deletions(-) diff --git a/include/lib.h b/include/lib.h index c5e47786..9dfb4689 100644 --- a/include/lib.h +++ b/include/lib.h @@ -168,8 +168,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/include/tpm_tis.h b/include/tpm_tis.h index 86e83f13..2af974db 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 53870aa4..2fc81f20 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -355,11 +354,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; @@ -412,10 +406,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; @@ -482,10 +472,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; @@ -543,11 +529,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); @@ -636,10 +617,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 477f5550..b88ec874 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,26 @@ 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 +1266,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 +1284,19 @@ 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(struct file *file) { - /* Silently prevent multiple opens */ - if(tpm->fd !=3D -1) { - return tpm->fd; - } + shutdown_tpm_tis(file->dev); =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; + return 0; } =20 -int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count) +static int tpm_tis_posix_write(struct file *file, const void *buf, size_t = count) { - struct tpm_chip* tpm; - tpm =3D files[fd].dev; + struct tpm_chip *tpm =3D file->dev; =20 if(tpm->locality < 0) { printk("tpm_tis_posix_write() failed! locality not set!\n"); @@ -1319,11 +1320,10 @@ 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(struct file *file, void *buf, size_t count) { int rc; - struct tpm_chip* tpm; - tpm =3D files[fd].dev; + struct tpm_chip *tpm =3D file->dev; =20 if(count =3D=3D 0) { return 0; @@ -1337,20 +1337,21 @@ 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(struct file *file, struct stat *buf) { - struct tpm_chip* tpm; - tpm =3D files[fd].dev; + struct tpm_chip *tpm =3D file->dev; =20 buf->st_mode =3D O_RDWR; buf->st_uid =3D 0; @@ -1360,6 +1361,38 @@ int tpm_tis_posix_fstat(int fd, struct stat* buf) return 0; } =20 +static const 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, +}; + +static unsigned int ftype_tis; + +__attribute__((constructor)) +static void tpm_tis_initialize(void) +{ + ftype_tis =3D alloc_file_type(&tpm_tis_ops); +} + +int tpm_tis_open(struct tpm_chip *tpm) +{ + struct file *file; + + /* Silently prevent multiple opens */ + if ( tpm->fd !=3D -1 ) + return tpm->fd; + + 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 Sun May 5 09:56:36 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=1642322038; cv=none; d=zohomail.com; s=zohoarc; b=kDfbm1MXqK7FzPTS2OrIrHBQCy1FsePL7TNSHlqmddroyFCt1NSqKSiP1Li/9o+j6XycCmOWjZCnFGtTeY89C7RvPaDjYsT2mvyFYIFS92uQDfs7CCTrb8fbEyVmJKU+UWAHKNNaqsz9iRi8rRLB1qnJyjF/lms+D2kwx4GsGvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322038; 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=g38pTaT4/z9XKrWqRxaUROnYf4HhbDG2ikYR2ifx7WM=; b=RbcRzUQ38fSAMTD3NqfZsJs04+RkAtp/l4geDfmdjpRegBdB8HxEMHzpnXki/XagSPmn7L6hkouMDSOA9NHEIQqZDEuTf/KZbgq8FI0KF5v9EhWC3PKEdbIX/3f4/tubZL3Cj51oPWp0+5ui64kBw6CaGz4Kln7ITZcl5inROLc= 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 1642322038543670.9387943502092; Sun, 16 Jan 2022 00:33:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257824.443209 (Exim 4.92) (envelope-from ) id 1n90yn-0000au-0Z; Sun, 16 Jan 2022 08:33:37 +0000 Received: by outflank-mailman (output) from mailman id 257824.443209; Sun, 16 Jan 2022 08:33:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90ym-0000aI-RJ; Sun, 16 Jan 2022 08:33:36 +0000 Received: by outflank-mailman (input) for mailman id 257824; Sun, 16 Jan 2022 08:33:35 +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 1n90yk-0008IQ-UY for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:35 +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 fc522c0f-76a6-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:33:31 +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 8B1211F45F; Sun, 16 Jan 2022 08:33:31 +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 5D8631346A; Sun, 16 Jan 2022 08:33:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GPWRFVvY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:31 +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: fc522c0f-76a6-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322011; 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=g38pTaT4/z9XKrWqRxaUROnYf4HhbDG2ikYR2ifx7WM=; b=mRfbTabA5NNamgetFyP0/9CEZSIsACvFyE7wvMvi7WZQbEwd9I8EF3FzbslncBWJJXw88t DLVcFBNXUSK0SMfQT7JY/zVBW3SfGKCWOv4WiPgKw9RX1iX+6xlAMHtYrLQNsSdh4IBZua pBg3lOrmPtV/d5YYpTTkDsRcNV0nAJc= 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: [MINIOS PATCH v3 05/12] use alloc_file_type() and get_file_from_fd() in tpmfront Date: Sun, 16 Jan 2022 09:33:21 +0100 Message-Id: <20220116083328.26524-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322039508100006 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) --- include/lib.h | 3 +- include/tpmfront.h | 5 --- lib/sys.c | 23 ----------- tpmfront.c | 100 ++++++++++++++++++++++++++++++--------------- 4 files changed, 69 insertions(+), 62 deletions(-) diff --git a/include/lib.h b/include/lib.h index 9dfb4689..9b7eaae7 100644 --- a/include/lib.h +++ b/include/lib.h @@ -167,8 +167,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/include/tpmfront.h b/include/tpmfront.h index b7da50e3..a527371b 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 2fc81f20..39f51980 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -349,11 +348,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; @@ -402,10 +396,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; @@ -468,10 +458,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; @@ -524,11 +510,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); @@ -613,10 +594,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 0a2fefc5..13163ad6 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,11 @@ 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(struct file *file, const void *buf, size_t= count) { int rc; - struct tpmfront_dev* dev; - dev =3D files[fd].dev; + struct tpmfront_dev *dev =3D file->dev; =20 if(count =3D=3D 0) { return 0; @@ -566,14 +562,12 @@ 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(struct file *file, void *buf, size_t count) { int rc; uint8_t* dummybuf; size_t dummysz; - struct tpmfront_dev* dev; - - dev =3D files[fd].dev; + struct tpmfront_dev *dev =3D file->dev; =20 if(count =3D=3D 0) { return 0; @@ -588,29 +582,32 @@ 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(struct file *file, struct stat *buf) { uint8_t* dummybuf; size_t dummysz; int rc; - struct tpmfront_dev* dev =3D files[fd].dev; + 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 +623,44 @@ int tpmfront_posix_fstat(int fd, struct stat* buf) return 0; } =20 +static int tpmfront_close_fd(struct file *file) +{ + shutdown_tpmfront(file->dev); + + return 0; +} + +static const 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, +}; + +static unsigned int ftype_tpmfront; + +__attribute__((constructor)) +static void tpmfront_initialize(void) +{ + ftype_tpmfront =3D alloc_file_type(&tpmfront_ops); +} + +int tpmfront_open(struct tpmfront_dev *dev) +{ + struct file *file; + + /* Silently prevent multiple opens */ + if ( dev->fd !=3D -1 ) + return dev->fd; + + 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 Sun May 5 09:56:36 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=1642322040; cv=none; d=zohomail.com; s=zohoarc; b=Zhs5TnU2fdUmOyFiE/ATzqEMapArTqt3KJ7wO15W5V50mThaJ6KVp5Qf8x2AgiiZX/dpWUPPDUvmLDLsHt2di2QRrZxcZ1+Tx/hTNFD52BtGDj9TqtAq2eEvzyB4QEks1AzoJBwoE3MSFemFK29EH6ri8OH+7hfmWsS4XJSKVlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322040; 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=FFReguV4y++M9NUukSuxH+eG17KkgvbSsHOjbRhtUks=; b=OSqrhT3AiEyLoqfuxvd9q/axAi5uu8cQkT5n+NrvlmNfrU8tYEM5CnQUBWDdQxPZ9c3kgAh+n3RleDST+8Z5h8E+KHa1CW9eevUfUZ6FCHB+Fbs305BfzjPJQ8uo8hKCVxPAozWln6B8Qt/jykBuslw5pwTkztWwMkNqNFobi68= 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 1642322040175443.47437137667373; Sun, 16 Jan 2022 00:34:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257828.443236 (Exim 4.92) (envelope-from ) id 1n90yp-0001BE-Tv; Sun, 16 Jan 2022 08:33:39 +0000 Received: by outflank-mailman (output) from mailman id 257828.443236; Sun, 16 Jan 2022 08:33:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90yp-00018z-H2; Sun, 16 Jan 2022 08:33:39 +0000 Received: by outflank-mailman (input) for mailman id 257828; Sun, 16 Jan 2022 08:33:37 +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 1n90ym-0008IQ-Ui for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:37 +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 fc710686-76a6-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:33:31 +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 BB119219C8; Sun, 16 Jan 2022 08:33:31 +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 90E761346A; Sun, 16 Jan 2022 08:33:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WGg2IlvY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:31 +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: fc710686-76a6-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322011; 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=FFReguV4y++M9NUukSuxH+eG17KkgvbSsHOjbRhtUks=; b=Tr9a4POanzkbMhoSmBb9h3eLdK4XMXem0XTRAILtKVbPbd7bIfhWz0s/QaNk8tZqOsGTlo EVCVbE8P9WVFwY3Lik4axLUHqEHsO5egyd7uP/sHOKsqwJthNdpTdQzEDx0WjIkewfB7Yo 99Jd+/ggIcGKXO6YS2qbjKUch7gFsR8= 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: [MINIOS PATCH v3 06/12] use alloc_file_type() and get_file_from_fd() in blkfront Date: Sun, 16 Jan 2022 09:33:22 +0100 Message-Id: <20220116083328.26524-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322041243100017 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) --- 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 e3f42bef..ed902702 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) +static int blkfront_posix_rwop(struct file *file, uint8_t *buf, size_t cou= nt, + bool write) { - /* 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) -{ - struct blkfront_dev* dev =3D files[fd].dev; - off_t offset =3D files[fd].offset; + 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,24 @@ 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(struct file *file, void *buf, size_t nbytes) { - struct blkfront_dev* dev =3D files[fd].dev; + return blkfront_posix_rwop(file, buf, nbytes, false); +} + +static int blkfront_posix_write(struct file *file, const void *buf, size_t= nbytes) +{ + return blkfront_posix_rwop(file, (void *)buf, nbytes, true); +} + +static int blkfront_posix_fstat(struct file *file, struct stat *buf) +{ + struct blkfront_dev *dev =3D file->dev; =20 buf->st_mode =3D dev->info.mode; buf->st_uid =3D 0; @@ -728,4 +731,45 @@ int blkfront_posix_fstat(int fd, struct stat* buf) =20 return 0; } + +static int blkfront_close_fd(struct file *file) +{ + shutdown_blkfront(file->dev); + + return 0; +} + +static const 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, +}; + +static unsigned int ftype_blk; + +__attribute__((constructor)) +static void blkfron_initialize(void) +{ + ftype_blk =3D alloc_file_type(&blk_ops); +} + +int blkfront_open(struct blkfront_dev *dev) +{ + struct file *file; + + /* 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); + 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 3528af9d..7f84a0a2 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 9b7eaae7..2f472b00 100644 --- a/include/lib.h +++ b/include/lib.h @@ -166,8 +166,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/lib/sys.c b/lib/sys.c index 39f51980..90684335 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -343,11 +343,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; @@ -392,10 +387,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; @@ -455,10 +446,6 @@ off_t lseek(int fd, off_t offset, int whence) return ops->lseek(file, offset, whence); =20 switch(file->type) { -#ifdef CONFIG_BLKFRONT - case FTYPE_BLK: - break; -#endif case FTYPE_FILE: break; default: @@ -505,11 +492,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); @@ -591,10 +573,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; } @@ -710,7 +688,6 @@ static const char *const 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", }; @@ -896,7 +873,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 Sun May 5 09:56:36 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=1642322038; cv=none; d=zohomail.com; s=zohoarc; b=A+PWho7iZxMK2zyYsfLDahn5nFi0ZnIrFO+VUIUApybCSv9NYpQOzRfbuNOmalRpfgUWwUqGtD8rT/yiiwDmFVpmNx29N+uOKCdcSGkoYOxYJSkgxVD4v+vZ48kslS1yV4l1qOIodlOA/+0ctlAPKZVdHRxpL5SkEu++3nd1DUw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322038; 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=V/vC7tx78nDm4GqTKex/CmQNpmhFP/CrwSTFfFKDiV0=; b=W/dhY3ftCN9/5oLq3a8VcMAGcncRkruhxlonS+KLpYFvhcMTIH1hxIfpKc40obH1ODBwQkr1uYe3f+nenRMCkWpZLbh/D4RfXtV3Y8oOGT6DzLtPfSyyAktMWVIjNp1+NvXLpS21phkirvFGswRbC11KmwjLyY3Jbozox8TXUkU= 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 1642322038654855.9492261045165; Sun, 16 Jan 2022 00:33:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257835.443268 (Exim 4.92) (envelope-from ) id 1n90yt-0001sG-Nv; Sun, 16 Jan 2022 08:33:43 +0000 Received: by outflank-mailman (output) from mailman id 257835.443268; Sun, 16 Jan 2022 08:33:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90yt-0001oe-8s; Sun, 16 Jan 2022 08:33:43 +0000 Received: by outflank-mailman (input) for mailman id 257835; Sun, 16 Jan 2022 08:33:40 +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 1n90yp-0008IP-PN for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:39 +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 fcddc162-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:32 +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 00A211F3B2; Sun, 16 Jan 2022 08:33:32 +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 C14431346A; Sun, 16 Jan 2022 08:33:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SBf1LVvY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:31 +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: fcddc162-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322012; 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=V/vC7tx78nDm4GqTKex/CmQNpmhFP/CrwSTFfFKDiV0=; b=GNbSZjwy7POyyXYRYjJBwE0+AievuggavYIBPtCINlJ6RJj6rMv5rduHp2JCvUN/g40k/l msxIrrAuYJr2WFo75sNf6pGbDdMSyQgpvjV1YvM8k32Zl8rZ+P/7xJETUIZ8Dqe07LobjF C/1ZOSGWsyRMhepceTlQyAyubIgnM6s= 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: [MINIOS PATCH v3 07/12] use alloc_file_type() and get_file_from_fd() in netfront Date: Sun, 16 Jan 2022 09:33:23 +0100 Message-Id: <20220116083328.26524-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322039482100003 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) --- include/lib.h | 3 +-- include/netfront.h | 3 ++- lib/sys.c | 23 ---------------- netfront.c | 65 +++++++++++++++++++++++++++++++++++++++------- 4 files changed, 59 insertions(+), 35 deletions(-) diff --git a/include/lib.h b/include/lib.h index 2f472b00..b0d08807 100644 --- a/include/lib.h +++ b/include/lib.h @@ -165,8 +165,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/include/netfront.h b/include/netfront.h index ec641c80..75080c26 100644 --- a/include/netfront.h +++ b/include/netfront.h @@ -10,7 +10,8 @@ struct netfront_dev *init_netfront(char *nodename, char **ip); char *netfront_get_netmask(struct netfront_dev *dev); char *netfront_get_gateway(struct netfront_dev *dev); -void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len); +void netfront_xmit(struct netfront_dev *dev, const unsigned char *data, + int len); void shutdown_netfront(struct netfront_dev *dev); void suspend_netfront(void); void resume_netfront(void); diff --git a/lib/sys.c b/lib/sys.c index 90684335..44fe848c 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -309,17 +309,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; @@ -382,11 +371,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; @@ -487,11 +471,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); @@ -687,7 +666,6 @@ static const char *const 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", }; @@ -872,7 +850,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 76964514..164fdc66 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,53 @@ error: } =20 #ifdef HAVE_LIBC +static int netfront_read(struct file *file, void *buf, size_t nbytes) +{ + ssize_t ret; + + ret =3D netfront_receive(file->dev, buf, nbytes); + if ( ret <=3D 0 ) + { + errno =3D EAGAIN; + return -1; + } + + return ret; +} + +static int netfront_write(struct file *file, const void *buf, size_t nbyte= s) +{ + netfront_xmit(file->dev, buf, nbytes); + + return nbytes; +} + +static int netfront_close_fd(struct file *file) +{ + shutdown_netfront(file->dev); + + return 0; +} + +static const 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, +}; + +static unsigned int ftype_netfront; + +__attribute__((constructor)) +static void netfront_initialize(void) +{ + ftype_netfront =3D alloc_file_type(&netfront_ops); +} + int netfront_tap_open(char *nodename) { struct netfront_dev *dev; + struct file *file; =20 dev =3D init_netfront(nodename, NETIF_SELECT_RX, NULL, NULL); if (!dev) { @@ -574,9 +619,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 @@ -720,7 +766,7 @@ void init_rx_buffers(struct netfront_dev *dev) } =20 =20 -void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len) +void netfront_xmit(struct netfront_dev *dev, const unsigned char *data, in= t len) { int flags; struct netif_tx_request *tx; @@ -772,7 +818,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 +828,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 Sun May 5 09:56:36 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=1642322240; cv=none; d=zohomail.com; s=zohoarc; b=RtY8IiHNsXCK5u1uU6qyD5AU8nFl9g0y0KWgYBFWzMi6Lw5fHAssP3PcW8MOADHvSmeqtOaXGGymmD/x9FQaz+FlDFAJ6CzJ4RlWGfQzRIZ6pgdcsHYND5o7WOSNs3MfUsBdwNTZAN8JxBV3b/TuIVX7CTEPSQAsz9FxzDxtLLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322240; 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=EyEnGVB5vj2rXALZOQkxMfap/9vtF59SnM7EBGmKPBU=; b=PoUYyX7peE1bYU+PNmpGekOILliiI3aVGzj9aP0eJK5vWrjqj5mQxzZyuiwE4Wm8SJT40KveeJYJ+UiQ2W17XzbPszxcB4FweWuWitJbmYX8MC0U2lN9+syTvOkFOO12VK5HQilN79dwxj+f5/tHWfrf9DKUrI/xJvvyAsAOM9k= 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 1642322240153319.95108389613006; Sun, 16 Jan 2022 00:37:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257841.443322 (Exim 4.92) (envelope-from ) id 1n9122-0006Zf-BR; Sun, 16 Jan 2022 08:36:58 +0000 Received: by outflank-mailman (output) from mailman id 257841.443322; Sun, 16 Jan 2022 08:36:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n9122-0006ZI-4U; Sun, 16 Jan 2022 08:36:58 +0000 Received: by outflank-mailman (input) for mailman id 257841; Sun, 16 Jan 2022 08:36:56 +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 1n90ys-0008IP-Pp for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:42 +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 fcf64275-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:32 +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 27B76219A8; Sun, 16 Jan 2022 08:33:32 +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 EFD8113AB5; Sun, 16 Jan 2022 08:33:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8IJYOVvY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:31 +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: fcf64275-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322012; 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=EyEnGVB5vj2rXALZOQkxMfap/9vtF59SnM7EBGmKPBU=; b=XTt8ZgVkevEntWYLIy95AiISyMPJcQd+OeXPsM85X6QLSBshhnH7Lk7XZHaeT0mJOsl+bo VZbvoXtK6Y2pb/4KCflxof1UPEAEFsACyvVP9Bl59o2J2FQHjpF5U2kD96+bBON7wabze6 C5BGQKzQ1e+KX9SbXApJT2Q2RzCERNg= 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: [MINIOS PATCH v3 08/12] use alloc_file_type() and get_file_from_fd() in fbfront Date: Sun, 16 Jan 2022 09:33:24 +0100 Message-Id: <20220116083328.26524-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322241174100001 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) --- fbfront.c | 127 ++++++++++++++++++++++++++++++++++++++++++-------- include/lib.h | 4 +- lib/sys.c | 47 ------------------- 3 files changed, 108 insertions(+), 70 deletions(-) diff --git a/fbfront.c b/fbfront.c index 1e055fb0..360a9cf6 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,51 @@ close_kbdfront: } =20 #ifdef HAVE_LIBC +static int kbd_read(struct file *file, void *buf, size_t nbytes) +{ + 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(struct file *file) +{ + 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, +}; + +static unsigned int ftype_kbd; + +__attribute__((constructor)) +static void kbdfront_initialize(void) +{ + ftype_kbd =3D alloc_file_type(&kbd_ops); +} + int kbdfront_open(struct kbdfront_dev *dev) { - dev->fd =3D alloc_fd(FTYPE_KBD); + struct file *file; + + 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 +391,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 +418,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 +443,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 +746,51 @@ close_fbfront: } =20 #ifdef HAVE_LIBC +static int fbfront_read(struct file *file, void *buf, size_t nbytes) +{ + 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(struct file *file) +{ + shutdown_fbfront(file->dev); + + return 0; +} + +static const struct file_ops fb_ops =3D { + .name =3D "fb", + .read =3D fbfront_read, + .close =3D fbfront_close_fd, + .select_rd =3D select_read_flag, +}; + +static unsigned int ftype_fb; + +__attribute__((constructor)) +static void fbfront_initialize(void) +{ + ftype_fb =3D alloc_file_type(&fb_ops); +} + int fbfront_open(struct fbfront_dev *dev) { - dev->fd =3D alloc_fd(FTYPE_FB); + struct file *file; + + 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 b0d08807..b1beeed3 100644 --- a/include/lib.h +++ b/include/lib.h @@ -163,9 +163,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/lib/sys.c b/lib/sys.c index 44fe848c..db26fd2d 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -308,30 +308,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; @@ -471,16 +447,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: @@ -666,8 +632,6 @@ static const char *const 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 const char *get_type_name(unsigned int type) @@ -850,17 +814,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 Sun May 5 09:56:36 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=1642322287; cv=none; d=zohomail.com; s=zohoarc; b=AUemtDm0Cusrh3cIwsSr6DS65mG1NVKcj1XWWG6PONlsyCGb2z7A44gd330KRx2gAvZASqI/Ajn5gPzX9n5EOUlkFGua+LTfn7Ax19cTAVg7L7f9lWHpjvu18tTxLHZBmOxDZaPLcaBHzxGCe5Vktoq7IKenfX9ZAJvfPgFPw8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322287; 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=LVU0gEoX6rgZcZx+F07Qd6YUFiSDhtCjunERzqwuuYk=; b=MdOuAmmg6ObMaQvAksAFY79fBZczWwe5G/JJ9gRYnU4IWg9cHzIexSA/9GKp9Da+heYzZt5QkjDhNHnageHWBxIlioZeSGkdxfiSSThXnwD1dCe5BHLA5JpOCl3G7v9mXvm6YANehJyGjOQlAEf9iuoOOglx1hGxEAxHk9isy8Q= 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 1642322287014670.3217043797297; Sun, 16 Jan 2022 00:38:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257847.443336 (Exim 4.92) (envelope-from ) id 1n912o-0007GK-Jl; Sun, 16 Jan 2022 08:37:46 +0000 Received: by outflank-mailman (output) from mailman id 257847.443336; Sun, 16 Jan 2022 08:37:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n912o-0007GD-Ft; Sun, 16 Jan 2022 08:37:46 +0000 Received: by outflank-mailman (input) for mailman id 257847; Sun, 16 Jan 2022 08:37:45 +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 1n90yu-0008IP-Py for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:45 +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 fd1a925e-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:32 +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 5A1D7219C7; Sun, 16 Jan 2022 08:33:32 +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 2E8D01346A; Sun, 16 Jan 2022 08:33:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gPIjClzY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:32 +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: fd1a925e-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322012; 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=LVU0gEoX6rgZcZx+F07Qd6YUFiSDhtCjunERzqwuuYk=; b=kj5H3Kwbv0IQeztJ2dd0pWzgAEKjc2F6gZ1nJtUuQfy6YV6Cjl4u6ZTGGeKwgTo7EAVsDX ButBi2+MBU5DgfFtoLlRBAVhyGiq0dbQNegG0SPOxnAVadBQ5XZW+wBukIZ5YCu3/ECgWD ERv+eG/nVxiPO4IgDxOPcTj9GDOcYDo= 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: [MINIOS PATCH v3 09/12] use file_ops and get_file_from_fd() for console Date: Sun, 16 Jan 2022 09:33:25 +0100 Message-Id: <20220116083328.26524-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322289107100001 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 --- V3: - switch to struct file * parameter for callbacks - use __attribute__((constructor)) - make console_print() take a const pointer (Andrew Cooper) --- console/console.c | 2 +- console/xenbus.c | 112 +++++++++++++++++++++++++++++++++++++++++ console/xencons_ring.c | 6 +-- include/console.h | 7 ++- include/lib.h | 3 +- lib/sys.c | 87 ++++++++------------------------ 6 files changed, 144 insertions(+), 73 deletions(-) diff --git a/console/console.c b/console/console.c index af1a6dd3..68c8435e 100644 --- a/console/console.c +++ b/console/console.c @@ -76,7 +76,7 @@ void xencons_tx(void) #endif =20 =20 -void console_print(struct consfront_dev *dev, char *data, int length) +void console_print(struct consfront_dev *dev, const char *data, int length) { char *curr_char, saved_char; char copied_str[length+1]; diff --git a/console/xenbus.c b/console/xenbus.c index 05fc31c0..d8950454 100644 --- a/console/xenbus.c +++ b/console/xenbus.c @@ -192,3 +192,115 @@ void fini_consfront(struct consfront_dev *dev) { if (dev) free_consfront(dev); } + +#ifdef HAVE_LIBC +static int consfront_read(struct file *file, void *buf, size_t nbytes) +{ + int ret; + 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(struct file *file, const void *buf, size_t nbyte= s) +{ + int ret =3D 0, tot =3D nbytes; + + while ( nbytes > 0 ) + { + ret =3D xencons_ring_send(file->dev, buf, nbytes); + nbytes -=3D ret; + buf =3D (char *)buf + ret; + } + + return tot - nbytes; +} + +static int console_write(struct file *file, const void *buf, size_t nbytes) +{ + console_print(file->dev, buf, nbytes); + + return nbytes; +} + +static int consfront_close_fd(struct file *file) +{ + fini_consfront(file->dev); + + return 0; +} + +static int consfront_fstat(struct file *file, struct stat *buf) +{ + 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(struct file *file) +{ + return xencons_ring_avail(file->dev); +} + +static const 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, +}; + +const 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, +}; + +static unsigned int ftype_savefile; + +__attribute__((constructor)) +static void consfront_initialize(void) +{ + ftype_savefile =3D alloc_file_type(&savefile_ops); +} + +int open_consfront(char *nodename) +{ + struct consfront_dev *dev; + struct file *file; + + dev =3D init_consfront(nodename); + if ( !dev ) + return -1; + + dev->fd =3D alloc_fd(nodename ? ftype_savefile : FTYPE_CONSOLE); + 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 c348f3ce..efedf46b 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 0d7bf077..e76e4234 100644 --- a/include/console.h +++ b/include/console.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -77,7 +78,7 @@ void xencons_tx(void); =20 void get_console(void *p); void init_console(void); -void console_print(struct consfront_dev *dev, char *data, int length); +void console_print(struct consfront_dev *dev, const char *data, int length= ); void fini_consfront(struct consfront_dev *dev); void suspend_console(void); void resume_console(void); @@ -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 const 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 b1beeed3..e815e0a3 100644 --- a/include/lib.h +++ b/include/lib.h @@ -162,8 +162,7 @@ extern struct wait_queue_head event_queue; #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 struct file { diff --git a/lib/sys.c b/lib/sys.c index db26fd2d..74c82b2a 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -101,6 +101,9 @@ static const struct file_ops file_ops_none =3D { =20 static const 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(const struct file_ops *ops) @@ -212,31 +215,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) @@ -291,20 +289,6 @@ int read(int fd, void *buf, size_t nbytes) return ops->read(file, buf, nbytes); =20 switch (file->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); @@ -332,18 +316,6 @@ int write(int fd, const void *buf, size_t nbytes) return ops->write(file, buf, nbytes); =20 switch (file->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); @@ -446,12 +418,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: goto error; @@ -501,15 +467,8 @@ int fstat(int fd, struct stat *buf) return ops->fstat(file, buf); =20 switch (file->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; @@ -630,7 +589,6 @@ int closedir(DIR *dir) #if defined(LIBC_DEBUG) || defined(LIBC_VERBOSE) static const char *const file_types[] =3D { [FTYPE_NONE] =3D "none", - [FTYPE_CONSOLE] =3D "console", [FTYPE_SOCKET] =3D "socket", }; =20 @@ -799,21 +757,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 Sun May 5 09:56:36 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=1642322323; cv=none; d=zohomail.com; s=zohoarc; b=BJ+M8ntTqSe31RY2hQc9TQ/XfaWwNHzPElxqB4ls0BRc4OOphd+OPAoOgMBTHd+ormYYitVNUyvY9togBs0DyXbcE8rFj1qfoyGv90cPubVdhcvzP6qnJ5OHW9ABm7f8fw+yeh+ke+qbW0DBVAFN73ow8w2WYJI/Xw88Ef5c9n0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322323; 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=eDN7dygQtWpp4PtzeecJTsg/5tatNDTI+Yj25CuIEDI=; b=d0Pd/OXGAlSLq0iQkJ/V5JX+9rryvyrYjxhYK/FS6jMZMPRC2g3lYvk8PiyoMmKJP4I6fxXhi1aUuEzEoKKJmW3AUOcLR3Jho8gQAF7pZgiQYxuirE3DB5iEL6PPLRGHcjrrrOtH4scYYTM4G3EMtqW++xpk7AhXZhMR0K2RAJw= 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 1642322322993240.06215541838492; Sun, 16 Jan 2022 00:38:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257853.443347 (Exim 4.92) (envelope-from ) id 1n913Q-0007r0-Ru; Sun, 16 Jan 2022 08:38:24 +0000 Received: by outflank-mailman (output) from mailman id 257853.443347; Sun, 16 Jan 2022 08:38:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n913Q-0007qt-Oi; Sun, 16 Jan 2022 08:38:24 +0000 Received: by outflank-mailman (input) for mailman id 257853; Sun, 16 Jan 2022 08:38:22 +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 1n90yw-0008IP-Q6 for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:46 +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 fd3aa52c-76a6-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:33:32 +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 95034219C9; Sun, 16 Jan 2022 08:33:32 +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 5FFD213AB5; Sun, 16 Jan 2022 08:33:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6JszFlzY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:32 +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: fd3aa52c-76a6-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322012; 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=eDN7dygQtWpp4PtzeecJTsg/5tatNDTI+Yj25CuIEDI=; b=mDts5epmvwpbSWm2VbNo8wTury2KLFycD4WQVRdkLIDFtaCyxTI/cfExusLRtx2GeKgMD3 G2myLGJ94Try9iy8cDOmyw8R5WPkWGp0DikTQw6NSVIzhzKIEUgYvBNHXsI8G5oe5Zo+FZ JgndfXyroO35LPaTSHY1+L16C2JROu4= 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: [MINIOS PATCH v3 10/12] add struct file_ops for file type socket Date: Sun, 16 Jan 2022 09:33:26 +0100 Message-Id: <20220116083328.26524-11-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322323811100001 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 --- V3: - switch to struct file * parameter for callbacks --- lib/sys.c | 148 +++++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 84 deletions(-) diff --git a/lib/sys.c b/lib/sys.c index 74c82b2a..538d6e7b 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -99,11 +99,67 @@ static const struct file_ops file_ops_none =3D { .name =3D "none", }; =20 +#ifdef HAVE_LWIP +static int socket_read(struct file *file, void *buf, size_t nbytes) +{ + return lwip_read(file->fd, buf, nbytes); +} + +static int socket_write(struct file *file, const void *buf, size_t nbytes) +{ + return lwip_write(file->fd, buf, nbytes); +} + +static int close_socket_fd(struct file *file) +{ + return lwip_close(file->fd); +} + +static int socket_fstat(struct file *file, 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(struct file *file, int cmd, va_list args) +{ + long arg; + + 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("socket fcntl(fd, %d, %lx/%lo)\n", cmd, arg, arg); + errno =3D ENOSYS; + return -1; +} + +static const 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 const 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(const struct file_ops *ops) @@ -288,15 +344,6 @@ int read(int fd, void *buf, size_t nbytes) if ( ops->read ) return ops->read(file, buf, nbytes); =20 - switch (file->type) { -#ifdef HAVE_LWIP - case FTYPE_SOCKET: - return lwip_read(files[fd].fd, buf, nbytes); -#endif - default: - break; - } - error: printk("read(%d): Bad descriptor\n", fd); errno =3D EBADF; @@ -315,15 +362,6 @@ int write(int fd, const void *buf, size_t nbytes) if ( ops->write ) return ops->write(file, buf, nbytes); =20 - switch (file->type) { -#ifdef HAVE_LWIP - case FTYPE_SOCKET: - return lwip_write(files[fd].fd, (void*) buf, nbytes); -#endif - default: - break; - } - error: printk("write(%d): Bad descriptor\n", fd); errno =3D EBADF; @@ -406,24 +444,10 @@ int close(int fd) ops =3D get_file_ops(file->type); printk("close(%d)\n", fd); if ( ops->close ) - { res =3D ops->close(file); - goto out; - } - - switch (file->type) { - default: - break; -#ifdef HAVE_LWIP - case FTYPE_SOCKET: - res =3D lwip_close(files[fd].fd); - break; -#endif - case FTYPE_NONE: - goto error; - } + else if ( file->type =3D=3D FTYPE_NONE ) + goto error; =20 - out: memset(files + fd, 0, sizeof(struct file)); BUILD_BUG_ON(FTYPE_NONE !=3D 0); =20 @@ -466,21 +490,6 @@ int fstat(int fd, struct stat *buf) if ( ops->fstat ) return ops->fstat(file, buf); =20 - switch (file->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; - } - error: printk("statf(%d): Bad descriptor\n", fd); errno =3D EBADF; @@ -538,21 +547,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) @@ -586,23 +583,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 *const file_types[] =3D { - [FTYPE_NONE] =3D "none", - [FTYPE_SOCKET] =3D "socket", -}; - -static const 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) { @@ -613,7 +593,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; \ } \ } \ @@ -647,7 +627,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; } @@ -809,7 +789,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 Sun May 5 09:56:37 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=1642322038; cv=none; d=zohomail.com; s=zohoarc; b=fRsrZUItfwTAliC6BzF+cQZ3Y7j394lK9h8rXCEW4pOXc9AqbS02GxVppKRKXRUOqT7lP07X/Rep4pcAtBEONTQr70WejcOtFCrCFpmx4t2Zp6Ymd0ZDgbqi3XaXLr8/7TmujCNFspXfOc6Dwl4gpHlIlNvZWneozokJp4L8DhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322038; 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=sE2ME2yl3H92H6CBanzgJAMhj6JgWCncjlIia2KP7ss=; b=eI/PhsfCDN7dU+sMdISsHrWUenbeC4/++187lEQeU5GdBduSW/f/NkwDf7kM+t4cRnc3PdRuRhLHJW3SVkcM9LyX2WSPF4DLj5L3TWa3RsJhDr4zZ6vYv0qLZyOzIW2J7a8Wy3FX0WqgZdIuYLZO6uZCMFxJRwYedwv9iUzx8xw= 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 1642322038353751.150035623892; Sun, 16 Jan 2022 00:33:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257833.443261 (Exim 4.92) (envelope-from ) id 1n90yt-0001g7-3g; Sun, 16 Jan 2022 08:33:43 +0000 Received: by outflank-mailman (output) from mailman id 257833.443261; Sun, 16 Jan 2022 08:33:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90ys-0001b6-4l; Sun, 16 Jan 2022 08:33:42 +0000 Received: by outflank-mailman (input) for mailman id 257833; Sun, 16 Jan 2022 08:33:39 +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 1n90yo-0008IQ-Vd for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:38 +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 fd053218-76a6-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:33:32 +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 B7067219C8; Sun, 16 Jan 2022 08:33:32 +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 8DEF31346A; Sun, 16 Jan 2022 08:33:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oIN0IVzY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:32 +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: fd053218-76a6-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322012; 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=sE2ME2yl3H92H6CBanzgJAMhj6JgWCncjlIia2KP7ss=; b=sVHsnUB42fimeyRpdY0mC4n6za+sNhiKzqnZBmPUpban2shE3YrSiIanyFrFGlGvp/uomA PaodsxbHpsaWadBuoc4vldB73m98rAZLpc0HCIW4DYCYMBw+uwEQOh2WhQXYApaANnxCxH 4R74J0fouMHpIQVY8p6V752MtpM3Vjw= 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: [MINIOS PATCH v3 11/12] add struct file_ops for FTYPE_FILE Date: Sun, 16 Jan 2022 09:33:27 +0100 Message-Id: <20220116083328.26524-12-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322039481100001 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 538d6e7b..7f3dc4e4 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -99,6 +99,11 @@ static const struct file_ops file_ops_none =3D { .name =3D "none", }; =20 +static const struct file_ops file_file_ops =3D { + .name =3D "file", + .lseek =3D lseek_default, +}; + #ifdef HAVE_LWIP static int socket_read(struct file *file, void *buf, size_t nbytes) { @@ -157,6 +162,7 @@ static const 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 @@ -415,16 +421,9 @@ off_t lseek(int fd, off_t offset, int whence) if ( ops->lseek ) return ops->lseek(file, offset, whence); =20 - switch(file->type) { - case FTYPE_FILE: - break; - default: - /* Not implemented for this filetype */ - errno =3D ESPIPE; - return (off_t) -1; - } - - return lseek_default(file, 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 Sun May 5 09:56:37 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=1642322041; cv=none; d=zohomail.com; s=zohoarc; b=PfK9xnOO3lvTkda53Q9tvYg86W4lMkW0/WZ6rplw6HYbhMo2alTEviEIvICEXOGXsrTle6MNmeE+H+03fM4VV0ig9QH5XANDngF6TihgR2bP8YS0oAXtyfzQY/QXU9XjEORXUxiVbKZxCkQg/5ROAPTiiFVbrfbNyVY0UeZuY34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642322041; 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=oOgPnC87mBVmQF7jR57eu5ZPcD/ugF9PvO1qiNK3tw0=; b=WZdCZXT3y+i1kYnLIXlkWYS1rr7uV3x1q+yZP6HOkvNWHwyfOyRsp95RmDvtSNFmqXbMbY0Wsj/bWjLCaTZkZ6EOQk+48+1xk4qRub+JA51AImrgdo619zKxxTpDQNO33ZeZ0q86VRvWEh4EUxMDk6PGJ+hlwfsj4u9G4X7xBro= 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 1642322041699912.1898047686774; Sun, 16 Jan 2022 00:34:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257838.443286 (Exim 4.92) (envelope-from ) id 1n90yw-0002JR-85; Sun, 16 Jan 2022 08:33:46 +0000 Received: by outflank-mailman (output) from mailman id 257838.443286; Sun, 16 Jan 2022 08:33:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90yv-0002Ef-7M; Sun, 16 Jan 2022 08:33:45 +0000 Received: by outflank-mailman (input) for mailman id 257838; Sun, 16 Jan 2022 08:33:41 +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 1n90yq-0008IQ-VW for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:33:40 +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 fd22d509-76a6-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:33:32 +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 E6C091F3B3; Sun, 16 Jan 2022 08:33:32 +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 BCFAB1346A; Sun, 16 Jan 2022 08:33:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EPjeLFzY42HyFQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:33:32 +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: fd22d509-76a6-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642322012; 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=oOgPnC87mBVmQF7jR57eu5ZPcD/ugF9PvO1qiNK3tw0=; b=HdBkVf2IlC6eWGmvrIixjb+2K/YwN1MUNDEScGcmGfxlV4b5RnkNiXoNxsQ5AZohqT2jFe +feJmN4FboDawfwO5jShMtHnttg1SpDpZmcS68zURnwstJxl4Smf2F8Zlp2AhoO4zFJjPi rDf7PtjLkmYTgBg3u82uLB3XHJHEF/w= 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: [MINIOS PATCH v3 12/12] make files array private to sys.c Date: Sun, 16 Jan 2022 09:33:28 +0100 Message-Id: <20220116083328.26524-13-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116083328.26524-1-jgross@suse.com> References: <20220116083328.26524-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642322043318100019 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 e815e0a3..bec99646 100644 --- a/include/lib.h +++ b/include/lib.h @@ -175,8 +175,6 @@ struct file { }; }; =20 -extern struct file files[]; - struct file_ops { const char *name; int (*read)(struct file *file, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index 7f3dc4e4..8f8a3de2 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