From nobody Wed Nov 27 02:45: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=1701880849; cv=none; d=zohomail.com; s=zohoarc; b=mfwikh9QqSEJPb7uL3xXaWSUxLIZgeE8hToZHDb71g2p9TV3WfHpxJt4fu4lknCxjpbPC6dD0iL8Pui8rt5fmsj/DoETOF3bThkWcLXDZV9YLhGILoEBXonE1yVTEirZid0mzokpKw9ACRoX5OuN00xmryLKNNWwK92Uv1nI3Bo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701880849; 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=qhMhC1dRCAzfDuzYgcsG+53k26v66QjFrETHi98zfg4=; b=D8kref6vpHlOksHSTP0Ua3IKoXe7Hv/RYEF0iJsG27VF2sDI8bwvGdimFqCgqPPgxm2nPtbg0QAp4dLuDuqwRd3WBLPiGvB2fsw/m7xEswMh5/gImt9I4CeHr6ZeMLhpAzUL3bQxNg9wSvH5we9s01octI/SlNuVCMG07BVvHbU= 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 1701880849854622.5672086488394; Wed, 6 Dec 2023 08:40:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rAuwz-0007DE-BM; Wed, 06 Dec 2023 11:40:45 -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 1rAuwb-00073Q-FN for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:18 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rAuwW-0003oq-Db for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:15 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d04c097e34so137845ad.0 for ; Wed, 06 Dec 2023 08:38:11 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m14-20020a170902bb8e00b001d04d730687sm42570pls.103.2023.12.06.08.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:38:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701880691; x=1702485491; 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=qhMhC1dRCAzfDuzYgcsG+53k26v66QjFrETHi98zfg4=; b=NK+BzmYla6ksZeyMBHdP4k25UTJOgsAIFaMJPg6yDYRQzz1AO3a6NAzUESX/KkyqUV Hz0Of38/KKtUsHMj39YKV5U7OhAgvg/4RGfykfn0YdmuSkDG+ocQsVkmScJoUenQ+gZX el+MLLl+VwGtXA1laH9BEnPIqjVv9pSicBbzti9fZNTjm8CxA08vVvBZ4IMTH+LeBQIR dwHXiFw8ZRnBjt9iZhwUxCZ4L2JPnK4XLDMAStCxKTTsaWEOaZEPiNoCNdxKYCRNgyQ9 icBJPNkaqow+6K71RJyEi1iGxrmSOIerkWxftB5y5VR6VHjZHqnoxAxAigBtxbyzBuYQ /p2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701880691; x=1702485491; 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=qhMhC1dRCAzfDuzYgcsG+53k26v66QjFrETHi98zfg4=; b=HUmOjOtyNL9favrfo/1wx3RE89yaDeZ2wp1XlVi8k9ccRhNqICaaL3xN6JRdoMeIkI 1EZ1OKR++06SpoXty4hVKbw3aMwlCBiSvYiH/nn5aAqibRpZdUOHW/FgnSgR0bVAGeLa tM16lO/SBjYBmv1b4ld9OAlsrnalQmr1w/sJDAERKc/GYO7O6bFcXDD+TwXo6M4ouLw8 HxGeqwQfoM0XY1aRyKIqQ1cHbpMq7PFejG6v+X6/HWPK/G0lD5mu94C0UEvjQQ5uQ5CA aG4lYzIygn2zVEi4wml86fe7TsUZDckeZaXqvMjFSVpgO5Sy7ly/SjJQf/mUTWsmMHsY rKXw== X-Gm-Message-State: AOJu0Yz604vUhXM6gfqvxT/DZcwZtt938hKXAcvf5aSS8A/6smB3jKgB rsbhG06On7+v25cHMotAGC8OtQdigPwKufS9/OKN1bEn X-Google-Smtp-Source: AGHT+IEXyGEuBvgs5pBKRgZaStL31ffR79X1CEOuNwkByP/zqRwAhbS7l/A9QjyOEjY5EdXcfjmN8A== X-Received: by 2002:a17:902:ff01:b0:1cf:fc91:e4d0 with SMTP id f1-20020a170902ff0100b001cffc91e4d0mr4275488plj.16.1701880690497; Wed, 06 Dec 2023 08:38:10 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [v2 4/4] block: Support detached LUKS header creation for blockdev-create Date: Thu, 7 Dec 2023 00:37:45 +0800 Message-Id: <5ca4a43ea0795d9fb6ea3649eead10017df69b1c.1701879996.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::62b; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62b.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: 1701880850203100005 Content-Type: text/plain; charset="utf-8" Provide the "detached-mode" option for detached LUKS header formatting. To format the LUKS header on the pre-creating disk, example as follows: 1. add a protocol blockdev node of LUKS header $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-1-storage", "driver":"file", > "filename":"/path/to/cipher.gluks" }}' 2. add the secret for encrypting the cipher stored in LUKS header above $ virsh qemu-monitor-command vm '{"execute":"object-add", > "arguments":{"qom-type": "secret", "id": > "libvirt-1-storage-secret0", "data": "abc123"}}' 3. format the disk node $ virsh qemu-monitor-command vm '{"execute":"blockdev-create", > "arguments":{"job-id":"job0", "options":{"driver":"luks", > "size":0, "file":"libvirt-1-storage", "detached-mode":true, > "cipher-alg":"aes-256", > "key-secret":"libvirt-3-storage-encryption-secret0"}}}' Signed-off-by: Hyman Huang --- block/crypto.c | 8 +++++++- qapi/block-core.json | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 7d70349463..e77c49bd0c 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -667,10 +667,12 @@ block_crypto_co_create_luks(BlockdevCreateOptions *cr= eate_options, Error **errp) BlockDriverState *bs =3D NULL; QCryptoBlockCreateOptions create_opts; PreallocMode preallocation =3D PREALLOC_MODE_OFF; + int64_t size; int ret; =20 assert(create_options->driver =3D=3D BLOCKDEV_DRIVER_LUKS); luks_opts =3D &create_options->u.luks; + size =3D luks_opts->size; =20 bs =3D bdrv_co_open_blockdev_ref(luks_opts->file, errp); if (bs =3D=3D NULL) { @@ -686,7 +688,11 @@ block_crypto_co_create_luks(BlockdevCreateOptions *cre= ate_options, Error **errp) preallocation =3D luks_opts->preallocation; } =20 - ret =3D block_crypto_co_create_generic(bs, luks_opts->size, &create_op= ts, + if (luks_opts->detached_mode) { + size =3D 0; + } + + ret =3D block_crypto_co_create_generic(bs, size, &create_opts, preallocation, errp); if (ret < 0) { goto fail; diff --git a/qapi/block-core.json b/qapi/block-core.json index 10be08d08f..1e7a7e1b05 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4952,13 +4952,16 @@ # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full) # +# @detached-mode: create a detached LUKS header. (since 9.0) +# # Since: 2.12 ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', 'data': { 'file': 'BlockdevRef', 'size': 'size', - '*preallocation': 'PreallocMode' } } + '*preallocation': 'PreallocMode', + '*detached-mode': 'bool'}} =20 ## # @BlockdevCreateOptionsNfs: --=20 2.39.1