From nobody Wed Nov 27 00:47:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1703482264; cv=none; d=zohomail.com; s=zohoarc; b=elLuL2BBHRDx04sjRT/LgXpj14e46azSYTP60zTkpnNbOw78Sys24fSN/1qlfiiSvWX5hg501WsOJwi8miDdf+Y5VxOZ508cONmv8Fx/u0DLCmvGPbUHbHk9uTlCNK5IyNWaTQ4/+DTjZxAHzPEdffVLkIzjFkBjaGm7S1+cdwQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703482264; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bld8BoqgmZ1DODtactYuR62piREfvI2piUdxD5IPPLM=; b=JmD0ZFkFocXF9F+n42bQhBjDYiBLFU/aNvhUzKwLHbe8XfSJzorG2GTuV5sPa5av8KqLnsVnvFS8m4+JYLv48xV5//mYKeCki0CtAhxVBICKBu504wSPNNzHhLNWEGVcEcuwpFsSiAk3mWgH2PCSfwn4V3Lw+DwaKL+EfH41Z/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703482264833497.1727705391537; Sun, 24 Dec 2023 21:31:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHdXD-000565-LE; Mon, 25 Dec 2023 00:29:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHdXC-00055n-9m for qemu-devel@nongnu.org; Mon, 25 Dec 2023 00:29:50 -0500 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rHdXA-0007K1-Ne for qemu-devel@nongnu.org; Mon, 25 Dec 2023 00:29:50 -0500 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6dbed9bb54eso157630a34.3 for ; Sun, 24 Dec 2023 21:27:48 -0800 (PST) Received: from localhost.localdomain ([118.114.58.28]) by smtp.gmail.com with ESMTPSA id f7-20020aa79d87000000b006d991505b4csm4555800pfq.76.2023.12.24.21.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 21:27:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1703482067; x=1704086867; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bld8BoqgmZ1DODtactYuR62piREfvI2piUdxD5IPPLM=; b=oEq3manE1MTZfKK5CSltZmAW73sgBnital4Hp4AO5p6LjlV9fvL/XmdptZuqMLLI1t ABLQWe5NUhoeqG6ZHTxvyILbMPNSN2CI/4zkfZUqzA6iscpgQBwuksRpbVkE5R/3J6G/ zrruupa8E64WC3oncoYqGt22jOPkQxuhHljlnzKjsQoK//P1E4dPNeQcZOUMrpWu3OBP VxbPVmztGsVT1ldxElwN/NYHvVWO5uqbcwLsFiEa9BnkBtsbPT33gjZTn4UcWB5rj9E9 gAzauzMZ9Gp66St7FIhPBb3Aa3ZCR9hWjG6RlkvOAPtd2P+FxVFOAMn5gWBZFZe/4UZQ yE2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703482067; x=1704086867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bld8BoqgmZ1DODtactYuR62piREfvI2piUdxD5IPPLM=; b=iQNMxIyRIoUxQ7mbM8tkgoW+t1XcgSxqVSAX6D2QFeMbDqYM/vWZA12ebmhpQBdCrc bQ9nHS5AJJ3gHcoLpib6ChI7qzt0DdA2Fu33Y0zL+wvdTR3uNGyEog9W12uHDI25q4dO Ii7PmyrQyFDwm1oTmjbfNgy1Hz1lKBCu6Hzz7P1Cm8jQJAlw3bu9FFK0LP7SrnP+8U4g W8tNWKP21YYzzNSMwn94rcMdHdfHrdUOyNdEdhfpCvUPYKIgvvofIa3/4AlV5IaAspiC BgeHNWYxm/7T2oFTHtKVUDO7C0VSoBsiiYLOBIdK6PUosnYJ6ac6N7KfLPxAijbun3Nn CJgg== X-Gm-Message-State: AOJu0YyVGpboEUuohAU/QKyMSAQ76tYUgLdX9F+08ZN0FSV8Ea2EFUHP 3bdOgE+MGD7E/+2J+r5AHp0d/lEpHO0ZQfDRAC+To5GGM3EZIA== X-Google-Smtp-Source: AGHT+IFqsOQZrHXQTnPAowZ0lbrQKWsFf7FgGEmoDaYo4eCOVYL8D4kYNcX8icIrTFA/FXfQ0kfQIw== X-Received: by 2002:a05:6830:2701:b0:6d9:d3dc:231e with SMTP id j1-20020a056830270100b006d9d3dc231emr3647119otu.66.1703482066989; Sun, 24 Dec 2023 21:27:46 -0800 (PST) From: Hyman Huang To: qemu-devel Cc: Kevin Wolf , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Hanna Reitz , Eric Blake , Markus Armbruster , Hyman Huang Subject: [v3 07/10] block: Support detached LUKS header creation using qemu-img Date: Mon, 25 Dec 2023 13:26:57 +0800 Message-Id: <3179dbd4232303c64906eeffa2912d09a0fdcbeb.1703481380.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::32c; envelope-from=yong.huang@smartx.com; helo=mail-ot1-x32c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703482266947100007 Content-Type: text/plain; charset="utf-8" Add the 'detached-mode' option to specify the creation of a detached LUKS header. This is how it is used: $ qemu-img create --object secret,id=3Dsec0,data=3Dabc123 -f luks > -o cipher-alg=3Daes-256,cipher-mode=3Dxts -o key-secret=3Dsec0 > -o detached-mode=3Dtrue header.luks Signed-off-by: Hyman Huang --- block.c | 5 ++++- block/crypto.c | 9 ++++++++- block/crypto.h | 8 ++++++++ qapi/crypto.json | 5 ++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index bfb0861ec6..fa9ce36928 100644 --- a/block.c +++ b/block.c @@ -7517,7 +7517,10 @@ void bdrv_img_create(const char *filename, const cha= r *fmt, goto out; } =20 - if (size =3D=3D -1) { + /* Parameter 'size' is not needed for detached LUKS header */ + if (size =3D=3D -1 && + !(!strcmp(fmt, "luks") && + qemu_opt_get_bool(opts, "detached-mode", false))) { error_setg(errp, "Image creation needs a size parameter"); goto out; } diff --git a/block/crypto.c b/block/crypto.c index 76cc8bda49..812c3c28f5 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -229,6 +229,7 @@ static QemuOptsList block_crypto_create_opts_luks =3D { BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG(""), BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG(""), BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_DETACHED_MODE(""), { /* end of list */ } }, }; @@ -793,6 +794,8 @@ block_crypto_co_create_opts_luks(BlockDriver *drv, cons= t char *filename, PreallocMode prealloc; char *buf =3D NULL; int64_t size; + bool detached_mode =3D + qemu_opt_get_bool(opts, "detached-mode", false); int ret; Error *local_err =3D NULL; =20 @@ -832,8 +835,12 @@ block_crypto_co_create_opts_luks(BlockDriver *drv, con= st char *filename, goto fail; } =20 + /* The detached_header default to true if detached-mode is specified */ + create_opts->u.luks.detached_header =3D detached_mode ? true : false; + /* Create format layer */ - ret =3D block_crypto_co_create_generic(bs, size, create_opts, prealloc= , errp); + ret =3D block_crypto_co_create_generic(bs, detached_mode ? 0 : size, + create_opts, prealloc, errp); if (ret < 0) { goto fail; } diff --git a/block/crypto.h b/block/crypto.h index 72e792c9af..bceefd45bd 100644 --- a/block/crypto.h +++ b/block/crypto.h @@ -41,6 +41,7 @@ #define BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG "ivgen-hash-alg" #define BLOCK_CRYPTO_OPT_LUKS_HASH_ALG "hash-alg" #define BLOCK_CRYPTO_OPT_LUKS_ITER_TIME "iter-time" +#define BLOCK_CRYPTO_OPT_LUKS_DETACHED_MODE "detached-mode" #define BLOCK_CRYPTO_OPT_LUKS_KEYSLOT "keyslot" #define BLOCK_CRYPTO_OPT_LUKS_STATE "state" #define BLOCK_CRYPTO_OPT_LUKS_OLD_SECRET "old-secret" @@ -100,6 +101,13 @@ .help =3D "Select new state of affected keyslots (active/inactive)= ",\ } =20 +#define BLOCK_CRYPTO_OPT_DEF_LUKS_DETACHED_MODE(prefix) \ + { \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_DETACHED_MODE, \ + .type =3D QEMU_OPT_BOOL, \ + .help =3D "Create a detached LUKS header", \ + } + #define BLOCK_CRYPTO_OPT_DEF_LUKS_KEYSLOT(prefix) \ { \ .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_KEYSLOT, \ diff --git a/qapi/crypto.json b/qapi/crypto.json index 6b4e86cb81..8e81aa8454 100644 --- a/qapi/crypto.json +++ b/qapi/crypto.json @@ -226,6 +226,8 @@ # @iter-time: number of milliseconds to spend in PBKDF passphrase # processing. Currently defaults to 2000. (since 2.8) # +# @detached-mode: create a detached LUKS header. (since 9.0) +# # Since: 2.6 ## { 'struct': 'QCryptoBlockCreateOptionsLUKS', @@ -235,7 +237,8 @@ '*ivgen-alg': 'QCryptoIVGenAlgorithm', '*ivgen-hash-alg': 'QCryptoHashAlgorithm', '*hash-alg': 'QCryptoHashAlgorithm', - '*iter-time': 'int'}} + '*iter-time': 'int', + '*detached-mode': 'bool'}} =20 ## # @QCryptoBlockOpenOptions: --=20 2.39.1