1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
Commit Graph

3973 Commits

Author SHA1 Message Date
Zdenek Kabelac
843ee943ab lvremove: correct return code
Need to return ECMD_FAILED from toollib code.
Add missing stack traces.
2021-03-08 20:24:04 +01:00
Zdenek Kabelac
a125a3bb50 lv_remove: reduce commits for removed LVs
This patch postpones update of lvm metadata for each removed
LV for later moment depending on LV type.

It also queues messages to be printed after such write & commit.

As such there is some change in the behavior - although before
prompt we do make  write&commit happens automatically in some
other error case we rather keep 'existing' state - so there
could be difference in amount of removed & commited LVs.

IMHO introduce logic is slightly better and more save.

But some cases still need the early commit - i.e. thin-removal
and fixing this needs some more thinking.

TODO: improve removal at least with the case of the whole thin-pool.
i.e. we can simply recognize removal of 'all LVs/whole VG'.
2021-03-08 15:25:05 +01:00
Zdenek Kabelac
eb3dcc72eb cleanup: free already checks for NULL 2021-03-02 22:57:35 +01:00
Zdenek Kabelac
56620b9039 toolib: move sigint_caught
Move the check for catched signal to the loop front.
Currently not much usable - but we can improve it later.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
eb1160ee42 lvremove: backup at the end of loop
Taking backup with each removed LV is slowing down the process
considerable and is largerly uneeded. We are supposed to take
backup only on significant points and making sure the backup
is correct when the command is finished.

TODO: check how many other commands can be improved.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
081e47912e cmdline: use binary search
Reduce strcmp() call count by using binary search to find
commands in cmd_names[] and command_names[] arrays.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
589c654562 cmdline: drop MAX and check NULL
Remove MAX_COMMAND_NAMES and check for the last element as NULL pointer.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
e946a5e690 cmdline: lvcreate adds vdopool as vg name provider
Add same logic as with thinpool or cachepool.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
f87d1a2abb commands.h: keep entries alphabetically sorted
For binary search usage commands need to be sorted.
Later patch also adds check if the order would be broken.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
39eee85fff makefiles: better logging
Show only filename instead of full path name when building
in builddir != srcdir
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
8d93d8b7b7 makefiles: fix man-generate rule
Symlink and compiled man-generate binary has to go to builddir.
2021-03-02 22:54:40 +01:00
Zdenek Kabelac
824230e1e2 makefiles: avoid sorting by locales
Localized sort for building source file is not wanted.
2021-03-02 22:54:40 +01:00
David Teigland
83fe6e720f device usage based on devices file
The LVM devices file lists devices that lvm can use.  The default
file is /etc/lvm/devices/system.devices, and the lvmdevices(8)
command is used to add or remove device entries.  If the file
does not exist, or if lvm.conf includes use_devicesfile=0, then
lvm will not use a devices file.  When the devices file is in use,
the regex filter is not used, and the filter settings in lvm.conf
or on the command line are ignored.

LVM records devices in the devices file using hardware-specific
IDs, such as the WWID, and attempts to use subsystem-specific
IDs for virtual device types.  These device IDs are also written
in the VG metadata.  When no hardware or virtual ID is available,
lvm falls back using the unstable device name as the device ID.
When devnames are used, lvm performs extra scanning to find
devices if their devname changes, e.g. after reboot.

When proper device IDs are used, an lvm command will not look
at devices outside the devices file, but when devnames are used
as a fallback, lvm will scan devices outside the devices file
to locate PVs on renamed devices.  A config setting
search_for_devnames can be used to control the scanning for
renamed devname entries.

Related to the devices file, the new command option
--devices <devnames> allows a list of devices to be specified for
the command to use, overriding the devices file.  The listed
devices act as a sort of devices file in terms of limiting which
devices lvm will see and use.  Devices that are not listed will
appear to be missing to the lvm command.

Multiple devices files can be kept in /etc/lvm/devices, which
allows lvm to be used with different sets of devices, e.g.
system devices do not need to be exposed to a specific application,
and the application can use lvm on its own set of devices that are
not exposed to the system.  The option --devicesfile <filename> is
used to select the devices file to use with the command.  Without
the option set, the default system devices file is used.

Setting --devicesfile "" causes lvm to not use a devices file.

An existing, empty devices file means lvm will see no devices.

The new command vgimportdevices adds PVs from a VG to the devices
file and updates the VG metadata to include the device IDs.
vgimportdevices -a will import all VGs into the system devices file.

LVM commands run by dmeventd not use a devices file by default,
and will look at all devices on the system.  A devices file can
be created for dmeventd (/etc/lvm/devices/dmeventd.devices)  If
this file exists, lvm commands run by dmeventd will use it.

Internal implementaion:

- device_ids_read - read the devices file
  . add struct dev_use (du) to cmd->use_devices for each devices file entry
- dev_cache_scan - get /dev entries
  . add struct device (dev) to dev_cache for each device on the system
- device_ids_match - match devices file entries to /dev entries
  . match each du on cmd->use_devices to a dev in dev_cache, using device ID
  . on match, set du->dev, dev->id, dev->flags MATCHED_USE_ID
- label_scan - read lvm headers and metadata from devices
  . filters are applied, those that do not need data from the device
  . filter-deviceid skips devs without MATCHED_USE_ID, i.e.
    skips /dev entries that are not listed in the devices file
  . read lvm label from dev
  . filters are applied, those that use data from the device
  . read lvm metadata from dev
  . add info/vginfo structs for PVs/VGs (info is "lvmcache")
- device_ids_find_renamed_devs - handle devices with unstable devname ID
  where devname changed
  . this step only needed when devs do not have proper device IDs,
    and their dev names change, e.g. after reboot sdb becomes sdc.
  . detect incorrect match because PVID in the devices file entry
    does not match the PVID found when the device was read above
  . undo incorrect match between du and dev above
  . search system devices for new location of PVID
  . update devices file with new devnames for PVIDs on renamed devices
  . label_scan the renamed devs
- continue with command processing
2021-02-23 16:43:32 -06:00
Zdenek Kabelac
0c842ee8ad cleanup: improving message
lvconvert -Z can be used with snaps & pools.
2021-02-23 14:56:48 +01:00
Zdenek Kabelac
5237175cb6 cleanup: simplify initilization
Simplier code and also drop duplicate check for active LV.
2021-02-23 14:56:48 +01:00
Zdenek Kabelac
b5f906e984 cleanup: simply code 2021-02-23 14:56:48 +01:00
Zdenek Kabelac
5ecd65e6f2 lvconvert: change errors to internal ones
Since these errors should never happen, change them to  internal errors.
2021-02-23 14:56:47 +01:00
Zdenek Kabelac
b140bba9fe cache: fix warning test
The cache here is not 'writethough' - so print proper state
(writeback or passthrough)
2021-02-23 14:56:47 +01:00
David Teigland
9e836c77a0 command defs: add missing commas
even though the parser seems to work fine without them
2021-02-22 10:44:01 -06:00
Zdenek Kabelac
a7cb25c877 lvconvert: VDO kernel support before converting
Early check for kernel support of VDO target before starting any
conversion work.
2021-02-17 11:21:35 +01:00
Zdenek Kabelac
a915cd5a46 lvconvert: vdo may convert already formated vdo
User use 'lvconvert -Zn --type vdo-pool' to convert an existing
vdo formated volume and skip lvm2 internal formating.
This however requires user is passing proper matching parameters.
For them user can use --profile|--metadataprofile option whos
support has been also enhanced.

TODO: add support to read values directly from formated volume.
2021-02-17 11:21:35 +01:00
Zdenek Kabelac
f87ff95e32 lvchange: remove unneeded call
Sync is already happining in activate_and_wipe_lvlist().
2021-02-17 11:21:35 +01:00
Zdenek Kabelac
53666d6ee3 lvconvert: thin errorwhenfull and recalculation
When converting an existing LV to thin-pool,
user may now pass also '--errorwhenfull' option
like with 'lvcreate'.

Also recalculate chunksize when performace profile is
used with conversion (again matching lvcreate).

Adds missing flagging for uncropped metadata sizes.
2021-02-17 11:21:35 +01:00
David Teigland
4486f08d51 include lvm version in debug output 2021-02-12 10:51:41 -06:00
Zdenek Kabelac
f90082ce8f lvconvert: read-only origin cannot be merged
When user sets snapshost origin as read-only,
lvm will not allow simple merge and user needs to
flip permission,
2021-02-10 15:39:03 +01:00
Zdenek Kabelac
2895180058 lvchange: snapshot thick origin permission rw/r
User is allowed to change permission for thick origin.
FIXME: it's not quite clear why few others are prohibited to change.
2021-02-10 15:39:03 +01:00
Zdenek Kabelac
2be585b79c pvscan: support disabled event_activation
In past we had this control with use_lvmetad check for
pvscan --cache -aay

Howerer this got lost with lvmetad removal commit:
117160b27e

When user sets lvm.conf global/event_activation=0
pvscan service will no longer auto activate any LVs on appeared PVs.
2021-02-08 23:18:44 +01:00
David Teigland
87ee401eea md component detection changes
Move extra md component detection into the label scan phase.
It had been in set_pv_devices which was deep within the vg_read
phase, which wasn't a good place (better to detect that earlier.)
Now that pv metadata info is available in the scan phase, the pv
details (size and device_hint) can be used for extra md checking.

Use the device_hint from the pv metadata to trigger a full md
component check if the device_hint begins with /dev/md.

Stop triggering full md component checks based on missing
udev info for a dev.

Changes to tests to reflect that the code is now detecting
md components in some test case that it wasn't before.
2021-02-05 16:23:51 -06:00
David Teigland
834cba000a hints: clean up comment and init settings
no behavior change
2021-02-02 15:14:05 -06:00
David Teigland
cb54d0801d cachevol: allow forced detaching of damaged or invalid cachevol
A cachevol can be forcibly detached when it's missing devices.
Also allow this if it's damaged/invalid and unrepairable.
This would be needed to recover data from the origin LV after
a cachevol is lost or damaged beyond repair.
2021-02-02 14:31:23 -06:00
David Teigland
8454ce66c5 writecache: let block_size setting override device block sizes
In cases where lvconvert does not detect a fs block size on the
device, it falls back to choosing a writecache block size based
on the device's LBS and PBS (tries to match those.)

If the user specifies a writecache block size on the command
line (--cachesettings block_size=4096|512), lvconvert currently
fails and reports an error if the user-specified value does not
match the value lvconvert would have chosen based on LBS and PBS.

The purpose of allowing a user-specified value on the command line
is to override what lvconvert would otherwise do, so change this
to just print a warning that the user value does not match the
value that would be chosen based on the LBS/PBS, and then take
the user-specified value as the writecache block size.
2021-02-02 13:52:31 -06:00
Zdenek Kabelac
9fa4c099fb lvconvert: ensure device_name is defined 2021-02-01 12:13:49 +01:00
Zdenek Kabelac
a9fd207192 pvscan: enhance _count_pvid_files_from_lookup_file
Ensure all vars are always properly defined in all paths.
2021-02-01 12:13:49 +01:00
Zdenek Kabelac
abc9265a06 cache: reuse code for metadata min_max
Use update_pool_metadata_min_max() which is shared with
thin-pool metadata min-max updating.

Gives improved messages when converting volumes to metadata.
2021-02-01 12:06:13 +01:00
Zdenek Kabelac
b4212be2e7 thin: improve 16g support for thin pool metadata
Initial support for thin-pool used slightly smaller max size 15.81GiB
for thin-pool metadata. However the real limit later settled at 15.88GiB
(difference is ~64MiB - 16448 4K blocks).

lvm2 could not simply increase the size as it has been using hard cropping
of the loaded metadata device to avoid warnings printing warning of kernel
when the size was bigger (i.e. due to bigger extent_size).

This patch adds the new lvm.conf configurable setting:
allocation/thin_pool_crop_metadata
which defaults to 0 -> no crop of metadata beyond 15.81GiB.
Only user with these sizes of metadata will be affected.

Without cropping lvm2 now limits metadata allocation size to 15.88GiB.
Any space beyond is currently not used by thin-pool target.
Even if i.e. bigger LV is used for metadata via lvconvert,
or allocated bigger because of to large extent size.

With cropping enabled (=1) lvm2 preserves the old limitation
15.81GiB and should allow to work in the evironement with
older lvm2 tools (i.e. older distribution).

Thin-pool metadata with size bigger then 15.81G is now using CROP_METADATA
flag within lvm2 metadata, so older lvm2 recognizes an
incompatible thin-pool and cannot activate such pool!

Users should use uncropped version as it is not suffering
from various issues between thin_repair results and allocated
metadata LV as thin_repair limit is 15.88GiB
Users should use cropping only when really needed!

Patch also better handles resize of thin-pool metadata and prevents resize
beoyond usable size 15.88GiB. Resize beyond 15.81GiB automatically
switches pool to no-crop version. Even with existing bigger thin-pool
metadata command 'lvextend -l+1 vg/pool_tmeta' does the change.

Patch gives better controls 'coverted' metadata LV and
reports less confusing message during conversion.

Patch set also moves the code for updating min/max into pool_manip.c
for better sharing with cache_pool code.
2021-02-01 12:06:13 +01:00
David Teigland
a690d16d29 writecache: use cleaner message instead of table reload
When detaching writecache, make the first stage send a message
to dm-writecache to set the cleaner option.  This is instead of
reloading the dm table with the cleaner option set.  Reloading
the table causes udev to process/probe the dm dev, which gets
stalled because of the writeback activity, and the stalled udev
in turn stalls the lvconvert command when it tries to sync with
udev events.

When getting writecache status we do not need to get
open_count or read_head info, which can cause extra steps.
2021-01-28 15:14:25 -06:00
Zdenek Kabelac
fa2fa9f36d pvscan: ensure read buffer ends with 0
Read buffersize - 1 so the last byte is always 0.
Simplify init of 0 buffers.
Check snprintf result for error and report internal error as it could
happen only via bad compile parameters.
2021-01-22 15:30:37 +01:00
Zdenek Kabelac
5485ec10e2 pvscan: make ret value defined 2021-01-22 15:30:37 +01:00
David Teigland
74adbec77f pvck: fix warning and exit code for non-4k mda1 offset
Print a warning if mda1 is not 4k, 8k or 64k.
Don't exit with an error for any unexpected mda1 offset.
2021-01-19 11:21:20 -06:00
David Teigland
e9503f257a lvconvert: chunksize option was missing with cachedevice 2021-01-07 13:30:48 -06:00
David Teigland
5dbe2fdd9d writecache: fix uncache for two step detach
Fix the two-step writecache detach in commit c32d7fed4f.
In the case of uncache, the cachevol is removed after
detaching the writecache.  When the detach is finished
in the second step, the remove must wait until then.
2020-12-10 15:42:01 -06:00
David Teigland
aba9652e58 lvchange: fix error for foreign vg activation
was using ECMD_FAILED instead of 0.
2020-11-17 09:22:40 -06:00
David Teigland
6316959438 pvck: fix previous commit
line to setup bcache was misplaced in
commit 5a94126e7a
2020-10-28 16:50:47 -05:00
David Teigland
5a94126e7a pvck: fix dev filtering
filters needing io weren't being run because bcache
wasn't set up.  Read the first 4k of the device
before doing filtering or reading ondisk structs to
reduce reads.
2020-10-27 15:43:15 -05:00
David Teigland
c96645781c pvck: handle first mda at non-4096 offset
It's possible for a machine with a non-4k page size
to create a PV with an mda_header at an offset other
than 4k.  Fix pvck --dump to work with these other
mda offsets.  pvck --repair will write a new first
mda at 4096 but lvm with other page sizes will work
with this.
2020-10-27 14:28:54 -05:00
David Teigland
830c20d33c lvchange: allow syncaction check with integrity
syncaction check will detect and correct integrity checksum mismatches.
2020-10-26 14:16:33 -05:00
David Teigland
2c31939827 pvcreate: clean up opening and filtering of args
The args for pvcreate/pvremove (and vgcreate/vgextend
when applicable) were not efficiently opened, scanned,
and filtered.  This change reorganizes the opening
and filtering in the following steps:

- label scan and filter all devs
  . open ro
  . standard label scan at the start of command

- label scan and filter dev args
  . open ro
  . uses full md component check
  . typically the first scan and filter of pvcreate devs

- close and reopen dev args
  . open rw and excl

- repeat label scan and filter dev args
  . using reopened rw excl fd

- wipe and write new headers
  . using reopened rw excl fd
2020-10-26 11:13:27 -05:00
Zdenek Kabelac
413c88116d man: more precise UNIT
Since 'kilobytes' could be seen in 2 way - SI as '1000',
while all programmers sees it as '1024' - switch to
commonly acceptted  KiB, MiB....

Resolves RHBZ 1496255.
2020-10-24 01:42:16 +02:00
David Teigland
f3b723cd8d pvscan: rework to improve PVs without metadata
Restructure the pvscan code, and add new temporary files
that list pvids in a VG, used for processing PVs that
have no metadata.

The new temp files, in /run/lvm/pvs_lookup/<vgname>, allow a
proper pvscan --cache to be done on PVs that have no metadata.
pvscan --cache <dev> is only supposed to read <dev>, but when
<dev> has no metadata, this had not been possible.  The
command had to fall back to scanning all devices to read all
VG metadata to get the list of all PVIDs needed to check for
a complete VG.  Now, the temp file can be used in place of
reading metadata from all PVs on the system.
2020-10-22 13:14:31 -05:00
David Teigland
c7311d4722 lvmcache: rename label_read label_scan_dev
for consistent naming with other similar functions
2020-10-21 16:24:16 -05:00