2006-10-25 15:40:36 +02:00
|
|
|
/* Virtual mount table related routines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
2012-02-13 16:28:04 +01:00
|
|
|
#include "threads.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
#include "vmnt.h"
|
2012-02-13 16:28:04 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include "fproc.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
FORWARD _PROTOTYPE( int is_vmnt_locked, (struct vmnt *vmp) );
|
|
|
|
FORWARD _PROTOTYPE( void clear_vmnt, (struct vmnt *vmp) );
|
|
|
|
|
|
|
|
/* Is vmp pointer reasonable? */
|
|
|
|
#define SANEVMP(v) ((((v) >= &vmnt[0] && (v) < &vmnt[NR_MNTS])))
|
|
|
|
#define BADVMP(v, f, l) printf("%s:%d: bad vmp %p\n", f, l, v)
|
|
|
|
/* vp check that panics */
|
|
|
|
#define ASSERTVMP(v) if(!SANEVMP(v)) { \
|
|
|
|
BADVMP(v, __FILE__, __LINE__); panic("bad vmp"); }
|
|
|
|
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
/*===========================================================================*
|
|
|
|
* check_vmnt_locks_by_me *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void check_vmnt_locks_by_me(struct fproc *rfp)
|
|
|
|
{
|
|
|
|
/* Check whether this thread still has locks held on vmnts */
|
|
|
|
struct vmnt *vmp;
|
|
|
|
|
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) {
|
|
|
|
if (tll_locked_by_me(&vmp->m_lock))
|
|
|
|
panic("Thread %d still holds vmnt lock on vmp %p call_nr=%d\n",
|
|
|
|
mthread_self(), vmp, call_nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rfp->fp_vmnt_rdlocks != 0)
|
|
|
|
panic("Thread %d still holds read locks on a vmnt (%d) call_nr=%d\n",
|
|
|
|
mthread_self(), rfp->fp_vmnt_rdlocks, call_nr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* check_vmnt_locks *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void check_vmnt_locks()
|
|
|
|
{
|
|
|
|
struct vmnt *vmp;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++)
|
|
|
|
if (is_vmnt_locked(vmp)) {
|
|
|
|
count++;
|
|
|
|
printf("vmnt %p is %s, fs_e=%d dev=%d\n", vmp, (tll_islocked(&vmp->m_lock) ? "locked":"pending locked"), vmp->m_fs_e, vmp->m_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count) panic("%d locked vmnts\n", count);
|
|
|
|
#if 0
|
|
|
|
printf("check_vmnt_locks OK\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* clear_vmnt *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void clear_vmnt(struct vmnt *vmp)
|
|
|
|
{
|
|
|
|
/* Reset vmp to initial parameters */
|
|
|
|
ASSERTVMP(vmp);
|
|
|
|
|
|
|
|
vmp->m_fs_e = NONE;
|
|
|
|
vmp->m_dev = NO_DEV;
|
|
|
|
vmp->m_flags = 0;
|
|
|
|
vmp->m_mounted_on = NULL;
|
|
|
|
vmp->m_root_node = NULL;
|
|
|
|
vmp->m_label[0] = '\0';
|
|
|
|
vmp->m_comm.c_max_reqs = 1;
|
|
|
|
vmp->m_comm.c_cur_reqs = 0;
|
|
|
|
vmp->m_comm.c_req_queue = NULL;
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_free_vmnt *
|
|
|
|
*===========================================================================*/
|
2012-02-13 16:28:04 +01:00
|
|
|
PUBLIC struct vmnt *get_free_vmnt(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
struct vmnt *vp;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
for (vp = &vmnt[0]; vp < &vmnt[NR_MNTS]; ++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
|
|
|
if (vp->m_dev == NO_DEV) return(vp);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
return(NULL);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* find_vmnt *
|
|
|
|
*===========================================================================*/
|
2012-02-13 16:28:04 +01:00
|
|
|
PUBLIC struct vmnt *find_vmnt(endpoint_t fs_e)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
2012-02-13 16:28:04 +01:00
|
|
|
/* Find the vmnt belonging to an FS with endpoint 'fs_e' iff it's in use */
|
2006-10-25 15:40:36 +02:00
|
|
|
struct vmnt *vp;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
for (vp = &vmnt[0]; vp < &vmnt[NR_MNTS]; ++vp)
|
|
|
|
if (vp->m_fs_e == fs_e && vp->m_dev != NO_DEV)
|
|
|
|
return(vp);
|
2006-10-25 15:40:36 +02: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
|
|
|
/*===========================================================================*
|
|
|
|
* init_vmnts *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void init_vmnts(void)
|
|
|
|
{
|
|
|
|
/* Initialize vmnt table */
|
|
|
|
struct vmnt *vmp;
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) {
|
|
|
|
clear_vmnt(vmp);
|
|
|
|
tll_init(&vmp->m_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* is_vmnt_locked *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int is_vmnt_locked(struct vmnt *vmp)
|
|
|
|
{
|
|
|
|
ASSERTVMP(vmp);
|
|
|
|
return(tll_islocked(&vmp->m_lock) || tll_haspendinglock(&vmp->m_lock));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* lock_vmnt *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int lock_vmnt(struct vmnt *vmp, tll_access_t locktype)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
tll_access_t initial_locktype;
|
|
|
|
|
|
|
|
ASSERTVMP(vmp);
|
|
|
|
|
|
|
|
initial_locktype = (locktype == VMNT_EXCL) ? VMNT_WRITE : locktype;
|
|
|
|
|
|
|
|
if (vmp->m_fs_e == who_e) return(EDEADLK);
|
|
|
|
|
|
|
|
r = tll_lock(&vmp->m_lock, initial_locktype);
|
|
|
|
|
|
|
|
if (r == EBUSY) return(r);
|
|
|
|
|
|
|
|
if (initial_locktype != locktype) {
|
|
|
|
tll_upgrade(&vmp->m_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
if (locktype == VMNT_READ)
|
|
|
|
fp->fp_vmnt_rdlocks++;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* vmnt_unmap_by_endpoint *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void vmnt_unmap_by_endpt(endpoint_t proc_e)
|
|
|
|
{
|
|
|
|
struct vmnt *vmp;
|
|
|
|
|
|
|
|
if ((vmp = find_vmnt(proc_e)) != NULL) {
|
|
|
|
fs_cancel(vmp);
|
|
|
|
invalidate_filp_by_endpt(proc_e);
|
|
|
|
if (vmp->m_mounted_on) {
|
|
|
|
/* Only put mount point when it was actually used as mount
|
|
|
|
* point. That is, the mount was succesful. */
|
|
|
|
put_vnode(vmp->m_mounted_on);
|
|
|
|
}
|
|
|
|
clear_vmnt(vmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* unlock_vmnt *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void unlock_vmnt(struct vmnt *vmp)
|
|
|
|
{
|
|
|
|
ASSERTVMP(vmp);
|
|
|
|
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
/* Decrease read-only lock counter when not locked as VMNT_WRITE or
|
|
|
|
* VMNT_EXCL */
|
|
|
|
if (!tll_locked_by_me(&vmp->m_lock))
|
|
|
|
fp->fp_vmnt_rdlocks--;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tll_unlock(&vmp->m_lock);
|
|
|
|
|
|
|
|
#if LOCK_DEBUG
|
|
|
|
assert(!tll_locked_by_me(&vmp->m_lock));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|