Diff for /qemu/blockdev.c between versions 1.1.1.4 and 1.1.1.5

version 1.1.1.4, 2018/04/24 18:55:49 version 1.1.1.5, 2018/04/24 19:16:53
Line 14 Line 14
 #include "qemu-option.h"  #include "qemu-option.h"
 #include "qemu-config.h"  #include "qemu-config.h"
 #include "sysemu.h"  #include "sysemu.h"
 #include "hw/qdev.h"  
 #include "block_int.h"  #include "block_int.h"
   
 static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);  static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
Line 182  static void drive_uninit(DriveInfo *dinf Line 181  static void drive_uninit(DriveInfo *dinf
 {  {
     qemu_opts_del(dinfo->opts);      qemu_opts_del(dinfo->opts);
     bdrv_delete(dinfo->bdrv);      bdrv_delete(dinfo->bdrv);
     qemu_free(dinfo->id);      g_free(dinfo->id);
     QTAILQ_REMOVE(&drives, dinfo, next);      QTAILQ_REMOVE(&drives, dinfo, next);
     qemu_free(dinfo);      g_free(dinfo);
 }  }
   
 void drive_put_ref(DriveInfo *dinfo)  void drive_put_ref(DriveInfo *dinfo)
Line 321  DriveInfo *drive_init(QemuOpts *opts, in Line 320  DriveInfo *drive_init(QemuOpts *opts, in
     }      }
   
     if ((buf = qemu_opt_get(opts, "cache")) != NULL) {      if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
         if (!strcmp(buf, "off") || !strcmp(buf, "none")) {          if (bdrv_parse_cache_flags(buf, &bdrv_flags) != 0) {
             bdrv_flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;              error_report("invalid cache option");
         } else if (!strcmp(buf, "writeback")) {              return NULL;
             bdrv_flags |= BDRV_O_CACHE_WB;  
         } else if (!strcmp(buf, "unsafe")) {  
             bdrv_flags |= BDRV_O_CACHE_WB;  
             bdrv_flags |= BDRV_O_NO_FLUSH;  
         } else if (!strcmp(buf, "writethrough")) {  
             /* this is the default */  
         } else {  
            error_report("invalid cache option");  
            return NULL;  
         }          }
     }      }
   
Line 442  DriveInfo *drive_init(QemuOpts *opts, in Line 432  DriveInfo *drive_init(QemuOpts *opts, in
   
     /* init */      /* init */
   
     dinfo = qemu_mallocz(sizeof(*dinfo));      dinfo = g_malloc0(sizeof(*dinfo));
     if ((buf = qemu_opts_id(opts)) != NULL) {      if ((buf = qemu_opts_id(opts)) != NULL) {
         dinfo->id = qemu_strdup(buf);          dinfo->id = g_strdup(buf);
     } else {      } else {
         /* no id supplied -> create one */          /* no id supplied -> create one */
         dinfo->id = qemu_mallocz(32);          dinfo->id = g_malloc0(32);
         if (type == IF_IDE || type == IF_SCSI)          if (type == IF_IDE || type == IF_SCSI)
             mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";              mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
         if (max_devs)          if (max_devs)
Line 483  DriveInfo *drive_init(QemuOpts *opts, in Line 473  DriveInfo *drive_init(QemuOpts *opts, in
             }              }
             break;              break;
         case MEDIA_CDROM:          case MEDIA_CDROM:
             bdrv_set_removable(dinfo->bdrv, 1);  
             dinfo->media_cd = 1;              dinfo->media_cd = 1;
             break;              break;
         }          }
         break;          break;
     case IF_SD:      case IF_SD:
         /* FIXME: This isn't really a floppy, but it's a reasonable  
            approximation.  */  
     case IF_FLOPPY:      case IF_FLOPPY:
         bdrv_set_removable(dinfo->bdrv, 1);  
         break;  
     case IF_PFLASH:      case IF_PFLASH:
     case IF_MTD:      case IF_MTD:
         break;          break;
Line 542  DriveInfo *drive_init(QemuOpts *opts, in Line 527  DriveInfo *drive_init(QemuOpts *opts, in
   
 err:  err:
     bdrv_delete(dinfo->bdrv);      bdrv_delete(dinfo->bdrv);
     qemu_free(dinfo->id);      g_free(dinfo->id);
     QTAILQ_REMOVE(&drives, dinfo, next);      QTAILQ_REMOVE(&drives, dinfo, next);
     qemu_free(dinfo);      g_free(dinfo);
     return NULL;      return NULL;
 }  }
   
Line 646  out: Line 631  out:
   
 static int eject_device(Monitor *mon, BlockDriverState *bs, int force)  static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
 {  {
     if (!force) {      if (!bdrv_dev_has_removable_media(bs)) {
         if (!bdrv_is_removable(bs)) {          qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
             qerror_report(QERR_DEVICE_NOT_REMOVABLE,          return -1;
                            bdrv_get_device_name(bs));      }
             return -1;      if (bdrv_dev_is_medium_locked(bs) && !bdrv_dev_is_tray_open(bs)) {
         }          bdrv_dev_eject_request(bs, force);
         if (bdrv_is_locked(bs)) {          if (!force) {
             qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));              qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
             return -1;              return -1;
         }          }
Line 750  int do_drive_del(Monitor *mon, const QDi Line 735  int do_drive_del(Monitor *mon, const QDi
     bdrv_flush(bs);      bdrv_flush(bs);
     bdrv_close(bs);      bdrv_close(bs);
   
     /* if we have a device associated with this BlockDriverState (bs->peer)      /* if we have a device attached to this BlockDriverState
      * then we need to make the drive anonymous until the device       * then we need to make the drive anonymous until the device
      * can be removed.  If this is a drive with no device backing       * can be removed.  If this is a drive with no device backing
      * then we can just get rid of the block driver state right here.       * then we can just get rid of the block driver state right here.
      */       */
     if (bs->peer) {      if (bdrv_get_attached_dev(bs)) {
         bdrv_make_anon(bs);          bdrv_make_anon(bs);
     } else {      } else {
         drive_uninit(drive_get_by_blockdev(bs));          drive_uninit(drive_get_by_blockdev(bs));

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


unix.superglobalmegacorp.com