1 # Copyright (C) 2011 Red Hat, Inc. All rights reserved.
2 # This file is part of LVM2.
4 # This copyrighted material is made available to anyone wishing to use,
5 # modify, copy, or redistribute it subject to the terms and conditions
6 # of the GNU Lesser General Public License v.2.1.
8 # You should have received a copy of the GNU Lesser General Public License
9 # along with this program; if not, write to the Free Software Foundation,
10 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 # Jonathan Brassow <jbrassow@redhat.com>
15 # Copy this file to ~/.gdbinit or <working_dir>/.gdbinit
18 printf "Loading commands:\n"
19 printf " - dm_list_size <list ptr>\n"
20 printf " - first_seg <LV ptr>\n"
21 printf " - lv_status <LV ptr>\n"
22 printf " - lv_status_r <LV ptr>\n"
23 printf " - lv_is_mirrored <LV ptr>\n"
24 printf " - seg_item <seg ptr> <index>\n"
25 printf " - seg_status <seg ptr>\n"
26 printf " - segs_using_this_lv <seg ptr>\n"
28 printf "Use 'help <command>' for more info\n"
30 printf "Popular breakpoints:\n"
31 printf "break _get_udev_flags\n"
32 printf "run --splitmirrors 1 -n split vg/lv\n"
35 set follow-fork-mode child
38 # foo : function named 'foo' available to user
39 # __foo : an internal function
41 # External functions should have a corresponding 'document'
42 # section. Internal functions should have leading comments
45 set $_DLS_list_head = (struct dm_list *)$arg0
46 set $_DLS_list = $_DLS_list_head->n
49 while (($_DLS_list != $_DLS_list_head) && ($_DLS_size < 100))
50 set $_DLS_list = $_DLS_list->n
54 printf "%d list items\n", $_DLS_size
58 Returns the number of elements in the dm_list
60 Usage: dm_list_size <list ptr>
64 # __first_seg <return> <LV>
67 set $_FS_lv = (struct logical_volume *)$arg1
69 if ($_FS_lv->segments.n != &$_FS_lv->segments)
70 set $arg0 = (struct lv_segment *)$_FS_lv->segments.n
76 set $_lv=(struct logical_volume *)$arg0
78 __first_seg $_seg $_lv
83 printf "No segments (list empty)\n"
88 Returns the pointer to the first segment of an LV
90 Usage: first_seg <LV ptr>
92 WARNING: If the list pointer in 'struct lv_segment' moves,
93 this function will be wrong.
97 # __seg_type <return> <seg> <index>
100 set $_ST_seg = (struct lv_segment *)$arg1
101 set $_ST_index= $arg2
102 set $_ST_area = $_ST_seg->areas[$_ST_index]
103 set $_ST_type = $_ST_area.type
105 set $arg0 = $_ST_type
109 # __seg_item <return> <seg> <index>
112 set $_SI_seg = (struct lv_segment *)$arg1
113 set $_SI_index= $arg2
115 if ($_SI_index < $_SI_seg->area_count)
116 set $_SI_area = $_SI_seg->areas[$_SI_index]
117 set $_SI_type = $_SI_area.type
119 if ($_SI_type == AREA_PV)
120 set $arg0 = $_SI_area.u.pv.pvseg->pv
122 if ($_SI_type == AREA_LV)
123 set $arg0 = $_SI_area.u.lv.lv
130 # __seg_metaitem <return> <seg> <index>
131 define __seg_metaitem
133 set $_SMI_seg = (struct lv_segment *)$arg1
134 set $_SMI_index= $arg2
136 if (($_SMI_index < $_SMI_seg->area_count) && $_SMI_seg->meta_areas)
137 set $_SMI_area = $_SMI_seg->meta_areas[$_SMI_index]
138 set $_SMI_type = $_SMI_area.type
140 if ($_SMI_type == AREA_PV)
141 set $arg0 = $_SMI_area.u.pv.pvseg->pv
143 if ($_SMI_type == AREA_LV)
144 set $arg0 = $_SMI_area.u.lv.lv
153 __seg_item $_item $arg0 $arg1
157 printf "AREA_UNASSIGNED or invalid\n"
164 __seg_metaitem $_metaitem $arg0 $arg1
168 printf "AREA_UNASSIGNED or invalid\n"
173 Returns the pointer to the LV or PV for the indexed area of a segment
175 Usage: seg_item <struct lv_segment *> <index>
177 Example - Getting to the sub-lv of a mirror:
182 $2 = (struct lv_segment *) 0x7128b8
185 $3 = (struct logical_volume *) 0x712688
188 $4 = 0x712770 "lv_mimage_0"
192 set $_s_status = $arg0->status
194 # Constants defined in metadata-exported.h
196 # if ($_s_status & RAID)
197 if ($_s_status & 0x0000000100000000LU)
198 set $_s_status = $_s_status & ~0x0000000100000000LU
201 # if ($_s_status & RAID_META)
202 if ($_s_status & 0x0000000200000000LU)
203 set $_s_status = $_s_status & ~0x0000000200000000LU
206 # if ($_s_status & RAID_IMAGE)
207 if ($_s_status & 0x0000000400000000LU)
208 set $_s_status = $_s_status & ~0x0000000400000000LU
211 # if ($_s_status & MIRRORED)
212 if ($_s_status & 0x00008000U)
213 set $_s_status = $_s_status & ~0x00008000U
216 # if ($_s_status & MIRROR_LOG)
217 if ($_s_status & 0x00020000U)
218 set $_s_status = $_s_status & ~0x00020000U
221 # if ($_s_status & MIRROR_IMAGE)
222 if ($_s_status & 0x00040000U)
223 set $_s_status = $_s_status & ~0x00040000U
224 printf " MIRROR_IMAGE"
226 # if ($_s_status & VISIBLE_LV)
227 if ($_s_status & 0x00000040U)
229 set $_s_status = $_s_status & ~0x00000040U
231 printf " *HIDDEN_LV*"
233 # if ($_s_status & FIXED_MINOR)
234 if ($_s_status & 0x00000080U)
235 set $_s_status = $_s_status & ~0x00000080U
236 printf " FIXED_MINOR"
238 # if ($_s_status & LVM_READ)
239 if ($_s_status & 0x00000100U)
240 set $_s_status = $_s_status & ~0x00000100U
243 # if ($_s_status & LVM_WRITE)
244 if ($_s_status & 0x00000200U)
245 set $_s_status = $_s_status & ~0x00000200U
248 # if ($_s_status & SNAPSHOT)
249 if ($_s_status & 0x00001000U)
250 set $_s_status = $_s_status & ~0x00001000U
253 # if ($_s_status & PVMOVE)
254 if ($_s_status & 0x00002000U)
255 set $_s_status = $_s_status & ~0x00002000U
258 # if ($_s_status & LOCKED)
259 if ($_s_status & 0x00004000U)
260 set $_s_status = $_s_status & ~0x00004000U
263 # if ($_s_status & LV_NOTSYNCED)
264 if ($_s_status & 0x00080000U)
265 set $_s_status = $_s_status & ~0x00080000U
266 printf " LV_NOTSYNCED"
268 # if ($_s_status & CONVERTING)
269 if ($_s_status & 0x00400000U)
270 set $_s_status = $_s_status & ~0x00400000U
273 # if ($_s_status & MERGING)
274 if ($_s_status & 0x10000000U)
275 set $_s_status = $_s_status & ~0x10000000U
280 printf " 0x%x", $_s_status
285 # __print_indent <num indents> [No marks]
286 define __print_indent
287 set $_PI_indent = $arg0
288 set $_PI_lead_mark = 0
291 if ($_PI_indent == 1)
303 set $_PI_lead_mark = 1
310 # Use __lv because we don't want to overwrite higher functions
311 set $__lv = (struct logical_volume *)$arg0
316 printf "%s->status:", $__lv->name
322 Display the flags that are set on an LV.
324 Usage: lv_status <LV ptr>
328 set $_seg=(struct lv_segment *)$arg0
331 __print_indent $arg1 1
333 printf "[ (%s) seg->status:", $_seg->lv->name
339 Display the flags that are set on an lv_segment.
341 Usage: seg_status <(struct lv_segment *)>
345 # get_only_segment_using_this_lv <return> <LV>
346 define __get_only_segment_using_this_lv
348 set $_lv=(struct logical_volume *)$arg1
349 set $_seg_list_head = &$_lv->segs_using_this_lv
350 set $_s = $_lv->segs_using_this_lv.n
353 while (($_s != $_seg_list_head) && ($_i < 100))
354 set $_seg_list = (struct seg_list *)$_s
355 set $_seg = (struct lv_segment *)$_seg_list->seg
362 printf "More than %s using %s\n", ($_i > 99) ? "100 segments" : "one segment", $_lv->name
369 define segs_using_this_lv
370 set $_lv=(struct logical_volume *)$arg0
371 set $_seg_list_head = &$_lv->segs_using_this_lv
372 set $_s = $_lv->segs_using_this_lv.n
375 if ($_s != $_seg_list_head)
376 printf "Segments using %s\n", $_lv->name
378 printf "No segments using %s\n", $_lv->name
380 while ($_s != $_seg_list_head)
381 set $_seg_list = (struct seg_list *)$_s
382 set $_seg = (struct lv_segment *)$_seg_list->seg
383 printf " %d) seg: %p", $_i, $_seg
384 if ($_seg->lv < 0x200)
385 printf " [BAD LV POINTER FROM THIS SEG]\n"
387 printf " [seg found in %s]\n", $_seg->lv->name
394 document segs_using_this_lv
395 Display the segments (and their associated LV) using an LV
397 Usage: segs_using_this_lv <LV ptr>
400 (gdb) lv_is_mirrored lv
401 lv is mirrored ('core' log)
403 (gdb) segs_using_this_lv lv
407 $1 = (struct lv_segment *) 0x92d360
410 $2 = (struct logical_volume *) 0x928f58
412 (gdb) segs_using_this_lv $2
413 Segments using lv_mimage_0
414 0) seg: 0x92d360 [seg found in lv]
418 # __next_area_index <return> <seg> <seg_item>
419 define __next_area_index
421 set $_seg = (struct lv_segment *)$arg1
425 __seg_item $_item $_seg $_i
426 while ($_item && ($_item != $arg2))
428 __seg_item $_item $_seg $_i
431 # $_i points to current, now get next (if there)
433 __seg_item $_item $_seg $_i
442 # Decend tree, printing LV and seg status as we go. This
443 # performs a depth first approach (but can't come up)
447 # __lv_status_r <sub_lv> <seg using sub_lv>
448 # Try continuing decent of tree by first shifting to the
449 # next 'area' in the seg ($arg1). If no more areas, then
450 # try going to the next segment.
453 set $_lv=(struct logical_volume *)$arg0
454 set $_seg_list_head = &$_lv->segments
455 set $_s = $_lv->segments.n
459 lv_status $_lv $indent
461 set $_seg = (struct lv_segment *)$arg1
463 __next_area_index $_area_index $_seg $arg0
465 # Don't fuck this up. We need the next two lines here.
466 set $_lv=(struct logical_volume *)$_seg->lv
467 set $_seg_list_head = &$_lv->segments
468 set $_s = (struct dm_list *)$_seg
475 if ($_s == $_seg_list_head)
477 __print_indent $indent 1
478 printf "[ No segments for %s ]\n", $_lv->name
480 __get_only_segment_using_this_lv $_seg $_lv
482 if ($_seg && $indent)
484 __lv_status_r $_lv $_seg
487 set $_seg = (struct lv_segment *)$_s
491 seg_status $_seg $indent
493 __seg_type $_type $_seg $_area_index
494 if ($_type == AREA_LV)
497 __seg_metaitem $_lv $_seg $_area_index
499 set $rindent = $indent
501 set $rarea_index = $_area_index
506 set $indent = $rindent
508 set $_area_index = $rarea_index
512 __seg_item $_lv $_seg $_area_index
519 __first_seg $_log_seg $_seg->log_lv
520 lv_status $_seg->log_lv $indent
521 seg_status $_log_seg $indent
525 __get_only_segment_using_this_lv $_seg $_lv
528 __lv_status_r $_lv $_seg
540 Display the status flags of an LV and its sub_lvs.
542 Usage: lv_status_r <LV ptr>
544 This function is useful for checking that all the LVs that
545 compose a logical volume have the correct flags set (and also
546 their associated lv_segments)
549 define lv_is_mirrored
550 set $_lv=(struct logical_volume *)$arg0
551 set $_fs=(struct lv_segment *)$_lv->segments.n
552 set $_log_lv=(struct logical_volume *)$_fs->log_lv
554 # if ($_lv->status & MIRRORED)
555 if ($_lv->status & 0x00008000U)
556 printf "%s is mirrored (", $_lv->name
558 if ($_log_lv->status & 0x00008000U)
559 printf "'mirrored' log)\n"
561 printf "'disk' log)\n"
564 printf "'core' log)\n"
567 printf "%s is not mirrored\n", $_lv->name
571 document lv_is_mirrored
572 Report whether the given LV is mirrored (and its log type).
574 Usage: lv_is_mirrored <LV ptr>