All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: samuel.thibault@ens-lyon.org, wl@xen.org,
	Juergen Gross <jgross@suse.com>
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	[thread overview]
Message-ID: <20220111151215.22955-4-jgross@suse.com> (raw)
In-Reply-To: <20220111151215.22955-1-jgross@suse.com>

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 <jgross@suse.com>
---
 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
 
 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 = lwip_close(files[fd].fd);
@@ -712,7 +707,6 @@ int closedir(DIR *dir)
 static const char *file_types[] = {
     [FTYPE_NONE]    = "none",
     [FTYPE_CONSOLE] = "console",
-    [FTYPE_XENBUS]  = "xenbus",
     [FTYPE_SOCKET]  = "socket",
     [FTYPE_TAP]     = "net",
     [FTYPE_BLK]     = "blk",
@@ -892,18 +886,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *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;
 }
 
+static int xs_close_fd(int fd)
+{
+    struct xenbus_event *event, *next;
+    struct file *file = get_file_from_fd(fd);
+
+    for (event = file->dev; event; event = next)
+    {
+        next = event->next;
+        free(event);
+    }
+
+    return 0;
+}
+
+static bool xs_can_read(int fd)
+{
+    struct file *file = get_file_from_fd(fd);
+
+    return file && file->dev;
+}
+
+static struct file_ops xenbus_ops = {
+    .name = "xenbus",
+    .close = xs_close_fd,
+    .select_rd = xs_can_read,
+};
+
 struct xs_handle *xs_daemon_open()
 {
-    int fd = alloc_fd(FTYPE_XENBUS);
-    files[fd].dev = 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 = alloc_file_type(&xenbus_ops);
+
+    fd = alloc_fd(ftype_xenbus);
+    file = get_file_from_fd(fd);
+    if ( !file )
+        return NULL;
+
+    file->dev = NULL;
+    printk("xs_daemon_open -> %d, %p\n", fd, &file->dev);
     return (void*)(intptr_t) fd;
 }
 
 void xs_daemon_close(struct xs_handle *h)
 {
-    int fd = _xs_fileno(h);
-    struct xenbus_event *event, *next;
-    for (event = files[fd].dev; event; event = next)
-    {
-        next = event->next;
-        free(event);
-    }
+    close(_xs_fileno(h));
 }
 
 int xs_fileno(struct xs_handle *h)
@@ -169,18 +201,20 @@ char **xs_directory(struct xs_handle *h, xs_transaction_t t,
 
 bool xs_watch(struct xs_handle *h, const char *path, const char *token)
 {
-    int fd = _xs_fileno(h);
+    struct file *file = 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));
 }
 
 char **xs_read_watch(struct xs_handle *h, unsigned int *num)
 {
-    int fd = _xs_fileno(h);
     struct xenbus_event *event;
-    event = files[fd].dev;
-    files[fd].dev = event->next;
+    struct file *file = get_file_from_fd(_xs_fileno(h));
+
+    event = file->dev;
+    file->dev = event->next;
     printk("xs_read_watch() -> %s %s\n", event->path, event->token);
     *num = 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);
-- 
2.26.2



  parent reply	other threads:[~2022-01-11 15:12 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 15:12 [PATCH v2 00/12] mini-os: remove device specific struct file members Juergen Gross
2022-01-11 15:12 ` [PATCH v2 01/12] mini-os: remove event channel specific struct file definitions Juergen Gross
2022-01-11 19:50   ` Samuel Thibault
2022-01-11 15:12 ` [PATCH v2 02/12] mini-os: remove gnttab specific member from struct file Juergen Gross
2022-01-11 19:55   ` Samuel Thibault
2022-01-11 20:12   ` Andrew Cooper
2022-01-12  7:44     ` Juergen Gross
2022-01-11 15:12 ` Juergen Gross [this message]
2022-01-11 20:06   ` [PATCH v2 03/12] mini-os: use alloc_file_type() and get_file_from_fd() in xs Samuel Thibault
2022-01-11 20:11     ` Samuel Thibault
2022-01-11 20:14       ` Andrew Cooper
2022-01-11 20:21   ` Andrew Cooper
2022-01-12  7:52     ` Juergen Gross
2022-01-12  8:12       ` Andrew Cooper
2022-01-11 15:12 ` [PATCH v2 04/12] mini-os: use alloc_file_type() and get_file_from_fd() in tpm_tis Juergen Gross
2022-01-11 20:13   ` Samuel Thibault
2022-01-11 20:29   ` Andrew Cooper
2022-01-11 20:58     ` Jason Andryuk
2022-01-12  7:54     ` Juergen Gross
2022-01-12  8:14       ` Andrew Cooper
2022-01-11 15:12 ` [PATCH v2 05/12] mini-os: use alloc_file_type() and get_file_from_fd() in tpmfront Juergen Gross
2022-01-11 20:15   ` Samuel Thibault
2022-01-11 15:12 ` [PATCH v2 06/12] mini-os: use alloc_file_type() and get_file_from_fd() in blkfront Juergen Gross
2022-01-11 20:20   ` Samuel Thibault
2022-01-11 15:12 ` [PATCH v2 07/12] mini-os: use get_file_from_fd() in netfront Juergen Gross
2022-01-11 20:22   ` Samuel Thibault
2022-01-11 15:12 ` [PATCH v2 08/12] mini-os: use alloc_file_type() and get_file_from_fd() in fbfront Juergen Gross
2022-01-11 20:26   ` Samuel Thibault
2022-01-12  7:52     ` Juergen Gross
2022-01-11 15:12 ` [PATCH v2 09/12] mini-os: use file_ops and get_file_from_fd() for console Juergen Gross
2022-01-11 20:35   ` Samuel Thibault
2022-01-12  7:57     ` Juergen Gross
2022-01-12 10:30       ` Samuel Thibault
2022-01-12 10:30   ` Samuel Thibault
2022-01-12 11:23   ` Andrew Cooper
2022-01-12 11:30     ` Juergen Gross
2022-01-11 15:12 ` [PATCH v2 10/12] mini-os: add struct file_ops for file type socket Juergen Gross
2022-01-11 20:38   ` Samuel Thibault
2022-01-12 10:30   ` Samuel Thibault
2022-01-12 11:25   ` Andrew Cooper
2022-01-12 11:31     ` Juergen Gross
2022-01-12 11:28   ` Andrew Cooper
2022-01-12 11:32     ` Juergen Gross
2022-01-12 11:33       ` Andrew Cooper
2022-01-11 15:12 ` [PATCH v2 11/12] mini-os: add struct file_ops for FTYPE_FILE Juergen Gross
2022-01-11 20:42   ` Samuel Thibault
2022-01-11 15:12 ` [PATCH v2 12/12] mini-os: make files array private to sys.c Juergen Gross
2022-01-11 20:42   ` Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220111151215.22955-4-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=minios-devel@lists.xenproject.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.