From patchwork Tue Dec 13 12:37:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 131082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 83BA31007D3 for ; Wed, 14 Dec 2011 00:27:58 +1100 (EST) Received: from localhost ([::1]:32944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRcs-000640-89 for incoming@patchwork.ozlabs.org; Tue, 13 Dec 2011 07:38:30 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRcP-00058z-Vy for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaRcO-0004LJ-14 for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:01 -0500 Received: from mail-yx0-f173.google.com ([209.85.213.173]:36775) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRcN-0004GM-O6 for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:37:59 -0500 Received: by mail-yx0-f173.google.com with SMTP id m6so6316748yen.4 for ; Tue, 13 Dec 2011 04:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=LbKjRpFDPyH1j9sChJIAex9zB6McmyuzWLQUmC2JBXg=; b=BrtFqRRumoExxbXdlC/Wt7hJHCZNDxgmXxMJFffoTNqen5q3cQ7wLhct52e1QVealg dAiCeKYYZ1nlfm/Ahsx8UWv5/esGS5tWX0pde+7bIDRoNQiYPAQzQmdQ4l2cZyiRWHui rZV98m1H7NflvxzmNCyTfGPtDTRbIFRmxVECE= Received: by 10.236.190.130 with SMTP id e2mr3070438yhn.107.1323779879429; Tue, 13 Dec 2011 04:37:59 -0800 (PST) Received: from localhost.localdomain (93-34-178-147.ip50.fastwebnet.it. [93.34.178.147]) by mx.google.com with ESMTPS id i50sm35972917yhk.11.2011.12.13.04.37.57 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 13 Dec 2011 04:37:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 13 Dec 2011 13:37:19 +0100 Message-Id: <1323779840-4235-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1323779840-4235-1-git-send-email-pbonzini@redhat.com> References: <1323779840-4235-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.173 Subject: [Qemu-devel] [PATCH 16/17] block: default physical block size to host block size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hopefully, this will help operating systems and they will make less misaligned I/O operations. Or on Linux, at least fdisk will tell the user that they should try and align partitions. Signed-off-by: Paolo Bonzini --- block.c | 17 +++++++++++++++++ block.h | 15 ++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 44f5d83..1bfadaf 100644 --- a/block.c +++ b/block.c @@ -4041,3 +4041,20 @@ out: return ret; } + +unsigned int get_physical_block_exp(BlockConf *conf) +{ + unsigned int exp = 0, size; + + if (conf->bs && !conf->physical_block_size) { + size = conf->bs->host_block_size; + } else { + size = conf->physical_block_size; + } + + for (; size > conf->logical_block_size; size >>= 1) { + exp++; + } + + return exp; +} diff --git a/block.h b/block.h index e088146..67594d4 100644 --- a/block.h +++ b/block.h @@ -401,25 +401,14 @@ typedef struct BlockConf { uint32_t discard_granularity; } BlockConf; -static inline unsigned int get_physical_block_exp(BlockConf *conf) -{ - unsigned int exp = 0, size; - - for (size = conf->physical_block_size; - size > conf->logical_block_size; - size >>= 1) { - exp++; - } - - return exp; -} +unsigned int get_physical_block_exp(BlockConf *conf); #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \ DEFINE_PROP_UINT16("logical_block_size", _state, \ _conf.logical_block_size, 512), \ DEFINE_PROP_UINT16("physical_block_size", _state, \ - _conf.physical_block_size, 512), \ + _conf.physical_block_size, 0), \ DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \