~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to hw/block/virtio-blk.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "hw/virtio/virtio-blk.h"
20
20
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
21
21
# include "dataplane/virtio-blk.h"
 
22
# include "migration/migration.h"
22
23
#endif
23
24
#include "block/scsi.h"
24
25
#ifdef __linux__
459
460
 
460
461
static void virtio_blk_reset(VirtIODevice *vdev)
461
462
{
 
463
    VirtIOBlock *s = VIRTIO_BLK(vdev);
 
464
 
462
465
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
463
 
    VirtIOBlock *s = VIRTIO_BLK(vdev);
464
 
 
465
466
    if (s->dataplane) {
466
467
        virtio_blk_data_plane_stop(s->dataplane);
467
468
    }
472
473
     * are per-device request lists.
473
474
     */
474
475
    bdrv_drain_all();
 
476
    bdrv_set_enable_write_cache(s->bs, s->original_wce);
475
477
}
476
478
 
477
479
/* coalesce internal state, copy to pci i/o region 0
563
565
    }
564
566
 
565
567
    features = vdev->guest_features;
566
 
    bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
 
568
 
 
569
    /* A guest that supports VIRTIO_BLK_F_CONFIG_WCE must be able to send
 
570
     * cache flushes.  Thus, the "auto writethrough" behavior is never
 
571
     * necessary for guests that support the VIRTIO_BLK_F_CONFIG_WCE feature.
 
572
     * Leaving it enabled would break the following sequence:
 
573
     *
 
574
     *     Guest started with "-drive cache=writethrough"
 
575
     *     Guest sets status to 0
 
576
     *     Guest sets DRIVER bit in status field
 
577
     *     Guest reads host features (WCE=0, CONFIG_WCE=1)
 
578
     *     Guest writes guest features (WCE=0, CONFIG_WCE=1)
 
579
     *     Guest writes 1 to the WCE configuration field (writeback mode)
 
580
     *     Guest sets DRIVER_OK bit in status field
 
581
     *
 
582
     * s->bs would erroneously be placed in writethrough mode.
 
583
     */
 
584
    if (!(features & (1 << VIRTIO_BLK_F_CONFIG_WCE))) {
 
585
        bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE)));
 
586
    }
567
587
}
568
588
 
569
589
static void virtio_blk_save(QEMUFile *f, void *opaque)
628
648
    memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
629
649
}
630
650
 
 
651
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
 
652
/* Disable dataplane thread during live migration since it does not
 
653
 * update the dirty memory bitmap yet.
 
654
 */
 
655
static void virtio_blk_migration_state_changed(Notifier *notifier, void *data)
 
656
{
 
657
    VirtIOBlock *s = container_of(notifier, VirtIOBlock,
 
658
                                  migration_state_notifier);
 
659
    MigrationState *mig = data;
 
660
 
 
661
    if (migration_in_setup(mig)) {
 
662
        if (!s->dataplane) {
 
663
            return;
 
664
        }
 
665
        virtio_blk_data_plane_destroy(s->dataplane);
 
666
        s->dataplane = NULL;
 
667
    } else if (migration_has_finished(mig) ||
 
668
               migration_has_failed(mig)) {
 
669
        if (s->dataplane) {
 
670
            return;
 
671
        }
 
672
        bdrv_drain_all(); /* complete in-flight non-dataplane requests */
 
673
        virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->blk,
 
674
                                     &s->dataplane);
 
675
    }
 
676
}
 
677
#endif /* CONFIG_VIRTIO_BLK_DATA_PLANE */
 
678
 
631
679
static int virtio_blk_device_init(VirtIODevice *vdev)
632
680
{
633
681
    DeviceState *qdev = DEVICE(vdev);
645
693
    }
646
694
 
647
695
    blkconf_serial(&blk->conf, &blk->serial);
 
696
    s->original_wce = bdrv_enable_write_cache(blk->conf.bs);
648
697
    if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
649
698
        return -1;
650
699
    }
664
713
        virtio_cleanup(vdev);
665
714
        return -1;
666
715
    }
 
716
    s->migration_state_notifier.notify = virtio_blk_migration_state_changed;
 
717
    add_migration_state_change_notifier(&s->migration_state_notifier);
667
718
#endif
668
719
 
669
720
    s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
683
734
    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
684
735
    VirtIOBlock *s = VIRTIO_BLK(dev);
685
736
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
 
737
    remove_migration_state_change_notifier(&s->migration_state_notifier);
686
738
    virtio_blk_data_plane_destroy(s->dataplane);
687
739
    s->dataplane = NULL;
688
740
#endif
704
756
    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
705
757
    dc->exit = virtio_blk_device_exit;
706
758
    dc->props = virtio_blk_properties;
 
759
    set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
707
760
    vdc->init = virtio_blk_device_init;
708
761
    vdc->get_config = virtio_blk_update_config;
709
762
    vdc->set_config = virtio_blk_set_config;