From patchwork Sun Feb 1 03:00:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 4952 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n1131nGY019132 for ; Sun, 1 Feb 2009 03:01:49 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 31B238E0F90; Sat, 31 Jan 2009 22:01:49 -0500 (EST) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id n1131lZ0004983 for ; Sat, 31 Jan 2009 22:01:47 -0500 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n1131ndq006386; Sat, 31 Jan 2009 22:01:49 -0500 Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n1130t9V030563; Sat, 31 Jan 2009 22:00:55 -0500 Received: from htj.dyndns.org (IDENT:U2FsdGVkX19nGTf+zRF3GI0yp0USFoK86ma5PlYo9x0@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n1130ffD029570 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 1 Feb 2009 03:00:44 GMT Received: from [127.0.0.2] (htj.dyndns.org [127.0.0.2]) by htj.dyndns.org (Postfix) with ESMTPSA id BE3354094A7B7; Sun, 1 Feb 2009 12:00:36 +0900 (KST) Message-ID: <49851054.10605@kernel.org> Date: Sun, 01 Feb 2009 12:00:36 +0900 From: Tejun Heo User-Agent: Thunderbird 2.0.0.19 (X11/20081227) MIME-Version: 1.0 To: jeff@garzik.org, linux-ide@vger.kernel.org, jens.axboe@oracle.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, James.Bottomley@HansenPartnership.com, Mauelshagen@redhat.com, dm-devel@redhat.com References: <1233456951-992-1-git-send-email-tj@kernel.org> <49851012.8070904@kernel.org> In-Reply-To: <49851012.8070904@kernel.org> X-Enigmail-Version: 0.95.7 X-Virus-Scanned: ClamAV 0.93.3/8932/Sat Jan 31 23:12:16 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Sun, 01 Feb 2009 03:00:46 +0000 (UTC) X-RedHat-Spam-Score: -3.989 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-Scanned-By: MIMEDefang 2.63 on 172.16.48.31 X-loop: dm-devel@redhat.com Cc: Subject: [dm-devel] [PATCH 2/3] dmraid: add alt_size to dev_info X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Add alt_size to dev_info and set it during device scanning if available. Signed-off-by: Tejun Heo --- include/dmraid/metadata.h | 1 + lib/device/scan.c | 51 ++++++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/include/dmraid/metadata.h b/include/dmraid/metadata.h index 91bd221..538043e 100644 --- a/include/dmraid/metadata.h +++ b/include/dmraid/metadata.h @@ -120,6 +120,7 @@ struct dev_info { char *path; /* Actual device node path. */ char *serial; /* ATA/SCSI serial number. */ uint64_t sectors; /* Device size. */ + uint64_t alt_sectors; /* Alternative device size. (BIOS size) */ }; /* Metadata areas and size stored on a RAID device. */ diff --git a/lib/device/scan.c b/lib/device/scan.c index e9618c2..3befb08 100644 --- a/lib/device/scan.c +++ b/lib/device/scan.c @@ -233,29 +233,52 @@ sysfs_get_size(struct lib_context *lc, struct dev_info *di, { int ret = 0; char buf[22], *sysfs_file; - const char *sysfs_size = "size"; + const char *sysfs_size = "size", *sysfs_alt_size = "alt_size"; FILE *f; if (!(sysfs_file = dbg_malloc(strlen(path) + strlen(name) + - strlen(sysfs_size) + 3))) + max(strlen(sysfs_size), + strlen(sysfs_alt_size)) + 3))) return log_alloc_err(lc, __func__); + /* read size */ sprintf(sysfs_file, "%s/%s/%s", path, name, sysfs_size); - if ((f = fopen(sysfs_file, "r"))) { - /* Use fread+sscanf for klibc compatibility. */ - if (fread(buf, sizeof(char), sizeof buf - 1, f) && - (ret = sscanf(buf, "%" PRIu64, &di->sectors)) != 1) { - ret = 0; - log_err(lc, "reading disk size for %s from sysfs", - di->path); - } - - fclose(f); - } else + if (!(f = fopen(sysfs_file, "r"))) { log_err(lc, "opening %s", sysfs_file); + goto out; + } - dbg_free(sysfs_file); + /* Use fread+sscanf for klibc compatibility. */ + if (!fread(buf, sizeof(char), sizeof buf - 1, f) || + sscanf(buf, "%" PRIu64, &di->sectors) != 1) { + log_err(lc, "reading disk size for %s from sysfs", + di->path); + goto out; + } + fclose(f); + + /* read alt_size, missing alt_size isn't an error */ + sprintf(sysfs_file, "%s/%s/%s", path, name, sysfs_alt_size); + if (!(f = fopen(sysfs_file, "r"))) { + if (errno == ENOENT) + ret = 1; + else + log_err(lc, "opening %s", sysfs_file); + goto out; + } + + if (!fread(buf, sizeof(char), sizeof buf - 1, f) || + sscanf(buf, "%" PRIu64, &di->alt_sectors) != 1) { + log_err(lc, "reading disk alt size for %s from sysfs", + di->path); + goto out; + } + ret = 1; +out: + if (f) + fclose(f); + dbg_free(sysfs_file); return ret; }