[for-next][PATCH 21/33] ftrace: Add helper function ftrace_hash_move_and_update_ops()

2017-04-21 Thread Steven Rostedt
From: "Steven Rostedt (VMware)" 

The processes of updating a ops filter_hash is a bit complex, and requires
setting up an old hash to perform the update. This is done exactly the same
in two locations for the same reasons. Create a helper function that does it
in one place.

Signed-off-by: Steven Rostedt (VMware) 
---
 kernel/trace/ftrace.c | 105 +-
 1 file changed, 53 insertions(+), 52 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index f7fcab8f3aa1..5c8d8eea9e7c 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -3674,6 +3674,56 @@ ftrace_match_records(struct ftrace_hash *hash, char 
*buff, int len)
return match_records(hash, buff, len, NULL);
 }
 
+static void ftrace_ops_update_code(struct ftrace_ops *ops,
+  struct ftrace_ops_hash *old_hash)
+{
+   struct ftrace_ops *op;
+
+   if (!ftrace_enabled)
+   return;
+
+   if (ops->flags & FTRACE_OPS_FL_ENABLED) {
+   ftrace_run_modify_code(ops, FTRACE_UPDATE_CALLS, old_hash);
+   return;
+   }
+
+   /*
+* If this is the shared global_ops filter, then we need to
+* check if there is another ops that shares it, is enabled.
+* If so, we still need to run the modify code.
+*/
+   if (ops->func_hash != _ops.local_hash)
+   return;
+
+   do_for_each_ftrace_op(op, ftrace_ops_list) {
+   if (op->func_hash == _ops.local_hash &&
+   op->flags & FTRACE_OPS_FL_ENABLED) {
+   ftrace_run_modify_code(op, FTRACE_UPDATE_CALLS, 
old_hash);
+   /* Only need to do this once */
+   return;
+   }
+   } while_for_each_ftrace_op(op);
+}
+
+static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops,
+  struct ftrace_hash **orig_hash,
+  struct ftrace_hash *hash,
+  int enable)
+{
+   struct ftrace_ops_hash old_hash_ops;
+   struct ftrace_hash *old_hash;
+   int ret;
+
+   old_hash = *orig_hash;
+   old_hash_ops.filter_hash = ops->func_hash->filter_hash;
+   old_hash_ops.notrace_hash = ops->func_hash->notrace_hash;
+   ret = ftrace_hash_move(ops, enable, orig_hash, hash);
+   if (!ret) {
+   ftrace_ops_update_code(ops, _hash_ops);
+   free_ftrace_hash_rcu(old_hash);
+   }
+   return ret;
+}
 
 /*
  * We register the module command as a template to show others how
@@ -4306,44 +4356,11 @@ ftrace_match_addr(struct ftrace_hash *hash, unsigned 
long ip, int remove)
return add_hash_entry(hash, ip);
 }
 
-static void ftrace_ops_update_code(struct ftrace_ops *ops,
-  struct ftrace_ops_hash *old_hash)
-{
-   struct ftrace_ops *op;
-
-   if (!ftrace_enabled)
-   return;
-
-   if (ops->flags & FTRACE_OPS_FL_ENABLED) {
-   ftrace_run_modify_code(ops, FTRACE_UPDATE_CALLS, old_hash);
-   return;
-   }
-
-   /*
-* If this is the shared global_ops filter, then we need to
-* check if there is another ops that shares it, is enabled.
-* If so, we still need to run the modify code.
-*/
-   if (ops->func_hash != _ops.local_hash)
-   return;
-
-   do_for_each_ftrace_op(op, ftrace_ops_list) {
-   if (op->func_hash == _ops.local_hash &&
-   op->flags & FTRACE_OPS_FL_ENABLED) {
-   ftrace_run_modify_code(op, FTRACE_UPDATE_CALLS, 
old_hash);
-   /* Only need to do this once */
-   return;
-   }
-   } while_for_each_ftrace_op(op);
-}
-
 static int
 ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
unsigned long ip, int remove, int reset, int enable)
 {
struct ftrace_hash **orig_hash;
-   struct ftrace_ops_hash old_hash_ops;
-   struct ftrace_hash *old_hash;
struct ftrace_hash *hash;
int ret;
 
@@ -4378,14 +4395,7 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char 
*buf, int len,
}
 
mutex_lock(_lock);
-   old_hash = *orig_hash;
-   old_hash_ops.filter_hash = ops->func_hash->filter_hash;
-   old_hash_ops.notrace_hash = ops->func_hash->notrace_hash;
-   ret = ftrace_hash_move(ops, enable, orig_hash, hash);
-   if (!ret) {
-   ftrace_ops_update_code(ops, _hash_ops);
-   free_ftrace_hash_rcu(old_hash);
-   }
+   ret = ftrace_hash_move_and_update_ops(ops, orig_hash, hash, enable);
mutex_unlock(_lock);
 
  out_regex_unlock:
@@ -4624,10 +4634,8 @@ static void __init set_ftrace_early_filters(void)
 int ftrace_regex_release(struct inode *inode, struct file 

[for-next][PATCH 21/33] ftrace: Add helper function ftrace_hash_move_and_update_ops()

2017-04-21 Thread Steven Rostedt
From: "Steven Rostedt (VMware)" 

The processes of updating a ops filter_hash is a bit complex, and requires
setting up an old hash to perform the update. This is done exactly the same
in two locations for the same reasons. Create a helper function that does it
in one place.

Signed-off-by: Steven Rostedt (VMware) 
---
 kernel/trace/ftrace.c | 105 +-
 1 file changed, 53 insertions(+), 52 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index f7fcab8f3aa1..5c8d8eea9e7c 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -3674,6 +3674,56 @@ ftrace_match_records(struct ftrace_hash *hash, char 
*buff, int len)
return match_records(hash, buff, len, NULL);
 }
 
+static void ftrace_ops_update_code(struct ftrace_ops *ops,
+  struct ftrace_ops_hash *old_hash)
+{
+   struct ftrace_ops *op;
+
+   if (!ftrace_enabled)
+   return;
+
+   if (ops->flags & FTRACE_OPS_FL_ENABLED) {
+   ftrace_run_modify_code(ops, FTRACE_UPDATE_CALLS, old_hash);
+   return;
+   }
+
+   /*
+* If this is the shared global_ops filter, then we need to
+* check if there is another ops that shares it, is enabled.
+* If so, we still need to run the modify code.
+*/
+   if (ops->func_hash != _ops.local_hash)
+   return;
+
+   do_for_each_ftrace_op(op, ftrace_ops_list) {
+   if (op->func_hash == _ops.local_hash &&
+   op->flags & FTRACE_OPS_FL_ENABLED) {
+   ftrace_run_modify_code(op, FTRACE_UPDATE_CALLS, 
old_hash);
+   /* Only need to do this once */
+   return;
+   }
+   } while_for_each_ftrace_op(op);
+}
+
+static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops,
+  struct ftrace_hash **orig_hash,
+  struct ftrace_hash *hash,
+  int enable)
+{
+   struct ftrace_ops_hash old_hash_ops;
+   struct ftrace_hash *old_hash;
+   int ret;
+
+   old_hash = *orig_hash;
+   old_hash_ops.filter_hash = ops->func_hash->filter_hash;
+   old_hash_ops.notrace_hash = ops->func_hash->notrace_hash;
+   ret = ftrace_hash_move(ops, enable, orig_hash, hash);
+   if (!ret) {
+   ftrace_ops_update_code(ops, _hash_ops);
+   free_ftrace_hash_rcu(old_hash);
+   }
+   return ret;
+}
 
 /*
  * We register the module command as a template to show others how
@@ -4306,44 +4356,11 @@ ftrace_match_addr(struct ftrace_hash *hash, unsigned 
long ip, int remove)
return add_hash_entry(hash, ip);
 }
 
-static void ftrace_ops_update_code(struct ftrace_ops *ops,
-  struct ftrace_ops_hash *old_hash)
-{
-   struct ftrace_ops *op;
-
-   if (!ftrace_enabled)
-   return;
-
-   if (ops->flags & FTRACE_OPS_FL_ENABLED) {
-   ftrace_run_modify_code(ops, FTRACE_UPDATE_CALLS, old_hash);
-   return;
-   }
-
-   /*
-* If this is the shared global_ops filter, then we need to
-* check if there is another ops that shares it, is enabled.
-* If so, we still need to run the modify code.
-*/
-   if (ops->func_hash != _ops.local_hash)
-   return;
-
-   do_for_each_ftrace_op(op, ftrace_ops_list) {
-   if (op->func_hash == _ops.local_hash &&
-   op->flags & FTRACE_OPS_FL_ENABLED) {
-   ftrace_run_modify_code(op, FTRACE_UPDATE_CALLS, 
old_hash);
-   /* Only need to do this once */
-   return;
-   }
-   } while_for_each_ftrace_op(op);
-}
-
 static int
 ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
unsigned long ip, int remove, int reset, int enable)
 {
struct ftrace_hash **orig_hash;
-   struct ftrace_ops_hash old_hash_ops;
-   struct ftrace_hash *old_hash;
struct ftrace_hash *hash;
int ret;
 
@@ -4378,14 +4395,7 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char 
*buf, int len,
}
 
mutex_lock(_lock);
-   old_hash = *orig_hash;
-   old_hash_ops.filter_hash = ops->func_hash->filter_hash;
-   old_hash_ops.notrace_hash = ops->func_hash->notrace_hash;
-   ret = ftrace_hash_move(ops, enable, orig_hash, hash);
-   if (!ret) {
-   ftrace_ops_update_code(ops, _hash_ops);
-   free_ftrace_hash_rcu(old_hash);
-   }
+   ret = ftrace_hash_move_and_update_ops(ops, orig_hash, hash, enable);
mutex_unlock(_lock);
 
  out_regex_unlock:
@@ -4624,10 +4634,8 @@ static void __init set_ftrace_early_filters(void)
 int ftrace_regex_release(struct inode *inode, struct file *file)
 {
struct seq_file *m = (struct