mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o Ok, this seems to be a much better method for caching valid
devices based on /proc/devices + The dev_mgr structure now has a 256 element char array that is initially all 0s + When a match is found, the array element corresponding to the major number of the match is set to a non-zero value + to check for a match, all one has to do is check that the array element at the major number in question is non-zero. o I'm wondering if we should do this with bitwise operators instead? Does anyone expect the major numbers to grow larger than 8-bits?
This commit is contained in:
parent
83b2c0d30a
commit
a53d451f30
@ -49,6 +49,7 @@
|
|||||||
#define LOCAL_EPARAM 1
|
#define LOCAL_EPARAM 1
|
||||||
#define LOCAL_CHECK_NAME 2
|
#define LOCAL_CHECK_NAME 2
|
||||||
#define LOCAL_DEVICE_TYPE_INVALID 3
|
#define LOCAL_DEVICE_TYPE_INVALID 3
|
||||||
|
#define NUMBER_OF_MAJORS 256
|
||||||
|
|
||||||
static const char *device_names[] = {
|
static const char *device_names[] = {
|
||||||
"ide", /* IDE disk */
|
"ide", /* IDE disk */
|
||||||
@ -73,20 +74,13 @@ struct dev_i {
|
|||||||
struct dev_i *next;
|
struct dev_i *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* temporary structure - will replace with something smarter later */
|
|
||||||
struct dev_n {
|
|
||||||
int major;
|
|
||||||
struct dev_n *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dev_mgr {
|
struct dev_mgr {
|
||||||
/* everything is allocated from this pool */
|
/* everything is allocated from this pool */
|
||||||
struct pool *pool;
|
struct pool *pool;
|
||||||
|
|
||||||
int has_scanned;
|
int has_scanned;
|
||||||
|
|
||||||
/* linked list of valid major numbers */
|
char valid_majors[NUMBER_OF_MAJORS];
|
||||||
struct dev_n *dev_list;
|
|
||||||
|
|
||||||
/* hash table */
|
/* hash table */
|
||||||
int num_slots;
|
int num_slots;
|
||||||
@ -273,7 +267,6 @@ static struct dev_i *_add_named_device(struct dev_mgr *dm, const char *devpath)
|
|||||||
struct dev_i *dev = NULL;
|
struct dev_i *dev = NULL;
|
||||||
struct stat stat_b;
|
struct stat stat_b;
|
||||||
|
|
||||||
/* FIXME: move lvm_check_dev into this file */
|
|
||||||
if ((stat(devpath, &stat_b) == -1) || _check_dev(dm, &stat_b))
|
if ((stat(devpath, &stat_b) == -1) || _check_dev(dm, &stat_b))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@ -448,25 +441,25 @@ static int _check_dev(struct dev_mgr *dm, struct stat *stat_b)
|
|||||||
else if ( ! S_ISBLK(stat_b->st_mode))
|
else if ( ! S_ISBLK(stat_b->st_mode))
|
||||||
ret = -LOCAL_CHECK_NAME;
|
ret = -LOCAL_CHECK_NAME;
|
||||||
else {
|
else {
|
||||||
for(node = dm->dev_list; node != NULL; node = node->next)
|
if (dm->valid_majors[seek_major])
|
||||||
if (node->major == seek_major)
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Caches /proc/device info and
|
/* Caches /proc/device info and returns the number of block devices found
|
||||||
returns the number of block devices found in /proc/devices */
|
in /proc/devices */
|
||||||
static int _scan_proc_dev(struct dev_mgr *dm)
|
static int _scan_proc_dev(struct dev_mgr *dm)
|
||||||
{
|
{
|
||||||
char line[80];
|
char line[80];
|
||||||
FILE *procdevices = NULL;
|
FILE *procdevices = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int i, j = 0;
|
int i, j = 0;
|
||||||
int line_major = 0;
|
int line_maj = 0;
|
||||||
int blocksection = 0;
|
int blocksection = 0;
|
||||||
struct dev_n * dev_node= NULL;
|
struct dev_n * dev_node= NULL;
|
||||||
|
int dev_len = 0;
|
||||||
|
|
||||||
if ((procdevices = fopen("/proc/devices", "r")) != NULL) {
|
if ((procdevices = fopen("/proc/devices", "r")) != NULL) {
|
||||||
while (fgets(line, 80, procdevices) != NULL) {
|
while (fgets(line, 80, procdevices) != NULL) {
|
||||||
@ -475,8 +468,8 @@ static int _scan_proc_dev(struct dev_mgr *dm)
|
|||||||
i++;
|
i++;
|
||||||
|
|
||||||
/* If its not a number it may be name of section */
|
/* If its not a number it may be name of section */
|
||||||
line_major = atoi(((char *) (line + i)));
|
line_maj = atoi(((char *) (line + i)));
|
||||||
if (line_major == 0) {
|
if (line_maj == 0) {
|
||||||
blocksection = (line[i] == 'B') ? 1 : 0;
|
blocksection = (line[i] == 'B') ? 1 : 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -490,17 +483,18 @@ static int _scan_proc_dev(struct dev_mgr *dm)
|
|||||||
while (line[i] == ' ' && line[i] != '\0')
|
while (line[i] == ' ' && line[i] != '\0')
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
|
/* Go through the valid device names and if there is a
|
||||||
|
match, set the array member corresponding to the
|
||||||
|
major number to !0 */
|
||||||
for (j = 0; device_names[j] != NULL; j++) {
|
for (j = 0; device_names[j] != NULL; j++) {
|
||||||
if (strlen(device_names[j])
|
|
||||||
<= strlen(line + i)) {
|
dev_len = strlen(device_names[j]);
|
||||||
|
if (dev_len <= strlen(line + i)) {
|
||||||
if (strncmp (device_names[j],
|
if (strncmp (device_names[j],
|
||||||
line + i,
|
line + i,
|
||||||
strlen(device_names[j])) == 0) {
|
dev_len) == 0) {
|
||||||
dev_node = pool_alloc(dm->pool,
|
|
||||||
sizeof(*dev_node));
|
dm->valid_majors[line_maj]='1';
|
||||||
dev_node->major = line_major;
|
|
||||||
dev_node->next=dm->dev_list;
|
|
||||||
dm->dev_list = dev_node;
|
|
||||||
ret++;
|
ret++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user