public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] initscript: copy uprobes.ko to cache directory
  2014-08-08  6:33 [PATCH 0/2] initscript: add support for uprobes scripts Stefan Hajnoczi
  2014-08-08  6:33 ` [PATCH 2/2] initscript: allow scripts to load uprobes Stefan Hajnoczi
@ 2014-08-08  6:33 ` Stefan Hajnoczi
  2014-08-08  7:24 ` [PATCH 0/2] initscript: add support for uprobes scripts Masami Hiramatsu
  2014-08-08 17:21 ` Josh Stone
  3 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2014-08-08  6:33 UTC (permalink / raw)
  To: systemtap; +Cc: Frank Ch. Eigler, Josh Stone, Jonathan Lebon, Stefan Hajnoczi

If the uprobes.ko module was built then it will be needed at staprun
time.  Copy the module into the cache directory alongside compiled
scripts.

This patch uses the stap -k option to keep the temporary build directory
around.  The uprobes.ko module file can be found in there.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 initscript/systemtap.in | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/initscript/systemtap.in b/initscript/systemtap.in
index 2d770e4..7e9c680 100755
--- a/initscript/systemtap.in
+++ b/initscript/systemtap.in
@@ -457,7 +457,7 @@ prepare_stat_dir () {
 }
 
 compile_script () { # script checkcache
-  local opts f tmpdir ret
+  local opts f tmpdir ret stap_tmpdir
   eval f="$SCRIPT_PATH/$1.stp"
   if [ ! -f "$f" ]; then
     if [ $ALLOW_CACHEONLY -eq 1 ]; then
@@ -489,8 +489,19 @@ compile_script () { # script checkcache
     return 1
   fi
   pushd "$tmpdir" &> /dev/null
-  logex $STAP -m "$1" -p4 -r $KRELEASE $opts "$f"
+  log "Exec: $STAP -m \"$1\" -p4 -r $KRELEASE -k $opts \"$f\""
+  $STAP -m "$1" -p4 -r $KRELEASE -k $opts "$f" >stap.outerr 2>&1
   ret=$?
+  cat stap.outerr >> "$LOG_FILE"
+  stap_tmpdir=$(grep 'Keeping temporary directory' stap.outerr | \
+                sed 's/^Keeping temporary directory "\([^"]*\)"/\1/')
+  if [ $ret -eq 0 ]; then
+    if [ -f "$stap_tmpdir/uprobes/uprobes.ko" ]; then
+      logex mkdir -p "$CACHE_PATH/uprobes"
+      logex mv "$stap_tmpdir/uprobes/uprobes.ko" "$CACHE_PATH/uprobes/"
+      ret=$?
+    fi
+  fi
   if [ $ret -eq 0 ]; then
     $UNAME -a > "$1.opts"
     echo $opts >> "$1.opts"
@@ -500,6 +511,7 @@ compile_script () { # script checkcache
     slog "Failed to compile script($1)."
   fi
   popd &> /dev/null
+  [ -n "$stap_tmpdir" ] && rm -rf "$stap_tmpdir"
   rm -rf $tmpdir
   [ $ret -eq 0 ] && clog "done" || clog "error"
   return $ret
-- 
1.9.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/2] initscript: add support for uprobes scripts
@ 2014-08-08  6:33 Stefan Hajnoczi
  2014-08-08  6:33 ` [PATCH 2/2] initscript: allow scripts to load uprobes Stefan Hajnoczi
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2014-08-08  6:33 UTC (permalink / raw)
  To: systemtap; +Cc: Frank Ch. Eigler, Josh Stone, Jonathan Lebon, Stefan Hajnoczi

The initscript currently fails for user-space probing scripts on systems where
uprobes.ko is built from source by stap(1).  This is because the initscript
uses a two-phase "compile and then run" approach:

The uprobes.ko module is generated during the compile phase but not copied into
the cache directory where modules are placed for the run phase.  The staprun(8)
command fails because the script module cannot be loaded without uprobes.ko.

These patches address the issue by copying uprobes.ko into the cache directory.
If a script specifies the -u option in its initscript configuration file,
staprun(8) will receive the path to uprobes.ko.

There is no change in behavior on systems that do not build uprobes.ko.

Stefan Hajnoczi (2):
  initscript: copy uprobes.ko to cache directory
  initscript: allow scripts to load uprobes

 initscript/systemtap.in | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] initscript: allow scripts to load uprobes
  2014-08-08  6:33 [PATCH 0/2] initscript: add support for uprobes scripts Stefan Hajnoczi
@ 2014-08-08  6:33 ` Stefan Hajnoczi
  2014-08-08  6:33 ` [PATCH 1/2] initscript: copy uprobes.ko to cache directory Stefan Hajnoczi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2014-08-08  6:33 UTC (permalink / raw)
  To: systemtap; +Cc: Frank Ch. Eigler, Josh Stone, Jonathan Lebon, Stefan Hajnoczi

Scripts that rely on userspace probing must include the -u option in
their conf file:

  # cat /etc/systemtap/conf.d/example.conf
  example_OPT=-u

The uprobe kernel module will be loaded when the script runs.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 initscript/systemtap.in | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/initscript/systemtap.in b/initscript/systemtap.in
index 7e9c680..1e66694 100755
--- a/initscript/systemtap.in
+++ b/initscript/systemtap.in
@@ -401,7 +401,7 @@ get_compile_opts () { # opts
     case $o in
     -p|-m|-r|-c|-x|-e|-s|-o|-S)
        skip=1 ;;
-    -h|-V|-k|-F)
+    -h|-V|-k|-F|-u)
       ;;
     *)
       echo -n $o" " ;;
@@ -420,6 +420,12 @@ get_run_opts () { # normalized_opts
   show=0
   for o in $opts; do
     case $o in
+    -u)
+      # Use cached uprobes module, if available
+      if [ -f "$CACHE_PATH/uprobes/uprobes.ko" ]; then
+        echo -n "-u$CACHE_PATH/uprobes/uprobes.ko "
+      fi
+      ;;
     -c|-x|-s|-o|-S)
       [ $o == '-s' ] && o='-b'
       [ $o == '-o' ] && mode='-D'
-- 
1.9.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] initscript: add support for uprobes scripts
  2014-08-08  6:33 [PATCH 0/2] initscript: add support for uprobes scripts Stefan Hajnoczi
  2014-08-08  6:33 ` [PATCH 2/2] initscript: allow scripts to load uprobes Stefan Hajnoczi
  2014-08-08  6:33 ` [PATCH 1/2] initscript: copy uprobes.ko to cache directory Stefan Hajnoczi
@ 2014-08-08  7:24 ` Masami Hiramatsu
  2014-08-11 13:45   ` Stefan Hajnoczi
  2014-08-08 17:21 ` Josh Stone
  3 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2014-08-08  7:24 UTC (permalink / raw)
  To: systemtap

(2014/08/08 15:33), Stefan Hajnoczi wrote:
> The initscript currently fails for user-space probing scripts on systems where
> uprobes.ko is built from source by stap(1).  This is because the initscript
> uses a two-phase "compile and then run" approach:
> 
> The uprobes.ko module is generated during the compile phase but not copied into
> the cache directory where modules are placed for the run phase.  The staprun(8)
> command fails because the script module cannot be loaded without uprobes.ko.
> 
> These patches address the issue by copying uprobes.ko into the cache directory.
> If a script specifies the -u option in its initscript configuration file,
> staprun(8) will receive the path to uprobes.ko.

These look good to me :-)
BTW, is it still working with systemd?

Thanks!

> 
> There is no change in behavior on systems that do not build uprobes.ko.
> 
> Stefan Hajnoczi (2):
>   initscript: copy uprobes.ko to cache directory
>   initscript: allow scripts to load uprobes
> 
>  initscript/systemtap.in | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 


-- 
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] initscript: add support for uprobes scripts
  2014-08-08  6:33 [PATCH 0/2] initscript: add support for uprobes scripts Stefan Hajnoczi
                   ` (2 preceding siblings ...)
  2014-08-08  7:24 ` [PATCH 0/2] initscript: add support for uprobes scripts Masami Hiramatsu
@ 2014-08-08 17:21 ` Josh Stone
  2014-08-11 13:20   ` Stefan Hajnoczi
  3 siblings, 1 reply; 7+ messages in thread
From: Josh Stone @ 2014-08-08 17:21 UTC (permalink / raw)
  To: Stefan Hajnoczi, systemtap; +Cc: Frank Ch. Eigler, Jonathan Lebon

On 08/07/2014 11:33 PM, Stefan Hajnoczi wrote:
> The initscript currently fails for user-space probing scripts on systems where
> uprobes.ko is built from source by stap(1).  This is because the initscript
> uses a two-phase "compile and then run" approach:
> 
> The uprobes.ko module is generated during the compile phase but not copied into
> the cache directory where modules are placed for the run phase.  The staprun(8)
> command fails because the script module cannot be loaded without uprobes.ko.

This confused me at first, because uprobes.ko *is* cached with a
kernel-hashed name -- see uprobes_pass() in buildrun.cxx.  But that's in
SYSTEMTAP_DIR (default ~/.systemtap), and the initscript is talking
about its own CACHE_PATH in /var/cache/systemtap.  So, ok.

I'm not terribly keen on using -k to find uprobes.  But at a minimum, if
we do this, that "Keeping temp..." string is translatable, so you need
to ensure stap runs in English.

It's already using -m, which triggers systemtap_session::save_module to
copy the script module to $PWD at the end of passes_0_4() -- maybe this
should also save uprobes.ko if needed?  Or we could add an explicit
option to request this behavior.  Then the initscript can simply look in
its own tmpdir to see if uprobes.ko was created.

> These patches address the issue by copying uprobes.ko into the cache directory.
> If a script specifies the -u option in its initscript configuration file,
> staprun(8) will receive the path to uprobes.ko.
> 
> There is no change in behavior on systems that do not build uprobes.ko.
> 
> Stefan Hajnoczi (2):
>   initscript: copy uprobes.ko to cache directory
>   initscript: allow scripts to load uprobes
> 
>  initscript/systemtap.in | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] initscript: add support for uprobes scripts
  2014-08-08 17:21 ` Josh Stone
@ 2014-08-11 13:20   ` Stefan Hajnoczi
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2014-08-11 13:20 UTC (permalink / raw)
  To: Josh Stone; +Cc: systemtap, Frank Ch. Eigler, Jonathan Lebon

[-- Attachment #1: Type: text/plain, Size: 1543 bytes --]

On Fri, Aug 08, 2014 at 10:20:58AM -0700, Josh Stone wrote:
> On 08/07/2014 11:33 PM, Stefan Hajnoczi wrote:
> > The initscript currently fails for user-space probing scripts on systems where
> > uprobes.ko is built from source by stap(1).  This is because the initscript
> > uses a two-phase "compile and then run" approach:
> > 
> > The uprobes.ko module is generated during the compile phase but not copied into
> > the cache directory where modules are placed for the run phase.  The staprun(8)
> > command fails because the script module cannot be loaded without uprobes.ko.
> 
> This confused me at first, because uprobes.ko *is* cached with a
> kernel-hashed name -- see uprobes_pass() in buildrun.cxx.  But that's in
> SYSTEMTAP_DIR (default ~/.systemtap), and the initscript is talking
> about its own CACHE_PATH in /var/cache/systemtap.  So, ok.
> 
> I'm not terribly keen on using -k to find uprobes.  But at a minimum, if
> we do this, that "Keeping temp..." string is translatable, so you need
> to ensure stap runs in English.
> 
> It's already using -m, which triggers systemtap_session::save_module to
> copy the script module to $PWD at the end of passes_0_4() -- maybe this
> should also save uprobes.ko if needed?  Or we could add an explicit
> option to request this behavior.  Then the initscript can simply look in
> its own tmpdir to see if uprobes.ko was created.

An explicit stap option makes this cleaner since we don't have to manage
the temporary directory.

Will fix in v2.

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] initscript: add support for uprobes scripts
  2014-08-08  7:24 ` [PATCH 0/2] initscript: add support for uprobes scripts Masami Hiramatsu
@ 2014-08-11 13:45   ` Stefan Hajnoczi
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2014-08-11 13:45 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: systemtap

[-- Attachment #1: Type: text/plain, Size: 161 bytes --]

> BTW, is it still working with systemd?

Yes, I tested the patches on RHEL7 with systemd.  I think systemd is
just invoking the traditional initscript.

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-08-11 13:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-08  6:33 [PATCH 0/2] initscript: add support for uprobes scripts Stefan Hajnoczi
2014-08-08  6:33 ` [PATCH 2/2] initscript: allow scripts to load uprobes Stefan Hajnoczi
2014-08-08  6:33 ` [PATCH 1/2] initscript: copy uprobes.ko to cache directory Stefan Hajnoczi
2014-08-08  7:24 ` [PATCH 0/2] initscript: add support for uprobes scripts Masami Hiramatsu
2014-08-11 13:45   ` Stefan Hajnoczi
2014-08-08 17:21 ` Josh Stone
2014-08-11 13:20   ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).