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

4347 Commits

Author SHA1 Message Date
Zdenek Kabelac
d8dbabb28e lvcreate: cachesettings works also with writecache 2022-01-26 15:09:58 +01:00
Zdenek Kabelac
a06ccdf44b lvcreate: fix crash for unspecified LV name for writecache
Fix aplication crash when creating writecached LV with 'automatic' name.
2022-01-26 15:09:58 +01:00
Zdenek Kabelac
c6639056e0 writecache: handle options from lvm.conf
User can place default settings into lvm.conf i.e.:

allocation {
	cache_settings {
		writecache {
			block_size = 4096
		}
	}
}
2022-01-26 15:09:58 +01:00
David Teigland
de7892f0af Revert "pvcreate: overwrite partition header with -f"
This reverts commit d5a950ca67.

This commit did not properly recognize GPT cases.
2022-01-18 12:15:03 -06:00
David Teigland
a972d63c54 lvmdevices check: error exit if update is needed
. error exit means that lvmdevices --update would make a change.

. remove check of PART field from --check because it isn't used.

. unlink searched_devnames file to ensure check|update will search
2022-01-14 14:59:28 -06:00
David Teigland
d5a950ca67 pvcreate: overwrite partition header with -f
$ pvcreate /dev/sdc
  Cannot use /dev/sdc: device is partitioned
$ pvcreate -f /dev/sdc
  Physical volume "/dev/sdc" successfully created.
2022-01-14 13:57:20 -06:00
David Teigland
5e428d22d9 vgsplit: don't reread vg_to
The destination vg is first written with the EXPORTED flag,
then the source vg is written, then the destination vg is
written again without the EXPORTED flag.  Remove an unnecessary
vg_read of the destination vg just before the second write.
2022-01-12 16:42:01 -06:00
Zdenek Kabelac
04fbffb116 label: cache dm device list
Since we check for present DM devices - cache result for
futher use of checking presence of such device.

lvm2 uses cache result for label scan, but also when
it tries to activate or deactivate LV - however only simple
target 'striped' is reasonably supported.

Use disable_dm_devs to be able to control when lv_info()
get cache or uncached results.

TODO: support more type, however this is getting very complicated.
2021-12-20 16:13:28 +01:00
Zdenek Kabelac
5a78979b68 lvmcmdline: comment reset of configuration settings
We used to reset 'settings' to their defaults after command is finished.
This however has a drawback we lose all the logging after this point.

So this patch disables this 'reset' to observe for side-effects.

lvm shell should be getting reset when next command is run -
so this might or might not have some 'hidden' effects.

ATM it looks like nothing really bad should happen - we just should be
able to get more logs - at least from normal commands.
2021-12-20 16:13:28 +01:00
Zdenek Kabelac
ed1651d11f toollib: avoid repeated remove of online vg
Call just once unlink after every deactivation of LV from VG.
2021-12-20 16:13:28 +01:00
David Teigland
c28541eccd lvcreate: include recent options
The permitted option list in lvcreate has not kept
up with command-lines.in.
2021-12-13 08:59:31 -06:00
David Teigland
05d9a01351 pvscan: fix filter symlink checks
Fixes commit "pvscan: match device arg to filter symlink"
which failed to account for the fact that filter entries
are not just path names but include "a" or "r", etc.
2021-12-01 13:42:32 -06:00
David Teigland
470b967bc5 pvscan: limit md device_hint for slow autoactivation
The device_hint name in the metadata was meant to prevent
autoactivation from md components, but the name checks were
more general and would catch unnecessary cases.
2021-11-30 09:06:08 -06:00
David Teigland
d12baba1a9 pvscan: match device arg to filter symlink
This fixes an issue related to the optimization in
  "pvscan: only add device args to dev cache"

If the devices file is not used, and the lvm.conf filter
accepts devices via symlink names, then those devices won't
be accepted by pvscan for autoactivation.  To resolve this,
recognize when the filter contains symlinks and disable the
optimization.  When the optimization is disabled, a full
dev_cache_scan is performed, and symlinks are associated
with the device names passed to pvscan.  filter-regex
will accept a device if symlinks to that device are accepted.
2021-11-29 17:13:44 -06:00
David Teigland
b8f4ec846d display: ignore --reportformat
Using the option would do nothing useful but would
print extraneous braces.
2021-11-17 10:40:27 -06:00
David Teigland
89c54db16c vgchange autoactivation: error path cleanup
If the optimized label scan fails (using online files),
then clear the device state prior to falling back to the
standard label_scan.  This avoids printing output about
unexpected state.
2021-11-15 11:07:11 -06:00
David Teigland
5dbf316cee pvscan: consistent creation of pvs_lookup file
Consistently create the pvs_lookup file for VGs with
more than one PV.  Previously the file create would be
skipped if all the PVs happened to already be online.
That led to unpredicatable results in an uncommon case
(when the last PV to come online is the only PV with
metadata.)
2021-11-12 11:40:06 -06:00
David Teigland
0e0faf30e0 vgchange autoactivation: lock vg early to avoid second label scan
Copy another optimization from pvscan -aay to vgchange -aay.
When using the optimized label scan for only one VG, acquire the
VG lock prior to the scan.  This allows vg_read to then skip the
repeated label scan that normally happens after locking the vg.
2021-11-10 16:50:50 -06:00
David Teigland
92e741eda0 vgchange: move autoactivation setup code
into its own function, no functional change.
2021-11-10 14:44:11 -06:00
David Teigland
73b4602f21 pvs_online: include devname in pvid files
Include the device name in the /run/lvm/pvs_online/pvid files.
Commands using the pvid file can use the devname to more quickly
find the correct device, vs finding the device using the
major:minor number.  If the devname in the pvid file is missing
or incorrect, fall back to using the devno.
2021-11-09 11:26:26 -06:00
David Teigland
024ce50f06 vgchange -aay: improve unexpected command variations
For completeness and consistency, adjust the behavior
for some variations of:

  vgchange -aay --autoactivation event [vgname]

The current standard use is with a VG name arg, and the
command is only called when all pvs_online files exist.
This is the optimal case, in which only pvs_online devs
are read.  This remains the same.

Clean up behaviors for some other unexpected uses of the
command:

. With no VG name arg, the command activates any VGs
  that are complete according to pvs_online.  If no
  pvs_online files exist, it does nothing.

. If a VG name is used but no PVs online files exist for
  the VG, or the PVs online files are incomplete, then
  consider there could be a problem with the pvs_online
  files, and fall back to a full label scan prior to
  attempting the activation.
2021-11-08 15:19:25 -06:00
David Teigland
62533ae3fa vgchange -aay: optimize device list using pvs_online files
Port another optimization from pvscan -aay to vgchange -aay:
  "pvscan: only add device args to dev cache"

This optimization avoids doing a full dev_cache_scan, and
instead populates dev-cache with only the devices in the
VG being activated.

This involves shifting the use of pvs_online files from
the hints interface up to the higher level label_scan
interface.  This specialized label_scan is structured
around creating a list of devices from the pvs_online
files.  Previously, a list of all devices was created
first, and then reduced based on the pvs_online files.
The initial step of listing all devices was slow when
thousands of devices are present on the system.

This optimization extends the previous optimization that
used pvs_online files to limit the devices that were
actually scanned (i.e. reading to identify the device):
  "vgchange -aay: optimize device scan using pvs_online files"
2021-11-05 12:19:35 -05:00
David Teigland
f40fd88374 move code from pvscan.c to online.c
related to managing files in /run/lvm/pvs_online
and /run/lvm/vgs_online
2021-11-04 11:09:29 -05:00
David Teigland
d558b3ad7e vgchange -aay: optimize device scan using pvs_online files
Port the old pvscan -aay scanning optimization to vgchange -aay.
The optimization uses pvs_online files created by pvscan --cache
to derive a list of devices to use when activating a VG.  This
allows autoactivation of a VG to avoid scanning all devices, and
only scan the devices used by the VG itself.  The optimization is
applied internally using the device hints interface.

The new option "--autoactivation event" is given to pvscan and
vgchange commands that are called by event activation.  This
informs the command that it is being used for event activation,
so that it can apply checks and optimizations that are specific
to event activation.  Those include:

- skipping the command if lvm.conf event_activation=0
- checking that a VG is complete before activating it
- using pvs_online files to limit device scanning
2021-11-04 11:08:38 -05:00
David Teigland
594f6ca970 rename pvscan_cache_single to expect_missing_vg_device in cmd 2021-11-04 11:08:38 -05:00
David Teigland
726dd25969 add hints interface to the pvs_online file information
The information in /run/lvm/pvs_online/<pvid> files can
be used to build a list of devices for a given VG.

The pvscan -aay command has long used this information to
activate a VG while scanning only devices in that VG, which
is an important optimization for autoactivation.

This patch implements the same thing through the existing
device hints interface, so that the optimization can be
applied elsewhere.  A future patch will take advantage of
this optimization in vgchange -aay, which is now used in
place of pvscan -aay for event activation.
2021-11-04 10:58:16 -05:00
David Teigland
6ea8d975b2 lvmdevices: increase open file limit 2021-11-03 08:50:57 -05:00
David Teigland
b65a2c3f3a vgimportdevices: skip lvmlockd locking
Help bootstrapping existing shared vgs into the devices file.
Reading the vg in vgimportdevices would require locking to be
started, but vgchange lockstart won't see the vg if it's not
in the devices file.  The lvmlockd locks are not protecting
vg modifications so skipping them here won't be a problem.
2021-10-25 12:11:17 -05:00
David Teigland
ae355ffc3f pvscan: fix messages from coverity changes 2021-10-20 16:12:55 -05:00
David Teigland
33e47182f7 pvscan: only add device args to dev cache
Optimize the common pvscan --cache command by only adding
the necessary devs to dev-cache.
2021-10-19 17:13:57 -05:00
Zdenek Kabelac
04725763a1 gcc: always initialize vg_complete 2021-10-15 00:09:07 +02:00
Zdenek Kabelac
8784211958 debug: reduce some debugging noise
Resolve event_activation configure option just once.

Do not print debug_devs about 'bad' filtering, when
actually filter already printed reason for skipping

Do not trace more then once about backup being disabled.

No debug when unlinked file does not exists in pvscan.
2021-10-14 23:34:11 +02:00
David Teigland
c38473548e fix segfault handling duplicate PVs
cmd arg was missing when switching to use an alternative
duplicate dev.
2021-10-14 14:02:59 -05:00
David Teigland
6fb497ef42 toollib: remove all devices list from process_each_pv
Reporting non-PVs / "all devices" is only done by
pvs -a or pvdisplay -a, so avoid the work managing
a list of all devices in process_each_pv.
In the case when it's needed, use the results of
label_scan which already determines which devs
are not PVs.
2021-10-13 17:29:32 -05:00
David Teigland
bbf8e7db74 logging: to the systemd journal
Configure via lvm.conf log/journal or command line --journal.

Possible values:
"command" records command information.
"output" records default command output.
"debug" records full command debugging.

Multiple values can be set in lvm.conf as an array.
One value can be set in --journal which is added to
values set in lvm.conf
2021-10-07 12:06:49 -05:00
David Teigland
0b6782fa01 pvscan: add options listlvs listvg checkcomplete
pvscan --cache <dev>
    . read only dev
    . create online file for dev

pvscan --listvg <dev>
    . read only dev
    . list VG using dev

pvscan --listlvs <dev>
    . read only dev
    . list VG using dev
    . list LVs using dev

pvscan --cache --listvg [--checkcomplete] <dev>
    . read only dev
    . create online file for dev
    . list VG using dev
    . [check online files and report if VG is complete]

pvscan --cache --listlvs [--checkcomplete] <dev>
    . read only dev
    . create online file for dev
    . list VG using dev
    . list LVs using dev
    . [check online files and report if VG is complete]
    . [check online files and report if LVs are complete]

[--vgonline]
can be used with --checkcomplete, to enable use of a vg online
file.  This results in only the first pvscan command to see
the complete VG to report 'VG complete', and others will report
'VG finished'.  This allows the caller to easily run a single
activation of the VG.

[--udevoutput]
can be used with --cache --listvg --checkcomplete, to enable
an output mode that prints LVM_VG_NAME_COMPLETE='vgname' that
a udev rule can import, and prevents other output from the
command (other output causes udev to ignore the command.)

The list of complete LVs is meant to be passed to lvchange -aay,
or the complete VG used with vgchange -aay.

When --checkcomplete is used, lvm assumes that that the output
will be used to trigger event-based autoactivation, so the pvscan
does nothing if event_activation=0 and --checkcomplete is used.

Example of listlvs
------------------

$ lvs -a vg -olvname,devices
  LV     Devices
  lv_a   /dev/loop0(0)
  lv_ab  /dev/loop0(1),/dev/loop1(1)
  lv_abc /dev/loop0(3),/dev/loop1(3),/dev/loop2(1)
  lv_b   /dev/loop1(0)
  lv_c   /dev/loop2(0)

$ pvscan --cache --listlvs --checkcomplete /dev/loop0
  pvscan[35680] PV /dev/loop0 online, VG vg incomplete (need 2).
  VG vg incomplete
  LV vg/lv_a complete
  LV vg/lv_ab incomplete
  LV vg/lv_abc incomplete

$ pvscan --cache --listlvs --checkcomplete /dev/loop1
  pvscan[35681] PV /dev/loop1 online, VG vg incomplete (need 1).
  VG vg incomplete
  LV vg/lv_b complete
  LV vg/lv_ab complete
  LV vg/lv_abc incomplete

$ pvscan --cache --listlvs --checkcomplete /dev/loop2
  pvscan[35682] PV /dev/loop2 online, VG vg is complete.
  VG vg complete
  LV vg/lv_c complete
  LV vg/lv_abc complete

Example of listvg
-----------------

$ pvscan --cache --listvg --checkcomplete /dev/loop0
  pvscan[35684] PV /dev/loop0 online, VG vg incomplete (need 2).
  VG vg incomplete

$ pvscan --cache --listvg --checkcomplete /dev/loop1
  pvscan[35685] PV /dev/loop1 online, VG vg incomplete (need 1).
  VG vg incomplete

$ pvscan --cache --listvg --checkcomplete /dev/loop2
  pvscan[35686] PV /dev/loop2 online, VG vg is complete.
  VG vg complete
2021-10-07 12:06:49 -05:00
Zdenek Kabelac
3cf97a737b cleanup: use dm_list_empty
Instant check for 'dm_list_size() == 0' without any size calc.
2021-10-06 15:43:31 +02:00
David Teigland
8e62cbb18e device_id: update stacked PVs for vgchange uuid
If a VG uuid is changed, update the device_id of any
PVs stacked on LVs in the changed VG.
2021-10-04 16:54:44 -05:00
Zdenek Kabelac
9668427fe8 cleanup: use first parameter uint
Easier with struct zeroing and matching assing of type uint.
2021-09-27 18:56:14 +02:00
Zdenek Kabelac
614d150a8c cov; matching enum type 2021-09-27 18:56:14 +02:00
Zdenek Kabelac
bf0d558067 cov: ignoring 2021-09-27 18:56:14 +02:00
Zdenek Kabelac
6c85ea50de make: fix compilation for some compiler
Reported-by: adamboardman of gemian
2021-09-27 18:56:14 +02:00
Zdenek Kabelac
27eef1b964 cov: make more obvious buffer is zero ended 2021-09-27 18:56:13 +02:00
Zdenek Kabelac
3a3aabb832 metadata: avoid excessive check of /etc/localtime
With larger metadata, decoding 'localtime()' for hinting time creation
of every LV may cause excessive check of /etc/localtime file.
Set TZ to ":/etc/localtime" so glibc reads this file just once
instead of check everytime if there has anything changed.
2021-09-27 18:56:13 +02:00
David Teigland
e62a71f3dd lvmlockd: update error message
refer specifically to the "use_lvmlockd" setting in lvm.conf
2021-09-24 15:40:20 -05:00
Zdenek Kabelac
e6d3587482 cov: check dev_get_size result
Check we have obtained some device size out of dev_get_size().
2021-09-21 21:03:47 +02:00
Zdenek Kabelac
30e27d2f8b cov: sanitize function environment
Coverity can see that function is either used with 'dev' or 'def'.
2021-09-21 21:03:47 +02:00
Zdenek Kabelac
1b52451996 cov: mask some warning about leakage
Mask false-positive leak report.
2021-09-20 14:26:09 +02:00
Zdenek Kabelac
548c69f581 cov: hide reports from optarg being NULL
It's basically irrelavant which value we assing to optarg,
since it's set by getopt() function, but Coverity tool
is incorrectly reporting possibly dereference of NULL.
2021-09-20 14:26:09 +02:00
Zdenek Kabelac
ebd150366f cov: add explicit NULL pointer check
Make obvious to coverity strcmp() is not getting NULL pointer.
2021-09-20 14:26:09 +02:00
Zdenek Kabelac
752a9ec4b4 cov: make read buffer obviously zero ended
Coverity doesn't get the idea from memset() here.
2021-09-20 14:26:09 +02:00
Zdenek Kabelac
3e7e9cc5e6 cov: handle better leak reports
Rewrite code so the leaks are eliminated from Coverity.
2021-09-20 14:26:09 +02:00
Zdenek Kabelac
f410035181 cov: check fid instance is created 2021-09-20 14:26:09 +02:00
Zdenek Kabelac
6427803252 cov: pvck validates setup_device return value 2021-09-20 14:18:13 +02:00
Zdenek Kabelac
3e21c8524e gcc-fanalyzer: add extra check for origin_from_cow
Make analyzer work easier with explicit check for internal error.
2021-09-20 13:58:57 +02:00
Zdenek Kabelac
93d565eda9 gcc-fanalyzer: use zeroed memory
Analyzer here was rather confused about possiblity of loosing previously
assigned device pointers - fixed by passing zero initialize memory
before first assign.
2021-09-20 13:58:57 +02:00
Zdenek Kabelac
5126ac7c3a gcc-fanalyzer: explicit test null not pass
Make analyzer explicitelly aware we can't get NULL here.
2021-09-20 10:51:30 +02:00
Zdenek Kabelac
0d9f3dbd95 clang: add explicit test for VG
Clang can't figure out connection to 'skip' variable.
2021-09-20 10:51:30 +02:00
Zdenek Kabelac
1a5c79d1d1 clang: keep final_opts_list initialized for all paths
Likely impossible path, but just keep always initilized.
2021-09-15 15:24:56 +02:00
David Teigland
8935dfee56 lvmdevices: allow deviceidtype with addpvid
in addition to using with adddev
2021-09-13 14:11:07 -05:00
David Teigland
9857b5a3dc add --nohints option
The command will not use the hints file to locate devices for PVs.
It will still do standard hint file invalidation where appropriate.
2021-09-13 10:55:07 -05:00
Wu Guanghao
b36ab8a063 cmdlib_lvm2_init: release cmd on failure path
The cmd memory space is allocated by zalloc, and the registration
fails and is not released.

Although this code would be ever triggered just in the case
of some internal (likely compilation) bug.

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
2021-09-13 12:34:41 +02:00
Adrian Ratiu
cd897e536f man-generator: initialize struct stat to avoid MSAN error
When building lvm2 in Gentoo/ChromeOS with the ASAN memory
sanitizer enabled, man-generator fails with the following
error. Initializing makes the error go away.

* SUMMARY: MemorySanitizer: use-of-uninitialized-value /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3316:6 in _include_description_file
* Exiting
* ASAN error detected:
* ==2548047==WARNING: MemorySanitizer: use-of-uninitialized-value
*     #0 0x558b00ab4730 in _include_description_file /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3316:6
*     #1 0x558b00ab4730 in _print_man /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3426:21
*     #2 0x558b00ab4730 in main /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3570:7
*     #0 0x7fa9b2cbb807 in find_derivation /var/tmp/portage/cross-x86_64-cros-linux-gnu/glibc-2.33-r8/work/glibc-2.33/iconv/gconv_db.c:583:15
*     #1 0x558b00a29559 in ?? ??:0
*
*   Uninitialized value was created by an allocation of 'statbuf.i.i' in the stack frame of function 'main'
*     #0 0x558b00ab1d4d in main /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3505
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
064979dc32 gcc: remove unused vg setting 2021-09-13 12:34:41 +02:00
Zdenek Kabelac
3b2a4e3e6f cov: make it aware we need these headers for muslC 2021-09-13 12:34:41 +02:00
Zdenek Kabelac
63930f576a cov: add some initializers 2021-09-13 12:34:41 +02:00
Zdenek Kabelac
f5f1cdfa70 cov: initilized more struct members
For some hypothetical path, make these vars defined.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
a7258ae394 cov: do not try to change passed in argv
It's not a good idea to change passed 'argv[]' and replace it with
pointers to local stack - although in this case we are not using
this argv[] after return from this function.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
52b5620476 makefiles: sanitize environment
Compilation needs to generate 'C' locale sorted command file
definitions. To always enforce 'C' sorting rules user LC_ALL
instead of LANG, as  LANG settings can be overuled by
other LC settings like LC_COLLATE and may result into miscompiled
lvm2 binary if locales ordering differs from 'C'.

Reported-by: jmp-lvm2@ookaze.fr
2021-09-06 14:00:20 +02:00
Zdenek Kabelac
4afe872fd6 vdo: fix conversion of large virtual sizes
Properly accept virtual sizes above 2TiB.
2021-08-31 22:05:47 +02:00
David Teigland
350f8845bd pvremove: apply devices file
pvremove was wrongly allowed to operate on a device
not listed in the devices file.
2021-08-27 14:48:33 -05:00
Alex Xu (Hello71)
a6a8443a07 add missing sys/file.h include
required for LOCK_EX etc on musl
2021-08-23 09:24:45 -05:00
David Teigland
72af1cb085 vgimportclone: fix when duplicates are both in the devices file
Fix case where duplicate PVs are created (e.g. with dd) from
devices that are both already in the devices file.
2021-08-20 15:06:33 -05:00
David Teigland
8b72313936 devices file: recognize old locking_type 0
if the old locking_type is 0, set cmd->nolocking so that
it will be applied to the devices file lock.
2021-08-20 14:51:13 -05:00
David Teigland
6cd4470e6d devices: apply ignorelockingfailure to devices file lock 2021-08-20 14:07:00 -05:00
David Teigland
b0bda7c25b lvmdevices: check yes option for adding duplicate 2021-08-19 13:00:43 -05:00
David Teigland
96b777167c cov: clean up pvid and vgid usage
pvid and vgid are sometimes a null-terminated string, and
other times a 'struct id', and the two types were often
cast between each other.  When a struct id was cast to a char
pointer, the resulting string would not necessarily be null
terminated.  Casting a null-terminated string id to a
struct id is fine, but is still avoided when possible.

A struct id is:  int8_t uuid[ID_LEN]
A string id is:  char pvid[ID_LEN + 1]

A convention is introduced to help distinguish them:

- variables and struct fields named "pvid" or "vgid"
  should be null-terminated strings.

- variables and struct fields named "pv_id" or "vg_id"
  should be struct id's.

- examples:
  char pvid[ID_LEN + 1];
  char vgid[ID_LEN + 1];
  struct id pv_id;
  struct id vg_id;

Function names also attempt to follow this convention.

Avoid casting between the two types as much as possible,
with limited exceptions when known to be safe and clearly
commented.

Avoid using variations of strcpy and strcmp, and instead
use memcpy/memcmp with ID_LEN (with similar limited
exceptions possible.)
2021-08-16 11:31:15 -05:00
Yi Wang
47bcb446b8 lvchange: fix lvchange refresh failed for dm suspend or resume failed
When multiple lvchange refresh processes executed at the same time,
suspend/resume ioctl on the same dm, some of these commands will be failed
for dm aready change status, and ioctl will return EINVAL in _do_dm_ioctl function.
to avoid this problem, add READ_FOR_ACTIVATE flags in lvchange refresh process,
it will hold LCK_WRITE lock and avoid suspend/resume dm at the same time.

Signed-off-by: Long YunJian <long.yunjian@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
2021-08-16 09:45:40 -05:00
David Teigland
d0ab5bf7f9 pvscan: only match devices file for command args
Avoid matching all devices with the devices file to
avoid delays during startup.
2021-08-05 13:20:26 -05:00
David Teigland
87714a1384 devices file: avoid updating entry dev names in some cases
Avoid thrashing changes to devices file device names by
some commands that are run during startup when devnames
are still being set up.
2021-08-05 13:20:26 -05:00
David Teigland
d3d6a0e820 devices file: limit warnings about devices file entries not found
All commands were printing a warning if a devices file
entry was not found.  Limit this to commands that report/display
lvm state.
2021-08-05 13:20:26 -05:00
Zdenek Kabelac
d2a2dc2e41 debug: stack tracing on error path 2021-07-28 00:49:28 +02:00
Zdenek Kabelac
046d85af3d cov: add internal error for missing arg
Analyzer is happier.
2021-07-28 00:49:28 +02:00
Zdenek Kabelac
308c6f31c3 pvck: ensure buffer is 0 terminated
Since readed metadata buffer is passed to printf(),
ensure the buffer is '\0' terminated.
2021-07-28 00:49:22 +02:00
Zdenek Kabelac
01081b2100 cov: pvck fix memleak
Fix memory leaks on error paths for allocated
path and backup_file name by converting allocation to
dm_pool_alloc  and also change devicefile structure to contain
embeded  path as last struct member - so we could allocate
only needed string size  instead of PATH_MAX from pool.

TODO: still to be fixed 'mf' struct.
2021-07-28 00:49:22 +02:00
Zdenek Kabelac
4b856476e9 vgmerge: support option --poolmetadataspare 2021-07-23 16:36:31 +02:00
Zdenek Kabelac
9cbc9e8296 vgmerge: remove one of merge pmspare LVs
When merging 2 VG, where both of them have pmspare volume,
select the bigger one and remove the other.
2021-07-23 16:35:47 +02:00
David Teigland
06602942a3 writecache: use block size 512 for thin pool data
Recent commit 84bd394cf9
  "writecache: use block size 4096 when no fs is found"

failed to account for the case where writecache is attached
to thin pool data.  Checking fs block size on the thin pool
data LV is wrong, and checking the fs block on each thin LV
would be impractical, so default to 512 which cannot break
any existing file systems, and require the user to specify
4k when appropriate.
2021-07-21 14:24:27 -05:00
David Teigland
d91c018732 writecache: fix missing sync_dev_names when attaching cache
When activating an LV to check the fs block size, wait for
the LV dev to be accessible before running blkid on it.
2021-07-21 13:16:21 -05:00
Zdenek Kabelac
2132fdc11f vgsplit: add support for option --poolmetadataspare
When splitting VG with thin/cache pool volume, handle pmspare during
such split and allocate new pmspare in new VG or extend existing pmspare
there and eventually drop  pmspare in original VG if is no longer needed
there.
2021-07-21 15:56:33 +02:00
Zdenek Kabelac
5042463c50 vgremove: remove forgotten pmspare
As pmspare is an invisible LV it's not getting automatically removed
since vgremove removes only visible LVs and it depending LVs.
If there was no other thin/cache pool volume, such pmspare stayed
undeleted and caused command failure.

So handle explicitelly such forgotten pmspare and remove it.
2021-07-21 13:19:51 +02:00
David Teigland
e33c2e032c pvscan: narrow the previous commit slightly
to avoid change to pvscan-autoactivate.sh
2021-07-13 16:38:04 -05:00
David Teigland
25f0f5daac pvscan: do nothing for device removal and event_activation=0
The lvm2-pvscan service runs pvscan --cache -aay <dev> for
device addition, and pvscan --cache <dev> on device removal.
For event_activation=0, the addition does nothing.  Fix
device removal to also do nothing for event_activation=0.
Device removal was previously doing some work to process
the removal which slowed down stopping lvm2-pvscan services.
2021-07-13 16:09:54 -05:00
David Teigland
9048565093 devices: rework libudev usage
related to config settings:
  obtain_device_info_from_udev (controls if lvm gets
    a list of devices from readdir /dev or from libudev)
  external_device_info_source (controls if lvm asks
    libudev for device information)

. Make the obtain_device_list_from_udev setting
  affect only the choice of readdir /dev vs libudev.
  The setting no longer controls if udev is used for
  device type checks.

. Change obtain_device_list_from_udev default to 0.
  This helps avoid boot timeouts due to slow libudev
  queries, avoids reported failures from
  udev_enumerate_scan_devices, and avoids delays from
  "device not initialized in udev database" errors.
  Even without errors, for a system booting with 1024 PVs,
  lvm2-pvscan times improve from about 100 sec to 15 sec,
  and the pvscan command from about 64 sec to about 4 sec.

. For external_device_info_source="none", remove all
  libudev device info queries, and use only lvm
  native device info.

. For external_device_info_source="udev", first check
  lvm native device info, then check libudev info.

. Remove sleep/retry loop when attempting libudev
  queries for device info.  udev info will simply
  be skipped if it's not immediately available.

. Only set up a libdev connection if it will be used by
  obtain_device_list_from_udev/external_device_info_source.

. For native multipath component detection, use
  /etc/multipath/wwids.  If a device has a wwid
  matching an entry in the wwids file, then it's
  considered a multipath component.  This is
  necessary to natively detect multipath
  components when the mpath device is not set up.
2021-07-13 11:11:23 -05:00
David Teigland
66daedc6d2 skip indexing devices used by LVs in more commands
expands commit d5a06f9a7d
  "pvscan: skip indexing devices used by LVs"

The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device.  Commands that continue to use the index and
print the warnings:

  fullreport, lvmdiskscan, vgs, lvs, pvs,
  vgdisplay, lvdisplay, pvdisplay,
  vgscan, lvscan, pvscan (excluding --cache)

A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-09 13:59:31 -05:00
David Teigland
d5a06f9a7d pvscan: skip indexing devices used by LVs
dev_cache_index_devs() is taking a large amount of time
when there are many PVs.  The index keeps track of
devices that are currently in use by active LVs.  This
info is used to print warnings for users in some limited
cases.

The checks/warnings that are enabled by the index are not
needed by pvscan --cache, so disable it in this case.

This may be expanded to other cases in future commits.
dev_cache_index_devs should also be improved in another
commit to avoid the extreme delays with many devices.
2021-07-06 10:18:07 -05:00
Zdenek Kabelac
2c6a2b6e86 vdo: support vdo_pool_header_size
Add profilable configurable setting for vdo pool header size, that is
used as 'extra' empty space at the front and end of vdo-pool device
to avoid having a disk in the system the may have same data is real
vdo LV.

For some conversion cases however we may need to allow using '0' header size.

TODO: in this case we may eventually avoid adding 'linear' mapping layer
in future - but this requires further modification over lvm code base.
2021-06-28 20:41:07 +02:00
Zdenek Kabelac
5fcbc3bd7d vdo: rename variable vdo_pool_zero
Match rest of code.
2021-06-28 20:41:07 +02:00
David Teigland
84bd394cf9 writecache: use block size 4096 when no fs is found
When there is no block size constraint from a file system
or from a user setting, use 4096 rather than 512 because of
better performance.
2021-06-23 12:38:57 -05:00
David Teigland
c35f7722d5 lvconvert: allow writecache with other thinpool command syntax
"lvconvert --thinpool LV" should allow LV to have a writecache,
but there was an extra type check preventing it.
2021-06-17 16:15:18 -05:00
David Teigland
71cb54d92f coverity cleanups 2021-06-16 13:42:51 -05:00
David Teigland
440d6ae79f lvmdevices: add deviceidtype option
When adding a device to the devices file with --adddev, lvm
by default chooses the best device ID type for the new device.
The new --deviceidtype option allows the user to override the
built in preference.  This is useful if there's a problem with
the default type, or if a secondary type is preferrable.

If the specified deviceidtype does not produce a device ID,
then lvm falls back to the preference it would otherwise use.
2021-06-11 13:27:18 -05:00
Wu Guanghao
8331321070 pvck: add lock_global() before clean_hint_file()
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
2021-06-11 10:21:07 -05:00
Zdenek Kabelac
17b2746486 archive: avoid abuse of internal flag
Since archive is now postponned we use internal variable 'changed'
to mark we need to commit new metadata.
2021-06-09 16:18:20 +02:00
Zdenek Kabelac
bb45e33518 backup: automatically store data on vg_unlock
Previously there have been necessary explicit call of backup (often
either forgotten or over-used). With this patch the necessity to
store backup is remember at vg_commit and once the VG is unlocked,
the committed metadata are automatically store in backup file.

This may possibly alter some printed messages from command when the
backup is now taken later.
2021-06-09 14:56:13 +02:00
Zdenek Kabelac
ba3707d953 archiving: take archive automatically
Instead of calling explicit archive with command processing logic,
move this step towards 1st. vg_write() call, which will automatically
store archive of committed metadata.

This slightly changes some error path where the error in archiving
was detected earlier in the command, while now some on going command
'actions' might have been, but will be simply scratched in case
of error (since even new metadata would not have been even written).

So general effect should be only some command message ordering.
2021-06-09 14:56:13 +02:00
David Teigland
df27392c8c man/help: fix common option listing 2021-06-08 14:07:39 -05:00
David Teigland
2bce6faed0 pvchange: fix file locking deadlock
Calling clear_hint_file() to invalidate hints would acquire
the hints flock before the global flock which could cause deadlock.
The lock order requires the global lock to be taken first.

pvchange was always invalidating hints, which was unnecessary;
only invalidate hints when changing a PV uuid.  Because of the
lock ordering, take the global lock before clear_hint_file which
locks the hints file.
2021-06-02 16:29:54 -05:00
David Teigland
e7f107c246 writecache: don't pvmove device used by writecache
The existing check didn't cover the unusual case where the
cachevol exists on the same device as the origin LV.
2021-06-02 11:12:20 -05:00
David Teigland
a65f8e0a62 enable command syntax for thin and writecache
converting an LV with a writecache to thin pool data in
addition to previous attaching writecache to thin pool data
2021-05-24 16:09:35 -05:00
Leo Yan
8b904dc711 tools: Add support for "idm" lock type
This patch is to update the comment and code to support "idm" lock type
which is used for LVM toolkit.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
2021-05-20 16:01:05 -05:00
David Teigland
6b00c8c910 writecache: allow attaching to thin pool data 2021-05-06 16:23:03 -05:00
David Teigland
318bb3a06b blkid: simplify fs block size check
Only the LV path name is needed for blkid query,
the step of getting a dev struct is not needed.
2021-05-05 16:15:10 -05:00
David Teigland
2419345b9d pvremove: use consistent error message
When the device is not a PV print
  "No PV found on device ..."

instead of
  "Failed to read lvm info for ... PVID ."

an earlier check had been added with a different
message for the same condition.
2021-05-04 13:08:02 -05:00
David Teigland
4dc5d4ac7e label_read_pvid: separate error and no-pvid
error reading dev and no pvid on dev were both
returning 0.  make it easier for callers to
know which, if they care.

return 1 if the device could be read, regardless
of whether a pvid was found or not.
set has_pvid=1 if a pvid is found and 0 if no
pvid is found.
2021-04-23 17:37:08 -05:00
David Teigland
fcbed26393 Revert "cov: check label_read_pvid return value"
This reverts commit bf461b99c6.

label_read_pvid returns 0 for non-PVs and these callers want
to handle non-PVs.
2021-04-23 17:12:24 -05:00
Zdenek Kabelac
05eb90db68 cleanup: indent 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
6f61de3009 args.h: bold command refference 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
49caa9f3b1 clang: ensure vg is defined 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
e1287c3b71 cov: ensure fid is not null 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
04fd55a0c9 cov: ensure segtype is not null 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
cdcd8011d0 cov: add explicit check for external not being null
Although the code should never evaluate for null external
add explict check for analyzer.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
d95b26fae0 cov: check setup_devices return code 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
ece80cd0fb cov: avoid passed invalid dummy structure
Altough this dummy structure should not be using pe_size anywhere,
make analyzer happier and avoid PV structures with zero pe_size.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
bf461b99c6 cov: check label_read_pvid return value
Command can early exit when function returns 0.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
3d96203e21 cov: avoid leak when repeating options
Do not leak previous buffer, when option is set more then once.
2021-04-23 22:59:25 +02:00
Zdenek Kabelac
d1f9845c96 cov: ensure there is space for 0 at eol
Reserve 1 char for \0.
2021-04-23 22:58:45 +02:00
Zdenek Kabelac
65c4f81dc2 pvscan: fix memleak
Commit 25b58310e3 add zalloc()
without correspoding free(), switch to use cmd mempool.
2021-04-23 22:55:39 +02:00
David Teigland
66dd481f46 man/help: move implied annotation
from
[ --type foo (implied) ]

to
[ --type foo] (implied)
2021-04-21 12:05:10 -05:00
David Teigland
d651b340e6 commands: use AUTOTYPE in definitions
If a cmd def implies an LV type without --type
in the required options, then include the implied
type in the cmd def as AUTOTYPE: <type>
instead of including the redundant --type foo
in the OO list of options.

Including an implied --type in the OO list would
often cause multiple cmd defs to potentially be
identical when options were used, and a user
command could match more than one cmd def.

The AUTOTYPE values are listed in man page and
help output as
 [ --type foo (implied) ]

If a user command includes --type, it will usually
match a cmd def with --type in the required options.
But, if the user command matches a cmd def with
AUTOTYPE, then the specifed --type and AUTOTYPE must
match.

The man-generator program has a new --check
option that compares cmd defs to find any cmd defs
that are equivalent with the use of options,
and should have their options adjusted.
2021-04-21 08:41:37 -05:00
David Teigland
7b77226df2 man-generator: add option to check for repeated command definitions
Compares cmd defs based on two principles for avoiding repeated
commands (where a given command could match more than one cmd def):

. a cmd def should be a unique combination of required
  option args and position args

. avoid adding optional options to a cmd def that if
  used would make the command match a different cmd def

FIXME: record when repeated cmd defs are found so we can
avoid reporting them twice, e.g. once for A vs B and
second time for B vs A.
2021-04-20 10:31:00 -05:00
Zdenek Kabelac
0f87b015b5 args: documentation enhancements
Use #DEFAULT_SYS_DIR# replaceable string for devicesfile
so the man pages installation respects configured settings.

Update some missing lvm.conf(5) references.
2021-04-19 14:40:14 +02:00
Zdenek Kabelac
b1ad32acd6 commands: update definitions for thin creation
Add missing VG into description of thin pool creation command.

Remove one duplicated thin-pool creation command.
Remove options --discards and --errorwhenfull from the list when the command describes
only creation of a thin volume - as these options do apply for thin-pool.
Also use here more correct name OO_LVCONVERT_THINPOOL instead of OO_LVCONVERT_THIN.

Reorder extra options for cache & thin-pool before common pool options.
Order consistenly --stripes and --stripesize after --extents option
so the options related to pools are better together.

Remove invalid snapshot creation description - since this case is
handled through our configurable spare volume creation.

Add some missing optional --type parameters for few command instancies.
2021-04-19 14:40:14 +02:00
Zdenek Kabelac
82e3b2e0ad tools: correct units description
Option --units takes also [Number] to express size in configurable
units.
2021-04-19 14:40:14 +02:00
Zdenek Kabelac
7bde16f5e1 man-generator: markup updates
Emit .ad l / .ad b less frequently around larger blocks
we want to keep left aligned.

Avoid emittting empty lines.

Reduce .HP usage and replace it with .TP.
However keep .HP for all option listings, as i.e. html rendering
can't handle well combintion of .TP an .HP together and .TP alone
is not indenting 2nd. line of long option line.
(For .TP line we don't need to emit .br)

Surround .SH with dots for better look.

For some .TP use plain more readable .I for a line.

Support rendering of optional [Number] (for --units).

Use better markup for units and instead of long markup string,
show individual units with markup.
2021-04-19 14:40:07 +02:00
Zdenek Kabelac
d94e5ba5af man-generator: use \(em
Use \(em in command title description and command multidefs.
2021-04-19 14:37:08 +02:00
Zdenek Kabelac
efd0939583 man-generator: decorate optional option prefixes
Enhance man typography decoration of optional option
prefixes like --[raid]writebeind and use regular font to render []
as these are not part of the option name itself.
2021-04-19 14:37:08 +02:00
David Teigland
8daf5cd45f man/help: change LV type listing
Previously, accepted LV types were presented as a series of suffixes
after the "LV" on the command line.  The addition of many new types
resulted in this becoming too long, e.g

  lvconvert --type cache --cachepool LV LV_linear_striped_thinpool_vdo_vdopool_vdopooldata_raid

For man pages, move these types from the command line to a new line
dedicated to listing accepted LV types:

  lvconvert --type cache --cachepool LV LV1
  ...

  LV1 types: linear striped thinpool vdo vdopool vdopooldata raid

The special "LV1" is used as a reference to avoid confusion
with other LVs that may appear on the command line.  There
are currently no commands with more than one typed LV, but
if there are cases with more, then "LV2" could also be used.

For command line usage/-h output, drop the LV types from the
command line specification.  The more detailed is not needed
in the help output and can be found in the man page.
2021-04-14 17:25:10 -05:00
Zdenek Kabelac
87a3ea7f8f Revert "thinpool: support lvconvert without zeroing"
This reverts commit 8e7690b798.

Actully this was bad idea - to make it on pair.
-Zn for thin-pools is already used - so here user must have
create new pool and swap existing thin-pool metadata into.

So reverting this commit to avoid any possible regression.
2021-04-14 10:53:34 +02:00
Zdenek Kabelac
53fa1582d9 man-generator: spaces 2021-04-12 09:54:16 +02:00
Zdenek Kabelac
e01ce8e2ae man-generator: option description indented
Left indention is needed only for options, but is actually
unwanted for decription itself.
2021-04-12 09:54:16 +02:00
Zdenek Kabelac
441b702362 man-generator: remove ',' between some options
It would be complicated to handle ',' alignment after hyphenation
changes ATM, but these commas seems to be there rather unneeded
so remove them and make the man output more clear.
2021-04-12 09:54:16 +02:00
Zdenek Kabelac
d86b583644 man-generator: improve hyphenation for longer option list
Disable hyphenation around longer option lists (>42 chars)
and use \: to markup places for line splits.

The code ATM is somewhat mixtured so it's not easy to encapsulate
section .nh ... .hy.

ATM global _was_hyphen is used to properly finish sections after
disabled hyphenation.
2021-04-12 09:54:16 +02:00
Zdenek Kabelac
aee0cd6530 makefiles: static linking enhancements 2021-04-12 09:54:15 +02:00
David Teigland
0a28e3c44b Add metadata-based autoactivation property for VG and LV
The autoactivation property can be specified in lvcreate
or vgcreate for new LVs/VGs, and the property can be changed
by lvchange or vgchange for existing LVs/VGs.

 --setautoactivation y|n
 enables|disables autoactivation of a VG or LV.

Autoactivation is enabled by default, which is consistent with
past behavior.  The disabled state is stored as a new flag
in the VG metadata, and the absence of the flag allows
autoactivation.

If autoactivation is disabled for the VG, then no LVs in the VG
will be autoactivated (the LV autoactivation property will have
no effect.)  When autoactivation is enabled for the VG, then
autoactivation can be controlled on individual LVs.

The state of this property can be reported for LVs/VGs using
the "-o autoactivation" option in lvs/vgs commands, which will
report "enabled", or "" for the disabled state.

Previous versions of lvm do not recognize this property.  Since
autoactivation is enabled by default, the disabled setting will
have no effect in older lvm versions.  If the VG is modified by
older lvm versions, the disabled state will also be dropped from
the metadata.

The autoactivation property is an alternative to using the lvm.conf
auto_activation_volume_list, which is still applied to to VGs/LVs
in addition to the new property.

If VG or LV autoactivation is disabled either in metadata or in
auto_activation_volume_list, it will not be autoactivated.

An autoactivation command will silently skip activating an LV
when the autoactivation property is disabled.

To determine the effective autoactivation behavior for a specific
LV, multiple settings would need to be checked:
the VG autoactivation property, the LV autoactivation property,
the auto_activation_volume_list.  The "activation skip" property
would also be relevant, since it applies to both normal and auto
activation.
2021-04-07 15:32:49 -05:00
Zdenek Kabelac
d2522f4a05 polldaemon: improve support for interruptions
Enhance handling of interruptions of polling process and lvmpoll daemon.
Daemon should now react much faster on interrups (i.e. shutdown
sequence) and avoid taking lenghty sleep waiting on pvmove signaling.
2021-04-06 22:02:31 +02:00
David Teigland
12949ea886 hints: don't use hints when --sysinit is used
Devices are not in a steady state during system init,
so hints are repeatedly invalidated, and hardly used,
so maintaining them is wasted effort.
2021-04-01 14:37:24 -05:00
Samanta Navarro
01d5e4d1ca all: fix typos 2021-03-30 13:08:14 +02:00
Zdenek Kabelac
2aaea13aaa man: writecache missed for --type
Add missing writecache type into man pages.
2021-03-30 13:08:14 +02:00
Marian Csontos
b6cff47bde lvm: Fix editline compilation 2021-03-22 11:37:19 +01:00
Zdenek Kabelac
3d26bde1c0 make: cflow target works again
Restored 'make cflow' functinality.
Produces some quick referece of function chaining and usage.
2021-03-20 00:05:01 +01:00
Zdenek Kabelac
8e7690b798 thinpool: support lvconvert without zeroing
Since lvm does support external users of thin-pool when thin devices
are managed outside it can be useful to support conversion to
thin pool from data and metadata LV without zeroing.
TransactionID will be 0 in lvm2 metadata.

  lvconvert -Zn --thinpool vg/data --poolmetadata vg/meta
2021-03-18 18:57:45 +01:00
Zdenek Kabelac
1c3774c7a8 pool: allow data on zero and error segtypes
Renables usage of --type zero and --type error LVs to serve as
backend for _tdata device. Clearly not very useful in practice,
as it can't store any real data, but usable for some testing
and some sort of perfomance checking.

  lvcreate --type zero -L1T -n pool vg
  lvconvert --thinpool vg/pool

Will create a thin-pool with zero device backend.
2021-03-18 18:57:45 +01:00
Zdenek Kabelac
7a9efc5fae lvresize: allow mixing striped with errors or zero
Enabled extension/mixing of stripes/linears, error and zero
segtype LVs with stripes/linear, error and zero segtypes.

It is not very useful in practice, as the user cannot store any real
data on error or zero segtypes, but it may get some uses in
some scenarios where i.e. some portion of the device should not be
readable. Mixing of types happens on 'extent_size' level:

  lvcreate -L1 -n lv vg
  lvextend --type error  -L+1 vg/lv
  lvextend --type zero   -L+1 vg/lv
  lvextend --type linear -L+1 vg/lv
  lvextend --type striped -L+1 vg/lv

  lvs -o+segtype,seg_size vg

Note: when the type is not specified, the last segment type is
automatically selected.

It's also a small 'can of worms' since we can't tell LVs if
the LV is linear/error/zero or their mixtures. So the meaning behind
them may need some updates.

We already have this types of LV created i.e by:

  vgreduce --removemissing --force

where missing LV segments have been replaced by either
error or zero segtype (lvm.conf).

TODO: it might be worth adding a message while such device is activated.
2021-03-18 18:56:49 +01:00
Zdenek Kabelac
a60c8748ea thin: ignore parallel merge while polling
If the thin volume has no merging snapshot,
(being already merged) there is nothing to check.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
eadd58a97d lvpoll: improve merge polling
When multiple polling tasks are watching for same LV, clearly
when some of them wins the game - other polling tasks will fail.
Improve the logic and report success if the merged LV is
actually not a merging origin anymore (since likely someone
else has already finished merging).
2021-03-15 11:13:24 +01:00
Zdenek Kabelac
1a451207b8 pooldaemon: increase min polling interval
Although we support '0' interval - it's highly inefficent to
do so many scans in busy-loop.

So ATM raise minimal rescan time to 100ms.

TODO: revisit whole timing logic here as it does have some sideeffect
hiddent impact and can considerably eat CPU in some cases.
2021-03-15 11:13:24 +01:00
Zdenek Kabelac
b563c926ba cleanup: simplify 2021-03-14 16:34:38 +01:00
Zdenek Kabelac
236a45dfc5 toollib: preserve return code 5 2021-03-11 00:56:43 +01:00
Zdenek Kabelac
2cbe88d6a1 debug: display_lvname 2021-03-11 00:18:01 +01:00
Zdenek Kabelac
d7bb23dd15 cov: initialize value
Coverity can't understand conditions together, so just keep it quiet.
2021-03-11 00:18:01 +01:00
Zdenek Kabelac
23afad8247 cleanup: use already set vg_complete
Already set to 0.
2021-03-11 00:18:01 +01:00
Zdenek Kabelac
d86e943b80 toollib: use EINIT_FAILED for missing devs
There is really no practical reason to continue running
when we fail on allocation.

It seems we may need further fine frained errors, as for
some error type we simply need to exit ASAP, while
others may still produce usable results.
2021-03-11 00:18:01 +01:00
Zdenek Kabelac
dac8274701 toollib: prioritize processing thin-pool first
When generating list of processed LV, add thin-pool to the head of the
list, while other LVs are added on tail.

This makes it easier when removing many thin volumes, to recognize easily
when its thin-pool is also supposed to be removed.
2021-03-11 00:18:01 +01:00
Zdenek Kabelac
7a99dac9ad lvconvert: fix error path on writecache removal
After setting ret=0 there was missing 'goto out_release'.
Simplify with setting ret to 0 at front and to 1
at succesful end.
2021-03-10 23:32:12 +01:00
Zdenek Kabelac
6097dfb9ad cov: happier with defined extent_size
Set extent_size with != 0 value so there is not division by 0
in any code path.
2021-03-10 01:35:02 +01:00
Zdenek Kabelac
8a03675241 cov: variable initialization 2021-03-10 01:34:58 +01:00
Zdenek Kabelac
74936f53f7 cov: unused value 2021-03-10 01:29:44 +01:00
Zdenek Kabelac
d95c0e977c cov: remove unnecessary headers 2021-03-10 01:29:44 +01:00
Zdenek Kabelac
241c63f7a7 cov: fix iter memleak in vgimportclose
Add missing release of iterator on error path.
2021-03-10 01:29:06 +01:00
Zdenek Kabelac
75037bee5d debug: more tracing
Check result of device_ids_write() and at least provide stack;
2021-03-10 01:27:13 +01:00
Zdenek Kabelac
7342ab06fc debug: change sys_error to sys_debug
These messages do not cause command error - so changing logging level
to just 'sys_debug' (so visible only with -vvvv)
2021-03-10 01:11:52 +01:00
Zdenek Kabelac
5f7a7af7f2 cleanup: no backtraces needed after log_error
Reduce double backtracing.
2021-03-10 01:11:52 +01:00
Zdenek Kabelac
413a114cdb thin: correct ptr test for thin snapshot merging
The correct test needs to actually check  'lv->snapshot' is not NULL,
so the 'find_snapshot()' can work.

Test lv_is_snapshot was actually irrelavant for this case.

Also initialize device_id.
2021-03-10 01:09:14 +01:00
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
Zdenek Kabelac
bd272e3bce lvmcmdlib: lvm2_init_threaded
cmd context has 'threaded' value that used be set
by clvmd - and allowed proper memory locking management.
Reuse same bit for dmeventd.

Since dmeventd is using 300KiB stack per thread,
we will ignore any user settings for allocation/reserved_stack
until some better solution is find.
This avoids crashing of dmevend when user changes this value
and because in most cases lvm2 should work ok with 64K stack
size, this change should not cause any problems.
2020-10-20 22:22:52 +02:00
David Teigland
91f869e43c lvconvert: move log message to fix segfault
log message was printing lv name from released vg
2020-10-02 09:23:25 -05:00
David Teigland
0143c7aebe improve message for invalid device arg in process_each_pv
Multiple commands process pvs by name using process_each_pv()
and will now have an improved error message for a device
that's excluded by filters.
2020-10-01 12:34:36 -05:00
David Teigland
74ed6e8a99 improve message for invalid device arg
for pvcreate, pvremove, vgcreate, vgextend.
2020-10-01 12:20:16 -05:00
David Teigland
450f272b31 devices: support printing the filter that rejects a device
Use of this new message function needs to be added
to various commands to improve the output.
2020-10-01 12:00:09 -05:00
David Teigland
c32d7fed4f writecache: use two step detach
When detaching a writecache, use the cleaner setting
by default to writeback data prior to suspending the
lv to detach the writecache.  This avoids potentially
blocking for a long period with the device suspended.

Detaching a writecache first sets the cleaner option, waits
for a short period of time (less than a second), and checks
if the writecache has quickly become clean.  If so, the
writecache is detached immediately.  This optimizes the case
where little writeback is needed.

If the writecache does not quickly become clean, then the
detach command leaves the writecache attached with the
cleaner option set.  This leaves the LV in the same state
as if the user had set the cleaner option directly with
lvchange --cachesettings cleaner=1 LV.

After leaving the LV with the cleaner option set, the
detach command will wait and watch the writeback progress,
and will finally detach the writecache when the writeback
is finished.  The detach command does not need to wait
during the writeback phase, and can be canceled, in which
case the LV will remain with the writecache attached and
the cleaner option set.  When the user runs the detach
command again it will complete the detach.

To detach a writecache directly, without using the cleaner
step (which has been the approach previously), add the
option --cachesettings cleaner=0 to the detach command.
2020-10-01 11:33:02 -05:00
David Teigland
d1b7438c9f pvcreate/pvremove: reimplement device checks
Reorganize checking the device args for pvcreate/pvremove
to prepare for future changes.  There should be no change
in behavior.  Stop the inverted use of process_each_pv,
which pulled in a lot of unnecessary processing, and call
the check functions on each device directly.
2020-10-01 10:09:09 -05:00
Bastian Germann
168e2ffbcd lvm: add readline alternative editline
LVM2 is distributed under GPLv2 only. The readline library changed its
license long ago to GPLv3. Given that those licenses are incompatible
and you follow the FSF in their interpretation that dynamically linking
creates a derivative work, distributing LVM2 linked against a current
readline version might be legally problematic.

Add support for the BSD licensed editline library as an alternative for
readline.

Link: https://thrysoee.dk/editline
2020-09-29 10:13:24 +02:00
David Teigland
df6f16c081 lvpoll: don't use hints
There's a bug when lvpoll attempts to write new hints,
related to the fact that lvpoll does not follow the same
scanning process as standard commands.
Fix by disabling the use of hints in lvpoll.  We may want
to renable hints in lvpoll in a way that they can be used,
if valid, but not updated if they don't exist or are invalid.
2020-09-28 13:25:57 -05:00
Zdenek Kabelac
fc9e732811 vgsplit: support for VDO volumes
Enable support and ensure VDO always moves with VDOPOOL.
2020-09-25 22:51:50 +02:00
Zdenek Kabelac
90c50c1b53 lvconvert: suppport vdo raid conversion also through vpool
User could directly use 'vdopool' LV name for conversion into raid.
(lvconvert --type raid1 vg/vdopool)
2020-09-23 14:47:30 +02:00
David Teigland
1570e76233 bcache: use indirection table for fd
Add a "device index" (di) for each device, and use this
in the bcache api to the rest of lvm.  This replaces the
file descriptor (fd) in the api.  The rest of lvm uses
new functions bcache_set_fd(), bcache_clear_fd(), and
bcache_change_fd() to control which fd bcache uses for
io to a particular device.

. lvm opens a dev and gets and fd.
  fd = open(dev);

. lvm passes fd to the bcache layer and gets a di
  to use in the bcache api for the dev.
  di = bcache_set_fd(fd);

. lvm uses bcache functions, passing di for the dev.
  bcache_write_bytes(di, ...), etc.

. bcache translates di to fd to do io.

. lvm closes the device and clears the di/fd bcache state.
  close(fd);
  bcache_clear_fd(di);

In the bcache layer, a di-to-fd translation table
(int *_fd_table) is added.  When bcache needs to
perform io on a di, it uses _fd_table[di].

In the following commit, lvm will make use of the new
bcache_change_fd() function to change the fd that
bcache uses for the dev, without dropping cached blocks.
2020-09-18 15:10:11 -05:00
Zdenek Kabelac
c285bf2f37 headers: remove unused headers 2020-09-14 00:15:14 +02:00
Zdenek Kabelac
a9cb96f146 lvconvert: check if LV has cow type
Cow may not be a COW type, the return value of origin_from_cow(cow) may be NULL.

Reported-by: Wu Guanghao <wuguanghao3@huawei.com>
Reported-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
2020-09-12 12:55:20 +02:00
Zdenek Kabelac
463a61e62e revert "lvconvert: check if LV has snapshot type"
This reverts commit 7db124774a.
Actually we need to check for lv_is_cow().
2020-09-12 12:55:17 +02:00
Wu Guanghao
7db124774a lvconvert: check if LV has snapshot type
Cow may not be a snapshot type, the return value of origin_from_cow(cow) may be NULL

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
2020-09-11 21:48:37 +02:00
Wu Guanghao
223b75ee91 lvconvert_poll: ensure LV has snapshot type
LV may not be a snapshot type, the return value of find_snapshot(lv) may be NULL.
Here, we will call stack if LV is not a snapshot type.

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
2020-09-11 21:47:34 +02:00
Wu Guanghao
d71199920f pvmove: check return value of top_level_lv_name()
The return value of top_level_lv_name() may be NULL, so we should
check return value of top_level_lv_name before calling
strcmp(lv->name, top_level_lv_name(vg, lv_name)).

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
2020-09-11 21:43:08 +02:00
Zdenek Kabelac
8d6f1f9768 lvconvert: flip return value of _raid_split_image_conversion
Use '0' for error and '1' as success.
Also drop INTERNAL_ERROR from path - as this error
is ATM used for invalid devices.
(i.e. test lvconvert-raid1-split-trackchanges.sh)
2020-09-08 21:23:03 +02:00
David Teigland
d8bb85d963 writecache: allow pvmove on origin
The removed check didn't actually prevent pvmoving the origin,
which was possible by naming the wcorig lv, or naming no lv.
2020-09-02 14:45:52 -05:00
David Teigland
f5a669f314 pvck: repair should clear hints
repairing a pv can cause the hint file to become incorrect
2020-09-02 14:21:17 -05:00
David Teigland
f2c1de783c integrity: always default to journal mode
lvconvert was defaulting to bitmap mode,
and lvcreate was defaulting to journal mode.
2020-09-01 17:12:28 -05:00
Zdenek Kabelac
bc13c7d246 gcc: avoid shadowing of dev_name and pvs
Since we declare dev_name in lib/device/device.h
and pvs in commands.h
rename local dev_name to device_name
and pvs to pvs_list to prevent shadowing warning.

m
2020-09-01 23:40:24 +02:00
Zdenek Kabelac
11f08dacc9 pvck: add simple check for fwrite
Add at least very light check for result code of fwrite().
2020-09-01 23:40:24 +02:00
Zdenek Kabelac
66803586ef pvck: use array of bytes
Fix typo in use array of pointers instead of array of bytes.
This fixes 'break strict-aliasing rules' warning printed with older gcc.
2020-09-01 23:40:24 +02:00
Zdenek Kabelac
4baedfc578 cleanup: add spaces between literals 2020-09-01 17:57:50 +02:00