blob: 7a4fd554d45f31883ae1fc298e305d23d02d0a7f [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Evms topology
3 * -- this is fallback for old systems where the toplogy information is not
4 * exported by sysfs
5 *
6 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
7 *
8 * This file may be redistributed under the terms of the
9 * GNU Lesser General Public License.
10 *
11 */
12#include <errno.h>
13#include <fcntl.h>
14#include <stdint.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <sys/ioctl.h>
19#include <sys/stat.h>
20#include <sys/types.h>
21#include <unistd.h>
22
23#include "topology.h"
24
25#define EVMS_MAJOR 117
26
27#ifndef _IOT__IOTBASE_u_int32_t
28#define _IOT__IOTBASE_u_int32_t IOT_SIMPLE(uint32_t)
29#endif
30#define _IOT_evms_stripe_info _IOT (_IOTS(uint32_t), 2, 0, 0, 0, 0)
31#define EVMS_GET_STRIPE_INFO _IOR(EVMS_MAJOR, 0xF0, struct evms_stripe_info)
32
33struct evms_stripe_info {
34 uint32_t size; /* stripe unit 512-byte blocks */
35 uint32_t width; /* the number of stripe members or RAID data disks */
36} evms_stripe_info;
37
38static int is_evms_device(dev_t devno)
39{
40 if (major(devno) == EVMS_MAJOR)
41 return 1;
42 return blkid_driver_has_major("evms", major(devno));
43}
44
45static int probe_evms_tp(blkid_probe pr,
46 const struct blkid_idmag *mag __attribute__((__unused__)))
47{
48 struct evms_stripe_info evms;
49 dev_t devno = blkid_probe_get_devno(pr);
50
51 if (!devno)
52 goto nothing; /* probably not a block device */
53
54 if (!is_evms_device(devno))
55 goto nothing;
56
57 memset(&evms, 0, sizeof(evms));
58
59 if (ioctl(pr->fd, EVMS_GET_STRIPE_INFO, &evms))
60 goto nothing;
61
62 blkid_topology_set_minimum_io_size(pr, evms.size << 9);
63 blkid_topology_set_optimal_io_size(pr, (evms.size * evms.width) << 9);
64
65 return 0;
66
67nothing:
68 return 1;
69}
70
71const struct blkid_idinfo evms_tp_idinfo =
72{
73 .name = "evms",
74 .probefunc = probe_evms_tp,
75 .magics = BLKID_NONE_MAGIC
76};
77