Whamcloud - gitweb
LUDOC-11 misc: remove some 'l23' conditions add 'l2C'
[doc/manual.git] / LustreDebugging.xml
1 <?xml version='1.0' encoding='UTF-8'?><chapter xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en-US" xml:id="lustredebugging">
2   <title xml:id="lustredebugging.title">Debugging a Lustre File System</title>
3   <para>This chapter describes tips and information to debug a Lustre file system, and includes the
4     following sections:</para>
5   <itemizedlist>
6     <listitem>
7       <para><xref linkend="dbdoclet.50438274_15874"/></para>
8     </listitem>
9     <listitem>
10       <para><xref linkend="dbdoclet.50438274_23607"/></para>
11     </listitem>
12     <listitem>
13       <para><xref linkend="dbdoclet.50438274_80443"/></para>
14     </listitem>
15   </itemizedlist>
16   <section xml:id="dbdoclet.50438274_15874">
17     <title><indexterm><primary>debugging</primary></indexterm>
18 Diagnostic and Debugging Tools</title>
19     <para>A variety of diagnostic and analysis tools are available to debug issues with the Lustre software. Some of these are provided in Linux distributions, while others have been developed and are made available by the Lustre project.</para>
20     <section remap="h3" xml:id="section_dms_q21_kk">
21       <title><indexterm>
22           <primary>debugging</primary>
23           <secondary>tools</secondary>
24         </indexterm> Lustre Debugging Tools</title>
25       <para>The following in-kernel debug mechanisms are incorporated into the Lustre
26         software:</para>
27       <itemizedlist>
28         <listitem>
29           <para xml:id="para_fkj_rld_hk"><emphasis role="bold">Debug logs</emphasis> - A circular
30             debug buffer to which Lustre internal debug messages are written (in contrast to error
31             messages, which are printed to the syslog or console). Entries to the Lustre debug log
32             are controlled by the mask set by <literal>/proc/sys/lnet/debug</literal>. The log size
33             defaults to 5 MB per CPU but can be increased as a busy system will quickly overwrite 5
34             MB. When the buffer fills, the oldest information is discarded.</para>
35         </listitem>
36         <listitem>
37           <para><emphasis role="bold">Debug daemon</emphasis> - The debug daemon controls logging of
38             debug messages.</para>
39         </listitem>
40         <listitem>
41           <para><emphasis role="bold">
42               <literal>/proc/sys/lnet/debug</literal>
43             </emphasis> - This file contains a mask that can be used to delimit the debugging
44             information written out to the kernel debug logs.</para>
45         </listitem>
46       </itemizedlist>
47       <para>The following tools are also provided with the Lustre software:</para>
48       <itemizedlist>
49         <listitem>
50           <para><emphasis role="bold">
51               <literal>lctl</literal>
52             </emphasis> - This tool is used with the debug_kernel option to manually dump the Lustre
53             debugging log or post-process debugging logs that are dumped automatically. For more
54             information about the lctl tool, see <xref linkend="dbdoclet.50438274_62472"/> and <xref
55               linkend="dbdoclet.50438219_38274"/>.</para>
56         </listitem>
57         <listitem>
58           <para>Lustre subsystem asserts - A panic-style assertion (LBUG) in the kernel causes the
59             Lustre file system to dump the debug log to the file
60                 <literal>/tmp/lustre-log.<replaceable>timestamp</replaceable></literal> where it can
61             be retrieved after a reboot. For more information, see <xref
62               linkend="dbdoclet.50438198_40669"/>.</para>
63         </listitem>
64         <listitem>
65           <para>
66             <literal>
67               <replaceable>lfs</replaceable>
68             </literal> - This utility provides access to the extended attributes (EAs) of a Lustre
69             file (along with other information). For more information about lfs, see <xref
70               linkend="dbdoclet.50438206_94597"/>.</para>
71         </listitem>
72       </itemizedlist>
73     </section>
74     <section remap="h3">
75       <title><indexterm><primary>debugging</primary><secondary>external tools</secondary></indexterm>External Debugging Tools</title>
76       <para>The tools described in this section are provided in the Linux kernel or are available at an external website. For information about using some of these tools for Lustre debugging, see <xref linkend="dbdoclet.50438274_23607"/> and <xref linkend="dbdoclet.50438274_80443"/>.</para>
77       <section remap="h4">
78         <title><indexterm><primary>debugging</primary><secondary>admin tools</secondary></indexterm>Tools for Administrators and Developers</title>
79         <para>Some general debugging tools provided as a part of the standard Linux distribution
80           are:</para>
81         <itemizedlist>
82           <listitem>
83             <para><emphasis role="bold">
84                 <literal>strace</literal>
85               </emphasis> . This tool allows a system call to be traced.</para>
86           </listitem>
87           <listitem>
88             <para><emphasis role="bold">
89                 <literal>/var/log/messages</literal>
90               </emphasis> . <literal>syslogd</literal> prints fatal or serious messages at this log.</para>
91           </listitem>
92           <listitem>
93             <para><emphasis role="bold">Crash dumps</emphasis> . On crash-dump enabled kernels,
94               sysrq c produces a crash dump. The Lustre software enhances this crash dump with a log
95               dump (the last 64 KB of the log) to the console.</para>
96           </listitem>
97           <listitem>
98             <para><emphasis role="bold">
99                 <literal>debugfs</literal>
100               </emphasis>. Interactive file system debugger.</para>
101           </listitem>
102         </itemizedlist>
103         <para>The following logging and data collection tools can be used to collect information for debugging Lustre kernel issues:</para>
104         <itemizedlist>
105           <listitem>
106             <para><emphasis role="bold">
107                 <literal>kdump</literal>
108               </emphasis> . A Linux kernel crash utility useful for debugging a system running Red Hat Enterprise Linux. For more information about <literal>kdump</literal>, see the Red Hat knowledge base article <link xl:href="http://kbase.redhat.com/faq/docs/DOC-6039">How do I configure kexec/kdump on Red Hat Enterprise Linux 5?</link>. To download <literal>kdump</literal>, go to the <link xl:href="http://fedoraproject.org/wiki/SystemConfig/kdump#Download">Fedora Project Download</link> site.</para>
109           </listitem>
110           <listitem>
111             <para><emphasis role="bold">
112                 <literal>netconsole</literal>
113               </emphasis>. Enables kernel-level network logging over UDP. A system requires (SysRq) allows users to collect relevant data through <literal>netconsole</literal>.</para>
114           </listitem>
115           <listitem>
116             <para><emphasis role="bold">
117                 <literal>netdump</literal>
118               </emphasis>. A crash dump utility from Red Hat that allows memory images to be dumped
119               over a network to a central server for analysis. The <literal>netdump</literal>
120               utility was replaced by <literal>kdump</literal> in Red Hat Enterprise Linux 5. For
121               more information about <literal>netdump</literal>, see <link
122                 xl:href="http://www.redhat.com/support/wpapers/redhat/netdump/">Red Hat, Inc.&apos;s
123                 Network Console and Crash Dump Facility</link>.</para>
124           </listitem>
125           <listitem>
126             <para><emphasis><literal>wireshark</literal> </emphasis> . A network
127             packet inspection tool that allows debugging of information that was
128             sent between the various Lustre nodes. This tool is built on top of
129             <literal>tcpdump</literal> and can read packet dumps generated by
130             it.  There are plug-ins available to dissassemble the LNet and
131             Lustre protocols.  They are located within the <link
132             xl:href="http://git.whamcloud.com/">Lustre git repository</link>
133             under <literal>lustre/contrib/wireshark/</literal>.  Installation
134             instruction are included in that directory. See also <link
135             xl:href="http://www.wireshark.org/">Wireshark Website</link> for
136             more details.</para>
137           </listitem>
138         </itemizedlist>
139       </section>
140       <section remap="h4">
141         <title><indexterm><primary>debugging</primary><secondary>developer tools</secondary></indexterm>Tools for Developers</title>
142         <para>The tools described in this section may be useful for debugging a Lustre file system
143           in a development environment.</para>
144         <para>Of general interest is:</para>
145         <itemizedlist>
146           <listitem>
147             <para><literal>
148                 <replaceable>leak_finder.pl</replaceable>
149               </literal> . This program provided with the Lustre software is useful for finding
150               memory leaks in the code.</para>
151           </listitem>
152         </itemizedlist>
153         <para>A virtual machine is often used to create an isolated development and test environment. Some commonly-used virtual machines are:</para>
154         <itemizedlist>
155           <listitem>
156             <para><emphasis role="bold">VirtualBox Open Source Edition</emphasis> . Provides enterprise-class virtualization capability for all major platforms and is available free at <link xl:href="http://www.sun.com/software/products/virtualbox/get.jsp?intcmp=2945">Get Sun VirtualBox</link>.</para>
157           </listitem>
158           <listitem>
159             <para><emphasis role="bold">VMware Server</emphasis> . Virtualization platform available as free introductory software at <link xl:href="http://downloads.vmware.com/d/info/datacenter_downloads/vmware_server/2_0">Download VMware Server</link>.</para>
160           </listitem>
161           <listitem>
162             <para><emphasis role="bold">Xen</emphasis> . A para-virtualized environment with virtualization capabilities similar to VMware Server and Virtual Box. However, Xen allows the use of modified kernels to provide near-native performance and the ability to emulate shared storage. For more information, go to <link xl:href="http://xen.org/">xen.org</link>.</para>
163           </listitem>
164         </itemizedlist>
165         <para>A variety of debuggers and analysis tools are available including:</para>
166         <itemizedlist>
167           <listitem>
168             <para><emphasis role="bold">
169                 <literal>kgdb</literal>
170               </emphasis> . The Linux Kernel Source Level Debugger kgdb is used in conjunction with the GNU Debugger <literal>gdb</literal> for debugging the Linux kernel. For more information about using <literal>kgdb</literal> with <literal>gdb</literal>, see <link xl:href="http://www.linuxtopia.org/online_books/redhat_linux_debugging_with_gdb/running.html">Chapter 6. Running Programs Under gdb</link> in the <emphasis>Red Hat Linux 4 Debugging with GDB</emphasis> guide.</para>
171           </listitem>
172           <listitem>
173             <para><emphasis role="bold">
174                 <literal>crash</literal>
175               </emphasis> . Used to analyze saved crash dump data when a system had panicked or locked up or appears unresponsive. For more information about using crash to analyze a crash dump, see:</para>
176             <itemizedlist>
177               <listitem>
178                 <para> Red Hat Magazine article: <link xl:href="http://magazine.redhat.com/2007/08/15/a-quick-overview-of-linux-kernel-crash-dump-analysis/">A quick overview of Linux kernel crash dump analysis</link></para>
179               </listitem>
180               <listitem>
181                 <para><link xl:href="http://people.redhat.com/anderson/crash_whitepaper/#EXAMPLES">Crash Usage: A Case Study</link>  from the white paper <emphasis>Red Hat Crash Utility</emphasis> by David Anderson</para>
182               </listitem>
183               <listitem>
184                 <para> Kernel Trap forum entry: <link xl:href="http://kerneltrap.org/node/5758">Linux: Kernel Crash Dumps</link></para>
185               </listitem>
186               <listitem>
187                 <para> White paper: <link xl:href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=8&amp;ved=0CCUQFjAH&amp;url=http%3A%2F%2Fwww.kernel.sg%2Fpapers%2Fcrash-dump-analysis.pdf&amp;rct=j&amp;q=redhat+crash+dump&amp;ei=6aQBS-ifK4T8tAPcjdiHCw&amp;usg=AFQjCNEk03E3GDtAsawG3gfpwc1gGNELAg">A Quick Overview of Linux Kernel Crash Dump Analysis</link></para>
188               </listitem>
189             </itemizedlist>
190           </listitem>
191         </itemizedlist>
192       </section>
193     </section>
194   </section>
195   <section xml:id="dbdoclet.50438274_23607">
196     <title><indexterm><primary>debugging</primary><secondary>procedure</secondary></indexterm>Lustre Debugging Procedures</title>
197     <para>The procedures below may be useful to administrators or developers debugging a Lustre files system.</para>
198     <section remap="h3">
199       <title><indexterm><primary>debugging</primary><secondary>message format</secondary></indexterm>Understanding the Lustre Debug Messaging Format</title>
200       <para>Lustre debug messages are categorized by originating subsystem, message type, and location in the source code. For a list of subsystems and message types, see <xref linkend="dbdoclet.50438274_57603"/>.</para>
201       <note>
202         <para>For a current list of subsystems and debug message types, see
203             <literal>libcfs/include/libcfs/libcfs_debug.h</literal> in the Lustre software
204           tree</para>
205       </note>
206       <para>The elements of a Lustre debug message are described in <xref linkend="dbdoclet.50438274_57177"/> Format of Lustre Debug Messages.</para>
207       <section xml:id="dbdoclet.50438274_57603">
208         <title>Lustre Debug Messages</title>
209         <para>Each Lustre debug message has the tag of the subsystem it originated in, the message
210           type, and the location in the source code. The subsystems and debug types used are as
211           follows:</para>
212         <itemizedlist>
213           <listitem>
214             <para>  Standard Subsystems:</para>
215             <para> mdc, mds, osc, ost, obdclass, obdfilter, llite, ptlrpc, portals, lnd, ldlm, lov</para>
216           </listitem>
217         </itemizedlist>
218         <itemizedlist>
219           <listitem>
220             <para>  Debug Types:</para>
221           </listitem>
222           <listitem>
223             <para><informaltable frame="all">
224                 <tgroup cols="2">
225                   <colspec colname="c1" colwidth="50*"/>
226                   <colspec colname="c2" colwidth="50*"/>
227                   <thead>
228                     <row>
229                       <entry>
230                         <para><emphasis role="bold">Types</emphasis></para>
231                       </entry>
232                       <entry>
233                         <para><emphasis role="bold">Description</emphasis></para>
234                       </entry>
235                     </row>
236                   </thead>
237                   <tbody>
238                     <row>
239                       <entry>
240                         <para> <emphasis role="bold">trace</emphasis></para>
241                       </entry>
242                       <entry>
243                         <para> Entry/Exit markers</para>
244                       </entry>
245                     </row>
246                     <row>
247                       <entry>
248                         <para> <emphasis role="bold">dlmtrace</emphasis></para>
249                       </entry>
250                       <entry>
251                         <para> Locking-related information</para>
252                       </entry>
253                     </row>
254                     <row>
255                       <entry>
256                         <para> <emphasis role="bold">inode</emphasis></para>
257                       </entry>
258                       <entry>
259                         <para> &#160;</para>
260                       </entry>
261                     </row>
262                     <row>
263                       <entry>
264                         <para> <emphasis role="bold">super</emphasis></para>
265                       </entry>
266                       <entry>
267                         <para> &#160;</para>
268                       </entry>
269                     </row>
270                     <row>
271                       <entry>
272                         <para> <emphasis role="bold">ext2</emphasis></para>
273                       </entry>
274                       <entry>
275                         <para> Anything from the ext2_debug</para>
276                       </entry>
277                     </row>
278                     <row>
279                       <entry>
280                         <para> <emphasis role="bold">malloc</emphasis></para>
281                       </entry>
282                       <entry>
283                         <para> Print malloc or free information</para>
284                       </entry>
285                     </row>
286                     <row>
287                       <entry>
288                         <para> <emphasis role="bold">cache</emphasis></para>
289                       </entry>
290                       <entry>
291                         <para> Cache-related information</para>
292                       </entry>
293                     </row>
294                     <row>
295                       <entry>
296                         <para> <emphasis role="bold">info</emphasis></para>
297                       </entry>
298                       <entry>
299                         <para> General information</para>
300                       </entry>
301                     </row>
302                     <row>
303                       <entry>
304                         <para> <emphasis role="bold">ioctl</emphasis></para>
305                       </entry>
306                       <entry>
307                         <para> IOCTL-related information</para>
308                       </entry>
309                     </row>
310                     <row>
311                       <entry>
312                         <para> <emphasis role="bold">blocks</emphasis></para>
313                       </entry>
314                       <entry>
315                         <para> Ext2 block allocation information</para>
316                       </entry>
317                     </row>
318                     <row>
319                       <entry>
320                         <para> <emphasis role="bold">net</emphasis></para>
321                       </entry>
322                       <entry>
323                         <para> Networking</para>
324                       </entry>
325                     </row>
326                     <row>
327                       <entry>
328                         <para> <emphasis role="bold">warning</emphasis></para>
329                       </entry>
330                       <entry>
331                         <para> &#160;</para>
332                       </entry>
333                     </row>
334                     <row>
335                       <entry>
336                         <para> <emphasis role="bold">buffs</emphasis></para>
337                       </entry>
338                       <entry>
339                         <para> &#160;</para>
340                       </entry>
341                     </row>
342                     <row>
343                       <entry>
344                         <para> <emphasis role="bold">other</emphasis></para>
345                       </entry>
346                       <entry>
347                         <para> &#160;</para>
348                       </entry>
349                     </row>
350                     <row>
351                       <entry>
352                         <para> <emphasis role="bold">dentry</emphasis></para>
353                       </entry>
354                       <entry>
355                         <para> &#160;</para>
356                       </entry>
357                     </row>
358                     <row>
359                       <entry>
360                         <para> <emphasis role="bold">portals</emphasis></para>
361                       </entry>
362                       <entry>
363                         <para> Entry/Exit markers</para>
364                       </entry>
365                     </row>
366                     <row>
367                       <entry>
368                         <para> <emphasis role="bold">page</emphasis></para>
369                       </entry>
370                       <entry>
371                         <para> Bulk page handling</para>
372                       </entry>
373                     </row>
374                     <row>
375                       <entry>
376                         <para> <emphasis role="bold">error</emphasis></para>
377                       </entry>
378                       <entry>
379                         <para> Error messages</para>
380                       </entry>
381                     </row>
382                     <row>
383                       <entry>
384                         <para> <emphasis role="bold">emerg</emphasis></para>
385                       </entry>
386                       <entry>
387                         <para> &#160;</para>
388                       </entry>
389                     </row>
390                     <row>
391                       <entry>
392                         <para> <emphasis role="bold">rpctrace</emphasis></para>
393                       </entry>
394                       <entry>
395                         <para> For distributed debugging</para>
396                       </entry>
397                     </row>
398                     <row>
399                       <entry>
400                         <para> <emphasis role="bold">ha</emphasis></para>
401                       </entry>
402                       <entry>
403                         <para> Failover and recovery-related information</para>
404                       </entry>
405                     </row>
406                   </tbody>
407                 </tgroup>
408               </informaltable>
409 </para>
410           </listitem>
411         </itemizedlist>
412       </section>
413       <section xml:id="dbdoclet.50438274_57177">
414         <title>Format of Lustre Debug Messages</title>
415         <para>The Lustre software uses the <literal>CDEBUG()</literal> and
416             <literal>CERROR()</literal> macros to print the debug or error messages. To print the
417           message, the <literal>CDEBUG()</literal> macro uses the function
418             <literal>libcfs_debug_msg()</literal> (<literal>libcfs/libcfs/tracefile.c</literal>).
419           The message format is described below, along with an example.</para>
420         <informaltable frame="all">
421           <tgroup cols="2">
422             <colspec colname="c1" colwidth="50*"/>
423             <colspec colname="c2" colwidth="50*"/>
424             <thead>
425               <row>
426                 <entry>
427                   <para><emphasis role="bold">Description</emphasis></para>
428                 </entry>
429                 <entry>
430                   <para><emphasis role="bold">Parameter</emphasis></para>
431                 </entry>
432               </row>
433             </thead>
434             <tbody>
435               <row>
436                 <entry>
437                   <para> <emphasis role="bold">subsystem</emphasis></para>
438                 </entry>
439                 <entry>
440                   <para> 800000</para>
441                 </entry>
442               </row>
443               <row>
444                 <entry>
445                   <para> <emphasis role="bold">debug mask</emphasis></para>
446                 </entry>
447                 <entry>
448                   <para> 000010</para>
449                 </entry>
450               </row>
451               <row>
452                 <entry>
453                   <para> <emphasis role="bold">smp_processor_id</emphasis></para>
454                 </entry>
455                 <entry>
456                   <para> 0</para>
457                 </entry>
458               </row>
459               <row>
460                 <entry>
461                   <para> <emphasis role="bold">seconds.microseconds</emphasis></para>
462                 </entry>
463                 <entry>
464                   <para> 1081880847.677302</para>
465                 </entry>
466               </row>
467               <row>
468                 <entry>
469                   <para> <emphasis role="bold">stack size</emphasis></para>
470                 </entry>
471                 <entry>
472                   <para> 1204</para>
473                 </entry>
474               </row>
475               <row>
476                 <entry>
477                   <para> <emphasis role="bold">pid</emphasis></para>
478                 </entry>
479                 <entry>
480                   <para> 2973</para>
481                 </entry>
482               </row>
483               <row>
484                 <entry>
485                   <para> <emphasis role="bold">host pid (UML only) or zero</emphasis></para>
486                 </entry>
487                 <entry>
488                   <para> 31070</para>
489                 </entry>
490               </row>
491               <row>
492                 <entry>
493                   <para> <emphasis role="bold">(file:line #:function_name())</emphasis></para>
494                 </entry>
495                 <entry>
496                   <para> (obd_mount.c:2089:lustre_fill_super())</para>
497                 </entry>
498               </row>
499               <row>
500                 <entry>
501                   <para> <emphasis role="bold">debug message</emphasis></para>
502                 </entry>
503                 <entry>
504                   <para> kmalloced &apos;*obj&apos;: 24 at a375571c (tot 17447717)</para>
505                 </entry>
506               </row>
507             </tbody>
508           </tgroup>
509         </informaltable>
510       </section>
511       <section remap="h4">
512         <title>Lustre Debug Messages Buffer</title>
513         <para>Lustre debug messages are maintained in a buffer, with the maximum buffer size specified (in MBs) by the <literal>debug_mb</literal> parameter (<literal>lctl get_param debug_mb</literal>). The buffer is circular, so debug messages are kept until the allocated buffer limit is reached, and then the first messages are overwritten.</para>
514       </section>
515     </section>
516     <section xml:id="dbdoclet.50438274_62472">
517       <title><indexterm><primary>debugging</primary><secondary>using lctl</secondary></indexterm>Using the lctl Tool to View Debug Messages</title>
518       <para>The <literal>lctl</literal> tool allows debug messages to be filtered based on subsystems and message types to extract information useful for troubleshooting from a kernel debug log. For a command reference, see <xref linkend="dbdoclet.50438219_38274"/>.</para>
519       <para>You can use <literal>lctl</literal> to:</para>
520       <itemizedlist>
521         <listitem>
522           <para>Obtain a list of all the types and subsystems:</para>
523           <screen>lctl &gt; debug_list <replaceable>subsystems|types</replaceable></screen>
524         </listitem>
525       </itemizedlist>
526       <itemizedlist>
527         <listitem>
528           <para>Filter the debug log:</para>
529           <screen>lctl &gt; filter <replaceable>subsystem_name|debug_type</replaceable></screen>
530         </listitem>
531       </itemizedlist>
532       <note>
533         <para>When <literal>lctl</literal> filters, it removes unwanted lines from the displayed output. This does not affect the contents of the debug log in the kernel&apos;s memory. As a result, you can print the log many times with different filtering levels without worrying about losing data.</para>
534       </note>
535       <itemizedlist>
536         <listitem>
537           <para>Show debug messages belonging to certain subsystem or type:</para>
538           <screen>lctl &gt; show <replaceable>subsystem_name|debug_type</replaceable></screen>
539           <para><literal>debug_kernel</literal> pulls the data from the kernel logs, filters it appropriately, and displays or saves it as per the specified options</para>
540           <screen>lctl &gt; debug_kernel [<replaceable>output filename</replaceable>]</screen>
541           <para>If the debugging is being done on User Mode Linux (UML), it might be useful to save the logs on the host machine so that they can be used at a later time.</para>
542         </listitem>
543       </itemizedlist>
544       <itemizedlist>
545         <listitem>
546           <para>Filter a log on disk, if you already have a debug log saved to disk (likely from a crash):</para>
547           <screen>lctl &gt; debug_file <replaceable>input_file</replaceable> [<replaceable>output_file</replaceable>] </screen>
548           <para>During the debug session, you can add markers or breaks to the log for any reason:</para>
549           <screen>lctl &gt; mark [marker text] </screen>
550           <para>The marker text defaults to the current date and time in the debug log (similar to the example shown below):</para>
551           <screen>DEBUG MARKER: Tue Mar 5 16:06:44 EST 2002 
552 </screen>
553         </listitem>
554       </itemizedlist>
555       <itemizedlist>
556         <listitem>
557           <para>Completely flush the kernel debug buffer:</para>
558           <screen>lctl &gt; clear
559 </screen>
560         </listitem>
561       </itemizedlist>
562       <note>
563         <para>Debug messages displayed with <literal>lctl</literal> are also subject to the kernel debug masks; the filters are additive.</para>
564       </note>
565       <section remap="h4">
566         <title><indexterm><primary>debugging</primary><secondary>lctl example</secondary></indexterm>Sample <literal>lctl</literal> Run</title>
567         <para>Below is a sample run using the <literal>lctl</literal> command.</para>
568         <screen>bash-2.04# ./lctl 
569 lctl &gt; debug_kernel /tmp/lustre_logs/log_all 
570 Debug log: 324 lines, 324 kept, 0 dropped. 
571 lctl &gt; filter trace 
572 Disabling output of type &quot;trace&quot; 
573 lctl &gt; debug_kernel /tmp/lustre_logs/log_notrace 
574 Debug log: 324 lines, 282 kept, 42 dropped. 
575 lctl &gt; show trace 
576 Enabling output of type &quot;trace&quot; 
577 lctl &gt; filter portals 
578 Disabling output from subsystem &quot;portals&quot; 
579 lctl &gt; debug_kernel /tmp/lustre_logs/log_noportals 
580 Debug log: 324 lines, 258 kept, 66 dropped. 
581 </screen>
582       </section>
583     </section>
584     <section remap="h3">
585       <title>Dumping the Buffer to a File (<literal>debug_daemon</literal>)</title>
586       <para>The <literal>lctl debug_daemon</literal> command is used to continuously dump the <literal>debug_kernel</literal> buffer to a user-specified file. This functionality uses a kernel thread to continuously dump the messages from the kernel debug log, so that much larger debug logs can be saved over a longer time than would fit in the kernel ringbuffer.</para>
587       <para>The <literal>debug_daemon</literal> is highly dependent on file system write speed. File system write operations may not be fast enough to flush out all of the <literal>debug_buffer</literal> if the Lustre file system is under heavy system load and continues to log debug messages to the <literal>debug_buffer</literal>. The <literal>debug_daemon</literal> will write the message <literal>DEBUG MARKER: Trace buffer full</literal> into the <literal>debug_buffer</literal> to indicate the <literal>debug_buffer</literal> contents are overlapping before the <literal>debug_daemon</literal> flushes data to a file.</para>
588       <para>Users can use the <literal>lctl debug_daemon</literal> command to start or stop the Lustre daemon from dumping the <literal>debug_buffer</literal> to a file.</para>
589       <section remap="h4">
590         <title><literal>lctl debug_daemon</literal> Commands</title>
591         <para>To initiate the <literal>debug_daemon</literal> to start dumping the <literal>debug_buffer</literal> into a file, run as the root user:</para>
592         <screen>lctl debug_daemon start <replaceable>filename</replaceable> [<replaceable>megabytes</replaceable>]</screen>
593         <para>The debug log will be written to the specified filename from the kernel.  The file will be limited to the optionally specified number of megabytes.</para>
594         <para>The daemon wraps around and dumps data to the beginning of the file when the output file size is over the limit of the user-specified file size. To decode the dumped file to ASCII and sort the log entries by time, run:</para>
595         <screen>lctl debug_file <replaceable>filename</replaceable> &gt; <replaceable>newfile</replaceable></screen>
596         <para>The output is internally sorted by the <literal>lctl</literal> command.</para>
597         <para>To stop the <literal>debug_daemon</literal> operation and flush the file output, run:</para>
598         <screen>lctl debug_daemon stop</screen>
599         <para>Otherwise, <literal>debug_daemon</literal> is shut down as part of the Lustre file system shutdown process. Users can restart <literal>debug_daemon</literal> by using start command after each stop command issued.</para>
600         <para>This is an example using <literal>debug_daemon</literal> with the interactive mode of <literal>lctl</literal> to dump debug logs to a 40 MB file.</para>
601         <screen>lctl</screen>
602         <screen>lctl &gt; debug_daemon start /var/log/lustre.40.bin 40 </screen>
603         <screen><replaceable>run filesystem operations to debug</replaceable></screen>
604         <screen>lctl &gt; debug_daemon stop </screen>
605         <screen>lctl &gt; debug_file /var/log/lustre.bin /var/log/lustre.log</screen>
606         <para>To start another daemon with an unlimited file size, run:</para>
607         <screen>lctl &gt; debug_daemon start /var/log/lustre.bin </screen>
608         <para>The text message <literal>*** End of debug_daemon trace log ***</literal> appears at the end of each output file.</para>
609       </section>
610     </section>
611     <section remap="h3">
612       <title><indexterm><primary>debugging</primary><secondary>kernel debug log</secondary></indexterm>Controlling Information Written to the Kernel Debug Log</title>
613       <para>The <literal>lctl set_param subsystem_debug=<replaceable>subsystem_mask</replaceable></literal> and <literal>lctl set_param debug=<replaceable>debug_mask</replaceable></literal> are used to determine which information is written to the debug log. The subsystem_debug mask determines the information written to the log based on the functional area of the code (such as lnet, osc, or ldlm). The debug mask controls information based on the message type (such as info, error, trace, or malloc). For a complete list of possible debug masks use the <literal>lctl debug_list types</literal> command.</para>
614       <para>To turn off Lustre debugging completely:</para>
615       <screen>lctl set_param debug=0 </screen>
616       <para>To turn on full Lustre debugging:</para>
617       <screen>lctl set_param debug=-1 </screen>
618       <para>To list all possible debug masks:</para>
619       <screen>lctl debug_list types</screen>
620       <para>To log only messages related to network communications:</para>
621       <screen>lctl set_param debug=net </screen>
622       <para>To turn on logging of messages related to network communications and existing debug flags:</para>
623       <screen>lctl set_param debug=+net </screen>
624       <para>To turn off network logging with changing existing flags:</para>
625       <screen>lctl set_param debug=-net </screen>
626       <para>The various options available to print to kernel debug logs are listed in <literal>libcfs/include/libcfs/libcfs.h</literal></para>
627     </section>
628     <section remap="h3">
629       <title><indexterm><primary>debugging</primary><secondary>using strace</secondary></indexterm>Troubleshooting with <literal>strace</literal></title>
630       <para>The <literal>strace</literal> utility provided with the Linux distribution enables system calls to be traced by intercepting all the system calls made by a process and recording the system call name, arguments, and return values.</para>
631       <para>To invoke <literal>strace</literal> on a program, enter:</para>
632       <screen>$ strace <replaceable>program</replaceable> <replaceable>[arguments]</replaceable> </screen>
633       <para>Sometimes, a system call may fork child processes. In this situation, use the <literal>-f</literal> option of <literal>strace</literal> to trace the child processes:</para>
634       <screen>$ strace -f <replaceable>program</replaceable> <replaceable>[arguments]</replaceable> </screen>
635       <para>To redirect the <literal>strace</literal> output to a file, enter:</para>
636       <screen>$ strace -o <replaceable>filename</replaceable> <replaceable>program</replaceable> <replaceable>[arguments]</replaceable> </screen>
637       <para>Use the <literal>-ff</literal> option, along with <literal>-o</literal>, to save the trace output in <literal>filename.pid</literal>, where <literal>pid</literal> is the process ID of the process being traced. Use the <literal>-ttt</literal> option to timestamp all lines in the strace output, so they can be correlated to operations in the lustre kernel debug log.</para>
638     </section>
639     <section remap="h3">
640       <title><indexterm><primary>debugging</primary><secondary>disk contents</secondary></indexterm>Looking at Disk Content</title>
641       <para>In a Lustre file system, the inodes on the metadata server contain extended attributes
642         (EAs) that store information about file striping. EAs contain a list of all object IDs and
643         their locations (that is, the OST that stores them). The <literal>lfs</literal> tool can be
644         used to obtain this information for a given file using the <literal>getstripe</literal>
645         subcommand. Use a corresponding <literal>lfs setstripe</literal> command to specify striping
646         attributes for a new file or directory.</para>
647       <para>The <literal>lfs getstripe</literal> command takes a Lustre filename as input and lists
648         all the objects that form a part of this file. To obtain this information for the file
649           <literal>/mnt/testfs/frog</literal> in a Lustre file system, run:</para>
650       <screen>$ lfs getstripe /mnt/testfs/frog
651 lmm_stripe_count:   2
652 lmm_stripe_size:    1048576
653 lmm_pattern:        1
654 lmm_layout_gen:     0
655 lmm_stripe_offset:  2
656         obdidx           objid          objid           group
657              2          818855        0xc7ea7               0
658              0          873123        0xd52a3               0
659         </screen>
660       <para>The <literal>debugfs</literal> tool is provided in the
661           <literal>e2fsprogs</literal> package. It can be used for interactive
662           debugging of an <literal>ldiskfs</literal> file system. The
663           <literal>debugfs</literal> tool can either be used to check status or
664           modify information in the file system. In a Lustre file system, all
665           objects that belong to a file are stored in an underlying
666           <literal>ldiskfs</literal> file system on the OSTs. The file system
667           uses the object IDs as the file names. Once the object IDs are known,
668           use the <literal>debugfs</literal> tool to obtain the attributes of
669           all objects from different OSTs.</para>
670       <para>A sample run for the <literal>/mnt/testfs/frog</literal> file used
671           in the above example is shown here:</para>
672       <screen>$ debugfs -c -R "stat O/0/d$((818855 % 32))/818855" /dev/vgmyth/lvmythost2
673
674 debugfs 1.41.90.wc3 (28-May-2011)
675 /dev/vgmyth/lvmythost2: catastrophic mode - not reading inode or group bitmaps
676 Inode: 227649   Type: regular    Mode:  0666   Flags: 0x80000
677 Generation: 1375019198    Version: 0x0000002f:0000728f
678 User:  1000   Group:  1000   Size: 2800
679 File ACL: 0    Directory ACL: 0
680 Links: 1   Blockcount: 8
681 Fragment:  Address: 0    Number: 0    Size: 0
682  ctime: 0x4e177fe5:00000000 -- Fri Jul  8 16:08:37 2011
683  atime: 0x4d2e2397:00000000 -- Wed Jan 12 14:56:39 2011
684  mtime: 0x4e177fe5:00000000 -- Fri Jul  8 16:08:37 2011
685 crtime: 0x4c3b5820:a364117c -- Mon Jul 12 12:00:00 2010
686 Size of extra inode fields: 28
687 Extended attributes stored in inode body: 
688   fid = "08 80 24 00 00 00 00 00 28 8a e7 fc 00 00 00 00 a7 7e 0c 00 00 00 00 00
689  00 00 00 00 00 00 00 00 " (32)
690   fid: objid=818855 seq=0 parent=[0x248008:0xfce78a28:0x0] stripe=0
691 EXTENTS:
692 (0):63331288
693       </screen>
694     </section>
695     <section remap="h3">
696       <title>Finding the Lustre UUID of an OST</title>
697       <para>To determine the Lustre UUID of an OST disk (for example, if you mix up the cables on your OST devices or the SCSI bus numbering suddenly changes and the SCSI devices get new names), it is possible to extract this from the last_rcvd file using debugfs:</para>
698       <screen>debugfs -c -R "dump last_rcvd /tmp/last_rcvd" /dev/sdc
699 strings /tmp/last_rcvd | head -1
700 myth-OST0004_UUID
701       </screen>
702       <para>It is also possible (and easier) to extract this from the file system label using the
703           <literal>dumpe2fs</literal> command:</para>
704       <screen>dumpe2fs -h /dev/sdc | grep volume
705 dumpe2fs 1.41.90.wc3 (28-May-2011)
706 Filesystem volume name:   myth-OST0004
707       </screen>
708       <para>The debugfs and dumpe2fs commands are well documented in the <literal>debugfs(8)</literal> and <literal>dumpe2fs(8)</literal> manual pages.</para>
709     </section>
710     <section remap="h3">
711       <title>Printing Debug Messages to the Console</title>
712       <para>To dump debug messages to the console (<literal>/var/log/messages</literal>), set the corresponding debug mask in the <literal>printk</literal> flag:</para>
713       <screen>lctl set_param printk=-1 </screen>
714       <para>This slows down the system dramatically. It is also possible to selectively enable or disable this capability for particular flags using:<literal>lctl set_param printk=+vfstrace</literal> and <literal>lctl set_param printk=-vfstrace </literal>.</para>
715       <para>It is possible to disable warning, error, and console messages, though it is strongly recommended to have something like <literal>lctl debug_daemon</literal> running to capture this data to a local file system for failure detection purposes.</para>
716     </section>
717     <section remap="h3">
718       <title>Tracing Lock Traffic</title>
719       <para>The Lustre software provides a specific debug type category for tracing lock traffic.
720         Use:</para>
721       <screen>lctl&gt; filter all_types 
722 lctl&gt; show dlmtrace 
723 lctl&gt; debug_kernel [<replaceable>filename</replaceable>] </screen>
724     </section>
725     <section remap="h3">
726       <title>Controlling Console Message Rate Limiting</title>
727       <para>Some console messages which are printed by Lustre are rate limited.  When such messages are printed, they may be followed by a message saying "Skipped N previous similar message(s)," where N is the number of messages skipped.  This rate limiting can be completely disabled by a libcfs module parameter called <literal>libcfs_console_ratelimit</literal>.  To disable console message rate limiting, add this line to <literal>/etc/modprobe.d/lustre.conf</literal> and then reload Lustre modules.</para>
728       <screen>options libcfs libcfs_console_ratelimit=0</screen>
729       <para>It is also possible to set the minimum and maximum delays between rate-limited console messages using the module parameters <literal>libcfs_console_max_delay</literal> and <literal>libcfs_console_min_delay</literal>.  Set these in <literal>/etc/modprobe.d/lustre.conf</literal> and then reload Lustre modules.  Additional information on libcfs module parameters is available via <literal>modinfo</literal>:</para>
730       <screen>modinfo libcfs</screen>
731     </section>
732   </section>
733   <section xml:id="dbdoclet.50438274_80443">
734     <title><indexterm><primary>debugging</primary><secondary>developers tools</secondary></indexterm>Lustre Debugging for Developers</title>
735     <para>The procedures in this section may be useful to developers debugging Lustre source
736       code.</para>
737     <section remap="h3">
738       <title>Adding Debugging to the Lustre Source Code</title>
739       <para>The debugging infrastructure provides a number of macros that can be used in Lustre source code to aid in debugging or reporting serious errors.</para>
740       <para>To use these macros, you will need to set the <literal>DEBUG_SUBSYSTEM</literal> variable at the top of the file as shown below:</para>
741       <screen>#define DEBUG_SUBSYSTEM S_PORTALS</screen>
742       <para>A list of available macros with descriptions is provided in the table below.</para>
743       <informaltable frame="all">
744         <tgroup cols="2">
745           <colspec colname="c1" colwidth="50*"/>
746           <colspec colname="c2" colwidth="50*"/>
747           <thead>
748             <row>
749               <entry>
750                 <para><emphasis role="bold">Macro</emphasis></para>
751               </entry>
752               <entry>
753                 <para><emphasis role="bold">Description</emphasis></para>
754               </entry>
755             </row>
756           </thead>
757           <tbody>
758             <row>
759               <entry>
760                 <para> <emphasis role="bold">
761                     <literal>LBUG()</literal>
762                   </emphasis></para>
763               </entry>
764               <entry>
765                 <para>A panic-style assertion in the kernel which causes the Lustre file system to
766                   dump its circular log to the <literal>/tmp/lustre-log</literal> file. This file
767                   can be retrieved after a reboot. <literal>LBUG()</literal> freezes the thread to
768                   allow capture of the panic stack. A system reboot is needed to clear the
769                   thread.</para>
770               </entry>
771             </row>
772             <row>
773               <entry>
774                 <para> <emphasis role="bold">
775                     <literal>LASSERT()</literal>
776                   </emphasis></para>
777               </entry>
778               <entry>
779                 <para>Validates a given expression as true, otherwise calls LBUG(). The failed expression is printed on the console, although the values that make up the expression are not printed.</para>
780               </entry>
781             </row>
782             <row>
783               <entry>
784                 <para> <emphasis role="bold">
785                     <literal>LASSERTF()</literal>
786                   </emphasis></para>
787               </entry>
788               <entry>
789                 <para>Similar to <literal>LASSERT()</literal> but allows a free-format message to be printed, like <literal>printf/printk</literal>.</para>
790               </entry>
791             </row>
792             <row>
793               <entry>
794                 <para> <emphasis role="bold">
795                     <literal>CDEBUG()</literal>
796                   </emphasis></para>
797               </entry>
798               <entry>
799                 <para>The basic, most commonly used debug macro that takes just one more argument than standard <literal>printf()</literal> - the debug type. This message adds to the debug log with the debug mask set accordingly. Later, when a user retrieves the log for troubleshooting, they can filter based on this type.</para>
800                 <para><literal>CDEBUG(D_INFO, &quot;debug message: rc=%d\n&quot;, number);</literal></para>
801               </entry>
802             </row>
803             <row>
804               <entry>
805                 <para> <emphasis role="bold">
806                     <literal>CDEBUG_LIMIT()</literal>
807                   </emphasis></para>
808               </entry>
809               <entry>
810                 <para> Behaves similarly to <literal>CDEBUG()</literal>, but rate limits this message when printing to the console (for <literal>D_WARN</literal>, <literal>D_ERROR</literal>, and <literal>D_CONSOLE</literal> message types. This is useful for messages that use a variable debug mask:</para>
811                 <para><literal>CDEBUG(mask, &quot;maybe bad: rc=%d\n&quot;, rc);</literal></para>
812               </entry>
813             </row>
814             <row>
815               <entry>
816                 <para> <emphasis role="bold">
817                     <literal>CERROR()</literal>
818                   </emphasis></para>
819               </entry>
820               <entry>
821                 <para>Internally using <literal>CDEBUG_LIMIT(D_ERROR, ...)</literal>, which unconditionally prints the message in the debug log and to the console. This is appropriate for serious errors or fatal conditions.  Messages printed to the console are prefixed with <literal>LustreError:</literal>, and are rate-limited, to avoid flooding the console with duplicates.</para>
822                 <para><literal>CERROR(&quot;Something bad happened: rc=%d\n&quot;, rc);</literal></para>
823               </entry>
824             </row>
825             <row>
826               <entry>
827                 <para> <emphasis role="bold">
828                     <literal>CWARN()</literal>
829                   </emphasis></para>
830               </entry>
831               <entry>
832                 <para> Behaves similarly to <literal>CERROR()</literal>, but prefixes the messages with <literal>Lustre:</literal>. This is appropriate for important, but not fatal conditions.  Messages printed to the console are rate-limited.</para>
833               </entry>
834             </row>
835             <row>
836               <entry>
837                 <para> <emphasis role="bold">
838                     <literal>CNETERR()</literal>
839                   </emphasis></para>
840               </entry>
841               <entry>
842                 <para> Behaves similarly to <literal>CERROR()</literal>, but prints error messages for LNet if <literal>D_NETERR</literal> is set in the <literal>debug</literal> mask. This is appropriate for serious networking errors. Messages printed to the console are rate-limited.</para>
843               </entry>
844             </row>
845             <row>
846               <entry>
847                 <para> <emphasis role="bold">
848                     <literal>DEBUG_REQ()</literal>
849                   </emphasis></para>
850               </entry>
851               <entry>
852                 <para>Prints information about the given <literal>ptlrpc_request</literal> structure.</para>
853                 <para><literal>DEBUG_REQ(D_RPCTRACE, req, &quot;"Handled RPC: rc=%d\n&quot;, rc);</literal></para>
854               </entry>
855             </row>
856             <row>
857               <entry>
858                 <para> <emphasis role="bold">
859                     <literal>ENTRY</literal>
860                   </emphasis></para>
861               </entry>
862               <entry>
863                 <para> Add messages to the entry of a function to aid in call tracing (takes no arguments). When using these macros, cover all exit conditions with a single <literal>EXIT</literal>, <literal>GOTO()</literal>, or <literal>RETURN()</literal> macro to avoid confusion when the debug log reports that a function was entered, but never exited.</para>
864               </entry>
865             </row>
866             <row>
867               <entry>
868                 <para> <emphasis role="bold">
869                     <literal>EXIT</literal>
870                   </emphasis></para>
871               </entry>
872               <entry>
873                 <para> Mark the exit of a function, to match <literal>ENTRY</literal> (takes no arguments).</para>
874               </entry>
875             </row>
876             <row>
877               <entry>
878                 <para> <emphasis role="bold">
879                     <literal>GOTO()</literal>
880                   </emphasis></para>
881               </entry>
882               <entry>
883                 <para> Mark when code jumps via <literal>goto</literal> to the end of a function, to match <literal>ENTRY</literal>, and prints out the goto label and function return code in signed and unsigned decimal, and hexadecimal format.</para>
884               </entry>
885             </row>
886             <row>
887               <entry>
888                 <para> <emphasis role="bold">
889                     <literal>RETURN()</literal>
890                   </emphasis></para>
891               </entry>
892               <entry>
893                 <para> Mark the exit of a function, to match <literal>ENTRY</literal>, and prints out the function return code in signed and unsigned decimal, and hexadecimal format.</para>
894               </entry>
895             </row>
896             <row>
897               <entry>
898                 <para> <emphasis role="bold">
899                     <literal>LDLM_DEBUG()</literal>
900                   </emphasis></para>
901                 <para> <emphasis role="bold">
902                     <literal>LDLM_DEBUG_NOLOCK()</literal>
903                   </emphasis></para>
904               </entry>
905               <entry>
906                 <para>Used when tracing LDLM locking operations. These macros build a thin trace that shows the locking requests on a node, and can also be linked across the client and server node using the printed lock handles.</para>
907               </entry>
908             </row>
909             <row>
910               <entry>
911                 <para> <emphasis role="bold">
912                     <literal>OBD_FAIL_CHECK()</literal>
913                   </emphasis></para>
914               </entry>
915               <entry>
916                 <para>Allows insertion of failure points into the Lustre source code. This is useful
917                   to generate regression tests that can hit a very specific sequence of events. This
918                   works in conjunction with &quot;<literal>lctl set_param
919                       fail_loc=<replaceable>fail_loc</replaceable></literal>&quot; to set a specific
920                   failure point for which a given <literal>OBD_FAIL_CHECK()</literal> will
921                   test.</para>
922               </entry>
923             </row>
924             <row>
925               <entry>
926                 <para> <emphasis role="bold">
927                     <literal>OBD_FAIL_TIMEOUT()</literal>
928                   </emphasis></para>
929               </entry>
930               <entry>
931                 <para>Similar to <literal>OBD_FAIL_CHECK()</literal>. Useful to simulate hung, blocked or busy processes or network devices. If the given <literal>fail_loc</literal> is hit, <literal>OBD_FAIL_TIMEOUT()</literal> waits for the specified number of seconds.</para>
932               </entry>
933             </row>
934             <row>
935               <entry>
936                 <para> <emphasis role="bold">
937                     <literal>OBD_RACE()</literal>
938                   </emphasis></para>
939               </entry>
940               <entry>
941                 <para>Similar to <literal>OBD_FAIL_CHECK()</literal>. Useful to have multiple processes execute the same code concurrently to provoke locking races. The first process to hit <literal>OBD_RACE()</literal> sleeps until a second process hits <literal>OBD_RACE()</literal>, then both processes continue.</para>
942               </entry>
943             </row>
944             <row>
945               <entry>
946                 <para> <emphasis role="bold">
947                     <literal>OBD_FAIL_ONCE</literal>
948                   </emphasis></para>
949               </entry>
950               <entry>
951                 <para>A flag set on a <literal>fail_loc</literal> breakpoint to cause the <literal>OBD_FAIL_CHECK()</literal> condition to be hit only one time. Otherwise, a <literal>fail_loc</literal> is permanent until it is cleared with &quot;<literal>lctl set_param fail_loc=0</literal>&quot;.</para>
952               </entry>
953             </row>
954             <row>
955               <entry>
956                 <para> <emphasis role="bold">
957                     <literal>OBD_FAIL_RAND</literal>
958                   </emphasis></para>
959               </entry>
960               <entry>
961                 <para>A flag set on a <literal>fail_loc</literal> breakpoint to cause <literal>OBD_FAIL_CHECK()</literal> to fail randomly; on average every (1 / fail_val) times.</para>
962               </entry>
963             </row>
964             <row>
965               <entry>
966                 <para> <emphasis role="bold">
967                     <literal>OBD_FAIL_SKIP</literal>
968                   </emphasis></para>
969               </entry>
970               <entry>
971                 <para>A flag set on a <literal>fail_loc</literal> breakpoint to cause <literal>OBD_FAIL_CHECK()</literal> to succeed <literal>fail_val</literal> times, and then fail permanently or once with <literal>OBD_FAIL_ONCE</literal>.</para>
972               </entry>
973             </row>
974             <row>
975               <entry>
976                 <para> <emphasis role="bold">
977                     <literal>OBD_FAIL_SOME</literal>
978                   </emphasis></para>
979               </entry>
980               <entry>
981                 <para>A flag set on <literal>fail_loc</literal> breakpoint to cause <literal>OBD_FAIL_CHECK</literal> to fail <literal>fail_val</literal> times, and then succeed.</para>
982               </entry>
983             </row>
984           </tbody>
985         </tgroup>
986       </informaltable>
987     </section>
988     <section remap="h3">
989       <title>Accessing the <literal>ptlrpc</literal> Request History</title>
990       <para>Each service maintains a request history, which can be useful for first occurrence troubleshooting.</para>
991       <para><literal>ptlrpc</literal> is an RPC protocol layered on LNet that deals with stateful servers and has semantics and built-in support for recovery.</para>
992       <para>The ptlrpc request history works as follows:</para>
993       <orderedlist>
994         <listitem>
995           <para><literal>request_in_callback()</literal> adds the new request to the service&apos;s request history.</para>
996         </listitem>
997         <listitem>
998           <para>When a request buffer becomes idle, it is added to the service&apos;s request buffer history list.</para>
999         </listitem>
1000         <listitem>
1001           <para>Buffers are culled from the service request buffer history if it has grown above <literal>req_buffer_history_max</literal> and its reqs are removed from the service request history.</para>
1002         </listitem>
1003       </orderedlist>
1004       <para>Request history is accessed and controlled using the following /proc files under the service directory:</para>
1005       <itemizedlist>
1006         <listitem>
1007           <para><literal>req_buffer_history_len </literal></para>
1008           <para>Number of request buffers currently in the history</para>
1009         </listitem>
1010       </itemizedlist>
1011       <itemizedlist>
1012         <listitem>
1013           <para><literal>req_buffer_history_max </literal></para>
1014           <para>Maximum number of request buffers to keep</para>
1015         </listitem>
1016       </itemizedlist>
1017       <itemizedlist>
1018         <listitem>
1019           <para><literal>req_history </literal> </para>
1020           <para>The request history</para>
1021         </listitem>
1022       </itemizedlist>
1023       <para>Requests in the history include &quot;live&quot; requests that are currently being handled. Each line in <literal>req_history</literal> looks like:</para>
1024       <screen><replaceable>sequence</replaceable>:<replaceable>target_NID</replaceable>:<replaceable>client_NID</replaceable>:<replaceable>cliet_xid</replaceable>:<replaceable>request_length</replaceable>:<replaceable>rpc_phase</replaceable> <replaceable>service_specific_data</replaceable> </screen>
1025       <informaltable frame="all">
1026         <tgroup cols="2">
1027           <colspec colname="c1" colwidth="50*"/>
1028           <colspec colname="c2" colwidth="50*"/>
1029           <thead>
1030             <row>
1031               <entry>
1032                 <para><emphasis role="bold">Parameter</emphasis></para>
1033               </entry>
1034               <entry>
1035                 <para><emphasis role="bold">Description</emphasis></para>
1036               </entry>
1037             </row>
1038           </thead>
1039           <tbody>
1040             <row>
1041               <entry>
1042                 <para> <emphasis role="bold">
1043                     <literal>seq</literal>
1044                   </emphasis></para>
1045               </entry>
1046               <entry>
1047                 <para> Request sequence number</para>
1048               </entry>
1049             </row>
1050             <row>
1051               <entry>
1052                 <para> <literal>
1053                     <replaceable>target NID</replaceable>
1054                   </literal></para>
1055               </entry>
1056               <entry>
1057                 <para> Destination <literal>NID</literal> of the incoming request</para>
1058               </entry>
1059             </row>
1060             <row>
1061               <entry>
1062                 <para> <literal>
1063                     <replaceable>client ID</replaceable>
1064                   </literal></para>
1065               </entry>
1066               <entry>
1067                 <para> Client <literal>PID</literal> and <literal>NID</literal></para>
1068               </entry>
1069             </row>
1070             <row>
1071               <entry>
1072                 <para> 
1073                         <literal>
1074                     <replaceable>xid</replaceable>
1075                   </literal>
1076                   </para>
1077               </entry>
1078               <entry>
1079                 <para> <literal>rq_xid</literal></para>
1080               </entry>
1081             </row>
1082             <row>
1083               <entry>
1084                 <para> <emphasis role="bold">
1085                     <literal>length</literal>
1086                   </emphasis></para>
1087               </entry>
1088               <entry>
1089                 <para> Size of the request message</para>
1090               </entry>
1091             </row>
1092             <row>
1093               <entry>
1094                 <para> <emphasis role="bold">
1095                     <literal>phase</literal>
1096                   </emphasis></para>
1097               </entry>
1098               <entry>
1099                 <para><itemizedlist>
1100                     <listitem>
1101                       <para>New (waiting to be handled or could not be unpacked)</para>
1102                     </listitem>
1103                     <listitem>
1104                       <para>Interpret (unpacked or being handled)</para>
1105                     </listitem>
1106                     <listitem>
1107                       <para>Complete (handled)</para>
1108                     </listitem>
1109                   </itemizedlist></para>
1110               </entry>
1111             </row>
1112             <row>
1113               <entry>
1114                 <para> <emphasis role="bold">
1115                     <literal>svc specific</literal>
1116                   </emphasis></para>
1117               </entry>
1118               <entry>
1119                 <para>Service-specific request printout. Currently, the only service that does this is the OST (which prints the opcode if the message has been unpacked successfully</para>
1120               </entry>
1121             </row>
1122           </tbody>
1123         </tgroup>
1124       </informaltable>
1125     </section>
1126     <section remap="h3">
1127       <title><indexterm><primary>debugging</primary><secondary>memory leaks</secondary></indexterm>Finding Memory Leaks Using <literal>leak_finder.pl</literal></title>
1128       <para>Memory leaks can occur in code when memory has been allocated and then not freed once it is no longer required. The <literal>leak_finder.pl</literal> program provides a way to find memory leaks.</para>
1129       <para>Before running this program, you must turn on debugging to collect all <literal>malloc</literal> and free entries. Run:</para>
1130       <screen>lctl set_param debug=+malloc </screen>
1131       <para>Then complete the following steps:</para>
1132       <orderedlist>
1133         <listitem>
1134           <para>Dump the log into a user-specified log file using lctl (see <xref linkend="dbdoclet.50438274_62472"/>).</para>
1135         </listitem>
1136         <listitem>
1137           <para>Run the leak finder on the newly-created log dump:</para>
1138           <screen>perl leak_finder.pl <replaceable>ascii-logname</replaceable></screen>
1139         </listitem>
1140       </orderedlist>
1141       <para>The output is:</para>
1142       <screen>malloced 8bytes at a3116744 (called pathcopy) 
1143 (lprocfs_status.c:lprocfs_add_vars:80) 
1144 freed 8bytes at a3116744 (called pathcopy) 
1145 (lprocfs_status.c:lprocfs_add_vars:80) 
1146 </screen>
1147       <para>The tool displays the following output to show the leaks found:</para>
1148       <screen>Leak:32bytes allocated at a23a8fc(service.c:ptlrpc_init_svc:144,debug file line 241)</screen>
1149     </section>
1150   </section>
1151 </chapter>