1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

Retrieve MD sysfs attributes for MD partitions

Rename private _primary_dev() to a public get_primary_dev() and reuse it
to allow retrieval of the MD sysfs attributes (raid level, etc) for MD
partitions.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
This commit is contained in:
Mike Snitzer 2009-08-01 17:11:02 +00:00
parent bb2a46b218
commit e92d56a94d
3 changed files with 23 additions and 9 deletions

View File

@ -127,20 +127,25 @@ out:
static int _md_sysfs_attribute_snprintf(char *path, size_t size, static int _md_sysfs_attribute_snprintf(char *path, size_t size,
const char *sysfs_dir, const char *sysfs_dir,
struct device *dev, struct device *blkdev,
const char *attribute) const char *attribute)
{ {
struct stat info; struct stat info;
dev_t dev = blkdev->dev;
int ret = -1; int ret = -1;
if (MAJOR(dev->dev) != md_major())
return ret;
if (!sysfs_dir || !*sysfs_dir) if (!sysfs_dir || !*sysfs_dir)
return ret; return ret;
check_md_major:
if (MAJOR(dev) != md_major()) {
if (get_primary_dev(sysfs_dir, blkdev, &dev))
goto check_md_major;
return ret;
}
ret = dm_snprintf(path, size, "%s/dev/block/%d:%d/md/%s", sysfs_dir, ret = dm_snprintf(path, size, "%s/dev/block/%d:%d/md/%s", sysfs_dir,
(int)MAJOR(dev->dev), (int)MINOR(dev->dev), attribute); (int)MAJOR(dev), (int)MINOR(dev), attribute);
if (ret < 0) { if (ret < 0) {
log_error("dm_snprintf md %s failed", attribute); log_error("dm_snprintf md %s failed", attribute);
return ret; return ret;
@ -149,7 +154,7 @@ static int _md_sysfs_attribute_snprintf(char *path, size_t size,
if (stat(path, &info) < 0) { if (stat(path, &info) < 0) {
/* old sysfs structure */ /* old sysfs structure */
ret = dm_snprintf(path, size, "%s/block/md%d/md/%s", ret = dm_snprintf(path, size, "%s/block/md%d/md/%s",
sysfs_dir, (int)MINOR(dev->dev), attribute); sysfs_dir, (int)MINOR(dev), attribute);
if (ret < 0) { if (ret < 0) {
log_error("dm_snprintf old md %s failed", attribute); log_error("dm_snprintf old md %s failed", attribute);
return ret; return ret;

View File

@ -286,8 +286,8 @@ int _get_partition_type(struct dev_mgr *dm, struct device *d)
#ifdef linux #ifdef linux
static int _primary_dev(const char *sysfs_dir, int get_primary_dev(const char *sysfs_dir,
struct device *dev, dev_t *result) struct device *dev, dev_t *result)
{ {
char path[PATH_MAX+1]; char path[PATH_MAX+1];
char temp_path[PATH_MAX+1]; char temp_path[PATH_MAX+1];
@ -387,7 +387,7 @@ static unsigned long _dev_topology_attribute(const char *attribute,
* or the device could be a partition * or the device could be a partition
*/ */
if (stat(path, &info) < 0) { if (stat(path, &info) < 0) {
if (!_primary_dev(sysfs_dir, dev, &primary)) if (!get_primary_dev(sysfs_dir, dev, &primary))
return 0; return 0;
/* get attribute from partition's primary device */ /* get attribute from partition's primary device */
@ -450,6 +450,12 @@ unsigned long dev_optimal_io_size(const char *sysfs_dir,
#else #else
int get_primary_dev(const char *sysfs_dir,
struct device *dev, dev_t *result)
{
return 0;
}
unsigned long dev_alignment_offset(const char *sysfs_dir, unsigned long dev_alignment_offset(const char *sysfs_dir,
struct device *dev) struct device *dev)
{ {

View File

@ -100,6 +100,9 @@ unsigned long dev_md_stripe_width(const char *sysfs_dir, struct device *dev);
int is_partitioned_dev(struct device *dev); int is_partitioned_dev(struct device *dev);
int get_primary_dev(const char *sysfs_dir,
struct device *dev, dev_t *result);
unsigned long dev_alignment_offset(const char *sysfs_dir, unsigned long dev_alignment_offset(const char *sysfs_dir,
struct device *dev); struct device *dev);