Commit f6166a06 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

block/qdev: Allow configuring WCE with qdev properties



As cache.writeback is a BlockBackend property and as such more related
to the guest device than the BlockDriverState, we already removed it
from the blockdev-add interface. This patch adds the new way to set it,
as a qdev property of the corresponding guest device.

For example: -drive if=none,file=test.img,node-name=img
             -device ide-hd,drive=img,write-cache=off

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
parent 8daea510
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -51,6 +51,22 @@ void blkconf_blocksizes(BlockConf *conf)
    }
}

void blkconf_apply_backend_options(BlockConf *conf)
{
    BlockBackend *blk = conf->blk;
    bool wce;

    switch (conf->wce) {
    case ON_OFF_AUTO_ON:    wce = true; break;
    case ON_OFF_AUTO_OFF:   wce = false; break;
    case ON_OFF_AUTO_AUTO:  wce = blk_enable_write_cache(blk); break;
    default:
        abort();
    }

    blk_set_enable_write_cache(blk, wce);
}

void blkconf_geometry(BlockConf *conf, int *ptrans,
                      unsigned cyls_max, unsigned heads_max, unsigned secs_max,
                      Error **errp)
+1 −0
Original line number Diff line number Diff line
@@ -803,6 +803,7 @@ static int nvme_init(PCIDevice *pci_dev)
        return -1;
    }
    blkconf_blocksizes(&n->conf);
    blkconf_apply_backend_options(&n->conf);

    pci_conf = pci_dev->config;
    pci_conf[PCI_INTERRUPT_PIN] = 1;
+1 −0
Original line number Diff line number Diff line
@@ -897,6 +897,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
    }

    blkconf_serial(&conf->conf, &conf->serial);
    blkconf_apply_backend_options(&conf->conf);
    s->original_wce = blk_enable_write_cache(conf->conf.blk);
    blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, &err);
    if (err) {
+1 −0
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
            return -1;
        }
    }
    blkconf_apply_backend_options(&dev->conf);

    if (ide_init_drive(s, dev->conf.blk, kind,
                       dev->version, dev->serial, dev->model, dev->wwn,
+1 −0
Original line number Diff line number Diff line
@@ -2309,6 +2309,7 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
            return;
        }
    }
    blkconf_apply_backend_options(&dev->conf);

    if (s->qdev.conf.discard_granularity == -1) {
        s->qdev.conf.discard_granularity =
Loading