summaryrefslogtreecommitdiffstats
path: root/lib/filters/filter.c
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2012-03-20 10:47:02 +0000
committerZdenek Kabelac <zkabelac@redhat.com>2012-03-20 10:47:02 +0000
commit37672e676da49e29a2d98bae52ec543a81d9d3d9 (patch)
tree8a1c0cea5f5d6ded82731fea36232f272d92410e /lib/filters/filter.c
parent761407217a579ba3e0801f158929abf45e3e74a8 (diff)
downloadlvm2-37672e676da49e29a2d98bae52ec543a81d9d3d9.tar.gz
lvm2-37672e676da49e29a2d98bae52ec543a81d9d3d9.tar.xz
lvm2-37672e676da49e29a2d98bae52ec543a81d9d3d9.zip
Support improperly formated device numbers
There are kernel drivers (smblk) which set '-1' as their device major number. This number is listed in /proc/devices then - but the kernel itself is using just 12 bits - thus device is accessible via 4095 - there is posted patch for 3.4 to fix this behavior (0 for auto allocation was mean to be used). However to still allow using such devices with older kernels add some code to use same behavior - so cut 12 bits from the major number from /proc/devices. For now use log_warn() - maybe the severity of the message could be lowered to just verbose level.
Diffstat (limited to 'lib/filters/filter.c')
-rw-r--r--lib/filters/filter.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/filters/filter.c b/lib/filters/filter.c
index aa1e89c3..11b94c15 100644
--- a/lib/filters/filter.c
+++ b/lib/filters/filter.c
@@ -196,7 +196,7 @@ static int _scan_proc_dev(const char *proc, const struct dm_config_node *cn)
size_t dev_len = 0;
const struct dm_config_value *cv;
const char *name;
-
+ char *nl;
if (!*proc) {
log_verbose("No proc filesystem found: using all block device "
@@ -227,7 +227,20 @@ static int _scan_proc_dev(const char *proc, const struct dm_config_node *cn)
/* If it's not a number it may be name of section */
line_maj = atoi(((char *) (line + i)));
- if ((line_maj <= 0) || (line_maj >= NUMBER_OF_MAJORS)) {
+
+ if (line_maj < 0 || line_maj >= NUMBER_OF_MAJORS) {
+ /*
+ * Device numbers shown in /proc/devices are actually direct
+ * numbers passed to registering function, however the kernel
+ * uses only 12 bits, so use just 12 bits for major.
+ */
+ if ((nl = strchr(line, '\n'))) *nl = '\0';
+ log_warn("WARNING: /proc/devices line: %s, replacing major with %d.",
+ line, line_maj & (NUMBER_OF_MAJORS - 1));
+ line_maj &= (NUMBER_OF_MAJORS - 1);
+ }
+
+ if (!line_maj) {
blocksection = (line[i] == 'B') ? 1 : 0;
continue;
}