From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: Juergen Gross <jgross@suse.com>
Cc: minios-devel@lists.xenproject.org,
xen-devel@lists.xenproject.org, wl@xen.org
Subject: Re: [PATCH v2 2/7] Mini-OS: add concept of mount points
Date: Fri, 10 Feb 2023 19:44:45 +0100 [thread overview]
Message-ID: <20230210184445.p7aopsjlmvplfdze@begin> (raw)
In-Reply-To: <20230210104628.14374-3-jgross@suse.com>
Juergen Gross, le ven. 10 févr. 2023 11:46:23 +0100, a ecrit:
> Add the concept of mount points to Mini-OS. A mount point is a path
> associated with a device pointer and an open() callback. A mount point
> can be either a file (e.g. "/dev/mem") or a directory ("/var/log").
>
> This allows to replace the special casing in the generic open()
> handling with a generic mount point handling.
>
> Prepare the open() callbacks to support creating new files by adding a
> mode parameter.
>
> Additionally add a close() prototype to include/lib.h, as it is missing
> today.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
> V2:
> - pass path below mount point to open callbacks (Samuel Thibault)
> ---
> include/lib.h | 9 ++++++
> lib/sys.c | 80 +++++++++++++++++++++++++++++++++++++++------------
> 2 files changed, 70 insertions(+), 19 deletions(-)
>
> diff --git a/include/lib.h b/include/lib.h
> index bec99646..36d94ec4 100644
> --- a/include/lib.h
> +++ b/include/lib.h
> @@ -187,6 +187,13 @@ struct file_ops {
> bool (*select_wr)(struct file *file);
> };
>
> +struct mount_point {
> + const char *path;
> + int (*open)(struct mount_point *mnt, const char *pathname, int flags,
> + mode_t mode);
> + void *dev;
> +};
> +
> unsigned int alloc_file_type(const struct file_ops *ops);
>
> off_t lseek_default(struct file *file, off_t offset, int whence);
> @@ -198,6 +205,8 @@ int alloc_fd(unsigned int type);
> void close_all_files(void);
> extern struct thread *main_thread;
> void sparse(unsigned long data, size_t size);
> +
> +int close(int fd);
> #endif
>
> #endif /* _LIB_H_ */
> diff --git a/lib/sys.c b/lib/sys.c
> index 8f8a3de2..2f33c937 100644
> --- a/lib/sys.c
> +++ b/lib/sys.c
> @@ -263,11 +263,6 @@ char *getcwd(char *buf, size_t size)
> return buf;
> }
>
> -#define LOG_PATH "/var/log/"
> -#define SAVE_PATH "/var/lib/xen"
> -#define SAVE_CONSOLE 1
> -#define RESTORE_CONSOLE 2
> -
> int mkdir(const char *pathname, mode_t mode)
> {
> errno = EIO;
> @@ -286,18 +281,30 @@ int posix_openpt(int flags)
> return fd;
> }
>
> +static int open_pt(struct mount_point *mnt, const char *pathname, int flags,
> + mode_t mode)
> +{
> + return posix_openpt(flags);
> +}
> +
> int open_savefile(const char *path, int save)
> {
> int fd;
> char nodename[64];
>
> - snprintf(nodename, sizeof(nodename), "device/console/%d", save ? SAVE_CONSOLE : RESTORE_CONSOLE);
> + snprintf(nodename, sizeof(nodename), "device/console/%d", save ? 1 : 2);
>
> fd = open_consfront(nodename);
> printk("fd(%d) = open_savefile\n", fd);
>
> return fd;
> }
> +
> +static int open_save(struct mount_point *mnt, const char *pathname, int flags,
> + mode_t mode)
> +{
> + return open_savefile(pathname, flags & O_WRONLY);
> +}
> #else
> int posix_openpt(int flags)
> {
> @@ -311,24 +318,59 @@ int open_savefile(const char *path, int save)
> }
> #endif
>
> -int open(const char *pathname, int flags, ...)
> +static int open_log(struct mount_point *mnt, const char *pathname, int flags,
> + mode_t mode)
> {
> int fd;
> +
> /* Ugly, but fine. */
> - if (!strncmp(pathname,LOG_PATH,strlen(LOG_PATH))) {
> - fd = alloc_fd(FTYPE_CONSOLE);
> - printk("open(%s) -> %d\n", pathname, fd);
> - return fd;
> + fd = alloc_fd(FTYPE_CONSOLE);
> + printk("open(%s%s) -> %d\n", mnt->path, pathname, fd);
> + return fd;
> +}
> +
> +static int open_mem(struct mount_point *mnt, const char *pathname, int flags,
> + mode_t mode)
> +{
> + int fd;
> +
> + fd = alloc_fd(FTYPE_MEM);
> + printk("open(%s%s) -> %d\n", mnt->path, pathname, fd);
> + return fd;
> +}
> +
> +static struct mount_point mount_points[] = {
> + { .path = "/var/log", .open = open_log, .dev = NULL },
> + { .path = "/dev/mem", .open = open_mem, .dev = NULL },
> +#ifdef CONFIG_CONSFRONT
> + { .path = "/dev/ptmx", .open = open_pt, .dev = NULL },
> + { .path = "/var/lib/xen", .open = open_save, .dev = NULL },
> +#endif
> +};
> +
> +int open(const char *pathname, int flags, ...)
> +{
> + unsigned int m, mlen;
> + struct mount_point *mnt;
> + mode_t mode = 0;
> + va_list ap;
> +
> + if ( flags & O_CREAT )
> + {
> + va_start(ap, flags);
> + mode = va_arg(ap, mode_t);
> + va_end(ap);
> }
> - if (!strncmp(pathname, "/dev/mem", strlen("/dev/mem"))) {
> - fd = alloc_fd(FTYPE_MEM);
> - printk("open(/dev/mem) -> %d\n", fd);
> - return fd;
> +
> + for ( m = 0; m < ARRAY_SIZE(mount_points); m++ )
> + {
> + mnt = mount_points + m;
> + mlen = strlen(mnt->path);
> + if ( !strncmp(pathname, mnt->path, mlen) &&
> + (pathname[mlen] == '/' || pathname[mlen] == 0) )
> + return mnt->open(mnt, pathname + mlen, flags, mode);
> }
> - if (!strncmp(pathname, "/dev/ptmx", strlen("/dev/ptmx")))
> - return posix_openpt(flags);
> - if (!strncmp(pathname,SAVE_PATH,strlen(SAVE_PATH)))
> - return open_savefile(pathname, flags & O_WRONLY);
> +
> errno = EIO;
> return -1;
> }
> --
> 2.35.3
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
next prev parent reply other threads:[~2023-02-10 18:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 10:46 [PATCH v2 0/7] Mini-OS: add minimal 9pfs support Juergen Gross
2023-02-10 10:46 ` [PATCH v2 1/7] Mini-OS: xenbus: add support for reading node from directory Juergen Gross
2023-02-10 18:43 ` Samuel Thibault
2023-02-10 10:46 ` [PATCH v2 2/7] Mini-OS: add concept of mount points Juergen Gross
2023-02-10 18:44 ` Samuel Thibault [this message]
2023-02-10 10:46 ` [PATCH v2 3/7] Mini-OS: add support for runtime mounts Juergen Gross
2023-02-10 11:43 ` Andrew Cooper
2023-02-10 12:14 ` Juergen Gross
2023-02-10 12:44 ` Samuel Thibault
2023-02-10 18:51 ` Andrew Cooper
2023-02-10 10:46 ` [PATCH v2 4/7] Mini-OS: add 9pfs frontend Juergen Gross
2023-02-10 18:46 ` Samuel Thibault
2023-02-10 10:46 ` [PATCH v2 5/7] Mini-OS: add 9pfs transport layer Juergen Gross
2023-02-10 18:48 ` Samuel Thibault
2023-02-10 10:46 ` [PATCH v2 6/7] Mini-OS: add open and close handling to the 9pfs frontend Juergen Gross
2023-02-10 18:53 ` Samuel Thibault
2023-02-11 6:23 ` Juergen Gross
2023-02-10 10:46 ` [PATCH v2 7/7] Mini-OS: add read and write support to 9pfsfront Juergen Gross
2023-02-10 18:59 ` Samuel Thibault
2023-02-13 6:47 ` Juergen Gross
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=20230210184445.p7aopsjlmvplfdze@begin \
--to=samuel.thibault@ens-lyon.org \
--cc=jgross@suse.com \
--cc=minios-devel@lists.xenproject.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.