# MCzfsd.ctl:251: Collects ZFS Debug Information # $Id: MCzfsd.ctl,v 1.2 2015/02/19 09:49:20 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/EXPLORER/MCzfsd.ctl,v 1.2 2015/02/19 09:49:20 RDA Exp $ # # Change History # 20150218 PRA Avoid re-running commands for the same device. =head1 NAME EXPLORER:MCzfsd - Collects ZFS Debug Information =head1 DESCRIPTION This module collects debug information about ZFS file systems and pools. =cut use Mrc use Buffer # Initialization var $VALIDATE = true keep $VALIDATE section begin var $ERR = '---## Associated Errors' var $TOC = '%TOC%' var $TOP = '[[#Top][Back to top]]' run EXPLORER:XPLRlib('zfsdebug') #------------------------------------------------------------------------------ # XPLR_zfsd section #------------------------------------------------------------------------------ section XPLR_zfsd # Validate the execution context if or(not(${B_GLOBAL:1}),\ expr('<',get_osv(),10)) return if !and(defined(testFile('x','/usr/sbin/zpool')),\ defined(testFile('x','/usr/sbin/zfs')),\ defined(testFile('x','/usr/sbin/zdb'))) return log_error('Missing required ZFS binaries') call log_run('Processing ZFSD sections ...') # Define some module constants var $ZPOOL = '/usr/sbin/zpool' var $ZFS = '/usr/sbin/zfs' var $ZDB = '/usr/sbin/zdb' # Get the ZFS pools and cache if and(${RUN.EXPLORER.XPLR.ZFS.T_IMP_POOLS/E},\ ${RUN.EXPLORER.XPLR.ZFS.T_POOL_CACHE/E}) {var %imp = %{${RUN.EXPLORER.XPLR.ZFS.T_IMP_POOLS}} var %pcf = %{${RUN.EXPLORER.XPLR.ZFS.T_POOL_CACHE}} } else {if $lim = getTimeout() call setTimeout(expr('*',$lim,3)) var @all = command($cmd = concat($ZPOOL,' list')) var ($flg,%imp) = (true) loop $itm (grepCommand(concat($ZPOOL,' import'),'^\s*pool:\s+(.*)$','1')) var $imp{$itm} = $flg = 0 if $lim call setTimeout($lim) if and($flg,grep(@all,'no pools available','f')) return log_info('No pools available') # Get the cache file from the pool properties call shift(@all) # Discard the header line while ?shift(@all) {var ($nam) = match(last,'^(\S+)') var $arg = quote($nam) var ($pcf{$nam}) = grepCommand(concat($ZPOOL,' get all ',$arg),\ 'cachefile\s*(\S+)','f1') } } =head2 zfsd - ZFS debug information Gathers ZFS devices and pool debug information using the following commands: =over 2 =item o C =item o C =item o C =item o C =item o C =item o C =back =for stopwords Zpool Collects Zpool cache files also. =cut debug ' Inside ZFS debug collection, generating devices and pools report' var (%DEV,%FIL) = () # Perform the collection report zfsd title '---+!! ZFS Devices and Pools Debug Information' title $TOC var @fil = () # Define the collection mcro macro collect_device {var ($dev) = @arg import $TOC,$ZDB keep $TOC,$ZDB var $arg = quote($dev) var $lnk = encode($dev) var $nam = basename($dev) suspend main report concat('zfsd_',$dev) title '---+!! Device: ',$lnk title $TOC call do_exec(\ [concat('disks/zfs/zdb/zdb-l_',$nam),\ $ZDB,concat('-l ',$arg),\ '---+ Labels',\ {out => {mod => true,cat => 'T'}}],\ [concat('disks/zfs/zdb/zdb-lu_',$nam),\ $ZDB,concat('-lu ',$arg),\ '---+ Labels and Uberblocks',\ {out => {mod => true,cat => 'T'}}],\ [concat('disks/zfs/zdb/zdb-lluuucc_',$nam),\ $ZDB,concat('-lluuucc ',$arg),\ '---+ Labels, Uberblocks and Checksum Verification - Verbose',\ {out => {mod => true,cat => 'T'}}]) if isCreated(true) var $lnk = concat('[[',getHtmlLink(true),'][_blank][',$lnk,']]') resume main return $lnk } # Process imported pools call do_exec({cmd => 'TITLE',txt => '---+ ZFS Devices Debug - Imported Pools'}) prefix {write '---+++ Devices' write '|*Device Path*|' } loop $dev (grepCommand($ZDB,"^\s*path.\s*'(.*)'$",'1')) {if missing($DEV{$dev}) var $DEV{$dev} = collect_device($dev) write '|',$DEV{$dev},' |' } if hasOutput(true) write $TOP call do_exec({cmd => 'UNTITLE'}) # Process exported pools call do_exec({cmd => 'TITLE',txt => '---+ ZFS Devices Debug - Exported Pools'}) loop $nam (keys(%imp)) {var $arg = quote($nam) call do_exec(\ {cmd => 'TITLE',txt => concat('---++ Pool: ',encode($nam))},\ [concat('disks/zfs/zdb/zdb-eChu_',$nam),\ $ZDB,concat('-eChu ',$arg),\ '---+++ Configuration, History and Uberblock Information']) prefix {write '---+++ Devices' write '|*Device Path*|' } loop $dev (grepCommand(concat($ZDB,' -Ce ',$nam),"^\s*path.\s*'(.*)'$",'1')) {if missing($DEV{$dev}) var $DEV{$dev} = collect_device($dev) write '|',$DEV{$dev},' |' } if hasOutput(true) write $TOP call do_exec({cmd => 'UNTITLE'}) } call do_exec({cmd => 'UNTITLE'}) # Collect cache files call do_exec({cmd => 'TITLE',txt => '---+ ZFS Devices Debug - Cache Files'}) loop $nam (keys(%pcf)) {var $arg = quote($nam) var $enc = encode($nam) var $fil = cond(compare('eq',$pcf{$nam},'-'),'/etc/zfs/zpool.cache',$pcf{$nam}) var $cch = translate($fil,'/ ','@_') var $far = quote($fil) if missing($FIL{$fil}) {var $FIL{$fil} = 1 call push(@fil,[concat('disks/zfs/cachefile/',$cch),$fil,true]) } var @tbl = command($cmd = concat($ZDB,' -U ',$far)) call do_exec(\ {cmd => 'TITLE',txt => concat('---++ Pool: ',$enc,\ ' -- Cache File: ',encode($fil))},\ {cmd => 'ARRAY',\ det => $cmd,\ nam => concat('disks/zfs/zdb/zdb-U_',$cch),\ tbl => \@tbl,\ ttl => '---+++ Cache File'},\ [concat('disks/zfs/zdb/zdb-U_',$cch,'_-u_',$nam),\ $ZDB,concat('-U ',$far,' -u ',$arg),\ '---+++ Cache File and Pool']) prefix {write '---+++ Devices' write '|*Device Path*|' } loop $val (@tbl) {if match($val,"^\s*path.\s*'(.*)'$") {if missing($DEV{$dev = first}) var $DEV{$dev} = collect_device($dev) write '|',$DEV{$dev},' |' } } if hasOutput(true) write $TOP call do_exec({cmd => 'UNTITLE'}) } call do_exec({cmd => 'UNTITLE'}) # Collect files title '---+ Collected files' title ' * Links point to files that have been collected in their original \ format. Opening them directly in your browser can present \ risks. To prevent them, access the file outside the browser or \ use the link to save them and use an adequate viewer.' prefix write '|*File Path*| *Size*|*Last Modified Date*|' call do_collect_fil(@fil) if hasOutput(true) write $TOP # Add the report to the table of content if isCreated(true) toc '2:[[',getFile(),'][rda_report][ZFS Devices and Pools Debug Information]]' # Adjust the table of content unpretoc =head1 SEE ALSO L, L, L =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut