From: Date: June 29 2006 7:44pm Subject: bk commit into 5.1 tree (petr:1.2225) BUG#20692 List-Archive: http://lists.mysql.com/commits/8506 X-Bug: 20692 Message-Id: <20060629174406.C37E92B53E8@linux.local> Below is the list of changes that have just been committed into a local 5.1 repository of cps. When cps does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2225 06/06/29 21:43:52 petr@stripped +1 -0 Fix Bug#20692 rpl_* tests failure on hpux mysys/my_pread.c 1.11 06/06/29 21:43:34 petr@stripped +55 -11 Fix our implementation of pread/pwrite: we did change the file pointer in our implementation, while the normal preads/pwrites don't. The new code is based on glibc version of pread/pwrite. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: petr # Host: owlet. # Root: /home/cps/mysql/trees/5.1-team --- 1.10/mysys/my_pread.c 2004-10-06 20:14:29 +04:00 +++ 1.11/mysys/my_pread.c 2006-06-29 21:43:34 +04:00 @@ -27,7 +27,7 @@ myf MyFlags) { uint readbytes; - int error; + int error= 0; DBUG_ENTER("my_pread"); DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: 0x%lx Count: %u MyFlags: %d", Filedes, (ulong) offset, Buffer, Count, MyFlags)); @@ -38,17 +38,39 @@ errno=0; /* Linux doesn't reset this */ #endif #ifndef HAVE_PREAD + off_t old_offset; + pthread_mutex_lock(&my_file_info[Filedes].mutex); - readbytes= (uint) -1; - error= (lseek(Filedes, offset, MY_SEEK_SET) == -1L || - (readbytes = (uint) read(Filedes, Buffer, Count)) != Count); + /* + As we cannot change the file pointer, we save the old position, + before seeking to the given offset + */ + + error= (old_offset= lseek(Filedes, 0L, MY_SEEK_CUR)) == -1L || + lseek(Filedes, offset, MY_SEEK_SET) == -1L; + + if (!error) /* Seek was successful */ + { + if ((readbytes = (uint) read(Filedes, Buffer, Count)) == -1L) + my_errno= errno; + + /* + We should seek back, even if read failed. If this fails, + we will return an error. If read failed as well, we will + save the errno from read, not from lseek(). + */ + if ((error= (lseek(Filedes, old_offset, MY_SEEK_SET) == -1L)) && + readbytes != -1L) + my_errno= errno; + } + pthread_mutex_unlock(&my_file_info[Filedes].mutex); #else error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count); + my_errno= errno; #endif - if (error) + if (error || readbytes != Count) { - my_errno=errno; DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", readbytes,Count,Filedes,my_errno)); #ifdef THREAD @@ -89,17 +111,40 @@ for (;;) { #ifndef HAVE_PREAD - int error; + int error= 0; + off_t old_offset; writenbytes= (uint) -1; pthread_mutex_lock(&my_file_info[Filedes].mutex); - error=(lseek(Filedes, offset, MY_SEEK_SET) != -1L && - (writenbytes = (uint) write(Filedes, Buffer, Count)) == Count); + + /* + As we cannot change the file pointer, we save the old position, + before seeking to the given offset + */ + error= ((old_offset= lseek(Filedes, 0L, MY_SEEK_CUR)) == -1L || + lseek(Filedes, offset, MY_SEEK_SET) == -1L); + + if (!error) /* Seek was successful */ + { + if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == -1L) + my_errno= errno; + + /* + We should seek back, even if write failed. If this fails, + we will return an error. If write failed as well, we will + save the errno from write, not from lseek(). + */ + if ((error= (lseek(Filedes, old_offset, MY_SEEK_SET) == -1L)) && + writenbytes != -1L) + my_errno= errno; + } pthread_mutex_unlock(&my_file_info[Filedes].mutex); - if (error) + + if (!error && writenbytes == Count) break; #else if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count) break; + my_errno= errno; #endif if ((int) writenbytes != -1) { /* Safegueard */ @@ -108,7 +153,6 @@ Count-=writenbytes; offset+=writenbytes; } - my_errno=errno; DBUG_PRINT("error",("Write only %d bytes",writenbytes)); #ifndef NO_BACKGROUND #ifdef THREAD