[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 3/7] lib/9pfs: Implement mount and unmount


  • To: "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Sat, 7 Sep 2019 09:59:54 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OO1IJG0GEdxXiIIjpwIXgqwadvD+fHBLYuR+3z9dduA=; b=ie469ysZX32MyhovMfpMokED3kXnChhfQVnf+8Q+2RKc/HPgyvuw3Ltp+V0w0mGsGQgti2VIucpbsM/CSsojKjgn8TvbDPsmjNdLlVhQupwm4Z9oYNDAw7CVLMglDwPLVgjxKhTShiCTv7xJPgEY1NHldhh+R4iMPiyZeJmvApEJjS+2X1Da0P8id8z6qJRg6jfjbCerJ+Voadon89rv7Cxrwtyh5F4nHOhPFbWxIoUDFOBfTcT5eaVceOVbO1M8hvpR7wAWOgo1EJsOeXV1K0uidPQudiX+z6YOiuTGwCGhI2fXOCvBfmQEpuvdFwD9UG7nI8pWKAA0FbhbIBLOmQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GYe7llLkvJ4xGgOw99m3UTMcdni337hoQeQ+8kTqKqfSm1/ExK8cb6cIcH9J0Yy5jmx8UVHfWWWQVLZ7jou6VvX6xlUHWCXA5q5gOLq8yxg2DuUGYjya8YDZPEx+K0EHUH8HyjDCT48lHUaLsBMqHBmH0dNnW6ugpGelxUCbTo2kvcvIYgP+2z0q1hrXT57Cv3qo2G/KqTljbXessN9YXb4uZNZWETm2dY9p+V2BZ6Im0W+VRMmj9b+3p6taewV+vFieEZgYDCzXJ+hNmQ9nwx2zW+R9g+wozHUg0Yd2L1B1jA+TDONef0mETo3dzhSYmcYG9siYcVq2abL+TW7kPw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Cc: "costin.lupu@xxxxxxxxx" <costin.lupu@xxxxxxxxx>, Cristian Banu <cristb@xxxxxxxxx>
  • Delivery-date: Sat, 07 Sep 2019 10:00:12 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVZWL/bjgUpPIPgk2b5HJm5ofSSQ==
  • Thread-topic: [UNIKRAFT PATCH 3/7] lib/9pfs: Implement mount and unmount

From: Cristian Banu <cristb@xxxxxxxxx>

This patch implements the mount and unmount operations and adds the
skeleton for VFS node operations.

Signed-off-by: Cristian Banu <cristb@xxxxxxxxx>
---
 lib/9pfs/9pfs_vfsops.c | 189 +++++++++++++++++++++++++++++++++++++++++
 lib/9pfs/9pfs_vnops.c  | 135 +++++++++++++++++++++++++++++
 lib/9pfs/Makefile.uk   |   3 +
 3 files changed, 327 insertions(+)
 create mode 100644 lib/9pfs/9pfs_vfsops.c
 create mode 100644 lib/9pfs/9pfs_vnops.c

diff --git a/lib/9pfs/9pfs_vfsops.c b/lib/9pfs/9pfs_vfsops.c
new file mode 100644
index 00000000..accb3a56
--- /dev/null
+++ b/lib/9pfs/9pfs_vfsops.c
@@ -0,0 +1,189 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Cristian Banu <cristb@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest. All rights 
reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <uk/config.h>
+#include <uk/errptr.h>
+#include <uk/9p.h>
+#include <uk/9pdev_trans.h>
+#include <vfscore/mount.h>
+#include <vfscore/dentry.h>
+
+#include "9pfs.h"
+
+extern struct vnops uk_9pfs_vnops;
+
+static int uk_9pfs_mount(struct mount *mp, const char *dev, int flags,
+                        const void *data);
+
+static int uk_9pfs_unmount(struct mount *mp, int flags);
+
+#define uk_9pfs_sync           ((vfsop_sync_t)vfscore_nullop)
+#define uk_9pfs_vget           ((vfsop_vget_t)vfscore_nullop)
+#define uk_9pfs_statfs         ((vfsop_statfs_t)vfscore_nullop)
+
+struct vfsops uk_9pfs_vfsops = {
+       .vfs_mount      = uk_9pfs_mount,
+       .vfs_unmount    = uk_9pfs_unmount,
+       .vfs_sync       = uk_9pfs_sync,
+       .vfs_vget       = uk_9pfs_vget,
+       .vfs_statfs     = uk_9pfs_statfs,
+       .vfs_vnops      = &uk_9pfs_vnops
+};
+
+static struct vfscore_fs_type uk_9pfs_fs = {
+       .vs_name        = "9pfs",
+       .vs_init        = NULL,
+       .vs_op          = &uk_9pfs_vfsops
+};
+
+UK_FS_REGISTER(uk_9pfs_fs);
+
+static const char *uk_9pfs_proto_str[UK_9P_PROTO_MAX] = {
+       [UK_9P_PROTO_2000U] = "9P2000.u"
+};
+
+static int uk_9pfs_parse_options(struct uk_9pfs_mount_data *md,
+               const void *data __unused)
+{
+       int rc = 0;
+
+       md->trans = uk_9pdev_trans_get_default();
+       if (!md->trans)
+               goto out;
+
+       /* Currently, no options are supported. */
+
+       md->proto = UK_9P_PROTO_2000U;
+       md->uname = "";
+       md->aname = "";
+
+out:
+       return rc;
+}
+
+static int uk_9pfs_mount(struct mount *mp, const char *dev,
+                       int flags __unused, const void *data)
+{
+       struct uk_9pfs_mount_data *md;
+       struct uk_9preq *version_req;
+       struct uk_9p_str rcvd_version;
+       struct uk_9pfid *rootfid;
+       int version_accepted;
+       int rc;
+
+       /* Set data as null, vnop_inactive() checks this for the root fid. */
+       mp->m_root->d_vnode->v_data = NULL;
+
+       /* Allocate mount data, parse options. */
+       md = malloc(sizeof(*md));
+       if (!md)
+               return ENOMEM;
+
+       rc = uk_9pfs_parse_options(md, data);
+       if (rc)
+               goto out_free_mdata;
+
+       mp->m_data = md;
+
+       /* Establish connection with the given 9P endpoint. */
+       md->dev = uk_9pdev_connect(md->trans, dev, data, NULL);
+       if (PTRISERR(md->dev)) {
+               rc = -PTR2ERR(md->dev);
+               goto out_free_mdata;
+       }
+
+       /* Create a new 9pfs session via a VERSION message. */
+       version_req = uk_9p_version(md->dev, uk_9pfs_proto_str[md->proto],
+                       &rcvd_version);
+       if (PTRISERR(version_req)) {
+               rc = -PTR2ERR(version_req);
+               goto out_disconnect;
+       }
+
+       version_accepted = uk_9p_str_equal(&rcvd_version,
+                       uk_9pfs_proto_str[md->proto]);
+       uk_9pdev_req_remove(md->dev, version_req);
+
+       if (!version_accepted) {
+               rc = EIO;
+               uk_pr_warn("Could not negotiate protocol %s\n",
+                               uk_9pfs_proto_str[md->proto]);
+               goto out_disconnect;
+       }
+
+       /* Create root fid. */
+       rootfid = uk_9p_attach(md->dev, UK_9P_NOFID, md->uname,
+                       md->aname, UK_9P_NONUNAME);
+       if (PTRISERR(rootfid)) {
+               rc = -PTR2ERR(rootfid);
+               goto out_disconnect;
+       }
+
+       rc = uk_9pfs_allocate_vnode_data(mp->m_root->d_vnode, rootfid);
+       if (rc != 0) {
+               rc = -rc;
+               goto out_disconnect;
+       }
+
+       return 0;
+
+out_disconnect:
+       uk_9pdev_disconnect(md->dev);
+out_free_mdata:
+       free(md);
+       return rc;
+}
+
+static void uk_9pfs_release_tree_fids(struct dentry *d)
+{
+       struct dentry *p;
+
+       uk_list_for_each_entry(p, &d->d_child_list, d_child_link)
+               uk_9pfs_release_tree_fids(p);
+
+       if (d->d_vnode->v_data)
+               uk_9pfs_free_vnode_data(d->d_vnode);
+}
+
+static int uk_9pfs_unmount(struct mount *mp, int flags __unused)
+{
+       struct uk_9pfs_mount_data *md = UK_9PFS_MD(mp);
+
+       uk_9pfs_release_tree_fids(mp->m_root);
+       vfscore_release_mp_dentries(mp);
+       uk_9pdev_disconnect(md->dev);
+       free(md);
+
+       return 0;
+}
diff --git a/lib/9pfs/9pfs_vnops.c b/lib/9pfs/9pfs_vnops.c
new file mode 100644
index 00000000..809fac43
--- /dev/null
+++ b/lib/9pfs/9pfs_vnops.c
@@ -0,0 +1,135 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Cristian Banu <cristb@xxxxxxxxx>
+ *
+ * Copyright (c) 2019, University Politehnica of Bucharest. All rights 
reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#define _GNU_SOURCE
+
+#include <fcntl.h>
+#include <dirent.h>
+#include <uk/config.h>
+#include <uk/9p.h>
+#include <uk/errptr.h>
+#include <vfscore/mount.h>
+#include <vfscore/dentry.h>
+#include <vfscore/vnode.h>
+#include <vfscore/file.h>
+#include <vfscore/fs.h>
+
+#include "9pfs.h"
+
+int uk_9pfs_allocate_vnode_data(struct vnode *vp, struct uk_9pfid *fid)
+{
+       struct uk_9pfs_node_data *nd;
+
+       nd = malloc(sizeof(*nd));
+       if (nd == NULL)
+               return -ENOMEM;
+
+       nd->fid = fid;
+       nd->nb_open_files = 0;
+       nd->removed = false;
+       vp->v_data = nd;
+
+       return 0;
+}
+
+void uk_9pfs_free_vnode_data(struct vnode *vp)
+{
+       struct uk_9pdev *dev = UK_9PFS_MD(vp->v_mount)->dev;
+       struct uk_9pfs_node_data *nd = UK_9PFS_ND(vp);
+
+       if (nd->nb_open_files > 0)
+               return;
+
+       if (nd->removed)
+               uk_9p_remove(dev, nd->fid);
+
+       uk_9pfid_put(nd->fid);
+       free(nd);
+       vp->v_data = NULL;
+}
+
+static int uk_9pfs_readdir(struct vnode *vp, struct vfscore_file *fp,
+               struct dirent *dir)
+{
+       return ENOENT;
+}
+
+#define uk_9pfs_seek           ((vnop_seek_t)vfscore_vop_nullop)
+#define uk_9pfs_ioctl          ((vnop_ioctl_t)vfscore_vop_einval)
+#define uk_9pfs_fsync          ((vnop_fsync_t)vfscore_vop_nullop)
+#define uk_9pfs_getattr                ((vnop_getattr_t)vfscore_vop_nullop)
+#define uk_9pfs_setattr                ((vnop_setattr_t)vfscore_vop_nullop)
+#define uk_9pfs_truncate       ((vnop_truncate_t)vfscore_vop_nullop)
+#define uk_9pfs_inactive       ((vnop_inactive_t)vfscore_vop_nullop)
+#define uk_9pfs_link           ((vnop_link_t)vfscore_vop_eperm)
+#define uk_9pfs_cache          ((vnop_cache_t)NULL)
+#define uk_9pfs_readlink       ((vnop_readlink_t)vfscore_vop_einval)
+#define uk_9pfs_symlink                ((vnop_symlink_t)vfscore_vop_eperm)
+#define uk_9pfs_fallocate      ((vnop_fallocate_t)vfscore_vop_nullop)
+#define uk_9pfs_create         ((vnop_create_t)vfscore_vop_einval)
+#define uk_9pfs_remove         ((vnop_remove_t)vfscore_vop_einval)
+#define uk_9pfs_rename         ((vnop_rename_t)vfscore_vop_einval)
+#define uk_9pfs_mkdir          ((vnop_mkdir_t)vfscore_vop_einval)
+#define uk_9pfs_rmdir          ((vnop_rmdir_t)vfscore_vop_einval)
+#define uk_9pfs_open           ((vnop_open_t)vfscore_vop_einval)
+#define uk_9pfs_close          ((vnop_close_t)vfscore_vop_einval)
+#define uk_9pfs_read           ((vnop_read_t)vfscore_vop_einval)
+#define uk_9pfs_write          ((vnop_write_t)vfscore_vop_einval)
+#define uk_9pfs_lookup         ((vnop_lookup_t)vfscore_vop_einval)
+
+struct vnops uk_9pfs_vnops = {
+       .vop_open       = uk_9pfs_open,
+       .vop_close      = uk_9pfs_close,
+       .vop_read       = uk_9pfs_read,
+       .vop_write      = uk_9pfs_write,
+       .vop_seek       = uk_9pfs_seek,
+       .vop_ioctl      = uk_9pfs_ioctl,
+       .vop_fsync      = uk_9pfs_fsync,
+       .vop_readdir    = uk_9pfs_readdir,
+       .vop_lookup     = uk_9pfs_lookup,
+       .vop_create     = uk_9pfs_create,
+       .vop_remove     = uk_9pfs_remove,
+       .vop_rename     = uk_9pfs_rename,
+       .vop_mkdir      = uk_9pfs_mkdir,
+       .vop_rmdir      = uk_9pfs_rmdir,
+       .vop_getattr    = uk_9pfs_getattr,
+       .vop_setattr    = uk_9pfs_setattr,
+       .vop_inactive   = uk_9pfs_inactive,
+       .vop_truncate   = uk_9pfs_truncate,
+       .vop_link       = uk_9pfs_link,
+       .vop_cache      = uk_9pfs_cache,
+       .vop_fallocate  = uk_9pfs_fallocate,
+       .vop_readlink   = uk_9pfs_readlink,
+       .vop_symlink    = uk_9pfs_symlink
+};
diff --git a/lib/9pfs/Makefile.uk b/lib/9pfs/Makefile.uk
index e93ecc34..9d4dfb57 100644
--- a/lib/9pfs/Makefile.uk
+++ b/lib/9pfs/Makefile.uk
@@ -1 +1,4 @@
 $(eval $(call addlib_s,lib9pfs,$(CONFIG_LIB9PFS)))
+
+LIB9PFS_SRCS-y += $(LIB9PFS_BASE)/9pfs_vfsops.c
+LIB9PFS_SRCS-y += $(LIB9PFS_BASE)/9pfs_vnops.c
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.