2
* Linux Software RAID (md) topology
3
* -- this is fallback for old systems where the topology information is not
6
* Copyright (C) 2009 Karel Zak <kzak@redhat.com>
8
* This file may be redistributed under the terms of the
9
* GNU Lesser General Public License.
18
#include <sys/ioctl.h>
20
#include <sys/types.h>
29
#ifndef _IOT__IOTBASE_uint32_t
30
#define _IOT__IOTBASE_uint32_t IOT_SIMPLE(uint32_t)
32
#define _IOT_md_array_info _IOT (_IOTS(uint32_t), 18, 0, 0, 0, 0)
33
#define GET_ARRAY_INFO _IOR (MD_MAJOR, 0x11, struct md_array_info)
35
struct md_array_info {
37
* Generic constant information
39
uint32_t major_version;
40
uint32_t minor_version;
41
uint32_t patch_version;
48
uint32_t not_persistent;
51
* Generic state information
53
uint32_t utime; /* 0 Superblock update time */
54
uint32_t state; /* 1 State bits (clean, ...) */
55
uint32_t active_disks; /* 2 Number of currently active disks */
56
uint32_t working_disks; /* 3 Number of working disks */
57
uint32_t failed_disks; /* 4 Number of failed disks */
58
uint32_t spare_disks; /* 5 Number of spare disks */
61
* Personality information
63
uint32_t layout; /* 0 the array's physical layout */
64
uint32_t chunk_size; /* 1 chunk size in bytes */
68
static int is_md_device(dev_t devno)
70
if (major(devno) == MD_MAJOR)
72
return blkid_driver_has_major("md", major(devno));
75
static int probe_md_tp(blkid_probe pr, const struct blkid_idmag *mag)
79
dev_t devno = blkid_probe_get_devno(pr);
80
struct md_array_info md;
83
goto nothing; /* probably not a block device */
85
if (!is_md_device(devno))
88
if (blkid_devno_to_wholedisk(devno, NULL, 0, &disk))
94
char *diskpath = blkid_devno_to_devname(disk);
99
fd = open(diskpath, O_RDONLY);
106
memset(&md, 0, sizeof(md));
108
if (ioctl(fd, GET_ARRAY_INFO, &md))
115
* Ignore levels we don't want aligned (e.g. linear)
116
* and deduct disk(s) from stripe width on RAID4/5/6
134
blkid_topology_set_minimum_io_size(pr, md.chunk_size);
135
blkid_topology_set_optimal_io_size(pr, md.chunk_size * md.raid_disks);
140
if (fd != -1 && fd != pr->fd)
145
const struct blkid_idinfo md_tp_idinfo =
148
.probefunc = probe_md_tp,
149
.magics = BLKID_NONE_MAGIC