From patchwork Wed Nov 19 10:17:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ekaterina Tumanova X-Patchwork-Id: 412322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1C1E514012B for ; Wed, 19 Nov 2014 21:22:04 +1100 (AEDT) Received: from localhost ([::1]:57383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr2Of-000307-S3 for incoming@patchwork.ozlabs.org; Wed, 19 Nov 2014 05:22:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr2LW-0006ZX-4m for qemu-devel@nongnu.org; Wed, 19 Nov 2014 05:18:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xr2LM-00041C-10 for qemu-devel@nongnu.org; Wed, 19 Nov 2014 05:18:46 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:42614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr2LL-00040x-PI for qemu-devel@nongnu.org; Wed, 19 Nov 2014 05:18:35 -0500 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Nov 2014 10:18:34 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 19 Nov 2014 10:18:32 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 1AB1F2190045 for ; Wed, 19 Nov 2014 10:18:05 +0000 (GMT) Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sAJAIVUO17498556 for ; Wed, 19 Nov 2014 10:18:31 GMT Received: from d06av08.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sAJAIVQt031753 for ; Wed, 19 Nov 2014 03:18:31 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sAJAIHB6030750; Wed, 19 Nov 2014 03:18:31 -0700 From: Ekaterina Tumanova To: Public KVM Mailing List Date: Wed, 19 Nov 2014 11:17:53 +0100 Message-Id: <1416392276-10408-4-git-send-email-tumanova@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1416392276-10408-1-git-send-email-tumanova@linux.vnet.ibm.com> References: <1416392276-10408-1-git-send-email-tumanova@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14111910-0021-0000-0000-000001D5A1B9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.111 Cc: kwolf@redhat.com, dahi@linux.vnet.ibm.com, Ekaterina Tumanova , armbru@redhat.com, mihajlov@linux.vnet.ibm.com, borntraeger@de.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 3/6] geometry: Add driver methods to probe blocksizes and geometry 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 This patch introduces driver methods of defining disk blocksizes (physical and logical) and hard drive geometry. The method is only implemented for "host_device". For "raw" devices driver calls child's method. The detection will only work for DASD devices. In order to check that a local CheckForDASD function was introduced, which calls BIODASDINFO2 ioctl and returns 0 only if it succeeds. Signed-off-by: Ekaterina Tumanova --- block/raw-posix.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block/raw_bsd.c | 12 ++++++++++ 2 files changed, 77 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index 45f1d79..274ceda 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -56,6 +56,7 @@ #include #include #include +#include #ifndef FS_NOCOW_FL #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ #endif @@ -93,6 +94,10 @@ #include #endif +#ifdef __s390__ +#include +#endif + //#define DEBUG_FLOPPY //#define DEBUG_BLOCK @@ -678,6 +683,64 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.opt_mem_alignment = s->buf_align; } +static int CheckForDASD(int fd) +{ +#ifdef BIODASDINFO2 + struct dasd_information2_t info = {0}; + + return ioctl(fd, BIODASDINFO2, &info); +#endif + return -1; +} + +static struct ProbeBlockSize hdev_probe_blocksizes(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + struct ProbeBlockSize block_sizes = {0}; + + block_sizes.rc = CheckForDASD(s->fd); + /* If DASD, get blocksizes */ + if (block_sizes.rc == 0) { + block_sizes.size.log = probe_logical_blocksize(bs, s->fd); + block_sizes.size.phys = probe_physical_blocksize(bs, s->fd); + } + + return block_sizes; +} + +static struct ProbeGeometry hdev_probe_geometry(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + struct ProbeGeometry geometry = {0}; + struct hd_geometry ioctl_geo = {0}; + + geometry.rc = CheckForDASD(s->fd); + if (geometry.rc != 0) { + goto done; + } + /* If DASD, get it's geometry */ + geometry.rc = ioctl(s->fd, HDIO_GETGEO, &ioctl_geo); + /* Do not return a geometry for partition */ + if (ioctl_geo.start != 0) { + geometry.rc = -1; + goto done; + } + /* HDIO_GETGEO may return success even though geo contains zeros + (e.g. certain multipath setups) */ + if (!ioctl_geo.heads || !ioctl_geo.sectors || !ioctl_geo.cylinders) { + geometry.rc = -1; + goto done; + } + if (geometry.rc == 0) { + geometry.geo.heads = (uint32_t)ioctl_geo.heads; + geometry.geo.sectors = (uint32_t)ioctl_geo.sectors; + geometry.geo.cylinders = (uint32_t)ioctl_geo.cylinders; + geometry.geo.start = (uint32_t)ioctl_geo.start; + } +done: + return geometry; +} + static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) { int ret; @@ -2128,6 +2191,8 @@ static BlockDriver bdrv_host_device = { .bdrv_get_info = raw_get_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, .bdrv_detach_aio_context = raw_detach_aio_context, .bdrv_attach_aio_context = raw_attach_aio_context, diff --git a/block/raw_bsd.c b/block/raw_bsd.c index 401b967..d164eba 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -173,6 +173,16 @@ static int raw_probe(const uint8_t *buf, int buf_size, const char *filename) return 1; } +static struct ProbeBlockSize raw_probe_blocksizes(BlockDriverState *bs) +{ + return bdrv_probe_blocksizes(bs->file); +} + +static struct ProbeGeometry raw_probe_geometry(BlockDriverState *bs) +{ + return bdrv_probe_geometry(bs->file); +} + static BlockDriver bdrv_raw = { .format_name = "raw", .bdrv_probe = &raw_probe, @@ -190,6 +200,8 @@ static BlockDriver bdrv_raw = { .has_variable_length = true, .bdrv_get_info = &raw_get_info, .bdrv_refresh_limits = &raw_refresh_limits, + .bdrv_probe_blocksizes = &raw_probe_blocksizes, + .bdrv_probe_geometry = &raw_probe_geometry, .bdrv_is_inserted = &raw_is_inserted, .bdrv_media_changed = &raw_media_changed, .bdrv_eject = &raw_eject,