1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

filter-partitioned: use new 'udev' device status source to get partition status

Partitioned devices are marked in udev db as:
  ID_PART_TABLE="<partition table type name>"
and at the same time they are *not* marked with:
  ID_PART_ENTRY_DISK="<parent disk major:minor>"

Where partition table type name is dos/gpt/... But checking the presence
of this variable is enough for LVM here - it just needs to know whether
there's a partition table or not, not interested in the actual type.
The same applies for parent disk major:minor.
This commit is contained in:
Peter Rajnoha 2014-09-03 15:49:36 +02:00
parent 2fc126b00d
commit 787f6ce04a
2 changed files with 64 additions and 16 deletions

View File

@ -25,6 +25,10 @@
#include <blkid.h> #include <blkid.h>
#endif #endif
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
#endif
#include "device-types.h" #include "device-types.h"
struct dev_types *create_dev_types(const char *proc_dir, struct dev_types *create_dev_types(const char *proc_dir,
@ -324,8 +328,34 @@ static int _has_partition_table(struct device *dev)
return ret; return ret;
} }
int dev_is_partitioned(struct dev_types *dt, struct device *dev) #ifdef UDEV_SYNC_SUPPORT
static int _udev_dev_is_partitioned(struct device *dev)
{ {
const char *value;
struct dev_ext *ext;
if (!(ext = dev_ext_get(dev)))
return_0;
if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_PART_TABLE_TYPE")))
return 0;
if ((value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_PART_ENTRY_DISK")))
return 0;
return 1;
}
#else
static int _udev_dev_is_partitioned(struct device *dev)
{
return 0;
}
#endif
static int _native_dev_is_partitioned(struct dev_types *dt, struct device *dev)
{
int r;
if (!_is_partitionable(dt, dev)) if (!_is_partitionable(dt, dev))
return 0; return 0;
@ -333,7 +363,32 @@ int dev_is_partitioned(struct dev_types *dt, struct device *dev)
if (MAJOR(dev->dev) == dt->dasd_major) if (MAJOR(dev->dev) == dt->dasd_major)
return 1; return 1;
return _has_partition_table(dev); if (!dev_open_readonly_quiet(dev)) {
log_debug_devs("%s: failed to open device, considering device "
"is partitioned", dev_name(dev));
return 1;
}
r = _has_partition_table(dev);
if (!dev_close(dev))
stack;
return r;
}
int dev_is_partitioned(struct dev_types *dt, struct device *dev)
{
if (dev->ext.src == DEV_EXT_NONE)
return _native_dev_is_partitioned(dt, dev);
if (dev->ext.src == DEV_EXT_UDEV)
return _udev_dev_is_partitioned(dev);
log_error(INTERNAL_ERROR "Missing hook for partition table recognition "
"using external device info source %s", dev_ext_name(dev));
return 0;
} }
/* /*

View File

@ -15,28 +15,21 @@
#include "lib.h" #include "lib.h"
#include "filter.h" #include "filter.h"
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
#endif
static int _passes_partitioned_filter(struct dev_filter *f, struct device *dev) static int _passes_partitioned_filter(struct dev_filter *f, struct device *dev)
{ {
struct dev_types *dt = (struct dev_types *) f->private; struct dev_types *dt = (struct dev_types *) f->private;
int ret = 0;
if (!dev_open_readonly_quiet(dev)) { if (dev_is_partitioned(dt, dev)) {
log_debug_devs("%s: Skipping: open failed", dev_name(dev)); log_debug_devs("%s: Skipping: Partition table signature found [%s:%p]",
dev_name(dev), dev_ext_name(dev), dev->ext.handle);
return 0; return 0;
} }
if (dev_is_partitioned(dt, dev)) { return 1;
log_debug_devs("%s: Skipping: Partition table signature found",
dev_name(dev));
goto out;
}
ret = 1;
out:
if (!dev_close(dev))
stack;
return ret;
} }
static void _partitioned_filter_destroy(struct dev_filter *f) static void _partitioned_filter_destroy(struct dev_filter *f)