Diff for /qemu/block.c between versions 1.1.1.5 and 1.1.1.6

version 1.1.1.5, 2018/04/24 16:44:58 version 1.1.1.6, 2018/04/24 16:47:23
Line 1 Line 1
 /*  /*
  * QEMU System Emulator block driver   * QEMU System Emulator block driver
  *    *
  * Copyright (c) 2003 Fabrice Bellard   * Copyright (c) 2003 Fabrice Bellard
  *    *
  * Permission is hereby granted, free of charge, to any person obtaining a copy   * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal   * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights   * in the Software without restriction, including without limitation the rights
Line 21 Line 21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.   * THE SOFTWARE.
  */   */
 #include "vl.h"  #include "qemu-common.h"
   #ifndef QEMU_IMG
   #include "console.h"
   #endif
 #include "block_int.h"  #include "block_int.h"
   
 #ifdef _BSD  #ifdef _BSD
Line 48  static BlockDriverAIOCB *bdrv_aio_write_ Line 51  static BlockDriverAIOCB *bdrv_aio_write_
         int64_t sector_num, const uint8_t *buf, int nb_sectors,          int64_t sector_num, const uint8_t *buf, int nb_sectors,
         BlockDriverCompletionFunc *cb, void *opaque);          BlockDriverCompletionFunc *cb, void *opaque);
 static void bdrv_aio_cancel_em(BlockDriverAIOCB *acb);  static void bdrv_aio_cancel_em(BlockDriverAIOCB *acb);
 static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,   static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
                         uint8_t *buf, int nb_sectors);                          uint8_t *buf, int nb_sectors);
 static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,  static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
                          const uint8_t *buf, int nb_sectors);                           const uint8_t *buf, int nb_sectors);
   
 static BlockDriverState *bdrv_first;  BlockDriverState *bdrv_first;
 static BlockDriver *first_drv;  static BlockDriver *first_drv;
   
 int path_is_absolute(const char *path)  int path_is_absolute(const char *path)
Line 121  void path_combine(char *dest, int dest_s Line 124  void path_combine(char *dest, int dest_s
 }  }
   
   
 void bdrv_register(BlockDriver *bdrv)  static void bdrv_register(BlockDriver *bdrv)
 {  {
     if (!bdrv->bdrv_aio_read) {      if (!bdrv->bdrv_aio_read) {
         /* add AIO emulation layer */          /* add AIO emulation layer */
Line 167  BlockDriver *bdrv_find_format(const char Line 170  BlockDriver *bdrv_find_format(const char
     return NULL;      return NULL;
 }  }
   
 int bdrv_create(BlockDriver *drv,   int bdrv_create(BlockDriver *drv,
                 const char *filename, int64_t size_in_sectors,                  const char *filename, int64_t size_in_sectors,
                 const char *backing_file, int flags)                  const char *backing_file, int flags)
 {  {
Line 180  int bdrv_create(BlockDriver *drv,  Line 183  int bdrv_create(BlockDriver *drv, 
 void get_tmp_filename(char *filename, int size)  void get_tmp_filename(char *filename, int size)
 {  {
     char temp_dir[MAX_PATH];      char temp_dir[MAX_PATH];
       
     GetTempPath(MAX_PATH, temp_dir);      GetTempPath(MAX_PATH, temp_dir);
     GetTempFileName(temp_dir, "qem", 0, filename);      GetTempFileName(temp_dir, "qem", 0, filename);
 }  }
Line 202  static int is_windows_drive_prefix(const Line 205  static int is_windows_drive_prefix(const
              (filename[0] >= 'A' && filename[0] <= 'Z')) &&               (filename[0] >= 'A' && filename[0] <= 'Z')) &&
             filename[1] == ':');              filename[1] == ':');
 }  }
       
 static int is_windows_drive(const char *filename)  static int is_windows_drive(const char *filename)
 {  {
     if (is_windows_drive_prefix(filename) &&       if (is_windows_drive_prefix(filename) &&
         filename[2] == '\0')          filename[2] == '\0')
         return 1;          return 1;
     if (strstart(filename, "\\\\.\\", NULL) ||      if (strstart(filename, "\\\\.\\", NULL) ||
Line 236  static BlockDriver *find_protocol(const  Line 239  static BlockDriver *find_protocol(const 
     memcpy(protocol, filename, len);      memcpy(protocol, filename, len);
     protocol[len] = '\0';      protocol[len] = '\0';
     for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) {      for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) {
         if (drv1->protocol_name &&           if (drv1->protocol_name &&
             !strcmp(drv1->protocol_name, protocol))              !strcmp(drv1->protocol_name, protocol))
             return drv1;              return drv1;
     }      }
Line 251  static BlockDriver *find_image_format(co Line 254  static BlockDriver *find_image_format(co
     BlockDriver *drv1, *drv;      BlockDriver *drv1, *drv;
     uint8_t buf[2048];      uint8_t buf[2048];
     BlockDriverState *bs;      BlockDriverState *bs;
       
     /* detect host devices. By convention, /dev/cdrom[N] is always      /* detect host devices. By convention, /dev/cdrom[N] is always
        recognized as a host CDROM */         recognized as a host CDROM */
     if (strstart(filename, "/dev/cdrom", NULL))      if (strstart(filename, "/dev/cdrom", NULL))
Line 262  static BlockDriver *find_image_format(co Line 265  static BlockDriver *find_image_format(co
 #else  #else
     {      {
         struct stat st;          struct stat st;
         if (stat(filename, &st) >= 0 &&           if (stat(filename, &st) >= 0 &&
             (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {              (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
             return &bdrv_host_device;              return &bdrv_host_device;
         }          }
     }      }
 #endif  #endif
       
     drv = find_protocol(filename);      drv = find_protocol(filename);
     /* no need to test disk image formats for vvfat */      /* no need to test disk image formats for vvfat */
     if (drv == &bdrv_vvfat)      if (drv == &bdrv_vvfat)
Line 322  int bdrv_open2(BlockDriverState *bs, con Line 325  int bdrv_open2(BlockDriverState *bs, con
                BlockDriver *drv)                 BlockDriver *drv)
 {  {
     int ret, open_flags;      int ret, open_flags;
     char tmp_filename[1024];      char tmp_filename[PATH_MAX];
     char backing_filename[1024];      char backing_filename[PATH_MAX];
       
     bs->read_only = 0;      bs->read_only = 0;
     bs->is_temporary = 0;      bs->is_temporary = 0;
     bs->encrypted = 0;      bs->encrypted = 0;
Line 332  int bdrv_open2(BlockDriverState *bs, con Line 335  int bdrv_open2(BlockDriverState *bs, con
     if (flags & BDRV_O_SNAPSHOT) {      if (flags & BDRV_O_SNAPSHOT) {
         BlockDriverState *bs1;          BlockDriverState *bs1;
         int64_t total_size;          int64_t total_size;
           
         /* if snapshot, we create a temporary backing file and open it          /* if snapshot, we create a temporary backing file and open it
            instead of opening 'filename' directly */             instead of opening 'filename' directly */
   
Line 347  int bdrv_open2(BlockDriverState *bs, con Line 350  int bdrv_open2(BlockDriverState *bs, con
         }          }
         total_size = bdrv_getlength(bs1) >> SECTOR_BITS;          total_size = bdrv_getlength(bs1) >> SECTOR_BITS;
         bdrv_delete(bs1);          bdrv_delete(bs1);
           
         get_tmp_filename(tmp_filename, sizeof(tmp_filename));          get_tmp_filename(tmp_filename, sizeof(tmp_filename));
         realpath(filename, backing_filename);          realpath(filename, backing_filename);
         if (bdrv_create(&bdrv_qcow2, tmp_filename,           if (bdrv_create(&bdrv_qcow2, tmp_filename,
                         total_size, backing_filename, 0) < 0) {                          total_size, backing_filename, 0) < 0) {
             return -1;              return -1;
         }          }
Line 377  int bdrv_open2(BlockDriverState *bs, con Line 380  int bdrv_open2(BlockDriverState *bs, con
     /* Note: for compatibility, we open disk image files as RDWR, and      /* Note: for compatibility, we open disk image files as RDWR, and
        RDONLY as fallback */         RDONLY as fallback */
     if (!(flags & BDRV_O_FILE))      if (!(flags & BDRV_O_FILE))
         open_flags = BDRV_O_RDWR;          open_flags = BDRV_O_RDWR | (flags & BDRV_O_DIRECT);
     else      else
         open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);          open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
     ret = drv->bdrv_open(bs, filename, open_flags);      ret = drv->bdrv_open(bs, filename, open_flags);
Line 494  int bdrv_commit(BlockDriverState *bs) Line 497  int bdrv_commit(BlockDriverState *bs)
 }  }
   
 /* return < 0 if error. See bdrv_write() for the return codes */  /* return < 0 if error. See bdrv_write() for the return codes */
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,   int bdrv_read(BlockDriverState *bs, int64_t sector_num,
               uint8_t *buf, int nb_sectors)                uint8_t *buf, int nb_sectors)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 518  int bdrv_read(BlockDriverState *bs, int6 Line 521  int bdrv_read(BlockDriverState *bs, int6
             return ret;              return ret;
         else if (ret != len)          else if (ret != len)
             return -EINVAL;              return -EINVAL;
         else          else {
               bs->rd_bytes += (unsigned) len;
               bs->rd_ops ++;
             return 0;              return 0;
           }
     } else {      } else {
         return drv->bdrv_read(bs, sector_num, buf, nb_sectors);          return drv->bdrv_read(bs, sector_num, buf, nb_sectors);
     }      }
 }  }
   
 /* Return < 0 if error. Important errors are:   /* Return < 0 if error. Important errors are:
   -EIO         generic I/O error (may happen for all errors)    -EIO         generic I/O error (may happen for all errors)
   -ENOMEDIUM   No media inserted.    -ENOMEDIUM   No media inserted.
   -EINVAL      Invalid sector number or nb_sectors    -EINVAL      Invalid sector number or nb_sectors
   -EACCES      Trying to write a read-only device    -EACCES      Trying to write a read-only device
 */  */
 int bdrv_write(BlockDriverState *bs, int64_t sector_num,   int bdrv_write(BlockDriverState *bs, int64_t sector_num,
                const uint8_t *buf, int nb_sectors)                 const uint8_t *buf, int nb_sectors)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 540  int bdrv_write(BlockDriverState *bs, int Line 546  int bdrv_write(BlockDriverState *bs, int
     if (bs->read_only)      if (bs->read_only)
         return -EACCES;          return -EACCES;
     if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {      if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
         memcpy(bs->boot_sector_data, buf, 512);             memcpy(bs->boot_sector_data, buf, 512);
     }      }
     if (drv->bdrv_pwrite) {      if (drv->bdrv_pwrite) {
         int ret, len;          int ret, len;
Line 550  int bdrv_write(BlockDriverState *bs, int Line 556  int bdrv_write(BlockDriverState *bs, int
             return ret;              return ret;
         else if (ret != len)          else if (ret != len)
             return -EIO;              return -EIO;
         else          else {
               bs->wr_bytes += (unsigned) len;
               bs->wr_ops ++;
             return 0;              return 0;
           }
     } else {      } else {
         return drv->bdrv_write(bs, sector_num, buf, nb_sectors);          return drv->bdrv_write(bs, sector_num, buf, nb_sectors);
     }      }
 }  }
   
 static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,   static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,
                          uint8_t *buf, int count1)                           uint8_t *buf, int count1)
 {  {
     uint8_t tmp_buf[SECTOR_SIZE];      uint8_t tmp_buf[SECTOR_SIZE];
Line 601  static int bdrv_pread_em(BlockDriverStat Line 610  static int bdrv_pread_em(BlockDriverStat
     return count1;      return count1;
 }  }
   
 static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset,   static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset,
                           const uint8_t *buf, int count1)                            const uint8_t *buf, int count1)
 {  {
     uint8_t tmp_buf[SECTOR_SIZE];      uint8_t tmp_buf[SECTOR_SIZE];
Line 650  static int bdrv_pwrite_em(BlockDriverSta Line 659  static int bdrv_pwrite_em(BlockDriverSta
 }  }
   
 /**  /**
  * Read with byte offsets (needed only for file protocols)    * Read with byte offsets (needed only for file protocols)
  */   */
 int bdrv_pread(BlockDriverState *bs, int64_t offset,   int bdrv_pread(BlockDriverState *bs, int64_t offset,
                void *buf1, int count1)                 void *buf1, int count1)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 664  int bdrv_pread(BlockDriverState *bs, int Line 673  int bdrv_pread(BlockDriverState *bs, int
     return drv->bdrv_pread(bs, offset, buf1, count1);      return drv->bdrv_pread(bs, offset, buf1, count1);
 }  }
   
 /**   /**
  * Write with byte offsets (needed only for file protocols)    * Write with byte offsets (needed only for file protocols)
  */   */
 int bdrv_pwrite(BlockDriverState *bs, int64_t offset,   int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
                 const void *buf1, int count1)                  const void *buf1, int count1)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 708  int64_t bdrv_getlength(BlockDriverState  Line 717  int64_t bdrv_getlength(BlockDriverState 
 }  }
   
 /* return 0 as number of sectors if no device present or error */  /* return 0 as number of sectors if no device present or error */
 void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr)  void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
 {  {
     int64_t length;      int64_t length;
     length = bdrv_getlength(bs);      length = bdrv_getlength(bs);
Line 729  void bdrv_set_boot_sector(BlockDriverSta Line 738  void bdrv_set_boot_sector(BlockDriverSta
     memset(bs->boot_sector_data + size, 0, 512 - size);      memset(bs->boot_sector_data + size, 0, 512 - size);
 }  }
   
 void bdrv_set_geometry_hint(BlockDriverState *bs,   void bdrv_set_geometry_hint(BlockDriverState *bs,
                             int cyls, int heads, int secs)                              int cyls, int heads, int secs)
 {  {
     bs->cyls = cyls;      bs->cyls = cyls;
Line 749  void bdrv_set_translation_hint(BlockDriv Line 758  void bdrv_set_translation_hint(BlockDriv
     bs->translation = translation;      bs->translation = translation;
 }  }
   
 void bdrv_get_geometry_hint(BlockDriverState *bs,   void bdrv_get_geometry_hint(BlockDriverState *bs,
                             int *pcyls, int *pheads, int *psecs)                              int *pcyls, int *pheads, int *psecs)
 {  {
     *pcyls = bs->cyls;      *pcyls = bs->cyls;
Line 777  int bdrv_is_read_only(BlockDriverState * Line 786  int bdrv_is_read_only(BlockDriverState *
     return bs->read_only;      return bs->read_only;
 }  }
   
   int bdrv_is_sg(BlockDriverState *bs)
   {
       return bs->sg;
   }
   
 /* XXX: no longer used */  /* XXX: no longer used */
 void bdrv_set_change_cb(BlockDriverState *bs,   void bdrv_set_change_cb(BlockDriverState *bs,
                         void (*change_cb)(void *opaque), void *opaque)                          void (*change_cb)(void *opaque), void *opaque)
 {  {
     bs->change_cb = change_cb;      bs->change_cb = change_cb;
Line 816  void bdrv_get_format(BlockDriverState *b Line 830  void bdrv_get_format(BlockDriverState *b
     }      }
 }  }
   
 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),   void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
                          void *opaque)                           void *opaque)
 {  {
     BlockDriver *drv;      BlockDriver *drv;
Line 859  void bdrv_flush(BlockDriverState *bs) Line 873  void bdrv_flush(BlockDriverState *bs)
         bdrv_flush(bs->backing_hd);          bdrv_flush(bs->backing_hd);
 }  }
   
   #ifndef QEMU_IMG
 void bdrv_info(void)  void bdrv_info(void)
 {  {
     BlockDriverState *bs;      BlockDriverState *bs;
Line 899  void bdrv_info(void) Line 914  void bdrv_info(void)
     }      }
 }  }
   
 void bdrv_get_backing_filename(BlockDriverState *bs,   /* The "info blockstats" command. */
   void bdrv_info_stats (void)
   {
       BlockDriverState *bs;
   
       for (bs = bdrv_first; bs != NULL; bs = bs->next) {
           term_printf ("%s:"
                        " rd_bytes=%" PRIu64
                        " wr_bytes=%" PRIu64
                        " rd_operations=%" PRIu64
                        " wr_operations=%" PRIu64
                        "\n",
                        bs->device_name,
                        bs->rd_bytes, bs->wr_bytes,
                        bs->rd_ops, bs->wr_ops);
       }
   }
   #endif
   
   void bdrv_get_backing_filename(BlockDriverState *bs,
                                char *filename, int filename_size)                                 char *filename, int filename_size)
 {  {
     if (!bs->backing_hd) {      if (!bs->backing_hd) {
Line 909  void bdrv_get_backing_filename(BlockDriv Line 943  void bdrv_get_backing_filename(BlockDriv
     }      }
 }  }
   
 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,   int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
                           const uint8_t *buf, int nb_sectors)                            const uint8_t *buf, int nb_sectors)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 919  int bdrv_write_compressed(BlockDriverSta Line 953  int bdrv_write_compressed(BlockDriverSta
         return -ENOTSUP;          return -ENOTSUP;
     return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);      return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
 }  }
       
 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)  int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 934  int bdrv_get_info(BlockDriverState *bs,  Line 968  int bdrv_get_info(BlockDriverState *bs, 
 /**************************************************************/  /**************************************************************/
 /* handling of snapshots */  /* handling of snapshots */
   
 int bdrv_snapshot_create(BlockDriverState *bs,   int bdrv_snapshot_create(BlockDriverState *bs,
                          QEMUSnapshotInfo *sn_info)                           QEMUSnapshotInfo *sn_info)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 945  int bdrv_snapshot_create(BlockDriverStat Line 979  int bdrv_snapshot_create(BlockDriverStat
     return drv->bdrv_snapshot_create(bs, sn_info);      return drv->bdrv_snapshot_create(bs, sn_info);
 }  }
   
 int bdrv_snapshot_goto(BlockDriverState *bs,   int bdrv_snapshot_goto(BlockDriverState *bs,
                        const char *snapshot_id)                         const char *snapshot_id)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 966  int bdrv_snapshot_delete(BlockDriverStat Line 1000  int bdrv_snapshot_delete(BlockDriverStat
     return drv->bdrv_snapshot_delete(bs, snapshot_id);      return drv->bdrv_snapshot_delete(bs, snapshot_id);
 }  }
   
 int bdrv_snapshot_list(BlockDriverState *bs,   int bdrv_snapshot_list(BlockDriverState *bs,
                        QEMUSnapshotInfo **psn_info)                         QEMUSnapshotInfo **psn_info)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
Line 991  char *get_human_readable_size(char *buf, Line 1025  char *get_human_readable_size(char *buf,
         base = 1024;          base = 1024;
         for(i = 0; i < NB_SUFFIXES; i++) {          for(i = 0; i < NB_SUFFIXES; i++) {
             if (size < (10 * base)) {              if (size < (10 * base)) {
                 snprintf(buf, buf_size, "%0.1f%c",                   snprintf(buf, buf_size, "%0.1f%c",
                          (double)size / base,                           (double)size / base,
                          suffixes[i]);                           suffixes[i]);
                 break;                  break;
             } else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {              } else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {
                 snprintf(buf, buf_size, "%" PRId64 "%c",                   snprintf(buf, buf_size, "%" PRId64 "%c",
                          ((size + (base >> 1)) / base),                           ((size + (base >> 1)) / base),
                          suffixes[i]);                           suffixes[i]);
                 break;                  break;
Line 1019  char *bdrv_snapshot_dump(char *buf, int  Line 1053  char *bdrv_snapshot_dump(char *buf, int 
     int64_t secs;      int64_t secs;
   
     if (!sn) {      if (!sn) {
         snprintf(buf, buf_size,           snprintf(buf, buf_size,
                  "%-10s%-20s%7s%20s%15s",                    "%-10s%-20s%7s%20s%15s",
                  "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");                   "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
     } else {      } else {
         ti = sn->date_sec;          ti = sn->date_sec;
Line 1038  char *bdrv_snapshot_dump(char *buf, int  Line 1072  char *bdrv_snapshot_dump(char *buf, int 
                  "%02d:%02d:%02d.%03d",                   "%02d:%02d:%02d.%03d",
                  (int)(secs / 3600),                   (int)(secs / 3600),
                  (int)((secs / 60) % 60),                   (int)((secs / 60) % 60),
                  (int)(secs % 60),                    (int)(secs % 60),
                  (int)((sn->vm_clock_nsec / 1000000) % 1000));                   (int)((sn->vm_clock_nsec / 1000000) % 1000));
         snprintf(buf, buf_size,          snprintf(buf, buf_size,
                  "%-10s%-20s%7s%20s%15s",                    "%-10s%-20s%7s%20s%15s",
                  sn->id_str, sn->name,                   sn->id_str, sn->name,
                  get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),                   get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),
                  date_buf,                   date_buf,
Line 1059  BlockDriverAIOCB *bdrv_aio_read(BlockDri Line 1093  BlockDriverAIOCB *bdrv_aio_read(BlockDri
                                 BlockDriverCompletionFunc *cb, void *opaque)                                  BlockDriverCompletionFunc *cb, void *opaque)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
       BlockDriverAIOCB *ret;
   
     if (!drv)      if (!drv)
         return NULL;          return NULL;
       
     /* XXX: we assume that nb_sectors == 0 is suppored by the async read */      /* XXX: we assume that nb_sectors == 0 is suppored by the async read */
     if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {      if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
         memcpy(buf, bs->boot_sector_data, 512);          memcpy(buf, bs->boot_sector_data, 512);
Line 1071  BlockDriverAIOCB *bdrv_aio_read(BlockDri Line 1106  BlockDriverAIOCB *bdrv_aio_read(BlockDri
         buf += 512;          buf += 512;
     }      }
   
     return drv->bdrv_aio_read(bs, sector_num, buf, nb_sectors, cb, opaque);      ret = drv->bdrv_aio_read(bs, sector_num, buf, nb_sectors, cb, opaque);
   
       if (ret) {
           /* Update stats even though technically transfer has not happened. */
           bs->rd_bytes += (unsigned) nb_sectors * SECTOR_SIZE;
           bs->rd_ops ++;
       }
   
       return ret;
 }  }
   
 BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,  BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
Line 1079  BlockDriverAIOCB *bdrv_aio_write(BlockDr Line 1122  BlockDriverAIOCB *bdrv_aio_write(BlockDr
                                  BlockDriverCompletionFunc *cb, void *opaque)                                   BlockDriverCompletionFunc *cb, void *opaque)
 {  {
     BlockDriver *drv = bs->drv;      BlockDriver *drv = bs->drv;
       BlockDriverAIOCB *ret;
   
     if (!drv)      if (!drv)
         return NULL;          return NULL;
     if (bs->read_only)      if (bs->read_only)
         return NULL;          return NULL;
     if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {      if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
         memcpy(bs->boot_sector_data, buf, 512);             memcpy(bs->boot_sector_data, buf, 512);
     }      }
   
     return drv->bdrv_aio_write(bs, sector_num, buf, nb_sectors, cb, opaque);      ret = drv->bdrv_aio_write(bs, sector_num, buf, nb_sectors, cb, opaque);
   
       if (ret) {
           /* Update stats even though technically transfer has not happened. */
           bs->wr_bytes += (unsigned) nb_sectors * SECTOR_SIZE;
           bs->wr_ops ++;
       }
   
       return ret;
 }  }
   
 void bdrv_aio_cancel(BlockDriverAIOCB *acb)  void bdrv_aio_cancel(BlockDriverAIOCB *acb)
Line 1102  void bdrv_aio_cancel(BlockDriverAIOCB *a Line 1154  void bdrv_aio_cancel(BlockDriverAIOCB *a
 /**************************************************************/  /**************************************************************/
 /* async block device emulation */  /* async block device emulation */
   
 #ifdef QEMU_TOOL  #ifdef QEMU_IMG
 static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs,  static BlockDriverAIOCB *bdrv_aio_read_em(BlockDriverState *bs,
         int64_t sector_num, uint8_t *buf, int nb_sectors,          int64_t sector_num, uint8_t *buf, int nb_sectors,
         BlockDriverCompletionFunc *cb, void *opaque)          BlockDriverCompletionFunc *cb, void *opaque)
Line 1172  static void bdrv_aio_cancel_em(BlockDriv Line 1224  static void bdrv_aio_cancel_em(BlockDriv
     qemu_bh_cancel(acb->bh);      qemu_bh_cancel(acb->bh);
     qemu_aio_release(acb);      qemu_aio_release(acb);
 }  }
 #endif /* !QEMU_TOOL */  #endif /* !QEMU_IMG */
   
 /**************************************************************/  /**************************************************************/
 /* sync block device emulation */  /* sync block device emulation */
Line 1184  static void bdrv_rw_em_cb(void *opaque,  Line 1236  static void bdrv_rw_em_cb(void *opaque, 
   
 #define NOT_DONE 0x7fffffff  #define NOT_DONE 0x7fffffff
   
 static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,   static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
                         uint8_t *buf, int nb_sectors)                          uint8_t *buf, int nb_sectors)
 {  {
     int async_ret;      int async_ret;
Line 1192  static int bdrv_read_em(BlockDriverState Line 1244  static int bdrv_read_em(BlockDriverState
   
     async_ret = NOT_DONE;      async_ret = NOT_DONE;
     qemu_aio_wait_start();      qemu_aio_wait_start();
     acb = bdrv_aio_read(bs, sector_num, buf, nb_sectors,       acb = bdrv_aio_read(bs, sector_num, buf, nb_sectors,
                         bdrv_rw_em_cb, &async_ret);                          bdrv_rw_em_cb, &async_ret);
     if (acb == NULL) {      if (acb == NULL) {
         qemu_aio_wait_end();          qemu_aio_wait_end();
Line 1213  static int bdrv_write_em(BlockDriverStat Line 1265  static int bdrv_write_em(BlockDriverStat
   
     async_ret = NOT_DONE;      async_ret = NOT_DONE;
     qemu_aio_wait_start();      qemu_aio_wait_start();
     acb = bdrv_aio_write(bs, sector_num, buf, nb_sectors,       acb = bdrv_aio_write(bs, sector_num, buf, nb_sectors,
                          bdrv_rw_em_cb, &async_ret);                           bdrv_rw_em_cb, &async_ret);
     if (acb == NULL) {      if (acb == NULL) {
         qemu_aio_wait_end();          qemu_aio_wait_end();
Line 1241  void bdrv_init(void) Line 1293  void bdrv_init(void)
     bdrv_register(&bdrv_vpc);      bdrv_register(&bdrv_vpc);
     bdrv_register(&bdrv_vvfat);      bdrv_register(&bdrv_vvfat);
     bdrv_register(&bdrv_qcow2);      bdrv_register(&bdrv_qcow2);
       bdrv_register(&bdrv_parallels);
 }  }
   
 void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,  void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
Line 1292  int bdrv_is_inserted(BlockDriverState *b Line 1345  int bdrv_is_inserted(BlockDriverState *b
   
 /**  /**
  * Return TRUE if the media changed since the last call to this   * Return TRUE if the media changed since the last call to this
  * function. It is currently only used for floppy disks    * function. It is currently only used for floppy disks
  */   */
 int bdrv_media_changed(BlockDriverState *bs)  int bdrv_media_changed(BlockDriverState *bs)
 {  {
Line 1346  void bdrv_set_locked(BlockDriverState *b Line 1399  void bdrv_set_locked(BlockDriverState *b
         drv->bdrv_set_locked(bs, locked);          drv->bdrv_set_locked(bs, locked);
     }      }
 }  }
   
   /* needed for generic scsi interface */
   
   int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
   {
       BlockDriver *drv = bs->drv;
   
       if (drv && drv->bdrv_ioctl)
           return drv->bdrv_ioctl(bs, req, buf);
       return -ENOTSUP;
   }

Removed from v.1.1.1.5  
changed lines
  Added in v.1.1.1.6


unix.superglobalmegacorp.com