From: Li Zefan <lizf@cn.fujitsu.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, acme@redhat.com, hpa@zytor.com,
mingo@redhat.com, lizf@cn.fujitsu.com, jens.axboe@oracle.com,
fweisbec@gmail.com, rostedt@goodmis.org, tglx@linutronix.de,
mingo@elte.hu
Subject: [tip:tracing/blktrace] blktrace: fix blk_probes_ref chaos
Date: Mon, 30 Mar 2009 01:19:41 GMT [thread overview]
Message-ID: <tip-e465dbcc55d36b37af55d95a279f352a3f517279@git.kernel.org> (raw)
In-Reply-To: <49CC37D9.6030201@cn.fujitsu.com>
Commit-ID: e465dbcc55d36b37af55d95a279f352a3f517279
Gitweb: http://git.kernel.org/tip/e465dbcc55d36b37af55d95a279f352a3f517279
Author: Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Fri, 27 Mar 2009 10:20:09 +0800
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 30 Mar 2009 03:15:50 +0200
blktrace: fix blk_probes_ref chaos
Impact: fix mixed ioctl and ftrace-plugin blktrace use refcount bugs
ioctl-based blktrace allocates bt and registers tracepoints when
ioctl(BLKTRACESETUP), and do all cleanups when ioctl(BLKTRACETEARDOWN).
while ftrace-based blktrace allocates/frees bt when:
# echo 1/0 > /sys/block/sda/sda1/trace/enable
and registers/unregisters tracepoints when:
# echo blk/nop > /debugfs/tracing/current_tracer
or
# echo 1/0 > /debugfs/tracing/tracing_enable
The separatation of allocation and registeration causes 2 problems:
1. current user-space blktrace still calls ioctl(TEARDOWN) when
ioctl(SETUP) failed:
# echo 1 > /sys/block/sda/sda1/trace/enable
# blktrace /dev/sda
BLKTRACESETUP: Device or resource busy
^C
and now blk_probes_ref == -1
2. Another way to make blk_probes_ref == -1:
# plugin sdb && mount sdb1
# echo 1 > /sys/block/sdb/sdb1/trace/enable
# remove sdb
This patch does the allocation and registeration when writing
sdaX/trace/enable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <49CC37D9.6030201@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/trace/blktrace.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 5b28f0f..8d6bd12 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -478,7 +478,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
goto err;
}
- if (atomic_add_return(1, &blk_probes_ref) == 1)
+ if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
return 0;
@@ -1091,8 +1091,6 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- if (atomic_add_return(1, &blk_probes_ref) == 1)
- blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1107,15 +1105,10 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
}
static void blk_tracer_reset(struct trace_array *tr)
{
- if (!atomic_read(&blk_probes_ref))
- return;
-
blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1254,6 +1247,9 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (bt == NULL)
return -EINVAL;
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+
kfree(bt);
return 0;
}
@@ -1280,6 +1276,9 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
return -EBUSY;
}
+ if (atomic_inc_return(&blk_probes_ref) == 1)
+ blk_register_tracepoints();
+
return 0;
}
next prev parent reply other threads:[~2009-03-30 1:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-27 2:19 [PATCH 0/6] blktrace: last round of fixes Li Zefan
2009-03-27 2:19 ` [PATCH 1/6] blktrace: make classic output more classic Li Zefan
2009-03-27 3:30 ` Li Zefan
2009-03-28 21:27 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:20 ` [PATCH 2/6] blktrace: fix blk_probes_ref chaos Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan [this message]
2009-03-27 2:20 ` [PATCH 3/6] blktrace: fix memory leak when freeing struct blk_io_trace Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:19 ` Li Zefan
2009-03-27 2:21 ` [PATCH 4/6] trace: make argument 'mem' of trace_seq_putmem() const Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
2009-03-27 2:21 ` [PATCH 5/6] blktrace: extract duplidate code Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
2009-03-27 2:21 ` [PATCH 6/6] blktrace: print out BLK_TN_MESSAGE properly Li Zefan
2009-03-28 21:28 ` [tip:tracing/blktrace] " Li Zefan
2009-03-30 1:20 ` Li Zefan
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=tip-e465dbcc55d36b37af55d95a279f352a3f517279@git.kernel.org \
--to=lizf@cn.fujitsu.com \
--cc=acme@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=jens.axboe@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.