From nobody Thu Nov 28 08:51:24 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=1676277897; cv=none; d=zohomail.com; s=zohoarc; b=VPks0fzHe5e0MPrZsPouyHYZ8r54rrgOW2KNz3QQXfi5GKLNA65k7F0yR1Js+frupDU9HTq991pX7xvUA+FtgI2Eni1UzhcbPAmbPIwItcUUpIgc/pgMG8NNjkP0TLtxsBohT07DwXwwFHFmyPiU2n+W8Pv4ovwXX8D67K4ZHiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676277897; 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=7/tiDXbP/9+hZp0jDtSI+PwtYbXnE16R86Manl6T7bw=; b=eHPaS5BfDk0+xop5F4QFiGsSUjE7WEbRg3hmkOUOoac+2PAdEuJO4mz6eSgMFElv4UuQaZ3dNIh7Ph8IEOxYs11t7kEju29mSb/YwMuic1BKWY1d4WBFN2AJTqm7a+5Bte9JyeWH++5h9H24puGADROY9SUCnyQLNFCWQetqIis= 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 1676277897487479.5600491700045; Mon, 13 Feb 2023 00:44:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.494216.764241 (Exim 4.92) (envelope-from ) id 1pRURy-0006N4-Ox; Mon, 13 Feb 2023 08:44:38 +0000 Received: by outflank-mailman (output) from mailman id 494216.764241; Mon, 13 Feb 2023 08:44:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pRURy-0006Mu-LJ; Mon, 13 Feb 2023 08:44:38 +0000 Received: by outflank-mailman (input) for mailman id 494216; Mon, 13 Feb 2023 08:44:36 +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 1pRURw-0006An-NG for xen-devel@lists.xenproject.org; Mon, 13 Feb 2023 08:44:36 +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 a3098a0a-ab7a-11ed-93b5-47a8fe42b414; Mon, 13 Feb 2023 09:44:33 +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 B5FC137870; Mon, 13 Feb 2023 08:44:32 +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 8D23C1391B; Mon, 13 Feb 2023 08:44:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aHdDIXD46WNARAAAMHmgww (envelope-from ); Mon, 13 Feb 2023 08:44:32 +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: a3098a0a-ab7a-11ed-93b5-47a8fe42b414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1676277872; 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=7/tiDXbP/9+hZp0jDtSI+PwtYbXnE16R86Manl6T7bw=; b=qiR+HkdnGMmX36aZ+SoeWq7GNf4wwvzOGMdiNfYGeiA1zLvLOv6d/EiRWw5K3JRpmdJr1S 8nUOwXjEBHl7+0sNC8SUyEqCHPZOaAWUunLG4c6G56biCIP0q4goSBslMbUBZ2rS8JxS6/ MYvFRShMfQnaj/DJmzIY0bop4HB1F+M= 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 v3 3/7] Mini-OS: add support for runtime mounts Date: Mon, 13 Feb 2023 09:44:08 +0100 Message-Id: <20230213084412.21065-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230213084412.21065-1-jgross@suse.com> References: <20230213084412.21065-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1676277901107100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Samuel Thibault --- V3: - set number of possible mountpoints to 16 (Andrew Cooper) --- include/lib.h | 5 +++++ lib/sys.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 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; }; }; =20 @@ -194,6 +195,10 @@ struct mount_point { void *dev; }; =20 +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); =20 off_t lseek_default(struct file *file, off_t offset, int whence); diff --git a/lib/sys.c b/lib/sys.c index 2f33c937..118fc441 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -85,6 +85,8 @@ } =20 #define NOFILE 32 +#define N_MOUNTS 16 + extern void minios_evtchn_close_fd(int fd); extern void minios_gnttab_close_fd(int fd); =20 @@ -339,7 +341,7 @@ static int open_mem(struct mount_point *mnt, const char= *pathname, int flags, return fd; } =20 -static struct mount_point mount_points[] =3D { +static struct mount_point mount_points[N_MOUNTS] =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 @@ -365,6 +367,8 @@ int open(const char *pathname, int flags, ...) for ( m =3D 0; m < ARRAY_SIZE(mount_points); m++ ) { mnt =3D mount_points + m; + if ( !mnt->path ) + continue; mlen =3D strlen(mnt->path); if ( !strncmp(pathname, mnt->path, mlen) && (pathname[mlen] =3D=3D '/' || pathname[mlen] =3D=3D 0) ) @@ -375,6 +379,45 @@ int open(const char *pathname, int flags, ...) return -1; } =20 +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 =3D 0; m < ARRAY_SIZE(mount_points); m++ ) + { + mnt =3D mount_points + m; + if ( !mnt->path ) + { + mnt->path =3D strdup(path); + mnt->open =3D open; + mnt->dev =3D dev; + return 0; + } + } + + errno =3D ENOSPC; + return -1; +} + +void umount(const char *path) +{ + unsigned int m; + struct mount_point *mnt; + + for ( m =3D 0; m < ARRAY_SIZE(mount_points); m++ ) + { + mnt =3D mount_points + m; + if ( mnt->path && !strcmp(mnt->path, path) ) + { + free((char *)mnt->path); + mnt->path =3D NULL; + return; + } + } +} + int isatty(int fd) { return files[fd].type =3D=3D FTYPE_CONSOLE; --=20 2.35.3