1 From 834713b5aee1edc004f863231dd489ee3a79f536 Mon Sep 17 00:00:00 2001
2 From: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
3 Date: Thu, 17 Sep 2015 15:33:29 +0200
4 Subject: [PATCH 22/22] dasd: enhance device probing
6 Probe for all device/transport types as every block device
7 could be a DASD on s390.
9 Since the calculation of the minimum and optimum alignment
10 is different between DASDs and common fixed block disks
11 we need a means other than dev->type == PED_DEVICE_DASD.
12 For that purpose a static function _ped_device_like_dasd()
13 offering a DASD detection heuristic has been added to
16 By always providing arch-specific alignment functions the
17 need for DASD-specific code could be removed from device.c.
19 Observe fdasd_get_geometry return code for proper error
22 Remove the obsolete API check as we no longer require the
25 Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
26 Acked-by: Stefan Haberland <stefan.haberland@de.ibm.com>
27 Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
28 Signed-off-by: Brian C. Lane <bcl@redhat.com>
30 libparted/arch/linux.c | 85 ++++++++++++++++++++++++++++++++++++++++---------
31 libparted/device.c | 14 +++-----
32 libparted/labels/dasd.c | 18 +++++------
33 3 files changed, 82 insertions(+), 35 deletions(-)
35 diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
36 index adc368d..9344ceb 100644
37 --- a/libparted/arch/linux.c
38 +++ b/libparted/arch/linux.c
39 @@ -785,9 +785,13 @@ _device_set_sector_size (PedDevice* dev)
42 #if defined __s390__ || defined __s390x__
43 + /* The real_sector_size is currently needed for DASD layouts,
44 + * so we set it unconditionally. In the long run it should
45 + * be considered to use the dev->phys_sector_size in label/dasd.c.
47 + arch_specific->real_sector_size = dev->sector_size;
48 /* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */
49 if (dev->type == PED_DEVICE_DASD) {
50 - arch_specific->real_sector_size = dev->sector_size;
51 dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
54 @@ -3167,19 +3171,72 @@ linux_disk_commit (PedDisk* disk)
56 if (disk->dev->type != PED_DEVICE_FILE) {
58 - /* We now require BLKPG support. If this assertion fails,
59 - please write to the mailing list describing your system.
60 - Assuming it's never triggered, ...
61 - FIXME: remove this assertion in 2012. */
62 - assert (_have_blkpg ());
63 + /* We now require BLKPG support. If this assertion fails,
64 + please write to the mailing list describing your system.
65 + Assuming it's never triggered, ...
66 + FIXME: remove this assertion in 2012. */
67 + assert (_have_blkpg ());
69 - if (!_disk_sync_part_table (disk))
71 + if (!_disk_sync_part_table (disk))
78 +#if defined __s390__ || defined __s390x__
80 + * Check whether this device could be a DASD
82 + * The device probing yields PED_DEVICE_DASD for native DASD transport
83 + * If the block device uses a different transport (e.g. virtio)
84 + * a simplified heuristic (assuming a model 3390 with 4K sectors)
85 + * is applied (only) on s390x systems for this check.
87 + * \return 1 if the geometry indicates this could be a DASD
91 +_ped_device_like_dasd(const PedDevice *dev)
93 + return (dev->type == PED_DEVICE_DASD)
94 + || (dev->hw_geom.heads == 15
95 + && dev->hw_geom.sectors == 12
96 + && (dev->hw_geom.cylinders
97 + * dev->hw_geom.heads
98 + * dev->hw_geom.sectors
99 + * dev->phys_sector_size
100 + == dev->length * dev->sector_size));
105 +static PedAlignment*
106 +s390_get_minimum_alignment(const PedDevice *dev)
109 + return linux_get_minimum_alignment(dev);
111 + return ped_alignment_new(0,
112 + dev->phys_sector_size
113 + / dev->sector_size);
117 +static PedAlignment*
118 +s390_get_optimum_alignment(const PedDevice *dev)
120 + /* DASD needs to use minimum alignment */
121 + if (_ped_device_like_dasd(dev))
122 + return s390_get_minimum_alignment(dev);
124 + return linux_get_optimum_alignment(dev);
133 linux_get_minimum_alignment(const PedDevice *dev)
134 @@ -3220,15 +3277,10 @@ linux_get_optimum_alignment(const PedDevice *dev)
135 && PED_DEFAULT_ALIGNMENT % optimal_io == 0)
136 || (!optimal_io && minimum_io
137 && PED_DEFAULT_ALIGNMENT % minimum_io == 0)
139 - /* DASD needs to use minimum alignment */
140 - if (dev->type == PED_DEVICE_DASD)
141 - return linux_get_minimum_alignment(dev);
144 return ped_alignment_new(
145 blkid_topology_get_alignment_offset(tp) / dev->sector_size,
146 PED_DEFAULT_ALIGNMENT / dev->sector_size);
149 /* If optimal_io_size is 0 and we don't meet the other criteria
150 for using the device.c default, return the minimum alignment. */
151 @@ -3255,7 +3307,10 @@ static PedDeviceArchOps linux_dev_ops = {
153 sync_fast: linux_sync_fast,
154 probe_all: linux_probe_all,
156 +#if defined __s390__ || defined __s390x__
157 + get_minimum_alignment: s390_get_minimum_alignment,
158 + get_optimum_alignment: s390_get_optimum_alignment,
160 get_minimum_alignment: linux_get_minimum_alignment,
161 get_optimum_alignment: linux_get_optimum_alignment,
163 diff --git a/libparted/device.c b/libparted/device.c
164 index cdcc117..36fecd2 100644
165 --- a/libparted/device.c
166 +++ b/libparted/device.c
167 @@ -550,16 +550,10 @@ ped_device_get_optimum_alignment(const PedDevice *dev)
168 /* If the arch specific code could not give as an alignment
169 return a default value based on the type of device. */
171 - switch (dev->type) {
172 - case PED_DEVICE_DASD:
173 - align = ped_device_get_minimum_alignment(dev);
176 - /* Align to a grain of 1MiB (like vista / win7) */
177 - align = ped_alignment_new(0,
178 - (PED_DEFAULT_ALIGNMENT
179 - / dev->sector_size));
181 + /* Align to a grain of 1MiB (like vista / win7) */
182 + align = ped_alignment_new(0,
183 + (PED_DEFAULT_ALIGNMENT
184 + / dev->sector_size));
188 diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
189 index fa9414f..bb32d66 100644
190 --- a/libparted/labels/dasd.c
191 +++ b/libparted/labels/dasd.c
192 @@ -214,19 +214,13 @@ dasd_probe (const PedDevice *dev)
194 PED_ASSERT(dev != NULL);
196 - if (!(dev->type == PED_DEVICE_DASD
197 - || dev->type == PED_DEVICE_VIODASD
198 - || dev->type == PED_DEVICE_FILE))
201 arch_specific = LINUX_SPECIFIC(dev);
203 /* add partition test here */
204 fdasd_initialize_anchor(&anchor);
206 - fdasd_get_geometry(dev, &anchor, arch_specific->fd);
208 - fdasd_check_api_version(&anchor, arch_specific->fd);
209 + if (fdasd_get_geometry(dev, &anchor, arch_specific->fd) == 0)
210 + goto error_cleanup;
212 /* Labels are required on CDL formatted DASDs. */
213 if (fdasd_check_volume(&anchor, arch_specific->fd) &&
214 @@ -276,7 +270,9 @@ dasd_read (PedDisk* disk)
216 fdasd_initialize_anchor(&anchor);
218 - fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd);
219 + if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)
220 + goto error_close_dev;
222 disk_specific->label_block = anchor.label_block;
224 if ((anchor.geo.cylinders * anchor.geo.heads) > BIG_DISK_SIZE)
225 @@ -630,7 +626,9 @@ dasd_write (const PedDisk* disk)
227 /* initialize the anchor */
228 fdasd_initialize_anchor(&anchor);
229 - fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd);
230 + if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)
233 fdasd_check_volume(&anchor, arch_specific->fd);
234 memcpy(anchor.vlabel, &disk_specific->vlabel, sizeof(volume_label_t));
235 anchor.vlabel_changed++;