Skip to contentSkip to conversation

Remove libsysfs

PATCH In review Hannes Reinecke 1 participant 1 message May 21, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 17/21 Remove libsysfs

libsysfs is deprecated and doesn't work with recent kernels. Copied over stuff from udev and implemented our own sysfs handling. Much saner now.

---
 Makefile.inc               |    1 -
 libmultipath/Makefile      |    2 +-
 libmultipath/config.h      |    1 +
 libmultipath/configure.c   |    4 +-
 libmultipath/discovery.c   |  422 +++++++++++++++++---------------------------
 libmultipath/discovery.h   |    7 +-
 libmultipath/list.h        |  289 ++++++++++++++++++++++++++++++
 libmultipath/print.c       |   47 +++--
 libmultipath/structs.h     |   15 ++-
 libmultipath/structs_vec.c |    7 +-
 libmultipath/sysfs.c       |  409 ++++++++++++++++++++++++++++++++++++++++++
 libmultipath/sysfs.h       |   20 ++
 libmultipath/util.c        |   52 ++++++
 libmultipath/util.h        |    4 +-
 multipath/Makefile         |    2 +-
 multipath/main.c           |   11 +-
 multipathd/Makefile        |    2 +-
 multipathd/cli_handlers.c  |   17 ++-
 multipathd/main.c          |   92 +++++------
 multipathd/main.h          |    2 +-
 20 files changed, 1059 insertions(+), 347 deletions(-)
Makefile.inc +0 -1
index 71970ef..7eb3dfb 100644
@@ -17,7 +17,6 @@ ifeq ($(strip $(BUILD)),klibc)
 	CC = klcc
 	klibcdir = /usr/lib/klibc
 	libdm    = $(klibcdir)/lib/libdevmapper.a
-	libsysfs = $(klibcdir)/lib/libsysfs.a
 endif
 
 prefix      = 
libmultipath/Makefile +1 -1
index ef561a8..511f5ad 100644
@@ -13,7 +13,7 @@ OBJS = memory.o parser.o vector.o devmap
        structs.o discovery.o propsel.o dict.o \
        pgpolicies.o debug.o regex.o defaults.o uevent.o \
        switchgroup.o uxsock.o print.o alias.o log_pthread.o \
-       log.o configure.o structs_vec.o
+       log.o configure.o structs_vec.o sysfs.o
 
 PREVBUILD = $(shell nm debug.o 2> /dev/null|grep log_safe)
 
libmultipath/config.h +1 -0
index 7caa11d..a25b3ad 100644
@@ -66,6 +66,7 @@ struct config {
 	int pg_timeout;
 
 	char * dev;
+	char * sysfs_dir;
 	char * udev_dir;
 	char * selector;
 	char * getuid;
libmultipath/configure.c +3 -1
index a5bad4c..3cd6041 100644
@@ -325,8 +325,10 @@ domap (struct multipath * mpp)
 			return DOMAP_RETRY;
 		}
 
-		if (dm_map_present(mpp->alias))
+		if (dm_map_present(mpp->alias)) {
+			condlog(3, "%s: map already present", mpp->alias);
 			break;
+		}
 
 		r = dm_addmap(DM_DEVICE_CREATE, mpp->alias, DEFAULT_TARGET,
 			      mpp->params, mpp->size, mpp->wwid);
libmultipath/discovery.c +166 -256

568 lines not on this page · raw message

libmultipath/discovery.h +1 -6
index ab62a59..c7cf7e8 100644
@@ -24,12 +24,7 @@
 #define SCSI_COMMAND_TERMINATED 0x22
 #define SG_ERR_DRIVER_SENSE     0x08
 
-int sysfs_get_vendor (char * sysfs_path, char * dev, char * buff, int len);
-int sysfs_get_model (char * sysfs_path, char * dev, char * buff, int len);
-int sysfs_get_rev (char * sysfs_path, char * dev, char * buff, int len);
-int sysfs_get_dev (char * sysfs_path, char * dev, char * buff, int len);
-
-int sysfs_get_size (char * sysfs_path, char * dev, unsigned long long *);
+int sysfs_get_dev (struct sysfs_device * dev, char * buff, size_t len);
 int path_discovery (vector pathvec, struct config * conf, int flag);
 
 void basename (char *, char *);
libmultipath/list.h new file +289 -0

289 lines not on this page · raw message

libmultipath/print.c +29 -18

80 lines not on this page · raw message

libmultipath/structs.h +14 -1
index 46dcdee..75322aa 100644
@@ -9,6 +9,9 @@
 #define FILE_NAME_SIZE		256
 #define CALLOUT_MAX_SIZE	128
 #define BLK_DEV_SIZE		33
+#define PATH_SIZE		512
+#define NAME_SIZE		128
+
 
 #define SCSI_VENDOR_SIZE	9
 #define SCSI_PRODUCT_SIZE	17
@@ -86,9 +89,19 @@ struct scsi_dev {
 	int host_no;
 };
 
+struct sysfs_device {
+	struct sysfs_device *parent;		/* parent device */
+	char devpath[PATH_SIZE];
+	char subsystem[NAME_SIZE];		/* $class, $bus, drivers, module */
+	char kernel[NAME_SIZE];			/* device instance name */
+	char kernel_number[NAME_SIZE];
+	char driver[NAME_SIZE];			/* device driver name */
+};
+
 struct path {
 	char dev[FILE_NAME_SIZE];
 	char dev_t[BLK_DEV_SIZE];
+	struct sysfs_device *sysdev;
 	struct scsi_idlun scsi_id;
 	struct sg_id sg_id;
 	char wwid[WWID_SIZE];
@@ -200,6 +213,6 @@ struct path * first_path (struct multipa
 int pathcountgr (struct pathgroup *, int);
 int pathcount (struct multipath *, int);
 
-char sysfs_path[FILE_NAME_SIZE];
+extern char sysfs_path[PATH_SIZE];
 
 #endif /* _STRUCTS_H */
libmultipath/structs_vec.c +4 -3
index a4a996a..1cc6028 100644
@@ -13,6 +13,7 @@
 #include "dmparser.h"
 #include "config.h"
 #include "propsel.h"
+#include "sysfs.h"
 #include "discovery.h"
 #include "waiter.h"
 
@@ -373,10 +374,10 @@ verify_paths(struct multipath * mpp, str
 		/*
 		 * see if path is in sysfs
 		 */
-		if (!pp->dev || sysfs_get_dev(sysfs_path,
-				  pp->dev, pp->dev_t, BLK_DEV_SIZE)) {
+		if (!pp->sysdev || sysfs_get_dev(pp->sysdev,
+						 pp->dev_t, BLK_DEV_SIZE)) {
 			condlog(0, "%s: failed to access path %s", mpp->alias,
-				pp->dev ? pp->dev : pp->dev_t);
+				pp->sysdev ? pp->sysdev->devpath : pp->dev_t);
 			count++;
 			vector_del_slot(mpp->paths, i);
 			i--;
libmultipath/sysfs.c new file +409 -0

409 lines not on this page · raw message

libmultipath/sysfs.h new file +20 -0
new file mode 100644
index 0000000..4ac30db
@@ -0,0 +1,20 @@
+/*
+ * sysfs.h
+ */
+
+#ifndef _LIBMULTIPATH_SYSFS_H
+#define _LIBMULTIPATH_SYSFS_H
+
+#define dbg(format, arg...) do {} while (0)
+
+int sysfs_init(char *path, size_t len);
+void sysfs_cleanup(void);
+void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath,
+			     const char *subsystem, const char *driver);
+struct sysfs_device *sysfs_device_get(const char *devpath);
+struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
+struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
+char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
+int sysfs_resolve_link(char *path, size_t size);
+
+#endif
libmultipath/util.c +52 -0

55 lines not on this page · raw message

libmultipath/util.h +3 -1
index e86bae2..d0df8aa 100644
@@ -6,7 +6,9 @@ void strchop(char *);
 void basename (char * src, char * dst);
 int filepresent (char * run);
 int get_word (char * sentence, char ** word);
-
+size_t strlcpy(char *dst, const char *src, size_t size);
+size_t strlcat(char *dst, const char *src, size_t size);
+void remove_trailing_chars(char *path, char c);
 
 #define safe_sprintf(var, format, args...)	\
 	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
multipath/Makefile +1 -1
index 2afa6ad..8ff1775 100644
@@ -12,7 +12,7 @@ CFLAGS += -I$(multipathdir) -I$(checkers
 ifeq ($(strip $(BUILD)),klibc)
 	OBJS += $(libdm) $(libsysfs)
 else
-	LDFLAGS += -ldevmapper -lsysfs
+	LDFLAGS += -ldevmapper
 endif
 
 EXEC = multipath
multipath/main.c +6 -5
index c3d0dac..e2d7f41 100644
@@ -25,7 +25,6 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <ctype.h>
-#include <sysfs/libsysfs.h>
 
 #include <checkers.h>
 #include <vector.h>
@@ -37,6 +36,7 @@
 #include <structs.h>
 #include <structs_vec.h>
 #include <dmparser.h>
+#include <sysfs.h>
 #include <config.h>
 #include <blacklist.h>
 #include <discovery.h>
@@ -373,13 +373,13 @@ main (int argc, char *argv[])
 	if (dm_prereq(DEFAULT_TARGET))
 		exit(1);
 
-	if (sysfs_get_mnt_path(sysfs_path, FILE_NAME_SIZE)) {
-		condlog(0, "multipath tools need sysfs mounted");
-		exit(1);
-	}
 	if (load_config(DEFAULT_CONFIGFILE))
 		exit(1);
 
+	if (sysfs_init(conf->sysfs_dir, FILE_NAME_SIZE)) {
+		condlog(0, "multipath tools need sysfs mounted");
+		exit(1);
+	}
 	while ((arg = getopt(argc, argv, ":dhl::FfM:v:p:b:t")) != EOF ) {
 		switch(arg) {
 		case 1: printf("optarg : %s\n",optarg);
@@ -472,6 +472,7 @@ main (int argc, char *argv[])
 		condlog(3, "restart multipath configuration process");
 	
 out:
+	sysfs_cleanup();
 	free_config(conf);
 	dm_lib_release();
 	dm_lib_exit();
multipathd/Makefile +1 -1
index 8ad25ee..5ae9e7b 100644
@@ -7,7 +7,7 @@ include ../Makefile.inc
 # basic flags setting
 #
 CFLAGS += -DDAEMON -I$(multipathdir) -I$(checkersdir)
-LDFLAGS = -lpthread -ldevmapper -lsysfs -lreadline -lncurses
+LDFLAGS = -lpthread -ldevmapper -lreadline -lncurses
 
 #
 # debuging stuff
multipathd/cli_handlers.c +16 -1
index 4938e84..7bae02a 100644
@@ -13,6 +13,7 @@
 #include <blacklist.h>
 #include <debug.h>
 #include <print.h>
+#include <sysfs.h>
 
 #include "main.h"
 #include "cli.h"
@@ -312,6 +313,9 @@ cli_add_map (void * v, char ** reply, in
 {
 	struct vectors * vecs = (struct vectors *)data;
 	char * param = get_keyparam(v, MAP);
+	int minor;
+	char dev_path[PATH_SIZE];
+	struct sysfs_device *sysdev;
 
 	condlog(2, "%s: add map (operator)", param);
 
@@ -321,7 +325,18 @@ cli_add_map (void * v, char ** reply, in
 		condlog(2, "%s: map blacklisted", param);
 		return 0;
 	}
-	return ev_add_map(param, vecs);
+	minor = dm_get_minor(param);
+	if (minor < 0) {
+		condlog(2, "%s: not a device mapper table", param);
+		return 0;
+	}
+	sprintf(dev_path,"/block/dm-%d", minor);
+	sysdev = sysfs_device_get(dev_path);
+	if (!sysdev) {
+		condlog(2, "%s: not found in sysfs", param);
+		return 0;
+	}
+	return ev_add_map(sysdev, vecs);
 }
 
 int
multipathd/main.c +42 -50

228 lines not on this page · raw message

multipathd/main.h +1 -1
index d0cce3a..1a6dc55 100644
@@ -7,7 +7,7 @@
 int reconfigure (struct vectors *);
 int ev_add_path (char *, struct vectors *);
 int ev_remove_path (char *, struct vectors *);
-int ev_add_map (char *, struct vectors *);
+int ev_add_map (struct sysfs_device *, struct vectors *);
 int ev_remove_map (char *, struct vectors *);
 
 #endif /* MAIN_H */
Signature · 1 line
1.4.3.4