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

4389 Commits

Author SHA1 Message Date
Zdenek Kabelac
71ff21f57c gcc: initialize variables 2023-08-23 15:10:40 +02:00
Zdenek Kabelac
61499e870a debug: common error handling 2023-08-17 22:52:08 +02:00
Zdenek Kabelac
ba36ba8853 cleanup: move allocation code
Allocate new memory after validation passed.
2023-08-17 22:52:08 +02:00
Zdenek Kabelac
dde5b81079 lvconvert: run error path code only for shared VG
Error path for locking only for share VG.
2023-08-17 22:52:08 +02:00
Zdenek Kabelac
ad73f571b8 lvconvert: move _pmspare handling before conversion 2023-08-17 20:14:47 +02:00
David Teigland
6ca97e6e62 lvmlockd: fix lvconvert to thin-pool 2023-08-16 15:29:20 -05:00
David Teigland
696ee52ffd lvmlockd: let lockd_init_lv_args set lock_args
Set the lock_args string in addition to doing initialization.
lvconvert calls lockd_init_lv_args() directly, skipping
the normal lockd_init_lv() which usually sets lock_args.
2023-08-16 15:29:20 -05:00
David Teigland
096196281e lvmlockd: fix thick to thin lv conversion 2023-08-16 15:29:19 -05:00
Zdenek Kabelac
728617d25d gcc: cleanup warnings
Correcting signess comparation.
Also use standalone /* fall through */ comment as that's
the only one supported by gcc to quiet warning.
2023-08-16 15:13:25 +02:00
Zdenek Kabelac
085c3821a8 cleanup: no longer used
Previous commit made this var unused.
2023-08-16 15:13:00 +02:00
Zdenek Kabelac
54617805b8 lvconvert: use vg mempool
Keep allocation for a VG within vg memory pool.
2023-08-16 13:31:01 +02:00
Zdenek Kabelac
13225f1371 lvconvert: fix regresion from integrity check
Testing code sliped into commit and cause regression in testing for
a raid with integrity.
2023-08-16 11:25:54 +02:00
David Teigland
e548afd175 lvconvert swapmetadata: update lvmlockd locking for uuid exchange
lvmlockd locking for swapmetadata adjusted for commit
ac36153e99 lvconvert: preserve UUID for swapped metadata

Now that the LV uuid is swapped between LVs, the lvmlockd lock can
simply be moved between them, and the same lock can continue to be
used for the LV outside of the pool.
2023-08-15 13:13:06 -05:00
Zdenek Kabelac
ee6519f8e2 debug: use just single label 2023-08-14 17:02:11 +02:00
Zdenek Kabelac
741a166f3c debug: use common error exit path 2023-08-14 17:02:11 +02:00
Zdenek Kabelac
23019946c2 lvconvert: vdo needs writable LV 2023-08-14 17:02:11 +02:00
Zdenek Kabelac
2f3d8659b1 commands: add lv_is_writable 2023-08-14 17:02:11 +02:00
Zdenek Kabelac
0b7239ebc7 lvconvert: fix ret values fro integrity remove
Fix return value from _lvconvert_integrity_remove()
as it is expected to match _add() and be 0/1.

Also add some missing log_error() messages.
2023-08-14 17:02:11 +02:00
Zdenek Kabelac
80377eeb13 lvconvert: preserve UUID on pool repair
Once lvm2 repairs pool's metadata LV and preserves the original metadata LV
with unmodified metadata, for such LV in VG use newly created UUID for new
_pmspare and actually preserve UUID for this hidden _pmspare (if it
exists).
2023-08-14 17:02:11 +02:00
Zdenek Kabelac
ac36153e99 lvconvert: preserve UUID for swapped metadata
When swapping metadata LV for a pool volume, preserve UUID for metadata
LV during the swap - this allows to better utilise locks with lvmlockd.
2023-08-14 17:02:09 +02:00
David Teigland
2928891bd0 lvconvert swapmetadata: fix lvmlockd locking
The lockd lock needs to be freed for the LV that is becoming
the new metadata LV, and a new lockd lock needs to be created
for the old metadata LV that is becoming an independent LV.
Fixes b3e45219c2
2023-08-08 16:57:22 -05:00
David Teigland
7cc414135a lvmdevices: add --delnotfound to delete entries for missing devices
Used with update: lvmdevices --update --delnotfound.
Removes all devices file entries for which no matching device is found.
2023-07-24 14:56:32 -05:00
Zdenek Kabelac
09e17f99c5 cleanup: remove double //
dev_dir ends with /.
2023-07-17 12:44:23 +02:00
Zdenek Kabelac
d6771e513e lvconvert: code shuffle
Use cachepool name for create name for metadata backup LV.
(so we do not generate 2 'sequences' of metadata filenames.)
Move path preparion before handling _pmspare.
Also drop extra call to sync_local_dev_names() as it's
already got in sync with call of exec_cmd().
2023-07-17 12:44:23 +02:00
Zdenek Kabelac
f078ffc5e6 lvconvert: add support --setactivationskip
When repair thinpool or cachepool, lvm2 leaves original metadata
volume backup. To avoid potential damage of those data, mark such
volume as 'read-only' and also allow user to use --setactivationskip
option for this volume.

TODO: likely better default would be to automatically skip, but
that might need some more thinking about recovery reporting doc.
2023-07-17 12:44:23 +02:00
Zdenek Kabelac
d040b68aee lvconvert: use public LVs for recovery
Replace the use of internal /dev/mapper names with the use of
public LV names /dev/vg/lv for use with repair tools.
For this make the activation of _pmspare LV to be handled as
a component activation with public name.
Metadata is already atomatically activated this way (as readonly).

So if there is any 'error' happening, we leave public LVs in
system.
2023-07-17 12:44:23 +02:00
Zdenek Kabelac
4d2311655b lvm-exec: refactor code
Add prepare_exec_args() for reading option list for
thin/cache_repair, thin/cache_check.
2023-07-17 12:44:23 +02:00
Zdenek Kabelac
81ef1fd0cc debug: print WARNING:
Add WARNING: in front of log_warn() messages.
2023-07-15 11:05:35 +02:00
Zdenek Kabelac
b3e45219c2 lvconvert: hanle metadataswap with lvmlockd 2023-07-15 11:05:35 +02:00
Zdenek Kabelac
b89fc0564b cleanup: indent 2023-07-14 16:52:51 +02:00
Zdenek Kabelac
a2b2ae35b2 lvresize: improve usepolices
lvresize --usepolicy requires resized LVs to be active.
(So it's not only required for shared VG).

The test for active pool needs to use lv_info to query 'layer'
otherwise the pool is considered inactive if it was not activated
explicitely - thun 'implicit' activation with VDO or ThinLV was
not managed by --usepolicy option.
2023-07-14 16:52:51 +02:00
Zdenek Kabelac
8cbba1d164 lvmlockd: enable vdo conversion
As we turn 'already' active/locked LV into a data LV of vdopool,
we just keep active lock for such volume (uuid is preserved).
2023-07-14 16:52:51 +02:00
Zdenek Kabelac
8eb3a5b557 lvconvert: thin convert locking
Fix locking when converting thick to thin LV, ensure
we take pool lock for shared VG.
2023-07-14 16:51:46 +02:00
Zdenek Kabelac
93484c2a62 man-generator: ensure p is defined
In error path, p pointer could have been undefined.
2023-07-13 21:56:47 +02:00
Zdenek Kabelac
5ce236a691 gcc: correct signess comparation
Compare int to int and unsigned to unsigned...
2023-07-13 21:31:18 +02:00
Zdenek Kabelac
64b28e0839 lvchange: add log_error for failure path
When change of monitoring fails, ensure there is log_error() printed.
2023-07-13 21:31:18 +02:00
Zdenek Kabelac
7ec97ed5f2 cov: fix memleak in vgchange
Release allocated  vgname from get_single_vgname_cmd_arg()
when it is not returned via *vgname_ret.
2023-07-12 15:18:38 +02:00
Zdenek Kabelac
857f5d6e65 lvconvert: correction for thin conversion
Updates for 39457234db.
Off-by-one for option array - need 20 fields.
Missed to clear lock_args for cachepool.
2023-07-12 15:18:38 +02:00
Zdenek Kabelac
70c911b63f pool: improve message for data persistance
Inform a user that pools using either error or zero LVs are
not able to keep any data persistant.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
39457234db lvconvert: support conversion to thin volume
Update pool conversion function to handle also conversion of
thick LV to thin LV by moving thick LV into thin pool data LV
and creating fully provissioned thin LV on top of this volume.

Reworking existing conversion to use insert_layer_for_lv co
the uuid is now kept with thin-pool - this should however not
really matter as we are doing full deactivation & activation cycle.

With conversion to thin LV user can use same set of arguments
to set chunk-size.

TODO: add some smart code to decide best values for chunks sizes.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
96123b9059 cleanup: use spelling synchronize
Use single spelling form for synchronize.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
077b46e014 lv_manip: fix move_lv_segments moved bits
For proper functionality of insert_layer_for_lv we need to
move more bits to layerd LV.

Add some missing new types and correct usage of caller,
so the new LV type is set after the movement.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
e36028b7d2 cache: update validation rules
Validate cache origin in front of the prompt.
Also add some rules to command description file.

TODO:
more validation needed also for lvcreate,
more complex rules with "OR" seems to be needed.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
88f1e7a9a7 cache: support more segtypes for caching
Enable support to cache thin/error/zero virtual targets.

Use can now select whether he want to cache whole thin-pool,
or an individual thin volume out of whole thin-pool.
Support using zero and error LVs as data volume for
cachepool is possibly useful for benchmarking, not much
can be expected from such setup.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
0dee6fc28c cache: handle error segtype
Allow to convert error LV.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
558890ad0e pool: support passing data_lv for recalculation
Support data_lv to be passed as parameter when it's not yet
attached to the pool.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
5175e87fda commands: error and zero segtype handling
Add function to work with error and zero LVs more easily.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
226429058c commands: enhance error checking for generator
No exit value 0, when the parser hits an error.
Increase some buffers since as some arg lists are getting longer.
2023-07-10 17:13:32 +02:00
Zdenek Kabelac
44b070415b commands: support query for lv_is_cow 2023-07-10 17:13:32 +02:00
Zdenek Kabelac
e84b00964f pool: avoid using artificial name internally 2023-06-29 13:55:27 +02:00
Zdenek Kabelac
6ff65e6755 vdo: check_point_frequence is unused option
This vdo parameter existed in the early stage of integration of vdo into lvm2,
but later it's been removed from vdoformat tool - so actually if
there would be any non-zero value it would cause error on lvcreate.
Option was not stored on disk in lvm2 metadata.

Remove this vdo parameter from lvm2 sources.

(Although this vdo parameter will be still accepted on cmdline through
 --vdosettings option, but it will be ignored.)
2023-06-29 13:10:42 +02:00
David Teigland
ea6b5b694b lvcreate: allow thin snapshot syntax that broke
The command "lvcreate --type thin --snapshot ..." to create a thin
snapshot would fail.

commit d651b340e6 removed the optional
"--type thin" from the command definition "lvcreate --snapshot LV_thin",
and added --type thin as AUTOTYPE.  This was correct and should not have
changed anything if all the command defs were correct, but it broke
the "lvcreate --type thin --snapshot" case.  It reveals a problem in a
different command definintion:  "lvcreate --type thin LV_thin" that was
missing --snapshot in its OO list.
2023-06-20 15:47:01 -05:00
Peter Rajnoha
e2ecc6c763
reporter: restore report type to initial value after processing report_for_selection
If we are executing 'report_for_selection' to do an internal report
just for the selection itself (not for display), we can call it more
than once. In that case, we are reusing the same selection handle
(e.g. inside 'process_each_lv_in_vg').

The selection handle has 'report_type' field which is a union of all
report types needed for the report based on selection fields we actually
use.

The 'report_type' is further clarified based on checks and rules inside
'_get_final_report_type' which 'report_for_selection' calls. Then, this
final report type unambiguously identifies proper branch to take in
'report_all_in_{pv,vg,lv}' that is called next.

If the 'report_for_selection' is called more than once with the same
selection handle, we need to make sure that we always restore the report
type to its initial value, so all the rules inside 'report_for_selection'
are applied correctly next time.

This patch fixes the missing restoration of the 'report_type' value in
'selection_handle' that is reused for recurring 'report_for_selection'
calls.

An example scenario where this failed was with selecting an LV for
removal with "lvremove --select" while using a field in the selection
that required extra DM info or DM status call for the LV (that is,
"Logical Volume Device Info Fields" and "Logical Volume Device Status Fields"
as visible in 'lvs -S help').
2023-05-31 09:38:11 +02:00
Peter Rajnoha
3b4e7d1625
toollib: provide proper hint for referencing VG uuid in case of duplicate VG names
vgrename does not support -S|--select, so do not provide a hint about
using it. Instead, provide a hint about using VG uuid directly.

❯  vgs
  WARNING: VG name vg1 is used by VGs DXjcSK-gWfu-5gLh-9Kbg-sG49-dtRr-GqXzGL and MVMfyM-sjOa-M2xV-AT4Y-JddR-h4SP-UO5Ttk.
  Fix duplicate VG names with vgrename uuid, a device filter, or system IDs.
  VG     #PV #LV #SN Attr   VSize   VFree
  vg1      1   0   0 wz--n- 124.00m 124.00m
  vg1      1   0   0 wz--n- 124.00m 124.00m

(vgrename does not support -S|--select)
❯  vgrename vg1 vg2
  WARNING: VG name vg1 is used by VGs DXjcSK-gWfu-5gLh-9Kbg-sG49-dtRr-GqXzGL and MVMfyM-sjOa-M2xV-AT4Y-JddR-h4SP-UO5Ttk.
  Fix duplicate VG names with vgrename uuid, a device filter, or system IDs.
  Multiple VGs found with the same name: skipping vg1
  Use VG uuid in place of the VG name.

(vgchange does support -S|--select)
❯  vgchange --addtag a vg1
  WARNING: VG name vg1 is used by VGs DXjcSK-gWfu-5gLh-9Kbg-sG49-dtRr-GqXzGL and MVMfyM-sjOa-M2xV-AT4Y-JddR-h4SP-UO5Ttk.
  Fix duplicate VG names with vgrename uuid, a device filter, or system IDs.
  Multiple VGs found with the same name: skipping vg1
  Use --select vg_uuid=<uuid> in place of the VG name.
2023-05-16 17:17:55 +02:00
Zdenek Kabelac
d418fc14f4 cov: hide some false positives
Hide some false positives.

Note: there must not a be blank line after coverity hiding comment.
2023-05-10 16:19:46 +02:00
Zdenek Kabelac
cc7c41abbd cov: remove unneeded header file inclusion 2023-05-10 15:27:48 +02:00
Zdenek Kabelac
58293173cf cov: check syscall result 2023-05-06 20:38:57 +02:00
Zdenek Kabelac
f038fc3b17 cov: remove unused but set variables 2023-05-06 20:38:57 +02:00
Zdenek Kabelac
fae0ed8f10 cov: ensure there is either vg or error_vg
Make it explicitely visible to coverity that
_process_pvs_in_vg() is not passing  NULL vg.
2023-05-06 19:22:05 +02:00
Zdenek Kabelac
871d9f379f cov: ensure NULL baton is not dereferenced 2023-05-06 19:22:05 +02:00
David Teigland
c4440b5b49 pvck: improve error for write to existing file 2023-04-28 13:31:39 -05:00
David Teigland
b443eac6ef support 16KB page size 2023-04-07 14:26:09 -05:00
David Teigland
390ff5be2f raidintegrity: allow writecache and cache
Allow writecache|cache over raid+integrity LV.
2023-04-05 14:24:07 -05:00
David Teigland
aa85ed1784 vgchange: allow changing system ID with majority of PVs
when used with --majoritypvs.  This allows the fail-over
of a VG between systems by changing the VG system ID when
a PV is missing.
2023-03-08 16:30:54 -06:00
Peter Rajnoha
cd14d3fcc0
toollib: fix segfault if using -S|--select with log/report_command_log=1 setting
When we are using -S|--select for non-reporting tools while using command log
reporting (log/report_command_log=1 setting), we need to create an internal
processing handle to handle the selection itself. In this case, the internal
processing handle to execute the selection (to process the -S|--select) has
a parent handle (that is processing the actual non-reporting command).

When this parent handle exists, we can't destroy the command log report
in destroy_processing_handle as there's still the parent processing to
finish. The parent processing may still generate logs which need to be
reported in the command log report. If the command log report was
destroyed prematurely together with destroying the internal processing
handle for -S|--select, then any subsequent log request from processing
the actual command (and hence an attermpt to access the command log report)
ended up with a segfault.

See also: https://bugzilla.redhat.com/show_bug.cgi?id=2175220
2023-03-07 15:29:54 +01:00
David Teigland
25cb6a042f vgimport: invalidate hints
There may be some unconventional methods of sharing disks with vgimport
where hints could cause confusion.  Hints should be disabled when
sharing disks, or pvscan --cache used to regenerate hints as needed,
but invalidating hints from vgimport might help reduce confusion.
2023-02-22 16:19:48 -06:00
Zdenek Kabelac
3ef26494f2 debug: missing backtraces 2023-02-17 00:00:12 +01:00
Zdenek Kabelac
fb930c2165 lvconvert: use log_print_unless_silent
For better -qq.
2023-02-16 13:15:03 +01:00
Zdenek Kabelac
501cc19034 lvconvert: fix return codes
Several inverted return code resulted the command returned
a success as exit code, while the function errored internally.
2023-02-16 13:15:03 +01:00
David Teigland
08265641f3 pvscan: remove warning about excluded root dev
This was trying to warn about a misconfig where the root PV
was excluded by the devices file, but it wasn't covering all
cases.  Also, it's not very useful because the root LV is
usually activated directly in the initrd.
2023-02-15 10:21:13 -06:00
David Teigland
bd05318ba2 pvscan: filter does not need to be checked for symlink names
With the recent use of DEVLINKS, there is no longer any real
point in checking the filter for symlink names.  Removing
this check should not change behavior with or without symlinks
in the filter.
2023-02-15 10:19:57 -06:00
Zdenek Kabelac
2241982f96 cov: drop unneeded header 2023-02-13 13:41:59 +01:00
Zdenek Kabelac
4791a4fc68 makefiles: allow using configure cppflags
Configure defines 'CPPFLAGS' and we should use defined value
for compilation.

Reported-by: debian
2023-02-13 13:41:59 +01:00
Zdenek Kabelac
a0437225aa makefiles: avoid piping
Addressing problem for user of system without default bash shell.

As reported "set -o pipefail" is a bashism that causes the build to
fail when /bin/sh does not point to bash.
For example, this has been observed causing build failures
on Gentoo when /bin/sh is symlinked to /bin/dash.

Rule has been reworked and we started to use .DELETE_ON_ERROR to
ensure that with any errors during file generation, such invalid
file is automatically removed.

Rules were reworked to avoid using pipe and instead use temporary
files when necessary.
Printing lines with echo was replaced with POSIX recomended 'printf'
as proposed by reporter since handling of escape characters and
the "-n" flag for "echo" aren't portable across shells.

Also some build deps has been added.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1822280
Gentoo-bug: https://bugs.gentoo.org/682404
Gentoo-bug: https://bugs.gentoo.org/716496
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1822280

Reported-by: Michael Orlitzky <michael@orlitzky.com>

TODO: investage if the temporary files could be handled via some
intermediate target solution - ATM I couldn't make it work equally
well as current solution use shell 'trap' to remove temp file.
2023-02-10 17:50:27 +01:00
Zdenek Kabelac
a032e07578 makefiles: keep removing anchient files
Commit dropping lvmetad support 117160b27e
also removed cleaning of its generated files. However we need to keep
this functionality, otherwise we can leak them during various bisect.
Easier is to keep such rules forever.

Also commit c1ab9fb37f moved cmds.h to
include, so again keep it removed so it's not left there and in any
case could not misslead anyone.
2023-02-10 17:50:27 +01:00
Zdenek Kabelac
1fb5107eea lvresize: better detection of BLKID_SUBLKS_FSINFO
Use configure detection instead of trying to directly include
blkid.h inside lvresize.c - where we do not pass in BLKID_CFLAGS
and since we actually do not need to use blkid there, introeduce
test variable HAVE_BLKID_SUBLKS_FSINFO and avoid trying to
use blkid.h in this place - this also fixes builing problem for
systems without blkid.h.
2023-02-10 17:50:27 +01:00
Zdenek Kabelac
e3534d0f68 lvm: fix typos
Patch aec5e573af was fixing some
of typos only in generated file, but they need to be fixed in
the source files.
2023-02-10 17:50:27 +01:00
Jory Pratt
a1a1439215 vgimportdevices: LOCK_EX requires <sys/file.h> include
https://linux.die.net/man/2/flock

Bug: https://bugs.gentoo.org/887259
2023-02-10 17:50:27 +01:00
David Teigland
be124ae810 vgimportclone: fix non-duplicate PV with non-unique basevgname arg
Fix hang of vgimportclone command when:
the PV(s) being imported are not actually clones/duplicates, and
the -n vgname arg is the same as the current vgname.

(Not the intended use of the command, but it should still work.)

In this case, the old and new vgnames ended up being the same, when
the code expected they would be different.  A file lock on both the
old and new vgnames is used, so when both flocks are on the same
file, the second blocks indefinitely.

Fix the new vgname to be the old name plus a numeric suffix, which
is the expected result.
2023-02-09 17:37:22 -06:00
Zdenek Kabelac
94eda42e7a lv/vgchange: when refreshing whole vg skip snapshot
When refreshing all LVs in a VG, skip processing of thick snapshots,
since they will be refreshed through its origin LV.
Should reduce some unnecessary ioctl().
2023-02-01 11:48:53 +01:00
David Teigland
c9fdc828ff vgchange autoactivation: skip regex filter containing symlinks
"vgchange -aay --autoactivation event" is called by our udev rule.
When the udev rule runs, symlinks for devices may not all be created
yet.  If the regex filter contains symlinks, it won't work correctly.
This command uses devices that already passed through pvscan.  Since
pvscan applies the regex filter correctly, this command inherits the
filtering from pvscan and can skip the regex filter itself.

See the previous commit
"pvscan: use alternate device names from DEVLINKS to check filter"
2023-01-31 15:30:35 -06:00
David Teigland
17a3585cbb pvscan: use alternate device names from DEVLINKS to check filter
pvscan --cache <dev> is called by our udev rule at a time when all
the symlinks for <dev> may not be created yet (by other udev rules.)
The regex filter in lvm.conf may refer to <dev> using a symlink name
that hasn't yet been created, which would cause <dev> to not match
the filter regex.  The DEVLINKS env var, set by udev, contains all
the symlink names for <dev> that have been or will be created.
So, we add all these symlink names to dev->aliases, as if we had
found them in /dev.  This allows <dev> to be recognized by a regex
filter containing a symlink for <dev>.
2023-01-31 15:30:35 -06:00
Zdenek Kabelac
2451bc568f vdo: fix and enhance vdo constain checking
Enhance checking vdo constains so it also handles changes of active VDO LVs
where only added difference is considered now.

For this also the reported informational message about used memory
was improved to only list consuming RAM blocks.
2023-01-16 12:37:40 +01:00
lilinjie
bb34ebd4e4 fix typo
Signed-off-by: lilinjie <lilinjie@uniontech.com>
(cherry picked from commit 81b1f5bc3bac0e2e9099b67162da7d1a4995c5f4)
2023-01-11 13:52:12 +01:00
David Teigland
c4b898a53e vgimportclone: fix importing PV without metadata
If one of the PVs in the VG does not hold metadata, then the
command would fail, thinking that PV was from a different VG.
Also add missing free on that error path.
2023-01-05 14:28:31 -06:00
Zdenek Kabelac
edd6d84159 pvscan: free unused device_id
Fix memleak in function.
2022-12-20 15:04:36 +01:00
David Teigland
fa7fe5cbbe writecache: support settings metadata_only and pause_writeback
Two new settings for tuning dm-writecache.
2022-12-08 16:53:36 -06:00
David Teigland
9ce55a43d0 lvchange: handle unrecognized writecache setting
It was being ignored.
2022-12-08 15:48:30 -06:00
Zdenek Kabelac
b9f35e07db lvcreate: fix error path return values
Return failing error code for return path, as 'return 0' in this
case was returning success.
2022-11-08 12:39:25 +01:00
David Teigland
c98617c593 devices: factor common list functions
which were duplicated in various places
2022-11-07 11:38:46 -06:00
David Teigland
761b922178 device_id: handle duplicate serial numbers
Handle multiple devices using the same serial number as
their device id.  After matching devices to devices file
entries, if there is a discrepency between the ondisk PVID
and the devices file PVID, then rematch devices to
devices file entries using PVID, looking at all disks
on the system with the same serial number.
2022-11-07 08:56:02 -06:00
David Teigland
81f10c1d1e vgchange systemid: use tag or select
The command can do this but the command defs
were missing the annotation to allow it.
2022-10-31 08:54:33 -05:00
Peter Rajnoha
908555459f toollib: do not process just created historical LV
When executing process_each_lv_in_vg, we process live LVs first and
after that, we process any historical LVs. In case we have just removed
an LV, which also means we have just made it "historical" and so it
appears as fresh item in vg->historical_lvs list, we have to skip it
when we get to processing historical LVs inside the same process_each_lv_in_vg
call.

The simplest approach here, without introducing another LV list, is to
simply mark such historical LVs as "fresh" directly in struct
historical_logical_volume when we have just removed the original LV
and created the historical LV for it. Then, we just need to check the
flag when processing historical LVs and skip it if it is "fresh".

When we read historical LVs out of metadata, they are marked as
"not fresh" and so they can be processed as usual.

This was mainly an issue in conjuction with -S|--select use:

	#  lvmconfig --type diff
	metadata {
		record_lvs_history=1
	}

(In this example, a thin pool with lvol1 thin LV and lvol2 and lvol3 snapshots.)

	#  lvs -H vg -o name,pool_lv,full_ancestors,full_descendants
	  LV    Pool FAncestors  FDescendants
	  lvol1 pool             lvol2,lvol3
	  lvol2 pool lvol1       lvol3
	  lvol3 pool lvol2,lvol1
	  pool

	#  lvremove -S 'name=lvol2'
	  Logical volume "lvol2" successfully removed.
	  Historical logical volume "lvol2" successfully removed.

...here, the historical LV lvol2 should not have been removed because
we have just removed its original non-historical lvol2 and the fresh
historical lvol2 must not be included in the same processing spree.
2022-10-12 15:14:59 +02:00
David Teigland
13c63f0cfa lvmdevices: use deviceidtype option strictly
Only use the device id type specified by --deviceidtype,
and fail if that type is not available for the device.
2022-10-10 11:47:29 -05:00
David Teigland
1924fed308 lvresize: exclude new fs handling at build time
Exclude the new fs resizing capabilities at build time
(rather than run time) if the necessary libblkid features
are not available.  When excluded, all fs resizing options
are translated to resize_fsadm.  Accessing the new
features now requires rebuilding lvm if libblkid is
upgraded.
2022-09-28 11:16:43 -05:00
David Teigland
c1ab9fb37f make: move cmds.h
generate the header in the include dir so it
can be easily used from both lib and tools dirs.
2022-09-27 09:06:06 -05:00
David Teigland
0887896847 vgremove: remove online files in run dir
These files are automatically cleared on reboot given
that /run is tmpfs, and that remains the primary way
of clearing online files.

But, if there's extreme use of vgcreate+pvscan+vgremove
between reboots, then removing online files in vgremove
will limit the number of unused online files using space
in /run.
2022-09-14 14:19:29 -05:00
David Teigland
264827cb98 lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV.  --resizefs is the same as --fs resize.

The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.

Possible --fs values:

checksize
  Only applies to reducing size; does nothing for extend.
  Check the fs size and reduce the LV if the fs is not using
  the affected space, i.e. the fs does not need to be shrunk.
  Fail the command without reducing the fs or LV if the fs is
  using the affected space.

resize
  Resize the fs using the fs-specific resize command.
  This may include mounting, unmounting, or running fsck.
  See --fsmode to control mounting behavior, and --nofsck to
  disable fsck.

resize_fsadm
  Use the old method of calling fsadm to handle the fs
  (deprecated.) Warning: this option does not prevent lvreduce
  from destroying file systems that are unmounted (or mounted
  if prompts are skipped.)

ignore
  Resize the LV without checking for or handling a file system.
  Warning: using ignore when reducing the LV size may destroy the
  file system.

Possible --fsmode values:

manage
  Mount or unmount the fs as needed to resize the fs,
  and attempt to restore the original mount state at the end.

nochange
  Do not mount or unmount the fs. If mounting or unmounting
  is required to resize the fs, then do not resize the fs or
  the LV and fail the command.

offline
  Unmount the fs if it is mounted, and resize the fs while it
  is unmounted. If mounting is required to resize the fs,
  then do not resize the fs or the LV and fail the command.

Notes on lvreduce:

When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
  (includes activating the LV.)

With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-09-13 15:15:05 -05:00
David Teigland
18722dfdf4 lvresize: restructure code
Rewrite top level resize function to prepare for adding
new fs resizing.
2022-09-09 16:18:55 -05:00
David Teigland
b869a6ff7a fix fs block size detection
blkid_get_tag_value() is not a reliable way to query the fs
BLOCK_SIZE, so use the "probe" functions instead.
2022-09-09 15:50:00 -05:00
Zdenek Kabelac
e757965222 gcc: eliminate warnings
Gcc starts to show new warning - although unlikely to be able to hit
initialize variables to 0.
2022-09-07 14:58:01 +02:00
David Teigland
0eebd9d780 vgimportdevices: fix locking when creating devices file
Take the devices file lock before creating a new devices file.
(Was missed by the change to preemptively create the devices
file prior to setup_devices(), which was done to improve the
error path.)
2022-08-30 14:52:00 -05:00
David Teigland
3c49a2e43c vgimportdevices: change result when devices are not added
When using --all, if one VG is skipped, continue adding
other VGs, and do not return an error from the command
if some VGs are added. (A VG is skipped if it's missing PVs.)

If the command fails during devices file setup or device
scanning, then remove the devices file if it has been
newly created by the command, and exit with an error.

If devices from a named VG are not imported (e.g. the
VG is missing devices), then remove the devices file if
it has been newly created by the command, and exit with
an error.

If --all VGs are being imported, and no devices are found
to include in the devices file, then remove the devices
file if it has been newly created by the command, and
exit with an error.
2022-08-30 14:52:00 -05:00
Zdenek Kabelac
60ca2ce20f thin: rename internal function
Names matching internal code layout.
Functionc in thin_manip.c uses thin_pool in its name.
Keep 'pool' only for function working for both cache and thin pools.

No change of functionality.
2022-08-30 13:54:19 +02:00
Peter Rajnoha
e6b6a09f90 args: add ARG_NONINTERACTIVE for cmds not supported in lvm shell
Certain args can't be used in lvm shell ("interactive mode") because
they are not supported there. Add ARG_NONINTERACTIVE flag to mark
such args and error out if we're in interactive mode and at the same
time we detect use of such argument.

Currently, this is the case for --reportformat arg - we don't support
changing the format per command in lvm shell. The whole shell is running
under a reportformat chosen at shell's start.
2022-08-26 12:17:50 +02:00
Peter Rajnoha
508782a913 shell: add pre-cmd log report object type and enable lastlog for it
If we failed or logged anything before we actually execute given command
in lvm shell, we couldn't report the log using lastlog command after.
This patch adds specific 'pre-cmd' log report object type to identify
such log messages and enables lastlog to report even this log.
2022-08-22 14:06:34 +02:00
Peter Rajnoha
b4cc28c2ef lvmconfig: add --valuesonly option
The new --valuesonly option causes the lvmconfig output to contain only
values without keys for each config node. This is practical mainly in
case where we use lvmconfig in scripts and we want to assign the value
to a different custom key or simply output the value itself without the
key.

For example:

  # lvmconfig --type full activation/raid_fault_policy
  raid_fault_policy="warn"

  # lvmconfig --type full activation/raid_fault_policy --valuesonly
  "warn"

  # my_var=$(lvmconfig --type full activation/raid_fault_policy --valuesonly)

  # echo $my_var
  "warn"
2022-08-17 10:47:24 +02:00
Peter Rajnoha
81839cc4eb report: report numeric values (not string synonyms) for NUM and BIN fields with json_std format
Internally, NUM and BIN fields are marked as DM_REPORT_FIELD_TYPE_NUM_NUMBER
through libdevmapper API. The new 'json_std' format mandates that the report
string representing such a value must be a number, not an arbitrary string.
This is because numeric values in 'json_std' format do not have double quotes
around them. This practically means, we can't use string synonyms
("named reserved values") for such values and the report string must always
represent a proper number.

With 'json' and 'basic' formats, this is not an issue because 'basic' format
doesn't have any structure or typing at all and 'json' format puts all values
in quotes, including numeric ones.
2022-08-16 13:42:50 +02:00
Zdenek Kabelac
bba96e8680 vdo: fix --vdosettings parser
Parser was incorrectly parsing vdo_use_features - move the skip
of 'use_' prefix into internal loop which handles skipping of '_'.
2022-08-15 13:32:55 +02:00
Zdenek Kabelac
d0697be500 lvconvert: correct test support for vdo-pool 2022-08-15 13:32:55 +02:00
Peter Rajnoha
aa7cec61ed args: recognize 'json_std' for --reportformat cmd line arg 2022-08-11 11:10:11 +02:00
Peter Rajnoha
6cba28a335 config: recognize 'json_std' for report/output_format config setting 2022-08-11 11:10:11 +02:00
Peter Rajnoha
2fa9916493 shell: also output error message about max number of args hit with JSON format
If using JSON format for lvm shell's output, the error message about
exceeding the maximum number of arguments was not reported on output if
this condition was ever hit.

This is because the JSON format (as well as any other future format)
requires extra formatting compared to "basic" format and so it also
requires extra calls when it comes to reporting. The report needs to
be added to a report group and then popped and put on output with
specialized "dm_report_group_output_and_pop_all".

This "output and pop" is normally executed after we execute the command
in the lvm shell. When we didn't get to the command exection at all because
some precondition was not met (like hitting the limit for the number of
arguments for the command here), we skipped this important call and
so there was no log report output.

Right now, it's only this exact error message for which we need to call
"output and pop" directly, all the other error messages are about
initializing and setting the log report itself which we can't report
obviously.

Before this patch:

  lvm> pvs 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  lvm>

With this patch applied:

  lvm> pvs 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  {
      "log": [
          {"log_seq_num":"1", "log_type":"error", "log_context":"shell", "log_object_type":"cmd", "log_object_name":"", "log_object_id":"", "log_object_group":"", "log_object_group_id":"", "log_message":"Too many arguments, sorry.", "log_errno":"-1", "log_ret_code":"0"}
      ]
  }

If there's any other error message in the future before we execute the
command itself, we also need to call the "output and pop" directly.
2022-08-08 15:46:52 +02:00
Zdenek Kabelac
493acb9195 vdo: suffle code for better error path handling
For failing dm_ no need to report 2nd. error,
but we missed to report error with 'updated==NULL'.
2022-07-11 01:18:24 +02:00
Zdenek Kabelac
e2e31d9acf vdo: enhance lvcreate validation
When creating VDO pool based of  % values, lvm2 is now more clever
and avoids to create 'unsupportable' sizes of physical backend
volumes as 16TiB is maximum size supported by VDO target
(and also limited by maximum supportable slabs (8192) based on slab
size.

If the requested virtual size is approaching max supported size 4PiB,
switch header size to 0.
2022-07-11 01:18:24 +02:00
Zdenek Kabelac
ebad057579 vdo: check vdo memory constrains
Add function to check for avaialble memory for particular VDO
configuration - to avoid unnecessary machine swapping for configs
that will not fit into memory (possibly in locked section).

Formula tries to estimate RAM size machine can use also with
swapping for kernel target - but still leaving some amount of
usable RAM.

Estimation is based on documented RAM usage of VDO target.

If the /proc/meminfo would be theoretically unavailable, try to use
'sysinfo()' function, however this is giving only free RAM without
the knowledge about how much RAM could be eventually swapped.

TODO: move _get_memory_info() into generic lvm2 API function used
by other targets with non-trivial memory requirements.
2022-07-11 01:18:24 +02:00
Zdenek Kabelac
fe6fb1ec52 man: space after size
Put space between size and SI unit.
Automatically make this 'space' as fixed size by Makefile sed script.
2022-07-11 01:18:24 +02:00
David Teigland
92b4fcf57f exit with error when --devicesfile name doesn't exist 2022-07-06 10:10:58 -05:00
David Teigland
db5277c971 pvdisplay: restore --reportformat option
Fixes commit b8f4ec846 "display: ignore --reportformat"
by restoring the --reportformat option to pvdisplay.
Adding -C to pvdisplay turns the command into a reporting
command (like pvs, vgs, lvs) in which --reportformat can
be useful.
2022-06-24 10:40:54 -05:00
David Teigland
9dfa6f3879 devices file: move clean up after command is run
devices_file_exit wasn't being called between lvm_shell
commands, so the file lock wouldn't be released.
2022-05-27 12:38:43 -05:00
Peter Rajnoha
7ec0726ce3 toollib: fix segfault when handling selection with historical LVs
When processing historical LVs inside process_each_lv_in_vg for
selection, we need to use dummy "_historical_lv" for select_match_lv.

This is because a historical LV is not an actual LV, but only a tiny
representation with subset of original properties that we recorded
(name, uuid...).

To use the same processing functions we use for full-fledged non-historical
LVs, we need to use the prefilled "_historical_lv" structure which has all
the other missing properties hard-coded.
2022-05-05 11:13:39 +02:00
Zdenek Kabelac
5e060b8fa7 vdo: support --vdosettings
Allow to use --vdosettings with lvcreate,lvconvert,lvchange.
Support settings currenly only configurable via lvm.conf.
With lvchange we require inactivate LV for changes to be applied.

Settings block_map_era_length has supported alias block_map_period.
2022-05-03 19:09:52 +02:00
David Teigland
dd28460017 improve description of devices option 2022-05-02 09:47:02 -05:00
David Teigland
fb7698b0ce lvmdevices: --deldev using device id
When used with --deviceidtype, --deldev can specify
a device id to remove.
2022-04-06 12:51:34 -05:00
David Teigland
151ce8b276 vgimportdevices: fix incorrect deviceidtype usage
When a VG has PVs with different device id types,
it would try to use the idtype of the previous PV
in the loop.  This would produce an unncessary warning,
or could lead to using the devname idtype when a better
idtype is available.
2022-04-06 12:20:26 -05:00
David Teigland
f840dbb320 pvscan: warn about /dev/sda excluded by devices file
In most installations, /dev/sda* or /dev/vda* should be included
in system.devices because the root, home, etc LVs are usually on
sda or vda.

Add a special case warning when a pvscan autoactivation command
sees that /dev/sda* or /dev/vda* are excluded by system.devices,
either not listed or having a different device id.
2022-04-01 13:38:21 -05:00
David Teigland
8db3b11e4e change messages about filtered devices
Change messages that refer to devices being "excluded by filters"
to say just "excluded".  This will avoid mistaking the word
"filters" with the lvm.conf filter setting.
2022-04-01 13:38:21 -05:00
David Teigland
23a9bd549a lvmdevices update: correct multipath entries
Remove multipath components.
Add multipath devs that have multipath components listed.
2022-04-01 13:38:21 -05:00
David Teigland
86a0a652a9 fix args entry for nolocking
typo in previous commit
2022-03-25 17:25:29 -05:00
David Teigland
f1578b4a5d Move nolocking warning to man page
It's more logical to warn about --nolocking in the man page
before it's used rather than after it's used and too late.
Also, warnings are usually for things the user may not know.
2022-03-25 15:43:53 -05:00
David Teigland
72f0b637d2 vgchange monitor: don't use udev info
vgchange --monitor y is run during startup when udev is being
initialized and is not yet ready to be used.
2022-03-25 14:13:56 -05:00
David Teigland
c7a5b5cca0 pvscan: don't use udev for external device info
pvscan is used to populate udev info, so it can't expect
to use that udev info.
2022-03-09 11:54:59 -06:00
David Teigland
bef1363c00 writecache: check memory usage
warn if writecache neds > 50% of system memory, and
confirm if writecache needs > 90% of system memory.
2022-03-01 16:29:53 -06:00
David Teigland
00c3069872 devices: initial use of existing option
Use dev_cache_get_existing() in a few common, high level
locations where it's obvious that only existing dev-cache
entries are wanted.  This can be expanded and used in more
locations (or dev_cache_get can stop creating new entries.)
2022-02-24 17:22:03 -06:00
David Teigland
96c99d647e man: update cachesettings option description
to be more consistent with man page description
2022-02-16 15:37:54 -06:00
Zdenek Kabelac
f83b3962c1 asan: fix some reports from libasan
When compiled and used with:

CFLAGS="-fsanitize=address -g -O0"
ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1

we have few reported issue - they where not normally spotted, since
we were still accessing our own memory - but ouf of buffer-range.

TODO: there is still something to enhance with handling of #orphan vgids
2022-02-07 20:02:11 +01:00
David Teigland
3fce6a81f8 lvmdevices: make deldev work for missing device 2022-02-03 16:56:03 -06:00
David Teigland
f0cd54a873 writecache: look for settings in lvm.conf
Restore the lvm.conf cache_settings for writecache
added by c6639056e0.
Shorter method reduces and isolates the complexity
of config trees.
2022-01-31 16:59:37 -06:00
David Teigland
ffa07c8e39 Revert "writecache: handle options from lvm.conf"
This reverts commit c6639056e0.

Next commit restores this feature.
2022-01-31 16:54:40 -06:00
Zdenek Kabelac
b36fce26a2 activation: use lv_is_active
Use existing lv_is_active
2022-01-31 14:56:11 +01:00
Zdenek Kabelac
f8d12913e7 tools: missing sync after deactivation
Caching of DM states optimisation revealed some missing
synchronisation points.
2022-01-31 14:55:42 +01:00
Zdenek Kabelac
7f1f7ad694 lvcreate: code move 2022-01-26 15:09:58 +01:00
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