Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4340991yba; Mon, 29 Apr 2019 18:33:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJjdtO2LYaI3AnPkfY58WVSN4cNgeyp5BpmmKE6w0KqOwUO5Z6wzz4dyvQXB2roEqpJknf X-Received: by 2002:a17:902:d83:: with SMTP id 3mr68532237plv.125.1556588022943; Mon, 29 Apr 2019 18:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556588022; cv=none; d=google.com; s=arc-20160816; b=APBP02CHqvdS+YMip5R+HZwU1+r+gK1stp3LEhA4AwFRn9h/ErHOwONBnG0UM4AzZj nd7LC2wT9QvWohZiz+j5VWQwqV0+eoxP/mBltmhZBDojxZ4AeoCcK+tIRD7NhXdxhs75 qZkWVW2xKQ1WovkpSxGYNUCk1eEXLVXPb+58/ob0iDcDtMsPSYKNMYD4obEGnDdnDdeO bWNyme7AKkZn5lYWPobEYhuDRvOknkAhc8iwyYfJWo/EPTGVWi4j+z9K4VAERPYijBca Q1QgQEfGzWTOuxuIJavVTLsusVPbz2svdQ335fs/b3qyRQZ7ymg1lkxq+Fr55ebU3phJ NSfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=3lBPGifk0g/Ym5DzrymiWRCw58/24lXuhpA4w8u758o=; b=CychahaD2FbAiXVbFeNz+Nyp3M9JnCnv6JeZoF7Sd3ZuYf8zbkjduRVYIq5eKhy7mC FUXWTONNHIuYDnJEjiH5a213n1z+eXCiO8Vpu4CYU0sxoBQCK2yv1IlQ96gAJifWvz8W pllBAOB+ThtTfFMPxfZwe59F3eMJJn3/pCyFJ4oIHdk9qqOqYxPMJ4fUaS8xkSSmOk3u 5eDRHzRBnkqfHL0xWbVnAbvRJR7Nh03f3PPN6n6yQGq+5ORpeHSNDigLw5gGdZwWe2L6 zx4VvUKai8/eV1ZWc9MlJaAfswCwkCJD6ZODDwU+7Hj2nac57SgWJMHqSXVGeUgl0nUH HJVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VVDBEcYK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si36595535plk.421.2019.04.29.18.33.27; Mon, 29 Apr 2019 18:33:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VVDBEcYK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729850AbfD3Bcc (ORCPT + 99 others); Mon, 29 Apr 2019 21:32:32 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:44895 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729238AbfD3Bcb (ORCPT ); Mon, 29 Apr 2019 21:32:31 -0400 Received: by mail-qt1-f195.google.com with SMTP id s10so14340628qtc.11; Mon, 29 Apr 2019 18:32:31 -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; bh=3lBPGifk0g/Ym5DzrymiWRCw58/24lXuhpA4w8u758o=; b=VVDBEcYKiveCHRGrj0VI42vziUd60oDkEsa//wmOyIo1CiYGSHRg7tQj6hQDIa167l BjmnulNGrqMlsJqJ9NMDDv4fokOAspNSHzqakJsLuiuEv/M4C0vKexL/rV59HXjsDZGC V9CA/IcVDM/p6Vrx5fBXlc8opKZfV66X+YRfCebj/OJJZhT44PHJ0u8AuhKlgM9+pxN5 lbinGxS5tgeYtym9I3bYG46IsPvSXrFnR7hUTRvTMWOjaB0Tt2zFqplLEewiuyoQ0eMf aNUwi5gH7twMVJ2XQrUebwxMQAu4WTLakuucRXhUFwygIhGh6U51gI3l073tq4+Da1XZ wyIg== 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; bh=3lBPGifk0g/Ym5DzrymiWRCw58/24lXuhpA4w8u758o=; b=Qzd3TatspWE+7wXX6Yq71Fd+vDb6s1jO6UcV2Hi6oFxRkVi6UlPBJmcTKk7HtF7v1u KVNgEXcY160ab4KIj3I4hTf8BKNq9vH/tnjLZY0YPpsXBqXGBsCsQvMZsUQwN/fnB0sw wZM1bhT3Mew1JlhNCZfVcZyMjGl8RPlSTWEmwc79KvCsISh/VXVA7ggPWUfY+aN+lZOw 5gcV6k30n+3ubpVaHnZ984k2rim5L4E0K4hB9pkW079sYsgCx+kWMKkvZlqZfaHWz6dq Bixv/qrM+s0ip5ONezZAKh/xUGvkdhcWUPTHFMK/QePda2FQIHV+vXJznI1OlWFn3adk 994g== X-Gm-Message-State: APjAAAWmEpJOjOaBDLFRBGltL2bCdbXkE9OCnholUgJdw7Ibd5FJVll9 SpOqwNfrq2lYFTVtAn1VSfSbABeo X-Received: by 2002:aed:35fa:: with SMTP id d55mr27349020qte.169.1556587950213; Mon, 29 Apr 2019 18:32:30 -0700 (PDT) Received: from laptop.suse.cz ([179.185.223.166]) by smtp.gmail.com with ESMTPSA id v57sm5127019qtc.10.2019.04.29.18.32.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 18:32:29 -0700 (PDT) From: Marcos Paulo de Souza To: linux-block@vger.kernel.org Cc: Marcos Paulo de Souza , Jens Axboe , Hannes Reinecke , Omar Sandoval , Ming Lei , Damien Le Moal , Bart Van Assche , Greg Edwards , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/2] blkdev.h: Introduce size_to_sectors hlper function Date: Mon, 29 Apr 2019 22:32:04 -0300 Message-Id: <20190430013205.1561708-2-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190430013205.1561708-1-marcos.souza.org@gmail.com> References: <20190430013205.1561708-1-marcos.souza.org@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function takes an argument to specify the size of a block device, in bytes, and return the number of sectors of 512 bytes. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Marcos Paulo de Souza --- Changes from v1: Reworked the documentation of size_to_sectors by removing a sentence that was explaining the size -> sectors math, which wasn't necessary given the description prior to the example. (suggested by Chaitanya) include/linux/blkdev.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 317ab30d2904..f6cfe6970756 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -871,6 +871,23 @@ static inline struct request_queue *bdev_get_queue(struct block_device *bdev) #define SECTOR_SIZE (1 << SECTOR_SHIFT) #endif +/** + * size_to_sectors - Convert size in bytes to number of sectors of 512 bytes + * @size: size in bytes to be converted to sectors + * + * Description: + * Kernel I/O operations are always made in "sectors". In order to set the + * correct number of sectors for a given number of bytes, we need to group the + * number of bytes in "sectors of 512 bytes" by shifting the size value by 9, + * which is the same than dividing the size by 512. + * + * Returns the number of sectors by the given number of bytes. + */ +static inline sector_t size_to_sectors(long long size) +{ + return size >> SECTOR_SHIFT; +} + /* * blk_rq_pos() : the current sector * blk_rq_bytes() : bytes left in the entire request -- 2.16.4