From nobody Fri Apr 19 09:41:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913960; cv=none; d=zohomail.com; s=zohoarc; b=Jt6YFJd2V0E4QAWmh8n1/68rtqegNuKbXCRxrdtKoPvtwsHlDSnk9GEsfuuzGO6MJ7imX8IUYyuVW5qjPKLibaf9hA9Ovp6YuHzEax8XKymWp+dIvAc9513yeA+LperkyNCD/+OGqL+g4cjyyc/gXIA05pSrPnXfDFuyGrwqwdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913960; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gTPeNHy0AVh7duIevs+xqjLxKhkGSrZIz5TiPB1taxY=; b=WcE3PCSq2jUZYKFA2MXSrTRx2yr8sj0Bi7WJQ0kgOTKPFMn7CBKZKfI+dgOHeMcTrxxZMPzVZlam8wcmhSYGmDMpsZsjGb7SoyYOWan/cZa+9ztVAnZmuUD176u4yehqbmNDUwtOtTI+7/5Sa82EtBL+sriplnReae6DQ69EMxw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913960232307.55089590170496; Tue, 11 Jan 2022 07:12:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255867.438738 (Exim 4.92) (envelope-from ) id 1n7Iow-0002yC-T3; Tue, 11 Jan 2022 15:12:22 +0000 Received: by outflank-mailman (output) from mailman id 255867.438738; Tue, 11 Jan 2022 15:12:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iow-0002y3-P5; Tue, 11 Jan 2022 15:12:22 +0000 Received: by outflank-mailman (input) for mailman id 255867; Tue, 11 Jan 2022 15:12:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Iou-0002Fv-VK for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:21 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dd8042dd-72f0-11ec-9ce5-af14b9085ebd; Tue, 11 Jan 2022 16:12:17 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7BC961F3B8; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5665A13DDD; Tue, 11 Jan 2022 15:12:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UNUCFFGe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dd8042dd-72f0-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913937; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gTPeNHy0AVh7duIevs+xqjLxKhkGSrZIz5TiPB1taxY=; b=IRkL3v6k2KUYC2e1crbEs0Lw5Izu4d+fHlophfX9cPw76G/pbv0YqXKfbEwbqEysaBI8xa Q3Fo82RyLoSralVP088j9JE1wfo/qBNlvFtKyVN6d2H2Bhtkk/28Xo3pLB6EP57ilJhV0p 4p7xRiGRrlwFAt+8mBeLO3eHtsG1gLM= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 03/12] mini-os: use alloc_file_type() and get_file_from_fd() in xs Date: Tue, 11 Jan 2022 16:12:06 +0100 Message-Id: <20220111151215.22955-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913961357100011 Content-Type: text/plain; charset="utf-8" Allocate the needed file type via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 3 +-- lib/sys.c | 18 -------------- lib/xs.c | 64 +++++++++++++++++++++++++++++++++++++------------ xenbus/xenbus.c | 1 + 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/include/lib.h b/include/lib.h index 283abb8..05c7de5 100644 --- a/include/lib.h +++ b/include/lib.h @@ -167,8 +167,7 @@ void sanity_check(void); #define FTYPE_BLK 9 #define FTYPE_TPMFRONT 10 #define FTYPE_TPM_TIS 11 -#define FTYPE_XENBUS 12 -#define FTYPE_N 13 +#define FTYPE_N 12 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index 9540410..d213ae5 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -495,11 +495,6 @@ int close(int fd) switch (files[fd].type) { default: break; -#ifdef CONFIG_XENBUS - case FTYPE_XENBUS: - xs_daemon_close((void*)(intptr_t) fd); - break; -#endif #ifdef HAVE_LWIP case FTYPE_SOCKET: res =3D lwip_close(files[fd].fd); @@ -712,7 +707,6 @@ int closedir(DIR *dir) static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", [FTYPE_CONSOLE] =3D "console", - [FTYPE_XENBUS] =3D "xenbus", [FTYPE_SOCKET] =3D "socket", [FTYPE_TAP] =3D "net", [FTYPE_BLK] =3D "blk", @@ -892,18 +886,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_s= et *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; -#ifdef CONFIG_XENBUS - case FTYPE_XENBUS: - if (FD_ISSET(i, readfds)) { - if (files[i].dev) - n++; - else - FD_CLR(i, readfds); - } - FD_CLR(i, writefds); - FD_CLR(i, exceptfds); - break; -#endif case FTYPE_TAP: case FTYPE_BLK: case FTYPE_KBD: diff --git a/lib/xs.c b/lib/xs.c index 4af0f96..ac830d2 100644 --- a/lib/xs.c +++ b/lib/xs.c @@ -18,23 +18,55 @@ static inline int _xs_fileno(struct xs_handle *h) { return (intptr_t) h; } =20 +static int xs_close_fd(int fd) +{ + struct xenbus_event *event, *next; + struct file *file =3D get_file_from_fd(fd); + + for (event =3D file->dev; event; event =3D next) + { + next =3D event->next; + free(event); + } + + return 0; +} + +static bool xs_can_read(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + return file && file->dev; +} + +static struct file_ops xenbus_ops =3D { + .name =3D "xenbus", + .close =3D xs_close_fd, + .select_rd =3D xs_can_read, +}; + struct xs_handle *xs_daemon_open() { - int fd =3D alloc_fd(FTYPE_XENBUS); - files[fd].dev =3D NULL; - printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].dev); + int fd; + struct file *file; + static unsigned int ftype_xenbus; + + if ( !ftype_xenbus ) + ftype_xenbus =3D alloc_file_type(&xenbus_ops); + + fd =3D alloc_fd(ftype_xenbus); + file =3D get_file_from_fd(fd); + if ( !file ) + return NULL; + + file->dev =3D NULL; + printk("xs_daemon_open -> %d, %p\n", fd, &file->dev); return (void*)(intptr_t) fd; } =20 void xs_daemon_close(struct xs_handle *h) { - int fd =3D _xs_fileno(h); - struct xenbus_event *event, *next; - for (event =3D files[fd].dev; event; event =3D next) - { - next =3D event->next; - free(event); - } + close(_xs_fileno(h)); } =20 int xs_fileno(struct xs_handle *h) @@ -169,18 +201,20 @@ char **xs_directory(struct xs_handle *h, xs_transacti= on_t t, =20 bool xs_watch(struct xs_handle *h, const char *path, const char *token) { - int fd =3D _xs_fileno(h); + struct file *file =3D get_file_from_fd(_xs_fileno(h)); + printk("xs_watch(%s, %s)\n", path, token); return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token, - (xenbus_event_queue *)&files[fd].dev)); + (xenbus_event_queue *)&file->dev)); } =20 char **xs_read_watch(struct xs_handle *h, unsigned int *num) { - int fd =3D _xs_fileno(h); struct xenbus_event *event; - event =3D files[fd].dev; - files[fd].dev =3D event->next; + struct file *file =3D get_file_from_fd(_xs_fileno(h)); + + event =3D file->dev; + file->dev =3D event->next; printk("xs_read_watch() -> %s %s\n", event->path, event->token); *num =3D 2; return (char **) &event->path; diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c index b687678..785389f 100644 --- a/xenbus/xenbus.c +++ b/xenbus/xenbus.c @@ -393,6 +393,7 @@ static int allocate_xenbus_id(void) void init_xenbus(void) { int err; + DEBUG("init_xenbus called.\n"); create_thread("xenstore", xenbus_thread_func, NULL); DEBUG("buf at %p.\n", xenstore_buf); --=20 2.26.2