block_sync bugfix & cleanup
PATCH 1/1 block_sync bugfix & cleanup
Hi Julian and Andrew,
This patch reindents some lines of block_sync.c and fixes a small bug. Please apply.
tools/blktap/drivers/block-sync.c +24 -24
@@ -119,24 +119,24 @@ int tdsync_open (struct td_state *s, conreturn (0 - errno);/* Open the file */ - fd =open (name,O_RDWR |O_DIRECT |O_LARGEFILE ); - -if ( (fd ==-1 ) && (errno ==EINVAL ) ) { - -/* Maybe O_DIRECT isn't supported. */ - fd =open (name,O_RDWR |O_LARGEFILE ); -if (fd !=-1 )DPRINTF ("WARNING: Accessing image without" -"O_DIRECT! (%s)\n" , name); - - }else if (fd !=-1 )DPRINTF ("open(%s) with O_DIRECT\n" , name); - -if (fd ==-1 ) { + fd =open (name,O_RDWR |O_DIRECT |O_LARGEFILE ); + +if ( (fd ==-1 ) && (errno ==EINVAL ) ) { + +/* Maybe O_DIRECT isn't supported. */ + fd =open (name,O_RDWR |O_LARGEFILE ); +if (fd !=-1 )DPRINTF ("WARNING: Accessing image without" +"O_DIRECT! (%s)\n" , name); + + }else if (fd !=-1 )DPRINTF ("open(%s) with O_DIRECT\n" , name); + +if (fd ==-1 ) {DPRINTF ("Unable to open [%s]!\n" ,name); - ret =0 - errno; - goto done; - } - - prv->fd = fd; + ret =0 - errno; + goto done; + } + + prv->fd = fd; ret =get_image_info (s, fd); done:
@@ -156,15 +156,15 @@ done:if (ret != (off_t)-1 ) { ret =read (prv->fd, buf, size);if (ret != size) { - ret =0 - errno; + ret = -errno; }else { ret =1 ; } - }else ret =0 - errno; + }else ret = -errno;cb (s, (ret <0 ) ? ret:0 , id, private); -return 1 ; +return ret; } int tdsync_queue_write(struct td_state *s, uint64_t sector,
@@ -174,21 +174,21 @@ done:struct tdsync_state *prv = (struct tdsync_state *)s->private;int size = nb_sectors * s->sector_size;uint64_t offset = sector * (uint64_t )s->sector_size; -int ret =0 ; +int ret; ret =lseek (prv->fd, offset,SEEK_SET );if (ret != (off_t)-1 ) { ret =write (prv->fd, buf, size);if (ret != size) { - ret =0 - errno; + ret = -errno; }else { ret =1 ; } - }else ret =0 - errno; + }else ret = -errno;cb (s, (ret <0 ) ? ret :0 , id, private); -return 1 ; +return ret; }int tdsync_submit (struct td_state *s)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi Jun,
The sync disk hasn't received a lot of use (it's quite slow) and is
intended mostly as a simpledemontrator of writing disk plugins. I'm happy to take cleanups to error handling code, but would rather that they also fix the call in tapdisk to actually handle the error properly -- returning BLKIF_RSP_ERROR to the frontend if the io can't be issued for whatever reason.
Whitespace fixes are fine, but lets do them all at once and in a
separate patch from bug fixes. I can take a look at this for the entirety of the user blktap code next week.
Thanks!
a.
Quoted 9 lines · Jun Koi
Hi Julian and Andrew,
This patch reindents some lines of
block_sync.cand fixes a small bug. Please apply.Signed-off-by Jun Koi <[email protected]>