Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1364994

Summary: lvconvert has wrong argument logic deduction
Product: Red Hat Enterprise Linux 7 Reporter: Roman Bednář <rbednar>
Component: lvm2Assignee: David Teigland <teigland>
lvm2 sub component: Changing Logical Volumes QA Contact: cluster-qe <cluster-qe>
Status: CLOSED NOTABUG Docs Contact:
Severity: unspecified    
Priority: unspecified CC: agk, heinzm, jbrassow, msnitzer, prajnoha, zkabelac
Version: 7.3   
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-09-09 15:14:52 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:

Description Roman Bednář 2016-08-08 10:32:16 UTC
Description of problem:

This bug is based on BZ #1353759 to track issue related to wrong argument parsing. The current logic contains a bug because the implicit deduction of lvconvert considers last argument as PV while it should estimate logic and calculate cache-pool or cache type instead.

zkabelac:
># Buggy example (should be fixed) as free-arg  vg/lv cannot be used as PV.
>lvconvert --cachepool vg/lv vg/lv

>ATM it gives:
>Physical Volume "vg/lv" not found in Volume Group "vg".

>Internal lvconvert deducing logic missed to calculate cache-pool or cache type.


How reproducible:
always



3.10.0-475.el7.x86_64

lvm2-2.02.161-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
lvm2-libs-2.02.161-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
lvm2-cluster-2.02.161-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
device-mapper-1.02.131-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
device-mapper-libs-1.02.131-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
device-mapper-event-1.02.131-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
device-mapper-event-libs-1.02.131-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016
device-mapper-persistent-data-0.6.3-1.el7    BUILT: Fri Jul 22 12:29:13 CEST 2016
cmirror-2.02.161-2.el7    BUILT: Wed Jul 20 14:48:14 CEST 2016

Comment 1 Roman Bednář 2016-08-08 10:42:09 UTC
wrong package list, here are the ones actually used:

3.10.0-481.el7.x86_64

lvm2-2.02.162-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
lvm2-libs-2.02.162-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
lvm2-cluster-2.02.162-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
device-mapper-1.02.132-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
device-mapper-libs-1.02.132-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
device-mapper-event-1.02.132-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
device-mapper-event-libs-1.02.132-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016
device-mapper-persistent-data-0.6.3-1.el7    BUILT: Fri Jul 22 05:29:13 CDT 2016
cmirror-2.02.162-1.el7    BUILT: Fri Jul 29 02:26:36 CDT 2016

Comment 3 Alasdair Kergon 2016-08-15 22:40:14 UTC
I'm confused!

>lvconvert --cachepool vg/lv vg/lv

Surely that command is nonsense?  Why is vg/lv listed twice?

The "--cachepool vg/lv" piece means to convert existing LV vg/lv into a cache-pool.  Any free args are PVs for the allocation of the extra pieces.

So an error message treating the second vg/lv as a PV doesn't seem unreasonable.

Comment 4 Alasdair Kergon 2016-08-15 22:51:16 UTC
Even if the second LV listed was different LV from the first, I don't see how you could infer anything else for the command to do.

It's clear that --cachepool ALWAYS take an LV argument, and if you want to also cache an LV, then that needs one of:
  --cache LV
  --type cache LV
  -H LV

So the 3 forms are:
  lvconvert --cachepool vg/lv --cache lv2
  lvconvert -H --cachepool vg/lv lv2
  lvconvert --type cache --cachepool vg/lv lv2
with different orderings of the arguments possible as lv2 is a free arg, and only the first listed LV needs a vg/ prefix on it.
So this also works:
  lvconvert -H vg/lv2 --cachepool lv

Any remaining free args are PVs for the allocation.

Comment 5 Zdenek Kabelac 2016-08-16 07:48:28 UTC
(In reply to Alasdair Kergon from comment #4)
> Even if the second LV listed was different LV from the first, I don't see
> how you could infer anything else for the command to do.
> 
> It's clear that --cachepool ALWAYS take an LV argument, and if you want to
> also cache an LV, then that needs one of:
>   --cache LV
>   --type cache LV
>   -H LV
> 
> So the 3 forms are:
>   lvconvert --cachepool vg/lv --cache lv2
>   lvconvert -H --cachepool vg/lv lv2
>   lvconvert --type cache --cachepool vg/lv lv2
> with different orderings of the arguments possible as lv2 is a free arg, and
> only the first listed LV needs a vg/ prefix on it.
> So this also works:
>   lvconvert -H vg/lv2 --cachepool lv
> 
> Any remaining free args are PVs for the allocation.

Clear logic here comes from our arg parsing:
  lvconvert [OPTIONS] LVNAME [PVLIST]

lvconvert  takes 'free arg' (vg/lv) as a converted LV name before any PV list.

So we have:

lvconvert --type cache-pool  vg/lv

We also have arg --cachepool  which consumes arg:

lvconvert --cachepool vg/lv

When 'freearg' is not given - lvconvert uses already known cachepool parameter.

But since pool needs to allocate also space for metadata (as lvconvert is allowed to create new metadata LVs for conversion) and PV list might be supplied by user as allocation space.

In this case we need to respect free-arg logic - so next arg must be still LV.
And just after this PV list may follow (currently there is a bug).

lvconvert --cachepool vg/lv1  vg/lv1  /dev/pv1...

'lv1' -> convert to cachepool.


Technically we may 'deduce'   cache or cache-pool arg. So even this command:

lvconvert --cachepool  vg/lv1   vg/lv2  

can be still pretty much valid and convert (or just use) vg/lv1 as cachepool
and make vg/lv2  a cache.  ATM we do require  'lvconvert -H' in this case.


It's the same concept we use for convert LV to a thin with external origin:

lvconvert -T --thinpool vg/pool vg/lv

Then here we may possibly also introduce same implicit -T deduction.