Skip to contentSkip to conversation

Block patches

GIT PULL Max Reitz 3 participants 9 messages Jul 19, 2016 – Jul 22, 2016

Subsystems (2)
lore
Share & tools
lore

Max Reitz

author
#0 lore raw

The following changes since commit 5d3217340adcb6c4f0e4af5d2b865331eb2ff63d:

disas: Fix ATTRIBUTE_UNUSED define clash with ALSA headers (2016-07-19 16:40:39 +0100)

are available in the git repository at:

git://github.com/XanClic/qemu.git tags/pull-block-2016-07-20

for you to fetch changes up to bafea5b7c26dd14895f7be64685a12645a75f4cf:

block: export LUKS specific data to qemu-img info (2016-07-20 00:34:03 +0200)

----------------------------------------------------------------
Block patches for master

----------------------------------------------------------------
Cao jin (1):
AioContext: correct comments

Daniel P. Berrange (2):
crypto: add support for querying parameters for block encryption
block: export LUKS specific data to qemu-img info

Vladimir Sementsov-Ogievskiy (1):
qcow2: do not allocate extra memory

 block/crypto.c         | 49 ++++++++++++++++++++++++++++++++
 block/qcow.c           |  2 +-
 block/qcow2.c          |  2 +-
 crypto/block-luks.c    | 67 ++++++++++++++++++++++++++++++++++++++++++++
 crypto/block.c         | 17 +++++++++++
 crypto/blockpriv.h     |  4 +++
 include/block/aio.h    |  2 +-
 include/crypto/block.h | 16 +++++++++++
 qapi/block-core.json   |  6 +++-
 qapi/crypto.json       | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 237 insertions(+), 4 deletions(-)
Signature · 1 line
2.9.0
author
#1 lore raw

[Qemu-devel] [PULL 1/4] qcow2: do not allocate extra memory

From: Vladimir Sementsov-Ogievskiy <[email protected]>

There are no needs to allocate more than one cluster, as we set avail_out for deflate to one cluster.

Zlib docs (http://www.zlib.net/manual.html) says:
"deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full."

So, deflate will not write more than avail_out to output buffer. If there is not enough space in output buffer for compressed data (it may be larger than input data) deflate just returns Z_OK. (if all data is compressed and written to output buffer deflate returns Z_STREAM_END).

Message-id: [email protected]

---
 block/qcow.c  | 2 +-
 block/qcow2.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
block/qcow.c +1 -1
index 0c7b75b..6f9b2e2 100644
@@ -983,7 +983,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
         return ret;
     }
 
-    out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
+    out_buf = g_malloc(s->cluster_size);
 
     /* best compression, small window, no zlib header */
     memset(&strm, 0, sizeof(strm));
block/qcow2.c +1 -1
index a6bca73..b326d0b 100644
@@ -2612,7 +2612,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num,
         return ret;
     }
 
-    out_buf = g_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
+    out_buf = g_malloc(s->cluster_size);
 
     /* best compression, small window, no zlib header */
     memset(&strm, 0, sizeof(strm));
Signature · 1 line
2.9.0
author
#2 lore raw

[Qemu-devel] [PULL 2/4] AioContext: correct comments

In reply to Max Reitz

From: Cao jin <[email protected]>

Correct comments of field notify_me

Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>

Message-id: [email protected]

---
 include/block/aio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/block/aio.h +1 -1
index 209551d..173c1ed 100644
@@ -74,7 +74,7 @@ struct AioContext {
      * event_notifier_set necessary.
      *
      * Bit 0 is reserved for GSource usage of the AioContext, and is 1
-     * between a call to aio_ctx_check and the next call to aio_ctx_dispatch.
+     * between a call to aio_ctx_prepare and the next call to aio_ctx_check.
      * Bits 1-31 simply count the number of active calls to aio_poll
      * that are in the prepare or poll phase.
      *
Signature · 1 line
2.9.0
author
#3 lore raw

[Qemu-devel] [PULL 3/4] crypto: add support for querying parameters for block encryption

In reply to Max Reitz

From: "Daniel P. Berrange" <[email protected]>

When creating new block encryption volumes, we accept a list of parameters to control the formatting process. It is useful to be able to query what those parameters were for existing block devices. Add a qcrypto_block_get_info() method which returns a QCryptoBlockInfo instance to report this data.

Message-id: [email protected]

---
 crypto/block-luks.c    | 67 ++++++++++++++++++++++++++++++++++++++++++++
 crypto/block.c         | 17 +++++++++++
 crypto/blockpriv.h     |  4 +++
 include/crypto/block.h | 16 +++++++++++
 qapi/crypto.json       | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 180 insertions(+)
crypto/block-luks.c +67 -0
index fcf3b04..aba4455 100644
@@ -201,6 +201,15 @@ QEMU_BUILD_BUG_ON(sizeof(struct QCryptoBlockLUKSHeader) != 592);
 
 struct QCryptoBlockLUKS {
     QCryptoBlockLUKSHeader header;
+
+    /* Cache parsed versions of what's in header fields,
+     * as we can't rely on QCryptoBlock.cipher being
+     * non-NULL */
+    QCryptoCipherAlgorithm cipher_alg;
+    QCryptoCipherMode cipher_mode;
+    QCryptoIVGenAlgorithm ivgen_alg;
+    QCryptoHashAlgorithm ivgen_hash_alg;
+    QCryptoHashAlgorithm hash_alg;
 };
 
 
@@ -847,6 +856,12 @@ qcrypto_block_luks_open(QCryptoBlock *block,
     block->payload_offset = luks->header.payload_offset *
         QCRYPTO_BLOCK_LUKS_SECTOR_SIZE;
 
+    luks->cipher_alg = cipheralg;
+    luks->cipher_mode = ciphermode;
+    luks->ivgen_alg = ivalg;
+    luks->ivgen_hash_alg = ivhash;
+    luks->hash_alg = hash;
+
     g_free(masterkey);
     g_free(password);
 
@@ -1271,6 +1286,12 @@ qcrypto_block_luks_create(QCryptoBlock *block,
         goto error;
     }
 
+    luks->cipher_alg = luks_opts.cipher_alg;
+    luks->cipher_mode = luks_opts.cipher_mode;
+    luks->ivgen_alg = luks_opts.ivgen_alg;
+    luks->ivgen_hash_alg = luks_opts.ivgen_hash_alg;
+    luks->hash_alg = luks_opts.hash_alg;
+
     memset(masterkey, 0, luks->header.key_bytes);
     g_free(masterkey);
     memset(slotkey, 0, luks->header.key_bytes);
@@ -1305,6 +1326,51 @@ qcrypto_block_luks_create(QCryptoBlock *block,
 }
 
 
+static int qcrypto_block_luks_get_info(QCryptoBlock *block,
+                                       QCryptoBlockInfo *info,
+                                       Error **errp)
+{
+    QCryptoBlockLUKS *luks = block->opaque;
+    QCryptoBlockInfoLUKSSlot *slot;
+    QCryptoBlockInfoLUKSSlotList *slots = NULL, **prev = &info->u.luks.slots;
+    size_t i;
+
+    info->u.luks.cipher_alg = luks->cipher_alg;
+    info->u.luks.cipher_mode = luks->cipher_mode;
+    info->u.luks.ivgen_alg = luks->ivgen_alg;
+    if (info->u.luks.ivgen_alg == QCRYPTO_IVGEN_ALG_ESSIV) {
+        info->u.luks.has_ivgen_hash_alg = true;
+        info->u.luks.ivgen_hash_alg = luks->ivgen_hash_alg;
+    }
+    info->u.luks.hash_alg = luks->hash_alg;
+    info->u.luks.payload_offset = block->payload_offset;
+    info->u.luks.master_key_iters = luks->header.master_key_iterations;
+    info->u.luks.uuid = g_strndup((const char *)luks->header.uuid,
+                                  sizeof(luks->header.uuid));
+
+    for (i = 0; i < QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS; i++) {
+        slots = g_new0(QCryptoBlockInfoLUKSSlotList, 1);
+        *prev = slots;
+
+        slots->value = slot = g_new0(QCryptoBlockInfoLUKSSlot, 1);
+        slot->active = luks->header.key_slots[i].active ==
+            QCRYPTO_BLOCK_LUKS_KEY_SLOT_ENABLED;
+        slot->key_offset = luks->header.key_slots[i].key_offset
+             * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE;
+        if (slot->active) {
+            slot->has_iters = true;
+            slot->iters = luks->header.key_slots[i].iterations;
+            slot->has_stripes = true;
+            slot->stripes = luks->header.key_slots[i].stripes;
+        }
+
+        prev = &slots->next;
+    }
+
+    return 0;
+}
+
+
 static void qcrypto_block_luks_cleanup(QCryptoBlock *block)
 {
     g_free(block->opaque);
@@ -1342,6 +1408,7 @@ qcrypto_block_luks_encrypt(QCryptoBlock *block,
 const QCryptoBlockDriver qcrypto_block_driver_luks = {
     .open = qcrypto_block_luks_open,
     .create = qcrypto_block_luks_create,
+    .get_info = qcrypto_block_luks_get_info,
     .cleanup = qcrypto_block_luks_cleanup,
     .decrypt = qcrypto_block_luks_decrypt,
     .encrypt = qcrypto_block_luks_encrypt,
crypto/block.c +17 -0
index da60eba..be823ee 100644
@@ -105,6 +105,23 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
 }
 
 
+QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block,
+                                         Error **errp)
+{
+    QCryptoBlockInfo *info = g_new0(QCryptoBlockInfo, 1);
+
+    info->format = block->format;
+
+    if (block->driver->get_info &&
+        block->driver->get_info(block, info, errp) < 0) {
+        g_free(info);
+        return NULL;
+    }
+
+    return info;
+}
+
+
 int qcrypto_block_decrypt(QCryptoBlock *block,
                           uint64_t startsector,
                           uint8_t *buf,
crypto/blockpriv.h +4 -0
index 15b547d..68f0f06 100644
@@ -53,6 +53,10 @@ struct QCryptoBlockDriver {
                   void *opaque,
                   Error **errp);
 
+    int (*get_info)(QCryptoBlock *block,
+                    QCryptoBlockInfo *info,
+                    Error **errp);
+
     void (*cleanup)(QCryptoBlock *block);
 
     int (*encrypt)(QCryptoBlock *block,
include/crypto/block.h +16 -0
index 8955211..b6971de 100644
@@ -138,6 +138,22 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
                                    void *opaque,
                                    Error **errp);
 
+
+/**
+ * qcrypto_block_get_info:
+ * @block: the block encryption object
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Get information about the configuration options for the
+ * block encryption object. This includes details such as
+ * the cipher algorithms, modes, and initialization vector
+ * generators.
+ *
+ * Returns: a block encryption info object, or NULL on error
+ */
+QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block,
+                                         Error **errp);
+
 /**
  * @qcrypto_block_decrypt:
  * @block: the block encryption object
qapi/crypto.json +76 -0

79 lines not on this page · raw message

Signature · 1 line
2.9.0
author
#4 lore raw

[Qemu-devel] [PULL 4/4] block: export LUKS specific data to qemu-img info

In reply to Max Reitz

From: "Daniel P. Berrange" <[email protected]>

The qemu-img info command has the ability to expose format specific metadata about volumes. Wire up this facility for the LUKS driver to report on cipher configuration and key slot usage.

    $ qemu-img info ~/VirtualMachines/demo.luks
    image: /home/berrange/VirtualMachines/demo.luks
    file format: luks
    virtual size: 98M (102760448 bytes)
    disk size: 100M
    encrypted: yes
    Format specific information:
        ivgen alg: plain64
        hash alg: sha1
        cipher alg: aes-128
        uuid: 6ddee74b-3a22-408c-8909-6789d4fa2594
        cipher mode: xts
        slots:
            [0]:
                active: true
                iters: 572706
                key offset: 4096
                stripes: 4000
            [1]:
                active: false
                key offset: 135168
            [2]:
                active: false
                key offset: 266240
            [3]:
                active: false
                key offset: 397312
            [4]:
                active: false
                key offset: 528384
            [5]:
                active: false
                key offset: 659456
            [6]:
                active: false
                key offset: 790528
            [7]:
                active: false
                key offset: 921600
        payload offset: 2097152
        master key iters: 142375

One somewhat undesirable artifact is that the data fields are printed out in (apparently) random order. This will be addressed later by changing the way the block layer pretty-prints the image specific data.

Message-id: [email protected]

---
 block/crypto.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 qapi/block-core.json |  6 +++++-
 2 files changed, 54 insertions(+), 1 deletion(-)
block/crypto.c +49 -0
index 7eaa057..7f61e12 100644
@@ -563,6 +563,53 @@ static int block_crypto_create_luks(const char *filename,
                                        filename, opts, errp);
 }
 
+static int block_crypto_get_info_luks(BlockDriverState *bs,
+                                      BlockDriverInfo *bdi)
+{
+    BlockDriverInfo subbdi;
+    int ret;
+
+    ret = bdrv_get_info(bs->file->bs, &subbdi);
+    if (ret != 0) {
+        return ret;
+    }
+
+    bdi->unallocated_blocks_are_zero = false;
+    bdi->can_write_zeroes_with_unmap = false;
+    bdi->cluster_size = subbdi.cluster_size;
+
+    return 0;
+}
+
+static ImageInfoSpecific *
+block_crypto_get_specific_info_luks(BlockDriverState *bs)
+{
+    BlockCrypto *crypto = bs->opaque;
+    ImageInfoSpecific *spec_info;
+    QCryptoBlockInfo *info;
+
+    info = qcrypto_block_get_info(crypto->block, NULL);
+    if (!info) {
+        return NULL;
+    }
+    if (info->format != Q_CRYPTO_BLOCK_FORMAT_LUKS) {
+        qapi_free_QCryptoBlockInfo(info);
+        return NULL;
+    }
+
+    spec_info = g_new(ImageInfoSpecific, 1);
+    spec_info->type = IMAGE_INFO_SPECIFIC_KIND_LUKS;
+    spec_info->u.luks.data = g_new(QCryptoBlockInfoLUKS, 1);
+    *spec_info->u.luks.data = info->u.luks;
+
+    /* Blank out pointers we've just stolen to avoid double free */
+    memset(&info->u.luks, 0, sizeof(info->u.luks));
+
+    qapi_free_QCryptoBlockInfo(info);
+
+    return spec_info;
+}
+
 BlockDriver bdrv_crypto_luks = {
     .format_name        = "luks",
     .instance_size      = sizeof(BlockCrypto),
@@ -576,6 +623,8 @@ BlockDriver bdrv_crypto_luks = {
     .bdrv_co_readv      = block_crypto_co_readv,
     .bdrv_co_writev     = block_crypto_co_writev,
     .bdrv_getlength     = block_crypto_getlength,
+    .bdrv_get_info      = block_crypto_get_info_luks,
+    .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
 };
 
 static void block_crypto_init(void)
qapi/block-core.json +5 -1
index 3444a9b..8d1913d 100644
@@ -85,7 +85,11 @@
 { 'union': 'ImageInfoSpecific',
   'data': {
       'qcow2': 'ImageInfoSpecificQCow2',
-      'vmdk': 'ImageInfoSpecificVmdk'
+      'vmdk': 'ImageInfoSpecificVmdk',
+      # If we need to add block driver specific parameters for
+      # LUKS in future, then we'll subclass QCryptoBlockInfoLUKS
+      # to define a ImageInfoSpecificLUKS
+      'luks': 'QCryptoBlockInfoLUKS'
   } }
 
 ##
Signature · 1 line
2.9.0
#5 lore raw
In reply to Max Reitz
Quoted 8 lines · Max Reitz

The following changes since commit 5d3217340adcb6c4f0e4af5d2b865331eb2ff63d:

disas: Fix ATTRIBUTE_UNUSED define clash with ALSA headers (2016-07-19 16:40:39 +0100)

are available in the git repository at:

git://github.com/XanClic/qemu.git tags/pull-block-2016-07-20

Quoted 8 lines

for you to fetch changes up to bafea5b7c26dd14895f7be64685a12645a75f4cf:

block: export LUKS specific data to qemu-img info (2016-07-20 00:34:03 +0200)

----------------------------------------------------------------
Block patches for master

----------------------------------------------------------------

Fails to build on everything:

GEN qapi-visit.h
In file included from /Users/pm215/src/qemu-for-merges/qapi-schema.json:9:
/Users/pm215/src/qemu-for-merges/qapi/crypto.json:299: Union 'QCryptoBlockInfo' data missing 'qcow' branch

thanks
-- PMM

#6 lore raw
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Max Reitz

The following changes since commit 5d3217340adcb6c4f0e4af5d2b865331eb2ff63d:

disas: Fix ATTRIBUTE_UNUSED define clash with ALSA headers (2016-07-19 16:40:39 +0100)

are available in the git repository at:

git://github.com/XanClic/qemu.git tags/pull-block-2016-07-20

for you to fetch changes up to bafea5b7c26dd14895f7be64685a12645a75f4cf:

block: export LUKS specific data to qemu-img info (2016-07-20 00:34:03 +0200)

----------------------------------------------------------------
Block patches for master

Quoted 8 lines
Quoted 1 line

----------------------------------------------------------------

Fails to build on everything:

GEN qapi-visit.h
In file included from /Users/pm215/src/qemu-for-merges/qapi-schema.json:9:
/Users/pm215/src/qemu-for-merges/qapi/crypto.json:299: Union 'QCryptoBlockInfo' data missing 'qcow' branch

Aha. Cause is two branches developed in parallel; commit d0b18239 forces all branches of a flat union to be listed (to avoid an abort() if the user passes a branch that was not listed); solution is to expand the crypto.json addition to cover all branches, even if it means an empty type for the branches that have no additional data.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw
Quoted 26 lines · Eric Blake
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Max Reitz

The following changes since commit 5d3217340adcb6c4f0e4af5d2b865331eb2ff63d:

disas: Fix ATTRIBUTE_UNUSED define clash with ALSA headers (2016-07-19 16:40:39 +0100)

are available in the git repository at:

git://github.com/XanClic/qemu.git tags/pull-block-2016-07-20

for you to fetch changes up to bafea5b7c26dd14895f7be64685a12645a75f4cf:

block: export LUKS specific data to qemu-img info (2016-07-20 00:34:03 +0200)

----------------------------------------------------------------
Block patches for master

Quoted 8 lines
Quoted 1 line

----------------------------------------------------------------

Fails to build on everything:

GEN qapi-visit.h
In file included from /Users/pm215/src/qemu-for-merges/qapi-schema.json:9:
/Users/pm215/src/qemu-for-merges/qapi/crypto.json:299: Union 'QCryptoBlockInfo' data missing 'qcow' branch

Quoted 5 lines

Aha. Cause is two branches developed in parallel; commit d0b18239 forces all branches of a flat union to be listed (to avoid an abort() if the user passes a branch that was not listed); solution is to expand the crypto.json addition to cover all branches, even if it means an empty type for the branches that have no additional data.

I'm just processing the last other outstanding pullreq now, so unless a respin of this arrives by tomorrow lunchtime UK time it's going to miss rc0, I think.

thanks
-- PMM

author
#8 lore raw
Quoted 33 lines · Peter Maydell
Quoted 26 lines · Eric Blake
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Max Reitz

The following changes since commit 5d3217340adcb6c4f0e4af5d2b865331eb2ff63d:

disas: Fix ATTRIBUTE_UNUSED define clash with ALSA headers (2016-07-19 16:40:39 +0100)

are available in the git repository at:

git://github.com/XanClic/qemu.git tags/pull-block-2016-07-20

for you to fetch changes up to bafea5b7c26dd14895f7be64685a12645a75f4cf:

block: export LUKS specific data to qemu-img info (2016-07-20 00:34:03 +0200)

----------------------------------------------------------------
Block patches for master

Quoted 8 lines
Quoted 1 line

----------------------------------------------------------------

Fails to build on everything:

GEN qapi-visit.h
In file included from /Users/pm215/src/qemu-for-merges/qapi-schema.json:9:
/Users/pm215/src/qemu-for-merges/qapi/crypto.json:299: Union 'QCryptoBlockInfo' data missing 'qcow' branch

Quoted 5 lines

Aha. Cause is two branches developed in parallel; commit d0b18239 forces all branches of a flat union to be listed (to avoid an abort() if the user passes a branch that was not listed); solution is to expand the crypto.json addition to cover all branches, even if it means an empty type for the branches that have no additional data.

Quoted 3 lines

I'm just processing the last other outstanding pullreq now, so unless a respin of this arrives by tomorrow lunchtime UK time it's going to miss rc0, I think.

Since there's nothing critical in this pull request, I'll drop the crypto patches and keep the non-offending patches for the next pull request (for rc1).

So no need to wait for another pull request from me for rc0.

Max