Commit 42fb2807d9886e485652e7512398b9d5a83bd768

Authored by aliguori
1 parent c2b3b41a

bdrv_write should not stop on partial write (Gleb Natapov)

Should return real error instead.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6323 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 14 additions and 13 deletions
@@ -565,21 +565,22 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, @@ -565,21 +565,22 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
565 if (bs->read_only) 565 if (bs->read_only)
566 return -EACCES; 566 return -EACCES;
567 if (drv->bdrv_pwrite) { 567 if (drv->bdrv_pwrite) {
568 - int ret, len; 568 + int ret, len, count = 0;
569 len = nb_sectors * 512; 569 len = nb_sectors * 512;
570 - ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len);  
571 - if (ret < 0)  
572 - return ret;  
573 - else if (ret != len)  
574 - return -EIO;  
575 - else {  
576 - bs->wr_bytes += (unsigned) len;  
577 - bs->wr_ops ++;  
578 - return 0;  
579 - }  
580 - } else {  
581 - return drv->bdrv_write(bs, sector_num, buf, nb_sectors); 570 + do {
  571 + ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len - count);
  572 + if (ret < 0) {
  573 + printf("bdrv_write ret=%d\n", ret);
  574 + return ret;
  575 + }
  576 + count += ret;
  577 + buf += ret;
  578 + } while (count != len);
  579 + bs->wr_bytes += (unsigned) len;
  580 + bs->wr_ops ++;
  581 + return 0;
582 } 582 }
  583 + return drv->bdrv_write(bs, sector_num, buf, nb_sectors);
583 } 584 }
584 585
585 static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, 586 static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,