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

[Minios-devel] [UNIKRAFT PATCH 7/7] lib/9pfs: Add read and write vnops


  • To: "minios-devel@xxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Sat, 7 Sep 2019 09:59:56 +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=HswhVuC1oX7eq23UoeLIqr8mC6rZIAzb7jl6FZrwI0A=; b=BrLlNI9nMx9iJYBA0LB9V3+sNvvLqPPQcM/ZBwHVEXWV+DdljtUPWOcvOrzv0xxenIUMCe8TlfM/0BXUKjXmjiwAcRWRVLH8McB+MTMEPb6gTS77mE7S4+VC0g7yiLltXtwoyaAUWrTM7fqFdRJfysykTzrpjHiod7Q0tl0s1uQN9Dp8hZncNJmcosp6BoiWGSth+e9so+U/3wV3R3/iJ0UlIxhoEWuxbnTrlp/5JLfVjuDw675bDSjD9zZGh8LPRvOwFxTBngcDzvgupE7EanaVCJJV0DTHq+gvvDH66ty2wDVjH5AfvzRqEJ7XNrrgoVK1rmWJ26/FqW4HGc53Qw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UqTBAw05WwD5Rx/Js80WWbioR1E+fQJjxS3E59dqXVYNkqbXhLEy1oFpU68ztvpjKvdpws0lz6qIl+m06a3bFDVg4UHf9YFS8bUyYK4jayt+xlFNC87y92wWsAbNW+BoQ6hlXbTqC/vkBtx5OQcCNDqljFaXBy6UYQ6+iAGKsAB64HI2VIUH9kWss/i2kP+LbjDxIcrt/IkiXxN7UleDSFe8efG/DGt0IyPfKjpxnrlSBrw4tdn7Hpz4sjRBzpR2NpqysRQpnxvVfI5LEL0WfB3NUJiX5LsS6u9KEZSeL1qXlTbGL8Wnj+kAyBJkTunwTrbjPD54e1NMBv85ZYQiHg==
  • 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:32 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVZWMAg4rfQzrDZECpAh7lPp76Ow==
  • Thread-topic: [UNIKRAFT PATCH 7/7] lib/9pfs: Add read and write vnops

From: Cristian Banu <cristb@xxxxxxxxx>

This patch adds the read and write VFS node operations.

Signed-off-by: Cristian Banu <cristb@xxxxxxxxx>
---
 lib/9pfs/9pfs_vnops.c | 108 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 2 deletions(-)

diff --git a/lib/9pfs/9pfs_vnops.c b/lib/9pfs/9pfs_vnops.c
index bf008a88..53d00b8e 100644
--- a/lib/9pfs/9pfs_vnops.c
+++ b/lib/9pfs/9pfs_vnops.c
@@ -443,6 +443,112 @@ out:
        return -rc;
 }
 
+static int uk_9pfs_read(struct vnode *vp, struct vfscore_file *fp,
+                       struct uio *uio, int ioflag __unused)
+{
+       struct uk_9pdev *dev = UK_9PFS_MD(vp->v_mount)->dev;
+       struct uk_9pfid *fid = UK_9PFS_FD(fp)->fid;
+       struct iovec *iov;
+       int rc;
+
+       if (vp->v_type == VDIR)
+               return EISDIR;
+       if (vp->v_type != VREG)
+               return EINVAL;
+       if (uio->uio_offset < 0)
+               return EINVAL;
+       if (uio->uio_offset >= (off_t) vp->v_size)
+               return 0;
+
+       if (!uio->uio_resid)
+               return 0;
+
+       iov = uio->uio_iov;
+       while (!iov->iov_len) {
+               uio->uio_iov++;
+               uio->uio_iovcnt--;
+       }
+
+       rc = uk_9p_read(dev, fid, uio->uio_offset,
+                          iov->iov_len, iov->iov_base);
+       if (rc < 0)
+               return -rc;
+
+       iov->iov_base = (char *)iov->iov_base + rc;
+       iov->iov_len -= rc;
+       uio->uio_resid -= rc;
+       uio->uio_offset += rc;
+
+       return 0;
+}
+
+static int uk_9pfs_write(struct vnode *vp, struct uio *uio, int ioflag)
+{
+       struct uk_9pdev *dev = UK_9PFS_MD(vp->v_mount)->dev;
+       struct uk_9pfid *fid;
+       struct iovec *iov;
+       int rc;
+
+       if (vp->v_type == VDIR)
+               return EISDIR;
+       if (vp->v_type != VREG)
+               return EINVAL;
+       if (uio->uio_offset < 0)
+               return EINVAL;
+       if (uio->uio_offset >= LONG_MAX)
+               return EFBIG;
+       if (uio->uio_resid == 0)
+               return 0;
+
+       if (ioflag & IO_APPEND)
+               uio->uio_offset = vp->v_size;
+
+       /* Clone vnode fid. */
+       fid = uk_9p_walk(dev, UK_9PFS_VFID(vp), NULL);
+       if (PTRISERR(fid))
+               return -PTR2ERR(fid);
+
+       rc = uk_9p_open(dev, fid, UK_9P_OWRITE);
+       if (rc < 0)
+               goto out;
+
+       if (!uio->uio_resid)
+               return 0;
+
+       iov = uio->uio_iov;
+       while (!iov->iov_len) {
+               uio->uio_iov++;
+               uio->uio_iovcnt--;
+       }
+
+       rc = uk_9p_write(dev, fid, uio->uio_offset,
+                           iov->iov_len, iov->iov_base);
+       if (rc < 0)
+               return -rc;
+
+       iov->iov_base = (char *)iov->iov_base + rc;
+       iov->iov_len -= rc;
+       uio->uio_resid -= rc;
+       uio->uio_offset += rc;
+
+       if (rc < 0)
+               goto out;
+
+       rc = 0;
+
+       /*
+        * If the uio offset after completion of the write requests is bigger
+        * than the vnode's associated size, then the size must be updated
+        * accordingly.
+        */
+       if (uio->uio_offset > vp->v_size)
+               vp->v_size = uio->uio_offset;
+
+out:
+       uk_9pfid_put(fid);
+       return -rc;
+}
+
 #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)
@@ -455,8 +561,6 @@ out:
 #define uk_9pfs_symlink                ((vnop_symlink_t)vfscore_vop_eperm)
 #define uk_9pfs_fallocate      ((vnop_fallocate_t)vfscore_vop_nullop)
 #define uk_9pfs_rename         ((vnop_rename_t)vfscore_vop_einval)
-#define uk_9pfs_read           ((vnop_read_t)vfscore_vop_einval)
-#define uk_9pfs_write          ((vnop_write_t)vfscore_vop_einval)
 
 struct vnops uk_9pfs_vnops = {
        .vop_open       = uk_9pfs_open,
-- 
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®.