minix/servers/vm/fork.c
Ben Gras 9cb6f376ed vm: new secondary cache code
Primary purpose of change: to support the mmap implementation, VM must
know both (a) about some block metadata for FS cache blocks, i.e. inode
numbers and inode offsets where applicable; and (b) know about *all*
cache blocks, i.e.  also of the FS primary caches and not just the
blocks that spill into the secondary one. This changes the interface and
VM data structures.

This change is only for the interface (libminixfs) and VM data
structures; the filesystem code is unmodified, so although the secondary
cache will be used as normal, blocks will not be annotated with inode
information until the FS is modified to provide this information. Until
it is modified, mmap of files will fail gracefully on such filesystems.

This is indicated to VFS/VM by returning ENOSYS for REQ_PEEK.

Change-Id: I1d2df6c485e6c5e89eb28d9055076cc02629594e
2013-03-21 23:07:08 +00:00

119 lines
2.8 KiB
C

#define _SYSTEM 1
#include <minix/callnr.h>
#include <minix/com.h>
#include <minix/config.h>
#include <minix/const.h>
#include <minix/ds.h>
#include <minix/endpoint.h>
#include <minix/keymap.h>
#include <minix/minlib.h>
#include <minix/type.h>
#include <minix/ipc.h>
#include <minix/sysutil.h>
#include <minix/syslib.h>
#include <minix/debug.h>
#include <minix/bitmap.h>
#include <string.h>
#include <errno.h>
#include <env.h>
#include <assert.h>
#include "glo.h"
#include "vm.h"
#include "proto.h"
#include "util.h"
#include "sanitycheck.h"
#include "region.h"
/*===========================================================================*
* do_fork *
*===========================================================================*/
int do_fork(message *msg)
{
int r, proc, childproc;
struct vmproc *vmp, *vmc;
pt_t origpt;
vir_bytes msgaddr;
SANITYCHECK(SCL_FUNCTIONS);
if(vm_isokendpt(msg->VMF_ENDPOINT, &proc) != OK) {
printf("VM: bogus endpoint VM_FORK %d\n", msg->VMF_ENDPOINT);
SANITYCHECK(SCL_FUNCTIONS);
return EINVAL;
}
childproc = msg->VMF_SLOTNO;
if(childproc < 0 || childproc >= NR_PROCS) {
printf("VM: bogus slotno VM_FORK %d\n", msg->VMF_SLOTNO);
SANITYCHECK(SCL_FUNCTIONS);
return EINVAL;
}
vmp = &vmproc[proc]; /* parent */
vmc = &vmproc[childproc]; /* child */
assert(vmc->vm_slot == childproc);
/* The child is basically a copy of the parent. */
origpt = vmc->vm_pt;
*vmc = *vmp;
vmc->vm_slot = childproc;
region_init(&vmc->vm_regions_avl);
vmc->vm_endpoint = NONE; /* In case someone tries to use it. */
vmc->vm_pt = origpt;
#if VMSTATS
vmc->vm_bytecopies = 0;
#endif
if(pt_new(&vmc->vm_pt) != OK) {
return ENOMEM;
}
SANITYCHECK(SCL_DETAIL);
if(map_proc_copy(vmc, vmp) != OK) {
printf("VM: fork: map_proc_copy failed\n");
pt_free(&vmc->vm_pt);
return(ENOMEM);
}
/* Only inherit these flags. */
vmc->vm_flags &= VMF_INUSE;
/* inherit the priv call bitmaps */
memcpy(&vmc->vm_call_mask, &vmp->vm_call_mask, sizeof(vmc->vm_call_mask));
/* Tell kernel about the (now successful) FORK. */
if((r=sys_fork(vmp->vm_endpoint, childproc,
&vmc->vm_endpoint, PFF_VMINHIBIT, &msgaddr)) != OK) {
panic("do_fork can't sys_fork: %d", r);
}
if((r=pt_bind(&vmc->vm_pt, vmc)) != OK)
panic("fork can't pt_bind: %d", r);
{
vir_bytes vir;
/* making these messages writable is an optimisation
* and its return value needn't be checked.
*/
vir = msgaddr;
if (handle_memory(vmc, vir, sizeof(message), 1, NULL, 0, 0) != OK)
panic("do_fork: handle_memory for child failed\n");
vir = msgaddr;
if (handle_memory(vmp, vir, sizeof(message), 1, NULL, 0, 0) != OK)
panic("do_fork: handle_memory for parent failed\n");
}
/* Inform caller of new child endpoint. */
msg->VMF_CHILD_ENDPOINT = vmc->vm_endpoint;
SANITYCHECK(SCL_FUNCTIONS);
return OK;
}