From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IPlqY-00038l-Kj for qemu-devel@nongnu.org; Mon, 27 Aug 2007 17:10:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IPlqW-00037a-Hq for qemu-devel@nongnu.org; Mon, 27 Aug 2007 17:10:05 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IPlqW-00037X-CZ for qemu-devel@nongnu.org; Mon, 27 Aug 2007 17:10:04 -0400 Received: from mail.virtualiron.com ([209.213.88.114]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IPlqW-0002Hh-0S for qemu-devel@nongnu.org; Mon, 27 Aug 2007 17:10:04 -0400 Message-ID: <46D338B9.5020409@virtualiron.com> Date: Mon, 27 Aug 2007 16:48:57 -0400 From: Ben Guthro MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000106050108000104060700" Subject: [Qemu-devel] [PATCH] Enhance raw io reliability Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Josh Nicholas This is a multi-part message in MIME format. --------------000106050108000104060700 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit For raw block device only : log any I/O error and perform automatic read retry for CDrom (improves MediaCheck with old installers). Signed-off-by: Ben Guthro Signed-off-by: Josh Nicholas --------------000106050108000104060700 Content-Type: text/x-patch; name="qemu-raw-io-reliability.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-raw-io-reliability.patch" diff -r 808c4b54209f block-raw.c --- a/block-raw.c Fri Aug 10 16:30:38 2007 -0400 +++ b/block-raw.c Fri Aug 10 16:30:38 2007 -0400 @@ -59,6 +59,13 @@ //#define DEBUG_FLOPPY +#define DEBUG_BLOCK +#ifdef DEBUG_BLOCK +#define DEBUG_BLOCK_PRINT( formatCstr, args... ) fprintf( logfile, formatCstr, ##args ); fflush( logfile ) +#else +#define DEBUG_BLOCK_PRINT( formatCstr, args... ) +#endif + #define FTYPE_FILE 0 #define FTYPE_CD 1 #define FTYPE_FD 2 @@ -70,6 +77,7 @@ typedef struct BDRVRawState { typedef struct BDRVRawState { int fd; int type; + unsigned int lseek_err_cnt; #if defined(__linux__) /* linux floppy specific */ int fd_open_flags; @@ -87,6 +95,8 @@ static int raw_open(BlockDriverState *bs BDRVRawState *s = bs->opaque; int fd, open_flags, ret; + s->lseek_err_cnt = 0; + open_flags = O_BINARY; if ((flags & BDRV_O_ACCESS) == O_RDWR) { open_flags |= O_RDWR; @@ -137,8 +147,58 @@ static int raw_pread(BlockDriverState *b if (ret < 0) return ret; - lseek(s->fd, offset, SEEK_SET); + if (lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { + ++(s->lseek_err_cnt); + if(s->lseek_err_cnt <= 10) { + DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %ld, %p, %d) [%ld] lseek failed : %d = %s\n", + s->fd, + bs->filename, + offset, + buf, + count, + bs->total_sectors, errno, strerror(errno) ); + } + return -1; + } + s->lseek_err_cnt=0; + ret = read(s->fd, buf, count); + if (ret == count) + goto label__raw_read__success; + + DEBUG_BLOCK_PRINT("raw_read(%d:%s, %ld, %p, %d) [%ld] read failed %d : %d = %s\n", + s->fd, + bs->filename, + offset, + buf, + count, + bs->total_sectors, + ret, errno, strerror(errno) ); + + if (bs->type == BDRV_TYPE_CDROM) { // Try harder for CDrom + lseek(s->fd, offset, SEEK_SET); + ret = read(s->fd, buf, count); + if (ret == count) + goto label__raw_read__success; + lseek(s->fd, offset, SEEK_SET); + ret = read(s->fd, buf, count); + if (ret == count) + goto label__raw_read__success; + + DEBUG_BLOCK_PRINT("raw_read(%d:%s, %ld, %p, %d) [%ld] retry read failed %d : %d = %s\n", + s->fd, + bs->filename, + offset, + buf, + count, + bs->total_sectors, + ret, errno, strerror(errno) ); + } + + return -1; + +label__raw_read__success: + return ret; } @@ -152,8 +212,38 @@ static int raw_pwrite(BlockDriverState * if (ret < 0) return ret; - lseek(s->fd, offset, SEEK_SET); + if (lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { + ++(s->lseek_err_cnt); + if(s->lseek_err_cnt) { + DEBUG_BLOCK_PRINT("raw_write(%d:%s, %ld, %p, %d) [%ld] lseek failed : %d = %s\n", + s->fd, + bs->filename, + offset, + buf, + count, + bs->total_sectors, errno, strerror(errno) ); + } + return -1; + } + s->lseek_err_cnt = 0; + ret = write(s->fd, buf, count); + if (ret == count) + goto label__raw_write__success; + + DEBUG_BLOCK_PRINT("raw_write(%d:%s, %ld, %p, %d) [%ld] write failed %d : %d = %s\n", + s->fd, + bs->filename, + offset, + buf, + count, + bs->total_sectors, + ret, errno, strerror(errno) ); + + return -1; + +label__raw_write__success: + return ret; } --------------000106050108000104060700--