multipath-tools/multipath-tools-online-device.patch

108 lines
2.4 KiB
Diff

diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -209,6 +209,44 @@ sysfs_get_size (char * sysfs_path, char
return 0;
}
+int
+sysfs_get_online (char * sysfs_path, char * dev)
+{
+ char attr_path[SYSFS_PATH_SIZE];
+ char attr_buff[SYSFS_PATH_SIZE];
+ long r;
+ char *p;
+
+ if (safe_sprintf(attr_path, "%s/block/%s/online", sysfs_path, dev))
+ return -1;
+
+ if (0 > sysfs_read_attribute_value(attr_path, attr_buff, sizeof(attr_buff)))
+ return -1;
+
+ r = strtol(attr_buff,&p, 10);
+
+ if (attr_buff != p && r > 0)
+ return 1;
+
+ return 0;
+}
+
+int writeattr (char *path, const char *value)
+{
+ struct sysfs_attribute *attr;
+ int retval;
+
+ attr = sysfs_open_attribute(path);
+ if (!attr)
+ return -1;
+
+ retval = sysfs_write_attribute(attr, value, strlen(value));
+
+ sysfs_close_attribute(attr);
+
+ return retval > 0? -1 : 0;
+}
+
/*
* udev might be slow creating node files : wait
*/
@@ -565,6 +603,30 @@ sysfs_pathinfo(struct path * curpath)
return 0;
}
+extern int
+online_device(struct path *curpath)
+{
+ int online;
+ char attr_path[FILE_NAME_SIZE];
+
+ online = sysfs_get_online(sysfs_path, curpath->dev);
+ if (online > 0)
+ return 0;
+ else if(online < 0)
+ return 1;
+
+ if(safe_sprintf(attr_path, "%s/block/%s/device/online",
+ sysfs_path, curpath->dev)) {
+ condlog(0, "attr_path too small");
+ return 1;
+ }
+
+ condlog(1,"%s: setting device online", curpath->dev);
+ writeattr(attr_path, "1");
+
+ return 0;
+}
+
static int
apply_format (char * string, char * cmd, struct path * pp)
{
diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h
--- a/libmultipath/discovery.h
+++ b/libmultipath/discovery.h
@@ -28,6 +28,7 @@ int sysfs_get_dev (char * sysfs_path, ch
int sysfs_get_size (char * sysfs_path, char * dev, unsigned long long *);
int path_discovery (vector pathvec, struct config * conf, int flag);
+int online_device (struct path *curpath);
void basename (char *, char *);
int get_serial (char * buff, int fd);
diff --git a/multipathd/main.c b/multipathd/main.c
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -1185,6 +1185,13 @@ checkerloop (void *ap)
condlog(0, "%s: checkfn is void", pp->dev);
continue;
}
+
+ /*
+ * Set the device online for checkers
+ * to run successfully
+ */
+ online_device(pp);
+
newstate = pp->checkfn(pp->fd, checker_msg,
&pp->checker_context);