All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: samuel.thibault@ens-lyon.org, wl@xen.org,
	Juergen Gross <jgross@suse.com>
Subject: [PATCH 3/7] Mini-OS: add support for runtime mounts
Date: Fri,  3 Feb 2023 10:18:05 +0100	[thread overview]
Message-ID: <20230203091809.14478-4-jgross@suse.com> (raw)
In-Reply-To: <20230203091809.14478-1-jgross@suse.com>

Add the support to mount a device at runtime. The number of dynamic
mounts is limited by a #define.

For devices supporting multiple files struct file is modified to hold
a pointer to file specific data in contrast to device specific data.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/lib.h |  5 +++++
 lib/sys.c     | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/include/lib.h b/include/lib.h
index 36d94ec4..fd8c36de 100644
--- a/include/lib.h
+++ b/include/lib.h
@@ -172,6 +172,7 @@ struct file {
     union {
         int fd; /* Any fd from an upper layer. */
         void *dev;
+        void *filedata;
     };
 };
 
@@ -194,6 +195,10 @@ struct mount_point {
     void *dev;
 };
 
+int mount(const char *path, void *dev,
+          int (*open)(struct mount_point *, const char *, int, mode_t));
+void umount(const char *path);
+
 unsigned int alloc_file_type(const struct file_ops *ops);
 
 off_t lseek_default(struct file *file, off_t offset, int whence);
diff --git a/lib/sys.c b/lib/sys.c
index 1475c621..4171bfd6 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -339,7 +339,14 @@ static int open_mem(struct mount_point *mnt, const char *pathname, int flags,
     return fd;
 }
 
-static struct mount_point mount_points[] = {
+#ifdef CONFIG_CONSFRONT
+#define STATIC_MNTS   4
+#else
+#define STATIC_MNTS   2
+#endif
+#define DYNAMIC_MNTS  8
+
+static struct mount_point mount_points[STATIC_MNTS + DYNAMIC_MNTS] = {
     { .path = "/var/log",     .open = open_log,  .dev = NULL },
     { .path = "/dev/mem",     .open = open_mem,  .dev = NULL },
 #ifdef CONFIG_CONSFRONT
@@ -365,6 +372,8 @@ int open(const char *pathname, int flags, ...)
     for ( m = 0; m < ARRAY_SIZE(mount_points); m++ )
     {
         mnt = mount_points + m;
+        if ( !mnt->path )
+            continue;
         mlen = strlen(mnt->path);
         if ( !strncmp(pathname, mnt->path, mlen) &&
              (pathname[mlen] == '/' || pathname[mlen] == 0) )
@@ -375,6 +384,45 @@ int open(const char *pathname, int flags, ...)
     return -1;
 }
 
+int mount(const char *path, void *dev,
+          int (*open)(struct mount_point *, const char *, int, mode_t))
+{
+    unsigned int m;
+    struct mount_point *mnt;
+
+    for ( m = 0; m < ARRAY_SIZE(mount_points); m++ )
+    {
+        mnt = mount_points + m;
+        if ( !mnt->path )
+        {
+            mnt->path = strdup(path);
+            mnt->open = open;
+            mnt->dev = dev;
+            return 0;
+        }
+    }
+
+    errno = ENOSPC;
+    return -1;
+}
+
+void umount(const char *path)
+{
+    unsigned int m;
+    struct mount_point *mnt;
+
+    for ( m = 0; m < ARRAY_SIZE(mount_points); m++ )
+    {
+        mnt = mount_points + m;
+        if ( mnt->path && !strcmp(mnt->path, path) )
+        {
+            free((char *)mnt->path);
+            mnt->path = NULL;
+            return;
+        }
+    }
+}
+
 int isatty(int fd)
 {
     return files[fd].type == FTYPE_CONSOLE;
-- 
2.35.3



  parent reply	other threads:[~2023-02-03  9:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03  9:18 [PATCH 0/7] Mini-OS: ad minimal 9pfs support Juergen Gross
2023-02-03  9:18 ` [PATCH 1/7] Mini-OS: xenbus: add support for reading node from directory Juergen Gross
2023-02-04 14:01   ` Samuel Thibault
2023-02-06  9:23     ` Juergen Gross
2023-02-03  9:18 ` [PATCH 2/7] Mini-OS: add concept of mount points Juergen Gross
2023-02-05 12:40   ` Samuel Thibault
2023-02-05 12:45   ` Samuel Thibault
2023-02-06  9:25     ` Juergen Gross
2023-02-03  9:18 ` Juergen Gross [this message]
2023-02-05 12:42   ` [PATCH 3/7] Mini-OS: add support for runtime mounts Samuel Thibault
2023-02-03  9:18 ` [PATCH 4/7] Mini-OS: add 9pfs frontend Juergen Gross
2023-02-06  9:01   ` Samuel Thibault
2023-02-06  9:22     ` Juergen Gross
2023-02-06  9:48       ` Samuel Thibault
2023-02-03  9:18 ` [PATCH 5/7] Mini-OS: add 9pfs transport layer Juergen Gross
2023-02-06  9:40   ` Samuel Thibault
2023-02-06 10:23     ` Juergen Gross
2023-02-03  9:18 ` [PATCH 6/7] Mini-OS: add open and close handling to the 9pfs frontend Juergen Gross
2023-02-03 12:50   ` Juergen Gross
2023-02-06 10:05   ` Samuel Thibault
2023-02-06 10:15     ` Juergen Gross
2023-02-03  9:18 ` [PATCH 7/7] Mini-OS: add read and write support to 9pfsfront Juergen Gross
2023-02-03 12:52   ` Juergen Gross
2023-02-06 10:13   ` Samuel Thibault
2023-02-06 10:17     ` Juergen Gross
2023-02-06 12:05       ` Samuel Thibault
2023-02-06 15:35         ` Juergen Gross
2023-02-06 10:14 ` [PATCH 0/7] Mini-OS: ad minimal 9pfs support Samuel Thibault

Reply instructions:

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

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

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

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

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

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

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