2006-10-25 15:40:36 +02:00
|
|
|
/* This file contains the routines related to vnodes.
|
|
|
|
* The entry points are:
|
2012-02-13 16:28:04 +01:00
|
|
|
*
|
2006-10-25 15:40:36 +02:00
|
|
|
* get_vnode - increase counter and get details of an inode
|
|
|
|
* get_free_vnode - get a pointer to a free vnode obj
|
2012-02-13 16:28:04 +01:00
|
|
|
* find_vnode - find a vnode according to the FS endpoint and the inode num.
|
2006-10-25 15:40:36 +02:00
|
|
|
* dup_vnode - duplicate vnode (i.e. increase counter)
|
2012-02-13 16:28:04 +01:00
|
|
|
* put_vnode - drop vnode (i.e. decrease counter)
|
2006-10-25 15:40:36 +02:00
|
|
|
*/
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
#include "fs.h"
|
2012-02-13 16:28:04 +01:00
|
|
|
#include "threads.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
#include "vnode.h"
|
|
|
|
#include "vmnt.h"
|
2007-01-05 17:36:55 +01:00
|
|
|
#include "fproc.h"
|
|
|
|
#include "file.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <minix/vfsif.h>
|
2012-02-13 16:28:04 +01:00
|
|
|
#include <assert.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2009-01-26 18:43:59 +01:00
|
|
|
/* Is vnode pointer reasonable? */
|
2011-02-16 19:58:30 +01:00
|
|
|
#if NDEBUG
|
|
|
|
#define SANEVP(v)
|
|
|
|
#define CHECKVN(v)
|
|
|
|
#define ASSERTVP(v)
|
|
|
|
#else
|
2009-01-26 18:43:59 +01:00
|
|
|
#define SANEVP(v) ((((v) >= &vnode[0] && (v) < &vnode[NR_VNODES])))
|
|
|
|
|
2010-07-02 14:41:19 +02:00
|
|
|
#define BADVP(v, f, l) printf("%s:%d: bad vp %p\n", f, l, v)
|
2009-01-26 18:43:59 +01:00
|
|
|
|
|
|
|
/* vp check that returns 0 for use in check_vrefs() */
|
|
|
|
#define CHECKVN(v) if(!SANEVP(v)) { \
|
|
|
|
BADVP(v, __FILE__, __LINE__); \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vp check that panics */
|
|
|
|
#define ASSERTVP(v) if(!SANEVP(v)) { \
|
2010-03-05 16:05:11 +01:00
|
|
|
BADVP(v, __FILE__, __LINE__); panic("bad vp"); }
|
2011-02-16 19:58:30 +01:00
|
|
|
#endif
|
2007-01-05 17:36:55 +01:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
#if LOCK_DEBUG
|
|
|
|
/*===========================================================================*
|
|
|
|
* check_vnode_locks_by_me *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void check_vnode_locks_by_me(struct fproc *rfp)
|
|
|
|
{
|
|
|
|
/* Check whether this thread still has locks held on vnodes */
|
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; vp++) {
|
|
|
|
if (tll_locked_by_me(&vp->v_lock)) {
|
|
|
|
panic("Thread %d still holds vnode lock on vp %x call_nr=%d\n",
|
|
|
|
mthread_self(), vp, call_nr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rfp->fp_vp_rdlocks != 0)
|
|
|
|
panic("Thread %d still holds read locks on a vnode (%d) call_nr=%d\n",
|
|
|
|
mthread_self(), rfp->fp_vp_rdlocks, call_nr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* check_vnode_locks *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void check_vnode_locks()
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; vp++)
|
|
|
|
if (is_vnode_locked(vp)) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count) panic("%d locked vnodes\n", count);
|
|
|
|
#if 0
|
|
|
|
printf("check_vnode_locks OK\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_free_vnode *
|
|
|
|
*===========================================================================*/
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
PUBLIC struct vnode *get_free_vnode()
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
/* Find a free vnode slot in the vnode table (it's not actually allocated) */
|
2006-10-25 15:40:36 +02:00
|
|
|
struct vnode *vp;
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; ++vp) {
|
2012-02-13 16:28:04 +01:00
|
|
|
if (vp->v_ref_count == 0 && !is_vnode_locked(vp)) {
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
vp->v_pipe = NO_PIPE;
|
|
|
|
vp->v_uid = -1;
|
|
|
|
vp->v_gid = -1;
|
|
|
|
vp->v_sdev = NO_DEV;
|
2012-02-13 16:28:04 +01:00
|
|
|
vp->v_mapfs_e = NONE;
|
|
|
|
vp->v_mapfs_count = 0;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
vp->v_mapinode_nr = 0;
|
|
|
|
return(vp);
|
2007-01-05 17:36:55 +01:00
|
|
|
}
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
2007-01-05 17:36:55 +01:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
err_code = ENFILE;
|
2010-05-10 15:26:00 +02:00
|
|
|
return(NULL);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* find_vnode *
|
|
|
|
*===========================================================================*/
|
2012-02-13 16:28:04 +01:00
|
|
|
PUBLIC struct vnode *find_vnode(int fs_e, int ino)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
/* Find a specified (FS endpoint and inode number) vnode in the
|
|
|
|
* vnode table */
|
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; ++vp)
|
2012-02-13 16:28:04 +01:00
|
|
|
if (vp->v_ref_count > 0 && vp->v_inode_nr == ino && vp->v_fs_e == fs_e)
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(vp);
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
return(NULL);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* is_vnode_locked *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int is_vnode_locked(struct vnode *vp)
|
|
|
|
{
|
|
|
|
/* Find out whether a thread holds a lock on this vnode or is trying to obtain
|
|
|
|
* a lock. */
|
|
|
|
ASSERTVP(vp);
|
|
|
|
|
|
|
|
return(tll_islocked(&vp->v_lock) || tll_haspendinglock(&vp->v_lock));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* init_vnodes *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void init_vnodes(void)
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; ++vp) {
|
|
|
|
vp->v_fs_e = NONE;
|
|
|
|
vp->v_mapfs_e = NONE;
|
|
|
|
vp->v_inode_nr = 0;
|
|
|
|
vp->v_ref_count = 0;
|
|
|
|
vp->v_fs_count = 0;
|
|
|
|
vp->v_mapfs_count = 0;
|
|
|
|
tll_init(&vp->v_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* lock_vnode *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int lock_vnode(struct vnode *vp, tll_access_t locktype)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
ASSERTVP(vp);
|
|
|
|
|
|
|
|
r = tll_lock(&vp->v_lock, locktype);
|
|
|
|
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
if (locktype == VNODE_READ) {
|
|
|
|
fp->fp_vp_rdlocks++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (r == EBUSY) return(r);
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* unlock_vnode *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void unlock_vnode(struct vnode *vp)
|
|
|
|
{
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
int i;
|
|
|
|
register struct vnode *rvp;
|
|
|
|
struct worker_thread *w;
|
|
|
|
#endif
|
|
|
|
ASSERTVP(vp);
|
|
|
|
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
/* Decrease read-only lock counter when not locked as VNODE_OPCL or
|
|
|
|
* VNODE_WRITE */
|
|
|
|
if (!tll_locked_by_me(&vp->v_lock)) {
|
|
|
|
fp->fp_vp_rdlocks--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NR_VNODES; i++) {
|
|
|
|
rvp = &vnode[i];
|
|
|
|
|
|
|
|
w = rvp->v_lock.t_write;
|
|
|
|
assert(w != self);
|
|
|
|
while (w && w->w_next != NULL) {
|
|
|
|
w = w->w_next;
|
|
|
|
assert(w != self);
|
|
|
|
}
|
|
|
|
|
|
|
|
w = rvp->v_lock.t_serial;
|
|
|
|
assert(w != self);
|
|
|
|
while (w && w->w_next != NULL) {
|
|
|
|
w = w->w_next;
|
|
|
|
assert(w != self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tll_unlock(&vp->v_lock);
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dup_vnode *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void dup_vnode(struct vnode *vp)
|
|
|
|
{
|
|
|
|
/* dup_vnode() is called to increment the vnode and therefore the
|
|
|
|
* referred inode's counter.
|
|
|
|
*/
|
2009-01-26 18:43:59 +01:00
|
|
|
ASSERTVP(vp);
|
2007-01-05 17:36:55 +01:00
|
|
|
vp->v_ref_count++;
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* put_vnode *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void put_vnode(struct vnode *vp)
|
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Decrease vnode's usage counter and decrease inode's usage counter in the
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
* corresponding FS process. Decreasing the fs_count each time we decrease the
|
|
|
|
* ref count would lead to poor performance. Instead, only decrease fs_count
|
|
|
|
* when the ref count hits zero. However, this could lead to fs_count to wrap.
|
|
|
|
* To prevent this, we drop the counter to 1 when the counter hits 256.
|
|
|
|
* We maintain fs_count as a sanity check to make sure VFS and the FS are in
|
|
|
|
* sync.
|
2006-10-25 15:40:36 +02:00
|
|
|
*/
|
2012-02-13 16:28:04 +01:00
|
|
|
int r, lock_vp;
|
|
|
|
|
2009-01-26 18:43:59 +01:00
|
|
|
ASSERTVP(vp);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Lock vnode. It's quite possible this thread already has a lock on this
|
|
|
|
* vnode. That's no problem, because the reference counter will not decrease
|
|
|
|
* to zero in that case. However, if the counter does decrease to zero *and*
|
|
|
|
* is already locked, we have a consistency problem somewhere. */
|
|
|
|
lock_vp = lock_vnode(vp, VNODE_OPCL);
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
if (vp->v_ref_count > 1) {
|
2007-01-05 17:36:55 +01:00
|
|
|
/* Decrease counter */
|
|
|
|
vp->v_ref_count--;
|
2012-02-13 16:28:04 +01:00
|
|
|
if (vp->v_fs_count > 256)
|
2007-01-05 17:36:55 +01:00
|
|
|
vnode_clean_refs(vp);
|
2012-02-13 16:28:04 +01:00
|
|
|
if (lock_vp != EBUSY) unlock_vnode(vp);
|
2007-01-05 17:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* If we already had a lock, there is a consistency problem */
|
|
|
|
assert(lock_vp != EBUSY);
|
|
|
|
tll_upgrade(&vp->v_lock); /* Make sure nobody else accesses this vnode */
|
|
|
|
|
|
|
|
/* A vnode that's not in use can't be put back. */
|
|
|
|
if (vp->v_ref_count <= 0)
|
|
|
|
panic("put_vnode failed: bad v_ref_count %d\n", vp->v_ref_count);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
|
|
|
/* fs_count should indicate that the file is in use. */
|
2012-02-13 16:28:04 +01:00
|
|
|
if (vp->v_fs_count <= 0)
|
|
|
|
panic("put_vnode failed: bad v_fs_count %d\n", vp->v_fs_count);
|
2007-01-05 17:36:55 +01:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
/* Tell FS we don't need this inode to be open anymore. */
|
2012-02-13 16:28:04 +01:00
|
|
|
r = req_putnode(vp->v_fs_e, vp->v_inode_nr, vp->v_fs_count);
|
2007-01-05 17:36:55 +01:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
if (r != OK) {
|
|
|
|
printf("VFS: putnode failed: %d\n", r);
|
|
|
|
util_stacktrace();
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
/* This inode could've been mapped. If so, tell mapped FS to close it as
|
|
|
|
* well. If mapped onto same FS, this putnode is not needed. */
|
|
|
|
if (vp->v_mapfs_e != NONE && vp->v_mapfs_e != vp->v_fs_e)
|
|
|
|
req_putnode(vp->v_mapfs_e, vp->v_mapinode_nr, vp->v_mapfs_count);
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
vp->v_fs_count = 0;
|
|
|
|
vp->v_ref_count = 0;
|
2009-12-21 10:36:34 +01:00
|
|
|
vp->v_mapfs_count = 0;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
unlock_vnode(vp);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-05 17:36:55 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* vnode_clean_refs *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void vnode_clean_refs(struct vnode *vp)
|
|
|
|
{
|
|
|
|
/* Tell the underlying FS to drop all reference but one. */
|
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
if (vp == NULL) return;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
if (vp->v_fs_count <= 1) return; /* Nothing to do */
|
2007-01-05 17:36:55 +01:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
/* Drop all references except one */
|
|
|
|
req_putnode(vp->v_fs_e, vp->v_inode_nr, vp->v_fs_count - 1);
|
|
|
|
vp->v_fs_count = 1;
|
2007-01-05 17:36:55 +01:00
|
|
|
}
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2007-01-05 17:36:55 +01:00
|
|
|
|
2009-01-26 18:43:59 +01:00
|
|
|
#define REFVP(v) { vp = (v); CHECKVN(v); vp->v_ref_check++; }
|
|
|
|
|
2009-05-08 15:56:41 +02:00
|
|
|
#if DO_SANITYCHECKS
|
2007-01-05 17:36:55 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* check_vrefs *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int check_vrefs()
|
|
|
|
{
|
|
|
|
int i, bad;
|
|
|
|
int ispipe_flag, ispipe_mode;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vmnt *vmp;
|
|
|
|
struct fproc *rfp;
|
|
|
|
struct filp *f;
|
|
|
|
|
|
|
|
/* Clear v_ref_check */
|
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; ++vp)
|
|
|
|
vp->v_ref_check= 0;
|
|
|
|
|
|
|
|
/* Count reference for processes */
|
|
|
|
for (rfp=&fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
|
|
|
|
if (rfp->fp_pid == PID_FREE)
|
|
|
|
continue;
|
2009-04-29 18:59:18 +02:00
|
|
|
if(rfp->fp_rd) REFVP(rfp->fp_rd);
|
|
|
|
if(rfp->fp_wd) REFVP(rfp->fp_wd);
|
2012-02-13 16:28:04 +01:00
|
|
|
}
|
2007-01-05 17:36:55 +01:00
|
|
|
|
|
|
|
/* Count references from filedescriptors */
|
|
|
|
for (f = &filp[0]; f < &filp[NR_FILPS]; f++)
|
|
|
|
{
|
|
|
|
if (f->filp_count == 0)
|
|
|
|
continue;
|
2009-01-26 18:43:59 +01:00
|
|
|
REFVP(f->filp_vno);
|
2007-01-05 17:36:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Count references to mount points */
|
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp)
|
|
|
|
{
|
|
|
|
if (vmp->m_dev == NO_DEV)
|
|
|
|
continue;
|
2009-01-26 18:43:59 +01:00
|
|
|
REFVP(vmp->m_root_node);
|
|
|
|
if(vmp->m_mounted_on)
|
|
|
|
REFVP(vmp->m_mounted_on);
|
2007-01-05 17:36:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check references */
|
|
|
|
bad= 0;
|
|
|
|
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; ++vp)
|
|
|
|
{
|
|
|
|
if (vp->v_ref_count != vp->v_ref_check)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Bad reference count for inode %d on device 0x%x: found %d, listed %d\n",
|
|
|
|
vp->v_inode_nr, vp->v_dev, vp->v_ref_check,
|
|
|
|
vp->v_ref_count);
|
|
|
|
printf("last marked at %s, %d\n",
|
|
|
|
vp->v_file, vp->v_line);
|
|
|
|
bad= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Also check v_pipe */
|
|
|
|
if (vp->v_ref_count != 0)
|
|
|
|
{
|
|
|
|
ispipe_flag= (vp->v_pipe == I_PIPE);
|
|
|
|
ispipe_mode= ((vp->v_mode & I_TYPE) == I_NAMED_PIPE);
|
|
|
|
if (ispipe_flag != ispipe_mode)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Bad v_pipe for inode %d on device 0x%x: found %d, mode 0%o\n",
|
|
|
|
vp->v_inode_nr, vp->v_dev, vp->v_pipe,
|
|
|
|
vp->v_mode);
|
|
|
|
printf("last marked at %s, %d\n",
|
|
|
|
vp->v_file, vp->v_line);
|
|
|
|
bad= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !bad;
|
|
|
|
}
|
2009-05-08 15:56:41 +02:00
|
|
|
#endif
|