From: Hannes Reinecke <hare@suse.de>
To: Christophe Varoqui <christophe.varoqui@gmail.com>
Cc: dm-devel@redhat.com, Petr Uzel <petr.uzel@suse.cz>
Subject: [PATCH 05/42] prio: fix merging of prioritizers with different args
Date: Tue, 8 Jan 2013 14:53:43 +0100 [thread overview]
Message-ID: <1357653259-62650-6-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1357653259-62650-1-git-send-email-hare@suse.de>
From: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
libmultipath/discovery.c | 12 ++++---
libmultipath/prio.c | 49 +++++++++++++++++++++++++++++-
libmultipath/prio.h | 9 +++++-
libmultipath/prioritizers/alua.c | 1 +
libmultipath/prioritizers/datacore.c | 1 +
libmultipath/prioritizers/emc.c | 1 +
libmultipath/prioritizers/hds.c | 1 +
libmultipath/prioritizers/hp_sw.c | 1 +
libmultipath/prioritizers/ontap.c | 1 +
libmultipath/prioritizers/rdac.c | 1 +
libmultipath/prioritizers/weightedpath.c | 6 +++-
libmultipath/propsel.c | 15 ++++-----
libmultipath/structs.c | 3 ++
libmultipath/structs.h | 6 +++-
libmultipath/structs_vec.c | 2 +-
15 files changed, 90 insertions(+), 19 deletions(-)
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 33e44b6..6f5470f 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -777,21 +777,23 @@ get_prio (struct path * pp)
if (!pp)
return 0;
- if (!pp->prio) {
+ struct prio * p = &pp->prio;
+
+ if (!prio_selected(p)) {
select_prio(pp);
- if (!pp->prio) {
+ if (!prio_selected(p)) {
condlog(3, "%s: no prio selected", pp->dev);
return 1;
}
}
- pp->priority = prio_getprio(pp->prio, pp);
+ pp->priority = prio_getprio(p, pp);
if (pp->priority < 0) {
- condlog(3, "%s: %s prio error", pp->dev, prio_name(pp->prio));
+ condlog(3, "%s: %s prio error", pp->dev, prio_name(p));
pp->priority = PRIO_UNDEF;
return 1;
}
condlog(3, "%s: %s prio = %u",
- pp->dev, prio_name(pp->prio), pp->priority);
+ pp->dev, prio_name(p), pp->priority);
return 0;
}
diff --git a/libmultipath/prio.c b/libmultipath/prio.c
index 61c19b7..cf97fad 100644
--- a/libmultipath/prio.c
+++ b/libmultipath/prio.c
@@ -22,13 +22,23 @@ static struct prio * alloc_prio (void)
struct prio *p;
p = MALLOC(sizeof(struct prio));
- if (p)
+ if (p) {
INIT_LIST_HEAD(&p->node);
+ p->refcount = 1;
+ }
return p;
}
void free_prio (struct prio * p)
{
+ if (!p)
+ return;
+ p->refcount--;
+ if (p->refcount) {
+ condlog(3, "%s prioritizer refcount %d",
+ p->name, p->refcount);
+ return;
+ }
condlog(3, "unloading %s prioritizer", p->name);
list_del(&p->node);
if (p->handle) {
@@ -110,6 +120,13 @@ int prio_getprio (struct prio * p, struct path * pp)
return p->getprio(pp, p->args);
}
+int prio_selected (struct prio * p)
+{
+ if (!p || !p->getprio)
+ return 0;
+ return (p->getprio) ? 1 : 0;
+}
+
char * prio_name (struct prio * p)
{
return p->name;
@@ -119,3 +136,33 @@ char * prio_args (struct prio * p)
{
return p->args;
}
+
+void prio_get (struct prio * dst, char * name, char * args)
+{
+ struct prio * src = prio_lookup(name);
+
+ if (!src) {
+ dst->getprio = NULL;
+ return;
+ }
+
+ strncpy(dst->name, src->name, PRIO_NAME_LEN);
+ if (args)
+ strncpy(dst->args, args, PRIO_ARGS_LEN);
+ dst->getprio = src->getprio;
+ dst->handle = NULL;
+
+ src->refcount++;
+}
+
+void prio_put (struct prio * dst)
+{
+ struct prio * src;
+
+ if (!dst)
+ return;
+
+ src = prio_lookup(dst->name);
+ memset(dst, 0x0, sizeof(struct prio));
+ free_prio(src);
+}
diff --git a/libmultipath/prio.h b/libmultipath/prio.h
index 36929fb..4eeb216 100644
--- a/libmultipath/prio.h
+++ b/libmultipath/prio.h
@@ -6,7 +6,10 @@
*/
#include "checkers.h"
#include "vector.h"
-#include "structs.h"
+
+/* forward declaration to avoid circular dependency */
+struct path;
+
#include "list.h"
#include "memory.h"
@@ -41,6 +44,7 @@
struct prio {
void *handle;
+ int refcount;
struct list_head node;
char name[PRIO_NAME_LEN];
char args[PRIO_ARGS_LEN];
@@ -52,6 +56,9 @@ void cleanup_prio (void);
struct prio * add_prio (char *);
struct prio * prio_lookup (char *);
int prio_getprio (struct prio *, struct path *);
+void prio_get (struct prio *, char *, char *);
+void prio_put (struct prio *);
+int prio_selected (struct prio *);
char * prio_name (struct prio *);
char * prio_args (struct prio *);
int prio_set_args (struct prio *, char *);
diff --git a/libmultipath/prioritizers/alua.c b/libmultipath/prioritizers/alua.c
index 4da3ee7..b9493a4 100644
--- a/libmultipath/prioritizers/alua.c
+++ b/libmultipath/prioritizers/alua.c
@@ -16,6 +16,7 @@
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#include "alua.h"
diff --git a/libmultipath/prioritizers/datacore.c b/libmultipath/prioritizers/datacore.c
index 2c16c6c..e3e6a51 100644
--- a/libmultipath/prioritizers/datacore.c
+++ b/libmultipath/prioritizers/datacore.c
@@ -24,6 +24,7 @@
#include <sg_include.h>
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#define INQ_REPLY_LEN 255
#define INQ_CMD_CODE 0x12
diff --git a/libmultipath/prioritizers/emc.c b/libmultipath/prioritizers/emc.c
index 20d727e..87e9a8d 100644
--- a/libmultipath/prioritizers/emc.c
+++ b/libmultipath/prioritizers/emc.c
@@ -5,6 +5,7 @@
#include <sg_include.h>
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#define INQUIRY_CMD 0x12
#define INQUIRY_CMDLEN 6
diff --git a/libmultipath/prioritizers/hds.c b/libmultipath/prioritizers/hds.c
index 4789340..b22e1df 100644
--- a/libmultipath/prioritizers/hds.c
+++ b/libmultipath/prioritizers/hds.c
@@ -75,6 +75,7 @@
#include <sg_include.h>
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#define INQ_REPLY_LEN 255
#define INQ_CMD_CODE 0x12
diff --git a/libmultipath/prioritizers/hp_sw.c b/libmultipath/prioritizers/hp_sw.c
index 2de460f..c24baad 100644
--- a/libmultipath/prioritizers/hp_sw.c
+++ b/libmultipath/prioritizers/hp_sw.c
@@ -15,6 +15,7 @@
#include <sg_include.h>
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#define TUR_CMD_LEN 6
#define SCSI_CHECK_CONDITION 0x2
diff --git a/libmultipath/prioritizers/ontap.c b/libmultipath/prioritizers/ontap.c
index 6e6e3d3..0d34092 100644
--- a/libmultipath/prioritizers/ontap.c
+++ b/libmultipath/prioritizers/ontap.c
@@ -22,6 +22,7 @@
#include <sg_include.h>
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#define INQUIRY_CMD 0x12
#define INQUIRY_CMDLEN 6
diff --git a/libmultipath/prioritizers/rdac.c b/libmultipath/prioritizers/rdac.c
index 41ea887..8667790 100644
--- a/libmultipath/prioritizers/rdac.c
+++ b/libmultipath/prioritizers/rdac.c
@@ -5,6 +5,7 @@
#include <sg_include.h>
#include <debug.h>
#include <prio.h>
+#include <structs.h>
#define INQUIRY_CMD 0x12
#define INQUIRY_CMDLEN 6
diff --git a/libmultipath/prioritizers/weightedpath.c b/libmultipath/prioritizers/weightedpath.c
index d6c81f0..54c9039 100644
--- a/libmultipath/prioritizers/weightedpath.c
+++ b/libmultipath/prioritizers/weightedpath.c
@@ -60,6 +60,10 @@ int prio_path_weight(struct path *pp, char *prio_args)
regex = get_next_string(&temp, split_char);
+ /* Return default priority if the argument is not parseable */
+ if (!regex)
+ return priority;
+
if (!strcmp(regex, HBTL)) {
sprintf(path, "%d:%d:%d:%d", pp->sg_id.host_no,
pp->sg_id.channel, pp->sg_id.scsi_id, pp->sg_id.lun);
@@ -67,7 +71,7 @@ int prio_path_weight(struct path *pp, char *prio_args)
strcpy(path, pp->dev);
} else {
condlog(0, "%s: %s - Invalid arguments", pp->dev,
- pp->prio->name);
+ pp->prio.name);
return priority;
}
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
index 6ac4caa..17bd893 100644
--- a/libmultipath/propsel.c
+++ b/libmultipath/propsel.c
@@ -383,20 +383,19 @@ extern int
select_prio (struct path * pp)
{
struct mpentry * mpe;
+ struct prio * p = &pp->prio;
if ((mpe = find_mpe(pp->wwid))) {
if (mpe->prio_name) {
- pp->prio = prio_lookup(mpe->prio_name);
- prio_set_args(pp->prio, mpe->prio_args);
+ prio_get(p, mpe->prio_name, mpe->prio_args);
condlog(3, "%s: prio = %s (LUN setting)",
- pp->dev, pp->prio->name);
+ pp->dev, prio_name(p));
return 0;
}
}
if (pp->hwe && pp->hwe->prio_name) {
- pp->prio = prio_lookup(pp->hwe->prio_name);
- prio_set_args(pp->prio, pp->hwe->prio_args);
+ prio_get(p, pp->hwe->prio_name, pp->hwe->prio_name);
condlog(3, "%s: prio = %s (controller setting)",
pp->dev, pp->hwe->prio_name);
condlog(3, "%s: prio args = %s (controller setting)",
@@ -404,16 +403,14 @@ select_prio (struct path * pp)
return 0;
}
if (conf->prio_name) {
- pp->prio = prio_lookup(conf->prio_name);
- prio_set_args(pp->prio, conf->prio_args);
+ prio_get(p, conf->prio_name, conf->prio_args);
condlog(3, "%s: prio = %s (config file default)",
pp->dev, conf->prio_name);
condlog(3, "%s: prio args = %s (config file default)",
pp->dev, conf->prio_args);
return 0;
}
- pp->prio = prio_lookup(DEFAULT_PRIO);
- prio_set_args(pp->prio, DEFAULT_PRIO_ARGS);
+ prio_get(p, DEFAULT_PRIO, DEFAULT_PRIO_ARGS);
condlog(3, "%s: prio = %s (internal default)",
pp->dev, DEFAULT_PRIO);
condlog(3, "%s: prio = %s (internal default)",
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index 3c0fe90..ab57559 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -45,6 +45,9 @@ free_path (struct path * pp)
if (checker_selected(&pp->checker))
checker_put(&pp->checker);
+ if (prio_selected(&pp->prio))
+ prio_put(&pp->prio);
+
if (pp->fd >= 0)
close(pp->fd);
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
index 991ea6e..312014b 100644
--- a/libmultipath/structs.h
+++ b/libmultipath/structs.h
@@ -3,6 +3,8 @@
#include <sys/types.h>
+#include "prio.h"
+
#define WWID_SIZE 128
#define SERIAL_SIZE 65
#define NODE_NAME_SIZE 224
@@ -132,6 +134,7 @@ struct hd_geometry {
unsigned long start;
};
#endif
+
struct path {
char dev[FILE_NAME_SIZE];
char dev_t[BLK_DEV_SIZE];
@@ -157,7 +160,8 @@ struct path {
int priority;
int pgindex;
char * uid_attribute;
- struct prio * prio;
+ struct prio prio;
+ char * prio_args;
struct checker checker;
struct multipath * mpp;
int fd;
diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c
index f998708..d914435 100644
--- a/libmultipath/structs_vec.c
+++ b/libmultipath/structs_vec.c
@@ -82,7 +82,7 @@ orphan_path (struct path * pp)
pp->mpp = NULL;
pp->dmstate = PSTATE_UNDEF;
pp->uid_attribute = NULL;
- pp->prio = NULL;
+ prio_put(&pp->prio);
checker_put(&pp->checker);
if (pp->fd >= 0)
close(pp->fd);
--
1.7.4.2
next prev parent reply other threads:[~2013-01-08 13:53 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-08 13:53 [PATCH 00/42] SLES resync Hannes Reinecke
2013-01-08 13:53 ` [PATCH 01/42] libmultipath: Invalid check for mpp->wwid in dm_addmap() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 02/42] Remove newline from condlog() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 03/42] Fixup pathgroup allocation in disassemble_map() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 04/42] libmultipath: resource leak in read_value_block() Hannes Reinecke
2013-01-08 13:53 ` Hannes Reinecke [this message]
2013-01-08 13:53 ` [PATCH 06/42] Accept several whitespaces in bindings file Hannes Reinecke
2013-01-08 13:53 ` [PATCH 07/42] Add TAGS makefile target Hannes Reinecke
2013-01-08 13:53 ` [PATCH 08/42] libmultipath: Fix typo in mp_prio_handler() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 09/42] Do not trigger a map reload on priority updates Hannes Reinecke
2013-01-08 13:53 ` [PATCH 10/42] Introduce MP_FAST_IO_FAIL_UNSET Hannes Reinecke
2013-01-08 13:53 ` [PATCH 11/42] Checker name is not displayed on failure Hannes Reinecke
2013-01-08 13:53 ` [PATCH 12/42] Valgrind fixes for prioritizer Hannes Reinecke
2013-01-08 13:53 ` [PATCH 13/42] Incorrect inquiry vendor length in hds prioritizer Hannes Reinecke
2013-01-08 13:53 ` [PATCH 14/42] Print out multipath alias for flush_on_last_del messages Hannes Reinecke
2013-01-08 13:53 ` [PATCH 15/42] Clarify setting origin in propsel.c Hannes Reinecke
2013-01-08 13:53 ` [PATCH 16/42] libmultipath: error checking in remove_features() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 17/42] Increase parameter buffer Hannes Reinecke
2013-01-08 13:53 ` [PATCH 18/42] Check return code from pathinfo() Hannes Reinecke
2013-01-08 13:53 ` [PATCH 19/42] Inconsistent string quoting Hannes Reinecke
2013-01-08 13:53 ` [PATCH 20/42] Switch off 'queue_if_no_path' before removing maps Hannes Reinecke
2013-01-08 13:53 ` [PATCH 21/42] Double free in disassemble_map() Hannes Reinecke
2013-01-08 13:54 ` [PATCH 22/42] libmultipath: prio keyword ignored for multipath config Hannes Reinecke
2013-01-08 13:54 ` [PATCH 23/42] Path checker should return PATH_DOWN when no path is found Hannes Reinecke
2013-01-08 13:54 ` [PATCH 24/42] Do not call sysfs_get_timeout for non-SCSI devices Hannes Reinecke
2013-01-08 13:54 ` [PATCH 25/42] Make log_pthread more robust Hannes Reinecke
2013-01-09 0:16 ` Christophe Varoqui
2013-01-09 19:15 ` Xose Vazquez Perez
2013-01-08 13:54 ` [PATCH 26/42] Print log messages when updating tables failed Hannes Reinecke
2013-01-08 13:54 ` [PATCH 27/42] Update 'no_path_retry' correctly for failed paths Hannes Reinecke
2013-01-08 13:54 ` [PATCH 28/42] Clean up uevent queue on shutdown Hannes Reinecke
2013-01-08 13:54 ` [PATCH 29/42] libmultipath: Print out uevent sequence number Hannes Reinecke
2013-01-08 13:54 ` [PATCH 30/42] Fix race condition in stop_waiter_thread() Hannes Reinecke
2013-01-08 13:54 ` [PATCH 31/42] Use VECTOR_SIZE() defines Hannes Reinecke
2013-01-08 13:54 ` [PATCH 32/42] Make 'allocated' an integer in vector.h Hannes Reinecke
2013-01-08 13:54 ` [PATCH 33/42] Syntax error in /etc/init.d/boot.multipath Hannes Reinecke
2013-01-08 13:54 ` [PATCH 34/42] multipath.init.suse: Update usage message Hannes Reinecke
2013-01-08 13:54 ` [PATCH 35/42] multipath.conf.5: Clarify dev_loss_tmo settings Hannes Reinecke
2013-01-08 13:54 ` [PATCH 36/42] Clarify dev_loss_tmo capping in multipath.conf.5 Hannes Reinecke
2013-01-08 13:54 ` [PATCH 38/42] multipathd: Ignore errors when creating pidfile Hannes Reinecke
2013-01-08 13:54 ` [PATCH 39/42] multipathd deadlocks during restart Hannes Reinecke
2013-01-08 13:54 ` [PATCH 40/42] multipathd: sighandlers might use uninitialized gvecs Hannes Reinecke
2013-01-08 13:54 ` [PATCH 41/42] multipathd: crash in reconfigure CLI command Hannes Reinecke
2013-01-08 13:54 ` [PATCH 42/42] multipathd: lock vectors during initial configuration Hannes Reinecke
2013-01-08 23:37 ` Christophe Varoqui
2013-01-09 7:01 ` Hannes Reinecke
2013-01-08 23:53 ` [PATCH 00/42] SLES resync Christophe Varoqui
2013-01-10 5:36 ` Benjamin Marzinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357653259-62650-6-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=christophe.varoqui@gmail.com \
--cc=dm-devel@redhat.com \
--cc=petr.uzel@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox