From: Simon Wilkinson Date: Fri, 23 Apr 2010 16:07:40 +0000 (+0100) Subject: Linux: Don't hide memory management X-Git-Tag: openafs-devel-1_5_75~369 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=90c970d3b60bb28a21b2861b75469281b5c464a5 Linux: Don't hide memory management Given that we now only switch from user space into kernel space in one place, don't hide the mechanism we use to do so behind macros. This makes it much easier to visually confirm the correctness of the code. Change-Id: Ie52e071c81a9178c792be1eaa7e36d8453ebb319 Reviewed-on: http://gerrit.openafs.org/1820 Reviewed-by: Simon Wilkinson Reviewed-by: Dan Hyde Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c index ba6c873..33c9667 100644 --- a/src/afs/LINUX/osi_file.c +++ b/src/afs/LINUX/osi_file.c @@ -371,7 +371,7 @@ int osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) { struct file *filp = osifile->filp; - KERNEL_SPACE_DECL; + mm_segment_t old_fs = {0}; int code = 0; struct iovec *iov; size_t count; @@ -381,8 +381,11 @@ osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur; current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; - if (uiop->uio_seg == AFS_UIOSYS) - TO_USER_SPACE(); + if (uiop->uio_seg == AFS_UIOSYS) { + /* Switch into user space */ + old_fs = get_fs(); + set_fs(get_ds()); + } /* seek to the desired position. Return -1 on error. */ if (vfs_llseek(filp, (loff_t) uiop->uio_offset, 0) != uiop->uio_offset) { @@ -427,8 +430,10 @@ osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) } out: - if (uiop->uio_seg == AFS_UIOSYS) - TO_KERNEL_SPACE(); + if (uiop->uio_seg == AFS_UIOSYS) { + /* Switch back into kernel space */ + set_fs(old_fs); + } current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = savelim; diff --git a/src/afs/LINUX/osi_machdep.h b/src/afs/LINUX/osi_machdep.h index 4222caf..528e862 100644 --- a/src/afs/LINUX/osi_machdep.h +++ b/src/afs/LINUX/osi_machdep.h @@ -119,20 +119,8 @@ static inline time_t osi_Time(void) { #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS) /* test superblock instead */ #define SetAfsVnode(V) /* unnecessary */ -/* We often need to pretend we're in user space to get memory transfers - * right for the kernel calls we use. - */ #include -#ifdef KERNEL_SPACE_DECL -#undef KERNEL_SPACE_DECL -#undef TO_USER_SPACE -#undef TO_KERNEL_SPACE -#endif -#define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl={0} -#define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); } -#define TO_KERNEL_SPACE() set_fs(_fs_space_decl) - #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) static inline long copyinstr(char *from, char *to, int count, int *length) { long tmp;