. 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:
Ben Gras 2009-01-26 17:43:59 +00:00
parent 4984a86f32
commit 3cc092ff06
38 changed files with 243 additions and 531 deletions

View file

@ -204,15 +204,6 @@ struct driver *dp; /* Device dependent entry points. */
reply_mess.DEV_MINOR = mess.DEVICE; reply_mess.DEV_MINOR = mess.DEVICE;
reply_mess.DEV_SEL_OPS = r; reply_mess.DEV_SEL_OPS = r;
} }
else if (mess.m_type == DIAGNOSTICS_S)
{
#if 0
if (device_caller == FS_PROC_NR)
printf("driver_task: sending DIAG_REPL to FS\n");
#endif
reply_mess.m_type = DIAG_REPL;
reply_mess.REP_STATUS = r;
}
else else
{ {
#if 0 #if 0

View file

@ -16,7 +16,7 @@ LDFLAGS = -i -L../libdriver_asyn
LIBS = -ldriver -lsys LIBS = -ldriver -lsys
LIB_DEP = ../libdriver_asyn/libdriver.a LIB_DEP = ../libdriver_asyn/libdriver.a
OBJ = log.o diag.o kputc.o OBJ = log.o diag.o
# build local binary # build local binary
all build: $(DRIVER) all build: $(DRIVER)

View file

@ -134,7 +134,7 @@ PUBLIC int do_diagnostics(message *m, int safe)
} }
log_append(diagbuf, i); log_append(diagbuf, i);
if(m->m_type == ASYN_DIAGNOSTICS) return EDONTREPLY; if(m->m_type == ASYN_DIAGNOSTICS_OLD) return EDONTREPLY;
return OK; return OK;
} }

View file

@ -1,34 +0,0 @@
/* A server must occasionally print some message. It uses a simple version of
* printf() found in the system library that calls putk() to output characters.
* The LOG driver cannot use the regular putk(). Hence, it uses a special
* version of putk() that directly sends to the TTY task.
*
* Changes:
* 21 July 2005: Created (Jorrit N. Herder)
*/
#include "log.h"
/*===========================================================================*
* kputc *
*===========================================================================*/
void kputc(c)
int c;
{
/* Accumulate another character. If 0 or buffer full, print it. */
static int buf_count; /* # characters in the buffer */
static char print_buf[80]; /* output is buffered here */
message m;
if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
m.DIAG_BUF_COUNT = buf_count;
m.DIAG_PRINT_BUF_G = print_buf;
m.m_type = DIAGNOSTICS; /* request TTY to output this buffer */
_sendrec(TTY_PROC_NR, &m); /* if it fails, we give up */
buf_count = 0; /* clear buffer for next batch */
}
if (c != 0) {
print_buf[buf_count++] = c;
}
}

View file

@ -397,12 +397,12 @@ int safe;
* understand. * understand.
*/ */
switch(m_ptr->m_type) { switch(m_ptr->m_type) {
case DIAGNOSTICS: { case DIAGNOSTICS_OLD: {
r = do_diagnostics(m_ptr, 0); r = do_diagnostics(m_ptr, 0);
break; break;
} }
case ASYN_DIAGNOSTICS: case ASYN_DIAGNOSTICS_OLD:
case DIAGNOSTICS_S: case DIAGNOSTICS_S_OLD:
r = do_diagnostics(m_ptr, 1); r = do_diagnostics(m_ptr, 1);
break; break;
case DEV_STATUS: { case DEV_STATUS: {

View file

@ -31,7 +31,6 @@ struct logdevice {
}; };
/* Function prototypes. */ /* Function prototypes. */
_PROTOTYPE( void kputc, (int c) );
_PROTOTYPE( int do_new_kmess, (message *m) ); _PROTOTYPE( int do_new_kmess, (message *m) );
_PROTOTYPE( int do_diagnostics, (message *m, int safe) ); _PROTOTYPE( int do_diagnostics, (message *m, int safe) );
_PROTOTYPE( void log_append, (char *buf, int len) ); _PROTOTYPE( void log_append, (char *buf, int len) );

View file

@ -1150,8 +1150,8 @@ int safe;
} }
cons_putk(0); /* always terminate, even with EFAULT */ cons_putk(0); /* always terminate, even with EFAULT */
if(m_ptr->m_type != ASYN_DIAGNOSTICS) { if(m_ptr->m_type != ASYN_DIAGNOSTICS_OLD) {
m_ptr->m_type = DIAG_REPL; m_ptr->m_type = DIAG_REPL_OLD;
m_ptr->REP_STATUS = result; m_ptr->REP_STATUS = result;
send(m_ptr->m_source, m_ptr); send(m_ptr->m_source, m_ptr);
} }

View file

@ -216,7 +216,7 @@ PUBLIC int main(void)
if (sigismember(&sigset, SIGKMESS)) do_new_kmess(&tty_mess); if (sigismember(&sigset, SIGKMESS)) do_new_kmess(&tty_mess);
continue; continue;
} }
case DIAGNOSTICS: /* a server wants to print some */ case DIAGNOSTICS_OLD: /* a server wants to print some */
#if 0 #if 0
if (tty_mess.m_source != LOG_PROC_NR) if (tty_mess.m_source != LOG_PROC_NR)
{ {
@ -225,8 +225,8 @@ PUBLIC int main(void)
#endif #endif
do_diagnostics(&tty_mess, 0); do_diagnostics(&tty_mess, 0);
continue; continue;
case DIAGNOSTICS_S: case DIAGNOSTICS_S_OLD:
case ASYN_DIAGNOSTICS: case ASYN_DIAGNOSTICS_OLD:
do_diagnostics(&tty_mess, 1); do_diagnostics(&tty_mess, 1);
continue; continue;
case GET_KMESS: case GET_KMESS:

View file

@ -16,6 +16,7 @@ driver floppy
SAFECOPYFROM # 31 SAFECOPYFROM # 31
SAFECOPYTO # 32 SAFECOPYTO # 32
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
}; };
@ -31,6 +32,7 @@ driver dp8390
SAFECOPYTO # 32 SAFECOPYTO # 32
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 10ec/8029; pci device 10ec/8029;
uid 0; uid 0;
@ -48,6 +50,7 @@ driver dpeth
SAFECOPYTO # 32 SAFECOPYTO # 32
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };
@ -65,6 +68,7 @@ driver lance
SAFECOPYTO # 32 SAFECOPYTO # 32
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 1022/2000; pci device 1022/2000;
uid 0; uid 0;
@ -85,6 +89,7 @@ driver rtl8139
SETGRANT # 34 SETGRANT # 34
MAPDMA # 41 MAPDMA # 41
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 10ec/8139; pci device 10ec/8139;
ipc ipc
@ -107,6 +112,7 @@ driver fxp
SAFECOPYTO # 32 SAFECOPYTO # 32
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 8086/1229; pci device 8086/1229;
ipc ipc
@ -123,6 +129,7 @@ driver dumpcore
GETINFO # 26 GETINFO # 26
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
}; };
@ -137,6 +144,7 @@ driver inet
VSAFECOPY # 33 VSAFECOPY # 33
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };
@ -151,6 +159,7 @@ driver random
SAFECOPYTO # 32 SAFECOPYTO # 32
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
}; };
@ -166,6 +175,7 @@ driver readclock.drv
SETGRANT # 34 SETGRANT # 34
READBIOS # 35 READBIOS # 35
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };
@ -176,6 +186,7 @@ driver is
GETINFO # 26 GETINFO # 26
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };
@ -193,6 +204,7 @@ driver pci
SAFECOPYTO # 32 SAFECOPYTO # 32
SETGRANT # 34 SETGRANT # 34
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };
@ -222,6 +234,7 @@ driver at_wini
SETGRANT # 34 SETGRANT # 34
READBIOS # 35 READBIOS # 35
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci class pci class
1/1 # Mass storage / IDE 1/1 # Mass storage / IDE
@ -238,6 +251,7 @@ driver mfs
SETGRANT # 34 SETGRANT # 34
UMAP # 14 UMAP # 14
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };
@ -262,6 +276,7 @@ driver printer
SAFECOPYFROM # 31 SAFECOPYFROM # 31
SAFECOPYTO # 32 SAFECOPYTO # 32
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
}; };
@ -283,6 +298,7 @@ driver orinoco
SETGRANT # 34 SETGRANT # 34
VM_MAP # 30 VM_MAP # 30
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 1260/3873; pci device 1260/3873;
uid 0; uid 0;
@ -299,6 +315,7 @@ driver es1370
IRQCTL # 19 IRQCTL # 19
DEVIO # 21 DEVIO # 21
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 1274/5000; pci device 1274/5000;
}; };
@ -314,6 +331,7 @@ driver es1371
IRQCTL # 19 IRQCTL # 19
DEVIO # 21 DEVIO # 21
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
pci device 1274/1371; pci device 1274/1371;
}; };
@ -327,6 +345,7 @@ driver amddev
GETINFO GETINFO
REGDEV # 40 REGDEV # 40
PROFBUF # 38 PROFBUF # 38
SYSCTL
; ;
uid 0; uid 0;
}; };

View file

@ -326,8 +326,9 @@
# define SYS_MAPDMA (KERNEL_CALL + 42) /* sys_mapdma() */ # define SYS_MAPDMA (KERNEL_CALL + 42) /* sys_mapdma() */
# define SYS_VMCTL (KERNEL_CALL + 43) /* sys_vmctl() */ # define SYS_VMCTL (KERNEL_CALL + 43) /* sys_vmctl() */
# define SYS_SYSCTL (KERNEL_CALL + 44) /* sys_sysctl() */
#define NR_SYS_CALLS 44 /* number of system calls */ #define NR_SYS_CALLS 45 /* number of system calls */
/* Pseudo call for use in kernel/table.c. */ /* Pseudo call for use in kernel/table.c. */
#define SYS_ALL_CALLS (NR_SYS_CALLS) #define SYS_ALL_CALLS (NR_SYS_CALLS)
@ -584,6 +585,13 @@
#define SVMCTL_MRG_WRITE m1_i2 /* MEMREQ_GET reply: writeflag */ #define SVMCTL_MRG_WRITE m1_i2 /* MEMREQ_GET reply: writeflag */
#define SVMCTL_MRG_EP m1_i3 /* MEMREQ_GET reply: process */ #define SVMCTL_MRG_EP m1_i3 /* MEMREQ_GET reply: process */
/* Codes and field names for SYS_SYSCTL. */
#define SYSCTL_CODE m1_i1 /* SYSCTL_CODE_* below */
#define SYSCTL_ARG1 m1_p1
#define SYSCTL_ARG2 m1_i2
#define SYSCTL_CODE_DIAG 1 /* Print diagnostics. */
#define DIAG_BUFSIZE (80*25)
/* Values for SVMCTL_PARAM. */ /* Values for SVMCTL_PARAM. */
#define VMCTL_I386_SETCR3 10 #define VMCTL_I386_SETCR3 10
#define VMCTL_GET_PAGEFAULT 11 #define VMCTL_GET_PAGEFAULT 11
@ -654,17 +662,17 @@
# define FKEY_FKEYS m2_l1 /* F1-F12 keys pressed */ # define FKEY_FKEYS m2_l1 /* F1-F12 keys pressed */
# define FKEY_SFKEYS m2_l2 /* Shift-F1-F12 keys pressed */ # define FKEY_SFKEYS m2_l2 /* Shift-F1-F12 keys pressed */
#define DIAG_BASE 0xa00 #define DIAG_BASE 0xa00
#define DIAGNOSTICS (DIAG_BASE+1) /* output a string without FS in between */ #define DIAGNOSTICS_OLD (DIAG_BASE+1) /* output a string without FS in between */
#define DIAGNOSTICS_S (DIAG_BASE+2) /* grant-based version of DIAGNOSTICS */ #define DIAGNOSTICS_S_OLD (DIAG_BASE+2) /* grant-based version of DIAGNOSTICS */
# define DIAG_PRINT_BUF_G m1_p1 # define DIAG_PRINT_BUF_G m1_p1
# define DIAG_BUF_COUNT m1_i1 # define DIAG_BUF_COUNT m1_i1
#define GET_KMESS (DIAG_BASE+3) /* get kmess from TTY */ #define GET_KMESS (DIAG_BASE+3) /* get kmess from TTY */
# define GETKM_PTR m1_p1 # define GETKM_PTR m1_p1
#define GET_KMESS_S (DIAG_BASE+4) /* get kmess from TTY */ #define GET_KMESS_S (DIAG_BASE+4) /* get kmess from TTY */
# define GETKM_GRANT m1_i1 # define GETKM_GRANT m1_i1
#define ASYN_DIAGNOSTICS (DIAG_BASE+5) /* grant-based, replyless DIAGNOSTICS */ #define ASYN_DIAGNOSTICS_OLD (DIAG_BASE+5) /* grant-based, replyless DIAGNOSTICS */
#define DIAG_REPL (DIAG_BASE+0x80+0) /* reply to DIAGNOSTICS(_S) */ #define DIAG_REPL_OLD (DIAG_BASE+0x80+0) /* reply to DIAGNOSTICS(_S) */
#define PM_BASE 0x900 #define PM_BASE 0x900
#define PM_GET_WORK (PM_BASE + 1) /* Get work from PM */ #define PM_GET_WORK (PM_BASE + 1) /* Get work from PM */

View file

@ -60,6 +60,7 @@ _PROTOTYPE( int sys_vmctl_stacktrace, (endpoint_t who));
_PROTOTYPE( int sys_readbios, (phys_bytes address, void *buf, size_t size)); _PROTOTYPE( int sys_readbios, (phys_bytes address, void *buf, size_t size));
_PROTOTYPE( int sys_stime, (time_t boottime)); _PROTOTYPE( int sys_stime, (time_t boottime));
_PROTOTYPE( int sys_sysctl, (int ctl, char *arg1, int arg2));
/* Shorthands for sys_sdevio() system call. */ /* Shorthands for sys_sdevio() system call. */
#define sys_insb(port, proc_nr, buffer, count) \ #define sys_insb(port, proc_nr, buffer, count) \

View file

@ -52,4 +52,7 @@
#define INTS_ORIG 0 /* restore interrupts */ #define INTS_ORIG 0 /* restore interrupts */
#define INTS_MINIX 1 /* initialize interrupts for minix */ #define INTS_MINIX 1 /* initialize interrupts for minix */
/* for kputc() */
#define END_OF_KMESS 0
#endif /* CONST_H */ #endif /* CONST_H */

View file

@ -93,6 +93,9 @@ _PROTOTYPE( void check_runqueues_f, (char *file, int line) );
_PROTOTYPE( int verify_grant, (endpoint_t, endpoint_t, cp_grant_id_t, vir_bytes, _PROTOTYPE( int verify_grant, (endpoint_t, endpoint_t, cp_grant_id_t, vir_bytes,
int, vir_bytes, vir_bytes *, endpoint_t *)); int, vir_bytes, vir_bytes *, endpoint_t *));
/* system/do_sysctl.c */
_PROTOTYPE( int do_sysctl, (message *m));
#if SPROFILE #if SPROFILE
/* profile.c */ /* profile.c */
_PROTOTYPE( void init_profile_clock, (u32_t) ); _PROTOTYPE( void init_profile_clock, (u32_t) );

View file

@ -241,6 +241,7 @@ PRIVATE void initialize(void)
/* System control. */ /* System control. */
map(SYS_ABORT, do_abort); /* abort MINIX */ map(SYS_ABORT, do_abort); /* abort MINIX */
map(SYS_GETINFO, do_getinfo); /* request system information */ map(SYS_GETINFO, do_getinfo); /* request system information */
map(SYS_SYSCTL, do_sysctl); /* misc system manipulation */
/* Profiling. */ /* Profiling. */
map(SYS_SPROF, do_sprofile); /* start/stop statistical profiling */ map(SYS_SPROF, do_sprofile); /* start/stop statistical profiling */

View file

@ -43,6 +43,7 @@ OBJECTS = \
$(SYSTEM)(do_privctl.o) \ $(SYSTEM)(do_privctl.o) \
$(SYSTEM)(do_segctl.o) \ $(SYSTEM)(do_segctl.o) \
$(SYSTEM)(do_safecopy.o) \ $(SYSTEM)(do_safecopy.o) \
$(SYSTEM)(do_sysctl.o) \
$(SYSTEM)(do_getksig.o) \ $(SYSTEM)(do_getksig.o) \
$(SYSTEM)(do_endksig.o) \ $(SYSTEM)(do_endksig.o) \
$(SYSTEM)(do_kill.o) \ $(SYSTEM)(do_kill.o) \
@ -151,6 +152,9 @@ $(SYSTEM)(do_privctl.o): do_privctl.c
$(SYSTEM)(do_safecopy.o): do_safecopy.c $(SYSTEM)(do_safecopy.o): do_safecopy.c
$(CC) do_safecopy.c $(CC) do_safecopy.c
$(SYSTEM)(do_sysctl.o): do_sysctl.c
$(CC) do_sysctl.c
$(SYSTEM)(do_segctl.o): do_segctl.c $(SYSTEM)(do_segctl.o): do_segctl.c
$(CC) do_segctl.c $(CC) do_segctl.c

58
kernel/system/do_sysctl.c Normal file
View file

@ -0,0 +1,58 @@
/* The kernel call implemented in this file:
* m_type: SYS_SYSCTL
*
* The parameters for this kernel call are:
* SYSCTL_CODE request
* and then request-specific arguments in SYSCTL_ARG1 and SYSCTL_ARG2.
*/
#include "../system.h"
#include "../vm.h"
/*===========================================================================*
* do_sysctl *
*===========================================================================*/
PUBLIC int do_sysctl(m_ptr)
register message *m_ptr; /* pointer to request message */
{
phys_bytes ph;
vir_bytes len, buf;
static char mybuf[DIAG_BUFSIZE];
struct proc *caller;
int s, i;
caller = proc_addr(who_p);
switch (m_ptr->SYSCTL_CODE) {
case SYSCTL_CODE_DIAG:
buf = (vir_bytes) m_ptr->SYSCTL_ARG1;
len = (vir_bytes) m_ptr->SYSCTL_ARG2;
if(len < 1 || len > DIAG_BUFSIZE) {
kprintf("do_sysctl: diag for %d: len %d out of range\n",
caller->p_endpoint, len);
return EINVAL;
}
if((ph=umap_local(caller, D, buf, len)) == 0)
return EFAULT;
CHECKRANGE_OR_SUSPEND(caller, ph, len, 1);
if((s=data_copy(who_e, buf, SYSTEM, (vir_bytes) mybuf, len)) != OK) {
kprintf("do_sysctl: diag for %d: len %d: copy failed: %d\n",
caller->p_endpoint, len, s);
return s;
}
for(i = 0; i < len; i++)
kputc(mybuf[i]);
kputc(END_OF_KMESS);
return OK;
break;
default:
kprintf("do_sysctl: invalid request %d\n", m_ptr->SYSCTL_CODE);
return(EINVAL);
}
minix_panic("do_sysctl: can't happen", NO_NUM);
return(OK);
}

View file

@ -83,9 +83,9 @@ PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)];
*/ */
#define FS_C SYS_KILL, SYS_VIRCOPY, SYS_SAFECOPYFROM, SYS_SAFECOPYTO, \ #define FS_C SYS_KILL, SYS_VIRCOPY, SYS_SAFECOPYFROM, SYS_SAFECOPYTO, \
SYS_VIRVCOPY, SYS_UMAP, SYS_GETINFO, SYS_EXIT, SYS_TIMES, SYS_SETALARM, \ SYS_VIRVCOPY, SYS_UMAP, SYS_GETINFO, SYS_EXIT, SYS_TIMES, SYS_SETALARM, \
SYS_PRIVCTL, SYS_TRACE , SYS_SETGRANT, SYS_PROFBUF SYS_PRIVCTL, SYS_TRACE , SYS_SETGRANT, SYS_PROFBUF, SYS_SYSCTL
#define DRV_C FS_C, SYS_SEGCTL, SYS_IRQCTL, SYS_INT86, SYS_DEVIO, \ #define DRV_C FS_C, SYS_SEGCTL, SYS_IRQCTL, SYS_INT86, SYS_DEVIO, \
SYS_SDEVIO, SYS_VDEVIO, SYS_SETGRANT, SYS_PROFBUF SYS_SDEVIO, SYS_VDEVIO, SYS_SETGRANT, SYS_PROFBUF, SYS_SYSCTL
PRIVATE int PRIVATE int
fs_c[] = { FS_C }, fs_c[] = { FS_C },

View file

@ -59,8 +59,6 @@ int nr;
#define printf kprintf #define printf kprintf
#include "../lib/sysutil/kprintf.c" #include "../lib/sysutil/kprintf.c"
#define END_OF_KMESS 0
/*===========================================================================* /*===========================================================================*
* kputc * * kputc *
*===========================================================================*/ *===========================================================================*/

View file

@ -47,6 +47,7 @@ libsys_FILES=" \
sys_physcopy.c \ sys_physcopy.c \
sys_readbios.c \ sys_readbios.c \
sys_safecopy.c \ sys_safecopy.c \
sys_sysctl.c \
sys_vsafecopy.c \ sys_vsafecopy.c \
sys_profbuf.c \ sys_profbuf.c \
sys_sdevio.c \ sys_sdevio.c \

14
lib/syslib/sys_sysctl.c Normal file
View file

@ -0,0 +1,14 @@
#include "syslib.h"
PUBLIC int sys_sysctl(int code, char *arg1, int arg2)
{
message m;
m.SYSCTL_CODE = code;
m.SYSCTL_ARG1 = arg1;
m.SYSCTL_ARG2 = arg2;
return(_taskcall(SYSTASK, SYS_SYSCTL, &m));
}

View file

@ -9,9 +9,7 @@
#include "sysutil.h" #include "sysutil.h"
static char print_buf[80*25]; /* output is buffered here */ static char print_buf[DIAG_BUFSIZE]; /* output is buffered here */
int kputc_use_private_grants= 0;
/*===========================================================================* /*===========================================================================*
* kputc * * kputc *
@ -24,62 +22,8 @@ int c;
message m; message m;
if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) { if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
#define PRINTPROCS (sizeof(procs)/sizeof(procs[0])) sys_sysctl(SYSCTL_CODE_DIAG, print_buf, buf_count);
int procs[] = OUTPUT_PROCS_ARRAY;
static int firstprint = 1;
static cp_grant_id_t printgrants[PRINTPROCS];
int p;
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);
}
}
for(p = 0; procs[p] != NONE; p++) {
/* Send the buffer to this output driver. */
int may_asyn = 0;
m.DIAG_BUF_COUNT = buf_count;
if(GRANT_VALID(printgrants[p])) {
m.m_type = DIAGNOSTICS_S;
m.DIAG_PRINT_BUF_G = (char *) printgrants[p];
may_asyn = 1;
} else {
m.m_type = DIAGNOSTICS;
m.DIAG_PRINT_BUF_G = print_buf;
}
if(may_asyn && procs[p] == LOG_PROC_NR) {
m.m_type = ASYN_DIAGNOSTICS;
(void) asynsend(procs[p], &m);
} else {
sendrec(procs[p], &m);
}
}
buf_count = 0; buf_count = 0;
/* If the output fails, e.g., due to an ELOCKED, do not retry output
* at the FS as if this were a normal user-land printf(). This may
* result in even worse problems.
*/
} }
if (c != 0) { if (c != 0) {

View file

@ -48,16 +48,20 @@ PUBLIC int fs_putnode()
fs_m_in.REQ_INODE_INDEX < NR_INODES && fs_m_in.REQ_INODE_INDEX < NR_INODES &&
inode[fs_m_in.REQ_INODE_INDEX].i_num == fs_m_in.REQ_INODE_NR) { inode[fs_m_in.REQ_INODE_INDEX].i_num == fs_m_in.REQ_INODE_NR) {
rip = &inode[fs_m_in.REQ_INODE_INDEX]; rip = &inode[fs_m_in.REQ_INODE_INDEX];
if(!rip) {
panic(__FILE__, "null rip", NO_NUM);
}
} }
/* Otherwise find it */ /* Otherwise find it */
else { 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) 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); panic(__FILE__, "fs_putnode failed", NO_NUM);
} }

View file

@ -18,7 +18,7 @@ LDFLAGS = -i
OBJ = main.o forkexit.o break.o exec.o time.o timers.o \ 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 \ 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 # build local binary
all build: $(SERVER) all build: $(SERVER)

View file

@ -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);
}

View file

@ -121,10 +121,6 @@ PUBLIC int main()
case GETPUID: case GETPUID:
result= do_getpuid(); result= do_getpuid();
break; break;
case DIAG_REPL :
diag_repl();
result= SUSPEND;
break;
default: default:
/* Else, if the system call number is valid, perform the /* Else, if the system call number is valid, perform the
* call. * call.

View file

@ -69,7 +69,7 @@ PUBLIC int do_allocmem()
{ {
int r; int r;
phys_bytes retmembase; phys_bytes retmembase;
r = vm_allocmem(m_in.memsize, &retmembase); r = vm_allocmem(m_in.memsize, (phys_clicks *) &retmembase);
if(r == OK) if(r == OK)
mp->mp_reply.membase = retmembase; mp->mp_reply.membase = retmembase;
return r; return r;

View file

@ -1024,10 +1024,6 @@ struct rproc *rp;
case 0: case 0:
execle(rp->r_script, rp->r_script, rp->r_label, reason, execle(rp->r_script, rp->r_script, rp->r_label, reason,
incarnation_str, NULL, NULL); incarnation_str, NULL, NULL);
{
extern int kputc_use_private_grants;
kputc_use_private_grants= 1;
}
printf("RS: run_script: execl '%s' failed: %s\n", printf("RS: run_script: execl '%s' failed: %s\n",
rp->r_script, strerror(errno)); rp->r_script, strerror(errno));
exit(1); exit(1);

View file

@ -692,6 +692,7 @@ struct
{ "MAPDMA", SYS_MAPDMA }, { "MAPDMA", SYS_MAPDMA },
{ "VMCTL", SYS_VMCTL }, { "VMCTL", SYS_VMCTL },
{ "PROFBUF", SYS_PROFBUF }, { "PROFBUF", SYS_PROFBUF },
{ "SYSCTL", SYS_SYSCTL },
{ NULL, 0 } { NULL, 0 }
}; };

View file

@ -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 \ path.o device.o mount.o link.o exec.o \
filedes.o stadir.o protect.o time.o \ filedes.o stadir.o protect.o time.o \
lock.o misc.o utility.o select.o timers.o table.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 # build local binary
install all build: $(SERVER) install all build: $(SERVER)

View file

@ -891,8 +891,6 @@ PUBLIC void dev_up(int maj)
printf( printf(
"VFSdev_up: error sending new driver endpoint. FS_e: %d req_nr: %d\n", "VFSdev_up: error sending new driver endpoint. FS_e: %d req_nr: %d\n",
vmp->m_fs_e, REQ_NEW_DRIVER); 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 /* Look for processes that are suspened in an OPEN call. Set SUSP_REOPEN

View file

@ -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);
}

View file

@ -64,10 +64,6 @@ PUBLIC int main()
if (who_e == PM_PROC_NR && call_nr != PROC_EVENT) if (who_e == PM_PROC_NR && call_nr != PROC_EVENT)
printf("FS: strange, got message %d from PM\n", call_nr); 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) if (call_nr == DEV_REVIVE)
{ {
endpoint_t endpt; endpoint_t endpt;
@ -105,11 +101,6 @@ PUBLIC int main()
select_reply2(); select_reply2();
continue; continue;
} }
if (call_nr == DIAG_REPL)
{
diag_repl();
continue;
}
/* Check for special control messages first. */ /* Check for special control messages first. */
if ((call_nr & NOTIFY_MESSAGE)) { if ((call_nr & NOTIFY_MESSAGE)) {
@ -477,16 +468,14 @@ PRIVATE void init_root()
/* Fill in max file size and blocksize for the vmnt */ /* Fill in max file size and blocksize for the vmnt */
vmp->m_fs_e = resX.fs_e; vmp->m_fs_e = resX.fs_e;
vmp->m_dev = root_dev; vmp->m_dev = root_dev;
vmp->m_driver_e = dp->dmap_driver;
vmp->m_flags = 0; vmp->m_flags = 0;
/* Root node is indeed on the partition */ /* Root node is indeed on the partition */
root_node->v_vmnt = vmp; root_node->v_vmnt = vmp;
root_node->v_dev = vmp->m_dev; root_node->v_dev = vmp->m_dev;
/* Root directory is mounted on itself */ /* Root directory is not mounted on a vnode. */
vmp->m_mounted_on = root_node; vmp->m_mounted_on = NULL;
root_node->v_ref_count++;
vmp->m_root_node = root_node; vmp->m_root_node = root_node;
} }

View file

@ -305,26 +305,24 @@ PUBLIC void pm_reboot()
{ {
/* Perform the FS side of the reboot call. */ /* Perform the FS side of the reboot call. */
int i; int i;
struct vnode vdummy;
struct vmnt *vmp; struct vmnt *vmp;
do_sync();
CHECK_VREFS;
/* Do exit processing for all leftover processes and servers, /* Do exit processing for all leftover processes and servers,
* but don't actually exit them (if they were really gone, PM * but don't actually exit them (if they were really gone, PM
* will tell us about it). * will tell us about it).
*/ */
for (i = 0; i < NR_PROCS; i++) for (i = 0; i < NR_PROCS; i++)
if((m_in.endpt1 = fproc[i].fp_endpoint) != NONE) 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 /* 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. * 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, /* 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. * 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++) { for (i= 0; i < NR_SUPERS; i++) {
/* Unmount at least one. */ /* Unmount at least one. */
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { 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;
} }
/*===========================================================================* /*===========================================================================*

View file

@ -103,7 +103,7 @@ PRIVATE int mount_fs(endpoint_t fs_e)
dev_t dev; dev_t dev;
message m; message m;
struct vnode *vp, *root_node, *mounted_on, *bspec; struct vnode *vp, *root_node, *mounted_on, *bspec;
struct vmnt *vmp, *vmp2; struct vmnt *vmp;
char *label; char *label;
struct node_details res; struct node_details res;
@ -168,8 +168,7 @@ PRIVATE int mount_fs(endpoint_t fs_e)
if (found) { if (found) {
/* It is possible that we have an old root lying around that /* It is possible that we have an old root lying around that
* needs to be remounted. */ * needs to be remounted. */
if (vmp->m_mounted_on != vmp->m_root_node || if (vmp->m_mounted_on || vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
/* Normally, m_mounted_on refers to the mount point. For a /* Normally, m_mounted_on refers to the mount point. For a
* root filesystem, m_mounted_on is equal to the root vnode. * root filesystem, m_mounted_on is equal to the root vnode.
* We assume that the root of FS is always the real root. If * 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 */ return EBUSY; /* already mounted */
} }
if(vmp->m_mounted_on)
panic("vfs", "root unexpectedly mounted somewhere", NO_NUM);
if (root_dev == vmp->m_dev) if (root_dev == vmp->m_dev)
panic("fs", "inconsistency remounting old root", NO_NUM); 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. */ /* Nothing else can go wrong. Perform the mount. */
put_vnode(vmp->m_mounted_on);
vmp->m_mounted_on = mounted_on; vmp->m_mounted_on = mounted_on;
vmp->m_flags = m_in.rd_only; vmp->m_flags = m_in.rd_only;
allow_newroot = 0; /* The root is now fixed */ 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_fs_e = res.fs_e;
vmp->m_dev = dev; vmp->m_dev = dev;
vmp->m_flags = m_in.rd_only; vmp->m_flags = m_in.rd_only;
vmp->m_driver_e = dp->dmap_driver;
/* Root node is indeed on the partition */ /* Root node is indeed on the partition */
root_node->v_vmnt = vmp; root_node->v_vmnt = vmp;
@ -318,8 +318,7 @@ PRIVATE int mount_fs(endpoint_t fs_e)
/* Superblock and root node already read. /* Superblock and root node already read.
* Nothing else can go wrong. Perform the mount. */ * Nothing else can go wrong. Perform the mount. */
vmp->m_root_node = root_node; vmp->m_root_node = root_node;
root_node->v_ref_count++; vmp->m_mounted_on = NULL;
vmp->m_mounted_on = root_node;
root_dev = dev; root_dev = dev;
ROOT_FS_E = fs_e; ROOT_FS_E = fs_e;
@ -388,13 +387,17 @@ PUBLIC int do_umount()
{ {
/* Perform the umount(name) system call. */ /* Perform the umount(name) system call. */
dev_t dev; dev_t dev;
CHECK_VREFS;
/* Only the super-user may do UMOUNT. */ /* Only the super-user may do UMOUNT. */
if (!super_user) return(EPERM); if (!super_user) return(EPERM);
CHECK_VREFS;
/* If 'name' is not for a block special file, return error. */ /* 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); 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); if ( (dev = name_to_dev()) == NO_DEV) return(err_code);
CHECK_VREFS;
return(unmount(dev)); return(unmount(dev));
} }
@ -406,7 +409,7 @@ PUBLIC int do_umount()
PUBLIC int unmount(dev) PUBLIC int unmount(dev)
Dev_t dev; Dev_t dev;
{ {
struct vnode *vp; struct vnode *vp, *vi;
struct vmnt *vmp_i = NULL, *vmp = NULL; struct vmnt *vmp_i = NULL, *vmp = NULL;
struct dmap *dp; struct dmap *dp;
int count, r; int count, r;
@ -436,8 +439,8 @@ Dev_t dev;
#if 1 #if 1
int i; int i;
struct fproc *tfp; struct fproc *tfp;
printf("unmount: vnode %d in use %d times\n", printf("unmount: vnode 0x%x/%d in use %d times\n",
vp->v_inode_nr, vp->v_ref_count); dev, vp->v_inode_nr, vp->v_ref_count);
for (i= 0, tfp= fproc; i<NR_PROCS; i++, tfp++) { for (i= 0, tfp= fproc; i<NR_PROCS; i++, tfp++) {
int n; int n;
if (tfp->fp_pid == PID_FREE) if (tfp->fp_pid == PID_FREE)
@ -454,22 +457,57 @@ Dev_t dev;
vp->v_inode_nr, n, tfp->fp_pid); 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 #endif
count += vp->v_ref_count; count += vp->v_ref_count;
} }
} }
CHECK_VREFS;
if (count > 1) { if (count > 1) {
return(EBUSY); /* can't umount a busy file system */ return(EBUSY); /* can't umount a busy file system */
} }
CHECK_VREFS;
vnode_clean_refs(vmp->m_root_node); 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 */ /* 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); 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? */ /* Is there a block special file that was handled by that partition? */
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; vp++) { 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; CHECK_VREFS;
return(OK); return(OK);

View file

@ -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( struct vnode *get_vnode_x, (int fs_e, int inode_nr) );
_PROTOTYPE( void mark_vn, (struct vnode *vp, char *file, int line) ); _PROTOTYPE( void mark_vn, (struct vnode *vp, char *file, int line) );
#endif #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) ); _PROTOTYPE( int check_vrefs, (void) );
/* write.c */ /* write.c */

View file

@ -577,6 +577,7 @@ endpoint_t driver_e;
/* Issue request */ /* Issue request */
if ((r = sendrec(fs_e, &m)) != OK) { if ((r = sendrec(fs_e, &m)) != OK) {
printf("VFSreq_newdriver: error sending message to %d: %d\n", fs_e, r); printf("VFSreq_newdriver: error sending message to %d: %d\n", fs_e, r);
util_stacktrace();
return r; return r;
} }
@ -1019,11 +1020,8 @@ PRIVATE int fs_sendrec_f(char *file, int line, endpoint_t fs_e, message *reqm)
message origm, m; message origm, m;
struct vmnt *vmp; struct vmnt *vmp;
if (fs_e == PM_PROC_NR) if(fs_e <= 0 || fs_e == NONE)
{ panic(__FILE__, "talking to bogus endpoint", fs_e);
printf("from %s, %d\n", file, line);
panic(__FILE__, "talking to PM", NO_NUM);
}
/* Make a copy of the request so that we can load it back in /* Make a copy of the request so that we can load it back in
* case of a dead driver */ * 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))) { 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", 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); file, line, fs_e, reqm->m_type, r);
util_stacktrace();
return r; 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 */ /* Find old driver by endpoint */
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) { for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
if (vmp->m_fs_e == fs_e) { /* found FS */ if (vmp->m_fs_e == fs_e) { /* found FS */
#if 0
old_driver_e = vmp->m_driver_e; old_driver_e = vmp->m_driver_e;
#endif
dmap_unmap_by_endpt(old_driver_e); /* unmap driver */ dmap_unmap_by_endpt(old_driver_e); /* unmap driver */
break; break;
} }

View file

@ -3,7 +3,6 @@
EXTERN struct vmnt { EXTERN struct vmnt {
int m_fs_e; /* FS process' kernel endpoint */ int m_fs_e; /* FS process' kernel endpoint */
dev_t m_dev; /* device number */ dev_t m_dev; /* device number */
int m_driver_e; /* device driver process' kernel endpoint */
int m_flags; /* mount flags */ int m_flags; /* mount flags */
struct vnode *m_mounted_on; /* the vnode on which the partition is mounted */ struct vnode *m_mounted_on; /* the vnode on which the partition is mounted */
struct vnode *m_root_node; /* root vnode */ struct vnode *m_root_node; /* root vnode */

View file

@ -19,6 +19,20 @@
#include <minix/vfsif.h> #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 * * 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 /* dup_vnode() is called to increment the vnode and therefore the
* referred inode's counter. * referred inode's counter.
*/ */
if (vp == NIL_VNODE) { ASSERTVP(vp);
printf("VFSdup_vnode NIL_VNODE\n");
return;
}
vp->v_ref_count++; 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 /* Decrease vnode's usage counter and decrease inode's usage counter in the
* corresponding FS process. * corresponding FS process.
*/ */
if (vp == NIL_VNODE) { ASSERTVP(vp);
/*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);
}
if (vp->v_ref_count > 1) if (vp->v_ref_count > 1)
{ {
@ -167,6 +167,8 @@ int line;
} }
#endif #endif
#define REFVP(v) { vp = (v); CHECKVN(v); vp->v_ref_check++; }
/*===========================================================================* /*===========================================================================*
* check_vrefs * * check_vrefs *
*===========================================================================*/ *===========================================================================*/
@ -187,16 +189,8 @@ PUBLIC int check_vrefs()
for (rfp=&fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) { for (rfp=&fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
if (rfp->fp_pid == PID_FREE) if (rfp->fp_pid == PID_FREE)
continue; continue;
vp= rfp->fp_rd; REFVP(rfp->fp_rd);
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES]) REFVP(rfp->fp_wd);
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++;
} }
/* Count references from filedescriptors */ /* Count references from filedescriptors */
@ -204,10 +198,7 @@ PUBLIC int check_vrefs()
{ {
if (f->filp_count == 0) if (f->filp_count == 0)
continue; continue;
vp= f->filp_vno; REFVP(f->filp_vno);
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
vp->v_ref_check++;
} }
/* Count references to mount points */ /* Count references to mount points */
@ -215,15 +206,9 @@ PUBLIC int check_vrefs()
{ {
if (vmp->m_dev == NO_DEV) if (vmp->m_dev == NO_DEV)
continue; continue;
vp= vmp->m_mounted_on; REFVP(vmp->m_root_node);
if (vp < &vnode[0] || vp >= &vnode[NR_VNODES]) if(vmp->m_mounted_on)
panic(__FILE__, "check_vrefs: bad vnode", NO_NUM); REFVP(vmp->m_mounted_on);
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++;
} }
/* Check references */ /* Check references */