trace-cmd record: Have -d only touch the instance its for

The -d option for trace-cmd record disables the function tracing option.
It currently only does it for the top level, which does not affect the
instances. It should only disable the instances it is for and not touch
the top level if the top level is not part of the command line.

Also have set_ftrace return the result of set_ftrace_proc() if it was
called.

Link: https://lore.kernel.org/linux-trace-devel/20210407175427.536f0423@gandalf.local.home

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index f8d6e6f..6b608ad 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -829,13 +829,14 @@
 	return ret;
 }
 
-static int set_ftrace(int set, int use_proc)
+static int set_ftrace(struct buffer_instance *instance, int set, int use_proc)
 {
 	char *path;
 	int ret;
 
-	/* First check if the function-trace option exists */
-	path = tracefs_get_tracing_file("options/function-trace");
+	path = tracefs_instance_get_file(instance->tracefs, "options/function-trace");
+	if (!path)
+		return -1;
 	ret = set_ftrace_enable(path, set);
 	tracefs_put_tracing_file(path);
 
@@ -843,7 +844,7 @@
 	if (ret < 0 || set || use_proc)
 		ret = set_ftrace_proc(set);
 
-	return 0;
+	return ret;
 }
 
 static int write_file(const char *file, const char *str)
@@ -6601,7 +6602,7 @@
 	page_size = getpagesize();
 
 	if (!is_guest(ctx->instance))
-		fset = set_ftrace(!ctx->disable, ctx->total_disable);
+		fset = set_ftrace(ctx->instance, !ctx->disable, ctx->total_disable);
 	if (!IS_CMDSET(ctx))
 		tracecmd_disable_all_tracing(1);