Bug 1334678

Summary: Make it possible to query lvm2 command status report
Product: [Community] LVM and device-mapper Reporter: Peter Rajnoha <prajnoha>
Component: lvm2Assignee: Peter Rajnoha <prajnoha>
lvm2 sub component: Displaying and Reporting QA Contact: cluster-qe <cluster-qe>
Status: CLOSED UPSTREAM Docs Contact:
Severity: low    
Priority: medium CC: agk, heinzm, jbrassow, msnitzer, pasik, prajnoha, zkabelac
Version: unspecifiedFlags: prajnoha: lvm-technical-solution+
rule-engine: lvm-test-coverage?
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-24 08:40:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1334674    
Bug Blocks: 1334682, 1346079    

Description Peter Rajnoha 2016-05-10 10:22:55 UTC
This is an enhancement to bug #1334674 ("Issue warnings, errors and status per object from lvm2 command line tools via report").

Since status is going to be reported as any other report, reuse existing selection mechanism to query for status of last command when the command is run within lvm shell. Any subsequent command will destroy previous status report and new status report is active which can be queried again.

This feature requires some minor modifications and enhancements to existing code supporting report selection. For now, selection is defined during report intialization (dm_report_init_with_selection) and lines from report are selected as soon as they're reported (dm_report_object).

To support the new feature, we need:

  - to be able to keep data reported even after it's reported on output (currently, the data is trashed as soon as they're reported on output)
  - to be able to define selection criteria any time, not just during report initialization so we can use several queries on same report data set
  - to be able to output same report several times, taking into account current selection criteria

Comment 1 Peter Rajnoha 2016-09-22 12:11:49 UTC
LVM2 supports this feature since lvm2 2.02.158 with the "lastlog" command together with keeping data from any last report. This works while running commands in LVM shell. Then, it's possible to call lastlog as many times as needed with different possible selections (-S|--select).

See also "man 7 lvmreport" for more information.

Example:

# lvm
lvm> lvs
 Logical Volume
 ==============
 LV    LSize Cpy%Sync
 lvol1 4.00m 100.00
 lvol0 4.00m

 Command Log
 ===========
 Seq LogType Context    ObjType ObjName ObjGrp  Msg     Errno RetCode
   1 status  processing lv      lvol0   vg      success     0       1
   2 status  processing lv      lvol1   vg      success     0       1
   3 status  processing vg      vg              success     0       1
   4 status  shell      cmd     lvs             success     0       1

lvm> lastlog
 Command Log
 ===========
 Seq LogType Context    ObjType ObjName ObjGrp  Msg     Errno RetCode
   1 status  processing lv      lvol0   vg      success     0       1
   2 status  processing lv      lvol1   vg      success     0       1
   3 status  processing vg      vg              success     0       1
   4 status  shell      cmd     lvs             success     0       1

lvm> lastlog -S log_object_type=lv
 Command Log
 ===========
 Seq LogType Context    ObjType ObjName ObjGrp  Msg     Errno RetCode
   1 status  processing lv      lvol0   vg      success     0       1
   2 status  processing lv      lvol1   vg      success     0       1

lvm> lastlog -S log_context=shell
 Command Log
 ===========
 Seq LogType Context ObjType ObjName ObjGrp  Msg     Errno RetCode
   4 status  shell   cmd     lvs             success     0       1

lvm> abc
 Command Log
 ===========
 Seq LogType Context ObjType ObjName ObjGrp  Msg                                 Errno RetCode
   1 error   shell   cmd     abc             No such command 'abc'.  Try 'help'.    -1       0
   2 status  shell   cmd     abc             failure                                -1       2