lib/sysfs: add sysfs_devno_is_lvm_private() from libblkid

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-06-17 11:20:32 +02:00
parent 097e7f2ff4
commit 39866431ee
6 changed files with 32 additions and 32 deletions

View File

@ -73,6 +73,8 @@ extern int sysfs_is_partition_dirent(DIR *dir, struct dirent *d,
extern int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
size_t len, dev_t *diskdevno);
extern int sysfs_devno_is_lvm_private(dev_t devno);
extern int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h,
int *c, int *t, int *l);
extern char *sysfs_scsi_host_strdup_attribute(struct sysfs_cxt *cxt,

View File

@ -629,6 +629,34 @@ err:
return -1;
}
/*
* Returns 1 if the device is private LVM device.
*/
int sysfs_devno_is_lvm_private(dev_t devno)
{
struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
char *uuid = NULL;
int rc = 0;
if (sysfs_init(&cxt, devno, NULL) != 0)
return 0;
uuid = sysfs_strdup(&cxt, "dm/uuid");
/* Private LVM devices use "LVM-<uuid>-<name>" uuid format (important
* is the "LVM" prefix and "-<name>" postfix).
*/
if (uuid && strncmp(uuid, "LVM-", 4) == 0) {
char *p = strrchr(uuid + 4, '-');
if (p && *(p + 1))
rc = 1;
}
sysfs_deinit(&cxt);
free(uuid);
return rc;
}
int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h, int *c, int *t, int *l)
{

View File

@ -348,7 +348,6 @@ extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **)
__attribute__((nonnull(1,4)));
extern int blkid_driver_has_major(const char *drvname, int major)
__attribute__((warn_unused_result));
extern int blkid_lvm_private(dev_t devno);
/* lseek.c */
extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);

View File

@ -326,35 +326,6 @@ int blkid_driver_has_major(const char *drvname, int major)
return match;
}
/*
* Returns 1 if the device is private LVM device.
*/
int blkid_lvm_private(dev_t devno)
{
struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
char *uuid = NULL;
int rc = 0;
if (sysfs_init(&cxt, devno, NULL) != 0)
return 0;
uuid = sysfs_strdup(&cxt, "dm/uuid");
/* Private LVM devices use "LVM-<uuid>-<name>" uuid format (important
* is the "LVM" prefix and "-<name>" postfix).
*/
if (uuid && strncmp(uuid, "LVM-", 4) == 0) {
char *p = strrchr(uuid + 4, '-');
if (p && *(p + 1))
rc = 1;
}
sysfs_deinit(&cxt);
free(uuid);
return rc;
}
#ifdef TEST_PROGRAM
int main(int argc, char** argv)
{

View File

@ -725,7 +725,7 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
if (pr->size <= 1440 * 1024 && !S_ISCHR(sb.st_mode))
pr->flags |= BLKID_FL_TINY_DEV;
if (S_ISBLK(sb.st_mode) && blkid_lvm_private(sb.st_rdev)) {
if (S_ISBLK(sb.st_mode) && sysfs_devno_is_lvm_private(sb.st_rdev)) {
DBG(LOWPROBE, ul_debug("ignore private LVM device"));
pr->flags |= BLKID_FL_NOSCAN_DEV;
}

View File

@ -112,7 +112,7 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
(unsigned long)diff));
#endif
if (blkid_lvm_private(st.st_rdev)) {
if (sysfs_devno_is_lvm_private(st.st_rdev)) {
blkid_free_dev(dev);
return NULL;
}