Blame SOURCES/0197-RHBZ-1394059-max-sectors-kb.patch

4ae388
---
4ae388
 libmultipath/config.c      |    3 +
4ae388
 libmultipath/config.h      |    3 +
4ae388
 libmultipath/configure.c   |    1 
4ae388
 libmultipath/defaults.h    |    1 
4ae388
 libmultipath/devmapper.c   |    4 +-
4ae388
 libmultipath/dict.c        |   87 +++++++++++++++++++++++++++++++++++++++++++++
4ae388
 libmultipath/discovery.c   |   60 +++++++++++++++++++++++++++++++
4ae388
 libmultipath/discovery.h   |    1 
4ae388
 libmultipath/propsel.c     |   25 ++++++++++++
4ae388
 libmultipath/propsel.h     |    1 
4ae388
 libmultipath/structs.h     |    7 +++
4ae388
 multipath/multipath.conf.5 |    8 ++++
4ae388
 12 files changed, 200 insertions(+), 1 deletion(-)
4ae388
4ae388
Index: multipath-tools-130222/libmultipath/config.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/config.c
4ae388
+++ multipath-tools-130222/libmultipath/config.c
4ae388
@@ -344,6 +344,7 @@ merge_hwe (struct hwentry * dst, struct
4ae388
 	merge_num(delay_watch_checks);
4ae388
 	merge_num(delay_wait_checks);
4ae388
 	merge_num(skip_kpartx);
4ae388
+	merge_num(max_sectors_kb);
4ae388
 
4ae388
 	/*
4ae388
 	 * Make sure features is consistent with
4ae388
@@ -405,6 +406,7 @@ overwrite_hwe (struct hwentry * dst, str
4ae388
 	overwrite_num(delay_watch_checks);
4ae388
 	overwrite_num(delay_wait_checks);
4ae388
 	overwrite_num(skip_kpartx);
4ae388
+	overwrite_num(max_sectors_kb);
4ae388
 
4ae388
 	/*
4ae388
 	 * Make sure features is consistent with
4ae388
@@ -682,6 +684,7 @@ load_config (char * file, struct udev *u
4ae388
 	conf->skip_kpartx = DEFAULT_SKIP_KPARTX;
4ae388
 	conf->remove_retries = 0;
4ae388
 	conf->disable_changed_wwids = 0;
4ae388
+	conf->max_sectors_kb = DEFAULT_MAX_SECTORS_KB;
4ae388
 
4ae388
 	/*
4ae388
 	 * preload default hwtable
4ae388
Index: multipath-tools-130222/libmultipath/config.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/config.h
4ae388
+++ multipath-tools-130222/libmultipath/config.h
4ae388
@@ -65,6 +65,7 @@ struct hwentry {
4ae388
 	int delay_watch_checks;
4ae388
 	int delay_wait_checks;
4ae388
 	int skip_kpartx;
4ae388
+	int max_sectors_kb;
4ae388
 	char * bl_product;
4ae388
 };
4ae388
 
4ae388
@@ -92,6 +93,7 @@ struct mpentry {
4ae388
 	int delay_watch_checks;
4ae388
 	int delay_wait_checks;
4ae388
 	int skip_kpartx;
4ae388
+	int max_sectors_kb;
4ae388
 	uid_t uid;
4ae388
 	gid_t gid;
4ae388
 	mode_t mode;
4ae388
@@ -148,6 +150,7 @@ struct config {
4ae388
 	int skip_kpartx;
4ae388
 	int remove_retries;
4ae388
 	int disable_changed_wwids;
4ae388
+	int max_sectors_kb;
4ae388
 	unsigned int version[3];
4ae388
 
4ae388
 	char * dev;
4ae388
Index: multipath-tools-130222/libmultipath/configure.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/configure.c
4ae388
+++ multipath-tools-130222/libmultipath/configure.c
4ae388
@@ -295,6 +295,7 @@ setup_map (struct multipath * mpp, char
4ae388
 	select_delay_watch_checks(mpp);
4ae388
 	select_delay_wait_checks(mpp);
4ae388
 	select_skip_kpartx(mpp);
4ae388
+	select_max_sectors_kb(mpp);
4ae388
 
4ae388
 	sysfs_set_scsi_tmo(mpp);
4ae388
 	/*
4ae388
Index: multipath-tools-130222/libmultipath/defaults.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/defaults.h
4ae388
+++ multipath-tools-130222/libmultipath/defaults.h
4ae388
@@ -25,6 +25,7 @@
4ae388
 #define DEFAULT_RETRIGGER_TRIES 3
4ae388
 #define DEFAULT_UEV_WAIT_TIMEOUT 30
4ae388
 #define DEFAULT_SKIP_KPARTX SKIP_KPARTX_OFF
4ae388
+#define DEFAULT_MAX_SECTORS_KB	MAX_SECTORS_KB_UNDEF
4ae388
 
4ae388
 #define DEFAULT_CHECKINT	5
4ae388
 #define MAX_CHECKINT(a)		(a << 2)
4ae388
Index: multipath-tools-130222/libmultipath/dict.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/dict.c
4ae388
+++ multipath-tools-130222/libmultipath/dict.c
4ae388
@@ -976,6 +976,22 @@ def_disable_changed_wwids_handler(vector
4ae388
 	return 0;
4ae388
 }
4ae388
 
4ae388
+static int
4ae388
+def_max_sectors_kb_handler(vector strvec)
4ae388
+{
4ae388
+	char * buff;
4ae388
+
4ae388
+	buff = set_value(strvec);
4ae388
+	if (!buff)
4ae388
+		return 1;
4ae388
+
4ae388
+	if ((conf->max_sectors_kb = atoi(buff)) < MAX_SECTORS_KB_MIN)
4ae388
+		conf->max_sectors_kb = MAX_SECTORS_KB_UNDEF;
4ae388
+
4ae388
+	FREE(buff);
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
 /*
4ae388
  * blacklist block handlers
4ae388
  */
4ae388
@@ -1765,6 +1781,26 @@ hw_delay_wait_checks_handler(vector strv
4ae388
 	return 0;
4ae388
 }
4ae388
 
4ae388
+static int
4ae388
+hw_max_sectors_kb_handler(vector strvec)
4ae388
+{
4ae388
+	struct hwentry *hwe = VECTOR_LAST_SLOT(conf->hwtable);
4ae388
+	char * buff;
4ae388
+
4ae388
+	if (!hwe)
4ae388
+		return 1;
4ae388
+
4ae388
+	buff = set_value(strvec);
4ae388
+	if (!buff)
4ae388
+		return 1;
4ae388
+
4ae388
+	if ((hwe->max_sectors_kb = atoi(buff)) < MAX_SECTORS_KB_MIN)
4ae388
+		hwe->max_sectors_kb = MAX_SECTORS_KB_UNDEF;
4ae388
+
4ae388
+	FREE(buff);
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
 /*
4ae388
  * multipaths block handlers
4ae388
  */
4ae388
@@ -2316,6 +2352,26 @@ mp_delay_wait_checks_handler(vector strv
4ae388
 	return 0;
4ae388
 }
4ae388
 
4ae388
+static int
4ae388
+mp_max_sectors_kb_handler(vector strvec)
4ae388
+{
4ae388
+	struct mpentry *mpe = VECTOR_LAST_SLOT(conf->mptable);
4ae388
+	char * buff;
4ae388
+
4ae388
+	if (!mpe)
4ae388
+		return 1;
4ae388
+
4ae388
+	buff = set_value(strvec);
4ae388
+	if (!buff)
4ae388
+		return 1;
4ae388
+
4ae388
+	if ((mpe->max_sectors_kb = atoi(buff)) < MAX_SECTORS_KB_MIN)
4ae388
+		mpe->max_sectors_kb = MAX_SECTORS_KB_UNDEF;
4ae388
+
4ae388
+	FREE(buff);
4ae388
+	return 0;
4ae388
+}
4ae388
+
4ae388
 /*
4ae388
  * config file keywords printing
4ae388
  */
4ae388
@@ -2615,6 +2671,16 @@ snprint_mp_delay_wait_checks(char * buff
4ae388
 }
4ae388
 
4ae388
 static int
4ae388
+snprint_mp_max_sectors_kb(char * buff, int len, void * data)
4ae388
+{
4ae388
+	struct mpentry * mpe = (struct mpentry *)data;
4ae388
+
4ae388
+	if (mpe->max_sectors_kb == MAX_SECTORS_KB_UNDEF)
4ae388
+		return 0;
4ae388
+	return snprintf(buff, len, "%d", mpe->max_sectors_kb);
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
 snprint_hw_fast_io_fail(char * buff, int len, void * data)
4ae388
 {
4ae388
 	struct hwentry * hwe = (struct hwentry *)data;
4ae388
@@ -2993,6 +3059,16 @@ snprint_detect_prio(char * buff, int len
4ae388
 }
4ae388
 
4ae388
 static int
4ae388
+snprint_hw_max_sectors_kb(char * buff, int len, void * data)
4ae388
+{
4ae388
+	struct hwentry * hwe = (struct hwentry *)data;
4ae388
+
4ae388
+	if (hwe->max_sectors_kb == MAX_SECTORS_KB_UNDEF)
4ae388
+		return 0;
4ae388
+	return snprintf(buff, len, "%d", hwe->max_sectors_kb);
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
 snprint_def_polling_interval (char * buff, int len, void * data)
4ae388
 {
4ae388
 	return snprintf(buff, len, "%i", conf->checkint);
4ae388
@@ -3461,6 +3537,14 @@ snprint_def_disable_changed_wwids(char *
4ae388
 }
4ae388
 
4ae388
 static int
4ae388
+snprint_def_max_sectors_kb(char * buff, int len, void * data)
4ae388
+{
4ae388
+	if (conf->max_sectors_kb == MAX_SECTORS_KB_UNDEF)
4ae388
+		return 0;
4ae388
+	return snprintf(buff, len, "%d", conf->max_sectors_kb);
4ae388
+}
4ae388
+
4ae388
+static int
4ae388
 snprint_ble_simple (char * buff, int len, void * data)
4ae388
 {
4ae388
 	struct blentry * ble = (struct blentry *)data;
4ae388
@@ -3541,6 +3625,7 @@ init_keywords(void)
4ae388
 	install_keyword("new_bindings_in_boot", &def_new_bindings_in_boot_handler, &snprint_def_new_bindings_in_boot);
4ae388
 	install_keyword("remove_retries", &def_remove_retries_handler, &snprint_def_remove_retries);
4ae388
 	install_keyword("disable_changed_wwids", &def_disable_changed_wwids_handler, &snprint_def_disable_changed_wwids);
4ae388
+	install_keyword("max_sectors_kb", &def_max_sectors_kb_handler, &snprint_def_max_sectors_kb);
4ae388
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
4ae388
 	__deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
4ae388
 	__deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
4ae388
@@ -3609,6 +3694,7 @@ init_keywords(void)
4ae388
 	install_keyword("delay_watch_checks", &hw_delay_watch_checks_handler, &snprint_hw_delay_watch_checks);
4ae388
 	install_keyword("delay_wait_checks", &hw_delay_wait_checks_handler, &snprint_hw_delay_wait_checks);
4ae388
 	install_keyword("skip_kpartx", &hw_skip_kpartx_handler, &snprint_hw_skip_kpartx);
4ae388
+	install_keyword("max_sectors_kb", &hw_max_sectors_kb_handler, &snprint_hw_max_sectors_kb);
4ae388
 	install_sublevel_end();
4ae388
 
4ae388
 	install_keyword_root("multipaths", &multipaths_handler);
4ae388
@@ -3637,5 +3723,6 @@ init_keywords(void)
4ae388
 	install_keyword("delay_watch_checks", &mp_delay_watch_checks_handler, &snprint_mp_delay_watch_checks);
4ae388
 	install_keyword("delay_wait_checks", &mp_delay_wait_checks_handler, &snprint_mp_delay_wait_checks);
4ae388
 	install_keyword("skip_kpartx", &mp_skip_kpartx_handler, &snprint_mp_skip_kpartx);
4ae388
+	install_keyword("max_sectors_kb", &mp_max_sectors_kb_handler, &snprint_mp_max_sectors_kb);
4ae388
 	install_sublevel_end();
4ae388
 }
4ae388
Index: multipath-tools-130222/libmultipath/discovery.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/discovery.c
4ae388
+++ multipath-tools-130222/libmultipath/discovery.c
4ae388
@@ -12,6 +12,7 @@
4ae388
 #include <errno.h>
4ae388
 #include <libgen.h>
4ae388
 #include <libudev.h>
4ae388
+#include <libdevmapper.h>
4ae388
 
4ae388
 #include "checkers.h"
4ae388
 #include "vector.h"
4ae388
@@ -27,6 +28,7 @@
4ae388
 #include "discovery.h"
4ae388
 #include "prio.h"
4ae388
 #include "defaults.h"
4ae388
+#include "devmapper.h"
4ae388
 
4ae388
 int
4ae388
 store_pathinfo (vector pathvec, vector hwtable, struct udev_device *udevice,
4ae388
@@ -166,6 +168,64 @@ declare_sysfs_get_str(rev);
4ae388
 declare_sysfs_get_str(dev);
4ae388
 
4ae388
 int
4ae388
+sysfs_set_max_sectors_kb(struct multipath *mpp, int is_reload)
4ae388
+{
4ae388
+	struct pathgroup * pgp;
4ae388
+	struct path *pp;
4ae388
+	char buff[11];
4ae388
+	struct udev_device *udevice = NULL;
4ae388
+	int i, j, len, ret;
4ae388
+	int max_sectors_kb;
4ae388
+
4ae388
+	if (mpp->max_sectors_kb == MAX_SECTORS_KB_UNDEF)
4ae388
+		return 0;
4ae388
+	max_sectors_kb = mpp->max_sectors_kb;
4ae388
+	if (is_reload) {
4ae388
+		if (!mpp->dmi && dm_get_info(mpp->alias, &mpp->dmi) != 0) {
4ae388
+			condlog(0, "failed to get dm info on %s to set max_sectors_kb", mpp->alias);
4ae388
+			return 1;
4ae388
+		}
4ae388
+		udevice = udev_device_new_from_devnum(conf->udev, 'b',
4ae388
+						      makedev(mpp->dmi->major,
4ae388
+							      mpp->dmi->minor));
4ae388
+		if (!udevice) {
4ae388
+			condlog(0, "failed to get udev device to set max_sectors_kb for %s", mpp->alias);
4ae388
+			return 1;
4ae388
+		}
4ae388
+		if (sysfs_attr_get_value(udevice, "queue/max_sectors_kb",
4ae388
+					 buff, sizeof(buff)) <= 0) {
4ae388
+			condlog(0, "failed to get current max_sectors_kb from %s", mpp->alias);
4ae388
+			goto fail_reload;
4ae388
+		}
4ae388
+		if (sscanf(buff, "%u\n", &max_sectors_kb) != 1) {
4ae388
+			condlog(0, "can't parse current max_sectors_kb from %s",
4ae388
+				mpp->alias);
4ae388
+			goto fail_reload;
4ae388
+		}
4ae388
+		udev_device_unref(udevice);
4ae388
+	}
4ae388
+	snprintf(buff, 11, "%d", max_sectors_kb);
4ae388
+	len = strlen(buff);
4ae388
+
4ae388
+	vector_foreach_slot (mpp->pg, pgp, i) {
4ae388
+		vector_foreach_slot (pgp->paths, pp, j) {
4ae388
+			ret = sysfs_attr_set_value(pp->udev,
4ae388
+						   "queue/max_sectors_kb",
4ae388
+					  	   buff, len);
4ae388
+			if (ret < 0) {
4ae388
+				condlog(0, "failed setting max_sectors_kb on %s : %s", pp->dev, strerror(-ret));
4ae388
+				return 1;
4ae388
+			}
4ae388
+		}
4ae388
+	}
4ae388
+	return 0;
4ae388
+
4ae388
+fail_reload:
4ae388
+	udev_device_unref(udevice);
4ae388
+	return 1;
4ae388
+}
4ae388
+
4ae388
+int
4ae388
 sysfs_get_timeout(struct path *pp, unsigned int *timeout)
4ae388
 {
4ae388
 	const char *attr = NULL;
4ae388
Index: multipath-tools-130222/libmultipath/discovery.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/discovery.h
4ae388
+++ multipath-tools-130222/libmultipath/discovery.h
4ae388
@@ -41,6 +41,7 @@ int store_pathinfo (vector pathvec, vect
4ae388
 		    struct udev_device *udevice, int flag,
4ae388
 		    struct path **pp_ptr);
4ae388
 int sysfs_set_scsi_tmo (struct multipath *mpp);
4ae388
+int sysfs_set_max_sectors_kb(struct multipath *mpp, int is_reload);
4ae388
 int sysfs_get_timeout(struct path *pp, unsigned int *timeout);
4ae388
 int sysfs_get_host_pci_name(struct path *pp, char *pci_name);
4ae388
 int sysfs_get_iscsi_ip_address(struct path *pp, char *ip_address);
4ae388
Index: multipath-tools-130222/libmultipath/propsel.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/propsel.c
4ae388
+++ multipath-tools-130222/libmultipath/propsel.c
4ae388
@@ -880,3 +880,28 @@ select_skip_kpartx (struct multipath * m
4ae388
 	condlog(3, "skip_kpartx = DISABLED (internal default)");
4ae388
 	return 0;
4ae388
 }
4ae388
+
4ae388
+extern int
4ae388
+select_max_sectors_kb (struct multipath * mp)
4ae388
+{
4ae388
+	if (mp->mpe && mp->mpe->max_sectors_kb != MAX_SECTORS_KB_UNDEF) {
4ae388
+		mp->max_sectors_kb = mp->mpe->max_sectors_kb;
4ae388
+		condlog(3, "max_sectors_kb = %i (multipath setting)",
4ae388
+				mp->max_sectors_kb);
4ae388
+		return 0;
4ae388
+	}
4ae388
+	if (mp->hwe && mp->hwe->max_sectors_kb != MAX_SECTORS_KB_UNDEF) {
4ae388
+		mp->max_sectors_kb = mp->hwe->max_sectors_kb;
4ae388
+		condlog(3, "max_sectors_kb = %i (controler setting)",
4ae388
+				mp->max_sectors_kb);
4ae388
+		return 0;
4ae388
+	}
4ae388
+	if (conf->max_sectors_kb != MAX_SECTORS_KB_UNDEF) {
4ae388
+		mp->max_sectors_kb = conf->max_sectors_kb;
4ae388
+		condlog(3, "max_sectors_kb = %i (config file default)",
4ae388
+				mp->max_sectors_kb);
4ae388
+		return 0;
4ae388
+	}
4ae388
+	mp->max_sectors_kb = MAX_SECTORS_KB_UNDEF;
4ae388
+	return 0;
4ae388
+}
4ae388
Index: multipath-tools-130222/libmultipath/propsel.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/propsel.h
4ae388
+++ multipath-tools-130222/libmultipath/propsel.h
4ae388
@@ -24,3 +24,4 @@ int select_deferred_remove(struct multip
4ae388
 int select_delay_watch_checks (struct multipath * mp);
4ae388
 int select_delay_wait_checks (struct multipath * mp);
4ae388
 int select_skip_kpartx (struct multipath * mp);
4ae388
+int select_max_sectors_kb (struct multipath * mp);
4ae388
Index: multipath-tools-130222/libmultipath/structs.h
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/structs.h
4ae388
+++ multipath-tools-130222/libmultipath/structs.h
4ae388
@@ -128,6 +128,12 @@ enum skip_kpartx_states {
4ae388
 	SKIP_KPARTX_ON,
4ae388
 };
4ae388
 
4ae388
+
4ae388
+enum max_sectors_kb_states {
4ae388
+	MAX_SECTORS_KB_UNDEF = 0,
4ae388
+	MAX_SECTORS_KB_MIN = 4,  /* can't be smaller than page size */
4ae388
+};
4ae388
+
4ae388
 enum scsi_protocol {
4ae388
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
4ae388
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
4ae388
@@ -245,6 +251,7 @@ struct multipath {
4ae388
 	int delay_wait_checks;
4ae388
 	int force_udev_reload;
4ae388
 	int skip_kpartx;
4ae388
+	int max_sectors_kb;
4ae388
 	unsigned int dev_loss;
4ae388
 	uid_t uid;
4ae388
 	gid_t gid;
4ae388
Index: multipath-tools-130222/multipath/multipath.conf.5
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipath/multipath.conf.5
4ae388
+++ multipath-tools-130222/multipath/multipath.conf.5
4ae388
@@ -567,6 +567,10 @@ disable access to the path until the wwi
4ae388
 This sets how may times multipath will retry removing a device that is in-use.
4ae388
 Between each attempt, multipath will sleep 1 second. The default is
4ae388
 .I 0
4ae388
+.TP
4ae388
+.B max_sectors_kb
4ae388
+Sets the max_sectors_kb device parameter on all path devices and the multipath
4ae388
+device to the specified value. Default is device dependent.
4ae388
 .
4ae388
 .SH "blacklist section"
4ae388
 The
4ae388
@@ -678,6 +682,8 @@ section:
4ae388
 .B delay_wait_checks
4ae388
 .TP
4ae388
 .B skip_kpartx
4ae388
+.TP
4ae388
+.B max_sectors_kb
4ae388
 .RE
4ae388
 .PD
4ae388
 .LP
4ae388
@@ -778,6 +784,8 @@ section:
4ae388
 .B delay_wait_checks
4ae388
 .TP
4ae388
 .B skip_kpartx
4ae388
+.TP
4ae388
+.B max_sectors_kb
4ae388
 .RE
4ae388
 .PD
4ae388
 .LP
4ae388
Index: multipath-tools-130222/libmultipath/devmapper.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/devmapper.c
4ae388
+++ multipath-tools-130222/libmultipath/devmapper.c
4ae388
@@ -21,7 +21,7 @@
4ae388
 #include "devmapper.h"
4ae388
 #include "config.h"
4ae388
 #include "sysfs.h"
4ae388
-
4ae388
+#include "discovery.h"
4ae388
 #include "log_pthread.h"
4ae388
 #include <sys/types.h>
4ae388
 #include <time.h>
4ae388
@@ -330,6 +330,7 @@ extern int
4ae388
 dm_addmap_create (struct multipath *mpp, char * params) {
4ae388
 	int ro;
4ae388
 
4ae388
+	sysfs_set_max_sectors_kb(mpp, 0);
4ae388
 	for (ro = 0; ro <= 1; ro++) {
4ae388
 		int err;
4ae388
 
4ae388
@@ -356,6 +357,7 @@ dm_addmap_create (struct multipath *mpp,
4ae388
 
4ae388
 extern int
4ae388
 dm_addmap_reload (struct multipath *mpp, char *params) {
4ae388
+	sysfs_set_max_sectors_kb(mpp, 1);
4ae388
 	if (dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW, SKIP_KPARTX_OFF))
4ae388
 		return 1;
4ae388
 	if (errno != EROFS)