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

[Minios-devel] [UNIKRAFT PATCH 08/22] lib/vfscore: use Unikraft types and functions



Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 lib/vfscore/dentry.c                 | 137 ++++++++++++++-------------
 lib/vfscore/fops.c                   |   2 +-
 lib/vfscore/include/vfscore/dentry.h |  10 +-
 lib/vfscore/include/vfscore/mount.h  |   1 +
 lib/vfscore/include/vfscore/vnode.h  |  29 +++---
 lib/vfscore/lookup.c                 |  30 +++---
 lib/vfscore/main.c                   | 121 +++++++++++------------
 lib/vfscore/mount.c                  | 114 ++++++++++++----------
 lib/vfscore/subr_uio.c               |   2 +-
 lib/vfscore/syscalls.c               | 128 ++++++++++++-------------
 lib/vfscore/vfs.h                    |  38 ++++----
 lib/vfscore/vnode.c                  | 122 ++++++++++++------------
 12 files changed, 376 insertions(+), 358 deletions(-)

diff --git a/lib/vfscore/dentry.c b/lib/vfscore/dentry.c
index a780203f..aea94364 100644
--- a/lib/vfscore/dentry.c
+++ b/lib/vfscore/dentry.c
@@ -45,18 +45,18 @@
 
 #define DENTRY_BUCKETS 32
 
-static LIST_HEAD(dentry_hash_head, dentry) dentry_hash_table[DENTRY_BUCKETS];
-static LIST_HEAD(fake, dentry) fake;
-static mutex dentry_hash_lock;
+static struct uk_hlist_head dentry_hash_table[DENTRY_BUCKETS];
+static UK_HLIST_HEAD(fake);
+static struct uk_mutex dentry_hash_lock;
 
 /*
  * Get the hash value from the mount point and path name.
  * XXX: replace with a better hash for 64-bit pointers.
  */
-static u_int
+static unsigned int
 dentry_hash(struct mount *mp, const char *path)
 {
-       u_int val = 0;
+       unsigned int val = 0;
 
        if (path) {
                while (*path) {
@@ -71,10 +71,10 @@ struct dentry *
 dentry_alloc(struct dentry *parent_dp, struct vnode *vp, const char *path)
 {
        struct mount *mp = vp->v_mount;
-       struct dentry *dp = (dentry*)calloc(sizeof(*dp), 1);
+       struct dentry *dp = (struct dentry*)calloc(sizeof(*dp), 1);
 
        if (!dp) {
-               return nullptr;
+               return NULL;
        }
 
        vref(vp);
@@ -83,22 +83,24 @@ dentry_alloc(struct dentry *parent_dp, struct vnode *vp, 
const char *path)
        dp->d_vnode = vp;
        dp->d_mount = mp;
        dp->d_path = strdup(path);
-       LIST_INIT(&dp->d_children);
+       UK_INIT_LIST_HEAD(&dp->d_child_list);
 
        if (parent_dp) {
                dref(parent_dp);
-               WITH_LOCK(parent_dp->d_lock) {
-                       // Insert dp into its parent's children list.
-                       LIST_INSERT_HEAD(&parent_dp->d_children, dp, 
d_children_link);
-               }
+
+               uk_mutex_lock(&parent_dp->d_lock);
+               // Insert dp into its parent's children list.
+               uk_list_add(&dp->d_child_link, &parent_dp->d_child_list);
+               uk_mutex_unlock(&parent_dp->d_lock);
        }
        dp->d_parent = parent_dp;
 
        vn_add_name(vp, dp);
 
-       mutex_lock(&dentry_hash_lock);
-       LIST_INSERT_HEAD(&dentry_hash_table[dentry_hash(mp, path)], dp, d_link);
-       mutex_unlock(&dentry_hash_lock);
+       uk_mutex_lock(&dentry_hash_lock);
+       uk_hlist_add_head(&dp->d_link,
+                         &dentry_hash_table[dentry_hash(mp, path)]);
+       uk_mutex_unlock(&dentry_hash_lock);
        return dp;
 };
 
@@ -107,29 +109,30 @@ dentry_lookup(struct mount *mp, char *path)
 {
        struct dentry *dp;
 
-       mutex_lock(&dentry_hash_lock);
-       LIST_FOREACH(dp, &dentry_hash_table[dentry_hash(mp, path)], d_link) {
+       uk_mutex_lock(&dentry_hash_lock);
+       uk_hlist_for_each_entry(dp, &dentry_hash_table[dentry_hash(mp, path)], 
d_link) {
                if (dp->d_mount == mp && !strncmp(dp->d_path, path, PATH_MAX)) {
                        dp->d_refcnt++;
-                       mutex_unlock(&dentry_hash_lock);
+                       uk_mutex_unlock(&dentry_hash_lock);
                        return dp;
                }
        }
-       mutex_unlock(&dentry_hash_lock);
-       return nullptr;                /* not found */
+       uk_mutex_unlock(&dentry_hash_lock);
+       return NULL;                /* not found */
 }
 
 static void dentry_children_remove(struct dentry *dp)
 {
-       struct dentry *entry = nullptr;
+       struct dentry *entry = NULL;
 
-       WITH_LOCK(dp->d_lock) {
-               LIST_FOREACH(entry, &dp->d_children, d_children_link) {
-                       ASSERT(entry);
-                       ASSERT(entry->d_refcnt > 0);
-                       LIST_REMOVE(entry, d_link);
-               }
+       uk_mutex_lock(&dp->d_lock);
+       uk_list_for_each_entry(entry, &dp->d_child_list, d_child_link) {
+               UK_ASSERT(entry);
+               UK_ASSERT(entry->d_refcnt > 0);
+               uk_hlist_del(&entry->d_link);
        }
+       uk_mutex_unlock(&dp->d_lock);
+
 }
 
 void
@@ -139,33 +142,34 @@ dentry_move(struct dentry *dp, struct dentry *parent_dp, 
char *path)
        char *old_path = dp->d_path;
 
        if (old_pdp) {
-               WITH_LOCK(old_pdp->d_lock) {
-                       // Remove dp from its old parent's children list.
-                       LIST_REMOVE(dp, d_children_link);
-               }
+               uk_mutex_lock(&old_pdp->d_lock);
+               // Remove dp from its old parent's children list.
+               uk_list_del(&dp->d_child_link);
+               uk_mutex_unlock(&old_pdp->d_lock);
        }
 
        if (parent_dp) {
                dref(parent_dp);
-               WITH_LOCK(parent_dp->d_lock) {
-                       // Insert dp into its new parent's children list.
-                       LIST_INSERT_HEAD(&parent_dp->d_children, dp, 
d_children_link);
-               }
-       }
 
-       WITH_LOCK(dentry_hash_lock) {
-               // Remove all dp's child dentries from the hashtable.
-               dentry_children_remove(dp);
-               // Remove dp with outdated hash info from the hashtable.
-               LIST_REMOVE(dp, d_link);
-               // Update dp.
-               dp->d_path = strdup(path);
-               dp->d_parent = parent_dp;
-               // Insert dp updated hash info into the hashtable.
-               LIST_INSERT_HEAD(&dentry_hash_table[dentry_hash(dp->d_mount, 
path)],
-                       dp, d_link);
+               uk_mutex_lock(&parent_dp->d_lock);
+               // Insert dp into its new parent's children list.
+               uk_list_add(&dp->d_child_link, &parent_dp->d_child_list);
+               uk_mutex_unlock(&parent_dp->d_lock);
        }
 
+       uk_mutex_lock(&dentry_hash_lock);
+       // Remove all dp's child dentries from the hashtable.
+       dentry_children_remove(dp);
+       // Remove dp with outdated hash info from the hashtable.
+       uk_hlist_del(&dp->d_link);
+       // Update dp.
+       dp->d_path = strdup(path);
+       dp->d_parent = parent_dp;
+       // Insert dp updated hash info into the hashtable.
+       uk_hlist_add_head(&dp->d_link,
+                         &dentry_hash_table[dentry_hash(dp->d_mount, path)]);
+       uk_mutex_unlock(&dentry_hash_lock);
+
        if (old_pdp) {
                drele(old_pdp);
        }
@@ -176,45 +180,46 @@ dentry_move(struct dentry *dp, struct dentry *parent_dp, 
char *path)
 void
 dentry_remove(struct dentry *dp)
 {
-       mutex_lock(&dentry_hash_lock);
-       LIST_REMOVE(dp, d_link);
+       uk_mutex_lock(&dentry_hash_lock);
+       uk_hlist_del(&dp->d_link);
        /* put it on a fake list for drele() to work*/
-       LIST_INSERT_HEAD(&fake, dp, d_link);
-       mutex_unlock(&dentry_hash_lock);
+       uk_hlist_add_head(&dp->d_link, &fake);
+       uk_mutex_unlock(&dentry_hash_lock);
 }
 
 void
 dref(struct dentry *dp)
 {
-       ASSERT(dp);
-       ASSERT(dp->d_refcnt > 0);
+       UK_ASSERT(dp);
+       UK_ASSERT(dp->d_refcnt > 0);
 
-       mutex_lock(&dentry_hash_lock);
+       uk_mutex_lock(&dentry_hash_lock);
        dp->d_refcnt++;
-       mutex_unlock(&dentry_hash_lock);
+       uk_mutex_unlock(&dentry_hash_lock);
 }
 
 void
 drele(struct dentry *dp)
 {
-       ASSERT(dp);
-       ASSERT(dp->d_refcnt > 0);
+       UK_ASSERT(dp);
+       UK_ASSERT(dp->d_refcnt > 0);
 
-       mutex_lock(&dentry_hash_lock);
+       uk_mutex_lock(&dentry_hash_lock);
        if (--dp->d_refcnt) {
-               mutex_unlock(&dentry_hash_lock);
+               uk_mutex_unlock(&dentry_hash_lock);
                return;
        }
-       LIST_REMOVE(dp, d_link);
+       uk_hlist_del(&dp->d_link);
        vn_del_name(dp->d_vnode, dp);
 
-       mutex_unlock(&dentry_hash_lock);
+       uk_mutex_unlock(&dentry_hash_lock);
 
        if (dp->d_parent) {
-               WITH_LOCK(dp->d_parent->d_lock) {
-                       // Remove dp from its parent's children list.
-                       LIST_REMOVE(dp, d_children_link);
-               }
+               uk_mutex_lock(&dp->d_parent->d_lock);
+               // Remove dp from its parent's children list.
+               uk_list_del(&dp->d_child_link);
+               uk_mutex_unlock(&dp->d_parent->d_lock);
+
                drele(dp->d_parent);
        }
 
@@ -230,6 +235,6 @@ dentry_init(void)
        int i;
 
        for (i = 0; i < DENTRY_BUCKETS; i++) {
-               LIST_INIT(&dentry_hash_table[i]);
+               UK_INIT_HLIST_HEAD(&dentry_hash_table[i]);
        }
 }
diff --git a/lib/vfscore/fops.c b/lib/vfscore/fops.c
index a1c07821..068a2e84 100644
--- a/lib/vfscore/fops.c
+++ b/lib/vfscore/fops.c
@@ -88,7 +88,7 @@ int vfs_write(struct vfscore_file *fp, struct uio *uio, int 
flags)
        return error;
 }
 
-int vfs_ioctl(struct vfscore_file *fp, u_long com, void *data)
+int vfs_ioctl(struct vfscore_file *fp, unsigned long com, void *data)
 {
        struct vnode *vp = fp->f_dentry->d_vnode;
        int error;
diff --git a/lib/vfscore/include/vfscore/dentry.h 
b/lib/vfscore/include/vfscore/dentry.h
index f499b2bb..45839581 100644
--- a/lib/vfscore/include/vfscore/dentry.h
+++ b/lib/vfscore/include/vfscore/dentry.h
@@ -14,16 +14,16 @@
 struct vnode;
 
 struct dentry {
-       LIST_ENTRY(dentry) d_link;      /* link for hash list */
+       struct uk_hlist_node d_link;    /* link for hash list */
        int             d_refcnt;       /* reference count */
        char            *d_path;        /* pointer to path in fs */
        struct vnode    *d_vnode;
        struct mount    *d_mount;
        struct dentry   *d_parent; /* pointer to parent */
-       LIST_ENTRY(dentry) d_names_link; /* link fo vnode::d_names */
-       mutex_t         d_lock;
-       LIST_HEAD(, dentry) d_children;
-       LIST_ENTRY(dentry) d_children_link;
+       struct uk_list_head d_names_link; /* link fo vnode::d_names */
+       struct uk_mutex d_lock;
+       struct uk_list_head d_child_list;
+       struct uk_list_head d_child_link;
 };
 
 #endif /* _OSV_DENTRY_H */
diff --git a/lib/vfscore/include/vfscore/mount.h 
b/lib/vfscore/include/vfscore/mount.h
index e12a1039..7a638dbe 100644
--- a/lib/vfscore/include/vfscore/mount.h
+++ b/lib/vfscore/include/vfscore/mount.h
@@ -52,6 +52,7 @@ struct mount {
        struct dentry   *m_root;        /* root vnode */
        struct dentry   *m_covered;     /* vnode covered on parent fs */
        void            *m_data;        /* private data for fs */
+       struct uk_list_head mnt_list;
        fsid_t          m_fsid;         /* id that uniquely identifies the fs */
 };
 
diff --git a/lib/vfscore/include/vfscore/vnode.h 
b/lib/vfscore/include/vfscore/vnode.h
index 52de2fdf..64f4ad0c 100644
--- a/lib/vfscore/include/vfscore/vnode.h
+++ b/lib/vfscore/include/vfscore/vnode.h
@@ -44,7 +44,7 @@
 struct vfsops;
 struct vnops;
 struct vnode;
-struct file;
+struct vfscore_file;
 
 /*
  * Vnode types.
@@ -67,7 +67,7 @@ enum vtype {
  */
 struct vnode {
        uint64_t        v_ino;          /* inode number */
-       LIST_ENTRY(vnode) v_link;       /* link for hash list */
+       struct uk_list_head v_link;     /* link for hash list */
        struct mount    *v_mount;       /* mounted vfs pointer */
        struct vnops    *v_op;          /* vnode operations */
        int             v_refcnt;       /* reference count */
@@ -75,9 +75,8 @@ struct vnode {
        int             v_flags;        /* vnode flag */
        mode_t          v_mode;         /* file mode */
        off_t           v_size;         /* file size */
-       mutex_t         v_lock;         /* lock for this vnode */
-       LIST_HEAD(, dentry) v_names;    /* directory entries pointing at this */
-       int             v_nrlocks;      /* lock count (for debug) */
+       struct uk_mutex v_lock;         /* lock for this vnode */
+       struct uk_list_head v_names;    /* directory entries pointing at this */
        void            *v_data;        /* private data for fs */
 };
 
@@ -124,14 +123,14 @@ struct vattr {
 #define ARC_ACTION_HOLD     1
 #define ARC_ACTION_RELEASE  2
 
-typedef        int (*vnop_open_t)      (struct file *);
-typedef        int (*vnop_close_t)     (struct vnode *, struct file *);
-typedef        int (*vnop_read_t)      (struct vnode *, struct file *, struct 
uio *, int);
-typedef        int (*vnop_write_t)     (struct vnode *, struct uio *, int);
-typedef        int (*vnop_seek_t)      (struct vnode *, struct file *, off_t, 
off_t);
-typedef        int (*vnop_ioctl_t)     (struct vnode *, struct file *, u_long, 
void *);
-typedef        int (*vnop_fsync_t)     (struct vnode *, struct file *);
-typedef        int (*vnop_readdir_t)   (struct vnode *, struct file *, struct 
dirent *);
+typedef        int (*vnop_open_t)      (struct vfscore_file *);
+typedef        int (*vnop_close_t)     (struct vnode *, struct vfscore_file *);
+typedef        ssize_t (*vnop_read_t)  (struct vnode *, struct vfscore_file *, 
struct uio *, int);
+typedef        ssize_t (*vnop_write_t) (struct vnode *, struct uio *, int);
+typedef        off_t (*vnop_seek_t)    (struct vnode *, struct vfscore_file *, 
off_t, off_t);
+typedef        int (*vnop_ioctl_t)     (struct vnode *, struct vfscore_file *, 
unsigned long, void *);
+typedef        int (*vnop_fsync_t)     (struct vnode *, struct vfscore_file *);
+typedef        int (*vnop_readdir_t)   (struct vnode *, struct vfscore_file *, 
struct dirent *);
 typedef        int (*vnop_lookup_t)    (struct vnode *, char *, struct vnode 
**);
 typedef        int (*vnop_create_t)    (struct vnode *, char *, mode_t);
 typedef        int (*vnop_remove_t)    (struct vnode *, struct vnode *, char 
*);
@@ -144,8 +143,8 @@ typedef     int (*vnop_setattr_t)   (struct vnode *, struct 
vattr *);
 typedef        int (*vnop_inactive_t)  (struct vnode *);
 typedef        int (*vnop_truncate_t)  (struct vnode *, off_t);
 typedef        int (*vnop_link_t)      (struct vnode *, struct vnode *, char 
*);
-typedef int (*vnop_cache_t) (struct vnode *, struct file *, struct uio *);
-typedef int (*vnop_fallocate_t) (struct vnode *, int, loff_t, loff_t);
+typedef int (*vnop_cache_t) (struct vnode *, struct vfscore_file *, struct uio 
*);
+typedef int (*vnop_fallocate_t) (struct vnode *, int, off_t, off_t);
 typedef int (*vnop_readlink_t)  (struct vnode *, struct uio *);
 typedef int (*vnop_symlink_t)   (struct vnode *, char *, char *);
 
diff --git a/lib/vfscore/lookup.c b/lib/vfscore/lookup.c
index 45bbfe6d..7fe06d6a 100644
--- a/lib/vfscore/lookup.c
+++ b/lib/vfscore/lookup.c
@@ -108,7 +108,7 @@ namei(const char *path, struct dentry **dpp)
        struct vnode *dvp, *vp;
        int error, i;
        int links_followed;
-       bool need_continue;
+       int need_continue;
 
        DPRINTF(VFSDB_VNODE, ("namei: path=%s\n", path));
 
@@ -116,7 +116,7 @@ namei(const char *path, struct dentry **dpp)
        strlcpy(fp, path, PATH_MAX);
 
        do {
-               need_continue = false;
+               need_continue = 0;
                /*
                 * Convert a full path name to its mount point and
                 * the local node in the file system.
@@ -140,7 +140,7 @@ namei(const char *path, struct dentry **dpp)
                 */
                ddp = mp->m_root;
                if (!ddp) {
-                       sys_panic("VFS: no root");
+                       UK_CRASH("VFS: no root");
                }
                dref(ddp);
 
@@ -174,7 +174,7 @@ namei(const char *path, struct dentry **dpp)
                        dvp = ddp->d_vnode;
                        vn_lock(dvp);
                        dp = dentry_lookup(mp, node);
-                       if (dp == nullptr) {
+                       if (dp == NULL) {
                                /* Find a vnode in this directory. */
                                error = VOP_LOOKUP(dvp, name, &vp);
                                if (error) {
@@ -206,17 +206,17 @@ namei(const char *path, struct dentry **dpp)
                                drele(dp);
 
                                p       = fp;
-                               dp      = nullptr;
-                               ddp     = nullptr;
-                               vp      = nullptr;
-                               dvp     = nullptr;
+                               dp      = NULL;
+                               ddp     = NULL;
+                               vp      = NULL;
+                               dvp     = NULL;
                                name[0] = 0;
                                node[0] = 0;
 
                                if (++links_followed >= MAXSYMLINKS) {
                                        return (ELOOP);
                                }
-                               need_continue = true;
+                               need_continue = 1;
                                break;
                        }
 
@@ -225,7 +225,7 @@ namei(const char *path, struct dentry **dpp)
                                return ENOTDIR;
                        }
                }
-       } while (need_continue == true);
+       } while (need_continue);
 
        *dpp = dp;
        return 0;
@@ -250,14 +250,14 @@ namei_last_nofollow(char *path, struct dentry *ddp, 
struct dentry **dpp)
        struct vnode  *vp;
        char node[PATH_MAX];
 
-       dvp  = nullptr;
+       dvp  = NULL;
 
        if (path[0] != '/') {
                return (ENOTDIR);
        }
 
        name = strrchr(path, '/');
-       if (name == nullptr) {
+       if (name == NULL) {
                return (ENOENT);
        }
        name++;
@@ -280,7 +280,7 @@ namei_last_nofollow(char *path, struct dentry *ddp, struct 
dentry **dpp)
        dvp = ddp->d_vnode;
        vn_lock(dvp);
        dp = dentry_lookup(mp, node);
-       if (dp == nullptr) {
+       if (dp == NULL) {
                error = VOP_LOOKUP(dvp, name, &vp);
                if (error != 0) {
                        goto out;
@@ -289,7 +289,7 @@ namei_last_nofollow(char *path, struct dentry *ddp, struct 
dentry **dpp)
                dp = dentry_alloc(ddp, vp, node);
                vput(vp);
 
-               if (dp == nullptr) {
+               if (dp == NULL) {
                        error = ENOMEM;
                        goto out;
                }
@@ -298,7 +298,7 @@ namei_last_nofollow(char *path, struct dentry *ddp, struct 
dentry **dpp)
        *dpp  = dp;
        error = 0;
 out:
-       if (dvp != nullptr) {
+       if (dvp != NULL) {
                vn_unlock(dvp);
        }
        return (error);
diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index 2bd27736..3cd5b097 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -83,7 +83,7 @@ int open(const char *pathname, int flags, ...)
 
        struct task *t = main_task;
        char path[PATH_MAX];
-       struct file *fp;
+       struct vfscore_file *fp;
        int fd, error;
        int acc;
 
@@ -139,7 +139,7 @@ int openat(int dirfd, const char *pathname, int flags, ...)
                return open(pathname, flags, mode);
        }
 
-       struct file *fp;
+       struct vfscore_file *fp;
        int error = fget(dirfd, &fp);
        if (error) {
                errno = error;
@@ -201,7 +201,7 @@ TRACEPOINT(trace_vfs_mknod_err, "%d", int);
 
 int __xmknod(int ver, const char *pathname, mode_t mode, dev_t *dev)
 {
-       assert(ver == 0); // On x86-64 Linux, _MKNOD_VER_LINUX is 0.
+       UK_ASSERT(ver == 0); // On x86-64 Linux, _MKNOD_VER_LINUX is 0.
        struct task *t = main_task;
        char path[PATH_MAX];
        int error;
@@ -235,7 +235,7 @@ TRACEPOINT(trace_vfs_lseek_err, "%d", int);
 
 off_t lseek(int fd, off_t offset, int whence)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        off_t org;
        int error;
 
@@ -269,11 +269,12 @@ TRACEPOINT(trace_vfs_pread_err, "%d", int);
 // *and* a non-zero number of written bytes. In that case, we need to zero the
 // error, so the system call appear a successful partial read/write.
 // In FreeBSD, dofilewrite() and dofileread() (sys_generic.c) do this too.
-static inline bool has_error(int error, int bytes)
+static inline int has_error(int error, int bytes)
 {
+       /* TODO: OSv checks also for ERESTART */
        return error && (
                        (bytes == 0) ||
-                       (error != EWOULDBLOCK && error != EINTR && error != 
ERESTART));
+                       (error != EWOULDBLOCK && error != EINTR));
 }
 
 
@@ -284,7 +285,7 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset)
                        .iov_base       = buf,
                        .iov_len        = count,
        };
-       struct file *fp;
+       struct vfscore_file *fp;
        size_t bytes;
        int error;
 
@@ -324,7 +325,7 @@ ssize_t pwrite(int fd, const void *buf, size_t count, off_t 
offset)
                        .iov_base       = (void *)buf,
                        .iov_len        = count,
        };
-       struct file *fp;
+       struct vfscore_file *fp;
        size_t bytes;
        int error;
 
@@ -355,7 +356,7 @@ ssize_t write(int fd, const void *buf, size_t count)
 
 ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        size_t bytes;
        int error;
 
@@ -388,7 +389,7 @@ TRACEPOINT(trace_vfs_pwritev_err, "%d", int);
 
 ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        size_t bytes;
        int error;
 
@@ -423,7 +424,7 @@ TRACEPOINT(trace_vfs_ioctl_err, "%d", int);
 
 int ioctl(int fd, unsigned long int request, ...)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
        va_list ap;
        void* arg;
@@ -460,7 +461,7 @@ TRACEPOINT(trace_vfs_fsync_err, "%d", int);
 
 int fsync(int fd)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        trace_vfs_fsync(fd);
@@ -494,7 +495,7 @@ TRACEPOINT(trace_vfs_fstat_err, "%d", int);
 
 int __fxstat(int ver, int fd, struct stat *st)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        trace_vfs_fstat(fd, st);
@@ -530,7 +531,7 @@ int __fxstatat(int ver, int dirfd, const char *pathname, 
struct stat *st,
                int flags)
 {
        if (flags & AT_SYMLINK_NOFOLLOW) {
-               UNIMPLEMENTED("fstatat() with AT_SYMLINK_NOFOLLOW");
+               UK_CRASH("UNIMPLEMENTED: fstatat() with AT_SYMLINK_NOFOLLOW");
        }
 
        if (pathname[0] == '/' || dirfd == AT_FDCWD) {
@@ -542,7 +543,7 @@ int __fxstatat(int ver, int dirfd, const char *pathname, 
struct stat *st,
                return fstat(dirfd, st);
        }
 
-       struct file *fp;
+       struct vfscore_file *fp;
        int error = fget(dirfd, &fp);
        if (error) {
                errno = error;
@@ -578,7 +579,9 @@ LFS64(fstatat);
 
 int flock(int fd, int operation)
 {
-       if (!fileref_from_fd(fd)) {
+       struct vfscore_file *file;
+
+       if (!fget(fd, &file)) {
                return libc_error(EBADF);
        }
 
@@ -596,7 +599,7 @@ int flock(int fd, int operation)
        return 0;
 }
 
-TRACEPOINT(trace_vfs_readdir, "%d %p", int, dirent*);
+TRACEPOINT(trace_vfs_readdir, "%d %p", int, struct dirent*);
 TRACEPOINT(trace_vfs_readdir_ret, "");
 TRACEPOINT(trace_vfs_readdir_err, "%d", int);
 
@@ -615,7 +618,7 @@ DIR *opendir(const char *path)
        dir->fd = open(path, O_RDONLY);
        if (dir->fd < 0) {
                free(dir);
-               return nullptr;
+               return NULL;
        }
        return dir;
 }
@@ -625,11 +628,11 @@ DIR *fdopendir(int fd)
        DIR *dir;
        struct stat st;
        if (fstat(fd, &st) < 0) {
-               return nullptr;
+               return NULL;
        }
        if (!S_ISDIR(st.st_mode)) {
                errno = ENOTDIR;
-               return nullptr;
+               return NULL;
        }
        dir = malloc(sizeof(*dir));
        if (!dir) {
@@ -673,13 +676,11 @@ struct dirent *readdir(DIR *dir)
 int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
 {
        int error;
-       struct file *fp;
+       struct vfscore_file *fp;
 
        trace_vfs_readdir(dir->fd, entry);
        error = fget(dir->fd, &fp);
-       if (error) {
-               trace_vfs_readdir_err(error);
-       } else {
+       if (!error) {
                error = sys_readdir(fp, entry);
                fdrop(fp);
                if (error) {
@@ -692,7 +693,7 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent 
**result)
        entry->d_reclen = sizeof(*entry);
 
        if (error) {
-               *result = nullptr;
+               *result = NULL;
        } else {
                *result = entry;
        }
@@ -710,7 +711,7 @@ struct dirent *readdir64(DIR *dir) 
__attribute__((alias("readdir")));
 
 void rewinddir(DIR *dirp)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
 
        int error = fget(dirp->fd, &fp);
        if (error) {
@@ -726,7 +727,7 @@ void rewinddir(DIR *dirp)
 
 long telldir(DIR *dirp)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error = fget(dirp->fd, &fp);
        if (error) {
                return libc_error(error);
@@ -743,7 +744,7 @@ long telldir(DIR *dirp)
 
 void seekdir(DIR *dirp, long loc)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error = fget(dirp->fd, &fp);
        if (error) {
                // POSIX specifies seekdir() cannot return errors.
@@ -794,7 +795,7 @@ int rmdir(const char *pathname)
 
        trace_vfs_rmdir(pathname);
        error = ENOENT;
-       if (pathname == nullptr)
+       if (pathname == NULL)
                goto out_errno;
        if ((error = task_conv(t, pathname, VWRITE, path)) != 0)
                goto out_errno;
@@ -830,9 +831,9 @@ get_last_component(const char *path, char *dst)
        dst[len] = 0;
 }
 
-static bool null_or_empty(const char *str)
+static int null_or_empty(const char *str)
 {
-       return str == nullptr || *str == '\0';
+       return str == NULL || *str == '\0';
 }
 
 TRACEPOINT(trace_vfs_rename, "\"%s\" \"%s\"", const char*, const char*);
@@ -887,7 +888,7 @@ TRACEPOINT(trace_vfs_chdir_err, "%d", int);
 static int
 __do_fchdir(struct vfscore_file *fp, struct task *t)
 {
-       struct file *old = nullptr;
+       struct vfscore_file *old = NULL;
 
        UK_ASSERT(t);
 
@@ -911,11 +912,11 @@ int chdir(const char *pathname)
        trace_vfs_chdir(pathname);
        struct task *t = main_task;
        char path[PATH_MAX];
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        error = ENOENT;
-       if (pathname == nullptr)
+       if (pathname == NULL)
                goto out_errno;
 
        if ((error = task_conv(t, pathname, VREAD, path)) != 0)
@@ -949,7 +950,7 @@ int fchdir(int fd)
 {
        trace_vfs_fchdir(fd);
        struct task *t = main_task;
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        error = fget(fd, &fp);
@@ -985,7 +986,7 @@ int link(const char *oldpath, const char *newpath)
        trace_vfs_link(oldpath, newpath);
 
        error = ENOENT;
-       if (oldpath == nullptr || newpath == nullptr)
+       if (oldpath == NULL || newpath == NULL)
                goto out_errno;
        if ((error = task_conv(t, oldpath, VWRITE, path1)) != 0)
                goto out_errno;
@@ -1015,7 +1016,7 @@ int symlink(const char *oldpath, const char *newpath)
        trace_vfs_symlink(oldpath, newpath);
 
        error = ENOENT;
-       if (oldpath == nullptr || newpath == nullptr) {
+       if (oldpath == NULL || newpath == NULL) {
                errno = ENOENT;
                trace_vfs_symlink_err(error);
                return (-1);
@@ -1044,7 +1045,7 @@ int unlink(const char *pathname)
        int error;
 
        error = ENOENT;
-       if (pathname == nullptr)
+       if (pathname == NULL)
                goto out_errno;
        if ((error = task_conv(t, pathname, VWRITE, path)) != 0)
                goto out_errno;
@@ -1160,7 +1161,7 @@ int __statfs(const char *pathname, struct statfs *buf)
        errno = error;
        return -1;
 }
-weak_alias(__statfs, statfs);
+__weak_alias(__statfs, statfs);
 
 LFS64(statfs);
 
@@ -1170,7 +1171,7 @@ TRACEPOINT(trace_vfs_fstatfs_err, "%d", int);
 
 int __fstatfs(int fd, struct statfs *buf)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        trace_vfs_fstatfs(fd, buf);
@@ -1191,7 +1192,7 @@ int __fstatfs(int fd, struct statfs *buf)
        errno = error;
        return -1;
 }
-weak_alias(__fstatfs, fstatfs);
+__weak_alias(__fstatfs, fstatfs);
 
 LFS64(fstatfs);
 
@@ -1245,7 +1246,7 @@ char *getcwd(char *path, size_t size)
 {
        trace_vfs_getcwd(path, size);
        struct task *t = main_task;
-       int len = strlen(t->t_cwd) + 1;
+       size_t len = strlen(t->t_cwd) + 1;
        int error;
 
        if (!path) {
@@ -1275,7 +1276,7 @@ char *getcwd(char *path, size_t size)
        out_errno:
        trace_vfs_getcwd_err(error);
        errno = error;
-       return nullptr;
+       return NULL;
 }
 
 TRACEPOINT(trace_vfs_dup, "%d", int);
@@ -1286,7 +1287,7 @@ TRACEPOINT(trace_vfs_dup_err, "%d", int);
  */
 int dup(int oldfd)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int newfd;
        int error;
 
@@ -1319,7 +1320,7 @@ TRACEPOINT(trace_vfs_dup3_err, "%d", int);
  */
 int dup3(int oldfd, int newfd, int flags)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        trace_vfs_dup3(oldfd, newfd, flags);
@@ -1341,7 +1342,7 @@ int dup3(int oldfd, int newfd, int flags)
        if (error)
                goto out_errno;
 
-       error = fdset(newfd, fp);
+       error = vfscore_install_fd(newfd, fp);
        if (error) {
                fdrop(fp);
                goto out_errno;
@@ -1377,7 +1378,7 @@ TRACEPOINT(trace_vfs_fcntl_err, "%d", int);
 
 int fcntl(int fd, int cmd, int arg)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int ret = 0, error;
        int tmp;
 
@@ -1494,14 +1495,14 @@ int access(const char *pathname, int mode)
 int faccessat(int dirfd, const char *pathname, int mode, int flags)
 {
        if (flags & AT_SYMLINK_NOFOLLOW) {
-               UNIMPLEMENTED("faccessat() with AT_SYMLINK_NOFOLLOW");
+               UK_CRASH("UNIMPLEMENTED: faccessat() with AT_SYMLINK_NOFOLLOW");
        }
 
        if (pathname[0] == '/' || dirfd == AT_FDCWD) {
                return access(pathname, mode);
        }
 
-       struct file *fp;
+       struct vfscore_file *fp;
        int error = fget(dirfd, &fp);
        if (error) {
                errno = error;
@@ -1532,7 +1533,7 @@ int euidaccess(const char *pathname, int mode)
        return access(pathname, mode);
 }
 
-weak_alias(euidaccess,eaccess);
+__weak_alias(euidaccess,eaccess);
 
 #if 0
 /*
@@ -1540,7 +1541,7 @@ weak_alias(euidaccess,eaccess);
  */
 int isatty(int fd)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int istty = 0;
 
        trace_vfs_isatty(fd);
@@ -1574,7 +1575,7 @@ int truncate(const char *pathname, off_t length)
        int error;
 
        error = ENOENT;
-       if (pathname == nullptr)
+       if (pathname == NULL)
                goto out_errno;
        if ((error = task_conv(t, pathname, VWRITE, path)) != 0)
                goto out_errno;
@@ -1599,7 +1600,7 @@ TRACEPOINT(trace_vfs_ftruncate_err, "%d", int);
 int ftruncate(int fd, off_t length)
 {
        trace_vfs_ftruncate(fd, length);
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        error = fget(fd, &fp);
@@ -1634,7 +1635,7 @@ ssize_t readlink(const char *pathname, char *buf, size_t 
bufsize)
                goto out_errno;
 
        error = ENOENT;
-       if (pathname == nullptr)
+       if (pathname == NULL)
                goto out_errno;
        error = task_conv(t, pathname, VWRITE, path);
        if (error)
@@ -1658,7 +1659,7 @@ TRACEPOINT(trace_vfs_fallocate_err, "%d", int);
 
 int fallocate(int fd, int mode, loff_t offset, loff_t len)
 {
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
 
        trace_vfs_fallocate(fd, mode, offset, len);
@@ -1686,14 +1687,14 @@ LFS64(fallocate);
 int futimesat(int dirfd, const char *pathname, const struct timeval times[2])
 {
        struct stat st;
-       struct file *fp;
+       struct vfscore_file *fp;
        int error;
        char *absolute_path;
 
        if ((pathname && pathname[0] == '/') || dirfd == AT_FDCWD)
                return utimes(pathname, times);
 
-       // Note: if pathname == nullptr, futimesat operates on dirfd itself, 
and in
+       // Note: if pathname == NULL, futimesat operates on dirfd itself, and in
        // that case it doesn't have to be a directory.
        if (pathname) {
                error = fstat(dirfd, &st);
@@ -1839,7 +1840,7 @@ int chmod(const char *pathname, mode_t mode)
        struct task *t = main_task;
        char path[PATH_MAX];
        int error = ENOENT;
-       if (pathname == nullptr)
+       if (pathname == NULL)
                goto out_errno;
        if ((error = task_conv(t, pathname, VWRITE, path)) != 0)
                goto out_errno;
@@ -1897,8 +1898,8 @@ int lchown(const char *path, uid_t owner, gid_t group)
 #if 0
 ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
 {
-       struct file *in_fp;
-       struct file *out_fp;
+       struct vfscore_file *in_fp;
+       struct vfscore_file *out_fp;
        fileref in_f{fileref_from_fd(in_fd)};
        fileref out_f{fileref_from_fd(out_fd)};
 
diff --git a/lib/vfscore/mount.c b/lib/vfscore/mount.c
index f7ab711e..7fecfd5d 100644
--- a/lib/vfscore/mount.c
+++ b/lib/vfscore/mount.c
@@ -51,12 +51,13 @@
 /*
  * List for VFS mount points.
  */
-static std::list<mount*> mount_list;
+
+UK_LIST_HEAD(mount_list);
 
 /*
  * Global lock to access mount point.
  */
-static mutex mount_lock;
+static struct uk_mutex mount_lock;
 
 /*
  * Lookup file system.
@@ -81,11 +82,11 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        const struct vfssw *fs;
        struct mount *mp;
        struct device *device;
-       struct dentry *dp_covered;
-       struct vnode *vp;
+       struct dentry *dp_covered = NULL;
+       struct vnode *vp = NULL;
        int error;
 
-       kprintf("VFS: mounting %s at %s\n", fsname, dir);
+       uk_pr_info("VFS: mounting %s at %s\n", fsname, dir);
 
        if (!dir || *dir == '\0')
                return ENOENT;
@@ -94,7 +95,7 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        if (!(fs = fs_getfs(fsname)))
                return ENODEV;  /* No such file system */
 
-       /* Open device. nullptr can be specified as a device. */
+       /* Open device. NULL can be specified as a device. */
        // Allow device_open() to fail, in which case dev is interpreted
        // by the file system mount routine (e.g zfs pools)
        device = 0;
@@ -108,17 +109,21 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        // that only one sys_mount() runs at a time. We cannot reuse the 
existing
        // mount_lock for this purpose: If we take mount_lock and then do
        // lookups, this is lock order inversion and can result in deadlock.
-       static mutex sys_mount_lock;
-       SCOPE_LOCK(sys_mount_lock);
-       WITH_LOCK(mount_lock) {
-               for (auto&& mp : mount_list) {
-                       if (!strcmp(mp->m_path, dir) ||
-                               (device && mp->m_dev == device)) {
-                               error = EBUSY;  /* Already mounted */
-                               goto err1;
-                       }
+
+       /* TODO: protect the function from reentrance, as described in
+        * the comment above */
+       /* static mutex sys_mount_lock; */
+       /* SCOPE_LOCK(sys_mount_lock); */
+
+       uk_mutex_lock(&mount_lock);
+       uk_list_for_each_entry(mp, &mount_list, mnt_list) {
+               if (!strcmp(mp->m_path, dir) ||
+                   (device && mp->m_dev == device)) {
+                       error = EBUSY;  /* Already mounted */
+                       goto err1;
                }
        }
+       uk_mutex_unlock(&mount_lock);
        /*
         * Create VFS mount entry.
         */
@@ -131,7 +136,7 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        mp->m_op = fs->vs_op;
        mp->m_flags = flags;
        mp->m_dev = device;
-       mp->m_data = nullptr;
+       mp->m_data = NULL;
        strlcpy(mp->m_path, dir, sizeof(mp->m_path));
        strlcpy(mp->m_special, dev, sizeof(mp->m_special));
 
@@ -140,7 +145,7 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
         */
        if (*dir == '/' && *(dir + 1) == '\0') {
                /* Ignore if it mounts to global root directory. */
-               dp_covered = nullptr;
+               dp_covered = NULL;
        } else {
                if ((error = namei(dir, &dp_covered)) != 0) {
 
@@ -157,8 +162,8 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        /*
         * Create a root vnode for this file system.
         */
-       vget(mp, 0, &vp);
-       if (vp == nullptr) {
+       vfscore_vget(mp, 0, &vp);
+       if (vp == NULL) {
                error = ENOMEM;
                goto err3;
        }
@@ -166,7 +171,7 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        vp->v_flags = VROOT;
        vp->v_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
 
-       mp->m_root = dentry_alloc(nullptr, vp, "/");
+       mp->m_root = dentry_alloc(NULL, vp, "/");
        if (!mp->m_root) {
                vput(vp);
                goto err3;
@@ -185,9 +190,9 @@ sys_mount(const char *dev, const char *dir, const char 
*fsname, int flags, const
        /*
         * Insert to mount list
         */
-       WITH_LOCK(mount_lock) {
-               mount_list.push_back(mp);
-       }
+       uk_mutex_lock(&mount_lock);
+       uk_list_add_tail(&mp->mnt_list, &mount_list);
+       uk_mutex_unlock(&mount_lock);
 
        return 0;   /* success */
  err4:
@@ -219,12 +224,12 @@ release_mp_dentries(struct mount *mp)
 int
 sys_umount2(const char *path, int flags)
 {
-       struct mount *mp;
+       struct mount *mp, *tmp;
        int error, pathlen;
 
-       kprintf("VFS: unmounting %s\n", path);
+       uk_pr_info("VFS: unmounting %s\n", path);
 
-       SCOPE_LOCK(mount_lock);
+       uk_mutex_lock(&mount_lock);
 
        pathlen = strlen(path);
        if (pathlen >= MAXPATHLEN) {
@@ -233,7 +238,7 @@ sys_umount2(const char *path, int flags)
        }
 
        /* Get mount entry */
-       for (auto&& tmp : mount_list) {
+       uk_list_for_each_entry(tmp, &mount_list, mnt_list) {
                if (!strcmp(path, tmp->m_path)) {
                        mp = tmp;
                        goto found;
@@ -247,14 +252,14 @@ found:
        /*
         * Root fs can not be unmounted.
         */
-       if (mp->m_covered == nullptr && !(flags & MNT_FORCE)) {
+       if (mp->m_covered == NULL && !(flags & MNT_FORCE)) {
                error = EINVAL;
                goto out;
        }
 
        if ((error = VFS_UNMOUNT(mp, flags)) != 0)
                goto out;
-       mount_list.remove(mp);
+       uk_list_del_init(&mp->mnt_list);
 
 #ifdef HAVE_BUFFERS
        /* Flush all buffers */
@@ -265,6 +270,7 @@ found:
                device_close(mp->m_dev);
        free(mp);
  out:
+       uk_mutex_unlock(&mount_lock);
        return error;
 }
 
@@ -278,7 +284,7 @@ sys_umount(const char *path)
 int
 sys_pivot_root(const char *new_root, const char *put_old)
 {
-       struct mount *newmp = nullptr, *oldmp = nullptr;
+       struct mount *newmp = NULL, *oldmp = NULL;
        int error;
 
        WITH_LOCK(mount_lock) {
@@ -311,12 +317,12 @@ sys_pivot_root(const char *new_root, const char *put_old)
                if (newmp->m_covered) {
                        drele(newmp->m_covered);
                }
-               newmp->m_covered = nullptr;
+               newmp->m_covered = NULL;
 
                if (newmp->m_root->d_parent) {
                        drele(newmp->m_root->d_parent);
                }
-               newmp->m_root->d_parent = nullptr;
+               newmp->m_root->d_parent = NULL;
 
                strlcpy(newmp->m_path, "/", sizeof(newmp->m_path));
        }
@@ -327,11 +333,12 @@ sys_pivot_root(const char *new_root, const char *put_old)
 int
 sys_sync(void)
 {
+       struct mount *mp;
+       uk_mutex_lock(&mount_lock);
+
        /* Call each mounted file system. */
-       WITH_LOCK(mount_lock) {
-               for (auto&& mp : mount_list) {
-                       VFS_SYNC(mp);
-               }
+       uk_list_for_each_entry(mp, &mount_list, mnt_list) {
+               VFS_SYNC(mp);
        }
 #ifdef HAVE_BUFFERS
        bio_sync();
@@ -377,22 +384,23 @@ count_match(const char *path, char *mount_root)
 int
 vfs_findroot(const char *path, struct mount **mp, char **root)
 {
-       struct mount *m = nullptr;
+       struct mount *m = NULL, *tmp;
        size_t len, max_len = 0;
 
        if (!path)
                return -1;
 
        /* Find mount point from nearest path */
-       SCOPE_LOCK(mount_lock);
-       for (auto&& tmp : mount_list) {
+       uk_mutex_lock(&mount_lock);
+       uk_list_for_each_entry(tmp, &mount_list, mnt_list) {
                len = count_match(path, tmp->m_path);
                if (len > max_len) {
                        max_len = len;
                        m = tmp;
                }
        }
-       if (m == nullptr)
+       uk_mutex_unlock(&mount_lock);
+       if (m == NULL)
                return -1;
        *root = (char *)(path + max_len);
        if (**root == '/')
@@ -407,8 +415,10 @@ vfs_findroot(const char *path, struct mount **mp, char 
**root)
 void
 vfs_busy(struct mount *mp)
 {
-       SCOPE_LOCK(mount_lock);
-       mp->m_count++;
+       /* The m_count is not really checked anywhere
+        * currently. Atomic is enough. But it could be that obtaining
+        * mount_lock will be needed in the future */
+       ukarch_inc(&mp->m_count);
 }
 
 
@@ -418,8 +428,10 @@ vfs_busy(struct mount *mp)
 void
 vfs_unbusy(struct mount *mp)
 {
-       SCOPE_LOCK(mount_lock);
-       mp->m_count--;
+       /* The m_count is not really checked anywhere
+        * currently. Atomic is enough. But it could be that obtaining
+        * mount_lock will be needed in the future */
+       ukarch_dec(&mp->m_count);
 }
 
 int
@@ -438,14 +450,16 @@ vfs_einval(void)
 void
 mount_dump(void)
 {
-       SCOPE_LOCK(mount_lock);
+       struct mount *mp;
+       uk_mutex_lock(&mount_lock);
 
-       kprintf("mount_dump\n");
-       kprintf("dev      count root\n");
-       kprintf("-------- ----- --------\n");
+       uk_pr_debug("mount_dump\n");
+       uk_pr_debug("dev      count root\n");
+       uk_pr_debug("-------- ----- --------\n");
 
-       for (auto&& mp : mount_list) {
-               kprintf("%8x %5d %s\n", mp->m_dev, mp->m_count, mp->m_path);
+       uk_list_for_each_entry(mp, &mount_list, mnt_list) {
+               uk_pr_debug("%8p %5d %s\n", mp->m_dev, mp->m_count, mp->m_path);
        }
+       uk_mutex_unlock(&mount_lock);
 }
 #endif
diff --git a/lib/vfscore/subr_uio.c b/lib/vfscore/subr_uio.c
index 80680fb5..3377ac12 100644
--- a/lib/vfscore/subr_uio.c
+++ b/lib/vfscore/subr_uio.c
@@ -43,7 +43,7 @@
 int
 uiomove(void *cp, int n, struct uio *uio)
 {
-       assert(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
+       UK_ASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
 
        while (n > 0 && uio->uio_resid) {
                struct iovec *iov = uio->uio_iov;
diff --git a/lib/vfscore/syscalls.c b/lib/vfscore/syscalls.c
index a7203cf5..84db2b58 100644
--- a/lib/vfscore/syscalls.c
+++ b/lib/vfscore/syscalls.c
@@ -69,9 +69,9 @@ open_no_follow_chk(char *path)
        struct dentry *dp;
        struct vnode  *vp;
 
-       ddp = nullptr;
-       dp  = nullptr;
-       vp  = nullptr;
+       ddp = NULL;
+       dp  = NULL;
+       vp  = NULL;
 
        error = lookup(path, &ddp, &name);
        if (error) {
@@ -92,15 +92,15 @@ open_no_follow_chk(char *path)
 
        error = 0;
 out:
-       if (vp != nullptr) {
+       if (vp != NULL) {
                vn_unlock(vp);
        }
 
-       if (dp != nullptr) {
+       if (dp != NULL) {
                drele(dp);
        }
 
-       if (ddp != nullptr) {
+       if (ddp != NULL) {
                drele(ddp);
        }
 
@@ -108,9 +108,9 @@ out:
 }
 
 int
-sys_open(char *path, int flags, mode_t mode, struct file **fpp)
+sys_open(char *path, int flags, mode_t mode, struct vfscore_file **fpp)
 {
-       file *fp;
+       struct vfscore_file *fp;
        struct dentry *dp, *ddp;
        struct vnode *vp;
        char *filename;
@@ -119,11 +119,11 @@ sys_open(char *path, int flags, mode_t mode, struct file 
**fpp)
        DPRINTF(VFSDB_SYSCALL, ("sys_open: path=%s flags=%x mode=%x\n",
                                path, flags, mode));
 
-       flags = fflags(flags);
+       flags = vfscore_fflags(flags);
        if (flags & O_CREAT) {
                error = namei(path, &dp);
                if (error == ENOENT) {
-                       /* Create new file. */
+                       /* Create new struct vfscore_file. */
                        if ((error = lookup(path, &ddp, &filename)) != 0)
                                return error;
 
@@ -237,14 +237,14 @@ out_drele:
 }
 
 int
-sys_close(struct file *fp)
+sys_close(struct vfscore_file *fp __unused)
 {
 
        return 0;
 }
 
 int
-sys_read(struct file *fp, const struct iovec *iov, size_t niov,
+sys_read(struct vfscore_file *fp, const struct iovec *iov, size_t niov,
                off_t offset, size_t *count)
 {
        int error = 0;
@@ -294,7 +294,7 @@ sys_read(struct file *fp, const struct iovec *iov, size_t 
niov,
 }
 
 int
-sys_write(struct file *fp, const struct iovec *iov, size_t niov,
+sys_write(struct vfscore_file *fp, const struct iovec *iov, size_t niov,
                off_t offset, size_t *count)
 {
        struct iovec *copy_iov;
@@ -341,12 +341,12 @@ sys_write(struct file *fp, const struct iovec *iov, 
size_t niov,
 }
 
 int
-sys_lseek(struct file *fp, off_t off, int type, off_t *origin)
+sys_lseek(struct vfscore_file *fp, off_t off, int type, off_t *origin)
 {
        struct vnode *vp;
 
-       DPRINTF(VFSDB_SYSCALL, ("sys_seek: fp=%x off=%d type=%d\n",
-                               (u_long)fp, (u_int)off, type));
+       DPRINTF(VFSDB_SYSCALL, ("sys_seek: fp=%p off=%ud type=%d\n",
+                               fp, (unsigned int)off, type));
 
        if (!fp->f_dentry) {
            // Linux doesn't implement lseek() on pipes, sockets, or ttys.
@@ -377,11 +377,11 @@ sys_lseek(struct file *fp, off_t off, int type, off_t 
*origin)
 }
 
 int
-sys_ioctl(struct file *fp, u_long request, void *buf)
+sys_ioctl(struct vfscore_file *fp, unsigned long request, void *buf)
 {
        int error;
 
-       DPRINTF(VFSDB_SYSCALL, ("sys_ioctl: fp=%x request=%x\n", fp, request));
+       DPRINTF(VFSDB_SYSCALL, ("sys_ioctl: fp=%p request=%lux\n", fp, 
request));
 
        if ((fp->f_flags & (FREAD | FWRITE)) == 0)
                return EBADF;
@@ -393,7 +393,7 @@ sys_ioctl(struct file *fp, u_long request, void *buf)
 }
 
 int
-sys_fsync(struct file *fp)
+sys_fsync(struct vfscore_file *fp)
 {
        struct vnode *vp;
        int error;
@@ -411,7 +411,7 @@ sys_fsync(struct file *fp)
 }
 
 int
-sys_fstat(struct file *fp, struct stat *st)
+sys_fstat(struct vfscore_file *fp, struct stat *st)
 {
        int error = 0;
 
@@ -429,7 +429,7 @@ static int
 check_dir_empty(char *path)
 {
        int error;
-       struct file *fp;
+       struct vfscore_file *fp;
        struct dirent dir;
 
        DPRINTF(VFSDB_SYSCALL, ("check_dir_empty\n"));
@@ -457,7 +457,7 @@ out_error:
 }
 
 int
-sys_readdir(struct file *fp, struct dirent *dir)
+sys_readdir(struct vfscore_file *fp, struct dirent *dir)
 {
        struct vnode *dvp;
        int error;
@@ -481,7 +481,7 @@ sys_readdir(struct file *fp, struct dirent *dir)
 }
 
 int
-sys_rewinddir(struct file *fp)
+sys_rewinddir(struct vfscore_file *fp)
 {
        struct vnode *dvp;
 
@@ -500,7 +500,7 @@ sys_rewinddir(struct file *fp)
 }
 
 int
-sys_seekdir(struct file *fp, long loc)
+sys_seekdir(struct vfscore_file *fp, long loc)
 {
        struct vnode *dvp;
 
@@ -519,7 +519,7 @@ sys_seekdir(struct file *fp, long loc)
 }
 
 int
-sys_telldir(struct file *fp, long *loc)
+sys_telldir(struct vfscore_file *fp, long *loc)
 {
        struct vnode *dvp;
 
@@ -666,14 +666,14 @@ sys_mknod(char *path, mode_t mode)
  *
  * Assumes both paths do not have trailing slashes.
  */
-static bool
+static int
 is_parent(const char *parent, const char *child)
 {
        size_t p_len = strlen(parent);
        return !strncmp(parent, child, p_len) && (parent[p_len-1] == '/' || 
child[p_len] == '/');
 }
 
-static bool
+static int
 has_trailing(const char *path, char ch)
 {
        size_t len = strlen(path);
@@ -699,16 +699,16 @@ sys_rename(char *src, char *dest)
        char *sname, *dname;
        int error;
        char root[] = "/";
-       bool ts; /* trailing slash */
+       int ts; /* trailing slash */
 
        DPRINTF(VFSDB_SYSCALL, ("sys_rename: src=%s dest=%s\n", src, dest));
 
-       ts = false;
-       if (has_trailing(src, '/') == true) {
+       ts = 0;
+       if (has_trailing(src, '/')) {
                if (strlen(src) != 1) {
                        /* remove trailing slash iff path is none root */
                        strip_trailing(src, '/');
-                       ts = true;
+                       ts = 1;
                }
        }
 
@@ -726,17 +726,17 @@ sys_rename(char *src, char *dest)
        vp1 = dp1->d_vnode;
        vn_lock(vp1);
 
-       if (vp1->v_type != VDIR && ts == true) {
+       if (vp1->v_type != VDIR && ts) {
                error = ENOTDIR;
                goto err1;
        }
 
-       ts = false;
-       if (has_trailing(dest, '/') == true) {
+       ts = 0;
+       if (has_trailing(dest, '/')) {
                if (strlen(dest) != 1) {
                        /* remove trailing slash iff path is none root */
                        strip_trailing(dest, '/');
-                       ts = true;
+                       ts = 1;
                }
        }
 
@@ -753,7 +753,7 @@ sys_rename(char *src, char *dest)
                vn_lock(vp2);
 
                if (vp2->v_type != VDIR && vp2->v_type != VLNK) {
-                       if (vp1->v_type == VDIR || ts == true) {
+                       if (vp1->v_type == VDIR || ts) {
                                error = ENOTDIR;
                                goto err2;
                        }
@@ -766,7 +766,7 @@ sys_rename(char *src, char *dest)
                        goto err2;
                }
        } else if (error == ENOENT) {
-               if (vp1->v_type != VDIR && ts == true) {
+               if (vp1->v_type != VDIR && ts) {
                        error = ENOTDIR;
                        goto err2;
                }
@@ -791,7 +791,7 @@ sys_rename(char *src, char *dest)
        }
 
        dname = strrchr(dest, '/');
-       if (dname == nullptr) {
+       if (dname == NULL) {
                error = ENOTDIR;
                goto err2;
        }
@@ -852,15 +852,15 @@ sys_symlink(const char *oldpath, const char *newpath)
        struct dentry   *newdirdp;
        char            *name;
 
-       if (oldpath == nullptr || newpath == nullptr) {
+       if (oldpath == NULL || newpath == NULL) {
                return (EFAULT);
        }
 
        DPRINTF(VFSDB_SYSCALL, ("sys_link: oldpath=%s newpath=%s\n",
                                oldpath, newpath));
 
-       newdp           = nullptr;
-       newdirdp        = nullptr;
+       newdp           = NULL;
+       newdirdp        = NULL;
 
        error = task_conv(t, newpath, VWRITE, np);
        if (error != 0) {
@@ -896,7 +896,7 @@ sys_symlink(const char *oldpath, const char *newpath)
        error = VOP_SYMLINK(newdirdp->d_vnode, name, op);
 
 out:
-       if (newdirdp != nullptr) {
+       if (newdirdp != NULL) {
                vn_unlock(newdirdp->d_vnode);
                drele(newdirdp);
        }
@@ -976,9 +976,9 @@ sys_unlink(char *path)
 
        DPRINTF(VFSDB_SYSCALL, ("sys_unlink: path=%s\n", path));
 
-       ddp   = nullptr;
-       dp    = nullptr;
-       vp    = nullptr;
+       ddp   = NULL;
+       dp    = NULL;
+       vp    = NULL;
 
        error = lookup(path, &ddp, &name);
        if (error != 0) {
@@ -1017,15 +1017,15 @@ sys_unlink(char *path)
        drele(dp);
        return error;
  out:
-       if (vp != nullptr) {
+       if (vp != NULL) {
                vn_unlock(vp);
        }
 
-       if (dp != nullptr) {
+       if (dp != NULL) {
                drele(dp);
        }
 
-       if (ddp != nullptr) {
+       if (ddp != NULL) {
                drele(ddp);
        }
        return error;
@@ -1119,7 +1119,7 @@ sys_statfs(char *path, struct statfs *buf)
 }
 
 int
-sys_fstatfs(struct file *fp, struct statfs *buf)
+sys_fstatfs(struct vfscore_file *fp, struct statfs *buf)
 {
        struct vnode *vp;
        int error = 0;
@@ -1156,7 +1156,7 @@ sys_truncate(char *path, off_t length)
 }
 
 int
-sys_ftruncate(struct file *fp, off_t length)
+sys_ftruncate(struct vfscore_file *fp, off_t length)
 {
        struct vnode *vp;
        int error;
@@ -1173,7 +1173,7 @@ sys_ftruncate(struct file *fp, off_t length)
 }
 
 int
-sys_fchdir(struct file *fp, char *cwd)
+sys_fchdir(struct vfscore_file *fp, char *cwd)
 {
        struct vnode *dvp;
 
@@ -1248,7 +1248,7 @@ sys_readlink(char *path, char *buf, size_t bufsize, 
ssize_t *size)
 /*
  * Check the validity of the members of a struct timeval.
  */
-static bool is_timeval_valid(const struct timeval *time)
+static int is_timeval_valid(const struct timeval *time)
 {
        return (time->tv_sec >= 0) &&
                   (time->tv_usec >= 0 && time->tv_usec < 1000000);
@@ -1280,18 +1280,18 @@ sys_utimes(char *path, const struct timeval times[2], 
int flags)
                return EINVAL;
 
        // Convert each element of timeval array to the timespec type
-       convert_timeval(timespec_times[0], times ? times + 0 : nullptr);
-       convert_timeval(timespec_times[1], times ? times + 1 : nullptr);
+       convert_timeval(timespec_times[0], times ? times + 0 : NULL);
+       convert_timeval(timespec_times[1], times ? times + 1 : NULL);
 
        if (flags & AT_SYMLINK_NOFOLLOW) {
                struct dentry *ddp;
-               error = lookup(path, &ddp, nullptr);
+               error = lookup(path, &ddp, NULL);
                if (error) {
                        return error;
                }
 
                error = namei_last_nofollow(path, ddp, &dp);
-               if (ddp != nullptr) {
+               if (ddp != NULL) {
                        drele(ddp);
                }
                if (error) {
@@ -1316,7 +1316,7 @@ sys_utimes(char *path, const struct timeval times[2], int 
flags)
 /*
  * Check the validity of members of a struct timespec
  */
-static bool is_timespec_valid(const struct timespec &time)
+static int is_timespec_valid(const struct timespec &time)
 {
        return (time.tv_sec >= 0) &&
           ((time.tv_nsec >= 0 && time.tv_nsec <= 999999999) ||
@@ -1326,7 +1326,7 @@ static bool is_timespec_valid(const struct timespec &time)
 
 void init_timespec(struct timespec &_times, const struct timespec *times)
 {
-       if (times == nullptr || times->tv_nsec == UTIME_NOW) {
+       if (times == NULL || times->tv_nsec == UTIME_NOW) {
                clock_gettime(CLOCK_REALTIME, &_times);
        } else {
                _times.tv_sec = times->tv_sec;
@@ -1354,8 +1354,8 @@ sys_utimensat(int dirfd, const char *pathname, const 
struct timespec times[2], i
        if (times && (!is_timespec_valid(times[0]) || 
!is_timespec_valid(times[1])))
                return EINVAL;
 
-       init_timespec(timespec_times[0], times ? times + 0 : nullptr);
-       init_timespec(timespec_times[1], times ? times + 1 : nullptr);
+       init_timespec(timespec_times[0], times ? times + 0 : NULL);
+       init_timespec(timespec_times[1], times ? times + 1 : NULL);
 
        if (pathname && pathname[0] == '/') {
        ap = pathname;
@@ -1364,7 +1364,7 @@ sys_utimensat(int dirfd, const char *pathname, const 
struct timespec times[2], i
            return EFAULT;
        ap = std::string(main_task->t_cwd) + "/" + pathname;
        } else {
-               struct file *fp;
+               struct vfscore_file *fp;
                fileref f(fileref_from_fd(dirfd));
 
                if (!f)
@@ -1414,7 +1414,7 @@ sys_utimensat(int dirfd, const char *pathname, const 
struct timespec times[2], i
 int
 sys_futimens(int fd, const struct timespec times[2])
 {
-       struct file *fp;
+       struct vfscore_file *fp;
 
        fileref f(fileref_from_fd(fd));
        if (!f)
@@ -1432,7 +1432,7 @@ sys_futimens(int fd, const struct timespec times[2])
 #endif
 
 int
-sys_fallocate(struct file *fp, int mode, loff_t offset, loff_t len)
+sys_fallocate(struct vfscore_file *fp, int mode, off_t offset, off_t len)
 {
        int error;
        struct vnode *vp;
@@ -1497,7 +1497,7 @@ sys_chmod(const char *path, mode_t mode)
 int
 sys_fchmod(int fd, mode_t mode)
 {
-       fileref f(fileref_from_fd(fd));
+       struct vfscore_file *f = vfscore_get_file(fd);
        if (!f)
                return EBADF;
        // Posix is ambivalent on what fchmod() should do on an fd that does not
diff --git a/lib/vfscore/vfs.h b/lib/vfscore/vfs.h
index 1965ae86..356f215e 100644
--- a/lib/vfscore/vfs.h
+++ b/lib/vfscore/vfs.h
@@ -54,7 +54,7 @@ extern int vfs_debug;
 
 #define VFSDB_FLAGS    0x00000013
 
-#define        DPRINTF(_m,X)   if (vfs_debug & (_m)) kprintf X
+#define        DPRINTF(_m,X)   if (vfs_debug & (_m)) uk_pr_debug X
 #else
 #define        DPRINTF(_m, X)
 #endif
@@ -68,28 +68,26 @@ extern int vfs_debug;
  */
 struct task {
        char        t_cwd[PATH_MAX];    /* current working directory */
-       struct file *t_cwdfp;           /* directory for cwd */
+       struct vfscore_file *t_cwdfp;           /* directory for cwd */
 };
 
-extern const struct vfssw vfssw[];
-
-int     sys_open(char *path, int flags, mode_t mode, struct file **fp);
-int     sys_read(struct file *fp, const struct iovec *iov, size_t niov,
+int     sys_open(char *path, int flags, mode_t mode, struct vfscore_file **fp);
+int     sys_read(struct vfscore_file *fp, const struct iovec *iov, size_t niov,
                off_t offset, size_t *count);
-int     sys_write(struct file *fp, const struct iovec *iov, size_t niov,
+int     sys_write(struct vfscore_file *fp, const struct iovec *iov, size_t 
niov,
                off_t offset, size_t *count);
-int     sys_lseek(struct file *fp, off_t off, int type, off_t * cur_off);
-int     sys_ioctl(struct file *fp, u_long request, void *buf);
-int     sys_fstat(struct file *fp, struct stat *st);
-int     sys_fstatfs(struct file *fp, struct statfs *buf);
-int     sys_fsync(struct file *fp);
-int     sys_ftruncate(struct file *fp, off_t length);
-
-int     sys_readdir(struct file *fp, struct dirent *dirent);
-int     sys_rewinddir(struct file *fp);
-int     sys_seekdir(struct file *fp, long loc);
-int     sys_telldir(struct file *fp, long *loc);
-int     sys_fchdir(struct file *fp, char *path);
+int     sys_lseek(struct vfscore_file *fp, off_t off, int type, off_t * 
cur_off);
+int     sys_ioctl(struct vfscore_file *fp, unsigned long request, void *buf);
+int     sys_fstat(struct vfscore_file *fp, struct stat *st);
+int     sys_fstatfs(struct vfscore_file *fp, struct statfs *buf);
+int     sys_fsync(struct vfscore_file *fp);
+int     sys_ftruncate(struct vfscore_file *fp, off_t length);
+
+int     sys_readdir(struct vfscore_file *fp, struct dirent *dirent);
+int     sys_rewinddir(struct vfscore_file *fp);
+int     sys_seekdir(struct vfscore_file *fp, long loc);
+int     sys_telldir(struct vfscore_file *fp, long *loc);
+int     sys_fchdir(struct vfscore_file *fp, char *path);
 
 int     sys_mkdir(char *path, mode_t mode);
 int     sys_rmdir(char *path);
@@ -108,7 +106,7 @@ int  sys_utimes(char *path, const struct timeval times[2], 
int flags);
 int  sys_utimensat(int dirfd, const char *pathname,
                                   const struct timespec times[2], int flags);
 int  sys_futimens(int fd, const struct timespec times[2]);
-int  sys_fallocate(struct file *fp, int mode, loff_t offset, loff_t len);
+int  sys_fallocate(struct vfscore_file *fp, int mode, loff_t offset, loff_t 
len);
 
 int     sys_mount(const char *dev, const char *dir, const char *fsname, int 
flags, const void *data);
 int     sys_umount2(const char *path, int flags);
diff --git a/lib/vfscore/vnode.c b/lib/vfscore/vnode.c
index 7eca7721..cf4c64bc 100644
--- a/lib/vfscore/vnode.c
+++ b/lib/vfscore/vnode.c
@@ -74,24 +74,27 @@ int vttoif_tab[10] = {
  * All active (opened) vnodes are stored on this hash table.
  * They can be accessed by its path name.
  */
-static LIST_HEAD(vnode_hash_head, vnode) vnode_table[VNODE_BUCKETS];
+static struct uk_list_head vnode_table[VNODE_BUCKETS];
 
 /*
  * Global lock to access all vnodes and vnode table.
  * If a vnode is already locked, there is no need to
  * lock this global lock to access internal data.
  */
-static mutex_t vnode_lock = MUTEX_INITIALIZER;
-#define VNODE_LOCK()   mutex_lock(&vnode_lock)
-#define VNODE_UNLOCK() mutex_unlock(&vnode_lock)
-#define VNODE_OWNED()  mutex_owned(&vnode_lock)
+static struct uk_mutex vnode_lock = UK_MUTEX_INITIALIZER(vnode_lock);
+#define VNODE_LOCK()   uk_mutex_lock(&vnode_lock)
+#define VNODE_UNLOCK() uk_mutex_unlock(&vnode_lock)
+
+/* TODO: implement mutex_owned */
+#define VNODE_OWNED()  (1)
+/* #define VNODE_OWNED()       mutex_owned(&vnode_lock) */
+
 
 /*
  * Get the hash value from the mount point and path name.
  * XXX(hch): replace with a better hash for 64-bit pointers.
  */
-static u_int
-vn_hash(struct mount *mp, uint64_t ino)
+static unsigned int vn_hash(struct mount *mp, uint64_t ino)
 {
        return (ino ^ (unsigned long)mp) & (VNODE_BUCKETS - 1);
 }
@@ -107,16 +110,15 @@ vn_lookup(struct mount *mp, uint64_t ino)
 {
        struct vnode *vp;
 
-       assert(VNODE_OWNED());
-       LIST_FOREACH(vp, &vnode_table[vn_hash(mp, ino)], v_link) {
+       UK_ASSERT(VNODE_OWNED());
+       uk_list_for_each_entry(vp, &vnode_table[vn_hash(mp, ino)], v_link) {
                if (vp->v_mount == mp && vp->v_ino == ino) {
                        vp->v_refcnt++;
-                       mutex_lock(&vp->v_lock);
-                       vp->v_nrlocks++;
+                       uk_mutex_lock(&vp->v_lock);
                        return vp;
                }
        }
-       return nullptr;         /* not found */
+       return NULL;            /* not found */
 }
 
 #ifdef DEBUG_VFS
@@ -125,10 +127,10 @@ vn_path(struct vnode *vp)
 {
        struct dentry *dp;
 
-       if (LIST_EMPTY(&vp->v_names) == 1) {
+       if (uk_list_empty(&vp->v_names) == 1) {
                return (" ");
        }
-       dp = LIST_FIRST(&vp->v_names);
+       dp = uk_list_first_entry(&vp->v_names, struct dentry, d_names_link);
        return (dp->d_path);
 }
 #endif
@@ -139,11 +141,10 @@ vn_path(struct vnode *vp)
 void
 vn_lock(struct vnode *vp)
 {
-       ASSERT(vp);
-       ASSERT(vp->v_refcnt > 0);
+       UK_ASSERT(vp);
+       UK_ASSERT(vp->v_refcnt > 0);
 
-       mutex_lock(&vp->v_lock);
-       vp->v_nrlocks++;
+       uk_mutex_lock(&vp->v_lock);
        DPRINTF(VFSDB_VNODE, ("vn_lock:   %s\n", vn_path(vp)));
 }
 
@@ -153,12 +154,10 @@ vn_lock(struct vnode *vp)
 void
 vn_unlock(struct vnode *vp)
 {
-       ASSERT(vp);
-       ASSERT(vp->v_refcnt > 0);
-       ASSERT(vp->v_nrlocks > 0);
+       UK_ASSERT(vp);
+       UK_ASSERT(vp->v_refcnt >= 0);
 
-       vp->v_nrlocks--;
-       mutex_unlock(&vp->v_lock);
+       uk_mutex_unlock(&vp->v_lock);
        DPRINTF(VFSDB_VNODE, ("vn_lock:   %s\n", vn_path(vp)));
 }
 
@@ -173,7 +172,7 @@ vget(struct mount *mp, uint64_t ino, struct vnode **vpp)
        struct vnode *vp;
        int error;
 
-       *vpp = nullptr;
+       *vpp = NULL;
 
        DPRINTF(VFSDB_VNODE, ("vget %LLu\n", ino));
 
@@ -192,26 +191,24 @@ vget(struct mount *mp, uint64_t ino, struct vnode **vpp)
                return 0;
        }
 
-       LIST_INIT(&vp->v_names);
+       UK_INIT_LIST_HEAD(&vp->v_names);
        vp->v_ino = ino;
        vp->v_mount = mp;
        vp->v_refcnt = 1;
        vp->v_op = mp->m_op->vfs_vnops;
-       vp->v_nrlocks = 0;
-
+       uk_mutex_init(&vp->v_lock);
        /*
         * Request to allocate fs specific data for vnode.
         */
        if ((error = VFS_VGET(mp, vp)) != 0) {
                VNODE_UNLOCK();
-               delete vp;
+               free(vp);
                return error;
        }
        vfs_busy(vp->v_mount);
-       mutex_lock(&vp->v_lock);
-       vp->v_nrlocks++;
+       uk_mutex_lock(&vp->v_lock);
 
-       LIST_INSERT_HEAD(&vnode_table[vn_hash(mp, ino)], vp, v_link);
+       uk_list_add(&vp->v_link, &vnode_table[vn_hash(mp, ino)]);
        VNODE_UNLOCK();
 
        *vpp = vp;
@@ -225,9 +222,8 @@ vget(struct mount *mp, uint64_t ino, struct vnode **vpp)
 void
 vput(struct vnode *vp)
 {
-       ASSERT(vp);
-       ASSERT(vp->v_nrlocks > 0);
-       ASSERT(vp->v_refcnt > 0);
+       UK_ASSERT(vp);
+       UK_ASSERT(vp->v_refcnt > 0);
        DPRINTF(VFSDB_VNODE, ("vput: ref=%d %s\n", vp->v_refcnt, vn_path(vp)));
 
        VNODE_LOCK();
@@ -237,7 +233,7 @@ vput(struct vnode *vp)
                vn_unlock(vp);
                return;
        }
-       LIST_REMOVE(vp, v_link);
+       uk_list_del(&vp->v_link);
        VNODE_UNLOCK();
 
        /*
@@ -246,10 +242,8 @@ vput(struct vnode *vp)
        if (vp->v_op->vop_inactive)
                VOP_INACTIVE(vp);
        vfs_unbusy(vp->v_mount);
-       vp->v_nrlocks--;
-       ASSERT(vp->v_nrlocks == 0);
-       mutex_unlock(&vp->v_lock);
-       delete vp;
+       uk_mutex_unlock(&vp->v_lock);
+       free(vp);
 }
 
 /*
@@ -258,8 +252,8 @@ vput(struct vnode *vp)
 void
 vref(struct vnode *vp)
 {
-       ASSERT(vp);
-       ASSERT(vp->v_refcnt > 0);       /* Need vget */
+       UK_ASSERT(vp);
+       UK_ASSERT(vp->v_refcnt > 0);    /* Need vfscore_vget */
 
        VNODE_LOCK();
        DPRINTF(VFSDB_VNODE, ("vref: ref=%d\n", vp->v_refcnt));
@@ -276,8 +270,8 @@ vref(struct vnode *vp)
 void
 vrele(struct vnode *vp)
 {
-       ASSERT(vp);
-       ASSERT(vp->v_refcnt > 0);
+       UK_ASSERT(vp);
+       UK_ASSERT(vp->v_refcnt > 0);
 
        VNODE_LOCK();
        DPRINTF(VFSDB_VNODE, ("vrele: ref=%d\n", vp->v_refcnt));
@@ -286,7 +280,7 @@ vrele(struct vnode *vp)
                VNODE_UNLOCK();
                return;
        }
-       LIST_REMOVE(vp, v_link);
+       uk_list_del(&vp->v_link);
        VNODE_UNLOCK();
 
        /*
@@ -294,7 +288,7 @@ vrele(struct vnode *vp)
         */
        VOP_INACTIVE(vp);
        vfs_unbusy(vp->v_mount);
-       delete vp;
+       free(vp);
 }
 
 /*
@@ -453,21 +447,25 @@ vnode_dump(void)
                           "VLNK ", "VSOCK", "VFIFO" };
 
        VNODE_LOCK();
-       kprintf("Dump vnode\n");
-       kprintf(" vnode    mount    type  refcnt blkno    path\n");
-       kprintf(" -------- -------- ----- ------ -------- 
------------------------------\n");
+
+       uk_pr_debug("Dump vnode\n");
+       uk_pr_debug(" vnode            mount            type  refcnt path\n");
+       uk_pr_debug(" ---------------- ---------------- ----- ------ 
------------------------------\n");
 
        for (i = 0; i < VNODE_BUCKETS; i++) {
-               LIST_FOREACH(vp, &vnode_table[i], v_link) {
+               uk_list_for_each_entry(vp, &vnode_table[i], v_link) {
                        mp = vp->v_mount;
 
-                       kprintf(" %08x %08x %s %6d %8d %s%s\n", (u_long)vp,
-                               (u_long)mp, type[vp->v_type], vp->v_refcnt,
-                               (strlen(mp->m_path) == 1) ? "\0" : mp->m_path,
-                               vn_path(vp));
+
+                       uk_pr_debug(" %016lx %016lx %s %6d %s%s\n",
+                                   (unsigned long) vp,
+                                   (unsigned long) mp, type[vp->v_type],
+                                   vp->v_refcnt,
+                                   (strlen(mp->m_path) == 1) ? "\0" : 
mp->m_path,
+                                   vn_path(vp));
                }
        }
-       kprintf("\n");
+       uk_pr_debug("\n");
        VNODE_UNLOCK();
 }
 #endif
@@ -506,20 +504,22 @@ vnode_init(void)
        int i;
 
        for (i = 0; i < VNODE_BUCKETS; i++)
-               LIST_INIT(&vnode_table[i]);
+               UK_INIT_LIST_HEAD(&vnode_table[i]);
 }
 
 void vn_add_name(struct vnode *vp, struct dentry *dp)
 {
-       vn_lock(vp);
-       LIST_INSERT_HEAD(&vp->v_names, dp, d_names_link);
-       vn_unlock(vp);
+       /* TODO: Re-enable this check when preemption and/or smp is
+        * here */
+       /* UK_ASSERT(uk_mutex_is_locked(&vp->v_lock)); */
+       uk_list_add(&dp->d_names_link, &vp->v_names);
 }
 
 void vn_del_name(struct vnode *vp, struct dentry *dp)
 {
-       vn_lock(vp);
-       LIST_REMOVE(dp, d_names_link);
-       vn_unlock(vp);
+       /* TODO: Re-enable this check when preemption and/or smp is
+        * here */
+       /* UK_ASSERT(uk_mutex_is_locked(&vp->v_lock)); */
+       uk_list_del(&dp->d_names_link);
 }
 
-- 
2.19.2


_______________________________________________
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®.