From nobody Mon Feb 9 00:19:48 2026 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=1641913142; cv=none; d=zohomail.com; s=zohoarc; b=Kaalrr+arvpnLZwq4wJ/GT3eiG6kMJTUGx46OAgXQkSO9khq3TiRONlCfCYu78c9KpDCFDmKY4oBztn+uG3e5U1u+0jLxvuxbDUm81JFLTlpJVLIc9vKyf6fj9XVqNw/UcQ11fhDtTnoziYiiR1XI6P7EBW2us+jQARU8J29SEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913142; 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=DMMBPYWRjtz4/x5ruR8HIV8cwX5HYWaCHB+pYDCnRVA=; b=HMCyCxX8c+vzN9z+CkVwcsZK/MGECQQPje1FMQVhX/r4p/5VzArYV679+1VfXI6wT+v/VIku75SZy1gYyB+9DXvkjzgO9B7gzdk0Vy5S5qHK0QDGLl7pusDq9SoIZBgRZ5awyFe3rjDBwlyK0327SxnQwWEcl1i/KdlvIFYulXg= 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 164191314210577.06509157836763; Tue, 11 Jan 2022 06:59:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255776.438464 (Exim 4.92) (envelope-from ) id 1n7IbZ-000468-Ma; Tue, 11 Jan 2022 14:58:33 +0000 Received: by outflank-mailman (output) from mailman id 255776.438464; Tue, 11 Jan 2022 14:58:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7IbZ-00042H-5n; Tue, 11 Jan 2022 14:58:33 +0000 Received: by outflank-mailman (input) for mailman id 255776; Tue, 11 Jan 2022 14:58:30 +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 1n7IbW-0002OZ-DN for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 14:58:30 +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 eabddecc-72ee-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 15:58:22 +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 B8B941F3BA; Tue, 11 Jan 2022 14:58:20 +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 90B4913DDD; Tue, 11 Jan 2022 14:58:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YLshIgyb3WH9eQAAMHmgww (envelope-from ); Tue, 11 Jan 2022 14:58:20 +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: eabddecc-72ee-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913100; 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=DMMBPYWRjtz4/x5ruR8HIV8cwX5HYWaCHB+pYDCnRVA=; b=JzdJyIpda3v4DRJ6dS3sevj+AMPFI4kl5bVC6hqBjKmi/wVNJD011RpzoX3nC6Wow99h/x abJGpEd/063Sn404YSrpDDbM34VQl0OcQOOvrZrKpVyM5NMvV9IkhKmt972sFvCU31b+Ce tIjGmAXz8jLlE4wy673TLMcZqma+nX8= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 04/18] mini-os: replace multiple fd elements in struct file by common one Date: Tue, 11 Jan 2022 15:58:03 +0100 Message-Id: <20220111145817.22170-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111145817.22170-1-jgross@suse.com> References: <20220111145817.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913143981100002 Content-Type: text/plain; charset="utf-8" The type specific union in struct files contains two instances of "int fd". Replace them by a common one. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 9 +-------- lib/sys.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/include/lib.h b/include/lib.h index 4d9b14b..dc56f52 100644 --- a/include/lib.h +++ b/include/lib.h @@ -187,14 +187,7 @@ struct file { bool read; /* maybe available for read */ off_t offset; union { - struct { - /* lwIP fd */ - int fd; - } socket; - struct { - /* FS import fd */ - int fd; - } file; + int fd; /* Any fd from an upper layer. */ struct { struct evtchn_port_list ports; } evtchn; diff --git a/lib/sys.c b/lib/sys.c index e1cea70..1da7401 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -258,7 +258,7 @@ int read(int fd, void *buf, size_t nbytes) } #ifdef HAVE_LWIP case FTYPE_SOCKET: - return lwip_read(files[fd].socket.fd, buf, nbytes); + return lwip_read(files[fd].fd, buf, nbytes); #endif #ifdef CONFIG_NETFRONT case FTYPE_TAP: { @@ -335,7 +335,7 @@ int write(int fd, const void *buf, size_t nbytes) return nbytes; #ifdef HAVE_LWIP case FTYPE_SOCKET: - return lwip_write(files[fd].socket.fd, (void*) buf, nbytes); + return lwip_write(files[fd].fd, (void*) buf, nbytes); #endif #ifdef CONFIG_NETFRONT case FTYPE_TAP: @@ -428,7 +428,7 @@ int close(int fd) #endif #ifdef HAVE_LWIP case FTYPE_SOCKET: { - int res =3D lwip_close(files[fd].socket.fd); + int res =3D lwip_close(files[fd].fd); files[fd].type =3D FTYPE_NONE; return res; } @@ -594,7 +594,7 @@ int fcntl(int fd, int cmd, ...) 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].socket.fd, FIONBIO, &nblock); + return lwip_ioctl(files[fd].fd, FIONBIO, &nblock); } /* Fallthrough */ #endif @@ -732,15 +732,15 @@ static int select_poll(int nfds, fd_set *readfds, fd_= set *writefds, fd_set *exce for (i =3D 0; i < nfds; i++) { if (files[i].type =3D=3D FTYPE_SOCKET) { if (FD_ISSET(i, readfds)) { - FD_SET(files[i].socket.fd, &sock_readfds); + FD_SET(files[i].fd, &sock_readfds); sock_nfds =3D i+1; } if (FD_ISSET(i, writefds)) { - FD_SET(files[i].socket.fd, &sock_writefds); + FD_SET(files[i].fd, &sock_writefds); sock_nfds =3D i+1; } if (FD_ISSET(i, exceptfds)) { - FD_SET(files[i].socket.fd, &sock_exceptfds); + FD_SET(files[i].fd, &sock_exceptfds); sock_nfds =3D i+1; } } @@ -803,19 +803,19 @@ static int select_poll(int nfds, fd_set *readfds, fd_= set *writefds, fd_set *exce case FTYPE_SOCKET: if (FD_ISSET(i, readfds)) { /* Optimize no-network-packet case. */ - if (sock_n && FD_ISSET(files[i].socket.fd, &sock_readfds)) + if (sock_n && FD_ISSET(files[i].fd, &sock_readfds)) n++; else FD_CLR(i, readfds); } if (FD_ISSET(i, writefds)) { - if (sock_n && FD_ISSET(files[i].socket.fd, &sock_writefds)) + if (sock_n && FD_ISSET(files[i].fd, &sock_writefds)) n++; else FD_CLR(i, writefds); } if (FD_ISSET(i, exceptfds)) { - if (sock_n && FD_ISSET(files[i].socket.fd, &sock_exceptfds)) + if (sock_n && FD_ISSET(files[i].fd, &sock_exceptfds)) n++; else FD_CLR(i, exceptfds); @@ -1112,7 +1112,7 @@ int socket(int domain, int type, int protocol) return -1; res =3D alloc_fd(FTYPE_SOCKET); printk("socket -> %d\n", res); - files[res].socket.fd =3D fd; + files[res].fd =3D fd; return res; } =20 @@ -1124,11 +1124,11 @@ int accept(int s, struct sockaddr *addr, socklen_t = *addrlen) errno =3D EBADF; return -1; } - fd =3D lwip_accept(files[s].socket.fd, addr, addrlen); + fd =3D lwip_accept(files[s].fd, addr, addrlen); if (fd < 0) return -1; res =3D alloc_fd(FTYPE_SOCKET); - files[res].socket.fd =3D fd; + files[res].fd =3D fd; printk("accepted on %d -> %d\n", s, res); return res; } @@ -1141,7 +1141,7 @@ ret name proto \ errno =3D EBADF; \ return -1; \ } \ - s =3D files[s].socket.fd; \ + s =3D files[s].fd; \ return lwip_##name args; \ } =20 --=20 2.26.2