From nobody Thu Nov 28 08:46:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1676026034; cv=none; d=zohomail.com; s=zohoarc; b=d7tRJt5LxNzK9OjRWG0w0T74BGf/cDw7xyubJdUiBI5OG9ChT5S+kbyqkcncvl7xNwjYuu5XW/s9dGLRqzFUs0dV96q7rF4UgqiQ85G/M0Iqv/Z4BL4Xg2us5tWQRAsHSNLiiBKhgSU8YiwdJfOOm46kuh03tW444a++CySqdLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676026034; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/AHf/75zmPALL2yeH8dnyZ0qXj5tN9xIh6TXHZM0XmI=; b=OwirBkaPUsOy8u3y2kIGTrDjMRk46gXy+uvhlxOh26swDtcspPwknoNZROgXPYIzZ1QTSEPW7a3tnVdB7rfSfiuhHP8AqWKI7s9T4UIB+DqeZBzPZt8wgaWyF/5otHmFrpr7erFf12pKGznZaEMw5i6FnK6dsObX4nqlxlll5y0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1676026034022717.8435754459688; Fri, 10 Feb 2023 02:47:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.493255.763122 (Exim 4.92) (envelope-from ) id 1pQQvY-0006PG-8Q; Fri, 10 Feb 2023 10:46:48 +0000 Received: by outflank-mailman (output) from mailman id 493255.763122; Fri, 10 Feb 2023 10:46:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pQQvY-0006P9-4l; Fri, 10 Feb 2023 10:46:48 +0000 Received: by outflank-mailman (input) for mailman id 493255; Fri, 10 Feb 2023 10:46:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pQQvW-000617-Jz for xen-devel@lists.xenproject.org; Fri, 10 Feb 2023 10:46:46 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 34a04e52-a930-11ed-93b5-47a8fe42b414; Fri, 10 Feb 2023 11:46:42 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 615EC3FEC5; Fri, 10 Feb 2023 10:46:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 39D171325E; Fri, 10 Feb 2023 10:46:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5aTuDJIg5mPXUwAAMHmgww (envelope-from ); Fri, 10 Feb 2023 10:46:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 34a04e52-a930-11ed-93b5-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1676026002; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/AHf/75zmPALL2yeH8dnyZ0qXj5tN9xIh6TXHZM0XmI=; b=uUnrQU6OBTmGEoK5GrqQ5X1uKYO50tysm/j0qaooTSeJQ2BfFKK4egmCT4hUuwYhyS1ZEq LxH6MFeQ7hdpMDYz59hrNEqR8JXTYmxpLEpUk7LM/Qn5LZD28KoJep29gwFa0s0TS9Jbzz iE28cYUEKlTy1HyP4v909JUgLcPRPOA= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 2/7] Mini-OS: add concept of mount points Date: Fri, 10 Feb 2023 11:46:23 +0100 Message-Id: <20230210104628.14374-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230210104628.14374-1-jgross@suse.com> References: <20230210104628.14374-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1676026036034100003 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Samuel Thibault --- 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); }; =20 +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); =20 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 =20 #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; } =20 -#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 =3D EIO; @@ -286,18 +281,30 @@ int posix_openpt(int flags) return fd; } =20 +static int open_pt(struct mount_point *mnt, const char *pathname, int flag= s, + mode_t mode) +{ + return posix_openpt(flags); +} + int open_savefile(const char *path, int save) { int fd; char nodename[64]; =20 - snprintf(nodename, sizeof(nodename), "device/console/%d", save ? SAVE_= CONSOLE : RESTORE_CONSOLE); + snprintf(nodename, sizeof(nodename), "device/console/%d", save ? 1 : 2= ); =20 fd =3D open_consfront(nodename); printk("fd(%d) =3D open_savefile\n", fd); =20 return fd; } + +static int open_save(struct mount_point *mnt, const char *pathname, int fl= ags, + 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 =20 -int open(const char *pathname, int flags, ...) +static int open_log(struct mount_point *mnt, const char *pathname, int fla= gs, + mode_t mode) { int fd; + /* Ugly, but fine. */ - if (!strncmp(pathname,LOG_PATH,strlen(LOG_PATH))) { - fd =3D alloc_fd(FTYPE_CONSOLE); - printk("open(%s) -> %d\n", pathname, fd); - return fd; + fd =3D 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 fla= gs, + mode_t mode) +{ + int fd; + + fd =3D alloc_fd(FTYPE_MEM); + printk("open(%s%s) -> %d\n", mnt->path, pathname, fd); + return fd; +} + +static struct mount_point mount_points[] =3D { + { .path =3D "/var/log", .open =3D open_log, .dev =3D NULL }, + { .path =3D "/dev/mem", .open =3D open_mem, .dev =3D NULL }, +#ifdef CONFIG_CONSFRONT + { .path =3D "/dev/ptmx", .open =3D open_pt, .dev =3D NULL }, + { .path =3D "/var/lib/xen", .open =3D open_save, .dev =3D NULL }, +#endif +}; + +int open(const char *pathname, int flags, ...) +{ + unsigned int m, mlen; + struct mount_point *mnt; + mode_t mode =3D 0; + va_list ap; + + if ( flags & O_CREAT ) + { + va_start(ap, flags); + mode =3D va_arg(ap, mode_t); + va_end(ap); } - if (!strncmp(pathname, "/dev/mem", strlen("/dev/mem"))) { - fd =3D alloc_fd(FTYPE_MEM); - printk("open(/dev/mem) -> %d\n", fd); - return fd; + + for ( m =3D 0; m < ARRAY_SIZE(mount_points); m++ ) + { + mnt =3D mount_points + m; + mlen =3D strlen(mnt->path); + if ( !strncmp(pathname, mnt->path, mlen) && + (pathname[mlen] =3D=3D '/' || pathname[mlen] =3D=3D 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 =3D EIO; return -1; } --=20 2.35.3