Skip to content

Instantly share code, notes, and snippets.

@archerslaw
Last active August 29, 2015 13:59
Show Gist options
  • Save archerslaw/10630872 to your computer and use it in GitHub Desktop.
Save archerslaw/10630872 to your computer and use it in GitHub Desktop.
Use the blockdev_add in qemu-kvm.
##
# @BlockdevOptionsBase
#
# Options that are available for all block devices, independent of the block
# driver.
#
# @driver: block driver name
# @id: #optional id by which the new block device can be referred to.
# This is a required option on the top level of blockdev-add, and
# currently not allowed on any other level.
# @node-name: #optional the name of a block driver state node (Since 2.0)
# @discard: #optional discard-related options (default: ignore)
# @cache: #optional cache-related options
# @aio: #optional AIO backend (default: threads)
# @rerror: #optional how to handle read errors on the device
# (default: report)
# @werror: #optional how to handle write errors on the device
# (default: enospc)
# @read-only: #optional whether the block device should be read-only
# (default: false)
#
# Since: 1.7
##
##
# @BlockdevCacheOptions
#
# Includes cache-related options for block devices
#
# @writeback: #optional enables writeback mode for any caches (default: true)
# @direct: #optional enables use of O_DIRECT (bypass the host page cache;
# default: false)
# @no-flush: #optional ignore any flush requests for the device (default:
# false)
#
# Since: 1.7
##
{ 'type': 'BlockdevCacheOptions',
'data': { '*writeback': 'bool',
'*direct': 'bool',
'*no-flush': 'bool' } }
discard: unmap/ignore <===> discard=on/off
rerror|werror: stop|report
read-only: true/false
aio: native/threads
For the virtio-blk:
{ "execute": "blockdev-add", "arguments": {'options' : {'driver': 'raw', 'id':'drive-disk1', 'read-only': true, 'discard':'unmap', 'file': {'driver': 'file', 'filename': '/home/my-data-disk.raw'}, 'cache': { 'writeback': false, 'direct': true, 'no-flush': false }}} }
{"return": {}}
{"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"drive-disk1","id":"data-disk1","bus":"pci.0","scsi":"off","addr":"0x8"}}
{"return": {}}
{"execute":"device_del","arguments":{"id":"data-disk1"}}
{"return": {}}
{"timestamp": {"seconds": 1397195455, "microseconds": 949758}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/disk1/virtio-backend"}}
{"timestamp": {"seconds": 1397195455, "microseconds": 952476}, "event": "DEVICE_DELETED", "data": {"device": "disk1", "path": "/machine/peripheral/disk1"}}
{"execute":"__com.redhat_drive_del","arguments":{"id":"drive-disk1"}}
{"return": {}}
For the virtio-scsi:
{ "execute": "blockdev-add", "arguments": {'options' : {'driver': 'raw', 'id':'drive-disk1', 'read-only': true, 'discard':'unmap', 'file': {'driver': 'file', 'filename': '/home/my-data-disk.raw'}, 'cache': { 'writeback': false, 'direct': true, 'no-flush': false }}} }
{"return": {}}
{"execute":"device_add","arguments":{"driver":"virtio-scsi-pci","id":"scsi1","bus":"pci.0","addr":"0x8"}}
{"return": {}}
{"execute":"device_add","arguments":{"driver":"scsi-hd","drive":"drive-disk1","id":"data-disk1","bus":"scsi1.0"}}
{"return": {}}
{"execute":"device_del","arguments":{"id":"data-disk1"}}
{"timestamp": {"seconds": 1397200276, "microseconds": 207737}, "event": "DEVICE_DELETED", "data": {"device": "data-disk1", "path": "/machine/peripheral/data-disk1"}}
{"return": {}}
{"execute":"device_del","arguments":{"id":"scsi1"}}
{"return": {}}
{"timestamp": {"seconds": 1397200279, "microseconds": 608212}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/scsi1/virtio-backend"}}
{"timestamp": {"seconds": 1397200279, "microseconds": 611160}, "event": "DEVICE_DELETED", "data": {"device": "scsi1", "path": "/machine/peripheral/scsi1"}}
{"execute":"__com.redhat_drive_del","arguments":{"id":"drive-disk1"}}
{"return": {}}
- For the original commands:
{"execute":"__com.redhat_drive_add","arguments": {"file":"iscsi://10.66.90.100:3260/iqn.2001-05.com.equallogic:0-8a0906-4c41f7d03-453f49b421052a57-s2-sluo-270305-1/0","format":"raw","id":"drive-data-disk1","aio":"native","werror":"stop","rerror":"stop"}}
{"return": {}}
{"execute":"device_add","arguments":{"driver":"virtio-scsi-pci","id":"scsi1","bus":"pci.0","addr":"0x8"}}
{"return": {}}
{"execute":"device_add","arguments":{"driver":"scsi-hd","drive":"drive-data-disk1","id":"data-disk1","bus":"scsi1.0"}}
{"return": {}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment