FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 04-19-2012, 09:08 AM
Hannes Reinecke
 
Default Use udev enumeration during discovery

Instead of scanning /sys/block by hand we should be using enumeration
provided by udev.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
libmultipath/discovery.c | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 426c511..d68324b 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -11,6 +11,7 @@
#include <dirent.h>
#include <errno.h>
#include <libgen.h>
+#include <libudev.h>

#include "checkers.h"
#include "vector.h"
@@ -91,37 +92,32 @@ path_discover (vector pathvec, struct config * conf, char * devname, int flag)
int
path_discovery (vector pathvec, struct config * conf, int flag)
{
- DIR *blkdir;
- struct dirent *blkdev;
- struct stat statbuf;
- char devpath[PATH_MAX];
+ struct udev_enumerate *udev_iter;
+ struct udev_list_entry *entry;
+ char *devpath;
char *devptr;
int r = 0;

- if (!(blkdir = opendir("/sys/block")))
+ udev_iter = udev_enumerate_new(conf->udev);
+ if (!udev_iter)
return 1;

- strcpy(devpath,"/sys/block");
- while ((blkdev = readdir(blkdir)) != NULL) {
- if ((strcmp(blkdev->d_name,".") == 0) ||
- (strcmp(blkdev->d_name,"..") == 0))
- continue;
-
- devptr = devpath + 10;
- *devptr = '';
- strcat(devptr,"/");
- strcat(devptr,blkdev->d_name);
- if (stat(devpath, &statbuf) < 0)
- continue;
-
- if (S_ISDIR(statbuf.st_mode) == 0)
- continue;
+ udev_enumerate_add_match_subsystem(udev_iter, "block");
+ udev_enumerate_scan_devices(udev_iter);

+ udev_list_entry_foreach(entry,
+ udev_enumerate_get_list_entry(udev_iter)) {
+ devpath = udev_list_entry_get_name(entry);
condlog(4, "Discover device %s", devpath);
+ devptr = strrchr(devpath, '/');
+ if (devptr)
+ devptr++;
+ else
+ devptr = devpath;

- r += path_discover(pathvec, conf, blkdev->d_name, flag);
+ r += path_discover(pathvec, conf, devptr, flag);
}
- closedir(blkdir);
+ udev_enumerate_unref(udev_iter);
condlog(4, "Discovery status %d", r);
return r;
}
--
1.7.3.4

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 04-30-2012, 10:25 AM
Hannes Reinecke
 
Default Use udev enumeration during discovery

Instead of scanning /sys/block by hand we should be using enumeration
provided by udev.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
libmultipath/discovery.c | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 426c511..d68324b 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -11,6 +11,7 @@
#include <dirent.h>
#include <errno.h>
#include <libgen.h>
+#include <libudev.h>

#include "checkers.h"
#include "vector.h"
@@ -91,37 +92,32 @@ path_discover (vector pathvec, struct config * conf, char * devname, int flag)
int
path_discovery (vector pathvec, struct config * conf, int flag)
{
- DIR *blkdir;
- struct dirent *blkdev;
- struct stat statbuf;
- char devpath[PATH_MAX];
+ struct udev_enumerate *udev_iter;
+ struct udev_list_entry *entry;
+ char *devpath;
char *devptr;
int r = 0;

- if (!(blkdir = opendir("/sys/block")))
+ udev_iter = udev_enumerate_new(conf->udev);
+ if (!udev_iter)
return 1;

- strcpy(devpath,"/sys/block");
- while ((blkdev = readdir(blkdir)) != NULL) {
- if ((strcmp(blkdev->d_name,".") == 0) ||
- (strcmp(blkdev->d_name,"..") == 0))
- continue;
-
- devptr = devpath + 10;
- *devptr = '';
- strcat(devptr,"/");
- strcat(devptr,blkdev->d_name);
- if (stat(devpath, &statbuf) < 0)
- continue;
-
- if (S_ISDIR(statbuf.st_mode) == 0)
- continue;
+ udev_enumerate_add_match_subsystem(udev_iter, "block");
+ udev_enumerate_scan_devices(udev_iter);

+ udev_list_entry_foreach(entry,
+ udev_enumerate_get_list_entry(udev_iter)) {
+ devpath = udev_list_entry_get_name(entry);
condlog(4, "Discover device %s", devpath);
+ devptr = strrchr(devpath, '/');
+ if (devptr)
+ devptr++;
+ else
+ devptr = devpath;

- r += path_discover(pathvec, conf, blkdev->d_name, flag);
+ r += path_discover(pathvec, conf, devptr, flag);
}
- closedir(blkdir);
+ udev_enumerate_unref(udev_iter);
condlog(4, "Discovery status %d", r);
return r;
}
--
1.7.3.4

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 02:51 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org