Diff for /qemu/block.c between versions 1.1.1.7 and 1.1.1.8

version 1.1.1.7, 2018/04/24 16:50:42 version 1.1.1.8, 2018/04/24 16:56:37
Line 311  int bdrv_file_open(BlockDriverState **pb Line 311  int bdrv_file_open(BlockDriverState **pb
     int ret;      int ret;
   
     bs = bdrv_new("");      bs = bdrv_new("");
     if (!bs)  
         return -ENOMEM;  
     ret = bdrv_open2(bs, filename, flags | BDRV_O_FILE, NULL);      ret = bdrv_open2(bs, filename, flags | BDRV_O_FILE, NULL);
     if (ret < 0) {      if (ret < 0) {
         bdrv_delete(bs);          bdrv_delete(bs);
Line 338  int bdrv_open2(BlockDriverState *bs, con Line 336  int bdrv_open2(BlockDriverState *bs, con
     bs->read_only = 0;      bs->read_only = 0;
     bs->is_temporary = 0;      bs->is_temporary = 0;
     bs->encrypted = 0;      bs->encrypted = 0;
       bs->valid_key = 0;
   
     if (flags & BDRV_O_SNAPSHOT) {      if (flags & BDRV_O_SNAPSHOT) {
         BlockDriverState *bs1;          BlockDriverState *bs1;
Line 349  int bdrv_open2(BlockDriverState *bs, con Line 348  int bdrv_open2(BlockDriverState *bs, con
   
         /* if there is a backing file, use it */          /* if there is a backing file, use it */
         bs1 = bdrv_new("");          bs1 = bdrv_new("");
         if (!bs1) {          ret = bdrv_open(bs1, filename, 0);
             return -ENOMEM;          if (ret < 0) {
         }  
         if (bdrv_open(bs1, filename, 0) < 0) {  
             bdrv_delete(bs1);              bdrv_delete(bs1);
             return -1;              return ret;
         }          }
         total_size = bdrv_getlength(bs1) >> SECTOR_BITS;          total_size = bdrv_getlength(bs1) >> SECTOR_BITS;
   
Line 372  int bdrv_open2(BlockDriverState *bs, con Line 369  int bdrv_open2(BlockDriverState *bs, con
         else          else
             realpath(filename, backing_filename);              realpath(filename, backing_filename);
   
         if (bdrv_create(&bdrv_qcow2, tmp_filename,          ret = bdrv_create(&bdrv_qcow2, tmp_filename,
                         total_size, backing_filename, 0) < 0) {                            total_size, backing_filename, 0);
             return -1;          if (ret < 0) {
               return ret;
         }          }
         filename = tmp_filename;          filename = tmp_filename;
         bs->is_temporary = 1;          bs->is_temporary = 1;
Line 383  int bdrv_open2(BlockDriverState *bs, con Line 381  int bdrv_open2(BlockDriverState *bs, con
     pstrcpy(bs->filename, sizeof(bs->filename), filename);      pstrcpy(bs->filename, sizeof(bs->filename), filename);
     if (flags & BDRV_O_FILE) {      if (flags & BDRV_O_FILE) {
         drv = find_protocol(filename);          drv = find_protocol(filename);
         if (!drv)      } else if (!drv) {
             return -ENOENT;          drv = find_image_format(filename);
     } else {      }
         if (!drv) {      if (!drv) {
             drv = find_image_format(filename);          ret = -ENOENT;
             if (!drv)          goto unlink_and_fail;
                 return -1;  
         }  
     }      }
     bs->drv = drv;      bs->drv = drv;
     bs->opaque = qemu_mallocz(drv->instance_size);      bs->opaque = qemu_mallocz(drv->instance_size);
Line 409  int bdrv_open2(BlockDriverState *bs, con Line 405  int bdrv_open2(BlockDriverState *bs, con
         qemu_free(bs->opaque);          qemu_free(bs->opaque);
         bs->opaque = NULL;          bs->opaque = NULL;
         bs->drv = NULL;          bs->drv = NULL;
       unlink_and_fail:
           if (bs->is_temporary)
               unlink(filename);
         return ret;          return ret;
     }      }
     if (drv->bdrv_getlength) {      if (drv->bdrv_getlength) {
Line 422  int bdrv_open2(BlockDriverState *bs, con Line 421  int bdrv_open2(BlockDriverState *bs, con
     if (bs->backing_file[0] != '\0') {      if (bs->backing_file[0] != '\0') {
         /* if there is a backing file, use it */          /* if there is a backing file, use it */
         bs->backing_hd = bdrv_new("");          bs->backing_hd = bdrv_new("");
         if (!bs->backing_hd) {  
         fail:  
             bdrv_close(bs);  
             return -ENOMEM;  
         }  
         path_combine(backing_filename, sizeof(backing_filename),          path_combine(backing_filename, sizeof(backing_filename),
                      filename, bs->backing_file);                       filename, bs->backing_file);
         if (bdrv_open(bs->backing_hd, backing_filename, open_flags) < 0)          ret = bdrv_open(bs->backing_hd, backing_filename, open_flags);
             goto fail;          if (ret < 0) {
               bdrv_close(bs);
               return ret;
           }
     }      }
   
     /* call the change callback */      /* call the change callback */
Line 970  int bdrv_is_encrypted(BlockDriverState * Line 967  int bdrv_is_encrypted(BlockDriverState *
     return bs->encrypted;      return bs->encrypted;
 }  }
   
   int bdrv_key_required(BlockDriverState *bs)
   {
       BlockDriverState *backing_hd = bs->backing_hd;
   
       if (backing_hd && backing_hd->encrypted && !backing_hd->valid_key)
           return 1;
       return (bs->encrypted && !bs->valid_key);
   }
   
 int bdrv_set_key(BlockDriverState *bs, const char *key)  int bdrv_set_key(BlockDriverState *bs, const char *key)
 {  {
     int ret;      int ret;
Line 982  int bdrv_set_key(BlockDriverState *bs, c Line 988  int bdrv_set_key(BlockDriverState *bs, c
     }      }
     if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key)      if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key)
         return -1;          return -1;
     return bs->drv->bdrv_set_key(bs, key);      ret = bs->drv->bdrv_set_key(bs, key);
       bs->valid_key = (ret == 0);
       return ret;
 }  }
   
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size)  void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size)
Line 1015  BlockDriverState *bdrv_find(const char * Line 1023  BlockDriverState *bdrv_find(const char *
     return NULL;      return NULL;
 }  }
   
 void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque)  void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void *opaque)
 {  {
     BlockDriverState *bs;      BlockDriverState *bs;
   
     for (bs = bdrv_first; bs != NULL; bs = bs->next) {      for (bs = bdrv_first; bs != NULL; bs = bs->next) {
         it(opaque, bs->device_name);          it(opaque, bs);
     }      }
 }  }
   
Line 1105  void bdrv_info(void) Line 1113  void bdrv_info(void)
             }              }
             term_printf(" ro=%d", bs->read_only);              term_printf(" ro=%d", bs->read_only);
             term_printf(" drv=%s", bs->drv->format_name);              term_printf(" drv=%s", bs->drv->format_name);
             if (bs->encrypted)              term_printf(" encrypted=%d", bdrv_is_encrypted(bs));
                 term_printf(" encrypted");  
         } else {          } else {
             term_printf(" [not inserted]");              term_printf(" [not inserted]");
         }          }
Line 1118  void bdrv_info(void) Line 1125  void bdrv_info(void)
 void bdrv_info_stats (void)  void bdrv_info_stats (void)
 {  {
     BlockDriverState *bs;      BlockDriverState *bs;
     BlockDriverInfo bdi;  
   
     for (bs = bdrv_first; bs != NULL; bs = bs->next) {      for (bs = bdrv_first; bs != NULL; bs = bs->next) {
         term_printf ("%s:"          term_printf ("%s:"
Line 1126  void bdrv_info_stats (void) Line 1132  void bdrv_info_stats (void)
                      " wr_bytes=%" PRIu64                       " wr_bytes=%" PRIu64
                      " rd_operations=%" PRIu64                       " rd_operations=%" PRIu64
                      " wr_operations=%" PRIu64                       " wr_operations=%" PRIu64
                      ,                       "\n",
                      bs->device_name,                       bs->device_name,
                      bs->rd_bytes, bs->wr_bytes,                       bs->rd_bytes, bs->wr_bytes,
                      bs->rd_ops, bs->wr_ops);                       bs->rd_ops, bs->wr_ops);
         if (bdrv_get_info(bs, &bdi) == 0)  
             term_printf(" high=%" PRId64  
                         " bytes_free=%" PRId64,  
                         bdi.highest_alloc, bdi.num_free_bytes);  
         term_printf("\n");  
     }      }
 }  }
   
   const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
   {
       if (bs->backing_hd && bs->backing_hd->encrypted)
           return bs->backing_file;
       else if (bs->encrypted)
           return bs->filename;
       else
           return NULL;
   }
   
 void bdrv_get_backing_filename(BlockDriverState *bs,  void bdrv_get_backing_filename(BlockDriverState *bs,
                                char *filename, int filename_size)                                 char *filename, int filename_size)
 {  {

Removed from v.1.1.1.7  
changed lines
  Added in v.1.1.1.8


unix.superglobalmegacorp.com