From 0b7c5f7b560e5dd116e6da99d19ec1a0dc969fe6 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Mon, 15 Mar 2010 12:42:23 -0500 Subject: [PATCH] ihandle positional read and write When available, use POSIX positional read and write calls in the ihandle package. Originally written by Derrick Brashear and Andrew Deason. (cherry picked from commit 335ccb4082657b7d0e4e9af1076356cf115642d2) Reviewed-on: http://gerrit.openafs.org/1562 Tested-by: BuildBot Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear Change-Id: I6616a8f7ba04410c57097fb6fa687258b847ac4e Reviewed-on: http://gerrit.openafs.org/3884 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- acinclude.m4 | 20 +++++++- src/viced/afsfileprocs.c | 102 +++++++++++++++++++-------------------- src/viced/physio.c | 24 +-------- src/vol/clone.c | 14 +++--- src/vol/ihandle.c | 85 +++++++++++++++++++++++++------- src/vol/ihandle.h | 18 +++++-- src/vol/listinodes.c | 15 +++--- src/vol/namei_ops.c | 58 +++++----------------- src/vol/ntops.c | 13 +---- src/vol/physio.c | 16 ++---- src/vol/purge.c | 4 +- src/vol/vnode.c | 25 ++-------- src/vol/vol-info.c | 4 +- src/vol/vol-salvage.c | 33 +++++-------- src/vol/volume.c | 16 ++---- src/vol/vutil.c | 16 +----- src/volser/dumpstuff.c | 49 +++++-------------- src/volser/physio.c | 14 +----- src/volser/vol-dump.c | 23 ++------- src/volser/vol_split.c | 70 ++++++++++++--------------- src/volser/volprocs.c | 5 +- 21 files changed, 264 insertions(+), 360 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 4903bbd493..b52627036f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1248,7 +1248,25 @@ AC_CHECK_FUNCS(snprintf strlcat strlcpy flock getrlimit) AC_CHECK_FUNCS(setprogname getprogname sigaction mkstemp vsnprintf strerror strcasestr) AC_CHECK_FUNCS(setvbuf vsyslog getcwd) AC_CHECK_FUNCS(regcomp regexec regerror) -AC_CHECK_FUNCS(fseeko64 ftello64) +AC_CHECK_FUNCS(fseeko64 ftello64 pread preadv pwrite pwritev) + +AC_MSG_CHECKING([for positional I/O]) +if test "$ac_cv_func_pread" = "yes" && \ + test "$ac_cv_func_pwrite" = "yes"; then + AC_DEFINE(HAVE_PIO, 1, [define if you have pread() and pwrite()]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +AC_MSG_CHECKING([for vectored positional I/O]) +if test "$ac_cv_func_preadv" = "yes" && \ + test "$ac_cv_func_pwritev" = "yes"; then + AC_DEFINE(HAVE_PIOV, 1, [define if you have preadv() and pwritev()]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + AC_MSG_CHECKING([for POSIX regex library]) if test "$ac_cv_header_regex_h" = "yes" && \ test "$ac_cv_func_regcomp" = "yes" && \ diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index ef439bf511..980e1a9f83 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -1114,6 +1114,7 @@ CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len) ssize_t rdlen; ssize_t wrlen; afs_fsize_t size; + afs_foff_t done; size_t length; char *buff; int rc; /* return code */ @@ -1175,8 +1176,7 @@ CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len) newFdP = IH_OPEN(newH); osi_Assert(newFdP != NULL); - FDH_SEEK(targFdP, off, SEEK_SET); - FDH_SEEK(newFdP, off, SEEK_SET); + done = off; while (size > 0) { if (size > COPYBUFFSIZE) { /* more than a buffer */ length = COPYBUFFSIZE; @@ -1185,10 +1185,11 @@ CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len) length = size; size = 0; } - rdlen = FDH_READ(targFdP, buff, length); - if (rdlen == length) - wrlen = FDH_WRITE(newFdP, buff, length); - else + rdlen = FDH_PREAD(targFdP, buff, length, done); + if (rdlen == length) { + wrlen = FDH_PWRITE(newFdP, buff, length, done); + done += rdlen; + } else wrlen = 0; /* Callers of this function are not prepared to recover * from error that put the filesystem in an inconsistent @@ -1272,9 +1273,7 @@ CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off, ssize_t rdlen; ssize_t wrlen; int rc = 0; - - FDH_SEEK(targFdP, off, SEEK_SET); - FDH_SEEK(newFdP, off, SEEK_SET); + afs_foff_t done = off; if (size > FDH_SIZE(targFdP) - off) size = FDH_SIZE(targFdP) - off; @@ -1287,9 +1286,11 @@ CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off, length = size; size = 0; } - rdlen = FDH_READ(targFdP, buff, length); - if (rdlen == length) - wrlen = FDH_WRITE(newFdP, buff, length); + rdlen = FDH_PREAD(targFdP, buff, length, done); + if (rdlen == length) { + wrlen = FDH_PWRITE(newFdP, buff, length, done); + done += rdlen; + } else wrlen = 0; @@ -2023,13 +2024,13 @@ SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid, return code; } -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV static struct afs_buffer { struct afs_buffer *next; } *freeBufferList = 0; static int afs_buffersAlloced = 0; -static +static int FreeSendBuffer(struct afs_buffer *adata) { FS_LOCK; @@ -2043,7 +2044,7 @@ FreeSendBuffer(struct afs_buffer *adata) /* allocate space for sender */ static char * -AllocSendBuffer() +AllocSendBuffer(void) { struct afs_buffer *tp; @@ -2065,7 +2066,7 @@ AllocSendBuffer() return (char *)tp; } /*AllocSendBuffer */ -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ /* * This routine returns the status info associated with the targetptr vnode @@ -4462,9 +4463,9 @@ SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name, return EIO; } len = strlen((char *) LinkContents); - code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL; + code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL; if (code) - ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique)); + ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique)); FDH_CLOSE(fdP); /* * Set up and return modified status for the parent dir and new symlink @@ -7023,12 +7024,12 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, struct timeval StartTime, StopTime; /* used to calculate file transfer rates */ IHandle_t *ihP; FdHandle_t *fdP; -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV char *tbuffer; -#else /* AFS_NT40_ENV */ +#else /* HAVE_PIOV */ struct iovec tiov[RX_MAXIOVECS]; int tnio; -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ afs_sfsize_t tlen; afs_int32 optSize; @@ -7083,7 +7084,6 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, if (Pos + Len > tlen) /* get length we should send */ Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos; - (void)FDH_SEEK(fdP, Pos, 0); { afs_int32 high, low; SplitOffsetOrSize(Len, high, low); @@ -7098,9 +7098,9 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, #if FS_STATS_DETAILED (*a_bytesToFetchP) = Len; #endif /* FS_STATS_DETAILED */ -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV tbuffer = AllocSendBuffer(); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ while (Len > 0) { size_t wlen; ssize_t nBytes; @@ -7108,8 +7108,8 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, wlen = optSize; else wlen = Len; -#ifdef AFS_NT40_ENV - nBytes = FDH_READ(fdP, tbuffer, wlen); +#ifndef HAVE_PIOV + nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos); if (nBytes != wlen) { FDH_CLOSE(fdP); FreeSendBuffer((struct afs_buffer *)tbuffer); @@ -7119,14 +7119,14 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, return EIO; } nBytes = rx_Write(Call, tbuffer, wlen); -#else /* AFS_NT40_ENV */ +#else /* HAVE_PIOV */ nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen); if (nBytes <= 0) { FDH_CLOSE(fdP); return EIO; } wlen = nBytes; - nBytes = FDH_READV(fdP, tiov, tnio); + nBytes = FDH_PREADV(fdP, tiov, tnio, Pos); if (nBytes != wlen) { FDH_CLOSE(fdP); VTakeOffline(volptr); @@ -7135,7 +7135,8 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, return EIO; } nBytes = rx_Writev(Call, tiov, tnio, wlen); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ + Pos += wlen; #if FS_STATS_DETAILED /* * Bump the number of bytes actually sent by the number from this @@ -7145,16 +7146,16 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, #endif /* FS_STATS_DETAILED */ if (nBytes != wlen) { FDH_CLOSE(fdP); -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV FreeSendBuffer((struct afs_buffer *)tbuffer); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ return -31; } Len -= wlen; } -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV FreeSendBuffer((struct afs_buffer *)tbuffer); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ FDH_CLOSE(fdP); FT_GetTimeOfDay(&StopTime, 0); @@ -7249,12 +7250,12 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */ struct timeval StartTime, StopTime; /* Used to measure how long the store takes */ Error errorCode = 0; /* Returned error code to caller */ -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV char *tbuffer; /* data copying buffer */ -#else /* AFS_NT40_ENV */ +#else /* HAVE_PIOV */ struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */ int tnio; /* temp for iovec size */ -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ afs_sfsize_t tlen; /* temp for xfr length */ Inode tinode; /* inode for I/O */ afs_int32 optSize; /* optimal transfer size */ @@ -7409,12 +7410,10 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */ if (FileLength < DataLength) FDH_TRUNC(fdP, FileLength); - if (Pos > 0) - FDH_SEEK(fdP, Pos, 0); bytesTransfered = 0; -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV tbuffer = AllocSendBuffer(); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ /* if length == 0, the loop below isn't going to do anything, including * extend the length of the inode, which it must do, since the file system * assumes that the inode length == vnode's file length. So, we extend @@ -7426,7 +7425,7 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, /* Set the file's length; we've already done an lseek to the right * spot above. */ - nBytes = FDH_WRITE(fdP, &tlen, 1); + nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos); if (nBytes != 1) { errorCode = -1; goto done; @@ -7448,11 +7447,11 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, rlen = optSize; /* bound by buffer size */ else rlen = (int)tlen; -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV errorCode = rx_Read(Call, tbuffer, rlen); -#else /* AFS_NT40_ENV */ +#else /* HAVE_PIOV */ errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ if (errorCode <= 0) { errorCode = -32; break; @@ -7461,22 +7460,23 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, (*a_bytesStoredP) += errorCode; #endif /* FS_STATS_DETAILED */ rlen = errorCode; -#ifdef AFS_NT40_ENV - nBytes = FDH_WRITE(fdP, tbuffer, rlen); -#else /* AFS_NT40_ENV */ - nBytes = FDH_WRITEV(fdP, tiov, tnio); -#endif /* AFS_NT40_ENV */ +#ifndef HAVE_PIOV + nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos); +#else /* HAVE_PIOV */ + nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos); +#endif /* HAVE_PIOV */ if (nBytes != rlen) { errorCode = VDISKFULL; break; } bytesTransfered += rlen; + Pos += rlen; } } done: -#ifdef AFS_NT40_ENV +#ifndef HAVE_PIOV FreeSendBuffer((struct afs_buffer *)tbuffer); -#endif /* AFS_NT40_ENV */ +#endif /* HAVE_PIOV */ if (sync) { FDH_SYNC(fdP); } diff --git a/src/viced/physio.c b/src/viced/physio.c index cf9ed61bed..3d23cbdc14 100644 --- a/src/viced/physio.c +++ b/src/viced/physio.c @@ -63,17 +63,7 @@ ReallyRead(DirHandle * file, int block, char *data) ih_ino), code)); return code; } - if (FDH_SEEK(fdP, block * PAGESIZE, SEEK_SET) < 0) { - code = errno; - ViceLog(0, - ("ReallyRead(): lseek failed device %X inode %s errno %d\n", - file->dirh_handle->ih_dev, PrintInode(NULL, - file->dirh_handle-> - ih_ino), code)); - FDH_REALLYCLOSE(fdP); - return code; - } - rdlen = FDH_READ(fdP, data, PAGESIZE); + rdlen = FDH_PREAD(fdP, data, PAGESIZE, ((afs_foff_t)block) * PAGESIZE); if (rdlen != PAGESIZE) { if (rdlen < 0) code = errno; @@ -109,17 +99,7 @@ ReallyWrite(DirHandle * file, int block, char *data) lpErrno = errno; return 0; } - if (FDH_SEEK(fdP, block * PAGESIZE, SEEK_SET) < 0) { - ViceLog(0, - ("ReallyWrite(): lseek failed device %X inode %s errno %d\n", - file->dirh_handle->ih_dev, PrintInode(NULL, - file->dirh_handle-> - ih_ino), errno)); - lpErrno = errno; - FDH_REALLYCLOSE(fdP); - return 0; - } - if ((count = FDH_WRITE(fdP, data, PAGESIZE)) != PAGESIZE) { + if ((count = FDH_PWRITE(fdP, data, PAGESIZE, ((afs_foff_t)block) * PAGESIZE)) != PAGESIZE) { ViceLog(0, ("ReallyWrite(): write failed device %X inode %s errno %d\n", file->dirh_handle->ih_dev, PrintInode(NULL, diff --git a/src/vol/clone.c b/src/vol/clone.c index de7091b1a3..b856cdb9df 100644 --- a/src/vol/clone.c +++ b/src/vol/clone.c @@ -189,7 +189,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) rwfile = FDH_FDOPEN(rwFd, ReadWriteOriginal ? "r+" : "r"); if (!rwfile) ERROR_EXIT(EIO); - STREAM_SEEK(rwfile, vcp->diskSize, 0); /* Will fail if no vnodes */ + STREAM_ASEEK(rwfile, vcp->diskSize); /* Will fail if no vnodes */ /* Open the clone volume's index file and seek to beginning */ IH_COPY(clHout, clvp->vnodeIndex[class].handle); @@ -199,7 +199,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) clfileout = FDH_FDOPEN(clFdOut, "a"); if (!clfileout) ERROR_EXIT(EIO); - code = STREAM_SEEK(clfileout, vcp->diskSize, 0); + code = STREAM_ASEEK(clfileout, vcp->diskSize); if (code) ERROR_EXIT(EIO); @@ -215,7 +215,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) clfilein = FDH_FDOPEN(clFdIn, "r"); if (!clfilein) ERROR_EXIT(EIO); - STREAM_SEEK(clfilein, vcp->diskSize, 0); /* Will fail if no vnodes */ + STREAM_ASEEK(clfilein, vcp->diskSize); /* Will fail if no vnodes */ } /* Initialize list of inodes to nuke */ @@ -282,14 +282,14 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) rwvnode->dataVersion++; #endif /* DVINC */ rwvnode->cloned = 1; - code = STREAM_SEEK(rwfile, offset, 0); + code = STREAM_ASEEK(rwfile, offset); if (code == -1) goto clonefailed; code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile); if (code != 1) goto clonefailed; dircloned = 1; - code = STREAM_SEEK(rwfile, offset + vcp->diskSize, 0); + code = STREAM_ASEEK(rwfile, offset + vcp->diskSize); if (code == -1) goto clonefailed; #ifdef DVINC @@ -318,7 +318,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) /* And if the directory was marked clone, unmark it */ if (dircloned) { rwvnode->cloned = 0; - if (STREAM_SEEK(rwfile, offset, 0) != -1) + if (STREAM_ASEEK(rwfile, offset) != -1) (void)STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile); } ERROR_EXIT(EIO); @@ -336,7 +336,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) /* Clean out any junk at end of clone file */ if (reclone) { - STREAM_SEEK(clfilein, offset, 0); + STREAM_ASEEK(clfilein, offset); while (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1) { if (clvnode->type != vNull && VNDISK_GET_INO(clvnode) != 0) { ci_AddItem(&decHead, VNDISK_GET_INO(clvnode)); diff --git a/src/vol/ihandle.c b/src/vol/ihandle.c index 2c312dea65..7cb0ae690c 100644 --- a/src/vol/ihandle.c +++ b/src/vol/ihandle.c @@ -299,6 +299,7 @@ fdHandleAllocateChunk(void) osi_Assert(fdP != NULL); for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) { fdP[i].fd_status = FD_HANDLE_AVAIL; + fdP[i].fd_refcnt = 0; fdP[i].fd_ih = NULL; fdP[i].fd_fd = INVALID_FD; DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev); @@ -340,12 +341,23 @@ ih_open(IHandle_t * ihP) /* Do we already have an open file handle for this Inode? */ for (fdP = ihP->ih_fdtail; fdP != NULL; fdP = fdP->fd_ihprev) { +#ifndef HAVE_PIO + /* + * If we don't have positional i/o, don't try to share fds, since + * we can't do so in a threadsafe way. + */ if (fdP->fd_status != FD_HANDLE_INUSE) { - fdP->fd_status = FD_HANDLE_INUSE; - DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); + osi_Assert(fdP->fd_status == FD_HANDLE_OPEN); +#else /* HAVE_PIO */ + if (fdP->fd_status != FD_HANDLE_AVAIL) { +#endif /* HAVE_PIO */ + fdP->fd_refcnt++; + if (fdP->fd_status == FD_HANDLE_OPEN) { + fdP->fd_status = FD_HANDLE_INUSE; + DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); + } ihP->ih_refcnt++; IH_UNLOCK; - (void)FDH_SEEK(fdP, 0, SEEK_SET); return fdP; } } @@ -398,6 +410,7 @@ ih_open_retry: fdP->fd_status = FD_HANDLE_INUSE; fdP->fd_fd = fd; fdP->fd_ih = ihP; + fdP->fd_refcnt++; ihP->ih_refcnt++; @@ -444,9 +457,12 @@ fd_close(FdHandle_t * fdP) return fd_reallyclose(fdP); } + fdP->fd_refcnt--; + if (fdP->fd_refcnt == 0) { /* Put this descriptor back into the cache */ fdP->fd_status = FD_HANDLE_OPEN; DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); + } /* If this is not the only reference to the Inode then we can decrement * the reference count, otherwise we need to call ih_release. @@ -482,13 +498,17 @@ fd_reallyclose(FdHandle_t * fdP) ihP = fdP->fd_ih; closeFd = fdP->fd_fd; + fdP->fd_refcnt--; + if (fdP->fd_refcnt == 0) { DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev); DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev); fdP->fd_status = FD_HANDLE_AVAIL; + fdP->fd_refcnt = 0; fdP->fd_ih = NULL; fdP->fd_fd = INVALID_FD; + } /* All the file descriptor handles have been closed; reset * the IH_REALLY_CLOSED flag indicating that ih_reallyclose @@ -498,10 +518,12 @@ fd_reallyclose(FdHandle_t * fdP) ihP->ih_flags &= ~IH_REALLY_CLOSED; } + if (fdP->fd_refcnt == 0) { IH_UNLOCK; OS_CLOSE(closeFd); IH_LOCK; fdInUseCount -= 1; + } /* If this is not the only reference to the Inode then we can decrement * the reference count, otherwise we need to call ih_release. */ @@ -532,6 +554,7 @@ stream_fdopen(FD_t fd) streamP->str_fd = fd; streamP->str_buflen = 0; streamP->str_bufoff = 0; + streamP->str_fdoff = 0; streamP->str_error = 0; streamP->str_eof = 0; streamP->str_direction = STREAM_DIRECTION_NONE; @@ -590,8 +613,8 @@ stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems, if (streamP->str_buflen == 0) { streamP->str_bufoff = 0; streamP->str_buflen = - OS_READ(streamP->str_fd, streamP->str_buffer, - STREAM_HANDLE_BUFSIZE); + OS_PREAD(streamP->str_fd, streamP->str_buffer, + STREAM_HANDLE_BUFSIZE, streamP->str_fdoff); if (streamP->str_buflen < 0) { streamP->str_error = errno; streamP->str_buflen = 0; @@ -601,6 +624,7 @@ stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems, streamP->str_eof = 1; break; } + streamP->str_fdoff += streamP->str_buflen; } bytesToRead = nbytes; @@ -641,13 +665,14 @@ stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems, p = (char *)ptr; while (nbytes > 0) { if (streamP->str_buflen == 0) { - rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, - STREAM_HANDLE_BUFSIZE); + rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer, + STREAM_HANDLE_BUFSIZE, streamP->str_fdoff); if (rc < 0) { streamP->str_error = errno; bytesWritten = 0; break; } + streamP->str_fdoff += rc; streamP->str_bufoff = 0; streamP->str_buflen = STREAM_HANDLE_BUFSIZE; } @@ -669,28 +694,25 @@ stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems, /* fseek for buffered I/O handles */ int -stream_seek(StreamHandle_t * streamP, afs_foff_t offset, int whence) +stream_aseek(StreamHandle_t * streamP, afs_foff_t offset) { ssize_t rc; int retval = 0; if (streamP->str_direction == STREAM_DIRECTION_WRITE && streamP->str_bufoff > 0) { - rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, - streamP->str_bufoff); + rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer, + streamP->str_bufoff, streamP->str_fdoff); if (rc < 0) { streamP->str_error = errno; retval = -1; } } + streamP->str_fdoff = offset; streamP->str_bufoff = 0; streamP->str_buflen = 0; streamP->str_eof = 0; streamP->str_direction = STREAM_DIRECTION_NONE; - if (OS_SEEK(streamP->str_fd, offset, whence) < 0) { - streamP->str_error = errno; - retval = -1; - } return retval; } @@ -703,11 +725,13 @@ stream_flush(StreamHandle_t * streamP) if (streamP->str_direction == STREAM_DIRECTION_WRITE && streamP->str_bufoff > 0) { - rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, - streamP->str_bufoff); + rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer, + streamP->str_bufoff, streamP->str_fdoff); if (rc < 0) { streamP->str_error = errno; retval = -1; + } else { + streamP->str_fdoff += rc; } streamP->str_bufoff = 0; streamP->str_buflen = STREAM_HANDLE_BUFSIZE; @@ -726,10 +750,12 @@ stream_close(StreamHandle_t * streamP, int reallyClose) osi_Assert(streamP != NULL); if (streamP->str_direction == STREAM_DIRECTION_WRITE && streamP->str_bufoff > 0) { - rc = OS_WRITE(streamP->str_fd, streamP->str_buffer, - streamP->str_bufoff); + rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer, + streamP->str_bufoff, streamP->str_fdoff); if (rc < 0) { retval = -1; + } else { + streamP->str_fdoff += rc; } } if (reallyClose) { @@ -806,6 +832,7 @@ ih_fdclose(IHandle_t * ihP) for (fdP = head; fdP != NULL; fdP = fdP->fd_next) { OS_CLOSE(fdP->fd_fd); fdP->fd_status = FD_HANDLE_AVAIL; + fdP->fd_refcnt = 0; fdP->fd_fd = INVALID_FD; fdP->fd_ih = NULL; closeCount++; @@ -1018,3 +1045,25 @@ ih_size(int fd) return status.st_size; } #endif + +#ifndef HAVE_PIO +ssize_t +ih_pread(int fd, void * buf, size_t count, afs_foff_t offset) +{ + afs_foff_t code; + code = OS_SEEK(fd, offset, 0); + if (code < 0) + return code; + return OS_READ(fd, buf, count); +} + +ssize_t +ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset) +{ + afs_foff_t code; + code = OS_SEEK(fd, offset, 0); + if (code < 0) + return code; + return OS_WRITE(fd, buf, count); +} +#endif /* !HAVE_PIO */ diff --git a/src/vol/ihandle.h b/src/vol/ihandle.h index fb206d8974..ea4411e18e 100644 --- a/src/vol/ihandle.h +++ b/src/vol/ihandle.h @@ -155,6 +155,7 @@ typedef int FD_t; /* file descriptor handle */ typedef struct FdHandle_s { int fd_status; /* status flags */ + int fd_refcnt; /* refcnt */ FD_t fd_fd; /* file descriptor */ struct IHandle_s *fd_ih; /* Pointer to Inode handle */ struct FdHandle_s *fd_next; /* LRU/Avail list pointers */ @@ -175,6 +176,7 @@ typedef struct StreamHandle_s { int str_direction; /* current read/write direction */ afs_sfsize_t str_buflen; /* bytes remaining in buffer */ afs_foff_t str_bufoff; /* current offset into buffer */ + afs_foff_t str_fdoff; /* current offset into file */ int str_error; /* error code */ int str_eof; /* end of file flag */ struct StreamHandle_s *str_next; /* Avail list pointers */ @@ -305,8 +307,7 @@ extern afs_sfsize_t stream_read(void *ptr, afs_fsize_t size, extern afs_sfsize_t stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems, StreamHandle_t * streamP); -extern int stream_seek(StreamHandle_t * streamP, afs_foff_t offset, - int whence); +extern int stream_aseek(StreamHandle_t * streamP, afs_foff_t offset); extern int stream_flush(StreamHandle_t * streamP); extern int stream_close(StreamHandle_t * streamP, int reallyClose); extern int ih_reallyclose(IHandle_t * ihP); @@ -336,7 +337,7 @@ extern int ih_condsync(IHandle_t * ihP); #define STREAM_WRITE(A, B, C, H) stream_write(A, B, C, H) -#define STREAM_SEEK(H, A, B) stream_seek(H, A, B) +#define STREAM_ASEEK(H, A) stream_aseek(H, A) #define STREAM_FLUSH(H) stream_flush(H) @@ -428,6 +429,8 @@ extern int OS_OPEN(const char *F, int M, mode_t P); extern int OS_CLOSE(int FD); extern ssize_t OS_READ(int FD, void *B, size_t S); extern ssize_t OS_WRITE(int FD, void *B, size_t S); +extern ssize_t OS_PREAD(int FD, void *B, size_t S, afs_foff_t O); +extern ssize_t OS_PWRITE(int FD, void *B, size_t S, afs_foff_t O); extern int OS_SYNC(int FD); extern afs_sfsize_t OS_SIZE(int FD); extern int IH_INC(IHandle_t * H, Inode I, int /*@alt VolId, VolumeId @ */ P); @@ -499,8 +502,6 @@ extern Inode ih_icreate(IHandle_t * ih, int dev, char *part, Inode nI, int p1, #define OS_OPEN(F, M, P) open(F, M, P) #define OS_CLOSE(FD) close(FD) -#define OS_READ(FD, B, S) read(FD, B, S) -#define OS_WRITE(FD, B, S) write(FD, B, S) #ifdef O_LARGEFILE #define OS_SEEK(FD, O, F) lseek64(FD, (off64_t) (O), F) #else /* !O_LARGEFILE */ @@ -538,6 +539,13 @@ extern afs_sfsize_t ih_size(int fd); #define FDH_WRITEV(H, I, N) writev((H)->fd_fd, I, N) #endif +#ifdef HAVE_PIOV +#define FDH_PREADV(H, I, N, O) preadv((H)->fd_fd, I, N, O) +#define FDH_PWRITEV(H, I, N, O) pwritev((H)->fd_fd, I, N, O) +#endif + +#define FDH_PREAD(H, B, S, O) OS_PREAD((H)->fd_fd, B, S, O) +#define FDH_PWRITE(H, B, S, O) OS_PWRITE((H)->fd_fd, B, S, O) #define FDH_READ(H, B, S) OS_READ((H)->fd_fd, B, S) #define FDH_WRITE(H, B, S) OS_WRITE((H)->fd_fd, B, S) #define FDH_SEEK(H, O, F) OS_SEEK((H)->fd_fd, O, F) diff --git a/src/vol/listinodes.c b/src/vol/listinodes.c index 44ab446b22..9c52462fb0 100644 --- a/src/vol/listinodes.c +++ b/src/vol/listinodes.c @@ -1306,12 +1306,12 @@ bread(int fd, char *buf, daddr_t blk, afs_int32 size) #endif /* AFS_LINUX20_ENV */ static afs_int32 -convertVolumeInfo(int fdr, int fdw, afs_uint32 vid) +convertVolumeInfo(FdHandle_t *fdhr, FdHandle_t *fdhw, afs_uint32 vid) { struct VolumeDiskData vd; char *p; - if (read(fdr, &vd, sizeof(struct VolumeDiskData)) != + if (FDH_PREAD(fdhr, &vd, sizeof(struct VolumeDiskData), 0) != sizeof(struct VolumeDiskData)) { Log("1 convertiVolumeInfo: read failed for %lu with code %d\n", vid, errno); @@ -1331,7 +1331,7 @@ convertVolumeInfo(int fdr, int fdw, afs_uint32 vid) memset(p, 0, 9); } - if (write(fdw, &vd, sizeof(struct VolumeDiskData)) != + if (FDH_PWRITE(fdhw, &vd, sizeof(struct VolumeDiskData), 0) != sizeof(struct VolumeDiskData)) { Log("1 convertiVolumeInfo: write failed for %lu with code %d\n", vid, errno); @@ -1395,6 +1395,7 @@ inode_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId) struct VolumeDiskHeader h; IHandle_t *ih, *ih2; FdHandle_t *fdP, *fdP2; + ssize_t offset; char wpath[100]; char tmpDevName[100]; char buffer[128]; @@ -1475,19 +1476,21 @@ inode_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId) } if (j == VI_VOLINFO) - convertVolumeInfo(fdP->fd_fd, fdP2->fd_fd, ih2->ih_vid); + convertVolumeInfo(fdP, fdP2, ih2->ih_vid); else { + offset = 0; while (1) { - len = read(fdP->fd_fd, buffer, sizeof(buffer)); + len = FDH_PREAD(fdP, buffer, sizeof(buffer), offset); if (len < 0) return errno; if (len == 0) break; - nBytes = write(fdP2->fd_fd, buffer, len); + nBytes = FDH_PWRITE(fdP2, buffer, len, offset); if (nBytes != len) { code = -1; goto done; } + offset += len; } } diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 520f2f0685..e408c15c20 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -47,18 +47,14 @@ /*@+fcnmacros +macrofcndecl@*/ #ifdef O_LARGEFILE #ifdef S_SPLINT_S -extern off64_t afs_lseek(int FD, off64_t O, int F); #endif /*S_SPLINT_S */ -#define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F) #define afs_stat stat64 #define afs_fstat fstat64 #define afs_open open64 #define afs_fopen fopen64 #else /* !O_LARGEFILE */ #ifdef S_SPLINT_S -extern off_t afs_lseek(int FD, off_t O, int F); #endif /*S_SPLINT_S */ -#define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F) #define afs_stat stat #define afs_fstat fstat #define afs_open open @@ -111,12 +107,7 @@ namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size) if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - FDH_REALLYCLOSE(fdP); - return -1; - } - - nBytes = FDH_READ(fdP, buf, size); + nBytes = FDH_PREAD(fdP, buf, size, offset); FDH_CLOSE(fdP); return nBytes; } @@ -131,11 +122,7 @@ namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size) if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - FDH_REALLYCLOSE(fdP); - return -1; - } - nBytes = FDH_WRITE(fdP, buf, size); + nBytes = FDH_PWRITE(fdP, buf, size, offset); FDH_CLOSE(fdP); return nBytes; } @@ -825,6 +812,7 @@ namei_copy_on_write(IHandle_t *h) namei_t name; FdHandle_t *fdP; struct afs_stat tstat; + afs_foff_t offset; namei_HandleToName(&name, h); if (afs_stat(name.n_path, &tstat) < 0) @@ -852,14 +840,15 @@ namei_copy_on_write(IHandle_t *h) return ENOMEM; } size = tstat.st_size; - FDH_SEEK(fdP, 0, 0); + offset = 0; while (size) { tlen = size > 8192 ? 8192 : size; - if (FDH_READ(fdP, buf, tlen) != tlen) + if (FDH_PREAD(fdP, buf, tlen, offset) != tlen) break; if (write(fd, buf, tlen) != tlen) break; size -= tlen; + offset += tlen; } close(fd); FDH_REALLYCLOSE(fdP); @@ -988,10 +977,7 @@ namei_GetLinkCount2(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrit return -1; } - if (afs_lseek(h->fd_fd, offset, SEEK_SET) == -1) - goto bad_getLinkByte; - - rc = read(h->fd_fd, (char *)&row, sizeof(row)); + rc = FDH_PREAD(h, (char*)&row, sizeof(row), offset); if ((rc == 0 || !((row >> index) & NAMEI_TAGMASK)) && fixup && nowrite) return 1; if (rc == 0 && fixup) { @@ -1000,7 +986,7 @@ namei_GetLinkCount2(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrit goto bad_getLinkByte; FDH_TRUNC(h, offset+sizeof(row)); row = 1 << index; - rc = write(h->fd_fd, (char *)&row, sizeof(row)); + rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset); } if (rc != sizeof(row)) { goto bad_getLinkByte; @@ -1008,9 +994,7 @@ namei_GetLinkCount2(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrit if (fixup && !((row >> index) & NAMEI_TAGMASK)) { row |= 1<fd_fd, offset, SEEK_SET) == -1) - goto bad_getLinkByte; - rc = write(h->fd_fd, (char *)&row, sizeof(row)); + rc = FDH_PWRITE(h, (char *)&row, sizeof(row), offset); if (rc != sizeof(row)) goto bad_getLinkByte; } @@ -1052,11 +1036,8 @@ GetFreeTag(IHandle_t * ih, int vno) } offset = (vno << LINKTABLE_SHIFT) + 8; /* * 2 + sizeof stamp */ - if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { - goto badGetFreeTag; - } - nBytes = read(fdP->fd_fd, (char *)&row, sizeof(row)); + nBytes = FDH_PREAD(fdP, (char *)&row, sizeof(row), offset); if (nBytes != sizeof(row)) { if (nBytes != 0) goto badGetFreeTag; @@ -1077,10 +1058,7 @@ GetFreeTag(IHandle_t * ih, int vno) coldata = 1 << (col * 3); row |= coldata; - if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { - goto badGetFreeTag; - } - if (write(fdP->fd_fd, (char *)&row, sizeof(row)) != sizeof(row)) { + if (FDH_PWRITE(fdP, (char *)&row, sizeof(row), offset) != sizeof(row)) { goto badGetFreeTag; } FDH_SYNC(fdP); @@ -1116,13 +1094,8 @@ namei_SetLinkCount(FdHandle_t * fdP, Inode ino, int count, int locked) return -1; } } - if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { - errno = EBADF; - goto bad_SetLinkCount; - } - - nBytes = read(fdP->fd_fd, (char *)&row, sizeof(row)); + nBytes = FDH_PREAD(fdP, (char *)&row, sizeof(row), offset); if (nBytes != sizeof(row)) { if (nBytes != 0) { errno = EBADF; @@ -1136,12 +1109,7 @@ namei_SetLinkCount(FdHandle_t * fdP, Inode ino, int count, int locked) row &= (unsigned short)~junk; row |= (unsigned short)count; - if (afs_lseek(fdP->fd_fd, offset, SEEK_SET) == -1) { - errno = EBADF; - goto bad_SetLinkCount; - } - - if (write(fdP->fd_fd, (char *)&row, sizeof(short)) != sizeof(short)) { + if (FDH_PWRITE(fdP, (char *)&row, sizeof(short), offset) != sizeof(short)) { errno = EBADF; goto bad_SetLinkCount; } diff --git a/src/vol/ntops.c b/src/vol/ntops.c index c14156c93e..835bc5124a 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -233,12 +233,7 @@ nt_iread(IHandle_t * h, int offset, char *buf, int size) if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - FDH_REALLYCLOSE(fdP); - return -1; - } - - nBytes = FDH_READ(fdP, buf, size); + nBytes = FDH_PREAD(fdP, buf, size, offset); FDH_CLOSE(fdP); return nBytes; } @@ -253,11 +248,7 @@ nt_iwrite(IHandle_t * h, int offset, char *buf, int size) if (fdP == NULL) return -1; - if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - FDH_REALLYCLOSE(fdP); - return -1; - } - nBytes = FDH_WRITE(fdP, buf, size); + nBytes = FDH_PWRITE(fdP, buf, size, offset); FDH_CLOSE(fdP); return nBytes; } diff --git a/src/vol/physio.c b/src/vol/physio.c index 70f254b305..bc9c900435 100644 --- a/src/vol/physio.c +++ b/src/vol/physio.c @@ -55,12 +55,8 @@ ReallyRead(DirHandle * file, int block, char *data) code = errno; return code; } - if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) { - code = errno; - FDH_REALLYCLOSE(fdP); - return code; - } - nBytes = FDH_READ(fdP, data, (afs_fsize_t) AFS_PAGESIZE); + nBytes = FDH_PREAD(fdP, data, (afs_fsize_t) AFS_PAGESIZE, + ((afs_foff_t)block) * AFS_PAGESIZE); if (nBytes != AFS_PAGESIZE) { if (nBytes < 0) code = errno; @@ -89,12 +85,8 @@ ReallyWrite(DirHandle * file, int block, char *data) code = errno; return code; } - if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) { - code = errno; - FDH_REALLYCLOSE(fdP); - return code; - } - nBytes = FDH_WRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE); + nBytes = FDH_PWRITE(fdP, data, (afs_fsize_t) AFS_PAGESIZE, + ((afs_foff_t)block) * AFS_PAGESIZE); if (nBytes != AFS_PAGESIZE) { if (nBytes < 0) code = errno; diff --git a/src/vol/purge.c b/src/vol/purge.c index 62b0cfa277..783e5d9080 100644 --- a/src/vol/purge.c +++ b/src/vol/purge.c @@ -127,7 +127,7 @@ ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile, * We remember the inodes in an array, and idec them after zeroing them in the index. * The reason for these contortions is to make volume deletion idempotent, even * if we crash in the middle of a delete operation. */ - STREAM_SEEK(afile, offset, 0); + STREAM_ASEEK(afile, offset); while (1) { if (iindex >= MAXOBLITATONCE) { break; @@ -148,7 +148,7 @@ ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile, } /* next, obliterate the index and fflush (and fsync) it */ - STREAM_SEEK(afile, *aoffset, 0); /* seek back to start of vnode index region */ + STREAM_ASEEK(afile, *aoffset); /* seek back to start of vnode index region */ memset(buf, 0, sizeof(buf)); /* zero out our proto-vnode */ for (i = 0; i < nscanned; i++) { if (STREAM_WRITE(buf, vcp->diskSize, 1, afile) != 1) diff --git a/src/vol/vnode.c b/src/vol/vnode.c index 57be1fe4cf..463afc5625 100644 --- a/src/vol/vnode.c +++ b/src/vol/vnode.c @@ -760,13 +760,8 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type) *ec = EIO; goto error_encountered; } - if (FDH_SEEK(fdP, off, SEEK_SET) < 0) { - Log("VAllocVnode: can't seek on index file!\n"); - *ec = EIO; - goto error_encountered; - } if (off + vcp->diskSize <= size) { - if (FDH_READ(fdP, &vnp->disk, vcp->diskSize) != vcp->diskSize) { + if (FDH_PREAD(fdP, &vnp->disk, vcp->diskSize, off) != vcp->diskSize) { Log("VAllocVnode: can't read index file!\n"); *ec = EIO; goto error_encountered; @@ -785,7 +780,7 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type) goto error_encountered; } memset(buf, 0, 16 * 1024); - if ((FDH_WRITE(fdP, buf, 16 * 1024)) != 16 * 1024) { + if ((FDH_PWRITE(fdP, buf, 16 * 1024, off)) != 16 * 1024) { Log("VAllocVnode: can't grow vnode index: write failed\n"); *ec = EIO; free(buf); @@ -897,12 +892,7 @@ VnLoad(Error * ec, Volume * vp, Vnode * vnp, PrintInode(NULL, vp->vnodeIndex[class].handle->ih_ino)); *ec = VIO; goto error_encountered_nolock; - } else if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, Vn_id(vnp)), SEEK_SET) - < 0) { - Log("VnLoad: can't seek on index file vn=%u\n", Vn_id(vnp)); - *ec = VIO; - goto error_encountered_nolock; - } else if ((nBytes = FDH_READ(fdP, (char *)&vnp->disk, vcp->diskSize)) + } else if ((nBytes = FDH_PREAD(fdP, (char *)&vnp->disk, vcp->diskSize, vnodeIndexOffset(vcp, Vn_id(vnp)))) != vcp->diskSize) { /* Don't take volume off line if the inumber is out of range * or the inode table is full. */ @@ -1023,14 +1013,7 @@ VnStore(Error * ec, Volume * vp, Vnode * vnp, Log("VnStore: can't open index file!\n"); goto error_encountered; } - if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - Log("VnStore: can't seek on index file! fdp=%"AFS_PTR_FMT - " offset=%d, errno=%d\n", - fdP, (int) offset, errno); - goto error_encountered; - } - - nBytes = FDH_WRITE(fdP, &vnp->disk, vcp->diskSize); + nBytes = FDH_PWRITE(fdP, &vnp->disk, vcp->diskSize, offset); if (nBytes != vcp->diskSize) { /* Don't force volume offline if the inumber is out of * range or the inode table is full. diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index f4eb0168bc..3aa5abe55a 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -780,7 +780,7 @@ PrintVnodes(Volume * vp, VnodeClass class) nVnodes = (size / diskSize) - 1; if (nVnodes > 0) { - STREAM_SEEK(file, diskSize, 0); + STREAM_ASEEK(file, diskSize); } else nVnodes = 0; @@ -811,7 +811,7 @@ PrintVnodes(Volume * vp, VnodeClass class) total = bad = 0; while (1) { ssize_t nBytes; - len = FDH_READ(fdP1, buffer, sizeof(buffer)); + len = FDH_PREAD(fdP1, buffer, sizeof(buffer), total); if (len < 0) { FDH_REALLYCLOSE(fdP1); IH_RELEASE(ih1); diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 419087ad02..a8df24c47b 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -1760,7 +1760,7 @@ CreateLinkTable(struct InodeSummary *isp, Inode ino) version.magic = LINKTABLEMAGIC; version.version = LINKTABLEVERSION; - if (FDH_WRITE(fdP, (char *)&version, sizeof(version)) + if (FDH_PWRITE(fdP, (char *)&version, sizeof(version), 0) != sizeof(version)) Abort("Can't truncate link table for volume %u (error = %d)\n", isp->RWvolumeId, errno); @@ -2366,7 +2366,7 @@ SalvageHeader(struct stuff *sp, struct InodeSummary *isp, int check, sp->description, errno); if (!recreate - && (FDH_READ(fdP, (char *)&header, sp->size) != sp->size + && (FDH_PREAD(fdP, (char *)&header, sp->size, 0) != sp->size || header.fileHeader.magic != sp->stamp.magic)) { if (check) { Log("Part of the header (%s) is corrupted\n", sp->description); @@ -2417,14 +2417,9 @@ SalvageHeader(struct stuff *sp, struct InodeSummary *isp, int check, header.volumeInfo.needsCallback = 0; gettimeofday(&tp, 0); header.volumeInfo.creationDate = tp.tv_sec; - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - Abort - ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n", - sp->description, errno); - } nBytes = - FDH_WRITE(fdP, (char *)&header.volumeInfo, - sizeof(header.volumeInfo)); + FDH_PWRITE(fdP, (char *)&header.volumeInfo, + sizeof(header.volumeInfo), 0); if (nBytes != sizeof(header.volumeInfo)) { if (nBytes < 0) Abort @@ -2434,12 +2429,7 @@ SalvageHeader(struct stuff *sp, struct InodeSummary *isp, int check, sp->description); } } else { - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - Abort - ("Unable to seek to beginning of volume header file (%s) (errno = %d)\n", - sp->description, errno); - } - nBytes = FDH_WRITE(fdP, (char *)&sp->stamp, sizeof(sp->stamp)); + nBytes = FDH_PWRITE(fdP, (char *)&sp->stamp, sizeof(sp->stamp), 0); if (nBytes != sizeof(sp->stamp)) { if (nBytes < 0) Abort @@ -2528,7 +2518,7 @@ SalvageIndex(Inode ino, VnodeClass class, int RW, nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { osi_Assert((nVnodes + 1) * vcp->diskSize == size); - osi_Assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); } else { nVnodes = 0; } @@ -3089,7 +3079,7 @@ JudgeEntry(void *dirVal, char *name, afs_int32 vnodeNumber, if (size > 1024) size = 1024; - nBytes = FDH_READ(fdP, buf, size); + nBytes = FDH_PREAD(fdP, buf, size, 0); if (nBytes == size) { buf[size] = '\0'; if ( (*buf != '#' && *buf != '%') || buf[strlen(buf)-1] != '.' ) { @@ -3184,7 +3174,7 @@ DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, Unique * maxu) vip->nVnodes = (size / vcp->diskSize) - 1; if (vip->nVnodes > 0) { osi_Assert((vip->nVnodes + 1) * vcp->diskSize == size); - osi_Assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); osi_Assert((vip->vnodes = (struct VnodeEssence *) calloc(vip->nVnodes, sizeof(struct VnodeEssence))) != NULL); if (class == vLarge) { @@ -4314,14 +4304,17 @@ CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume) IHandle_t *srcH, *destH; FdHandle_t *srcFdP, *destFdP; ssize_t nBytes = 0; + afs_foff_t size = 0; IH_INIT(srcH, device, rwvolume, inode1); srcFdP = IH_OPEN(srcH); osi_Assert(srcFdP != NULL); IH_INIT(destH, device, rwvolume, inode2); destFdP = IH_OPEN(destH); - while ((nBytes = FDH_READ(srcFdP, buf, sizeof(buf))) > 0) - osi_Assert(FDH_WRITE(destFdP, buf, nBytes) == nBytes); + while ((nBytes = FDH_PREAD(srcFdP, buf, sizeof(buf), size)) > 0) { + osi_Assert(FDH_PWRITE(destFdP, buf, nBytes, size) == nBytes); + size += nBytes; + } osi_Assert(nBytes == 0); FDH_REALLYCLOSE(srcFdP); FDH_REALLYCLOSE(destFdP); diff --git a/src/vol/volume.c b/src/vol/volume.c index 1916a651b8..7d294161e1 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -1885,13 +1885,8 @@ ReadHeader(Error * ec, IHandle_t * h, char *to, int size, bit32 magic, return; } - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - *ec = VSALVAGE; - FDH_REALLYCLOSE(fdP); - return; - } vsn = (struct versionStamp *)to; - if (FDH_READ(fdP, to, size) != size || vsn->magic != magic) { + if (FDH_PREAD(fdP, to, size, 0) != size || vsn->magic != magic) { *ec = VSALVAGE; FDH_REALLYCLOSE(fdP); return; @@ -1917,12 +1912,7 @@ WriteVolumeHeader_r(Error * ec, Volume * vp) *ec = VSALVAGE; return; } - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - *ec = VSALVAGE; - FDH_REALLYCLOSE(fdP); - return; - } - if (FDH_WRITE(fdP, (char *)&V_disk(vp), sizeof(V_disk(vp))) + if (FDH_PWRITE(fdP, (char *)&V_disk(vp), sizeof(V_disk(vp)), 0) != sizeof(V_disk(vp))) { *ec = VSALVAGE; FDH_REALLYCLOSE(fdP); @@ -5907,7 +5897,7 @@ VGetBitmap_r(Error * ec, Volume * vp, VnodeClass class) osi_Assert(vip->bitmap != NULL); vip->bitmapOffset = 0; #endif /* BITMAP_LATER */ - if (STREAM_SEEK(file, vcp->diskSize, 0) != -1) { + if (STREAM_ASEEK(file, vcp->diskSize) != -1) { int bitNumber = 0; for (bitNumber = 0; bitNumber < nVnodes + 100; bitNumber++) { if (STREAM_READ(vnode, vcp->diskSize, 1, file) != 1) diff --git a/src/vol/vutil.c b/src/vol/vutil.c index a8e5b25afe..eb6076d015 100644 --- a/src/vol/vutil.c +++ b/src/vol/vutil.c @@ -267,13 +267,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId) PrintInode(NULL, *(p->inode)), errno); goto bad; } - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - Log("VCreateVolume: Problem lseek inode %s (err=%d)\n", - PrintInode(NULL, *(p->inode)), errno); - FDH_REALLYCLOSE(fdP); - goto bad; - } - if (FDH_WRITE(fdP, (char *)&p->stamp, sizeof(p->stamp)) != + if (FDH_PWRITE(fdP, (char *)&p->stamp, sizeof(p->stamp), 0) != sizeof(p->stamp)) { Log("VCreateVolume: Problem writing to inode %s (err=%d)\n", PrintInode(NULL, *(p->inode)), errno); @@ -292,13 +286,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId) PrintInode(NULL, tempHeader.volumeInfo), errno); goto bad; } - if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) { - Log("VCreateVolume: Problem lseek inode %s (err=%d)\n", - PrintInode(NULL, tempHeader.volumeInfo), errno); - FDH_REALLYCLOSE(fdP); - goto bad; - } - if (FDH_WRITE(fdP, (char *)&vol, sizeof(vol)) != sizeof(vol)) { + if (FDH_PWRITE(fdP, (char *)&vol, sizeof(vol), 0) != sizeof(vol)) { Log("VCreateVolume: Problem writing to inode %s (err=%d)\n", PrintInode(NULL, tempHeader.volumeInfo), errno); FDH_REALLYCLOSE(fdP); diff --git a/src/volser/dumpstuff.c b/src/volser/dumpstuff.c index ba9b664d1e..8008f81a58 100644 --- a/src/volser/dumpstuff.c +++ b/src/volser/dumpstuff.c @@ -709,7 +709,7 @@ DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP) afs_sfsize_t nbytes, howBig; ssize_t n; size_t howMany; - afs_foff_t lcode = 0; + afs_foff_t howFar = 0; byte *p; afs_uint32 hi, lo; #ifndef AFS_NT40_ENV @@ -775,8 +775,9 @@ DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP) if (nbytes < howMany) howMany = nbytes; - /* Read the data - unless we know we can't */ - n = (lcode ? 0 : FDH_READ(handleP, p, howMany)); + /* Read the data */ + n = FDH_PREAD(handleP, p, howMany, howFar); + howFar += n; /* If read any good data and we null padded previously, log the * amount that we had null padded. @@ -810,17 +811,7 @@ DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP) /* Now seek over the data we could not get. An error here means we * can't do the next read. */ - lcode = FDH_SEEK(handleP, (size_t)((size - nbytes) + howMany), SEEK_SET); - if (lcode != ((size - nbytes) + howMany)) { - if (lcode < 0) { - Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d: %s\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode, afs_error_message(errno)); - } else { - Log("1 Volser: DumpFile: Error seeking in inode %s for vnode %d\n", PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); - lcode = -1; - } - } else { - lcode = 0; - } + howFar = (size_t)((size - nbytes) + howMany); } /* Now write the data out */ @@ -1003,7 +994,7 @@ DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class, nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { osi_Assert((nVnodes + 1) * vcp->diskSize == size); - osi_Assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); } else nVnodes = 0; for (vnodeIndex = 0; @@ -1135,7 +1126,7 @@ ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep, for (i = 0; i < *sizep; i++) { if (Buf[i]) { cnt++; - STREAM_SEEK(afile, Buf[i], 0); + STREAM_ASEEK(afile, Buf[i]); code = STREAM_READ(vnode, vcp->diskSize, 1, afile); if (code == 1) { if (vnode->type != vNull && VNDISK_GET_INO(vnode)) { @@ -1149,7 +1140,7 @@ ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep, V_parentId(vp)); DOPOLL; } - STREAM_SEEK(afile, Buf[i], 0); + STREAM_ASEEK(afile, Buf[i]); (void)STREAM_WRITE(zero, vcp->diskSize, 1, afile); /* Zero it out */ } Buf[i] = 0; @@ -1179,7 +1170,7 @@ ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep, return -1; } memset(Buf, 0, nVnodes * sizeof(afs_foff_t)); - STREAM_SEEK(afile, offset = vcp->diskSize, 0); + STREAM_ASEEK(afile, offset = vcp->diskSize); while (1) { code = STREAM_READ(vnode, vcp->diskSize, 1, afile); if (code != 1) { @@ -1475,14 +1466,7 @@ ReadVnodes(struct iod *iodp, Volume * vp, int incremental, afs_error_message(errno)); return VOLSERREAD_DUMPERROR; } - if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < - 0) { - Log("1 Volser: ReadVnodes: Error seeking into vnode index: %s; restore aborted\n", - afs_error_message(errno)); - FDH_REALLYCLOSE(fdP); - return VOLSERREAD_DUMPERROR; - } - if (FDH_READ(fdP, &oldvnode, sizeof(oldvnode)) == + if (FDH_PREAD(fdP, &oldvnode, sizeof(oldvnode), vnodeIndexOffset(vcp, vnodeNumber)) == sizeof(oldvnode)) { if (oldvnode.type != vNull && VNDISK_GET_INO(&oldvnode)) { IH_DEC(V_linkHandle(vp), VNDISK_GET_INO(&oldvnode), @@ -1490,14 +1474,7 @@ ReadVnodes(struct iod *iodp, Volume * vp, int incremental, } } vnode->vnodeMagic = vcp->magic; - if (FDH_SEEK(fdP, vnodeIndexOffset(vcp, vnodeNumber), SEEK_SET) < - 0) { - Log("1 Volser: ReadVnodes: Error seeking into vnode index: %s; restore aborted\n", - afs_error_message(errno)); - FDH_REALLYCLOSE(fdP); - return VOLSERREAD_DUMPERROR; - } - if (FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(fdP, vnode, vcp->diskSize, vnodeIndexOffset(vcp, vnodeNumber)) != vcp->diskSize) { Log("1 Volser: ReadVnodes: Error writing vnode index: %s; restore aborted\n", afs_error_message(errno)); FDH_REALLYCLOSE(fdP); @@ -1569,7 +1546,7 @@ volser_WriteFile(int vn, struct iod *iodp, FdHandle_t * handleP, int tag, break; } if (handleP) { - nBytes = FDH_WRITE(handleP, p, size); + nBytes = FDH_PWRITE(handleP, p, size, written); if (nBytes > 0) written += nBytes; if (nBytes != size) { @@ -1892,7 +1869,7 @@ SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class, nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { osi_Assert((nVnodes + 1) * vcp->diskSize == size); - osi_Assert(STREAM_SEEK(file, vcp->diskSize, 0) == 0); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); } else nVnodes = 0; for (vnodeIndex = 0; diff --git a/src/volser/physio.c b/src/volser/physio.c index 95467d4646..e431a36495 100644 --- a/src/volser/physio.c +++ b/src/volser/physio.c @@ -48,12 +48,7 @@ ReallyRead(DirHandle * file, int block, char *data) code = errno; return code; } - if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) { - code = errno; - FDH_REALLYCLOSE(fdP); - return code; - } - nBytes = FDH_READ(fdP, data, AFS_PAGESIZE); + nBytes = FDH_PREAD(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE); if (nBytes != AFS_PAGESIZE) { if (nBytes < 0) code = errno; @@ -82,12 +77,7 @@ ReallyWrite(DirHandle * file, int block, char *data) code = errno; return code; } - if (FDH_SEEK(fdP, ((afs_foff_t)block) * AFS_PAGESIZE, SEEK_SET) < 0) { - code = errno; - FDH_REALLYCLOSE(fdP); - return code; - } - nBytes = FDH_WRITE(fdP, data, AFS_PAGESIZE); + nBytes = FDH_PWRITE(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE); if (nBytes != AFS_PAGESIZE) { if (nBytes < 0) code = errno; diff --git a/src/volser/vol-dump.c b/src/volser/vol-dump.c index 9a90ffd9f5..3067e2ee60 100644 --- a/src/volser/vol-dump.c +++ b/src/volser/vol-dump.c @@ -563,6 +563,7 @@ DumpFile(int dumpfd, int vnode, FdHandle_t * handleP, struct VnodeDiskObject *v afs_sfsize_t nbytes, howBig; ssize_t n; size_t howMany; + afs_foff_t howFar = 0; byte *p; afs_uint32 hi, lo; #ifndef AFS_NT40_ENV @@ -627,7 +628,8 @@ DumpFile(int dumpfd, int vnode, FdHandle_t * handleP, struct VnodeDiskObject *v howMany = nbytes; /* Read the data - unless we know we can't */ - n = (failed_seek ? 0 : FDH_READ(handleP, p, howMany)); + n = (failed_seek ? 0 : FDH_PREAD(handleP, p, howMany, howFar)); + howFar += n; /* If read any good data and we null padded previously, log the * amount that we had null padded. @@ -668,22 +670,7 @@ DumpFile(int dumpfd, int vnode, FdHandle_t * handleP, struct VnodeDiskObject *v /* Now seek over the data we could not get. An error here means we * can't do the next read. */ - failed_seek = FDH_SEEK(handleP, ((size - nbytes) + howMany), SEEK_SET); - if (failed_seek != ((size - nbytes) + howMany)) { - if (failed_seek < 0) { - fprintf(stderr, - "Error %d seeking in inode %s for vnode %d\n", - errno, PrintInode(NULL, handleP->fd_ih->ih_ino), - vnode); - } else { - fprintf(stderr, - "Error seeking in inode %s for vnode %d\n", - PrintInode(NULL, handleP->fd_ih->ih_ino), vnode); - failed_seek = -1; - } - } else { - failed_seek = 0; - } + howFar = ((size - nbytes) + howMany); } /* Now write the data out */ @@ -793,7 +780,7 @@ DumpVnodeIndex(int dumpfd, Volume * vp, VnodeClass class, afs_int32 fromtime, nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { - STREAM_SEEK(file, vcp->diskSize, 0); + STREAM_ASEEK(file, vcp->diskSize); } else nVnodes = 0; for (vnodeIndex = 0; diff --git a/src/volser/vol_split.c b/src/volser/vol_split.c index 73fdeab18a..c34cbbeed7 100644 --- a/src/volser/vol_split.c +++ b/src/volser/vol_split.c @@ -123,7 +123,7 @@ ExtractVnodes(struct Msg *m, Volume *vol, afs_int32 class, code = EIO; goto Bad_Extract; } - code = STREAM_SEEK(stream, vcp->diskSize, 0); + code = STREAM_ASEEK(stream, vcp->diskSize); if (code) goto Bad_Extract; @@ -148,7 +148,7 @@ ExtractVnodes(struct Msg *m, Volume *vol, afs_int32 class, if (class == vLarge) { if (*parent) { offset = (*parent + 1 - class) << (vcp->logSize -1); - code = STREAM_SEEK(stream, offset, 0); + code = STREAM_ASEEK(stream, offset); if (STREAM_READ(vnode, vcp->diskSize, 1, stream) == 1) memcpy(parentvd, vnode, vcp->diskSize); else @@ -252,6 +252,7 @@ copyDir(struct Msg *m, IHandle_t *inh, IHandle_t *outh) FdHandle_t *infdP, *outfdP; char *tbuf; afs_sfsize_t size; + afs_foff_t offset; infdP = IH_OPEN(inh); if (!infdP) { @@ -273,13 +274,12 @@ copyDir(struct Msg *m, IHandle_t *inh, IHandle_t *outh) return EIO; } tbuf = malloc(2048); - FDH_SEEK(infdP, 0, 0); - FDH_SEEK(outfdP, 0, 0); + offset = 0; size = FDH_SIZE(infdP); while (size) { size_t tlen; tlen = size > 2048 ? 2048 : size; - if (FDH_READ(infdP, tbuf, tlen) != tlen) { + if (FDH_PREAD(infdP, tbuf, tlen, offset) != tlen) { sprintf(m->line, "Couldn't read directory %u.%u.%u\n", infdP->fd_ih->ih_vid, (afs_uint32)(infdP->fd_ih->ih_ino & NAMEI_VNODEMASK), @@ -290,7 +290,7 @@ copyDir(struct Msg *m, IHandle_t *inh, IHandle_t *outh) free(tbuf); return EIO; } - if (FDH_WRITE(outfdP, tbuf, tlen) != tlen) { + if (FDH_PWRITE(outfdP, tbuf, tlen, offset) != tlen) { sprintf(m->line, "Couldn't write directory %u.%u.%u\n", outfdP->fd_ih->ih_vid, (afs_uint32)(outfdP->fd_ih->ih_ino & NAMEI_VNODEMASK), @@ -302,6 +302,7 @@ copyDir(struct Msg *m, IHandle_t *inh, IHandle_t *outh) return EIO; } size -= tlen; + offset += tlen; } free(tbuf); FDH_CLOSE(outfdP); @@ -347,8 +348,7 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, if (e->flag) { afs_uint64 size; offset = (e->vN + 1 - class) << (vcp->logSize -1); - if (FDH_SEEK(fdP, offset, 0) != offset - || FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("Couldn't read in %s Index of volume %u at offset %" AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), offset); @@ -380,8 +380,7 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, /* Now update the vnode and write it back to disk */ VNDISK_SET_INO(vnode, newino); vnode->cloned = 0; - if (FDH_SEEK(fdP, offset, 0) != offset - || FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("Couldn't write in %s Index of volume %u at offset %" AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), offset); @@ -428,8 +427,7 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, if (e->flag & CHANGEPARENT) vnode->parent = 1; /* in new root-directory */ vnode->cloned = 0; - if (FDH_SEEK(newfdP, offset, 0) != offset - || FDH_WRITE(newfdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(newfdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("Couldn't write in %s Index of volume %u to offset %" AFS_UINT64_FMT "\n", class ? "small":"large", V_id(newvol), offset); @@ -449,16 +447,14 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, afs_uint64 newoffset; newoffset = vcp->diskSize; - if (FDH_SEEK(newfdP, newoffset, 0) != newoffset - || FDH_READ(newfdP, vnode2, vcp->diskSize) != vcp->diskSize) { + if (FDH_PREAD(newfdP, vnode2, vcp->diskSize, newoffset) != vcp->diskSize) { Log("splitvolume: couldn't read in large Index of new volume %u at offset %u\n", V_id(newvol), vcp->diskSize); code = EIO; goto Bad_Copy; } offset = (where + 1 - class) << (vcp->logSize -1); - if (FDH_SEEK(fdP, offset, 0) != offset - || FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("Couldn't read in large Index of old volume %u at offset %" AFS_UINT64_FMT "\n", V_id(vol), offset); code = EIO; @@ -483,8 +479,7 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, vnode->cloned = 0; vnode->parent = vnode2->parent; vnode->serverModifyTime = vnode2->serverModifyTime; - if (FDH_SEEK(newfdP, newoffset, 0) != newoffset - || FDH_WRITE(newfdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(newfdP, vnode, vcp->diskSize, newoffset) != vcp->diskSize) { Log("splitvolume: couldn't write in large Index of %u at offset %u\n", V_id(newvol), vcp->diskSize); code = EIO; @@ -535,6 +530,7 @@ createMountpoint(Volume *vol, Volume *newvol, struct VnodeDiskObject *parent, struct timeval now; afs_uint32 newvN; char symlink[32]; + ssize_t rc; FT_GetTimeOfDay(&now, 0); fdP = IH_OPEN(vol->vnodeIndex[vSmall].handle); @@ -543,13 +539,18 @@ createMountpoint(Volume *vol, Volume *newvol, struct VnodeDiskObject *parent, return EIO; } offset = vcp->diskSize; - if (FDH_SEEK(fdP, offset, 0) != offset) { - Log("split volume: error seeking in small vnode index of %u\n", V_id(vol)); - return EIO; - } while (1) { - if (FDH_READ(fdP, &vnode, vcp->diskSize) != vcp->diskSize) - break; + rc = FDH_PREAD(fdP, &vnode, vcp->diskSize, offset); + if (rc != vcp->diskSize) { + if (rc < 0) { + Log("split volume: error reading small vnode index of %u\n", V_id(vol)); + return EIO; + } + if (rc == 0) + break; + if (rc < vcp->diskSize) + break; + } if (vnode.type == vNull) break; offset += vcp->diskSize; @@ -583,10 +584,9 @@ createMountpoint(Volume *vol, Volume *newvol, struct VnodeDiskObject *parent, V_id(vol), newvN, vnode.uniquifier); return EIO; } - FDH_SEEK(fdP2, 0, 0); sprintf(symlink, "#%s", V_name(newvol)); size = strlen(symlink) + 1; - if (FDH_WRITE(fdP2, symlink, size) != size) { + if (FDH_PWRITE(fdP2, symlink, size, 0) != size) { Log("split volume: couldn't write mountpoint %u.%u.%u\n", V_id(vol), newvN, vnode.uniquifier); return EIO; @@ -598,8 +598,7 @@ createMountpoint(Volume *vol, Volume *newvol, struct VnodeDiskObject *parent, #ifndef AFS_RXOSD_SUPPORT vnode.vnodeMagic = SMALLVNODEMAGIC; #endif - if (FDH_SEEK(fdP, offset, 0) != offset - || FDH_WRITE(fdP, &vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(fdP, &vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("split volume: couldn't write vnode for mountpoint %u.%u.%u\n", V_id(vol), newvN, vnode.uniquifier); return EIO; @@ -631,8 +630,7 @@ createMountpoint(Volume *vol, Volume *newvol, struct VnodeDiskObject *parent, fdP = IH_OPEN(vol->vnodeIndex[class].handle); offset = (vN + 1 - class) << (vcp->logSize -1); parent->dataVersion++; - if (FDH_SEEK(fdP, offset, 0) != offset - || FDH_WRITE(fdP, parent, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(fdP, parent, vcp->diskSize, offset) != vcp->diskSize) { Log("split volume: couldn't write vnode for parent directory %u.%u.%u\n", V_id(vol), vN, parent->uniquifier); return EIO; @@ -668,14 +666,7 @@ deleteVnodes(Volume *vol, afs_int32 class, e = &list[i]; if (e->flag & NEEDED) { offset = (e->vN + 1 - class) << (vcp->logSize -1); - if (FDH_SEEK(fdP, offset, 0) != offset) { - Log("Couldn't seek in %s Index of volume %u to offset %" - AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), - offset); - code = EIO; - goto Bad_Delete; - } - if (FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("Couldn't read in %s Index of volume %u at offset %" AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), offset); @@ -696,8 +687,7 @@ deleteVnodes(Volume *vol, afs_int32 class, } memset(vnode, 0, vcp->diskSize); vnode->type = vNull; - if (FDH_SEEK(fdP, offset, 0) != offset - || FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) { + if (FDH_PWRITE(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { Log("Couldn't write in %s Index of volume %u to offset %" AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), offset); diff --git a/src/volser/volprocs.c b/src/volser/volprocs.c index a3572affb7..f936d4f49b 100644 --- a/src/volser/volprocs.c +++ b/src/volser/volprocs.c @@ -333,7 +333,6 @@ ViceCreateRoot(Volume *vp) FdHandle_t *fdP; afs_fsize_t length; ssize_t nBytes; - afs_foff_t off; vnode = (struct VnodeDiskObject *)malloc(SIZEOF_LARGEDISKVNODE); if (!vnode) @@ -393,9 +392,7 @@ ViceCreateRoot(Volume *vp) vp->vnodeIndex[vLarge].handle->ih_ino); fdP = IH_OPEN(h); osi_Assert(fdP != NULL); - off = FDH_SEEK(fdP, vnodeIndexOffset(vcp, 1), SEEK_SET); - osi_Assert(off >= 0); - nBytes = FDH_WRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE); + nBytes = FDH_PWRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE, vnodeIndexOffset(vcp, 1)); osi_Assert(nBytes == SIZEOF_LARGEDISKVNODE); FDH_REALLYCLOSE(fdP); IH_RELEASE(h);