From: Neil Horman <nhorman@tuxdriver.com>
Subject: irqbalance: separate cmomand line banned irqs from listed banned irqs
References: bnc#968711
Patch-Mainline: v1.0.8
Git-commit: 7f072d94c93174d30eb18426ee8f8727a9081c40
Git-repo: github.com/Irqbalance/irqbalance.git

Signed-off-by: Thomas Renninger <trenn@suse.de>

irqbalance was using one list for tracking banned irqs, but the list was being
used for disperate pruposes in different places.  It was tracking command line
banned irqs and irqs that were banned via banscript and policyscript.  The
former needs to be remembered accross db rebuilds, while the latter needs to be
rebuilt every time.  This patch separates the two in to two lists, so that we
don't stop banning command line specified irqs after the first db rebuild.

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>

Index: irqbalance-1.0.7/classify.c
===================================================================
--- irqbalance-1.0.7.orig/classify.c	2013-10-10 17:05:42.000000000 +0200
+++ irqbalance-1.0.7/classify.c	2016-04-06 11:21:10.792711465 +0200
@@ -59,8 +59,9 @@ struct user_irq_policy {
 	int numa_node;
 };
 
-static GList *interrupts_db;
-static GList *banned_irqs;
+static GList *interrupts_db = NULL;
+static GList *banned_irqs = NULL;
+static GList *cl_banned_irqs = NULL;
 
 #define SYSDEV_DIR "/sys/bus/pci/devices"
 
@@ -72,13 +73,13 @@ static gint compare_ints(gconstpointer a
 	return ai->irq - bi->irq;
 }
 
-void add_banned_irq(int irq)
+void add_banned_irq(int irq, GList **list)
 {
 	struct irq_info find, *new;
 	GList *entry;
 
 	find.irq = irq;
-	entry = g_list_find_custom(banned_irqs, &find, compare_ints);
+	entry = g_list_find_custom(*list, &find, compare_ints);
 	if (entry)
 		return;
 
@@ -91,10 +92,16 @@ void add_banned_irq(int irq)
 	new->irq = irq;
 	new->flags |= IRQ_FLAG_BANNED;
 
-	banned_irqs = g_list_append(banned_irqs, new);
+	*list = g_list_append(*list, new);
 	return;
 }
 
+void add_cl_banned_irq(int irq)
+{
+	add_banned_irq(irq, &cl_banned_irqs);
+}
+
+
 static int is_banned_irq(int irq)
 {
 	GList *entry;
@@ -324,10 +331,23 @@ static int check_for_irq_ban(char *path,
 {
 	char *cmd;
 	int rc;
+	struct irq_info find;
+	GList *entry;
+
+	/*
+	 * Check to see if we banned this irq on the command line
+	 */
+	find.irq = irq;
+	entry = g_list_find_custom(cl_banned_irqs, &find, compare_ints);
+	if (entry)
+		return 1;
 
 	if (!banscript)
 		return 0;
 
+	if (!path)
+		return 0;
+
 	cmd = alloca(strlen(path)+strlen(banscript)+32);
 	if (!cmd)
 		return 0;
@@ -382,7 +402,7 @@ static void build_one_dev_entry(const ch
 					continue;
 				get_irq_user_policy(devpath, irqnum, &pol);
 				if ((pol.ban == 1) || (check_for_irq_ban(devpath, irqnum))) {
-					add_banned_irq(irqnum);
+					add_banned_irq(irqnum, &banned_irqs);
 					continue;
 				}
 				new = add_one_irq_to_db(devpath, irqnum, &pol);
@@ -411,7 +431,7 @@ static void build_one_dev_entry(const ch
 			goto done;
 		get_irq_user_policy(devpath, irqnum, &pol);
 		if ((pol.ban == 1) || (check_for_irq_ban(path, irqnum))) {
-			add_banned_irq(irqnum);
+			add_banned_irq(irqnum, &banned_irqs);
 			goto done;
 		}
 
@@ -496,8 +516,8 @@ struct irq_info *add_new_irq(int irq, st
 		return NULL;
 
 	get_irq_user_policy("/sys", irq, &pol);
-	if (pol.ban == 1) {
-		add_banned_irq(irq);
+	if ((pol.ban == 1) || check_for_irq_ban(NULL, irq)) {
+		add_banned_irq(irq, &banned_irqs);
 		new = get_irq_info(irq);
 	} else
 		new = add_one_irq_to_db("/sys", irq, &pol);
Index: irqbalance-1.0.7/irqbalance.c
===================================================================
--- irqbalance-1.0.7.orig/irqbalance.c	2013-09-26 18:31:53.000000000 +0200
+++ irqbalance-1.0.7/irqbalance.c	2016-04-06 11:21:10.792711465 +0200
@@ -151,7 +151,7 @@ static void parse_command_line(int argc,
 					usage();
 					exit(1);
 				}
-				add_banned_irq((int)val);
+				add_cl_banned_irq((int)val);
 				break;
 			case 'l':
 				polscript = strdup(optarg);
Index: irqbalance-1.0.7/irqbalance.h
===================================================================
--- irqbalance-1.0.7.orig/irqbalance.h	2013-09-26 18:15:44.000000000 +0200
+++ irqbalance-1.0.7/irqbalance.h	2016-04-06 11:21:10.796711691 +0200
@@ -106,7 +106,7 @@ extern int get_cpu_count(void);
  */
 extern void rebuild_irq_db(void);
 extern void free_irq_db(void);
-extern void add_banned_irq(int irq);
+extern void add_cl_banned_irq(int irq);
 extern void for_each_irq(GList *list, void (*cb)(struct irq_info *info,  void *data), void *data);
 extern struct irq_info *get_irq_info(int irq);
 extern void migrate_irq(GList **from, GList **to, struct irq_info *info);
