[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mini-os master] use alloc_file_type() and get_file_from_fd() in xs



commit 0b4c24e0631bfe397be60b716f27e25334dc28a7
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Sun Jan 16 09:33:19 2022 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Tue Jan 18 18:26:43 2022 +0000

    use alloc_file_type() and get_file_from_fd() in xs
    
    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@xxxxxxxx>
    Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
---
 include/lib.h |  3 +--
 lib/sys.c     | 18 -----------------
 lib/xs.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++--------------
 3 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index 5838b0d..c5e4778 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
 
 struct file {
diff --git a/lib/sys.c b/lib/sys.c
index 9894233..217073d 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 = lwip_close(files[fd].fd);
@@ -759,7 +754,6 @@ int closedir(DIR *dir)
 static const char *const file_types[] = {
     [FTYPE_NONE]    = "none",
     [FTYPE_CONSOLE] = "console",
-    [FTYPE_XENBUS]  = "xenbus",
     [FTYPE_SOCKET]  = "socket",
     [FTYPE_TAP]     = "net",
     [FTYPE_BLK]     = "blk",
@@ -947,18 +941,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_set 
*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 4af0f96..7fe9b03 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;
 }
 
+static int xs_close_fd(struct file *file)
+{
+    struct xenbus_event *event, *next;
+
+    for ( event = file->dev; event; event = next )
+    {
+        next = event->next;
+        free(event);
+    }
+
+    return 0;
+}
+
+static bool xs_can_read(struct file *file)
+{
+    return file->dev;
+}
+
+static const struct file_ops xenbus_ops = {
+    .name = "xenbus",
+    .close = xs_close_fd,
+    .select_rd = xs_can_read,
+};
+
+static unsigned int ftype_xenbus;
+
+__attribute__((constructor))
+static void xs_initialize(void)
+{
+    ftype_xenbus = alloc_file_type(&xenbus_ops);
+}
+
 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;
+
+    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 +202,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;
--
generated by git-patchbot for /home/xen/git/mini-os.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.