qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P . Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 12/30] qapi crypto: Elide redundant has_FOO in generated C
Date: Wed, 14 Dec 2022 08:47:03 +0100	[thread overview]
Message-ID: <20221214074721.731441-15-armbru@redhat.com> (raw)
In-Reply-To: <20221214074721.731441-1-armbru@redhat.com>

The has_FOO for pointer-valued FOO are redundant, except for arrays.
They are also a nuisance to work with.  Recent commit "qapi: Start to
elide redundant has_FOO in generated C" provided the means to elide
them step by step.  This is the step for qapi/crypto.json.

Said commit explains the transformation in more detail.  The invariant
violations mentioned there do not occur here.

Cc: Daniel P. Berrangé" <berrange@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20221104160712.3005652-13-armbru@redhat.com>
---
 crypto/block-luks.c            | 16 ++++++++--------
 tests/unit/test-crypto-block.c |  6 ------
 scripts/qapi/schema.py         |  1 -
 3 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/crypto/block-luks.c b/crypto/block-luks.c
index df2b4105d6..ff9e3945d1 100644
--- a/crypto/block-luks.c
+++ b/crypto/block-luks.c
@@ -1597,13 +1597,13 @@ qcrypto_block_luks_amend_add_keyslot(QCryptoBlock *block,
     g_autofree char *new_password = NULL;
     g_autofree uint8_t *master_key = NULL;
 
-    char *secret = opts_luks->has_secret ? opts_luks->secret : luks->secret;
+    char *secret = opts_luks->secret ?: luks->secret;
 
-    if (!opts_luks->has_new_secret) {
+    if (!opts_luks->new_secret) {
         error_setg(errp, "'new-secret' is required to activate a keyslot");
         return -1;
     }
-    if (opts_luks->has_old_secret) {
+    if (opts_luks->old_secret) {
         error_setg(errp,
                    "'old-secret' must not be given when activating keyslots");
         return -1;
@@ -1677,7 +1677,7 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
     g_autofree uint8_t *tmpkey = NULL;
     g_autofree char *old_password = NULL;
 
-    if (opts_luks->has_new_secret) {
+    if (opts_luks->new_secret) {
         error_setg(errp,
                    "'new-secret' must not be given when erasing keyslots");
         return -1;
@@ -1687,14 +1687,14 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
                    "'iter-time' must not be given when erasing keyslots");
         return -1;
     }
-    if (opts_luks->has_secret) {
+    if (opts_luks->secret) {
         error_setg(errp,
                    "'secret' must not be given when erasing keyslots");
         return -1;
     }
 
     /* Load the old password if given */
-    if (opts_luks->has_old_secret) {
+    if (opts_luks->old_secret) {
         old_password = qcrypto_secret_lookup_as_utf8(opts_luks->old_secret,
                                                      errp);
         if (!old_password) {
@@ -1719,7 +1719,7 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
             return -1;
         }
 
-        if (opts_luks->has_old_secret) {
+        if (opts_luks->old_secret) {
             int rv = qcrypto_block_luks_load_key(block,
                                                  keyslot,
                                                  old_password,
@@ -1761,7 +1761,7 @@ qcrypto_block_luks_amend_erase_keyslots(QCryptoBlock *block,
         }
 
     /* Erase all keyslots that match the given old password */
-    } else if (opts_luks->has_old_secret) {
+    } else if (opts_luks->old_secret) {
 
         unsigned long slots_to_erase_bitmap = 0;
         size_t i;
diff --git a/tests/unit/test-crypto-block.c b/tests/unit/test-crypto-block.c
index b629e240a9..347cd5f3d7 100644
--- a/tests/unit/test-crypto-block.c
+++ b/tests/unit/test-crypto-block.c
@@ -41,7 +41,6 @@
 static QCryptoBlockCreateOptions qcow_create_opts = {
     .format = Q_CRYPTO_BLOCK_FORMAT_QCOW,
     .u.qcow = {
-        .has_key_secret = true,
         .key_secret = (char *)"sec0",
     },
 };
@@ -49,7 +48,6 @@ static QCryptoBlockCreateOptions qcow_create_opts = {
 static QCryptoBlockOpenOptions qcow_open_opts = {
     .format = Q_CRYPTO_BLOCK_FORMAT_QCOW,
     .u.qcow = {
-        .has_key_secret = true,
         .key_secret = (char *)"sec0",
     },
 };
@@ -59,7 +57,6 @@ static QCryptoBlockOpenOptions qcow_open_opts = {
 static QCryptoBlockOpenOptions luks_open_opts = {
     .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
     .u.luks = {
-        .has_key_secret = true,
         .key_secret = (char *)"sec0",
     },
 };
@@ -69,7 +66,6 @@ static QCryptoBlockOpenOptions luks_open_opts = {
 static QCryptoBlockCreateOptions luks_create_opts_default = {
     .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
     .u.luks = {
-        .has_key_secret = true,
         .key_secret = (char *)"sec0",
     },
 };
@@ -79,7 +75,6 @@ static QCryptoBlockCreateOptions luks_create_opts_default = {
 static QCryptoBlockCreateOptions luks_create_opts_aes256_cbc_plain64 = {
     .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
     .u.luks = {
-        .has_key_secret = true,
         .key_secret = (char *)"sec0",
         .has_cipher_alg = true,
         .cipher_alg = QCRYPTO_CIPHER_ALG_AES_256,
@@ -94,7 +89,6 @@ static QCryptoBlockCreateOptions luks_create_opts_aes256_cbc_plain64 = {
 static QCryptoBlockCreateOptions luks_create_opts_aes256_cbc_essiv = {
     .format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
     .u.luks = {
-        .has_key_secret = true,
         .key_secret = (char *)"sec0",
         .has_cipher_alg = true,
         .cipher_alg = QCRYPTO_CIPHER_ALG_AES_256,
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 707c671133..21d0b28790 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -759,7 +759,6 @@ def need_has(self):
         assert self.type
         # Temporary hack to support dropping the has_FOO in reviewable chunks
         opt_out = [
-            'qapi/crypto.json',
             'qapi/dump.json',
             'qapi/job.json',
             'qapi/machine.json',
-- 
2.37.3



  parent reply	other threads:[~2022-12-14  7:48 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14  7:46 [PULL 00/30] QAPI patches patches for 2022-12-14 Markus Armbruster
2022-12-14  7:46 ` [PULL 01/30] docs/devel/qapi-code-gen: Update example to match current code Markus Armbruster
2022-12-14  7:46 ` [PATCH 1/2] include/hw/virtio: Break inclusion loop Markus Armbruster
2022-12-14  7:49   ` Markus Armbruster
2022-12-14  7:46 ` [PATCH 2/2] include: Include headers where needed Markus Armbruster
2022-12-14  7:49   ` Markus Armbruster
2022-12-14  7:46 ` [PULL 02/30] qapi: Tidy up whitespace in generated code Markus Armbruster
2022-12-14  7:46 ` [PULL 03/30] docs/devel/qapi-code-gen: Extend example for next commit's change Markus Armbruster
2022-12-14  7:46 ` [PULL 04/30] qapi: Start to elide redundant has_FOO in generated C Markus Armbruster
2022-12-14  7:46 ` [PULL 05/30] qapi tests: Elide " Markus Armbruster
2022-12-14  7:46 ` [PULL 06/30] qapi acpi: " Markus Armbruster
2022-12-14  7:46 ` [PULL 07/30] qapi audio: " Markus Armbruster
2022-12-14  7:46 ` [PULL 08/30] blockdev: Clean up abuse of DriveBackup member format Markus Armbruster
2022-12-14  7:47 ` [PULL 09/30] nbd/server: Clean up abuse of BlockExportOptionsNbd member @arg Markus Armbruster
2022-12-14  7:47 ` [PULL 10/30] qapi block: Elide redundant has_FOO in generated C Markus Armbruster
2022-12-14  7:47 ` [PULL 11/30] qapi chardev: " Markus Armbruster
2022-12-14  7:47 ` Markus Armbruster [this message]
2022-12-14  7:47 ` [PULL 13/30] qapi dump: " Markus Armbruster
2022-12-14  7:47 ` [PULL 14/30] qapi job: " Markus Armbruster
2022-12-14  7:47 ` [PULL 15/30] qapi machine: " Markus Armbruster
2022-12-14  7:47 ` [PULL 16/30] qapi migration: " Markus Armbruster
2022-12-14  7:47 ` [PULL 17/30] qapi misc: " Markus Armbruster
2022-12-14  7:47 ` [PULL 18/30] qapi net: " Markus Armbruster
2022-12-14  7:47 ` [PULL 19/30] qapi pci: " Markus Armbruster
2022-12-14  7:47 ` [PULL 20/30] qapi qdev qom: " Markus Armbruster
2022-12-14  7:47 ` [PULL 21/30] qapi replay: " Markus Armbruster
2022-12-14  7:47 ` [PULL 22/30] qapi rocker: " Markus Armbruster
2022-12-14  7:47 ` [PULL 23/30] qapi run-state: " Markus Armbruster
2022-12-14  7:47 ` [PULL 24/30] qapi stats: " Markus Armbruster
2022-12-14  7:47 ` [PULL 25/30] qapi tpm: " Markus Armbruster
2022-12-14  7:47 ` [PULL 26/30] qapi transaction: " Markus Armbruster
2022-12-14  7:47 ` [PULL 27/30] qapi ui: " Markus Armbruster
2022-12-14  7:47 ` [PULL 28/30] qapi virtio: " Markus Armbruster
2022-12-14  7:47 ` [PULL 29/30] qapi qga: " Markus Armbruster
2022-12-14  7:47 ` [PULL 30/30] qapi: Drop temporary logic to support conversion step by step Markus Armbruster
2022-12-14 17:03 ` [PULL 00/30] QAPI patches patches for 2022-12-14 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214074721.731441-15-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).