. new kernel call sysctl for generic unprivileged system operations;
now used for printing diagnostic messages through the kernel message buffer. this lets processes print diagnostics without sending messages to tty and log directly, simplifying the message protocol a lot and reducing difficulties with deadlocks and other situations in which diagnostics are blackholed (e.g. grants don't work). this makes DIAGNOSTICS(_S), ASYN_DIAGNOSTICS and DIAG_REPL obsolete, although tty and log still accept the codes for 'old' binaries. This also simplifies diagnostics in several servers and drivers - only tty needs its own kputc() now. . simplifications in vfs, and some effort to get the vnode references right (consistent) even during shutdown. m_mounted_on is now NULL for root filesystems (!) (the original and new root), a less awkward special case than 'm_mounted_on == m_root_node'. root now has exactly one reference, to root, if no files are open, just like all other filesystems. m_driver_e is unused.
This commit is contained in:
@@ -48,16 +48,20 @@ PUBLIC int fs_putnode()
|
||||
fs_m_in.REQ_INODE_INDEX < NR_INODES &&
|
||||
inode[fs_m_in.REQ_INODE_INDEX].i_num == fs_m_in.REQ_INODE_NR) {
|
||||
rip = &inode[fs_m_in.REQ_INODE_INDEX];
|
||||
if(!rip) {
|
||||
panic(__FILE__, "null rip", NO_NUM);
|
||||
}
|
||||
}
|
||||
/* Otherwise find it */
|
||||
else {
|
||||
rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR);
|
||||
if(!(rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR))) {
|
||||
printf("FSput_inode: inode #%d dev: %d not found, req_nr: %d\n",
|
||||
fs_m_in.REQ_INODE_NR, fs_dev, req_nr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!rip)
|
||||
{
|
||||
printf("FSput_inode: inode #%d dev: %d couldn't be put, req_nr: %d\n",
|
||||
fs_m_in.REQ_INODE_NR, fs_dev, req_nr);
|
||||
panic(__FILE__, "fs_putnode failed", NO_NUM);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ LDFLAGS = -i
|
||||
|
||||
OBJ = main.o forkexit.o break.o exec.o time.o timers.o \
|
||||
signal.o utility.o table.o trace.o getset.o misc.o \
|
||||
profile.o kputc.o dma.o
|
||||
profile.o dma.o
|
||||
|
||||
# build local binary
|
||||
all build: $(SERVER)
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
/* A server must occasionally print some message. It uses a simple version of
|
||||
* printf() found in the system lib that calls kputc() to output characters.
|
||||
* Printing is done with a call to the kernel, and not by going through FS.
|
||||
*
|
||||
* This routine can only be used by servers and device drivers. The kernel
|
||||
* must define its own kputc(). Note that the log driver also defines its own
|
||||
* kputc() to directly call the TTY instead of going through this library.
|
||||
*/
|
||||
|
||||
#include "pm.h"
|
||||
#include <string.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
#define OVERFLOW_STR "[...]\n"
|
||||
|
||||
#define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
|
||||
|
||||
static char print_buf[800]; /* output is buffered here */
|
||||
|
||||
int kputc_use_private_grants= 0;
|
||||
|
||||
static int buf_count = 0; /* # characters in the buffer */
|
||||
static int buf_offset = 0; /* Start of current line in buffer */
|
||||
static int procs[] = OUTPUT_PROCS_ARRAY;
|
||||
static cp_grant_id_t printgrants[PRINTPROCS];
|
||||
static int procbusy[PRINTPROCS];
|
||||
static int do_flush = FALSE;
|
||||
static int overflow = FALSE;
|
||||
|
||||
/*===========================================================================*
|
||||
* kputc *
|
||||
*===========================================================================*/
|
||||
void kputc(c)
|
||||
int c;
|
||||
{
|
||||
/* Accumulate another character. If 0 or buffer full, print it. */
|
||||
int p;
|
||||
message m;
|
||||
|
||||
static int firstprint = 1;
|
||||
|
||||
if (c == 0)
|
||||
{
|
||||
if (buf_count > buf_offset)
|
||||
do_flush= TRUE;
|
||||
}
|
||||
else if (buf_count >= sizeof(print_buf))
|
||||
{
|
||||
overflow= TRUE;
|
||||
if (buf_count > buf_offset)
|
||||
do_flush= TRUE;
|
||||
}
|
||||
else
|
||||
print_buf[buf_count++] = c;
|
||||
|
||||
if (!do_flush || buf_offset != 0)
|
||||
return;
|
||||
|
||||
buf_offset= buf_count;
|
||||
if (kputc_use_private_grants)
|
||||
{
|
||||
for (p= 0; p<PRINTPROCS; p++)
|
||||
printgrants[p]= GRANT_INVALID;
|
||||
firstprint= 0;
|
||||
}
|
||||
if(firstprint) {
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
printgrants[p] = GRANT_INVALID;
|
||||
}
|
||||
|
||||
firstprint = 0;
|
||||
|
||||
/* First time? Initialize grant table;
|
||||
* Grant printing processes read copy access to our
|
||||
* print buffer forever. (So buffer can't be on stack!)
|
||||
*/
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
printgrants[p] = cpf_grant_direct(procs[p],
|
||||
(vir_bytes) print_buf,
|
||||
sizeof(print_buf), CPF_READ);
|
||||
}
|
||||
}
|
||||
|
||||
do_flush= FALSE;
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
/* Send the buffer to this output driver. */
|
||||
m.DIAG_BUF_COUNT = buf_count;
|
||||
if(GRANT_VALID(printgrants[p])) {
|
||||
m.m_type = DIAGNOSTICS_S;
|
||||
m.DIAG_PRINT_BUF_G = (char *) printgrants[p];
|
||||
} else {
|
||||
m.m_type = DIAGNOSTICS;
|
||||
m.DIAG_PRINT_BUF_G = print_buf;
|
||||
}
|
||||
if (procs[p] == LOG_PROC_NR)
|
||||
{
|
||||
procbusy[p]= TRUE;
|
||||
(void) asynsend(procs[p], &m);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendrec(procs[p], &m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void diag_repl()
|
||||
{
|
||||
endpoint_t driver_e;
|
||||
int p;
|
||||
|
||||
driver_e= m_in.m_source;
|
||||
|
||||
/* Find busy flag to clear */
|
||||
for(p = 0; procs[p] != NONE; p++)
|
||||
{
|
||||
if (procs[p] == driver_e)
|
||||
break;
|
||||
}
|
||||
if (procs[p] == NONE)
|
||||
{
|
||||
/* Message from wrong source */
|
||||
return;
|
||||
}
|
||||
procbusy[p]= FALSE;
|
||||
|
||||
/* Wait for more replies? */
|
||||
for(p = 0; procs[p] != NONE; p++)
|
||||
{
|
||||
if (procbusy[p])
|
||||
return;
|
||||
}
|
||||
if (buf_count > buf_offset)
|
||||
{
|
||||
memmove(&print_buf[0], &print_buf[buf_offset],
|
||||
buf_count-buf_offset);
|
||||
}
|
||||
buf_count -= buf_offset;
|
||||
buf_offset= 0;
|
||||
if (overflow)
|
||||
{
|
||||
if (buf_count + sizeof(OVERFLOW_STR) > sizeof(print_buf))
|
||||
buf_count= sizeof(print_buf)-sizeof(OVERFLOW_STR);
|
||||
overflow= FALSE;
|
||||
do_flush= FALSE;
|
||||
printf("%s", OVERFLOW_STR);
|
||||
}
|
||||
kputc(0);
|
||||
}
|
||||
@@ -121,10 +121,6 @@ PUBLIC int main()
|
||||
case GETPUID:
|
||||
result= do_getpuid();
|
||||
break;
|
||||
case DIAG_REPL :
|
||||
diag_repl();
|
||||
result= SUSPEND;
|
||||
break;
|
||||
default:
|
||||
/* Else, if the system call number is valid, perform the
|
||||
* call.
|
||||
|
||||
@@ -69,7 +69,7 @@ PUBLIC int do_allocmem()
|
||||
{
|
||||
int r;
|
||||
phys_bytes retmembase;
|
||||
r = vm_allocmem(m_in.memsize, &retmembase);
|
||||
r = vm_allocmem(m_in.memsize, (phys_clicks *) &retmembase);
|
||||
if(r == OK)
|
||||
mp->mp_reply.membase = retmembase;
|
||||
return r;
|
||||
|
||||
@@ -1024,10 +1024,6 @@ struct rproc *rp;
|
||||
case 0:
|
||||
execle(rp->r_script, rp->r_script, rp->r_label, reason,
|
||||
incarnation_str, NULL, NULL);
|
||||
{
|
||||
extern int kputc_use_private_grants;
|
||||
kputc_use_private_grants= 1;
|
||||
}
|
||||
printf("RS: run_script: execl '%s' failed: %s\n",
|
||||
rp->r_script, strerror(errno));
|
||||
exit(1);
|
||||
|
||||
@@ -692,6 +692,7 @@ struct
|
||||
{ "MAPDMA", SYS_MAPDMA },
|
||||
{ "VMCTL", SYS_VMCTL },
|
||||
{ "PROFBUF", SYS_PROFBUF },
|
||||
{ "SYSCTL", SYS_SYSCTL },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ OBJ = main.o open.o read.o write.o pipe.o dmap.o \
|
||||
path.o device.o mount.o link.o exec.o \
|
||||
filedes.o stadir.o protect.o time.o \
|
||||
lock.o misc.o utility.o select.o timers.o table.o \
|
||||
vnode.o vmnt.o request.o kputc.o mmap.o
|
||||
vnode.o vmnt.o request.o mmap.o
|
||||
|
||||
# build local binary
|
||||
install all build: $(SERVER)
|
||||
|
||||
@@ -891,8 +891,6 @@ PUBLIC void dev_up(int maj)
|
||||
printf(
|
||||
"VFSdev_up: error sending new driver endpoint. FS_e: %d req_nr: %d\n",
|
||||
vmp->m_fs_e, REQ_NEW_DRIVER);
|
||||
else
|
||||
vmp->m_driver_e = new_driver_e;
|
||||
}
|
||||
|
||||
/* Look for processes that are suspened in an OPEN call. Set SUSP_REOPEN
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
/* A server must occasionally print some message. It uses a simple version of
|
||||
* printf() found in the system lib that calls kputc() to output characters.
|
||||
* Printing is done with a call to the kernel, and not by going through FS.
|
||||
*
|
||||
* This routine can only be used by servers and device drivers. The kernel
|
||||
* must define its own kputc(). Note that the log driver also defines its own
|
||||
* kputc() to directly call the TTY instead of going through this library.
|
||||
*/
|
||||
|
||||
#include "fs.h"
|
||||
#include <string.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
#define OVERFLOW_STR "[...]\n"
|
||||
|
||||
#define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
|
||||
|
||||
static char print_buf[800]; /* output is buffered here */
|
||||
|
||||
int kputc_use_private_grants= 0;
|
||||
|
||||
static int buf_count = 0; /* # characters in the buffer */
|
||||
static int buf_offset = 0; /* Start of current line in buffer */
|
||||
static int procs[] = OUTPUT_PROCS_ARRAY;
|
||||
static cp_grant_id_t printgrants[PRINTPROCS];
|
||||
static int procbusy[PRINTPROCS];
|
||||
static int do_flush = FALSE;
|
||||
static int overflow = FALSE;
|
||||
|
||||
/*===========================================================================*
|
||||
* kputc *
|
||||
*===========================================================================*/
|
||||
void kputc(c)
|
||||
int c;
|
||||
{
|
||||
/* Accumulate another character. If 0 or buffer full, print it. */
|
||||
int p;
|
||||
message m;
|
||||
|
||||
static int firstprint = 1;
|
||||
|
||||
if (c == 0)
|
||||
{
|
||||
if (buf_count > buf_offset)
|
||||
do_flush= TRUE;
|
||||
}
|
||||
else if (buf_count >= sizeof(print_buf))
|
||||
{
|
||||
overflow= TRUE;
|
||||
if (buf_count > buf_offset)
|
||||
do_flush= TRUE;
|
||||
}
|
||||
else
|
||||
print_buf[buf_count++] = c;
|
||||
|
||||
if (!do_flush || buf_offset != 0)
|
||||
return;
|
||||
|
||||
buf_offset= buf_count;
|
||||
if (kputc_use_private_grants)
|
||||
{
|
||||
for (p= 0; p<PRINTPROCS; p++)
|
||||
printgrants[p]= GRANT_INVALID;
|
||||
firstprint= 0;
|
||||
}
|
||||
if(firstprint) {
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
printgrants[p] = GRANT_INVALID;
|
||||
}
|
||||
|
||||
firstprint = 0;
|
||||
|
||||
/* First time? Initialize grant table;
|
||||
* Grant printing processes read copy access to our
|
||||
* print buffer forever. (So buffer can't be on stack!)
|
||||
*/
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
printgrants[p] = cpf_grant_direct(procs[p],
|
||||
(vir_bytes) print_buf,
|
||||
sizeof(print_buf), CPF_READ);
|
||||
}
|
||||
}
|
||||
|
||||
do_flush= FALSE;
|
||||
for(p = 0; procs[p] != NONE; p++) {
|
||||
/* Send the buffer to this output driver. */
|
||||
m.DIAG_BUF_COUNT = buf_count;
|
||||
if(GRANT_VALID(printgrants[p])) {
|
||||
m.m_type = DIAGNOSTICS_S;
|
||||
m.DIAG_PRINT_BUF_G = (char *) printgrants[p];
|
||||
} else {
|
||||
m.m_type = DIAGNOSTICS;
|
||||
m.DIAG_PRINT_BUF_G = print_buf;
|
||||
}
|
||||
if (procs[p] == LOG_PROC_NR)
|
||||
{
|
||||
procbusy[p]= TRUE;
|
||||
(void) asynsend(procs[p], &m);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendrec(procs[p], &m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void diag_repl()
|
||||
{
|
||||
endpoint_t driver_e;
|
||||
int p;
|
||||
|
||||
driver_e= m_in.m_source;
|
||||
|
||||
/* Find busy flag to clear */
|
||||
for(p = 0; procs[p] != NONE; p++)
|
||||
{
|
||||
if (procs[p] == driver_e)
|
||||
break;
|
||||
}
|
||||
if (procs[p] == NONE)
|
||||
{
|
||||
/* Message from wrong source */
|
||||
return;
|
||||
}
|
||||
procbusy[p]= FALSE;
|
||||
|
||||
/* Wait for more replies? */
|
||||
for(p = 0; procs[p] != NONE; p++)
|
||||
{
|
||||
if (procbusy[p])
|
||||
return;
|
||||
}
|
||||
if (buf_count > buf_offset)
|
||||
{
|
||||
memmove(&print_buf[0], &print_buf[buf_offset],
|
||||
buf_count-buf_offset);
|
||||
}
|
||||
buf_count -= buf_offset;
|
||||
buf_offset= 0;
|
||||
if (overflow)
|
||||
{
|
||||
if (buf_count + sizeof(OVERFLOW_STR) > sizeof(print_buf))
|
||||
buf_count= sizeof(print_buf)-sizeof(OVERFLOW_STR);
|
||||
overflow= FALSE;
|
||||
do_flush= FALSE;
|
||||
printf("%s", OVERFLOW_STR);
|
||||
}
|
||||
kputc(0);
|
||||
}
|
||||
@@ -64,10 +64,6 @@ PUBLIC int main()
|
||||
if (who_e == PM_PROC_NR && call_nr != PROC_EVENT)
|
||||
printf("FS: strange, got message %d from PM\n", call_nr);
|
||||
|
||||
#if 0
|
||||
printf("VFS: got call %d from %d\n", call_nr, who_e);
|
||||
#endif
|
||||
|
||||
if (call_nr == DEV_REVIVE)
|
||||
{
|
||||
endpoint_t endpt;
|
||||
@@ -105,11 +101,6 @@ PUBLIC int main()
|
||||
select_reply2();
|
||||
continue;
|
||||
}
|
||||
if (call_nr == DIAG_REPL)
|
||||
{
|
||||
diag_repl();
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check for special control messages first. */
|
||||
if ((call_nr & NOTIFY_MESSAGE)) {
|
||||
@@ -477,16 +468,14 @@ PRIVATE void init_root()
|
||||
/* Fill in max file size and blocksize for the vmnt */
|
||||
vmp->m_fs_e = resX.fs_e;
|
||||
vmp->m_dev = root_dev;
|
||||
vmp->m_driver_e = dp->dmap_driver;
|
||||
vmp->m_flags = 0;
|
||||
|
||||
/* Root node is indeed on the partition */
|
||||
root_node->v_vmnt = vmp;
|
||||
root_node->v_dev = vmp->m_dev;
|
||||
|
||||
/* Root directory is mounted on itself */
|
||||
vmp->m_mounted_on = root_node;
|
||||
root_node->v_ref_count++;
|
||||
/* Root directory is not mounted on a vnode. */
|
||||
vmp->m_mounted_on = NULL;
|
||||
vmp->m_root_node = root_node;
|
||||
}
|
||||
|
||||
|
||||
@@ -305,26 +305,24 @@ PUBLIC void pm_reboot()
|
||||
{
|
||||
/* Perform the FS side of the reboot call. */
|
||||
int i;
|
||||
struct vnode vdummy;
|
||||
struct vmnt *vmp;
|
||||
|
||||
do_sync();
|
||||
|
||||
CHECK_VREFS;
|
||||
|
||||
/* Do exit processing for all leftover processes and servers,
|
||||
* but don't actually exit them (if they were really gone, PM
|
||||
* will tell us about it).
|
||||
*/
|
||||
for (i = 0; i < NR_PROCS; i++)
|
||||
if((m_in.endpt1 = fproc[i].fp_endpoint) != NONE)
|
||||
free_proc(&fproc[i], 0);
|
||||
free_proc(&fproc[i], FP_EXITING);
|
||||
CHECK_VREFS;
|
||||
|
||||
/* The root file system is mounted onto itself, which keeps it from being
|
||||
* unmounted. Pull an inode out of thin air and put the root on it.
|
||||
*/
|
||||
|
||||
put_vnode(vmnt[0].m_mounted_on);
|
||||
vmnt[0].m_mounted_on = &vdummy;
|
||||
vmnt[0].m_root_node = &vdummy;
|
||||
vdummy.v_fs_count = 0; /* Is this right? */
|
||||
vdummy.v_ref_count = 1;
|
||||
|
||||
/* Unmount all filesystems. File systems are mounted on other file systems,
|
||||
* so you have to pull off the loose bits repeatedly to get it all undone.
|
||||
@@ -332,9 +330,18 @@ PUBLIC void pm_reboot()
|
||||
for (i= 0; i < NR_SUPERS; i++) {
|
||||
/* Unmount at least one. */
|
||||
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) {
|
||||
if (vmp->m_dev != NO_DEV) (void) unmount(vmp->m_dev);
|
||||
if (vmp->m_dev != NO_DEV) {
|
||||
printf("VFS: pm_reboot: unmount 0x%x, FS %d\n",
|
||||
vmp->m_dev, vmp->m_fs_e);
|
||||
CHECK_VREFS;
|
||||
(void) unmount(vmp->m_dev);
|
||||
CHECK_VREFS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_VREFS;
|
||||
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
||||
@@ -103,7 +103,7 @@ PRIVATE int mount_fs(endpoint_t fs_e)
|
||||
dev_t dev;
|
||||
message m;
|
||||
struct vnode *vp, *root_node, *mounted_on, *bspec;
|
||||
struct vmnt *vmp, *vmp2;
|
||||
struct vmnt *vmp;
|
||||
char *label;
|
||||
struct node_details res;
|
||||
|
||||
@@ -168,8 +168,7 @@ PRIVATE int mount_fs(endpoint_t fs_e)
|
||||
if (found) {
|
||||
/* It is possible that we have an old root lying around that
|
||||
* needs to be remounted. */
|
||||
if (vmp->m_mounted_on != vmp->m_root_node ||
|
||||
vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
|
||||
if (vmp->m_mounted_on || vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
|
||||
/* Normally, m_mounted_on refers to the mount point. For a
|
||||
* root filesystem, m_mounted_on is equal to the root vnode.
|
||||
* We assume that the root of FS is always the real root. If
|
||||
@@ -180,6 +179,9 @@ PRIVATE int mount_fs(endpoint_t fs_e)
|
||||
return EBUSY; /* already mounted */
|
||||
}
|
||||
|
||||
if(vmp->m_mounted_on)
|
||||
panic("vfs", "root unexpectedly mounted somewhere", NO_NUM);
|
||||
|
||||
if (root_dev == vmp->m_dev)
|
||||
panic("fs", "inconsistency remounting old root", NO_NUM);
|
||||
|
||||
@@ -227,7 +229,6 @@ PRIVATE int mount_fs(endpoint_t fs_e)
|
||||
}
|
||||
|
||||
/* Nothing else can go wrong. Perform the mount. */
|
||||
put_vnode(vmp->m_mounted_on);
|
||||
vmp->m_mounted_on = mounted_on;
|
||||
vmp->m_flags = m_in.rd_only;
|
||||
allow_newroot = 0; /* The root is now fixed */
|
||||
@@ -308,7 +309,6 @@ PRIVATE int mount_fs(endpoint_t fs_e)
|
||||
vmp->m_fs_e = res.fs_e;
|
||||
vmp->m_dev = dev;
|
||||
vmp->m_flags = m_in.rd_only;
|
||||
vmp->m_driver_e = dp->dmap_driver;
|
||||
|
||||
/* Root node is indeed on the partition */
|
||||
root_node->v_vmnt = vmp;
|
||||
@@ -318,8 +318,7 @@ PRIVATE int mount_fs(endpoint_t fs_e)
|
||||
/* Superblock and root node already read.
|
||||
* Nothing else can go wrong. Perform the mount. */
|
||||
vmp->m_root_node = root_node;
|
||||
root_node->v_ref_count++;
|
||||
vmp->m_mounted_on = root_node;
|
||||
vmp->m_mounted_on = NULL;
|
||||
|
||||
root_dev = dev;
|
||||
ROOT_FS_E = fs_e;
|
||||
@@ -388,13 +387,17 @@ PUBLIC int do_umount()
|
||||
{
|
||||
/* Perform the umount(name) system call. */
|
||||
dev_t dev;
|
||||
CHECK_VREFS;
|
||||
|
||||
/* Only the super-user may do UMOUNT. */
|
||||
if (!super_user) return(EPERM);
|
||||
CHECK_VREFS;
|
||||
|
||||
/* If 'name' is not for a block special file, return error. */
|
||||
if (fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code);
|
||||
CHECK_VREFS;
|
||||
if ( (dev = name_to_dev()) == NO_DEV) return(err_code);
|
||||
CHECK_VREFS;
|
||||
|
||||
return(unmount(dev));
|
||||
}
|
||||
@@ -406,7 +409,7 @@ PUBLIC int do_umount()
|
||||
PUBLIC int unmount(dev)
|
||||
Dev_t dev;
|
||||
{
|
||||
struct vnode *vp;
|
||||
struct vnode *vp, *vi;
|
||||
struct vmnt *vmp_i = NULL, *vmp = NULL;
|
||||
struct dmap *dp;
|
||||
int count, r;
|
||||
@@ -436,8 +439,8 @@ Dev_t dev;
|
||||
#if 1
|
||||
int i;
|
||||
struct fproc *tfp;
|
||||
printf("unmount: vnode %d in use %d times\n",
|
||||
vp->v_inode_nr, vp->v_ref_count);
|
||||
printf("unmount: vnode 0x%x/%d in use %d times\n",
|
||||
dev, vp->v_inode_nr, vp->v_ref_count);
|
||||
for (i= 0, tfp= fproc; i<NR_PROCS; i++, tfp++) {
|
||||
int n;
|
||||
if (tfp->fp_pid == PID_FREE)
|
||||
@@ -454,22 +457,57 @@ Dev_t dev;
|
||||
vp->v_inode_nr, n, tfp->fp_pid);
|
||||
}
|
||||
}
|
||||
|
||||
for (vmp_i = &vmnt[0]; vmp_i < &vmnt[NR_MNTS]; ++vmp_i) {
|
||||
if (vmp_i->m_dev != NO_DEV) {
|
||||
if(vmp_i->m_mounted_on == vp) {
|
||||
printf("\tvnode %d: is a mount point\n",
|
||||
vp->v_inode_nr);
|
||||
}
|
||||
if(vmp_i->m_root_node == vp) {
|
||||
printf("\tvnode %d: is a root node\n",
|
||||
vp->v_inode_nr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
count += vp->v_ref_count;
|
||||
}
|
||||
}
|
||||
CHECK_VREFS;
|
||||
|
||||
if (count > 1) {
|
||||
return(EBUSY); /* can't umount a busy file system */
|
||||
}
|
||||
|
||||
CHECK_VREFS;
|
||||
|
||||
vnode_clean_refs(vmp->m_root_node);
|
||||
CHECK_VREFS;
|
||||
|
||||
if (vmp->m_mounted_on) {
|
||||
put_vnode(vmp->m_mounted_on);
|
||||
vmp->m_mounted_on->v_fs_count--;
|
||||
vmp->m_mounted_on = NIL_VNODE;
|
||||
}
|
||||
|
||||
put_vnode(vmp->m_root_node);
|
||||
vmp->m_root_node->v_ref_count = 0;
|
||||
vmp->m_root_node = NIL_VNODE;
|
||||
|
||||
/* Request FS the unmount */
|
||||
if(vmp->m_fs_e <= 0)
|
||||
if(vmp->m_fs_e <= 0 || vmp->m_fs_e == NONE)
|
||||
panic(__FILE__, "unmount: strange fs endpoint", vmp->m_fs_e);
|
||||
if ((r = req_unmount(vmp->m_fs_e)) != OK) return r;
|
||||
if ((r = req_unmount(vmp->m_fs_e)) != OK) {
|
||||
/* Not recoverable. */
|
||||
printf("VFS: ignoring unmount failure %d from %d\n", r, vmp->m_fs_e);
|
||||
}
|
||||
|
||||
vmp->m_dev = NO_DEV;
|
||||
vmp->m_fs_e = NONE;
|
||||
|
||||
CHECK_VREFS;
|
||||
|
||||
/* Is there a block special file that was handled by that partition? */
|
||||
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; vp++) {
|
||||
@@ -496,22 +534,6 @@ Dev_t dev;
|
||||
}
|
||||
}
|
||||
|
||||
/* Root device is mounted on itself */
|
||||
if (vmp->m_root_node != vmp->m_mounted_on) {
|
||||
put_vnode(vmp->m_mounted_on);
|
||||
vmp->m_root_node->v_ref_count = 0;
|
||||
}
|
||||
else {
|
||||
vmp->m_mounted_on->v_fs_count--;
|
||||
}
|
||||
|
||||
fs_e = vmp->m_fs_e;
|
||||
|
||||
vmp->m_root_node = NIL_VNODE;
|
||||
vmp->m_mounted_on = NIL_VNODE;
|
||||
vmp->m_dev = NO_DEV;
|
||||
vmp->m_fs_e = NONE;
|
||||
vmp->m_driver_e = NONE;
|
||||
CHECK_VREFS;
|
||||
|
||||
return(OK);
|
||||
|
||||
@@ -256,7 +256,9 @@ _PROTOTYPE( struct vnode *get_vnode, (int fs_e, int inode_nr) );
|
||||
_PROTOTYPE( struct vnode *get_vnode_x, (int fs_e, int inode_nr) );
|
||||
_PROTOTYPE( void mark_vn, (struct vnode *vp, char *file, int line) );
|
||||
#endif
|
||||
#define CHECK_VREFS do { if(!check_vrefs()) panic("VFS", "check_vrefs failed", NO_NUM);} while(0)
|
||||
#define CHECK_VREFS do { if(!check_vrefs()) { \
|
||||
printf("VFS:%s:%d: check_vrefs failed\n", __FILE__, __LINE__); \
|
||||
panic("VFS", "check_vrefs failed", NO_NUM);} } while(0)
|
||||
_PROTOTYPE( int check_vrefs, (void) );
|
||||
|
||||
/* write.c */
|
||||
|
||||
@@ -577,6 +577,7 @@ endpoint_t driver_e;
|
||||
/* Issue request */
|
||||
if ((r = sendrec(fs_e, &m)) != OK) {
|
||||
printf("VFSreq_newdriver: error sending message to %d: %d\n", fs_e, r);
|
||||
util_stacktrace();
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1019,11 +1020,8 @@ PRIVATE int fs_sendrec_f(char *file, int line, endpoint_t fs_e, message *reqm)
|
||||
message origm, m;
|
||||
struct vmnt *vmp;
|
||||
|
||||
if (fs_e == PM_PROC_NR)
|
||||
{
|
||||
printf("from %s, %d\n", file, line);
|
||||
panic(__FILE__, "talking to PM", NO_NUM);
|
||||
}
|
||||
if(fs_e <= 0 || fs_e == NONE)
|
||||
panic(__FILE__, "talking to bogus endpoint", fs_e);
|
||||
|
||||
/* Make a copy of the request so that we can load it back in
|
||||
* case of a dead driver */
|
||||
@@ -1036,6 +1034,7 @@ PRIVATE int fs_sendrec_f(char *file, int line, endpoint_t fs_e, message *reqm)
|
||||
if (OK != (r=sendrec(fs_e, reqm))) {
|
||||
printf("VFS:fs_sendrec:%s:%d: error sending message. FS_e: %d req_nr: %d err: %d\n",
|
||||
file, line, fs_e, reqm->m_type, r);
|
||||
util_stacktrace();
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1050,7 +1049,9 @@ PRIVATE int fs_sendrec_f(char *file, int line, endpoint_t fs_e, message *reqm)
|
||||
/* Find old driver by endpoint */
|
||||
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
|
||||
if (vmp->m_fs_e == fs_e) { /* found FS */
|
||||
#if 0
|
||||
old_driver_e = vmp->m_driver_e;
|
||||
#endif
|
||||
dmap_unmap_by_endpt(old_driver_e); /* unmap driver */
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
EXTERN struct vmnt {
|
||||
int m_fs_e; /* FS process' kernel endpoint */
|
||||
dev_t m_dev; /* device number */
|
||||
int m_driver_e; /* device driver process' kernel endpoint */
|
||||
int m_flags; /* mount flags */
|
||||
struct vnode *m_mounted_on; /* the vnode on which the partition is mounted */
|
||||
struct vnode *m_root_node; /* root vnode */
|
||||
|
||||
@@ -19,6 +19,20 @@
|
||||
|
||||
#include <minix/vfsif.h>
|
||||
|
||||
/* Is vnode pointer reasonable? */
|
||||
#define SANEVP(v) ((((v) >= &vnode[0] && (v) < &vnode[NR_VNODES])))
|
||||
|
||||
#define BADVP(v, f, l) printf("%s:%d: bad vp 0x%x\n", f, l, v)
|
||||
|
||||
/* 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)) { \
|
||||
BADVP(v, __FILE__, __LINE__); panic("vfs", "bad vp", NO_NUM); }
|
||||
|
||||
/*===========================================================================*
|
||||
* get_free_vnode *
|
||||
@@ -72,11 +86,7 @@ PUBLIC void dup_vnode(struct vnode *vp)
|
||||
/* dup_vnode() is called to increment the vnode and therefore the
|
||||
* referred inode's counter.
|
||||
*/
|
||||
if (vp == NIL_VNODE) {
|
||||
printf("VFSdup_vnode NIL_VNODE\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERTVP(vp);
|
||||
vp->v_ref_count++;
|
||||
}
|
||||
|
||||
@@ -89,17 +99,7 @@ PUBLIC void put_vnode(struct vnode *vp)
|
||||
/* Decrease vnode's usage counter and decrease inode's usage counter in the
|
||||
* corresponding FS process.
|
||||
*/
|
||||
if (vp == NIL_VNODE) {
|
||||
/*printf("VFSput_vnode NIL_VNODE\n");*/
|
||||
return;
|
||||
}
|
||||
|
||||
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
|
||||
{
|
||||
printf("put_vnode: &vnode[0] = %p, &vnode[NR_VNODES] = %p, vp = %p\n",
|
||||
&vnode[0], &vnode[NR_VNODES], vp);
|
||||
panic(__FILE__, "put_vnode: bad vnode pointer", NO_NUM);
|
||||
}
|
||||
ASSERTVP(vp);
|
||||
|
||||
if (vp->v_ref_count > 1)
|
||||
{
|
||||
@@ -167,6 +167,8 @@ int line;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define REFVP(v) { vp = (v); CHECKVN(v); vp->v_ref_check++; }
|
||||
|
||||
/*===========================================================================*
|
||||
* check_vrefs *
|
||||
*===========================================================================*/
|
||||
@@ -187,16 +189,8 @@ PUBLIC int check_vrefs()
|
||||
for (rfp=&fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
|
||||
if (rfp->fp_pid == PID_FREE)
|
||||
continue;
|
||||
vp= rfp->fp_rd;
|
||||
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
|
||||
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
|
||||
vp->v_ref_check++;
|
||||
|
||||
vp= rfp->fp_wd;
|
||||
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
|
||||
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
|
||||
vp->v_ref_check++;
|
||||
|
||||
REFVP(rfp->fp_rd);
|
||||
REFVP(rfp->fp_wd);
|
||||
}
|
||||
|
||||
/* Count references from filedescriptors */
|
||||
@@ -204,10 +198,7 @@ PUBLIC int check_vrefs()
|
||||
{
|
||||
if (f->filp_count == 0)
|
||||
continue;
|
||||
vp= f->filp_vno;
|
||||
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
|
||||
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
|
||||
vp->v_ref_check++;
|
||||
REFVP(f->filp_vno);
|
||||
}
|
||||
|
||||
/* Count references to mount points */
|
||||
@@ -215,15 +206,9 @@ PUBLIC int check_vrefs()
|
||||
{
|
||||
if (vmp->m_dev == NO_DEV)
|
||||
continue;
|
||||
vp= vmp->m_mounted_on;
|
||||
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
|
||||
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
|
||||
vp->v_ref_check++;
|
||||
|
||||
vp= vmp->m_root_node;
|
||||
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
|
||||
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
|
||||
vp->v_ref_check++;
|
||||
REFVP(vmp->m_root_node);
|
||||
if(vmp->m_mounted_on)
|
||||
REFVP(vmp->m_mounted_on);
|
||||
}
|
||||
|
||||
/* Check references */
|
||||
|
||||
Reference in New Issue
Block a user