Print this page
OS-279 #pragma D option zone= does not work on installed, halted zones
OS-208 DTrace needs to use zone_did to match zone-limited enablings
INTRO-118 enabling USDT probes in zones should be more scalable


  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  29  * Copyright (c) 2012 by Delphix. All rights reserved.
  30  */
  31 
  32 #include <sys/resource.h>
  33 #include <sys/mman.h>
  34 #include <sys/types.h>
  35 
  36 #include <strings.h>
  37 #include <signal.h>
  38 #include <stdlib.h>
  39 #include <unistd.h>
  40 #include <limits.h>
  41 #include <alloca.h>
  42 #include <errno.h>
  43 #include <fcntl.h>


  44 
  45 #include <dt_impl.h>
  46 #include <dt_string.h>
  47 
  48 static int
  49 dt_opt_agg(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
  50 {
  51         dt_aggregate_t *agp = &dtp->dt_aggregate;
  52 
  53         if (arg != NULL)
  54                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
  55 
  56         agp->dtat_flags |= option;
  57         return (0);
  58 }
  59 
  60 /*ARGSUSED*/
  61 static int
  62 dt_opt_amin(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
  63 {


 837         int i;
 838 
 839         if (arg == NULL)
 840                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
 841 
 842         for (i = 0; _dtrace_bufresize[i].dtbr_name != NULL; i++) {
 843                 if (strcmp(_dtrace_bufresize[i].dtbr_name, arg) == 0) {
 844                         policy = _dtrace_bufresize[i].dtbr_policy;
 845                         break;
 846                 }
 847         }
 848 
 849         if (policy == DTRACEOPT_UNSET)
 850                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
 851 
 852         dtp->dt_options[DTRACEOPT_BUFRESIZE] = policy;
 853 
 854         return (0);
 855 }
 856 






































 857 int
 858 dt_options_load(dtrace_hdl_t *dtp)
 859 {
 860         dof_hdr_t hdr, *dof;
 861         dof_sec_t *sec;
 862         size_t offs;
 863         int i;
 864 
 865         /*
 866          * To load the option values, we need to ask the kernel to provide its
 867          * DOF, which we'll sift through to look for OPTDESC sections.
 868          */
 869         bzero(&hdr, sizeof (dof_hdr_t));
 870         hdr.dofh_loadsz = sizeof (dof_hdr_t);
 871 
 872         if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1)
 873                 return (dt_set_errno(dtp, errno));
 874 
 875         if (hdr.dofh_loadsz < sizeof (dof_hdr_t))
 876                 return (dt_set_errno(dtp, EINVAL));


 977  */
 978 static const dt_option_t _dtrace_rtoptions[] = {
 979         { "aggsize", dt_opt_size, DTRACEOPT_AGGSIZE },
 980         { "bufsize", dt_opt_size, DTRACEOPT_BUFSIZE },
 981         { "bufpolicy", dt_opt_bufpolicy, DTRACEOPT_BUFPOLICY },
 982         { "bufresize", dt_opt_bufresize, DTRACEOPT_BUFRESIZE },
 983         { "cleanrate", dt_opt_rate, DTRACEOPT_CLEANRATE },
 984         { "cpu", dt_opt_runtime, DTRACEOPT_CPU },
 985         { "destructive", dt_opt_runtime, DTRACEOPT_DESTRUCTIVE },
 986         { "dynvarsize", dt_opt_size, DTRACEOPT_DYNVARSIZE },
 987         { "grabanon", dt_opt_runtime, DTRACEOPT_GRABANON },
 988         { "jstackframes", dt_opt_runtime, DTRACEOPT_JSTACKFRAMES },
 989         { "jstackstrsize", dt_opt_size, DTRACEOPT_JSTACKSTRSIZE },
 990         { "nspec", dt_opt_runtime, DTRACEOPT_NSPEC },
 991         { "specsize", dt_opt_size, DTRACEOPT_SPECSIZE },
 992         { "stackframes", dt_opt_runtime, DTRACEOPT_STACKFRAMES },
 993         { "statusrate", dt_opt_rate, DTRACEOPT_STATUSRATE },
 994         { "strsize", dt_opt_strsize, DTRACEOPT_STRSIZE },
 995         { "ustackframes", dt_opt_runtime, DTRACEOPT_USTACKFRAMES },
 996         { "temporal", dt_opt_runtime, DTRACEOPT_TEMPORAL },

 997         { NULL }
 998 };
 999 
1000 /*
1001  * Dynamic run-time options.
1002  */
1003 static const dt_option_t _dtrace_drtoptions[] = {
1004         { "agghist", dt_opt_runtime, DTRACEOPT_AGGHIST },
1005         { "aggpack", dt_opt_runtime, DTRACEOPT_AGGPACK },
1006         { "aggrate", dt_opt_rate, DTRACEOPT_AGGRATE },
1007         { "aggsortkey", dt_opt_runtime, DTRACEOPT_AGGSORTKEY },
1008         { "aggsortkeypos", dt_opt_runtime, DTRACEOPT_AGGSORTKEYPOS },
1009         { "aggsortpos", dt_opt_runtime, DTRACEOPT_AGGSORTPOS },
1010         { "aggsortrev", dt_opt_runtime, DTRACEOPT_AGGSORTREV },
1011         { "aggzoom", dt_opt_runtime, DTRACEOPT_AGGZOOM },
1012         { "flowindent", dt_opt_runtime, DTRACEOPT_FLOWINDENT },
1013         { "quiet", dt_opt_runtime, DTRACEOPT_QUIET },
1014         { "rawbytes", dt_opt_runtime, DTRACEOPT_RAWBYTES },
1015         { "stackindent", dt_opt_runtime, DTRACEOPT_STACKINDENT },
1016         { "switchrate", dt_opt_rate, DTRACEOPT_SWITCHRATE },




  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  29  * Copyright (c) 2012 by Delphix. All rights reserved.
  30  */
  31 
  32 #include <sys/resource.h>
  33 #include <sys/mman.h>
  34 #include <sys/types.h>
  35 
  36 #include <strings.h>
  37 #include <signal.h>
  38 #include <stdlib.h>
  39 #include <unistd.h>
  40 #include <limits.h>
  41 #include <alloca.h>
  42 #include <errno.h>
  43 #include <fcntl.h>
  44 #include <zone.h>
  45 #include <libzonecfg.h>
  46 
  47 #include <dt_impl.h>
  48 #include <dt_string.h>
  49 
  50 static int
  51 dt_opt_agg(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
  52 {
  53         dt_aggregate_t *agp = &dtp->dt_aggregate;
  54 
  55         if (arg != NULL)
  56                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
  57 
  58         agp->dtat_flags |= option;
  59         return (0);
  60 }
  61 
  62 /*ARGSUSED*/
  63 static int
  64 dt_opt_amin(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
  65 {


 839         int i;
 840 
 841         if (arg == NULL)
 842                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
 843 
 844         for (i = 0; _dtrace_bufresize[i].dtbr_name != NULL; i++) {
 845                 if (strcmp(_dtrace_bufresize[i].dtbr_name, arg) == 0) {
 846                         policy = _dtrace_bufresize[i].dtbr_policy;
 847                         break;
 848                 }
 849         }
 850 
 851         if (policy == DTRACEOPT_UNSET)
 852                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
 853 
 854         dtp->dt_options[DTRACEOPT_BUFRESIZE] = policy;
 855 
 856         return (0);
 857 }
 858 
 859 /*ARGSUSED*/
 860 static int
 861 dt_opt_zone(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
 862 {
 863         zoneid_t z, did;
 864 
 865         if (arg == NULL)
 866                 return (dt_set_errno(dtp, EDT_BADOPTVAL));
 867 
 868         /*
 869          * If the specified zone is currently running, we'll query the kernel
 870          * for its debugger ID.  If it doesn't appear to be running, we'll look
 871          * for it for among all installed zones (thereby allowing a zdefs
 872          * enabling against a halted zone).
 873          */
 874         if ((z = getzoneidbyname(arg)) != -1) {
 875                 if (zone_getattr(z, ZONE_ATTR_DID, &did, sizeof (did)) < 0)
 876                         return (dt_set_errno(dtp, EDT_BADOPTVAL));
 877         } else {
 878                 zone_dochandle_t handle;
 879 
 880                 if ((handle = zonecfg_init_handle()) == NULL)
 881                         return (dt_set_errno(dtp, errno));
 882 
 883                 if (zonecfg_get_handle(arg, handle) != Z_OK) {
 884                         zonecfg_fini_handle(handle);
 885                         return (dt_set_errno(dtp, EDT_BADOPTVAL));
 886                 }
 887 
 888                 did = zonecfg_get_did(handle);
 889                 zonecfg_fini_handle(handle);
 890         }
 891 
 892         dtp->dt_options[DTRACEOPT_ZONE] = did;
 893 
 894         return (0);
 895 }
 896 
 897 int
 898 dt_options_load(dtrace_hdl_t *dtp)
 899 {
 900         dof_hdr_t hdr, *dof;
 901         dof_sec_t *sec;
 902         size_t offs;
 903         int i;
 904 
 905         /*
 906          * To load the option values, we need to ask the kernel to provide its
 907          * DOF, which we'll sift through to look for OPTDESC sections.
 908          */
 909         bzero(&hdr, sizeof (dof_hdr_t));
 910         hdr.dofh_loadsz = sizeof (dof_hdr_t);
 911 
 912         if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1)
 913                 return (dt_set_errno(dtp, errno));
 914 
 915         if (hdr.dofh_loadsz < sizeof (dof_hdr_t))
 916                 return (dt_set_errno(dtp, EINVAL));


1017  */
1018 static const dt_option_t _dtrace_rtoptions[] = {
1019         { "aggsize", dt_opt_size, DTRACEOPT_AGGSIZE },
1020         { "bufsize", dt_opt_size, DTRACEOPT_BUFSIZE },
1021         { "bufpolicy", dt_opt_bufpolicy, DTRACEOPT_BUFPOLICY },
1022         { "bufresize", dt_opt_bufresize, DTRACEOPT_BUFRESIZE },
1023         { "cleanrate", dt_opt_rate, DTRACEOPT_CLEANRATE },
1024         { "cpu", dt_opt_runtime, DTRACEOPT_CPU },
1025         { "destructive", dt_opt_runtime, DTRACEOPT_DESTRUCTIVE },
1026         { "dynvarsize", dt_opt_size, DTRACEOPT_DYNVARSIZE },
1027         { "grabanon", dt_opt_runtime, DTRACEOPT_GRABANON },
1028         { "jstackframes", dt_opt_runtime, DTRACEOPT_JSTACKFRAMES },
1029         { "jstackstrsize", dt_opt_size, DTRACEOPT_JSTACKSTRSIZE },
1030         { "nspec", dt_opt_runtime, DTRACEOPT_NSPEC },
1031         { "specsize", dt_opt_size, DTRACEOPT_SPECSIZE },
1032         { "stackframes", dt_opt_runtime, DTRACEOPT_STACKFRAMES },
1033         { "statusrate", dt_opt_rate, DTRACEOPT_STATUSRATE },
1034         { "strsize", dt_opt_strsize, DTRACEOPT_STRSIZE },
1035         { "ustackframes", dt_opt_runtime, DTRACEOPT_USTACKFRAMES },
1036         { "temporal", dt_opt_runtime, DTRACEOPT_TEMPORAL },
1037         { "zone", dt_opt_zone, DTRACEOPT_ZONE },
1038         { NULL }
1039 };
1040 
1041 /*
1042  * Dynamic run-time options.
1043  */
1044 static const dt_option_t _dtrace_drtoptions[] = {
1045         { "agghist", dt_opt_runtime, DTRACEOPT_AGGHIST },
1046         { "aggpack", dt_opt_runtime, DTRACEOPT_AGGPACK },
1047         { "aggrate", dt_opt_rate, DTRACEOPT_AGGRATE },
1048         { "aggsortkey", dt_opt_runtime, DTRACEOPT_AGGSORTKEY },
1049         { "aggsortkeypos", dt_opt_runtime, DTRACEOPT_AGGSORTKEYPOS },
1050         { "aggsortpos", dt_opt_runtime, DTRACEOPT_AGGSORTPOS },
1051         { "aggsortrev", dt_opt_runtime, DTRACEOPT_AGGSORTREV },
1052         { "aggzoom", dt_opt_runtime, DTRACEOPT_AGGZOOM },
1053         { "flowindent", dt_opt_runtime, DTRACEOPT_FLOWINDENT },
1054         { "quiet", dt_opt_runtime, DTRACEOPT_QUIET },
1055         { "rawbytes", dt_opt_runtime, DTRACEOPT_RAWBYTES },
1056         { "stackindent", dt_opt_runtime, DTRACEOPT_STACKINDENT },
1057         { "switchrate", dt_opt_rate, DTRACEOPT_SWITCHRATE },