From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB227C43460 for ; Fri, 2 Apr 2021 16:06:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B0D261155 for ; Fri, 2 Apr 2021 16:06:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B0D261155 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSMJT-0001wt-B4 for qemu-devel@archiver.kernel.org; Fri, 02 Apr 2021 12:06:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSMGN-00006p-Ol; Fri, 02 Apr 2021 12:03:11 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:51816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSMGM-00029X-3w; Fri, 02 Apr 2021 12:03:11 -0400 Received: by mail-pj1-x1036.google.com with SMTP id s21so2900254pjq.1; Fri, 02 Apr 2021 09:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9+cB+4RWNjTMO5skPwNv/dthVhDglokW5cciULwl+L8=; b=QoLilbh4Za8qgoSVvLmMq7Pww9Vbp/1+ioFjUNR74TEwnbr3v/jiKHn5NN/tDQQuB6 fTWlIXmTgYpUwlr6jyoJ4G61nGh9/T2agOMvYdwhheGZQsBRE1RI43TxhqBnVhbFcZ4u GBJV5CLkVz+v2bxghrfTPAQzmQmPR8RhlsjRFcVIfX+Eec2lh9dLFTsquldJIAySdjrk PNx4AeyF+kvWZ97CfdliUky/5uOk1DESd7rfzdiJCyZwVNeDJlfEmuBZYx4zG5fR5vqG ASz5DrEExRyGd9YBHHTWV6/ZM4JAICmrLHxaY7ZAQRIBsKLmvrZ+qfFbQsaIKNv/wPRo +kGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9+cB+4RWNjTMO5skPwNv/dthVhDglokW5cciULwl+L8=; b=mGSafGp6X6FGLXTi0IWV80EXqXn/LCfqtcKPMftQAivLPa/l686klfJMrMlvsmCZaP jEWPIgQKdCDYbi+POUetcgGQPr74fDZBjFfQl3K9ytjndY0r3TzTrza6NjWobMw339SW JnrELPI8CsIYmh7w4ry2DeRS2UCWY9J5sHIkMHllHejK+UtKdmnmaEH3vqiA1xVXtRW1 NoiCOVhJ7dgz34Z7uO55EzMyg62izXqeUxG/PTNKtd6PCAZMQi98fDCpotCw1vzCgTIA GN+TniSenDibPHnyCrOhw35qqgdXaVGsBKMIhmKpr5CGhgsy8+rrrKIektLbFqxS3kbY rpJQ== X-Gm-Message-State: AOAM530XMZK28qIsG5mhC4IyKF0wpEhYTXeZATo36dcdsgCbyggVt4Ie kMA7PDnKSicu1Xw7KftOX+LCcP392JO9Qw== X-Google-Smtp-Source: ABdhPJztGuxtlcrHFZ4jN/n2FbFEkvX3UUSMZu0sH0sy0aMhKXdXbIqRkqzB4NASX5A4HnS40N7l5g== X-Received: by 2002:a17:90a:3b0e:: with SMTP id d14mr14596227pjc.198.1617379388366; Fri, 02 Apr 2021 09:03:08 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c360:8200:3c79:94d8:55ff:9601]) by smtp.gmail.com with ESMTPSA id w84sm8708723pfc.142.2021.04.02.09.03.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Apr 2021 09:03:08 -0700 (PDT) From: Akihiko Odaki To: Subject: [v5 2/3] block: Add backend_defaults property Date: Sat, 3 Apr 2021 01:02:55 +0900 Message-Id: <20210402160256.39647-2-akihiko.odaki@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210402160256.39647-1-akihiko.odaki@gmail.com> References: <20210402160256.39647-1-akihiko.odaki@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=akihiko.odaki@gmail.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , pkrempa@redhat.com, Akihiko Odaki , qemu-block@nongnu.org, Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , Konstantin Nazarov , Stefan Hajnoczi , John Snow , dgilbert@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" backend_defaults property allow users to control if default block properties should be decided with backend information. If it is off, any backend information will be discarded, which is suitable if you plan to perform live migration to a different disk backend. If it is on, a block device may utilize backend information more aggressively. By default, it is auto, which uses backend information for block sizes and ignores the others, which is consistent with the older versions. Signed-off-by: Akihiko Odaki --- hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++++---- include/hw/block/block.h | 3 +++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/hw/block/block.c b/hw/block/block.c index 1e34573da71..d47ebf005ad 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -65,24 +65,58 @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp) { BlockBackend *blk = conf->blk; BlockSizes blocksizes; - int backend_ret; + BlockDriverState *bs; + bool use_blocksizes; + bool use_bs; + + switch (conf->backend_defaults) { + case ON_OFF_AUTO_AUTO: + use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes); + use_bs = false; + break; + + case ON_OFF_AUTO_ON: + use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes); + bs = blk_bs(blk); + use_bs = bs; + break; + + case ON_OFF_AUTO_OFF: + use_blocksizes = false; + use_bs = false; + break; + + default: + abort(); + } - backend_ret = blk_probe_blocksizes(blk, &blocksizes); /* fill in detected values if they are not defined via qemu command line */ if (!conf->physical_block_size) { - if (!backend_ret) { + if (use_blocksizes) { conf->physical_block_size = blocksizes.phys; } else { conf->physical_block_size = BDRV_SECTOR_SIZE; } } if (!conf->logical_block_size) { - if (!backend_ret) { + if (use_blocksizes) { conf->logical_block_size = blocksizes.log; } else { conf->logical_block_size = BDRV_SECTOR_SIZE; } } + if (use_bs) { + if (!conf->opt_io_size) { + conf->opt_io_size = bs->bl.opt_transfer; + } + if (conf->discard_granularity == -1) { + if (bs->bl.pdiscard_alignment) { + conf->discard_granularity = bs->bl.pdiscard_alignment; + } else if (bs->bl.request_alignment != 1) { + conf->discard_granularity = bs->bl.request_alignment; + } + } + } if (conf->logical_block_size > conf->physical_block_size) { error_setg(errp, diff --git a/include/hw/block/block.h b/include/hw/block/block.h index c172cbe65f1..5902c0440a5 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -19,6 +19,7 @@ typedef struct BlockConf { BlockBackend *blk; + OnOffAuto backend_defaults; uint32_t physical_block_size; uint32_t logical_block_size; uint32_t min_io_size; @@ -48,6 +49,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) } #define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \ + DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \ + _conf.backend_defaults, ON_OFF_AUTO_AUTO), \ DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ _conf.logical_block_size), \ DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ -- 2.24.3 (Apple Git-128)