minix/servers/vfs/request.c

1214 lines
30 KiB
C
Raw Normal View History

/* This file contains the wrapper functions for issuing a request
2007-08-07 14:52:47 +02:00
* and receiving response from FS processes.
* Each function builds a request message according to the request
* parameter, calls the most low-level fs_sendrec, and copies
2007-08-07 14:52:47 +02:00
* back the response.
*/
#include "fs.h"
#include <minix/com.h>
#include <minix/const.h>
#include <minix/endpoint.h>
#include <minix/u64.h>
#include <minix/vfsif.h>
#include <sys/dirent.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <assert.h>
#include <stddef.h>
#include <string.h>
2007-08-07 14:52:47 +02:00
#include <unistd.h>
#include <time.h>
#include "path.h"
2007-08-07 14:52:47 +02:00
#include "vmnt.h"
#include "vnode.h"
/*===========================================================================*
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
* req_breadwrite_actual *
*===========================================================================*/
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
static int req_breadwrite_actual(endpoint_t fs_e, endpoint_t user_e, dev_t dev, off_t pos,
unsigned int num_of_bytes, vir_bytes user_addr, int rw_flag,
off_t *new_pos, unsigned int *cum_iop, int cpflag)
{
int r;
cp_grant_id_t grant_id;
message m;
grant_id = cpf_grant_magic(fs_e, user_e, user_addr, num_of_bytes,
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
(rw_flag == READING ? CPF_WRITE : CPF_READ) | cpflag);
if(grant_id == -1)
panic("req_breadwrite: cpf_grant_magic failed");
2007-08-07 14:52:47 +02:00
/* Fill in request message */
m.m_type = rw_flag == READING ? REQ_BREAD : REQ_BWRITE;
m.REQ_DEV = dev;
m.REQ_GRANT = grant_id;
m.REQ_SEEK_POS = pos;
m.REQ_NBYTES = num_of_bytes;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r != OK) return(r);
2007-08-07 14:52:47 +02:00
/* Fill in response structure */
*new_pos = m.RES_SEEK_POS;
*cum_iop = m.RES_NBYTES;
2007-08-07 14:52:47 +02:00
return(OK);
}
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
int req_breadwrite(endpoint_t fs_e, endpoint_t user_e, dev_t dev, off_t pos,
unsigned int num_of_bytes, vir_bytes user_addr, int rw_flag,
off_t *new_pos, unsigned int *cum_iop)
{
int r;
r = req_breadwrite_actual(fs_e, user_e, dev, pos, num_of_bytes,
user_addr, rw_flag, new_pos, cum_iop, CPF_TRY);
if(r == EFAULT) {
if((r=vm_vfs_procctl_handlemem(user_e, user_addr, num_of_bytes,
rw_flag == READING)) != OK) {
return r;
}
r = req_breadwrite_actual(fs_e, user_e, dev, pos, num_of_bytes,
user_addr, rw_flag, new_pos, cum_iop, 0);
}
return r;
}
/*===========================================================================*
* req_bpeek *
*===========================================================================*/
int req_bpeek(endpoint_t fs_e, dev_t dev, off_t pos, unsigned int num_of_bytes)
{
message m;
memset(&m, 0, sizeof(m));
/* Fill in request message */
m.m_type = REQ_BPEEK;
m.REQ_DEV = dev;
m.REQ_SEEK_POS = pos;
m.REQ_NBYTES = num_of_bytes;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_chmod *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_chmod(
endpoint_t fs_e,
ino_t inode_nr,
mode_t rmode,
mode_t *new_modep
)
{
message m;
int r;
/* Fill in request message */
m.m_type = REQ_CHMOD;
m.m_vfs_fs_chmod.inode = inode_nr;
m.m_vfs_fs_chmod.mode = rmode;
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
2012-02-13 16:28:04 +01:00
/* Copy back actual mode. */
*new_modep = m.m_fs_vfs_chmod.mode;
Mostly bugfixes of bugs triggered by the test set. bugfixes: SYSTEM: . removed rc->p_priv->s_flags = 0; for the priv struct shared by all user processes in get_priv(). this should only be done once. doing a SYS_PRIV_USER in sys_privctl() caused the flags of all user processes to be reset, so they were no longer PREEMPTIBLE. this happened when RS executed a policy script. (this broke test1 in the test set) VFS/MFS: . chown can change the mode of a file, and chmod arguments are only part of the full file mode so the full filemode is slightly magic. changed these calls so that the final modes are returned to VFS, so that the vnode can be kept up-to-date. (this broke test11 in the test set) MFS: . lookup() checked for sizeof(string) instead of sizeof(user_path), truncating long path names (caught by test 23) . truncate functions neglected to update ctime (this broke test16) VFS: . corner case of an empty filename lookup caused fields of a request not to be filled in in the lookup functions, not making it clear that the lookup had failed, causing messages to garbage processes, causing strange failures. (caught by test 30) . trust v_size in vnode when doing reads or writes on non-special files, truncating i/o where necessary; this is necessary for pipes, as MFS can't tell when a pipe has been truncated without it being told explicitly each time. when the last reader/writer on a pipe closes, tell FS about the new size using truncate_vn(). (this broke test 25, among others) . permission check for chdir() had disappeared; added a forbidden() call (caught by test 23) new code, shouldn't change anything: . introduced RTS_SET, RTS_UNSET, and RTS_ISSET macro's, and their LOCK variants. These macros set and clear the p_rts_flags field, causing a lot of duplicated logic like old_flags = rp->p_rts_flags; /* save value of the flags */ rp->p_rts_flags &= ~NO_PRIV; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); to change into the simpler RTS_LOCK_UNSET(rp, NO_PRIV); so the macros take care of calling dequeue() and enqueue() (or lock_*()), as the case may be). This makes the code a bit more readable and a bit less fragile. . removed return code from do_clocktick in CLOCK as it currently never replies . removed some debug code from VFS . fixed grant debug message in device.c preemptive checks, tests, changes: . added return code checks of receive() to SYSTEM and CLOCK . O_TRUNC should never arrive at MFS (added sanity check and removed O_TRUNC code) . user_path declared with PATH_MAX+1 to let it be null-terminated . checks in MFS to see if strings passed by VFS are null-terminated IS: . static irq name table thrown out
2007-02-01 18:50:02 +01:00
return(r);
}
/*===========================================================================*
* req_chown *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_chown(
endpoint_t fs_e,
ino_t inode_nr,
uid_t newuid,
gid_t newgid,
mode_t *new_modep
)
{
message m;
int r;
/* Fill in request message */
m.m_type = REQ_CHOWN;
m.REQ_INODE_NR = (pino_t) inode_nr;
m.REQ_UID = (puid_t) newuid;
m.REQ_GID = (pgid_t) newgid;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
/* Return new mode to caller. */
*new_modep = (mode_t) m.RES_MODE;
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_create *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_create(
endpoint_t fs_e,
ino_t inode_nr,
int omode,
uid_t uid,
gid_t gid,
char *path,
node_details_t *res
)
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
struct vmnt *vmp;
vmp = find_vmnt(fs_e);
len = strlen(path) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) path, len, CPF_READ);
if (grant_id == -1)
panic("req_create: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_CREATE;
m.m_vfs_fs_create.inode = inode_nr;
m.m_vfs_fs_create.mode = omode;
m.m_vfs_fs_create.uid = uid;
m.m_vfs_fs_create.gid = gid;
m.m_vfs_fs_create.grant = grant_id;
m.m_vfs_fs_create.path_len = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r != OK) return(r);
/* Fill in response structure */
res->fs_e = m.m_source;
res->inode_nr = m.m_fs_vfs_create.inode;
res->fmode = m.m_fs_vfs_create.mode;
res->fsize = m.m_fs_vfs_create.file_size;
res->uid = m.m_fs_vfs_create.uid;
res->gid = m.m_fs_vfs_create.gid;
res->dev = NO_DEV;
2012-02-13 16:28:04 +01:00
return(OK);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_flush *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_flush(endpoint_t fs_e, dev_t dev)
{
message m;
/* Fill in request message */
m.m_type = REQ_FLUSH;
m.m_vfs_fs_flush.device = dev;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
* req_statvfs *
*===========================================================================*/
int req_statvfs(endpoint_t fs_e, struct statvfs *buf)
{
int r;
cp_grant_id_t grant_id;
message m;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) buf, sizeof(struct statvfs),
CPF_WRITE);
if(grant_id == GRANT_INVALID)
panic("req_statvfs: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_STATVFS;
m.m_vfs_fs_statvfs.grant = grant_id;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_ftrunc *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_ftrunc(endpoint_t fs_e, ino_t inode_nr, off_t start, off_t end)
{
message m;
struct vmnt *vmp;
vmp = find_vmnt(fs_e);
/* Fill in request message */
m.m_type = REQ_FTRUNC;
m.m_vfs_fs_ftrunc.inode = inode_nr;
m.m_vfs_fs_ftrunc.trc_start = start;
m.m_vfs_fs_ftrunc.trc_end = end;
if (!(vmp->m_fs_flags & RES_64BIT) &&
((start > INT_MAX) || (end > INT_MAX))) {
/* FS does not support 64-bit off_t and 32 bits is not enough */
return EINVAL;
}
2012-02-13 16:28:04 +01:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
2007-08-07 14:52:47 +02:00
}
2007-01-05 17:36:55 +01:00
2007-08-07 14:52:47 +02:00
/*===========================================================================*
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
* req_getdents_actual *
2007-08-07 14:52:47 +02:00
*===========================================================================*/
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
static int req_getdents_actual(
endpoint_t fs_e,
ino_t inode_nr,
off_t pos,
char *buf,
size_t size,
off_t *new_pos,
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
int direct,
int cpflag
)
2007-08-07 14:52:47 +02:00
{
int r;
message m;
cp_grant_id_t grant_id;
struct vmnt *vmp;
vmp = find_vmnt(fs_e);
assert(vmp != NULL);
if (direct) {
grant_id = cpf_grant_direct(fs_e, (vir_bytes) buf, size, CPF_WRITE);
} else {
grant_id = cpf_grant_magic(fs_e, who_e, (vir_bytes) buf, size,
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
CPF_WRITE | cpflag);
}
if (grant_id < 0)
2012-02-13 16:28:04 +01:00
panic("req_getdents: cpf_grant_direct/cpf_grant_magic failed: %d",
grant_id);
m.m_type = REQ_GETDENTS;
m.m_vfs_fs_getdents.inode = inode_nr;
m.m_vfs_fs_getdents.grant = grant_id;
m.m_vfs_fs_getdents.mem_size = size;
m.m_vfs_fs_getdents.seek_pos = pos;
if (!(vmp->m_fs_flags & RES_64BIT) && (pos > INT_MAX)) {
/* FS does not support 64-bit off_t and 32 bits is not enough */
return EINVAL;
}
2012-02-13 16:28:04 +01:00
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2012-02-13 16:28:04 +01:00
if (r == OK) {
*new_pos = m.m_fs_vfs_getdents.seek_pos;
r = m.m_fs_vfs_getdents.nbytes;
}
return(r);
}
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
/*===========================================================================*
* req_getdents *
*===========================================================================*/
int req_getdents(
endpoint_t fs_e,
ino_t inode_nr,
off_t pos,
char *buf,
size_t size,
off_t *new_pos,
int direct)
{
int r;
r = req_getdents_actual(fs_e, inode_nr, pos, buf, size, new_pos,
direct, CPF_TRY);
if(r == EFAULT && !direct) {
if((r=vm_vfs_procctl_handlemem(who_e, (vir_bytes) buf,
size, 1)) != OK) {
return r;
}
r = req_getdents_actual(fs_e, inode_nr, pos, buf, size,
new_pos, direct, 0);
}
return r;
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_inhibread *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_inhibread(endpoint_t fs_e, ino_t inode_nr)
{
message m;
/* Fill in request message */
m.m_type = REQ_INHIBREAD;
m.m_vfs_fs_inhibread.inode = inode_nr;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_link *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_link(
endpoint_t fs_e,
ino_t link_parent,
char *lastc,
ino_t linked_file
)
{
int r;
cp_grant_id_t grant_id;
const size_t len = strlen(lastc) + 1;
message m;
grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_link: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_LINK;
m.m_vfs_fs_link.inode = linked_file;
m.m_vfs_fs_link.dir_ino = link_parent;
m.m_vfs_fs_link.grant = grant_id;
m.m_vfs_fs_link.path_len = len;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2012-02-13 16:28:04 +01:00
return(r);
2007-08-07 14:52:47 +02:00
}
2012-02-13 16:28:04 +01:00
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_lookup *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_lookup(
endpoint_t fs_e,
ino_t dir_ino,
ino_t root_ino,
uid_t uid,
gid_t gid,
2012-02-13 16:28:04 +01:00
struct lookup *resolve,
lookup_res_t *res,
struct fproc *rfp
)
{
message m;
vfs_ucred_t credentials;
int r, flags;
size_t len;
struct vmnt *vmp;
cp_grant_id_t grant_id=0, grant_id2=0;
vmp = find_vmnt(fs_e);
2012-02-13 16:28:04 +01:00
grant_id = cpf_grant_direct(fs_e, (vir_bytes) resolve->l_path, PATH_MAX,
CPF_READ | CPF_WRITE);
if(grant_id == -1)
panic("req_lookup: cpf_grant_direct failed");
2012-02-13 16:28:04 +01:00
flags = resolve->l_flags;
len = strlen(resolve->l_path) + 1;
m.m_type = REQ_LOOKUP;
m.m_vfs_fs_lookup.grant_path = grant_id;
m.m_vfs_fs_lookup.path_len = len;
m.m_vfs_fs_lookup.path_size = PATH_MAX + 1;
m.m_vfs_fs_lookup.dir_ino = dir_ino;
m.m_vfs_fs_lookup.root_ino = root_ino;
if(rfp->fp_ngroups > 0) { /* Is the process member of multiple groups? */
2012-02-13 16:28:04 +01:00
/* In that case the FS has to copy the uid/gid credentials */
int i;
2012-02-13 16:28:04 +01:00
/* Set credentials */
credentials.vu_uid = rfp->fp_effuid;
credentials.vu_gid = rfp->fp_effgid;
credentials.vu_ngroups = rfp->fp_ngroups;
for (i = 0; i < rfp->fp_ngroups; i++)
credentials.vu_sgroups[i] = rfp->fp_sgroups[i];
grant_id2 = cpf_grant_direct(fs_e, (vir_bytes) &credentials,
sizeof(credentials), CPF_READ);
if(grant_id2 == -1)
panic("req_lookup: cpf_grant_direct failed");
m.m_vfs_fs_lookup.grant_ucred = grant_id2;
m.m_vfs_fs_lookup.ucred_size = sizeof(credentials);
2012-02-13 16:28:04 +01:00
flags |= PATH_GET_UCRED;
} else {
2012-02-13 16:28:04 +01:00
/* When there's only one gid, we can send it directly */
m.m_vfs_fs_lookup.uid = uid;
m.m_vfs_fs_lookup.gid = gid;
flags &= ~PATH_GET_UCRED;
}
m.m_vfs_fs_lookup.flags = flags;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2012-02-13 16:28:04 +01:00
if(rfp->fp_ngroups > 0) cpf_revoke(grant_id2);
/* Fill in response according to the return value */
res->fs_e = m.m_source;
switch (r) {
case OK:
res->inode_nr = m.m_fs_vfs_lookup.inode;
res->fmode = m.m_fs_vfs_lookup.mode;
res->fsize = m.m_fs_vfs_lookup.file_size;
res->dev = m.m_fs_vfs_lookup.device;
res->uid = m.m_fs_vfs_lookup.uid;
res->gid = m.m_fs_vfs_lookup.gid;
break;
case EENTERMOUNT:
res->inode_nr = m.m_fs_vfs_lookup.inode;
res->char_processed = m.m_fs_vfs_lookup.offset;
res->symloop = m.m_fs_vfs_lookup.symloop;
break;
case ELEAVEMOUNT:
res->char_processed = m.m_fs_vfs_lookup.offset;
res->symloop = m.m_fs_vfs_lookup.symloop;
break;
case ESYMLINK:
res->char_processed = m.m_fs_vfs_lookup.offset;
res->symloop = m.m_fs_vfs_lookup.symloop;
break;
default:
break;
}
2012-02-13 16:28:04 +01:00
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_mkdir *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_mkdir(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
uid_t uid,
gid_t gid,
mode_t dmode
)
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
2012-02-13 16:28:04 +01:00
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_mkdir: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_MKDIR;
m.m_vfs_fs_mkdir.inode = inode_nr;
m.m_vfs_fs_mkdir.mode = dmode;
m.m_vfs_fs_mkdir.uid = uid;
m.m_vfs_fs_mkdir.gid = gid;
m.m_vfs_fs_mkdir.grant = grant_id;
m.m_vfs_fs_mkdir.path_len = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
}
/*===========================================================================*
2007-08-10 15:02:39 +02:00
* req_mknod *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_mknod(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
uid_t uid,
gid_t gid,
mode_t dmode,
dev_t dev
)
{
int r;
size_t len;
cp_grant_id_t grant_id;
message m;
2012-02-13 16:28:04 +01:00
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes)lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_mknod: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_MKNOD;
m.m_vfs_fs_mknod.inode = inode_nr;
m.m_vfs_fs_mknod.mode = dmode;
m.m_vfs_fs_mknod.device = dev;
m.m_vfs_fs_mknod.uid = uid;
m.m_vfs_fs_mknod.gid = gid;
m.m_vfs_fs_mknod.grant = grant_id;
m.m_vfs_fs_mknod.path_len = len;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2012-02-13 16:28:04 +01:00
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_mountpoint *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_mountpoint(endpoint_t fs_e, ino_t inode_nr)
{
message m;
/* Fill in request message */
m.m_type = REQ_MOUNTPOINT;
m.m_vfs_fs_mountpoint.inode = inode_nr;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
2007-08-07 14:52:47 +02:00
/*===========================================================================*
2007-08-10 15:02:39 +02:00
* req_newnode *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_newnode(
endpoint_t fs_e,
uid_t uid,
gid_t gid,
mode_t dmode,
dev_t dev,
struct node_details *res
)
{
struct vmnt *vmp;
int r;
message m;
vmp = find_vmnt(fs_e);
/* Fill in request message */
m.m_type = REQ_NEWNODE;
m.m_vfs_fs_newnode.mode = dmode;
m.m_vfs_fs_newnode.device = dev;
m.m_vfs_fs_newnode.uid = uid;
m.m_vfs_fs_newnode.gid = gid;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
res->fs_e = m.m_source;
res->inode_nr = m.m_fs_vfs_newnode.inode;
res->fmode = m.m_fs_vfs_newnode.mode;
res->fsize = m.m_fs_vfs_newnode.file_size;
res->dev = m.m_fs_vfs_newnode.device;
res->uid = m.m_fs_vfs_newnode.uid;
res->gid = m.m_fs_vfs_newnode.gid;
return(r);
}
2007-08-10 15:02:39 +02:00
/*===========================================================================*
* req_newdriver *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_newdriver(
endpoint_t fs_e,
dev_t dev,
char *label
)
2007-08-10 15:02:39 +02:00
{
cp_grant_id_t grant_id;
size_t len;
message m;
int r;
/* Grant access to label */
len = strlen(label) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) label, len, CPF_READ);
if (grant_id == -1)
panic("req_newdriver: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_NEW_DRIVER;
m.m_vfs_fs_new_driver.device = dev;
m.m_vfs_fs_new_driver.grant = grant_id;
m.m_vfs_fs_new_driver.path_len = len;
/* Issue request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
return(r);
2007-08-10 15:02:39 +02:00
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_putnode *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_putnode(fs_e, inode_nr, count)
2007-08-07 14:52:47 +02:00
int fs_e;
ino_t inode_nr;
int count;
{
message m;
/* Fill in request message */
m.m_type = REQ_PUTNODE;
m.m_vfs_fs_putnode.inode = inode_nr;
m.m_vfs_fs_putnode.count = count;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
* req_rdlink_actual *
*===========================================================================*/
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
static int req_rdlink_actual(endpoint_t fs_e, ino_t inode_nr,
endpoint_t proc_e, vir_bytes buf, size_t len,
int direct, /* set to 1 to use direct grants instead of magic grants */
int cpflag)
{
message m;
int r;
cp_grant_id_t grant_id;
if (direct) {
grant_id = cpf_grant_direct(fs_e, buf, len, CPF_WRITE);
} else {
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
grant_id = cpf_grant_magic(fs_e, proc_e, buf, len, CPF_WRITE | cpflag);
}
if (grant_id == -1)
panic("req_rdlink: cpf_grant_magic failed");
/* Fill in request message */
m.m_type = REQ_RDLINK;
m.m_vfs_fs_rdlink.inode = inode_nr;
m.m_vfs_fs_rdlink.grant = grant_id;
m.m_vfs_fs_rdlink.mem_size = len;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r == OK) r = m.m_fs_vfs_rdlink.nbytes;
2007-08-07 14:52:47 +02:00
return(r);
}
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
/*===========================================================================*
* req_rdlink *
*===========================================================================*/
int req_rdlink(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e,
vir_bytes buf, size_t len,
int direct /* set to 1 to use direct grants instead of magic grants */
)
{
int r;
r = req_rdlink_actual(fs_e, inode_nr, proc_e, buf, len, direct,
CPF_TRY);
if(r == EFAULT && !direct) {
if((r=vm_vfs_procctl_handlemem(proc_e, buf, len, 1)) != OK) {
return r;
}
r = req_rdlink_actual(fs_e, inode_nr, proc_e, buf, len,
direct, 0);
}
return r;
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_readsuper *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_readsuper(
struct vmnt *vmp,
char *label,
dev_t dev,
int readonly,
int isroot,
struct node_details *res,
unsigned int *fs_flags
)
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
endpoint_t fs_e;
fs_e = vmp->m_fs_e;
2012-02-13 16:28:04 +01:00
len = strlen(label)+1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) label, len, CPF_READ);
if (grant_id == -1)
panic("req_readsuper: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_READSUPER;
m.m_vfs_fs_readsuper.flags = 0;
if(readonly) m.m_vfs_fs_readsuper.flags |= REQ_RDONLY;
if(isroot) m.m_vfs_fs_readsuper.flags |= REQ_ISROOT;
m.m_vfs_fs_readsuper.grant = grant_id;
m.m_vfs_fs_readsuper.device = dev;
m.m_vfs_fs_readsuper.path_len = len;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if(r == OK) {
/* Fill in response structure */
res->fs_e = m.m_source;
res->inode_nr = m.m_fs_vfs_readsuper.inode;
res->fmode = m.m_fs_vfs_readsuper.mode;
res->fsize = m.m_fs_vfs_readsuper.file_size;
res->uid = m.m_fs_vfs_readsuper.uid;
res->gid = m.m_fs_vfs_readsuper.gid;
*fs_flags = m.m_fs_vfs_readsuper.flags;
}
return(r);
}
/*===========================================================================*
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
* req_readwrite_actual *
*===========================================================================*/
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
static int req_readwrite_actual(endpoint_t fs_e, ino_t inode_nr, off_t pos,
int rw_flag, endpoint_t user_e, vir_bytes user_addr,
unsigned int num_of_bytes, off_t *new_posp, unsigned int *cum_iop,
int cpflag)
{
struct vmnt *vmp;
int r;
cp_grant_id_t grant_id;
message m;
2007-08-07 14:52:47 +02:00
vmp = find_vmnt(fs_e);
2007-08-07 14:52:47 +02:00
grant_id = cpf_grant_magic(fs_e, user_e, user_addr, num_of_bytes,
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
(rw_flag==READING ? CPF_WRITE:CPF_READ) | cpflag);
if (grant_id == -1)
panic("req_readwrite: cpf_grant_magic failed");
/* Fill in request message */
m.m_type = rw_flag == READING ? REQ_READ : REQ_WRITE;
m.REQ_INODE_NR = (pino_t) inode_nr;
m.REQ_GRANT = grant_id;
m.REQ_SEEK_POS = pos;
if ((!(vmp->m_fs_flags & RES_64BIT)) && (pos > INT_MAX)) {
return EINVAL;
}
m.REQ_NBYTES = num_of_bytes;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
if (r == OK) {
/* Fill in response structure */
*new_posp = m.RES_SEEK_POS;
*cum_iop = m.RES_NBYTES;
}
2012-02-13 16:28:04 +01:00
return(r);
}
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
/*===========================================================================*
* req_readwrite *
*===========================================================================*/
int req_readwrite(endpoint_t fs_e, ino_t inode_nr, off_t pos,
int rw_flag, endpoint_t user_e, vir_bytes user_addr,
unsigned int num_of_bytes, off_t *new_posp, unsigned int *cum_iop)
{
int r;
r = req_readwrite_actual(fs_e, inode_nr, pos, rw_flag, user_e,
user_addr, num_of_bytes, new_posp, cum_iop, CPF_TRY);
if(r == EFAULT) {
if((r=vm_vfs_procctl_handlemem(user_e, (vir_bytes) user_addr, num_of_bytes,
rw_flag == READING)) != OK) {
return r;
}
r = req_readwrite_actual(fs_e, inode_nr, pos, rw_flag, user_e,
user_addr, num_of_bytes, new_posp, cum_iop, 0);
}
return r;
}
/*===========================================================================*
* req_peek *
*===========================================================================*/
int req_peek(endpoint_t fs_e, ino_t inode_nr, off_t pos, unsigned int bytes)
{
message m;
memset(&m, 0, sizeof(m));
if (ex64hi(pos) != 0)
panic("req_peek: pos too large");
/* Fill in request message */
m.m_type = REQ_PEEK;
m.REQ_INODE_NR = inode_nr;
m.REQ_GRANT = -1;
m.REQ_SEEK_POS = pos;
m.REQ_NBYTES = bytes;
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_rename *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_rename(fs_e, old_dir, old_name, new_dir, new_name)
2007-08-07 14:52:47 +02:00
endpoint_t fs_e;
ino_t old_dir;
char *old_name;
ino_t new_dir;
char *new_name;
{
int r;
cp_grant_id_t gid_old, gid_new;
size_t len_old, len_new;
message m;
len_old = strlen(old_name) + 1;
gid_old = cpf_grant_direct(fs_e, (vir_bytes) old_name, len_old, CPF_READ);
if(gid_old == -1)
panic("req_rename: cpf_grant_direct failed");
len_new = strlen(new_name) + 1;
gid_new = cpf_grant_direct(fs_e, (vir_bytes) new_name, len_new, CPF_READ);
if(gid_new == -1)
panic("req_rename: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_RENAME;
m.m_vfs_fs_rename.dir_old = old_dir;
m.m_vfs_fs_rename.grant_old = gid_old;
m.m_vfs_fs_rename.len_old = len_old;
m.m_vfs_fs_rename.dir_new = new_dir;
m.m_vfs_fs_rename.grant_new = gid_new;
m.m_vfs_fs_rename.len_new = len_new;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(gid_old);
cpf_revoke(gid_new);
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_rmdir *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_rmdir(fs_e, inode_nr, lastc)
2007-08-07 14:52:47 +02:00
endpoint_t fs_e;
ino_t inode_nr;
char *lastc;
{
int r;
cp_grant_id_t grant_id;
size_t len;
message m;
2012-02-13 16:28:04 +01:00
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_rmdir: cpf_grant_direct failed");
/* Fill in request message */
m.m_type = REQ_RMDIR;
m.m_vfs_fs_unlink.inode = inode_nr;
m.m_vfs_fs_unlink.grant = grant_id;
m.m_vfs_fs_unlink.path_len = len;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2007-08-07 14:52:47 +02:00
return(r);
2007-08-07 14:52:47 +02:00
}
/*===========================================================================*
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
* req_slink_actual *
*===========================================================================*/
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
static int req_slink_actual(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
2012-02-13 16:28:04 +01:00
endpoint_t proc_e,
vir_bytes path_addr,
size_t path_length,
uid_t uid,
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
gid_t gid,
int cpflag
)
{
int r;
size_t len;
cp_grant_id_t gid_name, gid_buf;
message m;
len = strlen(lastc) + 1;
gid_name = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
if (gid_name == GRANT_INVALID)
panic("req_slink: cpf_grant_direct failed");
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
gid_buf = cpf_grant_magic(fs_e, proc_e, path_addr, path_length,
CPF_READ | cpflag);
if (gid_buf == GRANT_INVALID) {
cpf_revoke(gid_name);
panic("req_slink: cpf_grant_magic failed");
}
/* Fill in request message */
m.m_type = REQ_SLINK;
m.m_vfs_fs_slink.inode = inode_nr;
m.m_vfs_fs_slink.uid = uid;
m.m_vfs_fs_slink.gid = gid;
m.m_vfs_fs_slink.grant_path = gid_name;
m.m_vfs_fs_slink.path_len = len;
m.m_vfs_fs_slink.grant_target = gid_buf;
m.m_vfs_fs_slink.mem_size = path_length;
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(gid_name);
cpf_revoke(gid_buf);
return(r);
}
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
/*===========================================================================*
* req_slink *
*===========================================================================*/
int req_slink(
endpoint_t fs_e,
ino_t inode_nr,
char *lastc,
endpoint_t proc_e,
vir_bytes path_addr,
size_t path_length,
uid_t uid,
gid_t gid
)
{
int r;
r = req_slink_actual(fs_e, inode_nr, lastc, proc_e, path_addr,
path_length, uid, gid, CPF_TRY);
if(r == EFAULT) {
if((r=vm_vfs_procctl_handlemem(proc_e, (vir_bytes) path_addr,
path_length, 0)) != OK) {
return r;
}
r = req_slink_actual(fs_e, inode_nr, lastc, proc_e, path_addr,
path_length, uid, gid, 0);
}
return r;
}
/*===========================================================================*
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
* req_stat_actual *
*===========================================================================*/
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
int req_stat_actual(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e,
vir_bytes buf, int cpflag)
{
cp_grant_id_t grant_id;
2007-08-07 14:52:47 +02:00
int r;
message m;
/* Grant FS access to copy straight into user provided buffer */
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
grant_id = cpf_grant_magic(fs_e, proc_e, buf, sizeof(struct stat),
CPF_WRITE | cpflag);
if (grant_id < 0)
panic("req_stat: cpf_grant_* failed");
2007-08-07 14:52:47 +02:00
/* Fill in request message */
m.m_type = REQ_STAT;
m.m_vfs_fs_stat.inode = inode_nr;
m.m_vfs_fs_stat.grant = grant_id;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2007-08-07 14:52:47 +02:00
return(r);
}
make vfs & filesystems use failable copying Change the kernel to add features to vircopy and safecopies so that transparent copy fixing won't happen to avoid deadlocks, and such copies fail with EFAULT. Transparently making copying work from filesystems (as normally done by the kernel & VM when copying fails because of missing/readonly memory) is problematic as it can happen that, for file-mapped ranges, that that same filesystem that is blocked on the copy request is needed to satisfy the memory range, leading to deadlock. Dito for VFS itself, if done with a blocking call. This change makes the copying done from a filesystem fail in such cases with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call fails with EFAULT, VFS will then request the range to be made available to VM after the FS is unblocked, allowing it to be used to satisfy the range if need be in another VFS thread. Similarly, for datacopies that VFS itself does, it uses the failable vircopy variant and callers use a wrapper that talk to VM if necessary to get the copy to work. . kernel: add CPF_TRY flag to safecopies . kernel: only request writable ranges to VM for the target buffer when copying fails . do copying in VFS TRY-first . some fixes in VM to build SANITYCHECK mode . add regression test for the cases where - a FS system call needs memory mapped in a process that the FS itself must map. - such a range covers more than one file-mapped region. . add 'try' mode to vircopy, physcopy . add flags field to copy kernel call messages . if CP_FLAG_TRY is set, do not transparently try to fix memory ranges . for use by VFS when accessing user buffers to avoid deadlock . remove some obsolete backwards compatability assignments . VFS: let thread scheduling work for VM requests too Allows VFS to make calls to VM while suspending and resuming the currently running thread. Does currently not work for the main thread. . VM: add fix memory range call for use by VFS Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
/*===========================================================================*
* req_stat *
*===========================================================================*/
int req_stat(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e,
vir_bytes buf)
{
int r;
r = req_stat_actual(fs_e, inode_nr, proc_e, buf, CPF_TRY);
if(r == EFAULT) {
if((r=vm_vfs_procctl_handlemem(proc_e, (vir_bytes) buf,
sizeof(struct stat), 1)) != OK) {
return r;
}
r = req_stat_actual(fs_e, inode_nr, proc_e, buf, 0);
}
return r;
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_sync *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_sync(fs_e)
2012-02-13 16:28:04 +01:00
endpoint_t fs_e;
{
message m;
/* Fill in request message */
m.m_type = REQ_SYNC;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
2007-08-07 14:52:47 +02:00
}
2007-08-07 14:52:47 +02:00
/*===========================================================================*
* req_unlink *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_unlink(fs_e, inode_nr, lastc)
endpoint_t fs_e;
ino_t inode_nr;
2007-08-07 14:52:47 +02:00
char *lastc;
{
cp_grant_id_t grant_id;
size_t len;
int r;
message m;
2012-02-13 16:28:04 +01:00
len = strlen(lastc) + 1;
grant_id = cpf_grant_direct(fs_e, (vir_bytes) lastc, len, CPF_READ);
if(grant_id == -1)
panic("req_unlink: cpf_grant_direct failed");
2007-08-07 14:52:47 +02:00
/* Fill in request message */
m.m_type = REQ_UNLINK;
m.m_vfs_fs_unlink.inode = inode_nr;
m.m_vfs_fs_unlink.grant = grant_id;
m.m_vfs_fs_unlink.path_len = len;
2007-08-07 14:52:47 +02:00
/* Send/rec request */
r = fs_sendrec(fs_e, &m);
cpf_revoke(grant_id);
2012-02-13 16:28:04 +01:00
return(r);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_unmount *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int req_unmount(fs_e)
2012-02-13 16:28:04 +01:00
endpoint_t fs_e;
{
message m;
/* Fill in request message */
m.m_type = REQ_UNMOUNT;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
}
/*===========================================================================*
2007-08-07 14:52:47 +02:00
* req_utime *
*===========================================================================*/
int req_utime(endpoint_t fs_e, ino_t inode_nr, struct timespec * actimespec,
struct timespec * modtimespec)
{
message m;
assert(actimespec != NULL);
assert(modtimespec != NULL);
/* Fill in request message */
m.m_type = REQ_UTIME;
m.m_vfs_fs_utime.inode = inode_nr;
m.m_vfs_fs_utime.actime = actimespec->tv_sec;
m.m_vfs_fs_utime.modtime = modtimespec->tv_sec;
m.m_vfs_fs_utime.acnsec = actimespec->tv_nsec;
m.m_vfs_fs_utime.modnsec = modtimespec->tv_nsec;
2012-02-13 16:28:04 +01:00
/* Send/rec request */
return fs_sendrec(fs_e, &m);
2007-08-07 14:52:47 +02:00
}