From 9d73dbe8ae760d44e034ca06e9f08c7245b6385b Mon Sep 17 00:00:00 2001 From: Chas Williams Date: Sun, 24 Apr 2005 21:11:14 +0000 Subject: [PATCH] STABLE14-linux-conflate-rdwrs-20050419 FIXES 17561 conflate the 2 rdwr routines we have (cherry picked from commit 77111b823235eefbcc43a61fc7917d25c1bdac44) --- src/afs/LINUX/osi_file.c | 41 +++++++++++++++---------- src/afs/LINUX/osi_misc.c | 56 ++++++---------------------------- src/afs/LINUX/osi_prototypes.h | 4 +-- src/afs/VNOPS/afs_vnop_read.c | 2 +- src/afs/VNOPS/afs_vnop_write.c | 2 +- src/afs/afs_prototypes.h | 4 +-- 6 files changed, 39 insertions(+), 70 deletions(-) diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c index 4caac7115..6b2ca4157 100644 --- a/src/afs/LINUX/osi_file.c +++ b/src/afs/LINUX/osi_file.c @@ -185,14 +185,16 @@ int afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, afs_int32 asize) { - size_t resid; - register afs_int32 code; + struct uio auio; + struct iovec iov; + afs_int32 code; + AFS_STATCNT(osi_Read); - /** - * If the osi_file passed in is NULL, panic only if AFS is not shutting - * down. No point in crashing when we are already shutting down - */ + /* + * If the osi_file passed in is NULL, panic only if AFS is not shutting + * down. No point in crashing when we are already shutting down + */ if (!afile) { if (!afs_shuttingdown) osi_Panic("osi_Read called with null param"); @@ -202,14 +204,15 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, if (offset != -1) afile->offset = offset; + setup_uio(&auio, &iov, aptr, afile->offset, asize, UIO_READ, AFS_UIOSYS); AFS_GUNLOCK(); - code = osi_rdwr(UIO_READ, afile, (caddr_t) aptr, asize, &resid); + code = osi_rdwr(afile, &auio, UIO_READ); AFS_GLOCK(); if (code == 0) { - code = asize - resid; + code = asize - auio.uio_resid; afile->offset += code; } else { - afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid, + afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, auio.uio_resid, ICL_TYPE_INT32, code); code = -1; } @@ -221,22 +224,27 @@ int afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, afs_int32 asize) { - size_t resid; - register afs_int32 code; + struct uio auio; + struct iovec iov; + afs_int32 code; + AFS_STATCNT(osi_Write); + if (!afile) { if (!afs_shuttingdown) osi_Panic("afs_osi_Write called with null param"); else return EIO; } + if (offset != -1) afile->offset = offset; + setup_uio(&auio, &iov, aptr, afile->offset, asize, UIO_WRITE, AFS_UIOSYS); AFS_GUNLOCK(); - code = osi_rdwr(UIO_WRITE, afile, (caddr_t) aptr, asize, &resid); + code = osi_rdwr(afile, &auio, UIO_WRITE); AFS_GLOCK(); if (code == 0) { - code = asize - resid; + code = asize - auio.uio_resid; afile->offset += code; } else { if (code == ENOSPC) @@ -244,9 +252,10 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n"); code = -1; } - if (afile->proc) { - (*afile->proc) (afile, code); - } + + if (afile->proc) + (*afile->proc)(afile, code); + return code; } diff --git a/src/afs/LINUX/osi_misc.c b/src/afs/LINUX/osi_misc.c index 440351c09..6a144e971 100644 --- a/src/afs/LINUX/osi_misc.c +++ b/src/afs/LINUX/osi_misc.c @@ -135,59 +135,17 @@ osi_InitCacheInfo(char *aname) #define FOP_WRITE(F, B, C) (F)->f_op->write(F, B, (size_t)(C), &(F)->f_pos) /* osi_rdwr - * Seek, then read or write to an open inode. addrp points to data in + * seek, then read or write to an open inode. addrp points to data in * kernel space. */ int -osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, - size_t * resid) -{ - int code = 0; - KERNEL_SPACE_DECL; - struct file *filp = &file->file; - off_t offset = file->offset; - unsigned long savelim; - - /* Seek to the desired position. Return -1 on error. */ - if (filp->f_op->llseek) { - if (filp->f_op->llseek(filp, (loff_t) offset, 0) != offset) - return -1; - } else - filp->f_pos = offset; - - savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur; - current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; - - /* Read/Write the data. */ - TO_USER_SPACE(); - if (rw == UIO_READ) - code = FOP_READ(filp, addrp, asize); - else if (rw == UIO_WRITE) - code = FOP_WRITE(filp, addrp, asize); - else /* all is well? */ - code = asize; - TO_KERNEL_SPACE(); - - current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = savelim; - - if (code >= 0) { - *resid = asize - code; - return 0; - } else - return -1; -} - -/* This variant is called from AFS read/write routines and takes a uio - * struct and, if successful, returns 0. - */ -int -osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) +osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) { struct file *filp = &osifile->file; KERNEL_SPACE_DECL; int code = 0; struct iovec *iov; - int count; + afs_size_t count; unsigned long savelim; savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur; @@ -196,7 +154,13 @@ osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw) if (uiop->uio_seg == AFS_UIOSYS) TO_USER_SPACE(); - filp->f_pos = uiop->uio_offset; + /* seek to the desired position. Return -1 on error. */ + if (filp->f_op->llseek) { + if (filp->f_op->llseek(filp, (loff_t) uiop->uio_offset, 0) != uiop->uio_offset) + return -1; + } else + filp->f_pos = uiop->uio_offset; + while (code == 0 && uiop->uio_resid > 0 && uiop->uio_iovcnt > 0) { iov = uiop->uio_iov; count = iov->iov_len; diff --git a/src/afs/LINUX/osi_prototypes.h b/src/afs/LINUX/osi_prototypes.h index 117fa9c69..4265e0037 100644 --- a/src/afs/LINUX/osi_prototypes.h +++ b/src/afs/LINUX/osi_prototypes.h @@ -34,9 +34,7 @@ extern afs_rwlock_t afs_xosi; extern int osi_lookupname(char *aname, uio_seg_t seg, int followlink, struct dentry **dpp); extern int osi_InitCacheInfo(char *aname); -extern int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, - size_t asize, size_t * resid); -extern int osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw); +extern int osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw); extern void afs_osi_SetTime(osi_timeval_t * tvp); extern void osi_linux_free_inode_pages(void); extern void check_bad_parent(struct dentry *dp); diff --git a/src/afs/VNOPS/afs_vnop_read.c b/src/afs/VNOPS/afs_vnop_read.c index 0d7ab8a85..5efc7b43c 100644 --- a/src/afs/VNOPS/afs_vnop_read.c +++ b/src/afs/VNOPS/afs_vnop_read.c @@ -788,7 +788,7 @@ afs_UFSRead(register struct vcache *avc, struct uio *auio, AFS_GLOCK(); #elif defined(AFS_LINUX20_ENV) AFS_GUNLOCK(); - code = osi_file_uio_rdwr(tfile, &tuio, UIO_READ); + code = osi_rdwr(tfile, &tuio, UIO_READ); AFS_GLOCK(); #elif defined(AFS_DARWIN_ENV) AFS_GUNLOCK(); diff --git a/src/afs/VNOPS/afs_vnop_write.c b/src/afs/VNOPS/afs_vnop_write.c index 22e0febd8..4a93e5572 100644 --- a/src/afs/VNOPS/afs_vnop_write.c +++ b/src/afs/VNOPS/afs_vnop_write.c @@ -560,7 +560,7 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio, } #elif defined(AFS_LINUX20_ENV) AFS_GUNLOCK(); - code = osi_file_uio_rdwr(tfile, &tuio, UIO_WRITE); + code = osi_rdwr(tfile, &tuio, UIO_WRITE); AFS_GLOCK(); #elif defined(AFS_DARWIN_ENV) AFS_GUNLOCK(); diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index 0fcbabe8b..96f17b914 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -540,9 +540,7 @@ extern void afs_osi_SetTime(osi_timeval_t * atv); extern int osi_lookupname(char *aname, uio_seg_t seg, int followlink, struct dentry **dpp); extern int osi_InitCacheInfo(char *aname); -extern int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, - size_t asize, size_t * resid); -extern int osi_file_uio_rdwr(struct osi_file *osifile, uio_t * uiop, int rw); +extern int osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw); extern void setup_uio(uio_t * uiop, struct iovec *iovecp, const char *buf, afs_offs_t pos, int count, uio_flag_t flag, uio_seg_t seg); -- 2.39.5