From nobody Mon May 6 14:18:17 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=1642315585; cv=none; d=zohomail.com; s=zohoarc; b=LEXMOvgUL1bqi2WZ8yJkK//9B1+oeXYWRyW0Fq60bELXwGN6FCviuRIRGsM+N7vv+OKm4ZQyL6TIgPSLx2lkHTxcI7ynjZveUPRkT/wIZUH7eEG/uy+jXLh+k8/goXNg+JA29LA3gAePBpvC7S2LL3gWEohuqp4HXw1vb4xqyo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642315585; 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=3GoDjpDXFuZrudyOquKeoDi2JAufp1li+iMTg9O8+0U=; b=iAcmqyjzFkE1pYU98xFduh9r9CQ95j33lOwjhiGjdh77JGi8aTjwpgSw+wAV3h/CCZzp2aYhGXAt3quaB8uQHKWhXGYDU0nwxC26oMvB38zCaJI94SoZO0T5rwbTzz672C7RIISZgKgV6McDFfan5A09nf/xnz5F6yeX+xD9S4M= 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 1642315585384516.6197371169112; Sat, 15 Jan 2022 22:46:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257775.443044 (Exim 4.92) (envelope-from ) id 1n8zIF-00006f-Kv; Sun, 16 Jan 2022 06:45:35 +0000 Received: by outflank-mailman (output) from mailman id 257775.443044; Sun, 16 Jan 2022 06:45:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n8zIF-00005S-Gm; Sun, 16 Jan 2022 06:45:35 +0000 Received: by outflank-mailman (input) for mailman id 257775; Sun, 16 Jan 2022 06:45:34 +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 1n8zIE-0008SI-9T for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 06:45:34 +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 e55a6a37-7697-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 07:45: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 F02511F3AF; Sun, 16 Jan 2022 06:45:29 +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 BA9E013ABD; Sun, 16 Jan 2022 06:45:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gKtILAm/42H0eQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 06:45:29 +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: e55a6a37-7697-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642315529; 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=3GoDjpDXFuZrudyOquKeoDi2JAufp1li+iMTg9O8+0U=; b=LOLd7RxCvyVRaao+x4dTavf06lBa9kyEh5im5XCdUCSuA+4oMDHyguqmMrkp+9SoR7N1ny EgXotHgErhIXkGwLLlK6Bf66WGUiAbXKimysZhqnLadPjC/9te7GatmnAuW2clV8LHOfQ+ inm1PXlURZyxTEfMN3BUJki/amJ8Ur4= 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 1/5] introduce get_file_from_fd() Date: Sun, 16 Jan 2022 07:45:23 +0100 Message-Id: <20220116064527.23519-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116064527.23519-1-jgross@suse.com> References: <20220116064527.23519-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642315586825100001 Content-Type: text/plain; charset="utf-8" Exporting the files[] array especially for components outside the mini-os source tree is limiting the ability to change any file handling in mini-os. Introduce a new function get_file_from_fd() to return the struct file pointer (or NULL) for a given file descriptor. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V3: - use ARRAY_SIZE() for boundary check (Andrew Cooper) --- include/lib.h | 1 + lib/sys.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/lib.h b/include/lib.h index 91364ba7..7a0546bd 100644 --- a/include/lib.h +++ b/include/lib.h @@ -198,6 +198,7 @@ struct file { =20 extern struct file files[]; =20 +struct file *get_file_from_fd(int fd); int alloc_fd(enum fd_type type); void close_all_files(void); extern struct thread *main_thread; diff --git a/lib/sys.c b/lib/sys.c index 6f2b026d..9a03875c 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -98,6 +98,14 @@ struct file files[NOFILE] =3D { { .type =3D FTYPE_CONSOLE }, /* stderr */ }; =20 +struct file *get_file_from_fd(int fd) +{ + if ( fd < 0 || fd >=3D ARRAY_SIZE(files) ) + return NULL; + + return (files[fd].type =3D=3D FTYPE_NONE) ? NULL : files + fd; +} + DECLARE_WAIT_QUEUE_HEAD(event_queue); =20 int alloc_fd(enum fd_type type) --=20 2.26.2 From nobody Mon May 6 14:18:17 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=1642315584; cv=none; d=zohomail.com; s=zohoarc; b=OpumlIvAWzxF7uo7H5wED2GpMBqHEmmmTZZ9DYNrQwp1vKUhkzvSJ1d1QCvNfIrUFUF9wQf0T3st5AX5HgIw4nwFPSUaswVxcSLmgYR33ZM9a7itYjjr666ROcU1X4fWA1FnbEZiNHR1rplDetI7D8sF2JHgru7Vso/69Urff7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642315584; 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=7gNDOfInVfcNlQrXw2pw9v+H3MpjcRV3L7PS0stFBOo=; b=h8qX4k2wYPvPZZi5oSrCSZkIDUG6y0WwvaukE42RENACpH1PNlilUil3vYAlsqAwKDRSTul3kuQwVamuUDtiYANm8tWX7HxwU2Qkhamiogm0oPIqed0FHT5/0pDiLFidAzuUDLRGgMteus13QfOloRA3PzLEyjOLri9wRsO2xnw= 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 1642315584200932.1067629728294; Sat, 15 Jan 2022 22:46:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257774.443041 (Exim 4.92) (envelope-from ) id 1n8zIF-00005O-G9; Sun, 16 Jan 2022 06:45:35 +0000 Received: by outflank-mailman (output) from mailman id 257774.443041; Sun, 16 Jan 2022 06:45:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n8zIF-00004q-8a; Sun, 16 Jan 2022 06:45:35 +0000 Received: by outflank-mailman (input) for mailman id 257774; Sun, 16 Jan 2022 06:45: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 1n8zIE-0008SH-0d for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 06:45:34 +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 e56722e7-7697-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 07:45: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 2085E1F3B2; Sun, 16 Jan 2022 06:45: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 EABF313350; Sun, 16 Jan 2022 06:45:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8BQdOAm/42H0eQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 06:45:29 +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: e56722e7-7697-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642315530; 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=7gNDOfInVfcNlQrXw2pw9v+H3MpjcRV3L7PS0stFBOo=; b=Gq18xKWfycegxkOc2K08BzGK4gxRqZRSeaKgjvUjTDmZJSEaYFFdNxPROi6msHdvphQ/kY OChWev3wte86QRL8c4LInH5R/HDNveeIlTzGJrTGbrHUDoS8uGs0lr5/IczUhyoV/N8P3I vBSB+0fqlXd/qp+S6fLBklbsEaH7UzY= 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 2/5] reset file type in close() in one place only Date: Sun, 16 Jan 2022 07:45:24 +0100 Message-Id: <20220116064527.23519-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116064527.23519-1-jgross@suse.com> References: <20220116064527.23519-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642315586833100003 Content-Type: text/plain; charset="utf-8" Today the file type in struct file is set to FTYPE_NONE for each file type individually. Do that at the end of close() handling for all types. While at it wipe the complete struct file, too, in order to avoid old data creeping into a new allocated struct file. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - new patch V3: - add error handling (Andrew Cooper) - use BUILD_BUG_ON() (Andrew Cooper) --- lib/sys.c | 56 ++++++++++++++++++++++++++++--------------------------- lib/xs.c | 1 - 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/sys.c b/lib/sys.c index 9a03875c..7df77cc6 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -265,7 +265,7 @@ int read(int fd, void *buf, size_t nbytes) return ret; } #ifdef HAVE_LWIP - case FTYPE_SOCKET: + case FTYPE_SOCKET: return lwip_read(files[fd].fd, buf, nbytes); #endif #ifdef CONFIG_NETFRONT @@ -424,84 +424,86 @@ int fsync(int fd) { =20 int close(int fd) { + int res =3D 0; + + if ( fd < 0 || fd >=3D ARRAY_SIZE(files) ) + goto error; + printk("close(%d)\n", fd); switch (files[fd].type) { default: - files[fd].type =3D FTYPE_NONE; - return 0; + break; #ifdef CONFIG_XENBUS case FTYPE_XENBUS: xs_daemon_close((void*)(intptr_t) fd); - return 0; + break; #endif #ifdef HAVE_LWIP - case FTYPE_SOCKET: { - int res =3D lwip_close(files[fd].fd); - files[fd].type =3D FTYPE_NONE; - return res; - } + case FTYPE_SOCKET: + res =3D lwip_close(files[fd].fd); + break; #endif #ifdef CONFIG_LIBXENCTRL case FTYPE_XC: minios_interface_close_fd(fd); - return 0; + break; #endif #ifdef CONFIG_LIBXENEVTCHN case FTYPE_EVTCHN: minios_evtchn_close_fd(fd); - return 0; + break; #endif #ifdef CONFIG_LIBXENGNTTAB case FTYPE_GNTMAP: minios_gnttab_close_fd(fd); - return 0; + break; #endif #ifdef CONFIG_NETFRONT case FTYPE_TAP: shutdown_netfront(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif #ifdef CONFIG_BLKFRONT case FTYPE_BLK: shutdown_blkfront(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif #ifdef CONFIG_TPMFRONT case FTYPE_TPMFRONT: shutdown_tpmfront(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif #ifdef CONFIG_TPM_TIS case FTYPE_TPM_TIS: shutdown_tpm_tis(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif #ifdef CONFIG_KBDFRONT case FTYPE_KBD: shutdown_kbdfront(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif #ifdef CONFIG_FBFRONT case FTYPE_FB: shutdown_fbfront(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif #ifdef CONFIG_CONSFRONT case FTYPE_SAVEFILE: case FTYPE_CONSOLE: fini_consfront(files[fd].dev); - files[fd].type =3D FTYPE_NONE; - return 0; + break; #endif case FTYPE_NONE: - break; + goto error; } + + memset(files + fd, 0, sizeof(struct file)); + BUILD_BUG_ON(FTYPE_NONE !=3D 0); + + return res; + + error: printk("close(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; diff --git a/lib/xs.c b/lib/xs.c index 0459f52f..4af0f960 100644 --- a/lib/xs.c +++ b/lib/xs.c @@ -35,7 +35,6 @@ void xs_daemon_close(struct xs_handle *h) next =3D event->next; free(event); } - files[fd].type =3D FTYPE_NONE; } =20 int xs_fileno(struct xs_handle *h) --=20 2.26.2 From nobody Mon May 6 14:18:17 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=1642315585; cv=none; d=zohomail.com; s=zohoarc; b=SifI0TXPI9yOxMGWFOKC2jDioJwMKbnIzUkPty73aibL1MMR6QiN+yWbTjT7IXNl3Zyf6TOn/d5Tge8kjGbDGaNhw8Z4jUUSzJTGPuC0zwLdbcKL2ITzpEylIM6vZrf2fthQxrDFVa1A3tN9YsS1YVuyA3YNi2ZBtDnZWXqiDNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642315585; 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=ETpovp+31TFjCpvLCv0O3rPi8bZ/B9q/oQBK6QgCQZw=; b=cNVllHnxzcQMDiSp6SocKn0V++vsIx7JoISlyseNGliz2g/4ax7vu4reh8VzwfNC/AU2HkaektjSZAEOw8NZNB6Dy8jjFvhpWHJhVtWrFfUX6oc/XI3tmFMc64aS0mc9NLBWocj6ZJXia2WYoZRFXSX2dorSFbp640FL8irChTY= 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 164231558540151.394552168031964; Sat, 15 Jan 2022 22:46:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257778.443071 (Exim 4.92) (envelope-from ) id 1n8zII-0000fM-26; Sun, 16 Jan 2022 06:45:38 +0000 Received: by outflank-mailman (output) from mailman id 257778.443071; Sun, 16 Jan 2022 06:45:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n8zIH-0000fF-Sr; Sun, 16 Jan 2022 06:45:37 +0000 Received: by outflank-mailman (input) for mailman id 257778; Sun, 16 Jan 2022 06:45: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 1n8zIF-0008SH-TN for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 06:45:36 +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 e585290c-7697-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 07:45: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 50CC41F45F; Sun, 16 Jan 2022 06:45: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 26CC413350; Sun, 16 Jan 2022 06:45:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YGkkCAq/42H0eQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 06:45: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: e585290c-7697-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642315530; 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=ETpovp+31TFjCpvLCv0O3rPi8bZ/B9q/oQBK6QgCQZw=; b=UiJJ71mN31xttAy/iMQhq68XNaZdnpgNvD0TzGtyyO2EIE3iPFXgib1W9+yJWPQSQ/oQox I2FJmPbZOOf+bLTHJVTQD9uDVdJQ6lX8BX0dKtncWtSZhebT+NAAs/JbZfgarwrp0xR/6Z 8RvYqQpo/1FF0GFIjzA0ytbkppLHLfk= 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 3/5] remove file type FTYPE_XC Date: Sun, 16 Jan 2022 07:45:25 +0100 Message-Id: <20220116064527.23519-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116064527.23519-1-jgross@suse.com> References: <20220116064527.23519-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642315586835100005 Content-Type: text/plain; charset="utf-8" The only reason for the file type FTYPE_XC has been gone long time ago: it was needed for xc_map_foreign_bulk(), which has been switched to use libxenforeignmemory and doesn't need this special file any more. So remove everything related to FTYPE_XC. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - new patch V3: - moved patch in series (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 | 1 - lib/sys.c | 13 ------------- 6 files changed, 18 deletions(-) diff --git a/Config.mk b/Config.mk index 5e660891..1e083881 100644 --- a/Config.mk +++ b/Config.mk @@ -197,7 +197,6 @@ CONFIG-n +=3D CONFIG_PARAVIRT endif # Support legacy CONFIG_XC value CONFIG_XC ?=3D $(libc) -CONFIG-$(CONFIG_XC) +=3D CONFIG_LIBXENCTRL CONFIG-$(CONFIG_XC) +=3D CONFIG_LIBXENEVTCHN CONFIG-$(CONFIG_XC) +=3D CONFIG_LIBXENGNTTAB =20 diff --git a/arch/x86/testbuild/all-no b/arch/x86/testbuild/all-no index 7972ecd5..d6fc2608 100644 --- a/arch/x86/testbuild/all-no +++ b/arch/x86/testbuild/all-no @@ -13,7 +13,6 @@ CONFIG_FBFRONT =3D n CONFIG_KBDFRONT =3D n CONFIG_CONSFRONT =3D n CONFIG_XENBUS =3D n -CONFIG_LIBXENCTRL =3D n CONFIG_LIBXENEVTCHN =3D n CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n diff --git a/arch/x86/testbuild/all-yes b/arch/x86/testbuild/all-yes index bc8eea57..98bbfebf 100644 --- a/arch/x86/testbuild/all-yes +++ b/arch/x86/testbuild/all-yes @@ -16,7 +16,6 @@ CONFIG_XENBUS =3D y CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y # The following are special: they need support from outside -CONFIG_LIBXENCTRL =3D n 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 f72123b5..06032004 100644 --- a/arch/x86/testbuild/newxen-yes +++ b/arch/x86/testbuild/newxen-yes @@ -17,7 +17,6 @@ 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_LIBXENCTRL =3D n CONFIG_LIBXENEVTCHN =3D n CONFIG_LIBXENGNTTAB =3D n CONFIG_LWIP =3D n diff --git a/include/lib.h b/include/lib.h index 7a0546bd..7ca90768 100644 --- a/include/lib.h +++ b/include/lib.h @@ -159,7 +159,6 @@ enum fd_type { FTYPE_CONSOLE, FTYPE_FILE, FTYPE_XENBUS, - FTYPE_XC, FTYPE_EVTCHN, FTYPE_GNTMAP, FTYPE_SOCKET, diff --git a/lib/sys.c b/lib/sys.c index 7df77cc6..a24687b7 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -87,7 +87,6 @@ } =20 #define NOFILE 32 -extern void minios_interface_close_fd(int fd); extern void minios_evtchn_close_fd(int fd); extern void minios_gnttab_close_fd(int fd); =20 @@ -443,11 +442,6 @@ int close(int fd) res =3D lwip_close(files[fd].fd); break; #endif -#ifdef CONFIG_LIBXENCTRL - case FTYPE_XC: - minios_interface_close_fd(fd); - break; -#endif #ifdef CONFIG_LIBXENEVTCHN case FTYPE_EVTCHN: minios_evtchn_close_fd(fd); @@ -651,7 +645,6 @@ static const char file_types[] =3D { [FTYPE_NONE] =3D 'N', [FTYPE_CONSOLE] =3D 'C', [FTYPE_XENBUS] =3D 'S', - [FTYPE_XC] =3D 'X', [FTYPE_EVTCHN] =3D 'E', [FTYPE_SOCKET] =3D 's', [FTYPE_TAP] =3D 'T', @@ -1383,12 +1376,6 @@ void *mmap(void *start, size_t length, int prot, int= flags, int fd, off_t offset =20 if (fd =3D=3D -1) return map_zero(n, 1); -#ifdef CONFIG_LIBXENCTRL - else if (files[fd].type =3D=3D FTYPE_XC) { - unsigned long zero =3D 0; - return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, NULL, 0); - } -#endif else if (files[fd].type =3D=3D FTYPE_MEM) { unsigned long first_mfn =3D offset >> PAGE_SHIFT; return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, NULL, _PAGE= _PRESENT|_PAGE_RW); --=20 2.26.2 From nobody Mon May 6 14:18:17 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=1642315586; cv=none; d=zohomail.com; s=zohoarc; b=kByv/PasWLLEEAA9ZrJ9Icf+5tf0nF439zu5UKLCoxQDe4kB4pxkJvnxOezb+ZkdeGMm+Bl55NZ1xU3my9RT558pamjlkI7xprgiuAxw4ZBQ1K5bgroqnvIF8L50Vm6yVo/N29WqtEyzUVXYnaocPHF4le69OZjLyoo0L/L9CV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642315586; 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=SkNjxyCrVquhfa9HVdl9OpDQbBK9fSye710YsOCgA5k=; b=bofAQt8Xa03R08sw+L9MS3pjcS6ILhPLL2DI4YPKZdodPRBQQqZQBuYRaOQ7M6buclfC0xAtA/kRCwNtI0YQSJbo/qyk5hj7NTcmSfusQKFteFnzIe1x0LQ3r93pKpMH1cPV6yGk3zdv+FJK/+8g4oU28hAIH3+qdh/MwrHBlTo= 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 1642315586782993.3538812769704; Sat, 15 Jan 2022 22:46:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257782.443107 (Exim 4.92) (envelope-from ) id 1n8zIL-0001WY-KY; Sun, 16 Jan 2022 06:45:41 +0000 Received: by outflank-mailman (output) from mailman id 257782.443107; Sun, 16 Jan 2022 06:45: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 1n8zIL-0001VS-Dn; Sun, 16 Jan 2022 06:45:41 +0000 Received: by outflank-mailman (input) for mailman id 257782; Sun, 16 Jan 2022 06:45: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 1n8zIJ-0008SI-4n for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 06:45:39 +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 e5a49238-7697-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 07:45: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 86B7F219C7; Sun, 16 Jan 2022 06:45: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 57CAB13350; Sun, 16 Jan 2022 06:45:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qB8QFAq/42H0eQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 06:45: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: e5a49238-7697-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642315530; 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=SkNjxyCrVquhfa9HVdl9OpDQbBK9fSye710YsOCgA5k=; b=byi+k86lKAlwts0BB/kn4fLt+/fUfhHyXnjWpmb29k86L6d3Wzq7iFCUOZMhp4HIfN68yF EVYMu+uQl+/iNqzSM3xIm1YM5YeV1YXvpa1/0QNCjoBurhvksv9w2s4txmrLcHjdIIU4np thDFnRVXY0ql92+APK8/YV5uN9B/JuI= 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 4/5] use function vectors instead of switch for file operations Date: Sun, 16 Jan 2022 07:45:26 +0100 Message-Id: <20220116064527.23519-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116064527.23519-1-jgross@suse.com> References: <20220116064527.23519-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642315588349100011 Content-Type: text/plain; charset="utf-8" Introduce file type specific function vectors for all the needed file operations which are file type specific in order to prepare replacing the large switch statements in each generic file function. Add a function to allocate a new file type dynamically in order to prepare removing direct dependencies to external components in the future. For this reason switch the file type from an enum to an unsigned int. Prepare removal of some statically defines file types by putting them at the end of the defined list. Change the debug output for the file type from a single character to a string in order to support a future removal of the file_types[] array. Provide some functions useful for file_ops in future patches. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - new patch V3: - drop typedefs for callbacks (Andrew Cooper) - const (Andrew Cooper) - drop loop from alloc_file_type() (Andrew Cooper) - switch to struct file * as first parameter of callbacks (Andrew Cooper) --- include/lib.h | 57 +++++++---- lib/sys.c | 268 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 263 insertions(+), 62 deletions(-) diff --git a/include/lib.h b/include/lib.h index 7ca90768..44696806 100644 --- a/include/lib.h +++ b/include/lib.h @@ -66,6 +66,7 @@ =20 #ifdef HAVE_LIBC #include +#include #include #include #else @@ -154,23 +155,23 @@ do { = \ void sanity_check(void); =20 #ifdef HAVE_LIBC -enum fd_type { - FTYPE_NONE =3D 0, - FTYPE_CONSOLE, - FTYPE_FILE, - FTYPE_XENBUS, - FTYPE_EVTCHN, - FTYPE_GNTMAP, - FTYPE_SOCKET, - FTYPE_TAP, - FTYPE_BLK, - FTYPE_KBD, - FTYPE_FB, - FTYPE_MEM, - FTYPE_SAVEFILE, - FTYPE_TPMFRONT, - FTYPE_TPM_TIS, -}; +#define FTYPE_NONE 0 +#define FTYPE_CONSOLE 1 +#define FTYPE_FILE 2 +#define FTYPE_SOCKET 3 +#define FTYPE_MEM 4 +#define FTYPE_SAVEFILE 5 +#define FTYPE_FB 6 +#define FTYPE_KBD 7 +#define FTYPE_TAP 8 +#define FTYPE_BLK 9 +#define FTYPE_TPMFRONT 10 +#define FTYPE_TPM_TIS 11 +#define FTYPE_XENBUS 12 +#define FTYPE_GNTMAP 13 +#define FTYPE_EVTCHN 14 +#define FTYPE_N 15 +#define FTYPE_SPARE 16 =20 LIST_HEAD(evtchn_port_list, evtchn_port_info); =20 @@ -182,7 +183,7 @@ struct evtchn_port_info { }; =20 struct file { - enum fd_type type; + unsigned int type; bool read; /* maybe available for read */ off_t offset; union { @@ -197,8 +198,26 @@ struct file { =20 extern struct file files[]; =20 +struct file_ops { + const char *name; + int (*read)(struct file *file, void *buf, size_t nbytes); + int (*write)(struct file *file, const void *buf, size_t nbytes); + off_t (*lseek)(struct file *file, off_t offset, int whence); + int (*close)(struct file *file); + int (*fstat)(struct file *file, struct stat *buf); + int (*fcntl)(struct file *file, int cmd, va_list args); + bool (*select_rd)(struct file *file); + bool (*select_wr)(struct file *file); +}; + +unsigned int alloc_file_type(const struct file_ops *ops); + +off_t lseek_default(struct file *file, off_t offset, int whence); +bool select_yes(struct file *file); +bool select_read_flag(struct file *file); + struct file *get_file_from_fd(int fd); -int alloc_fd(enum fd_type type); +int alloc_fd(unsigned int type); void close_all_files(void); extern struct thread *main_thread; void sparse(unsigned long data, size_t size); diff --git a/lib/sys.c b/lib/sys.c index a24687b7..7be01fd3 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -97,6 +97,40 @@ struct file files[NOFILE] =3D { { .type =3D FTYPE_CONSOLE }, /* stderr */ }; =20 +static const struct file_ops file_ops_none =3D { + .name =3D "none", +}; + +static const struct file_ops *file_ops[FTYPE_N + FTYPE_SPARE] =3D { + [FTYPE_NONE] =3D &file_ops_none, +}; + +unsigned int alloc_file_type(const struct file_ops *ops) +{ + static unsigned int i =3D FTYPE_N; + unsigned int ret; + + pthread_mutex_lock(&fd_lock); + + BUG_ON(i =3D=3D ARRAY_SIZE(file_ops)); + ret =3D i++; + file_ops[ret] =3D ops; + + pthread_mutex_unlock(&fd_lock); + + printk("New file type \"%s\"(%u) allocated\n", ops->name, ret); + + return ret; +} + +static const struct file_ops *get_file_ops(unsigned int type) +{ + if ( type >=3D ARRAY_SIZE(file_ops) || !file_ops[type] ) + return &file_ops_none; + + return file_ops[type]; +} + struct file *get_file_from_fd(int fd) { if ( fd < 0 || fd >=3D ARRAY_SIZE(files) ) @@ -107,7 +141,7 @@ struct file *get_file_from_fd(int fd) =20 DECLARE_WAIT_QUEUE_HEAD(event_queue); =20 -int alloc_fd(enum fd_type type) +int alloc_fd(unsigned int type) { int i; pthread_mutex_lock(&fd_lock); @@ -248,7 +282,17 @@ int isatty(int fd) =20 int read(int fd, void *buf, size_t nbytes) { - switch (files[fd].type) { + struct file *file =3D get_file_from_fd(fd); + const struct file_ops *ops; + + if ( !file ) + goto error; + + ops =3D get_file_ops(file->type); + if ( ops->read ) + return ops->read(file, buf, nbytes); + + switch (file->type) { case FTYPE_SAVEFILE: case FTYPE_CONSOLE: { int ret; @@ -320,6 +364,8 @@ int read(int fd, void *buf, size_t nbytes) default: break; } + + error: printk("read(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; @@ -327,7 +373,17 @@ int read(int fd, void *buf, size_t nbytes) =20 int write(int fd, const void *buf, size_t nbytes) { - switch (files[fd].type) { + struct file *file =3D get_file_from_fd(fd); + const struct file_ops *ops; + + if ( !file ) + goto error; + + ops =3D get_file_ops(file->type); + if ( ops->write ) + return ops->write(file, buf, nbytes); + + switch (file->type) { case FTYPE_SAVEFILE: { int ret =3D 0, tot =3D nbytes; while (nbytes > 0) { @@ -364,14 +420,61 @@ int write(int fd, const void *buf, size_t nbytes) default: break; } + + error: printk("write(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; } =20 +off_t lseek_default(struct file *file, off_t offset, int whence) +{ + switch ( whence ) + { + case SEEK_SET: + file->offset =3D offset; + break; + + case SEEK_CUR: + file->offset +=3D offset; + break; + + case SEEK_END: + { + struct stat st; + int ret; + + ret =3D fstat(file - files, &st); + if ( ret ) + return -1; + file->offset =3D st.st_size + offset; + break; + } + + default: + errno =3D EINVAL; + return -1; + } + + return file->offset; +} + off_t lseek(int fd, off_t offset, int whence) { - switch(files[fd].type) { + struct file *file =3D get_file_from_fd(fd); + const struct file_ops *ops; + + if ( !file ) + { + errno =3D EBADF; + return (off_t)-1; + } + + ops =3D get_file_ops(file->type); + if ( ops->lseek ) + return ops->lseek(file, offset, whence); + + switch(file->type) { #ifdef CONFIG_BLKFRONT case FTYPE_BLK: break; @@ -392,28 +495,7 @@ off_t lseek(int fd, off_t offset, int whence) return (off_t) -1; } =20 - switch (whence) { - case SEEK_SET: - files[fd].offset =3D offset; - break; - case SEEK_CUR: - files[fd].offset +=3D offset; - break; - case SEEK_END: - { - struct stat st; - int ret; - ret =3D fstat(fd, &st); - if (ret) - return -1; - files[fd].offset =3D st.st_size + offset; - break; - } - default: - errno =3D EINVAL; - return -1; - } - return files[fd].offset; + return lseek_default(file, offset, whence); } =20 int fsync(int fd) { @@ -424,12 +506,21 @@ int fsync(int fd) { int close(int fd) { int res =3D 0; + struct file *file =3D get_file_from_fd(fd); + const struct file_ops *ops; =20 - if ( fd < 0 || fd >=3D ARRAY_SIZE(files) ) + if ( !file ) goto error; =20 + ops =3D get_file_ops(file->type); printk("close(%d)\n", fd); - switch (files[fd].type) { + if ( ops->close ) + { + res =3D ops->close(file); + goto out; + } + + switch (file->type) { default: break; #ifdef CONFIG_XENBUS @@ -492,6 +583,7 @@ int close(int fd) goto error; } =20 + out: memset(files + fd, 0, sizeof(struct file)); BUILD_BUG_ON(FTYPE_NONE !=3D 0); =20 @@ -522,8 +614,19 @@ int stat(const char *path, struct stat *buf) =20 int fstat(int fd, struct stat *buf) { + struct file *file =3D get_file_from_fd(fd); + const struct file_ops *ops; + + if ( !file ) + goto error; + init_stat(buf); - switch (files[fd].type) { + + ops =3D get_file_ops(file->type); + if ( ops->fstat ) + return ops->fstat(file, buf); + + switch (file->type) { case FTYPE_SAVEFILE: case FTYPE_CONSOLE: case FTYPE_SOCKET: { @@ -557,6 +660,7 @@ int fstat(int fd, struct stat *buf) break; } =20 + error: printk("statf(%d): Bad descriptor\n", fd); errno =3D EBADF; return -1; @@ -588,6 +692,27 @@ int fcntl(int fd, int cmd, ...) { long arg; va_list ap; + int res; + struct file *file =3D get_file_from_fd(fd); + const struct file_ops *ops; + + if ( !file ) + { + errno =3D EBADF; + return -1; + } + + ops =3D get_file_ops(files[fd].type); + + if ( ops->fcntl ) + { + va_start(ap, cmd); + res =3D ops->fcntl(file, cmd, ap); + va_end(ap); + + return res; + } + va_start(ap, cmd); arg =3D va_arg(ap, long); va_end(ap); @@ -641,17 +766,28 @@ int closedir(DIR *dir) /* We assume that only the main thread calls select(). */ =20 #if defined(LIBC_DEBUG) || defined(LIBC_VERBOSE) -static const char file_types[] =3D { - [FTYPE_NONE] =3D 'N', - [FTYPE_CONSOLE] =3D 'C', - [FTYPE_XENBUS] =3D 'S', - [FTYPE_EVTCHN] =3D 'E', - [FTYPE_SOCKET] =3D 's', - [FTYPE_TAP] =3D 'T', - [FTYPE_BLK] =3D 'B', - [FTYPE_KBD] =3D 'K', - [FTYPE_FB] =3D 'G', +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", + [FTYPE_KBD] =3D "kbd", + [FTYPE_FB] =3D "fb", }; + +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) @@ -663,7 +799,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(%c)", i, file_types[files[i].type]); \ + printk("%d(%s)", i, get_type_name(files[i].type)); \ comma =3D 1; \ } \ } \ @@ -697,7 +833,7 @@ static void dump_pollfds(struct pollfd *pfd, int nfds, = int timeout) fd =3D pfd[i].fd; if (comma) printk(", "); - printk("%d(%c)/%02x", fd, file_types[files[fd].type], + printk("%d(%s)/%02x", fd, get_type_name(files[fd].type), pfd[i].events); comma =3D 1; } @@ -709,6 +845,16 @@ static void dump_pollfds(struct pollfd *pfd, int nfds,= int timeout) #define dump_pollfds(pfds, nfds, timeout) #endif =20 +bool select_yes(struct file *file) +{ + return true; +} + +bool select_read_flag(struct file *file) +{ + return file->read; +} + /* Just poll without blocking */ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set= *exceptfds) { @@ -760,11 +906,47 @@ static int select_poll(int nfds, fd_set *readfds, fd_= set *writefds, fd_set *exce =20 /* Then see others as well. */ for (i =3D 0; i < nfds; i++) { - switch(files[i].type) { + struct file *file =3D get_file_from_fd(i); + + if ( !file ) + { + FD_CLR(i, readfds); + FD_CLR(i, writefds); + FD_CLR(i, exceptfds); + continue; + } + + switch(file->type) { default: + { + const struct file_ops *ops =3D file_ops[file->type]; + + if ( ops ) + { + if ( FD_ISSET(i, readfds) ) + { + if ( ops->select_rd && ops->select_rd(file) ) + n++; + else + FD_CLR(i, readfds); + } + if ( FD_ISSET(i, writefds) ) + { + if ( ops->select_wr && ops->select_wr(file) ) + n++; + else + FD_CLR(i, writefds); + } + FD_CLR(i, exceptfds); + + break; + } + 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)) @@ -842,7 +1024,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_s= et *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, file_types[files[i].type]); + printk(" %d(%c):", i, get_type_name(files[i].type)); if (nbread[i]) printk(" %dR", nbread[i]); if (nbwrite[i]) --=20 2.26.2 From nobody Mon May 6 14:18:17 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=1642315584; cv=none; d=zohomail.com; s=zohoarc; b=aezPQEPYgzdYsgVWR6ttogiAKV01o/IglsfJw1kCpi6vEa8hgq1znGd9A+1h3g0Q7W1YSQ4XRj2r8hY4p+flWz2sgc0JLUcfBh15XaTmXn0PJwcDm107cucXJUuXzAM7H8il6gzULqSDY+j4XrYtrUGrct6viJihw+rkms5Y0ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642315584; 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=sMF8pqUc94a10+353xWoWiPfMeUftk07LIrUu9q2Fz8=; b=ahB1rKL3nLiwvoLnPsOVg9qS2tSBGW2XAi2tXUjTOBJltpoJazKO1r7YFeCqddu1EKxgoxqUkhG20Zpg5LpVrJjuC3CA4A+uRUoNKguIo3hfW2Z96K7LUfyjcayUn5Uts3LxkBueMJk/frqGdkJQLRo9xulne5MVQPkDdEK0Mno= 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 1642315584213615.892047630339; Sat, 15 Jan 2022 22:46:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257781.443096 (Exim 4.92) (envelope-from ) id 1n8zIJ-0001Ac-Vz; Sun, 16 Jan 2022 06:45:39 +0000 Received: by outflank-mailman (output) from mailman id 257781.443096; Sun, 16 Jan 2022 06:45: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 1n8zIJ-0001AA-Pj; Sun, 16 Jan 2022 06:45:39 +0000 Received: by outflank-mailman (input) for mailman id 257781; Sun, 16 Jan 2022 06:45:38 +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 1n8zII-0008SI-4X for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 06:45: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 e5c13b56-7697-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 07:45: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 B4FB7219C8; Sun, 16 Jan 2022 06:45: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 8B3DE13ABD; Sun, 16 Jan 2022 06:45:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cGS/IAq/42H0eQAAMHmgww (envelope-from ); Sun, 16 Jan 2022 06:45: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: e5c13b56-7697-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642315530; 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=sMF8pqUc94a10+353xWoWiPfMeUftk07LIrUu9q2Fz8=; b=dR4rbD/G7KbYn4CT4GiZWXUD6uomLLLQdYtB4cY6dLjUqm7e69v4zR9T/1YrWBD6o+0dM1 G+wKHa/tl3GSo4icxK0ls6IPHs1yIdjg0dMf08dI2R25cWTmUt/F7E2UV2lUvCrRIT39T6 CM1kOrnaSEv6OBEQN2fa3N9hoSW4jjM= 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 5/5] add CONFIG_LIBXS item Date: Sun, 16 Jan 2022 07:45:27 +0100 Message-Id: <20220116064527.23519-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116064527.23519-1-jgross@suse.com> References: <20220116064527.23519-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642315586835100004 Content-Type: text/plain; charset="utf-8" Mini-OS contains a stripped down version of libxenstore in lib/xs.c. Today it is being built always if CONFIG_XENBUS is set and libc support is enabled. In order to allow a Mini-OS specific build of libxenstore to be used instead add a new CONFIG_LIBXS item which per default will have the same setting as CONFIG_XENBUS. A user wanting to replace lib/xs.c with libxenstore would just need to set CONFIG_XENBUS=3Dy and CONFIG_LIBXS=3Dn. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V3: - new patch --- Config.mk | 10 ++++++++-- Makefile | 2 +- arch/x86/testbuild/all-no | 1 + arch/x86/testbuild/all-yes | 1 + arch/x86/testbuild/newxen-yes | 1 + lib/sys.c | 4 ++-- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Config.mk b/Config.mk index 1e083881..03023033 100644 --- a/Config.mk +++ b/Config.mk @@ -171,7 +171,10 @@ endif # arch/*/testbuild/*-yes and arch/*/testbuild/*-no should set ALL possible # CONFIG_ variables. =20 -# Configuration defaults +# Configuration defaults: +# CONFIG-y contains all items defaulting to "y" +# CONFIG-n contains all items defaulting to "n" +# CONFIG-x contains all items being calculated if not set explicitly CONFIG-y +=3D CONFIG_START_NETWORK CONFIG-y +=3D CONFIG_SPARSE_BSS CONFIG-y +=3D CONFIG_BLKFRONT @@ -205,7 +208,10 @@ CONFIG-$(lwip) +=3D CONFIG_LWIP $(foreach i,$(CONFIG-y),$(eval $(i) ?=3D y)) $(foreach i,$(CONFIG-n),$(eval $(i) ?=3D n)) =20 -CONFIG-all :=3D $(CONFIG-y) $(CONFIG-n) +CONFIG-x +=3D CONFIG_LIBXS +CONFIG_LIBXS ?=3D $(CONFIG_XENBUS) + +CONFIG-all :=3D $(CONFIG-y) $(CONFIG-n) $(CONFIG-x) =20 # Export config items as compiler directives $(foreach i,$(CONFIG-all),$(eval DEFINES-$($(i)) +=3D -D$(i))) diff --git a/Makefile b/Makefile index 06b60fc7..9f95d197 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ src-y +=3D lib/stack_chk_fail.c src-y +=3D lib/string.c src-y +=3D lib/sys.c src-y +=3D lib/xmalloc.c -src-$(CONFIG_XENBUS) +=3D lib/xs.c +src-$(CONFIG_LIBXS) +=3D lib/xs.c =20 src-$(CONFIG_XENBUS) +=3D xenbus/xenbus.c =20 diff --git a/arch/x86/testbuild/all-no b/arch/x86/testbuild/all-no index d6fc2608..46f974de 100644 --- a/arch/x86/testbuild/all-no +++ b/arch/x86/testbuild/all-no @@ -13,6 +13,7 @@ CONFIG_FBFRONT =3D n 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 diff --git a/arch/x86/testbuild/all-yes b/arch/x86/testbuild/all-yes index 98bbfebf..3ead12f1 100644 --- a/arch/x86/testbuild/all-yes +++ b/arch/x86/testbuild/all-yes @@ -13,6 +13,7 @@ CONFIG_FBFRONT =3D y CONFIG_KBDFRONT =3D y CONFIG_CONSFRONT =3D y CONFIG_XENBUS =3D y +CONFIG_LIBXS =3D y CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y # The following are special: they need support from outside diff --git a/arch/x86/testbuild/newxen-yes b/arch/x86/testbuild/newxen-yes index 06032004..5c0b3c80 100644 --- a/arch/x86/testbuild/newxen-yes +++ b/arch/x86/testbuild/newxen-yes @@ -13,6 +13,7 @@ CONFIG_FBFRONT =3D y CONFIG_KBDFRONT =3D y CONFIG_CONSFRONT =3D y CONFIG_XENBUS =3D y +CONFIG_LIBXS =3D y CONFIG_BALLOON =3D y CONFIG_USE_XEN_CONSOLE =3D y XEN_INTERFACE_VERSION=3D__XEN_LATEST_INTERFACE_VERSION__ diff --git a/lib/sys.c b/lib/sys.c index 7be01fd3..e0ac5099 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -523,7 +523,7 @@ int close(int fd) switch (file->type) { default: break; -#ifdef CONFIG_XENBUS +#ifdef CONFIG_LIBXS case FTYPE_XENBUS: xs_daemon_close((void*)(intptr_t) fd); break; @@ -958,7 +958,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_se= t *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; -#ifdef CONFIG_XENBUS +#ifdef CONFIG_LIBXS case FTYPE_XENBUS: if (FD_ISSET(i, readfds)) { if (files[i].dev) --=20 2.26.2