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.
19
#include <sys/types.h>
25
# define LVM_BLK_MAJOR 58
28
static int is_lvm_device(dev_t devno)
30
if (major(devno) == LVM_BLK_MAJOR)
32
return blkid_driver_has_major("lvm", major(devno));
35
static int probe_lvm_tp(blkid_probe pr, const struct blkid_idmag *mag)
37
const char *paths[] = {
38
"/usr/local/sbin/lvdisplay",
39
"/usr/sbin/lvdisplay",
42
int i, lvpipe[] = { -1, -1 }, stripes = 0, stripesize = 0;
44
char *cmd = NULL, *devname = NULL, buf[1024];
45
dev_t devno = blkid_probe_get_devno(pr);
48
goto nothing; /* probably not a block device */
49
if (!is_lvm_device(devno))
52
for (i = 0; i < ARRAY_SIZE(paths); i++) {
54
if (stat(paths[i], &sb) == 0) {
55
cmd = (char *) paths[i];
63
devname = blkid_devno_to_devname(devno);
67
if (pipe(lvpipe) < 0) {
69
printf("Failed to open pipe: errno=%d", errno));
81
if (lvpipe[1] != STDOUT_FILENO)
82
dup2(lvpipe[1], STDOUT_FILENO);
84
/* The libblkid library could linked with setuid programs */
85
if (setgid(getgid()) < 0)
87
if (setuid(getuid()) < 0)
94
execv(lvargv[0], lvargv);
97
printf("Failed to execute %s: errno=%d", cmd, errno));
102
printf("Failed to forking: errno=%d", errno));
108
stream = fdopen(lvpipe[0], "r");
112
while (fgets(buf, sizeof(buf), stream) != NULL) {
113
if (!strncmp(buf, "Stripes", 7))
114
sscanf(buf, "Stripes %d", &stripes);
116
if (!strncmp(buf, "Stripe size", 11))
117
sscanf(buf, "Stripe size (KByte) %d", &stripesize);
123
blkid_topology_set_minimum_io_size(pr, stripesize << 10);
124
blkid_topology_set_optimal_io_size(pr, (stripes * stripesize) << 10);
135
else if (lvpipe[0] != -1)
142
const struct blkid_idinfo lvm_tp_idinfo =
145
.probefunc = probe_lvm_tp,
146
.magics = BLKID_NONE_MAGIC