All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/15] mini-os: remove struct file dependency from config
@ 2022-01-06 11:57 Juergen Gross
  2022-01-06 11:57 ` [PATCH 01/15] mini-os: split struct file definition from its usage Juergen Gross
                   ` (15 more replies)
  0 siblings, 16 replies; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Today the layout of struct file is depending on the Mini-OS
configuration. This is especially bad as the layout is exported to
external users like the Xen libraries built for Mini-OS, and those
are being built only once for multiple stubdom configurations.

Today there is no direct problem resulting from this, as the main
difference between struct file layouts is a large union containing all
the device specific data for the different file types. The largest
union member is not configuration dependant, so the build is currently
not broken.

In order to avoid any future problems this patch series is eliminating
the configuration dependency by replacing most of the device specific
union members by a single pointer.

The two union members used by Xen libraries can't be replaced yet, as
those need to be switched to use the generic pointer first.

In order to hide the Mini-OS internal implementation of the files
array, the last patch is introducing a service function for obtaining
the pointer to struct file for a given file descriptor, which must be
used for that purpose by all Mini-OS external components.

Juergen Gross (15):
  mini-os: split struct file definition from its usage
  mini-os: makes file.read bool and move it ahead of device specific
    part
  mini-os: make offset a common struct file member for all types
  mini-os: replace multiple fd elements in struct file by common one
  mini-os: introduce a common dev pointer in struct file
  mini-os: eliminate blkfront union member in struct file
  mini-os: eliminate consfront union member in struct file
  mini-os: eliminate fbfront union member in struct file
  mini-os: eliminate kbdfront union member in struct file
  mini-os: eliminate netfront union member in struct file
  mini-os: move tpm respgot member of struct file to device specific
    data
  mini-os: eliminate tpmfront union member in struct file
  mini-os: eliminate tpmtis union member in struct file
  mini-os: eliminate xenbus union member in struct file
  mini-os: introduce get_file_from_fd()

 blkfront.c             |  15 +++---
 console/xencons_ring.c |   2 +-
 fbfront.c              |  16 +++----
 include/lib.h          |  59 ++++-------------------
 include/tpmfront.h     |   2 +
 lib/sys.c              | 103 ++++++++++++++++++++++-------------------
 lib/xs.c               |  13 +++---
 netfront.c             |   6 +--
 tpm_tis.c              |  23 ++++-----
 tpmfront.c             |  33 +++++++------
 10 files changed, 119 insertions(+), 153 deletions(-)

-- 
2.26.2



^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 01/15] mini-os: split struct file definition from its usage
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:17   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part Juergen Gross
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Make the struct file definition standalone and use it for the
declaration of the files array.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index 39d6a18..a638bc9 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -181,7 +181,7 @@ struct evtchn_port_info {
         int bound;
 };
 
-extern struct file {
+struct file {
     enum fd_type type;
     union {
 	struct {
@@ -236,7 +236,9 @@ extern struct file {
 #endif
     };
     int read;	/* maybe available for read */
-} files[];
+};
+
+extern struct file files[];
 
 int alloc_fd(enum fd_type type);
 void close_all_files(void);
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
  2022-01-06 11:57 ` [PATCH 01/15] mini-os: split struct file definition from its usage Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:18   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 03/15] mini-os: make offset a common struct file member for all types Juergen Gross
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

The read member of struct file should be bool.

In order to have the device specific part at the end of the structure
move "read" ahead of that.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 blkfront.c             |  4 ++--
 console/xencons_ring.c |  2 +-
 fbfront.c              | 12 ++++++------
 include/lib.h          |  3 ++-
 netfront.c             |  4 ++--
 tpm_tis.c              |  2 +-
 tpmfront.c             |  6 +++---
 7 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/blkfront.c b/blkfront.c
index 834a978..7c8eb74 100644
--- a/blkfront.c
+++ b/blkfront.c
@@ -62,7 +62,7 @@ void blkfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
     int fd = dev->fd;
 
     if (fd != -1)
-        files[fd].read = 1;
+        files[fd].read = true;
 #endif
     wake_up(&blkfront_queue);
 }
@@ -484,7 +484,7 @@ int blkfront_aio_poll(struct blkfront_dev *dev)
 moretodo:
 #ifdef HAVE_LIBC
     if (dev->fd != -1) {
-        files[dev->fd].read = 0;
+        files[dev->fd].read = false;
         mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
     }
 #endif
diff --git a/console/xencons_ring.c b/console/xencons_ring.c
index b6db74e..c348f3c 100644
--- a/console/xencons_ring.c
+++ b/console/xencons_ring.c
@@ -102,7 +102,7 @@ void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data)
         int fd = dev ? dev->fd : -1;
 
         if (fd != -1)
-            files[fd].read = 1;
+            files[fd].read = true;
 
         wake_up(&console_queue);
 #else
diff --git a/fbfront.c b/fbfront.c
index d3b3848..6725da1 100644
--- a/fbfront.c
+++ b/fbfront.c
@@ -45,7 +45,7 @@ void kbdfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
     int fd = dev->fd;
 
     if (fd != -1)
-        files[fd].read = 1;
+        files[fd].read = true;
 #endif
     wake_up(&kbdfront_queue);
 }
@@ -207,7 +207,7 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n
 
 #ifdef HAVE_LIBC
     if (dev->fd != -1) {
-        files[dev->fd].read = 0;
+        files[dev->fd].read = false;
         mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
     }
 #endif
@@ -229,7 +229,7 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n
 #ifdef HAVE_LIBC
     if (cons != prod && dev->fd != -1)
         /* still some events to read */
-        files[dev->fd].read = 1;
+        files[dev->fd].read = true;
 #endif
 
     return i;
@@ -349,7 +349,7 @@ void fbfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
     int fd = dev->fd;
 
     if (fd != -1)
-        files[fd].read = 1;
+        files[fd].read = true;
 #endif
     wake_up(&fbfront_queue);
 }
@@ -376,7 +376,7 @@ int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
 
 #ifdef HAVE_LIBC
     if (dev->fd != -1) {
-        files[dev->fd].read = 0;
+        files[dev->fd].read = false;
         mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
     }
 #endif
@@ -398,7 +398,7 @@ int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
 #ifdef HAVE_LIBC
     if (cons != prod && dev->fd != -1)
         /* still some events to read */
-        files[dev->fd].read = 1;
+        files[dev->fd].read = true;
 #endif
 
     return i;
diff --git a/include/lib.h b/include/lib.h
index a638bc9..df2de9e 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -49,6 +49,7 @@
 #define _LIB_H_
 
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <xen/xen.h>
 #include <xen/event_channel.h>
@@ -183,6 +184,7 @@ struct evtchn_port_info {
 
 struct file {
     enum fd_type type;
+    bool read;	/* maybe available for read */
     union {
 	struct {
             /* lwIP fd */
@@ -235,7 +237,6 @@ struct file {
         } xenbus;
 #endif
     };
-    int read;	/* maybe available for read */
 };
 
 extern struct file files[];
diff --git a/netfront.c b/netfront.c
index dfe065b..a566e34 100644
--- a/netfront.c
+++ b/netfront.c
@@ -255,7 +255,7 @@ void netfront_select_handler(evtchn_port_t port, struct pt_regs *regs, void *dat
     local_irq_restore(flags);
 
     if (fd != -1)
-        files[fd].read = 1;
+        files[fd].read = true;
     wake_up(&netfront_queue);
 }
 #endif
@@ -783,7 +783,7 @@ ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t l
     network_rx(dev);
     if (!dev->rlen && fd != -1)
         /* No data for us, make select stop returning */
-        files[fd].read = 0;
+        files[fd].read = false;
     /* Before re-enabling the interrupts, in case a packet just arrived in the
      * meanwhile. */
     local_irq_restore(flags);
diff --git a/tpm_tis.c b/tpm_tis.c
index 475ac5d..4a51027 100644
--- a/tpm_tis.c
+++ b/tpm_tis.c
@@ -845,7 +845,7 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
    }
 #ifdef HAVE_LIBC
    if(tpm->fd >= 0) {
-      files[tpm->fd].read = 0;
+      files[tpm->fd].read = false;
       files[tpm->fd].tpm_tis.respgot = 0;
       files[tpm->fd].tpm_tis.offset = 0;
    }
diff --git a/tpmfront.c b/tpmfront.c
index 6049244..d825b49 100644
--- a/tpmfront.c
+++ b/tpmfront.c
@@ -66,7 +66,7 @@ void tpmfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data) {
    dev->waiting = 0;
 #ifdef HAVE_LIBC
    if(dev->fd >= 0) {
-      files[dev->fd].read = 1;
+      files[dev->fd].read = true;
    }
 #endif
    wake_up(&dev->waitq);
@@ -438,7 +438,7 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
    dev->resplen = 0;
 #ifdef HAVE_LIBC
    if(dev->fd >= 0) {
-      files[dev->fd].read = 0;
+      files[dev->fd].read = false;
       files[dev->fd].tpmfront.respgot = 0;
       files[dev->fd].tpmfront.offset = 0;
    }
@@ -611,7 +611,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
 
    /* If we have a response waiting, then read it now from the backend
     * so we can get its length*/
-   if(dev->waiting || (files[dev->fd].read == 1 && !files[dev->fd].tpmfront.respgot)) {
+   if(dev->waiting || (files[dev->fd].read && !files[dev->fd].tpmfront.respgot)) {
       if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
 	 errno = EIO;
 	 return -1;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 03/15] mini-os: make offset a common struct file member for all types
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
  2022-01-06 11:57 ` [PATCH 01/15] mini-os: split struct file definition from its usage Juergen Gross
  2022-01-06 11:57 ` [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:23   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 04/15] mini-os: replace multiple fd elements in struct file by common one Juergen Gross
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Currently 4 file types have an offset member in their private struct
file part. Make offset a common struct member shared by all file types.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 blkfront.c    |  5 ++---
 include/lib.h |  5 +----
 lib/sys.c     | 14 +++++---------
 tpm_tis.c     | 11 +++++------
 tpmfront.c    | 11 +++++------
 5 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/blkfront.c b/blkfront.c
index 7c8eb74..8137106 100644
--- a/blkfront.c
+++ b/blkfront.c
@@ -563,14 +563,13 @@ int blkfront_open(struct blkfront_dev *dev)
     dev->fd = alloc_fd(FTYPE_BLK);
     printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
     files[dev->fd].blk.dev = dev;
-    files[dev->fd].blk.offset = 0;
     return dev->fd;
 }
 
 int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
 {
    struct blkfront_dev* dev = files[fd].blk.dev;
-   off_t offset = files[fd].blk.offset;
+   off_t offset = files[fd].offset;
    struct blkfront_aiocb aiocb;
    unsigned long long disksize = dev->info.sectors * dev->info.sector_size;
    unsigned int blocksize = dev->info.sector_size;
@@ -712,7 +711,7 @@ int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
    }
 
    free(copybuf);
-   files[fd].blk.offset += rc;
+   files[fd].offset += rc;
    return rc;
 
 }
diff --git a/include/lib.h b/include/lib.h
index df2de9e..4d9b14b 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -185,6 +185,7 @@ struct evtchn_port_info {
 struct file {
     enum fd_type type;
     bool read;	/* maybe available for read */
+    off_t offset;
     union {
 	struct {
             /* lwIP fd */
@@ -193,7 +194,6 @@ struct file {
 	struct {
             /* FS import fd */
 	    int fd;
-	    off_t offset;
 	} file;
 	struct {
 	    struct evtchn_port_list ports;
@@ -204,7 +204,6 @@ struct file {
 	} tap;
 	struct {
 	    struct blkfront_dev *dev;
-            off_t offset;
 	} blk;
 	struct {
 	    struct kbdfront_dev *dev;
@@ -219,14 +218,12 @@ struct file {
 	struct {
 	   struct tpmfront_dev *dev;
 	   int respgot;
-	   off_t offset;
 	} tpmfront;
 #endif
 #ifdef CONFIG_TPM_TIS
 	struct {
 	   struct tpm_chip *dev;
 	   int respgot;
-	   off_t offset;
 	} tpm_tis;
 #endif
 #ifdef CONFIG_XENBUS
diff --git a/lib/sys.c b/lib/sys.c
index e8d5eb2..e1cea70 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -107,6 +107,7 @@ int alloc_fd(enum fd_type type)
     for (i=0; i<NOFILE; i++) {
 	if (files[i].type == FTYPE_NONE) {
 	    files[i].type = type;
+            files[i].offset = 0;
 	    pthread_mutex_unlock(&fd_lock);
 	    return i;
 	}
@@ -363,25 +364,20 @@ int write(int fd, const void *buf, size_t nbytes)
 
 off_t lseek(int fd, off_t offset, int whence)
 {
-    off_t* target = NULL;
     switch(files[fd].type) {
 #ifdef CONFIG_BLKFRONT
        case FTYPE_BLK:
-          target = &files[fd].blk.offset;
           break;
 #endif
 #ifdef CONFIG_TPMFRONT
        case FTYPE_TPMFRONT:
-          target = &files[fd].tpmfront.offset;
           break;
 #endif
 #ifdef CONFIG_TPM_TIS
        case FTYPE_TPM_TIS:
-          target = &files[fd].tpm_tis.offset;
           break;
 #endif
        case FTYPE_FILE:
-          target = &files[fd].file.offset;
           break;
        default:
           /* Not implemented for this filetype */
@@ -391,10 +387,10 @@ off_t lseek(int fd, off_t offset, int whence)
 
     switch (whence) {
        case SEEK_SET:
-          *target = offset;
+          files[fd].offset = offset;
           break;
        case SEEK_CUR:
-          *target += offset;
+          files[fd].offset += offset;
           break;
        case SEEK_END:
           {
@@ -403,14 +399,14 @@ off_t lseek(int fd, off_t offset, int whence)
              ret = fstat(fd, &st);
              if (ret)
                 return -1;
-             *target = st.st_size + offset;
+             files[fd].offset = st.st_size + offset;
              break;
           }
        default:
           errno = EINVAL;
           return -1;
     }
-    return *target;
+    return files[fd].offset;
 }
 
 int fsync(int fd) {
diff --git a/tpm_tis.c b/tpm_tis.c
index 4a51027..8a632b1 100644
--- a/tpm_tis.c
+++ b/tpm_tis.c
@@ -847,7 +847,7 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
    if(tpm->fd >= 0) {
       files[tpm->fd].read = false;
       files[tpm->fd].tpm_tis.respgot = 0;
-      files[tpm->fd].tpm_tis.offset = 0;
+      files[tpm->fd].offset = 0;
    }
 #endif
    return len;
@@ -1290,7 +1290,6 @@ int tpm_tis_open(struct tpm_chip* tpm)
    tpm->fd = alloc_fd(FTYPE_TPM_TIS);
    printk("tpm_tis_open() -> %d\n", tpm->fd);
    files[tpm->fd].tpm_tis.dev = tpm;
-   files[tpm->fd].tpm_tis.offset = 0;
    files[tpm->fd].tpm_tis.respgot = 0;
    return tpm->fd;
 }
@@ -1340,13 +1339,13 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count)
 
 
    /* Handle EOF case */
-   if(files[fd].tpm_tis.offset >= tpm->data_len) {
+   if(files[fd].offset >= tpm->data_len) {
       rc = 0;
    } else {
-      rc = min(tpm->data_len - files[fd].tpm_tis.offset, count);
-      memcpy(buf, tpm->data_buffer + files[fd].tpm_tis.offset, rc);
+      rc = min(tpm->data_len - files[fd].offset, count);
+      memcpy(buf, tpm->data_buffer + files[fd].offset, rc);
    }
-   files[fd].tpm_tis.offset += rc;
+   files[fd].offset += rc;
    /* Reset the data pending flag */
    return rc;
 }
diff --git a/tpmfront.c b/tpmfront.c
index d825b49..8b2a910 100644
--- a/tpmfront.c
+++ b/tpmfront.c
@@ -440,7 +440,7 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
    if(dev->fd >= 0) {
       files[dev->fd].read = false;
       files[dev->fd].tpmfront.respgot = 0;
-      files[dev->fd].tpmfront.offset = 0;
+      files[dev->fd].offset = 0;
    }
 #endif
    wmb();
@@ -539,7 +539,6 @@ int tpmfront_open(struct tpmfront_dev* dev)
    dev->fd = alloc_fd(FTYPE_TPMFRONT);
    printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
    files[dev->fd].tpmfront.dev = dev;
-   files[dev->fd].tpmfront.offset = 0;
    files[dev->fd].tpmfront.respgot = 0;
    return dev->fd;
 }
@@ -589,14 +588,14 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t count)
    }
 
    /* handle EOF case */
-   if(files[dev->fd].tpmfront.offset >= dev->resplen) {
+   if(files[dev->fd].offset >= dev->resplen) {
       return 0;
    }
 
    /* Compute the number of bytes and do the copy operation */
-   if((rc = min(count, dev->resplen - files[dev->fd].tpmfront.offset)) != 0) {
-      memcpy(buf, dev->respbuf + files[dev->fd].tpmfront.offset, rc);
-      files[dev->fd].tpmfront.offset += rc;
+   if((rc = min(count, dev->resplen - files[dev->fd].offset)) != 0) {
+      memcpy(buf, dev->respbuf + files[dev->fd].offset, rc);
+      files[dev->fd].offset += rc;
    }
 
    return rc;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 04/15] mini-os: replace multiple fd elements in struct file by common one
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (2 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 03/15] mini-os: make offset a common struct file member for all types Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:25   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 05/15] mini-os: introduce a common dev pointer in struct file Juergen Gross
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

The type specific union in struct files contains two instances of
"int fd". Replace them by a common one.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 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 = lwip_close(files[fd].socket.fd);
+	    int res = lwip_close(files[fd].fd);
 	    files[fd].type = FTYPE_NONE;
 	    return res;
 	}
@@ -594,7 +594,7 @@ int fcntl(int fd, int cmd, ...)
 	    if (files[fd].type == FTYPE_SOCKET && !(arg & ~O_NONBLOCK)) {
 		/* Only flag supported: non-blocking mode */
 		uint32_t nblock = !!(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 = 0; i < nfds; i++) {
 	if (files[i].type == FTYPE_SOCKET) {
 	    if (FD_ISSET(i, readfds)) {
-		FD_SET(files[i].socket.fd, &sock_readfds);
+		FD_SET(files[i].fd, &sock_readfds);
 		sock_nfds = i+1;
 	    }
 	    if (FD_ISSET(i, writefds)) {
-		FD_SET(files[i].socket.fd, &sock_writefds);
+		FD_SET(files[i].fd, &sock_writefds);
 		sock_nfds = i+1;
 	    }
 	    if (FD_ISSET(i, exceptfds)) {
-		FD_SET(files[i].socket.fd, &sock_exceptfds);
+		FD_SET(files[i].fd, &sock_exceptfds);
 		sock_nfds = 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 = alloc_fd(FTYPE_SOCKET);
     printk("socket -> %d\n", res);
-    files[res].socket.fd = fd;
+    files[res].fd = fd;
     return res;
 }
 
@@ -1124,11 +1124,11 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 	errno = EBADF;
 	return -1;
     }
-    fd = lwip_accept(files[s].socket.fd, addr, addrlen);
+    fd = lwip_accept(files[s].fd, addr, addrlen);
     if (fd < 0)
 	return -1;
     res = alloc_fd(FTYPE_SOCKET);
-    files[res].socket.fd = fd;
+    files[res].fd = fd;
     printk("accepted on %d -> %d\n", s, res);
     return res;
 }
@@ -1141,7 +1141,7 @@ ret name proto \
 	errno = EBADF; \
 	return -1; \
     } \
-    s = files[s].socket.fd; \
+    s = files[s].fd; \
     return lwip_##name args; \
 }
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 05/15] mini-os: introduce a common dev pointer in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (3 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 04/15] mini-os: replace multiple fd elements in struct file by common one Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:25   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 06/15] mini-os: eliminate blkfront union member " Juergen Gross
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

There are many dev pointers in a union in struct file. Prepare to
switch to a single one by introducing a new common one.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/lib.h b/include/lib.h
index dc56f52..60aaf1c 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -188,6 +188,7 @@ struct file {
     off_t offset;
     union {
         int fd; /* Any fd from an upper layer. */
+        void *dev;
 	struct {
 	    struct evtchn_port_list ports;
 	} evtchn;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 06/15] mini-os: eliminate blkfront union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (4 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 05/15] mini-os: introduce a common dev pointer in struct file Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:26   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 07/15] mini-os: eliminate consfront " Juergen Gross
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the blkfront specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 blkfront.c    | 6 +++---
 include/lib.h | 3 ---
 lib/sys.c     | 2 +-
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/blkfront.c b/blkfront.c
index 8137106..e3f42be 100644
--- a/blkfront.c
+++ b/blkfront.c
@@ -562,13 +562,13 @@ int blkfront_open(struct blkfront_dev *dev)
     }
     dev->fd = alloc_fd(FTYPE_BLK);
     printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
-    files[dev->fd].blk.dev = dev;
+    files[dev->fd].dev = dev;
     return dev->fd;
 }
 
 int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
 {
-   struct blkfront_dev* dev = files[fd].blk.dev;
+   struct blkfront_dev* dev = files[fd].dev;
    off_t offset = files[fd].offset;
    struct blkfront_aiocb aiocb;
    unsigned long long disksize = dev->info.sectors * dev->info.sector_size;
@@ -718,7 +718,7 @@ int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
 
 int blkfront_posix_fstat(int fd, struct stat* buf)
 {
-   struct blkfront_dev* dev = files[fd].blk.dev;
+   struct blkfront_dev* dev = files[fd].dev;
 
    buf->st_mode = dev->info.mode;
    buf->st_uid = 0;
diff --git a/include/lib.h b/include/lib.h
index 60aaf1c..3a40634 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -196,9 +196,6 @@ struct file {
 	struct {
 	    struct netfront_dev *dev;
 	} tap;
-	struct {
-	    struct blkfront_dev *dev;
-	} blk;
 	struct {
 	    struct kbdfront_dev *dev;
 	} kbd;
diff --git a/lib/sys.c b/lib/sys.c
index 1da7401..f2fdbdf 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -456,7 +456,7 @@ int close(int fd)
 #endif
 #ifdef CONFIG_BLKFRONT
 	case FTYPE_BLK:
-            shutdown_blkfront(files[fd].blk.dev);
+            shutdown_blkfront(files[fd].dev);
 	    files[fd].type = FTYPE_NONE;
 	    return 0;
 #endif
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 07/15] mini-os: eliminate consfront union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (5 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 06/15] mini-os: eliminate blkfront union member " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:27   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 08/15] mini-os: eliminate fbfront " Juergen Gross
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the consfront specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h |  3 ---
 lib/sys.c     | 31 +++++++++++++++++--------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index 3a40634..0cedae6 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -202,9 +202,6 @@ struct file {
 	struct {
 	    struct fbfront_dev *dev;
 	} fb;
-	struct {
-	    struct consfront_dev *dev;
-	} cons;
 #ifdef CONFIG_TPMFRONT
 	struct {
 	   struct tpmfront_dev *dev;
diff --git a/lib/sys.c b/lib/sys.c
index f2fdbdf..62c2020 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -179,7 +179,7 @@ int posix_openpt(int flags)
 
     dev = init_consfront(NULL);
     dev->fd = alloc_fd(FTYPE_CONSOLE);
-    files[dev->fd].cons.dev = dev;
+    files[dev->fd].dev = dev;
 
     printk("fd(%d) = posix_openpt\n", dev->fd);
     return(dev->fd);
@@ -194,7 +194,7 @@ int open_savefile(const char *path, int save)
 
     dev = init_consfront(nodename);
     dev->fd = alloc_fd(FTYPE_SAVEFILE);
-    files[dev->fd].cons.dev = dev;
+    files[dev->fd].dev = dev;
 
     printk("fd(%d) = open_savefile\n", dev->fd);
     return(dev->fd);
@@ -248,7 +248,7 @@ int read(int fd, void *buf, size_t nbytes)
             DEFINE_WAIT(w);
             while(1) {
                 add_waiter(w, console_queue);
-                ret = xencons_ring_recv(files[fd].cons.dev, buf, nbytes);
+                ret = xencons_ring_recv(files[fd].dev, buf, nbytes);
                 if (ret)
                     break;
                 schedule();
@@ -324,14 +324,14 @@ int write(int fd, const void *buf, size_t nbytes)
         case FTYPE_SAVEFILE: {
                 int ret = 0, tot = nbytes;
                 while (nbytes > 0) {
-                    ret = xencons_ring_send(files[fd].cons.dev, (char *)buf, nbytes);
+                    ret = xencons_ring_send(files[fd].dev, (char *)buf, nbytes);
                     nbytes -= ret;
                     buf = (char *)buf + ret;
                 }
                 return tot - nbytes;
             }
 	case FTYPE_CONSOLE:
-	    console_print(files[fd].cons.dev, (char *)buf, nbytes);
+	    console_print(files[fd].dev, (char *)buf, nbytes);
 	    return nbytes;
 #ifdef HAVE_LWIP
 	case FTYPE_SOCKET:
@@ -487,7 +487,7 @@ int close(int fd)
 #ifdef CONFIG_CONSFRONT
         case FTYPE_SAVEFILE:
         case FTYPE_CONSOLE:
-            fini_consfront(files[fd].cons.dev);
+            fini_consfront(files[fd].dev);
             files[fd].type = FTYPE_NONE;
             return 0;
 #endif
@@ -764,7 +764,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce
 	    /* Fallthrough.  */
 	case FTYPE_CONSOLE:
 	    if (FD_ISSET(i, readfds)) {
-                if (xencons_ring_avail(files[i].cons.dev))
+                if (xencons_ring_avail(files[i].dev))
 		    n++;
 		else
 		    FD_CLR(i, readfds);
@@ -1447,6 +1447,8 @@ const struct termios default_termios = {0,             /* iflag */
 
 int tcsetattr(int fildes, int action, const struct termios *tios)
 {
+    struct consfront_dev *dev;
+
     if (fildes < 0 || fildes >= NOFILE) {
         errno = EBADF;
         return -1;
@@ -1472,21 +1474,21 @@ int tcsetattr(int fildes, int action, const struct termios *tios)
             return -1;
     }
 
-    if (files[fildes].cons.dev == NULL) {
+    dev = files[fildes].dev;
+    if (dev == NULL) {
         errno = ENOSYS;
         return -1;
     }
 
-    if (tios->c_oflag & OPOST)
-        files[fildes].cons.dev->is_raw = false;
-    else
-        files[fildes].cons.dev->is_raw = true;
+    dev->is_raw = !(tios->c_oflag & OPOST);
 
     return 0;
 }
 
 int tcgetattr(int fildes, struct termios *tios)
 {
+    struct consfront_dev *dev;
+
     if (fildes < 0 || fildes >= NOFILE) {
         errno = EBADF;
         return -1;
@@ -1497,7 +1499,8 @@ int tcgetattr(int fildes, struct termios *tios)
         return -1;
     }
 
-    if (files[fildes].cons.dev == NULL) {
+    dev = files[fildes].dev;
+    if (dev == NULL) {
         errno = ENOSYS;
         return 0;
     }
@@ -1509,7 +1512,7 @@ int tcgetattr(int fildes, struct termios *tios)
 
     memcpy(tios, &default_termios, sizeof(struct termios));
 
-    if (files[fildes].cons.dev->is_raw)
+    if (dev->is_raw)
         tios->c_oflag &= ~OPOST;
 
     return 0;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 08/15] mini-os: eliminate fbfront union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (6 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 07/15] mini-os: eliminate consfront " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:27   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 09/15] mini-os: eliminate kbdfront " Juergen Gross
                   ` (7 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the fbfront specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 fbfront.c     | 2 +-
 include/lib.h | 3 ---
 lib/sys.c     | 4 ++--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/fbfront.c b/fbfront.c
index 6725da1..c8410af 100644
--- a/fbfront.c
+++ b/fbfront.c
@@ -703,7 +703,7 @@ int fbfront_open(struct fbfront_dev *dev)
 {
     dev->fd = alloc_fd(FTYPE_FB);
     printk("fb_open(%s) -> %d\n", dev->nodename, dev->fd);
-    files[dev->fd].fb.dev = dev;
+    files[dev->fd].dev = dev;
     return dev->fd;
 }
 #endif
diff --git a/include/lib.h b/include/lib.h
index 0cedae6..2a9a01c 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -199,9 +199,6 @@ struct file {
 	struct {
 	    struct kbdfront_dev *dev;
 	} kbd;
-	struct {
-	    struct fbfront_dev *dev;
-	} fb;
 #ifdef CONFIG_TPMFRONT
 	struct {
 	   struct tpmfront_dev *dev;
diff --git a/lib/sys.c b/lib/sys.c
index 62c2020..2d48657 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -287,7 +287,7 @@ int read(int fd, void *buf, size_t nbytes)
         case FTYPE_FB: {
             int ret, n;
             n = nbytes / sizeof(union xenfb_in_event);
-            ret = fbfront_receive(files[fd].fb.dev, buf, n);
+            ret = fbfront_receive(files[fd].dev, buf, n);
 	    if (ret <= 0) {
 		errno = EAGAIN;
 		return -1;
@@ -480,7 +480,7 @@ int close(int fd)
 #endif
 #ifdef CONFIG_FBFRONT
 	case FTYPE_FB:
-            shutdown_fbfront(files[fd].fb.dev);
+            shutdown_fbfront(files[fd].dev);
             files[fd].type = FTYPE_NONE;
             return 0;
 #endif
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 09/15] mini-os: eliminate kbdfront union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (7 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 08/15] mini-os: eliminate fbfront " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:28   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 10/15] mini-os: eliminate netfront " Juergen Gross
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the kbdfront specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 fbfront.c     | 2 +-
 include/lib.h | 3 ---
 lib/sys.c     | 4 ++--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/fbfront.c b/fbfront.c
index c8410af..1e055fb 100644
--- a/fbfront.c
+++ b/fbfront.c
@@ -302,7 +302,7 @@ int kbdfront_open(struct kbdfront_dev *dev)
 {
     dev->fd = alloc_fd(FTYPE_KBD);
     printk("kbd_open(%s) -> %d\n", dev->nodename, dev->fd);
-    files[dev->fd].kbd.dev = dev;
+    files[dev->fd].dev = dev;
     return dev->fd;
 }
 #endif
diff --git a/include/lib.h b/include/lib.h
index 2a9a01c..5201ed7 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -196,9 +196,6 @@ struct file {
 	struct {
 	    struct netfront_dev *dev;
 	} tap;
-	struct {
-	    struct kbdfront_dev *dev;
-	} kbd;
 #ifdef CONFIG_TPMFRONT
 	struct {
 	   struct tpmfront_dev *dev;
diff --git a/lib/sys.c b/lib/sys.c
index 2d48657..8c7ea3c 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -275,7 +275,7 @@ int read(int fd, void *buf, size_t nbytes)
         case FTYPE_KBD: {
             int ret, n;
             n = nbytes / sizeof(union xenkbd_in_event);
-            ret = kbdfront_receive(files[fd].kbd.dev, buf, n);
+            ret = kbdfront_receive(files[fd].dev, buf, n);
 	    if (ret <= 0) {
 		errno = EAGAIN;
 		return -1;
@@ -474,7 +474,7 @@ int close(int fd)
 #endif
 #ifdef CONFIG_KBDFRONT
 	case FTYPE_KBD:
-            shutdown_kbdfront(files[fd].kbd.dev);
+            shutdown_kbdfront(files[fd].dev);
             files[fd].type = FTYPE_NONE;
             return 0;
 #endif
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 10/15] mini-os: eliminate netfront union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (8 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 09/15] mini-os: eliminate kbdfront " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:28   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 11/15] mini-os: move tpm respgot member of struct file to device specific data Juergen Gross
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the netfront specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h | 3 ---
 lib/sys.c     | 6 +++---
 netfront.c    | 2 +-
 3 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index 5201ed7..f2a124e 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -193,9 +193,6 @@ struct file {
 	    struct evtchn_port_list ports;
 	} evtchn;
 	struct gntmap gntmap;
-	struct {
-	    struct netfront_dev *dev;
-	} tap;
 #ifdef CONFIG_TPMFRONT
 	struct {
 	   struct tpmfront_dev *dev;
diff --git a/lib/sys.c b/lib/sys.c
index 8c7ea3c..b35e433 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -263,7 +263,7 @@ int read(int fd, void *buf, size_t nbytes)
 #ifdef CONFIG_NETFRONT
 	case FTYPE_TAP: {
 	    ssize_t ret;
-	    ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
+	    ret = netfront_receive(files[fd].dev, buf, nbytes);
 	    if (ret <= 0) {
 		errno = EAGAIN;
 		return -1;
@@ -339,7 +339,7 @@ int write(int fd, const void *buf, size_t nbytes)
 #endif
 #ifdef CONFIG_NETFRONT
 	case FTYPE_TAP:
-	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
+	    netfront_xmit(files[fd].dev, (void*) buf, nbytes);
 	    return nbytes;
 #endif
 #ifdef CONFIG_BLKFRONT
@@ -450,7 +450,7 @@ int close(int fd)
 #endif
 #ifdef CONFIG_NETFRONT
 	case FTYPE_TAP:
-	    shutdown_netfront(files[fd].tap.dev);
+	    shutdown_netfront(files[fd].dev);
 	    files[fd].type = FTYPE_NONE;
 	    return 0;
 #endif
diff --git a/netfront.c b/netfront.c
index a566e34..7696451 100644
--- a/netfront.c
+++ b/netfront.c
@@ -576,7 +576,7 @@ int netfront_tap_open(char *nodename) {
     }
     dev->fd = alloc_fd(FTYPE_TAP);
     printk("tap_open(%s) -> %d\n", nodename, dev->fd);
-    files[dev->fd].tap.dev = dev;
+    files[dev->fd].dev = dev;
     return dev->fd;
 }
 #endif
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 11/15] mini-os: move tpm respgot member of struct file to device specific data
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (9 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 10/15] mini-os: eliminate netfront " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:30   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 12/15] mini-os: eliminate tpmfront union member in struct file Juergen Gross
                   ` (4 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Tpmfront has a "respgot" flag in struct file, which can be moved to the
device specific data. While at it make it a bool.

The respgot flag of the tpm_tis member of struct file can be removed,
as it is never read.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h      |  2 --
 include/tpmfront.h |  2 ++
 tpm_tis.c          |  2 --
 tpmfront.c         | 10 +++++-----
 4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index f2a124e..d740065 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -196,13 +196,11 @@ struct file {
 #ifdef CONFIG_TPMFRONT
 	struct {
 	   struct tpmfront_dev *dev;
-	   int respgot;
 	} tpmfront;
 #endif
 #ifdef CONFIG_TPM_TIS
 	struct {
 	   struct tpm_chip *dev;
-	   int respgot;
 	} tpm_tis;
 #endif
 #ifdef CONFIG_XENBUS
diff --git a/include/tpmfront.h b/include/tpmfront.h
index c489fae..b7da50e 100644
--- a/include/tpmfront.h
+++ b/include/tpmfront.h
@@ -25,6 +25,7 @@
 #ifndef TPMFRONT_H
 #define TPMFRONT_H
 
+#include <stdbool.h>
 #include <mini-os/types.h>
 #include <mini-os/os.h>
 #include <mini-os/events.h>
@@ -53,6 +54,7 @@ struct tpmfront_dev {
 
 #ifdef HAVE_LIBC
    int fd;
+   bool respgot;
 #endif
 
 };
diff --git a/tpm_tis.c b/tpm_tis.c
index 8a632b1..4127118 100644
--- a/tpm_tis.c
+++ b/tpm_tis.c
@@ -846,7 +846,6 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
 #ifdef HAVE_LIBC
    if(tpm->fd >= 0) {
       files[tpm->fd].read = false;
-      files[tpm->fd].tpm_tis.respgot = 0;
       files[tpm->fd].offset = 0;
    }
 #endif
@@ -1290,7 +1289,6 @@ int tpm_tis_open(struct tpm_chip* tpm)
    tpm->fd = alloc_fd(FTYPE_TPM_TIS);
    printk("tpm_tis_open() -> %d\n", tpm->fd);
    files[tpm->fd].tpm_tis.dev = tpm;
-   files[tpm->fd].tpm_tis.respgot = 0;
    return tpm->fd;
 }
 
diff --git a/tpmfront.c b/tpmfront.c
index 8b2a910..be671c2 100644
--- a/tpmfront.c
+++ b/tpmfront.c
@@ -439,8 +439,8 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
 #ifdef HAVE_LIBC
    if(dev->fd >= 0) {
       files[dev->fd].read = false;
-      files[dev->fd].tpmfront.respgot = 0;
       files[dev->fd].offset = 0;
+      dev->respgot = false;
    }
 #endif
    wmb();
@@ -499,7 +499,7 @@ int i;
 #endif
 #ifdef HAVE_LIBC
    if(dev->fd >= 0) {
-      files[dev->fd].tpmfront.respgot = 1;
+      dev->respgot = true;
    }
 #endif
 quit:
@@ -539,7 +539,7 @@ int tpmfront_open(struct tpmfront_dev* dev)
    dev->fd = alloc_fd(FTYPE_TPMFRONT);
    printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
    files[dev->fd].tpmfront.dev = dev;
-   files[dev->fd].tpmfront.respgot = 0;
+   dev->respgot = false;
    return dev->fd;
 }
 
@@ -580,7 +580,7 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t count)
    }
 
    /* get the response if we haven't already */
-   if(files[dev->fd].tpmfront.respgot == 0) {
+   if (!dev->respgot) {
       if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
 	 errno = EIO;
 	 return -1;
@@ -610,7 +610,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
 
    /* If we have a response waiting, then read it now from the backend
     * so we can get its length*/
-   if(dev->waiting || (files[dev->fd].read && !files[dev->fd].tpmfront.respgot)) {
+   if(dev->waiting || (files[dev->fd].read && !dev->respgot)) {
       if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
 	 errno = EIO;
 	 return -1;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 12/15] mini-os: eliminate tpmfront union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (10 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 11/15] mini-os: move tpm respgot member of struct file to device specific data Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:30   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 13/15] mini-os: eliminate tpmtis " Juergen Gross
                   ` (3 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the tpmfront specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h | 5 -----
 lib/sys.c     | 2 +-
 tpmfront.c    | 8 ++++----
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index d740065..2ddc076 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -193,11 +193,6 @@ struct file {
 	    struct evtchn_port_list ports;
 	} evtchn;
 	struct gntmap gntmap;
-#ifdef CONFIG_TPMFRONT
-	struct {
-	   struct tpmfront_dev *dev;
-	} tpmfront;
-#endif
 #ifdef CONFIG_TPM_TIS
 	struct {
 	   struct tpm_chip *dev;
diff --git a/lib/sys.c b/lib/sys.c
index b35e433..b042bf5 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -462,7 +462,7 @@ int close(int fd)
 #endif
 #ifdef CONFIG_TPMFRONT
 	case FTYPE_TPMFRONT:
-            shutdown_tpmfront(files[fd].tpmfront.dev);
+            shutdown_tpmfront(files[fd].dev);
 	    files[fd].type = FTYPE_NONE;
 	    return 0;
 #endif
diff --git a/tpmfront.c b/tpmfront.c
index be671c2..0a2fefc 100644
--- a/tpmfront.c
+++ b/tpmfront.c
@@ -538,7 +538,7 @@ int tpmfront_open(struct tpmfront_dev* dev)
 
    dev->fd = alloc_fd(FTYPE_TPMFRONT);
    printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
-   files[dev->fd].tpmfront.dev = dev;
+   files[dev->fd].dev = dev;
    dev->respgot = false;
    return dev->fd;
 }
@@ -547,7 +547,7 @@ int tpmfront_posix_write(int fd, const uint8_t* buf, size_t count)
 {
    int rc;
    struct tpmfront_dev* dev;
-   dev = files[fd].tpmfront.dev;
+   dev = files[fd].dev;
 
    if(count == 0) {
       return 0;
@@ -573,7 +573,7 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t count)
    size_t dummysz;
    struct tpmfront_dev* dev;
 
-   dev = files[fd].tpmfront.dev;
+   dev = files[fd].dev;
 
    if(count == 0) {
       return 0;
@@ -606,7 +606,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
    uint8_t* dummybuf;
    size_t dummysz;
    int rc;
-   struct tpmfront_dev* dev = files[fd].tpmfront.dev;
+   struct tpmfront_dev* dev = files[fd].dev;
 
    /* If we have a response waiting, then read it now from the backend
     * so we can get its length*/
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 13/15] mini-os: eliminate tpmtis union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (11 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 12/15] mini-os: eliminate tpmfront union member in struct file Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:31   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 14/15] mini-os: eliminate xenbus " Juergen Gross
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the tpmtis specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h | 5 -----
 lib/sys.c     | 2 +-
 tpm_tis.c     | 8 ++++----
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index 2ddc076..d6a29ba 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -193,11 +193,6 @@ struct file {
 	    struct evtchn_port_list ports;
 	} evtchn;
 	struct gntmap gntmap;
-#ifdef CONFIG_TPM_TIS
-	struct {
-	   struct tpm_chip *dev;
-	} tpm_tis;
-#endif
 #ifdef CONFIG_XENBUS
         struct {
             /* To each xenbus FD is associated a queue of watch events for this
diff --git a/lib/sys.c b/lib/sys.c
index b042bf5..96fc769 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -468,7 +468,7 @@ int close(int fd)
 #endif
 #ifdef CONFIG_TPM_TIS
 	case FTYPE_TPM_TIS:
-            shutdown_tpm_tis(files[fd].tpm_tis.dev);
+            shutdown_tpm_tis(files[fd].dev);
 	    files[fd].type = FTYPE_NONE;
 	    return 0;
 #endif
diff --git a/tpm_tis.c b/tpm_tis.c
index 4127118..477f555 100644
--- a/tpm_tis.c
+++ b/tpm_tis.c
@@ -1288,14 +1288,14 @@ int tpm_tis_open(struct tpm_chip* tpm)
 
    tpm->fd = alloc_fd(FTYPE_TPM_TIS);
    printk("tpm_tis_open() -> %d\n", tpm->fd);
-   files[tpm->fd].tpm_tis.dev = tpm;
+   files[tpm->fd].dev = tpm;
    return tpm->fd;
 }
 
 int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count)
 {
    struct tpm_chip* tpm;
-   tpm = files[fd].tpm_tis.dev;
+   tpm = files[fd].dev;
 
    if(tpm->locality < 0) {
       printk("tpm_tis_posix_write() failed! locality not set!\n");
@@ -1323,7 +1323,7 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count)
 {
    int rc;
    struct tpm_chip* tpm;
-   tpm = files[fd].tpm_tis.dev;
+   tpm = files[fd].dev;
 
    if(count == 0) {
       return 0;
@@ -1350,7 +1350,7 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count)
 int tpm_tis_posix_fstat(int fd, struct stat* buf)
 {
    struct tpm_chip* tpm;
-   tpm = files[fd].tpm_tis.dev;
+   tpm = files[fd].dev;
 
    buf->st_mode = O_RDWR;
    buf->st_uid = 0;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 14/15] mini-os: eliminate xenbus union member in struct file
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (12 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 13/15] mini-os: eliminate tpmtis " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:32   ` Samuel Thibault
  2022-01-06 11:57 ` [PATCH 15/15] mini-os: introduce get_file_from_fd() Juergen Gross
  2022-01-07  2:39 ` [PATCH 00/15] mini-os: remove struct file dependency from config Samuel Thibault
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

Replace the xenbus specific union member in struct file with the
common dev pointer.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h |  7 -------
 lib/sys.c     |  2 +-
 lib/xs.c      | 13 +++++++------
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/include/lib.h b/include/lib.h
index d6a29ba..91364ba 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -193,13 +193,6 @@ struct file {
 	    struct evtchn_port_list ports;
 	} evtchn;
 	struct gntmap gntmap;
-#ifdef CONFIG_XENBUS
-        struct {
-            /* To each xenbus FD is associated a queue of watch events for this
-             * FD.  */
-            xenbus_event_queue events;
-        } xenbus;
-#endif
     };
 };
 
diff --git a/lib/sys.c b/lib/sys.c
index 96fc769..6f2b026 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -776,7 +776,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce
 #ifdef CONFIG_XENBUS
 	case FTYPE_XENBUS:
 	    if (FD_ISSET(i, readfds)) {
-                if (files[i].xenbus.events)
+                if (files[i].dev)
 		    n++;
 		else
 		    FD_CLR(i, readfds);
diff --git a/lib/xs.c b/lib/xs.c
index 324bd05..0459f52 100644
--- a/lib/xs.c
+++ b/lib/xs.c
@@ -21,8 +21,8 @@ static inline int _xs_fileno(struct xs_handle *h) {
 struct xs_handle *xs_daemon_open()
 {
     int fd = alloc_fd(FTYPE_XENBUS);
-    files[fd].xenbus.events = NULL;
-    printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].xenbus.events);
+    files[fd].dev = NULL;
+    printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].dev);
     return (void*)(intptr_t) fd;
 }
 
@@ -30,7 +30,7 @@ void xs_daemon_close(struct xs_handle *h)
 {
     int fd = _xs_fileno(h);
     struct xenbus_event *event, *next;
-    for (event = files[fd].xenbus.events; event; event = next)
+    for (event = files[fd].dev; event; event = next)
     {
         next = event->next;
         free(event);
@@ -172,15 +172,16 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)
 {
     int fd = _xs_fileno(h);
     printk("xs_watch(%s, %s)\n", path, token);
-    return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token, &files[fd].xenbus.events));
+    return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token,
+                   (xenbus_event_queue *)&files[fd].dev));
 }
 
 char **xs_read_watch(struct xs_handle *h, unsigned int *num)
 {
     int fd = _xs_fileno(h);
     struct xenbus_event *event;
-    event = files[fd].xenbus.events;
-    files[fd].xenbus.events = event->next;
+    event = files[fd].dev;
+    files[fd].dev = event->next;
     printk("xs_read_watch() -> %s %s\n", event->path, event->token);
     *num = 2;
     return (char **) &event->path;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 15/15] mini-os: introduce get_file_from_fd()
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (13 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 14/15] mini-os: eliminate xenbus " Juergen Gross
@ 2022-01-06 11:57 ` Juergen Gross
  2022-01-09  1:33   ` Samuel Thibault
  2022-01-07  2:39 ` [PATCH 00/15] mini-os: remove struct file dependency from config Samuel Thibault
  15 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-06 11:57 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, wl, Juergen Gross

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 <jgross@suse.com>
---
 include/lib.h | 1 +
 lib/sys.c     | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/lib.h b/include/lib.h
index 91364ba..7a0546b 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -198,6 +198,7 @@ struct file {
 
 extern struct file files[];
 
+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 6f2b026..0e6fe5d 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -98,6 +98,14 @@ struct file files[NOFILE] = {
     { .type = FTYPE_CONSOLE }, /* stderr */
 };
 
+struct file *get_file_from_fd(int fd)
+{
+    if ( fd < 0 || fd >= NOFILE )
+        return NULL;
+
+    return (files[fd].type == FTYPE_NONE) ? NULL : files + fd;
+}
+
 DECLARE_WAIT_QUEUE_HEAD(event_queue);
 
 int alloc_fd(enum fd_type type)
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/15] mini-os: remove struct file dependency from config
  2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
                   ` (14 preceding siblings ...)
  2022-01-06 11:57 ` [PATCH 15/15] mini-os: introduce get_file_from_fd() Juergen Gross
@ 2022-01-07  2:39 ` Samuel Thibault
  15 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-07  2:39 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Hello,

I had a glimpse at the changes, this looks good to me!

Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
on the whole series.

I'll see when I'll be able to find time to review the changes, unless
somebody beats me to it :)

Samuel

Juergen Gross, le jeu. 06 janv. 2022 12:57:26 +0100, a ecrit:
> Today the layout of struct file is depending on the Mini-OS
> configuration. This is especially bad as the layout is exported to
> external users like the Xen libraries built for Mini-OS, and those
> are being built only once for multiple stubdom configurations.
> 
> Today there is no direct problem resulting from this, as the main
> difference between struct file layouts is a large union containing all
> the device specific data for the different file types. The largest
> union member is not configuration dependant, so the build is currently
> not broken.
> 
> In order to avoid any future problems this patch series is eliminating
> the configuration dependency by replacing most of the device specific
> union members by a single pointer.
> 
> The two union members used by Xen libraries can't be replaced yet, as
> those need to be switched to use the generic pointer first.
> 
> In order to hide the Mini-OS internal implementation of the files
> array, the last patch is introducing a service function for obtaining
> the pointer to struct file for a given file descriptor, which must be
> used for that purpose by all Mini-OS external components.
> 
> Juergen Gross (15):
>   mini-os: split struct file definition from its usage
>   mini-os: makes file.read bool and move it ahead of device specific
>     part
>   mini-os: make offset a common struct file member for all types
>   mini-os: replace multiple fd elements in struct file by common one
>   mini-os: introduce a common dev pointer in struct file
>   mini-os: eliminate blkfront union member in struct file
>   mini-os: eliminate consfront union member in struct file
>   mini-os: eliminate fbfront union member in struct file
>   mini-os: eliminate kbdfront union member in struct file
>   mini-os: eliminate netfront union member in struct file
>   mini-os: move tpm respgot member of struct file to device specific
>     data
>   mini-os: eliminate tpmfront union member in struct file
>   mini-os: eliminate tpmtis union member in struct file
>   mini-os: eliminate xenbus union member in struct file
>   mini-os: introduce get_file_from_fd()
> 
>  blkfront.c             |  15 +++---
>  console/xencons_ring.c |   2 +-
>  fbfront.c              |  16 +++----
>  include/lib.h          |  59 ++++-------------------
>  include/tpmfront.h     |   2 +
>  lib/sys.c              | 103 ++++++++++++++++++++++-------------------
>  lib/xs.c               |  13 +++---
>  netfront.c             |   6 +--
>  tpm_tis.c              |  23 ++++-----
>  tpmfront.c             |  33 +++++++------
>  10 files changed, 119 insertions(+), 153 deletions(-)
> 
> -- 
> 2.26.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 01/15] mini-os: split struct file definition from its usage
  2022-01-06 11:57 ` [PATCH 01/15] mini-os: split struct file definition from its usage Juergen Gross
@ 2022-01-09  1:17   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:17 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:27 +0100, a ecrit:
> Make the struct file definition standalone and use it for the
> declaration of the files array.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index 39d6a18..a638bc9 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -181,7 +181,7 @@ struct evtchn_port_info {
>          int bound;
>  };
>  
> -extern struct file {
> +struct file {
>      enum fd_type type;
>      union {
>  	struct {
> @@ -236,7 +236,9 @@ extern struct file {
>  #endif
>      };
>      int read;	/* maybe available for read */
> -} files[];
> +};
> +
> +extern struct file files[];
>  
>  int alloc_fd(enum fd_type type);
>  void close_all_files(void);
> -- 
> 2.26.2
> 

-- 
Samuel
> C'est vrai. FreeBSD pourrait être bien s'il avait une licence
> correcte.
Oh, mon troll-ô-meter vient d'exploser...
-+- OR in Guide du linuxien pervers - "Bien regler son troll-ô-meter"


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-06 11:57 ` [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part Juergen Gross
@ 2022-01-09  1:18   ` Samuel Thibault
  2022-01-09  1:21     ` Samuel Thibault
  0 siblings, 1 reply; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:18 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:28 +0100, a ecrit:
> The read member of struct file should be bool.
> 
> In order to have the device specific part at the end of the structure
> move "read" ahead of that.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  blkfront.c             |  4 ++--
>  console/xencons_ring.c |  2 +-
>  fbfront.c              | 12 ++++++------
>  include/lib.h          |  3 ++-
>  netfront.c             |  4 ++--
>  tpm_tis.c              |  2 +-
>  tpmfront.c             |  6 +++---
>  7 files changed, 17 insertions(+), 16 deletions(-)
> 
> diff --git a/blkfront.c b/blkfront.c
> index 834a978..7c8eb74 100644
> --- a/blkfront.c
> +++ b/blkfront.c
> @@ -62,7 +62,7 @@ void blkfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
>      int fd = dev->fd;
>  
>      if (fd != -1)
> -        files[fd].read = 1;
> +        files[fd].read = true;
>  #endif
>      wake_up(&blkfront_queue);
>  }
> @@ -484,7 +484,7 @@ int blkfront_aio_poll(struct blkfront_dev *dev)
>  moretodo:
>  #ifdef HAVE_LIBC
>      if (dev->fd != -1) {
> -        files[dev->fd].read = 0;
> +        files[dev->fd].read = false;
>          mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
>      }
>  #endif
> diff --git a/console/xencons_ring.c b/console/xencons_ring.c
> index b6db74e..c348f3c 100644
> --- a/console/xencons_ring.c
> +++ b/console/xencons_ring.c
> @@ -102,7 +102,7 @@ void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data)
>          int fd = dev ? dev->fd : -1;
>  
>          if (fd != -1)
> -            files[fd].read = 1;
> +            files[fd].read = true;
>  
>          wake_up(&console_queue);
>  #else
> diff --git a/fbfront.c b/fbfront.c
> index d3b3848..6725da1 100644
> --- a/fbfront.c
> +++ b/fbfront.c
> @@ -45,7 +45,7 @@ void kbdfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
>      int fd = dev->fd;
>  
>      if (fd != -1)
> -        files[fd].read = 1;
> +        files[fd].read = true;
>  #endif
>      wake_up(&kbdfront_queue);
>  }
> @@ -207,7 +207,7 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n
>  
>  #ifdef HAVE_LIBC
>      if (dev->fd != -1) {
> -        files[dev->fd].read = 0;
> +        files[dev->fd].read = false;
>          mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
>      }
>  #endif
> @@ -229,7 +229,7 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n
>  #ifdef HAVE_LIBC
>      if (cons != prod && dev->fd != -1)
>          /* still some events to read */
> -        files[dev->fd].read = 1;
> +        files[dev->fd].read = true;
>  #endif
>  
>      return i;
> @@ -349,7 +349,7 @@ void fbfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
>      int fd = dev->fd;
>  
>      if (fd != -1)
> -        files[fd].read = 1;
> +        files[fd].read = true;
>  #endif
>      wake_up(&fbfront_queue);
>  }
> @@ -376,7 +376,7 @@ int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
>  
>  #ifdef HAVE_LIBC
>      if (dev->fd != -1) {
> -        files[dev->fd].read = 0;
> +        files[dev->fd].read = false;
>          mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
>      }
>  #endif
> @@ -398,7 +398,7 @@ int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
>  #ifdef HAVE_LIBC
>      if (cons != prod && dev->fd != -1)
>          /* still some events to read */
> -        files[dev->fd].read = 1;
> +        files[dev->fd].read = true;
>  #endif
>  
>      return i;
> diff --git a/include/lib.h b/include/lib.h
> index a638bc9..df2de9e 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -49,6 +49,7 @@
>  #define _LIB_H_
>  
>  #include <stdarg.h>
> +#include <stdbool.h>
>  #include <stddef.h>
>  #include <xen/xen.h>
>  #include <xen/event_channel.h>
> @@ -183,6 +184,7 @@ struct evtchn_port_info {
>  
>  struct file {
>      enum fd_type type;
> +    bool read;	/* maybe available for read */
>      union {
>  	struct {
>              /* lwIP fd */
> @@ -235,7 +237,6 @@ struct file {
>          } xenbus;
>  #endif
>      };
> -    int read;	/* maybe available for read */
>  };
>  
>  extern struct file files[];
> diff --git a/netfront.c b/netfront.c
> index dfe065b..a566e34 100644
> --- a/netfront.c
> +++ b/netfront.c
> @@ -255,7 +255,7 @@ void netfront_select_handler(evtchn_port_t port, struct pt_regs *regs, void *dat
>      local_irq_restore(flags);
>  
>      if (fd != -1)
> -        files[fd].read = 1;
> +        files[fd].read = true;
>      wake_up(&netfront_queue);
>  }
>  #endif
> @@ -783,7 +783,7 @@ ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t l
>      network_rx(dev);
>      if (!dev->rlen && fd != -1)
>          /* No data for us, make select stop returning */
> -        files[fd].read = 0;
> +        files[fd].read = false;
>      /* Before re-enabling the interrupts, in case a packet just arrived in the
>       * meanwhile. */
>      local_irq_restore(flags);
> diff --git a/tpm_tis.c b/tpm_tis.c
> index 475ac5d..4a51027 100644
> --- a/tpm_tis.c
> +++ b/tpm_tis.c
> @@ -845,7 +845,7 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
>     }
>  #ifdef HAVE_LIBC
>     if(tpm->fd >= 0) {
> -      files[tpm->fd].read = 0;
> +      files[tpm->fd].read = false;
>        files[tpm->fd].tpm_tis.respgot = 0;
>        files[tpm->fd].tpm_tis.offset = 0;
>     }
> diff --git a/tpmfront.c b/tpmfront.c
> index 6049244..d825b49 100644
> --- a/tpmfront.c
> +++ b/tpmfront.c
> @@ -66,7 +66,7 @@ void tpmfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data) {
>     dev->waiting = 0;
>  #ifdef HAVE_LIBC
>     if(dev->fd >= 0) {
> -      files[dev->fd].read = 1;
> +      files[dev->fd].read = true;
>     }
>  #endif
>     wake_up(&dev->waitq);
> @@ -438,7 +438,7 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
>     dev->resplen = 0;
>  #ifdef HAVE_LIBC
>     if(dev->fd >= 0) {
> -      files[dev->fd].read = 0;
> +      files[dev->fd].read = false;
>        files[dev->fd].tpmfront.respgot = 0;
>        files[dev->fd].tpmfront.offset = 0;
>     }
> @@ -611,7 +611,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
>  
>     /* If we have a response waiting, then read it now from the backend
>      * so we can get its length*/
> -   if(dev->waiting || (files[dev->fd].read == 1 && !files[dev->fd].tpmfront.respgot)) {
> +   if(dev->waiting || (files[dev->fd].read && !files[dev->fd].tpmfront.respgot)) {
>        if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
>  	 errno = EIO;
>  	 return -1;
> -- 
> 2.26.2
> 

-- 
Samuel
> No manual is ever necessary.
May I politely interject here: BULLSHIT.  That's the biggest Apple lie of all!
(Discussion in comp.os.linux.misc on the intuitiveness of interfaces.)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-09  1:18   ` Samuel Thibault
@ 2022-01-09  1:21     ` Samuel Thibault
  2022-01-09  6:12       ` Juergen Gross
  0 siblings, 1 reply; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:21 UTC (permalink / raw)
  To: Juergen Gross, minios-devel, xen-devel, wl

Samuel Thibault, le dim. 09 janv. 2022 02:18:44 +0100, a ecrit:
> Juergen Gross, le jeu. 06 janv. 2022 12:57:28 +0100, a ecrit:
> > The read member of struct file should be bool.
> > 
> > In order to have the device specific part at the end of the structure
> > move "read" ahead of that.
> > 
> > Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Mmm, but tools/libs/evtchn/minios.c needs updating, doesn't it?

> > ---
> >  blkfront.c             |  4 ++--
> >  console/xencons_ring.c |  2 +-
> >  fbfront.c              | 12 ++++++------
> >  include/lib.h          |  3 ++-
> >  netfront.c             |  4 ++--
> >  tpm_tis.c              |  2 +-
> >  tpmfront.c             |  6 +++---
> >  7 files changed, 17 insertions(+), 16 deletions(-)
> > 
> > diff --git a/blkfront.c b/blkfront.c
> > index 834a978..7c8eb74 100644
> > --- a/blkfront.c
> > +++ b/blkfront.c
> > @@ -62,7 +62,7 @@ void blkfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
> >      int fd = dev->fd;
> >  
> >      if (fd != -1)
> > -        files[fd].read = 1;
> > +        files[fd].read = true;
> >  #endif
> >      wake_up(&blkfront_queue);
> >  }
> > @@ -484,7 +484,7 @@ int blkfront_aio_poll(struct blkfront_dev *dev)
> >  moretodo:
> >  #ifdef HAVE_LIBC
> >      if (dev->fd != -1) {
> > -        files[dev->fd].read = 0;
> > +        files[dev->fd].read = false;
> >          mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
> >      }
> >  #endif
> > diff --git a/console/xencons_ring.c b/console/xencons_ring.c
> > index b6db74e..c348f3c 100644
> > --- a/console/xencons_ring.c
> > +++ b/console/xencons_ring.c
> > @@ -102,7 +102,7 @@ void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data)
> >          int fd = dev ? dev->fd : -1;
> >  
> >          if (fd != -1)
> > -            files[fd].read = 1;
> > +            files[fd].read = true;
> >  
> >          wake_up(&console_queue);
> >  #else
> > diff --git a/fbfront.c b/fbfront.c
> > index d3b3848..6725da1 100644
> > --- a/fbfront.c
> > +++ b/fbfront.c
> > @@ -45,7 +45,7 @@ void kbdfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
> >      int fd = dev->fd;
> >  
> >      if (fd != -1)
> > -        files[fd].read = 1;
> > +        files[fd].read = true;
> >  #endif
> >      wake_up(&kbdfront_queue);
> >  }
> > @@ -207,7 +207,7 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n
> >  
> >  #ifdef HAVE_LIBC
> >      if (dev->fd != -1) {
> > -        files[dev->fd].read = 0;
> > +        files[dev->fd].read = false;
> >          mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
> >      }
> >  #endif
> > @@ -229,7 +229,7 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n
> >  #ifdef HAVE_LIBC
> >      if (cons != prod && dev->fd != -1)
> >          /* still some events to read */
> > -        files[dev->fd].read = 1;
> > +        files[dev->fd].read = true;
> >  #endif
> >  
> >      return i;
> > @@ -349,7 +349,7 @@ void fbfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
> >      int fd = dev->fd;
> >  
> >      if (fd != -1)
> > -        files[fd].read = 1;
> > +        files[fd].read = true;
> >  #endif
> >      wake_up(&fbfront_queue);
> >  }
> > @@ -376,7 +376,7 @@ int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
> >  
> >  #ifdef HAVE_LIBC
> >      if (dev->fd != -1) {
> > -        files[dev->fd].read = 0;
> > +        files[dev->fd].read = false;
> >          mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
> >      }
> >  #endif
> > @@ -398,7 +398,7 @@ int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
> >  #ifdef HAVE_LIBC
> >      if (cons != prod && dev->fd != -1)
> >          /* still some events to read */
> > -        files[dev->fd].read = 1;
> > +        files[dev->fd].read = true;
> >  #endif
> >  
> >      return i;
> > diff --git a/include/lib.h b/include/lib.h
> > index a638bc9..df2de9e 100644
> > --- a/include/lib.h
> > +++ b/include/lib.h
> > @@ -49,6 +49,7 @@
> >  #define _LIB_H_
> >  
> >  #include <stdarg.h>
> > +#include <stdbool.h>
> >  #include <stddef.h>
> >  #include <xen/xen.h>
> >  #include <xen/event_channel.h>
> > @@ -183,6 +184,7 @@ struct evtchn_port_info {
> >  
> >  struct file {
> >      enum fd_type type;
> > +    bool read;	/* maybe available for read */
> >      union {
> >  	struct {
> >              /* lwIP fd */
> > @@ -235,7 +237,6 @@ struct file {
> >          } xenbus;
> >  #endif
> >      };
> > -    int read;	/* maybe available for read */
> >  };
> >  
> >  extern struct file files[];
> > diff --git a/netfront.c b/netfront.c
> > index dfe065b..a566e34 100644
> > --- a/netfront.c
> > +++ b/netfront.c
> > @@ -255,7 +255,7 @@ void netfront_select_handler(evtchn_port_t port, struct pt_regs *regs, void *dat
> >      local_irq_restore(flags);
> >  
> >      if (fd != -1)
> > -        files[fd].read = 1;
> > +        files[fd].read = true;
> >      wake_up(&netfront_queue);
> >  }
> >  #endif
> > @@ -783,7 +783,7 @@ ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t l
> >      network_rx(dev);
> >      if (!dev->rlen && fd != -1)
> >          /* No data for us, make select stop returning */
> > -        files[fd].read = 0;
> > +        files[fd].read = false;
> >      /* Before re-enabling the interrupts, in case a packet just arrived in the
> >       * meanwhile. */
> >      local_irq_restore(flags);
> > diff --git a/tpm_tis.c b/tpm_tis.c
> > index 475ac5d..4a51027 100644
> > --- a/tpm_tis.c
> > +++ b/tpm_tis.c
> > @@ -845,7 +845,7 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
> >     }
> >  #ifdef HAVE_LIBC
> >     if(tpm->fd >= 0) {
> > -      files[tpm->fd].read = 0;
> > +      files[tpm->fd].read = false;
> >        files[tpm->fd].tpm_tis.respgot = 0;
> >        files[tpm->fd].tpm_tis.offset = 0;
> >     }
> > diff --git a/tpmfront.c b/tpmfront.c
> > index 6049244..d825b49 100644
> > --- a/tpmfront.c
> > +++ b/tpmfront.c
> > @@ -66,7 +66,7 @@ void tpmfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data) {
> >     dev->waiting = 0;
> >  #ifdef HAVE_LIBC
> >     if(dev->fd >= 0) {
> > -      files[dev->fd].read = 1;
> > +      files[dev->fd].read = true;
> >     }
> >  #endif
> >     wake_up(&dev->waitq);
> > @@ -438,7 +438,7 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
> >     dev->resplen = 0;
> >  #ifdef HAVE_LIBC
> >     if(dev->fd >= 0) {
> > -      files[dev->fd].read = 0;
> > +      files[dev->fd].read = false;
> >        files[dev->fd].tpmfront.respgot = 0;
> >        files[dev->fd].tpmfront.offset = 0;
> >     }
> > @@ -611,7 +611,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
> >  
> >     /* If we have a response waiting, then read it now from the backend
> >      * so we can get its length*/
> > -   if(dev->waiting || (files[dev->fd].read == 1 && !files[dev->fd].tpmfront.respgot)) {
> > +   if(dev->waiting || (files[dev->fd].read && !files[dev->fd].tpmfront.respgot)) {
> >        if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
> >  	 errno = EIO;
> >  	 return -1;
> > -- 
> > 2.26.2
> > 
> 
> -- 
> Samuel
> > No manual is ever necessary.
> May I politely interject here: BULLSHIT.  That's the biggest Apple lie of all!
> (Discussion in comp.os.linux.misc on the intuitiveness of interfaces.)

-- 
Samuel
<c> xlnt comme sujet de stage je peux essayer de donner une description formelle de automake
 -+- #ens-mim -+-


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 03/15] mini-os: make offset a common struct file member for all types
  2022-01-06 11:57 ` [PATCH 03/15] mini-os: make offset a common struct file member for all types Juergen Gross
@ 2022-01-09  1:23   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:23 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:29 +0100, a ecrit:
> Currently 4 file types have an offset member in their private struct
> file part. Make offset a common struct member shared by all file types.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  blkfront.c    |  5 ++---
>  include/lib.h |  5 +----
>  lib/sys.c     | 14 +++++---------
>  tpm_tis.c     | 11 +++++------
>  tpmfront.c    | 11 +++++------
>  5 files changed, 18 insertions(+), 28 deletions(-)
> 
> diff --git a/blkfront.c b/blkfront.c
> index 7c8eb74..8137106 100644
> --- a/blkfront.c
> +++ b/blkfront.c
> @@ -563,14 +563,13 @@ int blkfront_open(struct blkfront_dev *dev)
>      dev->fd = alloc_fd(FTYPE_BLK);
>      printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
>      files[dev->fd].blk.dev = dev;
> -    files[dev->fd].blk.offset = 0;
>      return dev->fd;
>  }
>  
>  int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
>  {
>     struct blkfront_dev* dev = files[fd].blk.dev;
> -   off_t offset = files[fd].blk.offset;
> +   off_t offset = files[fd].offset;
>     struct blkfront_aiocb aiocb;
>     unsigned long long disksize = dev->info.sectors * dev->info.sector_size;
>     unsigned int blocksize = dev->info.sector_size;
> @@ -712,7 +711,7 @@ int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
>     }
>  
>     free(copybuf);
> -   files[fd].blk.offset += rc;
> +   files[fd].offset += rc;
>     return rc;
>  
>  }
> diff --git a/include/lib.h b/include/lib.h
> index df2de9e..4d9b14b 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -185,6 +185,7 @@ struct evtchn_port_info {
>  struct file {
>      enum fd_type type;
>      bool read;	/* maybe available for read */
> +    off_t offset;
>      union {
>  	struct {
>              /* lwIP fd */
> @@ -193,7 +194,6 @@ struct file {
>  	struct {
>              /* FS import fd */
>  	    int fd;
> -	    off_t offset;
>  	} file;
>  	struct {
>  	    struct evtchn_port_list ports;
> @@ -204,7 +204,6 @@ struct file {
>  	} tap;
>  	struct {
>  	    struct blkfront_dev *dev;
> -            off_t offset;
>  	} blk;
>  	struct {
>  	    struct kbdfront_dev *dev;
> @@ -219,14 +218,12 @@ struct file {
>  	struct {
>  	   struct tpmfront_dev *dev;
>  	   int respgot;
> -	   off_t offset;
>  	} tpmfront;
>  #endif
>  #ifdef CONFIG_TPM_TIS
>  	struct {
>  	   struct tpm_chip *dev;
>  	   int respgot;
> -	   off_t offset;
>  	} tpm_tis;
>  #endif
>  #ifdef CONFIG_XENBUS
> diff --git a/lib/sys.c b/lib/sys.c
> index e8d5eb2..e1cea70 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -107,6 +107,7 @@ int alloc_fd(enum fd_type type)
>      for (i=0; i<NOFILE; i++) {
>  	if (files[i].type == FTYPE_NONE) {
>  	    files[i].type = type;
> +            files[i].offset = 0;
>  	    pthread_mutex_unlock(&fd_lock);
>  	    return i;
>  	}
> @@ -363,25 +364,20 @@ int write(int fd, const void *buf, size_t nbytes)
>  
>  off_t lseek(int fd, off_t offset, int whence)
>  {
> -    off_t* target = NULL;
>      switch(files[fd].type) {
>  #ifdef CONFIG_BLKFRONT
>         case FTYPE_BLK:
> -          target = &files[fd].blk.offset;
>            break;
>  #endif
>  #ifdef CONFIG_TPMFRONT
>         case FTYPE_TPMFRONT:
> -          target = &files[fd].tpmfront.offset;
>            break;
>  #endif
>  #ifdef CONFIG_TPM_TIS
>         case FTYPE_TPM_TIS:
> -          target = &files[fd].tpm_tis.offset;
>            break;
>  #endif
>         case FTYPE_FILE:
> -          target = &files[fd].file.offset;
>            break;
>         default:
>            /* Not implemented for this filetype */
> @@ -391,10 +387,10 @@ off_t lseek(int fd, off_t offset, int whence)
>  
>      switch (whence) {
>         case SEEK_SET:
> -          *target = offset;
> +          files[fd].offset = offset;
>            break;
>         case SEEK_CUR:
> -          *target += offset;
> +          files[fd].offset += offset;
>            break;
>         case SEEK_END:
>            {
> @@ -403,14 +399,14 @@ off_t lseek(int fd, off_t offset, int whence)
>               ret = fstat(fd, &st);
>               if (ret)
>                  return -1;
> -             *target = st.st_size + offset;
> +             files[fd].offset = st.st_size + offset;
>               break;
>            }
>         default:
>            errno = EINVAL;
>            return -1;
>      }
> -    return *target;
> +    return files[fd].offset;
>  }
>  
>  int fsync(int fd) {
> diff --git a/tpm_tis.c b/tpm_tis.c
> index 4a51027..8a632b1 100644
> --- a/tpm_tis.c
> +++ b/tpm_tis.c
> @@ -847,7 +847,7 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
>     if(tpm->fd >= 0) {
>        files[tpm->fd].read = false;
>        files[tpm->fd].tpm_tis.respgot = 0;
> -      files[tpm->fd].tpm_tis.offset = 0;
> +      files[tpm->fd].offset = 0;
>     }
>  #endif
>     return len;
> @@ -1290,7 +1290,6 @@ int tpm_tis_open(struct tpm_chip* tpm)
>     tpm->fd = alloc_fd(FTYPE_TPM_TIS);
>     printk("tpm_tis_open() -> %d\n", tpm->fd);
>     files[tpm->fd].tpm_tis.dev = tpm;
> -   files[tpm->fd].tpm_tis.offset = 0;
>     files[tpm->fd].tpm_tis.respgot = 0;
>     return tpm->fd;
>  }
> @@ -1340,13 +1339,13 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count)
>  
>  
>     /* Handle EOF case */
> -   if(files[fd].tpm_tis.offset >= tpm->data_len) {
> +   if(files[fd].offset >= tpm->data_len) {
>        rc = 0;
>     } else {
> -      rc = min(tpm->data_len - files[fd].tpm_tis.offset, count);
> -      memcpy(buf, tpm->data_buffer + files[fd].tpm_tis.offset, rc);
> +      rc = min(tpm->data_len - files[fd].offset, count);
> +      memcpy(buf, tpm->data_buffer + files[fd].offset, rc);
>     }
> -   files[fd].tpm_tis.offset += rc;
> +   files[fd].offset += rc;
>     /* Reset the data pending flag */
>     return rc;
>  }
> diff --git a/tpmfront.c b/tpmfront.c
> index d825b49..8b2a910 100644
> --- a/tpmfront.c
> +++ b/tpmfront.c
> @@ -440,7 +440,7 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
>     if(dev->fd >= 0) {
>        files[dev->fd].read = false;
>        files[dev->fd].tpmfront.respgot = 0;
> -      files[dev->fd].tpmfront.offset = 0;
> +      files[dev->fd].offset = 0;
>     }
>  #endif
>     wmb();
> @@ -539,7 +539,6 @@ int tpmfront_open(struct tpmfront_dev* dev)
>     dev->fd = alloc_fd(FTYPE_TPMFRONT);
>     printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
>     files[dev->fd].tpmfront.dev = dev;
> -   files[dev->fd].tpmfront.offset = 0;
>     files[dev->fd].tpmfront.respgot = 0;
>     return dev->fd;
>  }
> @@ -589,14 +588,14 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t count)
>     }
>  
>     /* handle EOF case */
> -   if(files[dev->fd].tpmfront.offset >= dev->resplen) {
> +   if(files[dev->fd].offset >= dev->resplen) {
>        return 0;
>     }
>  
>     /* Compute the number of bytes and do the copy operation */
> -   if((rc = min(count, dev->resplen - files[dev->fd].tpmfront.offset)) != 0) {
> -      memcpy(buf, dev->respbuf + files[dev->fd].tpmfront.offset, rc);
> -      files[dev->fd].tpmfront.offset += rc;
> +   if((rc = min(count, dev->resplen - files[dev->fd].offset)) != 0) {
> +      memcpy(buf, dev->respbuf + files[dev->fd].offset, rc);
> +      files[dev->fd].offset += rc;
>     }
>  
>     return rc;
> -- 
> 2.26.2
> 

-- 
Samuel
`When you say "I wrote a program that crashed Windows", people just stare at
you blankly and say "Hey, I got those with the system, *for free*".'
(By Linus Torvalds)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 04/15] mini-os: replace multiple fd elements in struct file by common one
  2022-01-06 11:57 ` [PATCH 04/15] mini-os: replace multiple fd elements in struct file by common one Juergen Gross
@ 2022-01-09  1:25   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:25 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:30 +0100, a ecrit:
> The type specific union in struct files contains two instances of
> "int fd". Replace them by a common one.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  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 = lwip_close(files[fd].socket.fd);
> +	    int res = lwip_close(files[fd].fd);
>  	    files[fd].type = FTYPE_NONE;
>  	    return res;
>  	}
> @@ -594,7 +594,7 @@ int fcntl(int fd, int cmd, ...)
>  	    if (files[fd].type == FTYPE_SOCKET && !(arg & ~O_NONBLOCK)) {
>  		/* Only flag supported: non-blocking mode */
>  		uint32_t nblock = !!(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 = 0; i < nfds; i++) {
>  	if (files[i].type == FTYPE_SOCKET) {
>  	    if (FD_ISSET(i, readfds)) {
> -		FD_SET(files[i].socket.fd, &sock_readfds);
> +		FD_SET(files[i].fd, &sock_readfds);
>  		sock_nfds = i+1;
>  	    }
>  	    if (FD_ISSET(i, writefds)) {
> -		FD_SET(files[i].socket.fd, &sock_writefds);
> +		FD_SET(files[i].fd, &sock_writefds);
>  		sock_nfds = i+1;
>  	    }
>  	    if (FD_ISSET(i, exceptfds)) {
> -		FD_SET(files[i].socket.fd, &sock_exceptfds);
> +		FD_SET(files[i].fd, &sock_exceptfds);
>  		sock_nfds = 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 = alloc_fd(FTYPE_SOCKET);
>      printk("socket -> %d\n", res);
> -    files[res].socket.fd = fd;
> +    files[res].fd = fd;
>      return res;
>  }
>  
> @@ -1124,11 +1124,11 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
>  	errno = EBADF;
>  	return -1;
>      }
> -    fd = lwip_accept(files[s].socket.fd, addr, addrlen);
> +    fd = lwip_accept(files[s].fd, addr, addrlen);
>      if (fd < 0)
>  	return -1;
>      res = alloc_fd(FTYPE_SOCKET);
> -    files[res].socket.fd = fd;
> +    files[res].fd = fd;
>      printk("accepted on %d -> %d\n", s, res);
>      return res;
>  }
> @@ -1141,7 +1141,7 @@ ret name proto \
>  	errno = EBADF; \
>  	return -1; \
>      } \
> -    s = files[s].socket.fd; \
> +    s = files[s].fd; \
>      return lwip_##name args; \
>  }
>  
> -- 
> 2.26.2
> 

-- 
Samuel
<c> xlnt comme sujet de stage je peux essayer de donner une description formelle de automake
 -+- #ens-mim -+-


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 05/15] mini-os: introduce a common dev pointer in struct file
  2022-01-06 11:57 ` [PATCH 05/15] mini-os: introduce a common dev pointer in struct file Juergen Gross
@ 2022-01-09  1:25   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:25 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:31 +0100, a ecrit:
> There are many dev pointers in a union in struct file. Prepare to
> switch to a single one by introducing a new common one.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/lib.h b/include/lib.h
> index dc56f52..60aaf1c 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -188,6 +188,7 @@ struct file {
>      off_t offset;
>      union {
>          int fd; /* Any fd from an upper layer. */
> +        void *dev;
>  	struct {
>  	    struct evtchn_port_list ports;
>  	} evtchn;
> -- 
> 2.26.2
> 

-- 
Samuel
Now I know someone out there is going to claim, "Well then, UNIX is intuitive,
because you only need to learn 5000 commands, and then everything else follows
from that! Har har har!"
(Andy Bates in comp.os.linux.misc, on "intuitive interfaces", slightly
defending Macs.)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 06/15] mini-os: eliminate blkfront union member in struct file
  2022-01-06 11:57 ` [PATCH 06/15] mini-os: eliminate blkfront union member " Juergen Gross
@ 2022-01-09  1:26   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:26 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:32 +0100, a ecrit:
> Replace the blkfront specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  blkfront.c    | 6 +++---
>  include/lib.h | 3 ---
>  lib/sys.c     | 2 +-
>  3 files changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/blkfront.c b/blkfront.c
> index 8137106..e3f42be 100644
> --- a/blkfront.c
> +++ b/blkfront.c
> @@ -562,13 +562,13 @@ int blkfront_open(struct blkfront_dev *dev)
>      }
>      dev->fd = alloc_fd(FTYPE_BLK);
>      printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
> -    files[dev->fd].blk.dev = dev;
> +    files[dev->fd].dev = dev;
>      return dev->fd;
>  }
>  
>  int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
>  {
> -   struct blkfront_dev* dev = files[fd].blk.dev;
> +   struct blkfront_dev* dev = files[fd].dev;
>     off_t offset = files[fd].offset;
>     struct blkfront_aiocb aiocb;
>     unsigned long long disksize = dev->info.sectors * dev->info.sector_size;
> @@ -718,7 +718,7 @@ int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write)
>  
>  int blkfront_posix_fstat(int fd, struct stat* buf)
>  {
> -   struct blkfront_dev* dev = files[fd].blk.dev;
> +   struct blkfront_dev* dev = files[fd].dev;
>  
>     buf->st_mode = dev->info.mode;
>     buf->st_uid = 0;
> diff --git a/include/lib.h b/include/lib.h
> index 60aaf1c..3a40634 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -196,9 +196,6 @@ struct file {
>  	struct {
>  	    struct netfront_dev *dev;
>  	} tap;
> -	struct {
> -	    struct blkfront_dev *dev;
> -	} blk;
>  	struct {
>  	    struct kbdfront_dev *dev;
>  	} kbd;
> diff --git a/lib/sys.c b/lib/sys.c
> index 1da7401..f2fdbdf 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -456,7 +456,7 @@ int close(int fd)
>  #endif
>  #ifdef CONFIG_BLKFRONT
>  	case FTYPE_BLK:
> -            shutdown_blkfront(files[fd].blk.dev);
> +            shutdown_blkfront(files[fd].dev);
>  	    files[fd].type = FTYPE_NONE;
>  	    return 0;
>  #endif
> -- 
> 2.26.2
> 

-- 
Samuel
Accroche-toi au terminal, j'enlève le shell...
 -+- nojhan -+-


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 07/15] mini-os: eliminate consfront union member in struct file
  2022-01-06 11:57 ` [PATCH 07/15] mini-os: eliminate consfront " Juergen Gross
@ 2022-01-09  1:27   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:27 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:33 +0100, a ecrit:
> Replace the consfront specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h |  3 ---
>  lib/sys.c     | 31 +++++++++++++++++--------------
>  2 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index 3a40634..0cedae6 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -202,9 +202,6 @@ struct file {
>  	struct {
>  	    struct fbfront_dev *dev;
>  	} fb;
> -	struct {
> -	    struct consfront_dev *dev;
> -	} cons;
>  #ifdef CONFIG_TPMFRONT
>  	struct {
>  	   struct tpmfront_dev *dev;
> diff --git a/lib/sys.c b/lib/sys.c
> index f2fdbdf..62c2020 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -179,7 +179,7 @@ int posix_openpt(int flags)
>  
>      dev = init_consfront(NULL);
>      dev->fd = alloc_fd(FTYPE_CONSOLE);
> -    files[dev->fd].cons.dev = dev;
> +    files[dev->fd].dev = dev;
>  
>      printk("fd(%d) = posix_openpt\n", dev->fd);
>      return(dev->fd);
> @@ -194,7 +194,7 @@ int open_savefile(const char *path, int save)
>  
>      dev = init_consfront(nodename);
>      dev->fd = alloc_fd(FTYPE_SAVEFILE);
> -    files[dev->fd].cons.dev = dev;
> +    files[dev->fd].dev = dev;
>  
>      printk("fd(%d) = open_savefile\n", dev->fd);
>      return(dev->fd);
> @@ -248,7 +248,7 @@ int read(int fd, void *buf, size_t nbytes)
>              DEFINE_WAIT(w);
>              while(1) {
>                  add_waiter(w, console_queue);
> -                ret = xencons_ring_recv(files[fd].cons.dev, buf, nbytes);
> +                ret = xencons_ring_recv(files[fd].dev, buf, nbytes);
>                  if (ret)
>                      break;
>                  schedule();
> @@ -324,14 +324,14 @@ int write(int fd, const void *buf, size_t nbytes)
>          case FTYPE_SAVEFILE: {
>                  int ret = 0, tot = nbytes;
>                  while (nbytes > 0) {
> -                    ret = xencons_ring_send(files[fd].cons.dev, (char *)buf, nbytes);
> +                    ret = xencons_ring_send(files[fd].dev, (char *)buf, nbytes);
>                      nbytes -= ret;
>                      buf = (char *)buf + ret;
>                  }
>                  return tot - nbytes;
>              }
>  	case FTYPE_CONSOLE:
> -	    console_print(files[fd].cons.dev, (char *)buf, nbytes);
> +	    console_print(files[fd].dev, (char *)buf, nbytes);
>  	    return nbytes;
>  #ifdef HAVE_LWIP
>  	case FTYPE_SOCKET:
> @@ -487,7 +487,7 @@ int close(int fd)
>  #ifdef CONFIG_CONSFRONT
>          case FTYPE_SAVEFILE:
>          case FTYPE_CONSOLE:
> -            fini_consfront(files[fd].cons.dev);
> +            fini_consfront(files[fd].dev);
>              files[fd].type = FTYPE_NONE;
>              return 0;
>  #endif
> @@ -764,7 +764,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce
>  	    /* Fallthrough.  */
>  	case FTYPE_CONSOLE:
>  	    if (FD_ISSET(i, readfds)) {
> -                if (xencons_ring_avail(files[i].cons.dev))
> +                if (xencons_ring_avail(files[i].dev))
>  		    n++;
>  		else
>  		    FD_CLR(i, readfds);
> @@ -1447,6 +1447,8 @@ const struct termios default_termios = {0,             /* iflag */
>  
>  int tcsetattr(int fildes, int action, const struct termios *tios)
>  {
> +    struct consfront_dev *dev;
> +
>      if (fildes < 0 || fildes >= NOFILE) {
>          errno = EBADF;
>          return -1;
> @@ -1472,21 +1474,21 @@ int tcsetattr(int fildes, int action, const struct termios *tios)
>              return -1;
>      }
>  
> -    if (files[fildes].cons.dev == NULL) {
> +    dev = files[fildes].dev;
> +    if (dev == NULL) {
>          errno = ENOSYS;
>          return -1;
>      }
>  
> -    if (tios->c_oflag & OPOST)
> -        files[fildes].cons.dev->is_raw = false;
> -    else
> -        files[fildes].cons.dev->is_raw = true;
> +    dev->is_raw = !(tios->c_oflag & OPOST);
>  
>      return 0;
>  }
>  
>  int tcgetattr(int fildes, struct termios *tios)
>  {
> +    struct consfront_dev *dev;
> +
>      if (fildes < 0 || fildes >= NOFILE) {
>          errno = EBADF;
>          return -1;
> @@ -1497,7 +1499,8 @@ int tcgetattr(int fildes, struct termios *tios)
>          return -1;
>      }
>  
> -    if (files[fildes].cons.dev == NULL) {
> +    dev = files[fildes].dev;
> +    if (dev == NULL) {
>          errno = ENOSYS;
>          return 0;
>      }
> @@ -1509,7 +1512,7 @@ int tcgetattr(int fildes, struct termios *tios)
>  
>      memcpy(tios, &default_termios, sizeof(struct termios));
>  
> -    if (files[fildes].cons.dev->is_raw)
> +    if (dev->is_raw)
>          tios->c_oflag &= ~OPOST;
>  
>      return 0;
> -- 
> 2.26.2
> 

-- 
Samuel
<s> on se croirait en cool : Some browsers close comments on the first ">" character, so to hide script content from such browsers, you can transpose operands for relational and shift operators (e.g., use "y < x" rather than "x > y") or use scripting language-dependent escapes for ">".
 -+- #ens-mim -+-


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 08/15] mini-os: eliminate fbfront union member in struct file
  2022-01-06 11:57 ` [PATCH 08/15] mini-os: eliminate fbfront " Juergen Gross
@ 2022-01-09  1:27   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:27 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:34 +0100, a ecrit:
> Replace the fbfront specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  fbfront.c     | 2 +-
>  include/lib.h | 3 ---
>  lib/sys.c     | 4 ++--
>  3 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/fbfront.c b/fbfront.c
> index 6725da1..c8410af 100644
> --- a/fbfront.c
> +++ b/fbfront.c
> @@ -703,7 +703,7 @@ int fbfront_open(struct fbfront_dev *dev)
>  {
>      dev->fd = alloc_fd(FTYPE_FB);
>      printk("fb_open(%s) -> %d\n", dev->nodename, dev->fd);
> -    files[dev->fd].fb.dev = dev;
> +    files[dev->fd].dev = dev;
>      return dev->fd;
>  }
>  #endif
> diff --git a/include/lib.h b/include/lib.h
> index 0cedae6..2a9a01c 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -199,9 +199,6 @@ struct file {
>  	struct {
>  	    struct kbdfront_dev *dev;
>  	} kbd;
> -	struct {
> -	    struct fbfront_dev *dev;
> -	} fb;
>  #ifdef CONFIG_TPMFRONT
>  	struct {
>  	   struct tpmfront_dev *dev;
> diff --git a/lib/sys.c b/lib/sys.c
> index 62c2020..2d48657 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -287,7 +287,7 @@ int read(int fd, void *buf, size_t nbytes)
>          case FTYPE_FB: {
>              int ret, n;
>              n = nbytes / sizeof(union xenfb_in_event);
> -            ret = fbfront_receive(files[fd].fb.dev, buf, n);
> +            ret = fbfront_receive(files[fd].dev, buf, n);
>  	    if (ret <= 0) {
>  		errno = EAGAIN;
>  		return -1;
> @@ -480,7 +480,7 @@ int close(int fd)
>  #endif
>  #ifdef CONFIG_FBFRONT
>  	case FTYPE_FB:
> -            shutdown_fbfront(files[fd].fb.dev);
> +            shutdown_fbfront(files[fd].dev);
>              files[fd].type = FTYPE_NONE;
>              return 0;
>  #endif
> -- 
> 2.26.2
> 

-- 
Samuel
       La  fonction  memfrob() crypte les n premiers octets de la
       zone de mémoire  s  en  effectuant  un  OU-exclusif  entre
       chaque  octet  et le nombre 42.
(extrait de la page de man de memfrob -- Manuel du programmeur Linux)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 09/15] mini-os: eliminate kbdfront union member in struct file
  2022-01-06 11:57 ` [PATCH 09/15] mini-os: eliminate kbdfront " Juergen Gross
@ 2022-01-09  1:28   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:28 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:35 +0100, a ecrit:
> Replace the kbdfront specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  fbfront.c     | 2 +-
>  include/lib.h | 3 ---
>  lib/sys.c     | 4 ++--
>  3 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/fbfront.c b/fbfront.c
> index c8410af..1e055fb 100644
> --- a/fbfront.c
> +++ b/fbfront.c
> @@ -302,7 +302,7 @@ int kbdfront_open(struct kbdfront_dev *dev)
>  {
>      dev->fd = alloc_fd(FTYPE_KBD);
>      printk("kbd_open(%s) -> %d\n", dev->nodename, dev->fd);
> -    files[dev->fd].kbd.dev = dev;
> +    files[dev->fd].dev = dev;
>      return dev->fd;
>  }
>  #endif
> diff --git a/include/lib.h b/include/lib.h
> index 2a9a01c..5201ed7 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -196,9 +196,6 @@ struct file {
>  	struct {
>  	    struct netfront_dev *dev;
>  	} tap;
> -	struct {
> -	    struct kbdfront_dev *dev;
> -	} kbd;
>  #ifdef CONFIG_TPMFRONT
>  	struct {
>  	   struct tpmfront_dev *dev;
> diff --git a/lib/sys.c b/lib/sys.c
> index 2d48657..8c7ea3c 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -275,7 +275,7 @@ int read(int fd, void *buf, size_t nbytes)
>          case FTYPE_KBD: {
>              int ret, n;
>              n = nbytes / sizeof(union xenkbd_in_event);
> -            ret = kbdfront_receive(files[fd].kbd.dev, buf, n);
> +            ret = kbdfront_receive(files[fd].dev, buf, n);
>  	    if (ret <= 0) {
>  		errno = EAGAIN;
>  		return -1;
> @@ -474,7 +474,7 @@ int close(int fd)
>  #endif
>  #ifdef CONFIG_KBDFRONT
>  	case FTYPE_KBD:
> -            shutdown_kbdfront(files[fd].kbd.dev);
> +            shutdown_kbdfront(files[fd].dev);
>              files[fd].type = FTYPE_NONE;
>              return 0;
>  #endif
> -- 
> 2.26.2
> 

-- 
Samuel
X-Favorit-Cartoon: Calvin and Hobbes
 -+- Mail header of Wim van Dorst -+-


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 10/15] mini-os: eliminate netfront union member in struct file
  2022-01-06 11:57 ` [PATCH 10/15] mini-os: eliminate netfront " Juergen Gross
@ 2022-01-09  1:28   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:28 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:36 +0100, a ecrit:
> Replace the netfront specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h | 3 ---
>  lib/sys.c     | 6 +++---
>  netfront.c    | 2 +-
>  3 files changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index 5201ed7..f2a124e 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -193,9 +193,6 @@ struct file {
>  	    struct evtchn_port_list ports;
>  	} evtchn;
>  	struct gntmap gntmap;
> -	struct {
> -	    struct netfront_dev *dev;
> -	} tap;
>  #ifdef CONFIG_TPMFRONT
>  	struct {
>  	   struct tpmfront_dev *dev;
> diff --git a/lib/sys.c b/lib/sys.c
> index 8c7ea3c..b35e433 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -263,7 +263,7 @@ int read(int fd, void *buf, size_t nbytes)
>  #ifdef CONFIG_NETFRONT
>  	case FTYPE_TAP: {
>  	    ssize_t ret;
> -	    ret = netfront_receive(files[fd].tap.dev, buf, nbytes);
> +	    ret = netfront_receive(files[fd].dev, buf, nbytes);
>  	    if (ret <= 0) {
>  		errno = EAGAIN;
>  		return -1;
> @@ -339,7 +339,7 @@ int write(int fd, const void *buf, size_t nbytes)
>  #endif
>  #ifdef CONFIG_NETFRONT
>  	case FTYPE_TAP:
> -	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
> +	    netfront_xmit(files[fd].dev, (void*) buf, nbytes);
>  	    return nbytes;
>  #endif
>  #ifdef CONFIG_BLKFRONT
> @@ -450,7 +450,7 @@ int close(int fd)
>  #endif
>  #ifdef CONFIG_NETFRONT
>  	case FTYPE_TAP:
> -	    shutdown_netfront(files[fd].tap.dev);
> +	    shutdown_netfront(files[fd].dev);
>  	    files[fd].type = FTYPE_NONE;
>  	    return 0;
>  #endif
> diff --git a/netfront.c b/netfront.c
> index a566e34..7696451 100644
> --- a/netfront.c
> +++ b/netfront.c
> @@ -576,7 +576,7 @@ int netfront_tap_open(char *nodename) {
>      }
>      dev->fd = alloc_fd(FTYPE_TAP);
>      printk("tap_open(%s) -> %d\n", nodename, dev->fd);
> -    files[dev->fd].tap.dev = dev;
> +    files[dev->fd].dev = dev;
>      return dev->fd;
>  }
>  #endif
> -- 
> 2.26.2
> 

-- 
Samuel
<c> tiens, je suis déçu
<c> quand on clique sur le bouton random de http://xkcd.com/221/ on ne tombe pas (toujours) sur http://xkcd.com/4/
<c> bon, j'envoie un bug-report à l'auteur


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 11/15] mini-os: move tpm respgot member of struct file to device specific data
  2022-01-06 11:57 ` [PATCH 11/15] mini-os: move tpm respgot member of struct file to device specific data Juergen Gross
@ 2022-01-09  1:30   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:30 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:37 +0100, a ecrit:
> Tpmfront has a "respgot" flag in struct file, which can be moved to the
> device specific data. While at it make it a bool.
> 
> The respgot flag of the tpm_tis member of struct file can be removed,
> as it is never read.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h      |  2 --
>  include/tpmfront.h |  2 ++
>  tpm_tis.c          |  2 --
>  tpmfront.c         | 10 +++++-----
>  4 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index f2a124e..d740065 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -196,13 +196,11 @@ struct file {
>  #ifdef CONFIG_TPMFRONT
>  	struct {
>  	   struct tpmfront_dev *dev;
> -	   int respgot;
>  	} tpmfront;
>  #endif
>  #ifdef CONFIG_TPM_TIS
>  	struct {
>  	   struct tpm_chip *dev;
> -	   int respgot;
>  	} tpm_tis;
>  #endif
>  #ifdef CONFIG_XENBUS
> diff --git a/include/tpmfront.h b/include/tpmfront.h
> index c489fae..b7da50e 100644
> --- a/include/tpmfront.h
> +++ b/include/tpmfront.h
> @@ -25,6 +25,7 @@
>  #ifndef TPMFRONT_H
>  #define TPMFRONT_H
>  
> +#include <stdbool.h>
>  #include <mini-os/types.h>
>  #include <mini-os/os.h>
>  #include <mini-os/events.h>
> @@ -53,6 +54,7 @@ struct tpmfront_dev {
>  
>  #ifdef HAVE_LIBC
>     int fd;
> +   bool respgot;
>  #endif
>  
>  };
> diff --git a/tpm_tis.c b/tpm_tis.c
> index 8a632b1..4127118 100644
> --- a/tpm_tis.c
> +++ b/tpm_tis.c
> @@ -846,7 +846,6 @@ int tpm_tis_send(struct tpm_chip* tpm, uint8_t* buf, size_t len) {
>  #ifdef HAVE_LIBC
>     if(tpm->fd >= 0) {
>        files[tpm->fd].read = false;
> -      files[tpm->fd].tpm_tis.respgot = 0;
>        files[tpm->fd].offset = 0;
>     }
>  #endif
> @@ -1290,7 +1289,6 @@ int tpm_tis_open(struct tpm_chip* tpm)
>     tpm->fd = alloc_fd(FTYPE_TPM_TIS);
>     printk("tpm_tis_open() -> %d\n", tpm->fd);
>     files[tpm->fd].tpm_tis.dev = tpm;
> -   files[tpm->fd].tpm_tis.respgot = 0;
>     return tpm->fd;
>  }
>  
> diff --git a/tpmfront.c b/tpmfront.c
> index 8b2a910..be671c2 100644
> --- a/tpmfront.c
> +++ b/tpmfront.c
> @@ -439,8 +439,8 @@ int tpmfront_send(struct tpmfront_dev* dev, const uint8_t* msg, size_t length)
>  #ifdef HAVE_LIBC
>     if(dev->fd >= 0) {
>        files[dev->fd].read = false;
> -      files[dev->fd].tpmfront.respgot = 0;
>        files[dev->fd].offset = 0;
> +      dev->respgot = false;
>     }
>  #endif
>     wmb();
> @@ -499,7 +499,7 @@ int i;
>  #endif
>  #ifdef HAVE_LIBC
>     if(dev->fd >= 0) {
> -      files[dev->fd].tpmfront.respgot = 1;
> +      dev->respgot = true;
>     }
>  #endif
>  quit:
> @@ -539,7 +539,7 @@ int tpmfront_open(struct tpmfront_dev* dev)
>     dev->fd = alloc_fd(FTYPE_TPMFRONT);
>     printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
>     files[dev->fd].tpmfront.dev = dev;
> -   files[dev->fd].tpmfront.respgot = 0;
> +   dev->respgot = false;
>     return dev->fd;
>  }
>  
> @@ -580,7 +580,7 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t count)
>     }
>  
>     /* get the response if we haven't already */
> -   if(files[dev->fd].tpmfront.respgot == 0) {
> +   if (!dev->respgot) {
>        if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
>  	 errno = EIO;
>  	 return -1;
> @@ -610,7 +610,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
>  
>     /* If we have a response waiting, then read it now from the backend
>      * so we can get its length*/
> -   if(dev->waiting || (files[dev->fd].read && !files[dev->fd].tpmfront.respgot)) {
> +   if(dev->waiting || (files[dev->fd].read && !dev->respgot)) {
>        if ((rc = tpmfront_recv(dev, &dummybuf, &dummysz)) != 0) {
>  	 errno = EIO;
>  	 return -1;
> -- 
> 2.26.2
> 

-- 
Samuel
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This email was infected under the terms of the GNU General Public License.


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 12/15] mini-os: eliminate tpmfront union member in struct file
  2022-01-06 11:57 ` [PATCH 12/15] mini-os: eliminate tpmfront union member in struct file Juergen Gross
@ 2022-01-09  1:30   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:30 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:38 +0100, a ecrit:
> Replace the tpmfront specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h | 5 -----
>  lib/sys.c     | 2 +-
>  tpmfront.c    | 8 ++++----
>  3 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index d740065..2ddc076 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -193,11 +193,6 @@ struct file {
>  	    struct evtchn_port_list ports;
>  	} evtchn;
>  	struct gntmap gntmap;
> -#ifdef CONFIG_TPMFRONT
> -	struct {
> -	   struct tpmfront_dev *dev;
> -	} tpmfront;
> -#endif
>  #ifdef CONFIG_TPM_TIS
>  	struct {
>  	   struct tpm_chip *dev;
> diff --git a/lib/sys.c b/lib/sys.c
> index b35e433..b042bf5 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -462,7 +462,7 @@ int close(int fd)
>  #endif
>  #ifdef CONFIG_TPMFRONT
>  	case FTYPE_TPMFRONT:
> -            shutdown_tpmfront(files[fd].tpmfront.dev);
> +            shutdown_tpmfront(files[fd].dev);
>  	    files[fd].type = FTYPE_NONE;
>  	    return 0;
>  #endif
> diff --git a/tpmfront.c b/tpmfront.c
> index be671c2..0a2fefc 100644
> --- a/tpmfront.c
> +++ b/tpmfront.c
> @@ -538,7 +538,7 @@ int tpmfront_open(struct tpmfront_dev* dev)
>  
>     dev->fd = alloc_fd(FTYPE_TPMFRONT);
>     printk("tpmfront_open(%s) -> %d\n", dev->nodename, dev->fd);
> -   files[dev->fd].tpmfront.dev = dev;
> +   files[dev->fd].dev = dev;
>     dev->respgot = false;
>     return dev->fd;
>  }
> @@ -547,7 +547,7 @@ int tpmfront_posix_write(int fd, const uint8_t* buf, size_t count)
>  {
>     int rc;
>     struct tpmfront_dev* dev;
> -   dev = files[fd].tpmfront.dev;
> +   dev = files[fd].dev;
>  
>     if(count == 0) {
>        return 0;
> @@ -573,7 +573,7 @@ int tpmfront_posix_read(int fd, uint8_t* buf, size_t count)
>     size_t dummysz;
>     struct tpmfront_dev* dev;
>  
> -   dev = files[fd].tpmfront.dev;
> +   dev = files[fd].dev;
>  
>     if(count == 0) {
>        return 0;
> @@ -606,7 +606,7 @@ int tpmfront_posix_fstat(int fd, struct stat* buf)
>     uint8_t* dummybuf;
>     size_t dummysz;
>     int rc;
> -   struct tpmfront_dev* dev = files[fd].tpmfront.dev;
> +   struct tpmfront_dev* dev = files[fd].dev;
>  
>     /* If we have a response waiting, then read it now from the backend
>      * so we can get its length*/
> -- 
> 2.26.2
> 

-- 
Samuel
/* Halley */

	(Halley's comment.)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 13/15] mini-os: eliminate tpmtis union member in struct file
  2022-01-06 11:57 ` [PATCH 13/15] mini-os: eliminate tpmtis " Juergen Gross
@ 2022-01-09  1:31   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:31 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:39 +0100, a ecrit:
> Replace the tpmtis specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h | 5 -----
>  lib/sys.c     | 2 +-
>  tpm_tis.c     | 8 ++++----
>  3 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index 2ddc076..d6a29ba 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -193,11 +193,6 @@ struct file {
>  	    struct evtchn_port_list ports;
>  	} evtchn;
>  	struct gntmap gntmap;
> -#ifdef CONFIG_TPM_TIS
> -	struct {
> -	   struct tpm_chip *dev;
> -	} tpm_tis;
> -#endif
>  #ifdef CONFIG_XENBUS
>          struct {
>              /* To each xenbus FD is associated a queue of watch events for this
> diff --git a/lib/sys.c b/lib/sys.c
> index b042bf5..96fc769 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -468,7 +468,7 @@ int close(int fd)
>  #endif
>  #ifdef CONFIG_TPM_TIS
>  	case FTYPE_TPM_TIS:
> -            shutdown_tpm_tis(files[fd].tpm_tis.dev);
> +            shutdown_tpm_tis(files[fd].dev);
>  	    files[fd].type = FTYPE_NONE;
>  	    return 0;
>  #endif
> diff --git a/tpm_tis.c b/tpm_tis.c
> index 4127118..477f555 100644
> --- a/tpm_tis.c
> +++ b/tpm_tis.c
> @@ -1288,14 +1288,14 @@ int tpm_tis_open(struct tpm_chip* tpm)
>  
>     tpm->fd = alloc_fd(FTYPE_TPM_TIS);
>     printk("tpm_tis_open() -> %d\n", tpm->fd);
> -   files[tpm->fd].tpm_tis.dev = tpm;
> +   files[tpm->fd].dev = tpm;
>     return tpm->fd;
>  }
>  
>  int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count)
>  {
>     struct tpm_chip* tpm;
> -   tpm = files[fd].tpm_tis.dev;
> +   tpm = files[fd].dev;
>  
>     if(tpm->locality < 0) {
>        printk("tpm_tis_posix_write() failed! locality not set!\n");
> @@ -1323,7 +1323,7 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count)
>  {
>     int rc;
>     struct tpm_chip* tpm;
> -   tpm = files[fd].tpm_tis.dev;
> +   tpm = files[fd].dev;
>  
>     if(count == 0) {
>        return 0;
> @@ -1350,7 +1350,7 @@ int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count)
>  int tpm_tis_posix_fstat(int fd, struct stat* buf)
>  {
>     struct tpm_chip* tpm;
> -   tpm = files[fd].tpm_tis.dev;
> +   tpm = files[fd].dev;
>  
>     buf->st_mode = O_RDWR;
>     buf->st_uid = 0;
> -- 
> 2.26.2
> 

-- 
Samuel
<r> make
<r> oops
<m> make clean


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 14/15] mini-os: eliminate xenbus union member in struct file
  2022-01-06 11:57 ` [PATCH 14/15] mini-os: eliminate xenbus " Juergen Gross
@ 2022-01-09  1:32   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:32 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:40 +0100, a ecrit:
> Replace the xenbus specific union member in struct file with the
> common dev pointer.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h |  7 -------
>  lib/sys.c     |  2 +-
>  lib/xs.c      | 13 +++++++------
>  3 files changed, 8 insertions(+), 14 deletions(-)
> 
> diff --git a/include/lib.h b/include/lib.h
> index d6a29ba..91364ba 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -193,13 +193,6 @@ struct file {
>  	    struct evtchn_port_list ports;
>  	} evtchn;
>  	struct gntmap gntmap;
> -#ifdef CONFIG_XENBUS
> -        struct {
> -            /* To each xenbus FD is associated a queue of watch events for this
> -             * FD.  */
> -            xenbus_event_queue events;
> -        } xenbus;
> -#endif
>      };
>  };
>  
> diff --git a/lib/sys.c b/lib/sys.c
> index 96fc769..6f2b026 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -776,7 +776,7 @@ static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exce
>  #ifdef CONFIG_XENBUS
>  	case FTYPE_XENBUS:
>  	    if (FD_ISSET(i, readfds)) {
> -                if (files[i].xenbus.events)
> +                if (files[i].dev)
>  		    n++;
>  		else
>  		    FD_CLR(i, readfds);
> diff --git a/lib/xs.c b/lib/xs.c
> index 324bd05..0459f52 100644
> --- a/lib/xs.c
> +++ b/lib/xs.c
> @@ -21,8 +21,8 @@ static inline int _xs_fileno(struct xs_handle *h) {
>  struct xs_handle *xs_daemon_open()
>  {
>      int fd = alloc_fd(FTYPE_XENBUS);
> -    files[fd].xenbus.events = NULL;
> -    printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].xenbus.events);
> +    files[fd].dev = NULL;
> +    printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].dev);
>      return (void*)(intptr_t) fd;
>  }
>  
> @@ -30,7 +30,7 @@ void xs_daemon_close(struct xs_handle *h)
>  {
>      int fd = _xs_fileno(h);
>      struct xenbus_event *event, *next;
> -    for (event = files[fd].xenbus.events; event; event = next)
> +    for (event = files[fd].dev; event; event = next)
>      {
>          next = event->next;
>          free(event);
> @@ -172,15 +172,16 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)
>  {
>      int fd = _xs_fileno(h);
>      printk("xs_watch(%s, %s)\n", path, token);
> -    return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token, &files[fd].xenbus.events));
> +    return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token,
> +                   (xenbus_event_queue *)&files[fd].dev));
>  }
>  
>  char **xs_read_watch(struct xs_handle *h, unsigned int *num)
>  {
>      int fd = _xs_fileno(h);
>      struct xenbus_event *event;
> -    event = files[fd].xenbus.events;
> -    files[fd].xenbus.events = event->next;
> +    event = files[fd].dev;
> +    files[fd].dev = event->next;
>      printk("xs_read_watch() -> %s %s\n", event->path, event->token);
>      *num = 2;
>      return (char **) &event->path;
> -- 
> 2.26.2
> 

-- 
Samuel
"I don't know why, but first C programs tend to look a lot worse than
first programs in any other language (maybe except for fortran, but then
I suspect all fortran programs look like `firsts')"
(By Olaf Kirch)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 15/15] mini-os: introduce get_file_from_fd()
  2022-01-06 11:57 ` [PATCH 15/15] mini-os: introduce get_file_from_fd() Juergen Gross
@ 2022-01-09  1:33   ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09  1:33 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le jeu. 06 janv. 2022 12:57:41 +0100, a ecrit:
> 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 <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/lib.h | 1 +
>  lib/sys.c     | 8 ++++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/include/lib.h b/include/lib.h
> index 91364ba..7a0546b 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -198,6 +198,7 @@ struct file {
>  
>  extern struct file files[];
>  
> +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 6f2b026..0e6fe5d 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -98,6 +98,14 @@ struct file files[NOFILE] = {
>      { .type = FTYPE_CONSOLE }, /* stderr */
>  };
>  
> +struct file *get_file_from_fd(int fd)
> +{
> +    if ( fd < 0 || fd >= NOFILE )
> +        return NULL;
> +
> +    return (files[fd].type == FTYPE_NONE) ? NULL : files + fd;
> +}
> +
>  DECLARE_WAIT_QUEUE_HEAD(event_queue);
>  
>  int alloc_fd(enum fd_type type)
> -- 
> 2.26.2
> 

-- 
Samuel
The nice thing about Windows is - It does not just crash, it displays a
dialog box and lets you press 'OK' first.
(Arno Schaefer's .sig)


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-09  1:21     ` Samuel Thibault
@ 2022-01-09  6:12       ` Juergen Gross
  2022-01-09 10:20         ` Samuel Thibault
  0 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-09  6:12 UTC (permalink / raw)
  To: Samuel Thibault, minios-devel, xen-devel, wl


[-- Attachment #1.1.1: Type: text/plain, Size: 604 bytes --]

On 09.01.22 02:21, Samuel Thibault wrote:
> Samuel Thibault, le dim. 09 janv. 2022 02:18:44 +0100, a ecrit:
>> Juergen Gross, le jeu. 06 janv. 2022 12:57:28 +0100, a ecrit:
>>> The read member of struct file should be bool.
>>>
>>> In order to have the device specific part at the end of the structure
>>> move "read" ahead of that.
>>>
>>> Signed-off-by: Juergen Gross <jgross@suse.com>
>>
>> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> 
> Mmm, but tools/libs/evtchn/minios.c needs updating, doesn't it?

It will be, but assigning 1 to a bool is just fine.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-09  6:12       ` Juergen Gross
@ 2022-01-09 10:20         ` Samuel Thibault
  2022-01-09 10:28           ` Juergen Gross
  0 siblings, 1 reply; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09 10:20 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le dim. 09 janv. 2022 07:12:32 +0100, a ecrit:
> On 09.01.22 02:21, Samuel Thibault wrote:
> > Samuel Thibault, le dim. 09 janv. 2022 02:18:44 +0100, a ecrit:
> > > Juergen Gross, le jeu. 06 janv. 2022 12:57:28 +0100, a ecrit:
> > > > The read member of struct file should be bool.
> > > > 
> > > > In order to have the device specific part at the end of the structure
> > > > move "read" ahead of that.
> > > > 
> > > > Signed-off-by: Juergen Gross <jgross@suse.com>
> > > 
> > > Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > 
> > Mmm, but tools/libs/evtchn/minios.c needs updating, doesn't it?
> 
> It will be, but assigning 1 to a bool is just fine.

Yes but it's moved in the structure.

Samuel


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-09 10:20         ` Samuel Thibault
@ 2022-01-09 10:28           ` Juergen Gross
  2022-01-09 10:33             ` Samuel Thibault
  0 siblings, 1 reply; 37+ messages in thread
From: Juergen Gross @ 2022-01-09 10:28 UTC (permalink / raw)
  To: Samuel Thibault, minios-devel, xen-devel, wl


[-- Attachment #1.1.1: Type: text/plain, Size: 849 bytes --]

On 09.01.22 11:20, Samuel Thibault wrote:
> Juergen Gross, le dim. 09 janv. 2022 07:12:32 +0100, a ecrit:
>> On 09.01.22 02:21, Samuel Thibault wrote:
>>> Samuel Thibault, le dim. 09 janv. 2022 02:18:44 +0100, a ecrit:
>>>> Juergen Gross, le jeu. 06 janv. 2022 12:57:28 +0100, a ecrit:
>>>>> The read member of struct file should be bool.
>>>>>
>>>>> In order to have the device specific part at the end of the structure
>>>>> move "read" ahead of that.
>>>>>
>>>>> Signed-off-by: Juergen Gross <jgross@suse.com>
>>>>
>>>> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
>>>
>>> Mmm, but tools/libs/evtchn/minios.c needs updating, doesn't it?
>>
>> It will be, but assigning 1 to a bool is just fine.
> 
> Yes but it's moved in the structure.

It needs recompiling, but no change. Its still file->read.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part
  2022-01-09 10:28           ` Juergen Gross
@ 2022-01-09 10:33             ` Samuel Thibault
  0 siblings, 0 replies; 37+ messages in thread
From: Samuel Thibault @ 2022-01-09 10:33 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wl

Juergen Gross, le dim. 09 janv. 2022 11:28:58 +0100, a ecrit:
> On 09.01.22 11:20, Samuel Thibault wrote:
> > Juergen Gross, le dim. 09 janv. 2022 07:12:32 +0100, a ecrit:
> > > On 09.01.22 02:21, Samuel Thibault wrote:
> > > > Samuel Thibault, le dim. 09 janv. 2022 02:18:44 +0100, a ecrit:
> > > > > Juergen Gross, le jeu. 06 janv. 2022 12:57:28 +0100, a ecrit:
> > > > > > The read member of struct file should be bool.
> > > > > > 
> > > > > > In order to have the device specific part at the end of the structure
> > > > > > move "read" ahead of that.
> > > > > > 
> > > > > > Signed-off-by: Juergen Gross <jgross@suse.com>
> > > > > 
> > > > > Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > > > 
> > > > Mmm, but tools/libs/evtchn/minios.c needs updating, doesn't it?
> > > 
> > > It will be, but assigning 1 to a bool is just fine.
> > 
> > Yes but it's moved in the structure.
> 
> It needs recompiling, but no change. Its still file->read.

Ah, right, I was thinking about other fields such as gntmap,
evtchn.ports which will need updating.

Samuel


^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2022-01-09 10:34 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 11:57 [PATCH 00/15] mini-os: remove struct file dependency from config Juergen Gross
2022-01-06 11:57 ` [PATCH 01/15] mini-os: split struct file definition from its usage Juergen Gross
2022-01-09  1:17   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 02/15] mini-os: makes file.read bool and move it ahead of device specific part Juergen Gross
2022-01-09  1:18   ` Samuel Thibault
2022-01-09  1:21     ` Samuel Thibault
2022-01-09  6:12       ` Juergen Gross
2022-01-09 10:20         ` Samuel Thibault
2022-01-09 10:28           ` Juergen Gross
2022-01-09 10:33             ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 03/15] mini-os: make offset a common struct file member for all types Juergen Gross
2022-01-09  1:23   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 04/15] mini-os: replace multiple fd elements in struct file by common one Juergen Gross
2022-01-09  1:25   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 05/15] mini-os: introduce a common dev pointer in struct file Juergen Gross
2022-01-09  1:25   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 06/15] mini-os: eliminate blkfront union member " Juergen Gross
2022-01-09  1:26   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 07/15] mini-os: eliminate consfront " Juergen Gross
2022-01-09  1:27   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 08/15] mini-os: eliminate fbfront " Juergen Gross
2022-01-09  1:27   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 09/15] mini-os: eliminate kbdfront " Juergen Gross
2022-01-09  1:28   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 10/15] mini-os: eliminate netfront " Juergen Gross
2022-01-09  1:28   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 11/15] mini-os: move tpm respgot member of struct file to device specific data Juergen Gross
2022-01-09  1:30   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 12/15] mini-os: eliminate tpmfront union member in struct file Juergen Gross
2022-01-09  1:30   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 13/15] mini-os: eliminate tpmtis " Juergen Gross
2022-01-09  1:31   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 14/15] mini-os: eliminate xenbus " Juergen Gross
2022-01-09  1:32   ` Samuel Thibault
2022-01-06 11:57 ` [PATCH 15/15] mini-os: introduce get_file_from_fd() Juergen Gross
2022-01-09  1:33   ` Samuel Thibault
2022-01-07  2:39 ` [PATCH 00/15] mini-os: remove struct file dependency from config Samuel Thibault

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.