blob: 1fce25abe2fbca5c19a5744cd42b49c440de0a28 [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>
Ethan Yonkerfefe5912017-09-30 22:22:13 -050020#include <sys/sysmacros.h>
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050021#include <sys/types.h>
22#include <unistd.h>
23
24#include "topology.h"
25
26#define EVMS_MAJOR 117
27
28#ifndef _IOT__IOTBASE_u_int32_t
29#define _IOT__IOTBASE_u_int32_t IOT_SIMPLE(uint32_t)
30#endif
31#define _IOT_evms_stripe_info _IOT (_IOTS(uint32_t), 2, 0, 0, 0, 0)
32#define EVMS_GET_STRIPE_INFO _IOR(EVMS_MAJOR, 0xF0, struct evms_stripe_info)
33
34struct evms_stripe_info {
35 uint32_t size; /* stripe unit 512-byte blocks */
36 uint32_t width; /* the number of stripe members or RAID data disks */
37} evms_stripe_info;
38
39static int is_evms_device(dev_t devno)
40{
41 if (major(devno) == EVMS_MAJOR)
42 return 1;
43 return blkid_driver_has_major("evms", major(devno));
44}
45
46static int probe_evms_tp(blkid_probe pr,
47 const struct blkid_idmag *mag __attribute__((__unused__)))
48{
49 struct evms_stripe_info evms;
50 dev_t devno = blkid_probe_get_devno(pr);
51
52 if (!devno)
53 goto nothing; /* probably not a block device */
54
55 if (!is_evms_device(devno))
56 goto nothing;
57
58 memset(&evms, 0, sizeof(evms));
59
60 if (ioctl(pr->fd, EVMS_GET_STRIPE_INFO, &evms))
61 goto nothing;
62
63 blkid_topology_set_minimum_io_size(pr, evms.size << 9);
64 blkid_topology_set_optimal_io_size(pr, (evms.size * evms.width) << 9);
65
66 return 0;
67
68nothing:
69 return 1;
70}
71
72const struct blkid_idinfo evms_tp_idinfo =
73{
74 .name = "evms",
75 .probefunc = probe_evms_tp,
76 .magics = BLKID_NONE_MAGIC
77};
78