From f6473ef3b650b3d5ab1a07e25bdf94f5af4c5ef3 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig <hch@cloudius-systems.com> Date: Thu, 21 Mar 2013 16:36:26 +0100 Subject: [PATCH] do not grab a vnode reference in fget() and friends This is not needed because each file still keeps a vnode reference and thus pins it, but at the same time makes the close implementation a lot simpler, especially after file operations are added. --- fs/vfs/main.c | 3 --- fs/vfs/vfs_syscalls.c | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/vfs/main.c b/fs/vfs/main.c index ea9bba8e8..e2d69c1d1 100755 --- a/fs/vfs/main.c +++ b/fs/vfs/main.c @@ -793,7 +793,6 @@ int dup(int oldfd) t->t_ofile[newfd] = fp; /* Increment file reference */ - vref(fp->f_vnode); fp->f_count++; return newfd; @@ -832,7 +831,6 @@ int dup3(int oldfd, int newfd, int flags) t->t_ofile[newfd] = fp; /* Increment file reference */ - vref(fp->f_vnode); fp->f_count++; return newfd; out_errno: @@ -869,7 +867,6 @@ int fcntl(int fd, int cmd, int arg) t->t_ofile[new_fd] = fp; /* Increment file reference */ - vref(fp->f_vnode); fp->f_count++; return new_fd; case F_GETFD: diff --git a/fs/vfs/vfs_syscalls.c b/fs/vfs/vfs_syscalls.c index 91e1ce571..c8a0d4f3e 100755 --- a/fs/vfs/vfs_syscalls.c +++ b/fs/vfs/vfs_syscalls.c @@ -152,11 +152,10 @@ sys_close(file_t fp) if (fp->f_count <= 0) sys_panic("sys_close"); - vp = fp->f_vnode; - if (--fp->f_count > 0) { - vrele(vp); + if (--fp->f_count > 0) return 0; - } + + vp = fp->f_vnode; vn_lock(vp); if ((error = VOP_CLOSE(vp, fp)) != 0) { vn_unlock(vp); -- GitLab