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

7034 Commits

Author SHA1 Message Date
Zdenek Kabelac
9c5d2874a7 clang: avoid double free on error path
Error path in _lockd_retrive_vg_pv_list() has not zeroed released path
caussing possible double-free later in the code.

Fix it by using one single function freeing lock_pvs structure.
2021-09-15 15:24:56 +02:00
Zdenek Kabelac
00ec716b4d gcc: remove invalid attribute
In this function parameter 'attribute' is used.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
9ba76450f4 cov: remove unused variable setting
Since there is no use for &end after strtol, remove it.
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
a8ee13900d cov: initialize attr 2021-09-13 12:34:41 +02:00
Zdenek Kabelac
be1c2a1ae2 cov: keep time calculation ready for 2038
Be prepared ;) and keep arithmetic 64bit ready.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
3ce8db8b88 cov: keep 64bit arithmetic
Highly unlikely this case will ever need 64bit math, but just in case,
keep the expression as 64bit.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
d489445e5a cache: implement better revert path
When cache creation fails on table reload path, implemen more
advanced revert solution, that tries to restore state of LVM
metadata into is look before actual caching started.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
4c3d7a01d4 cache: filter out unsupported policy settings
Loading invalid MQ/SMQ policy settings table line cause immediate
rejection - to prevent such failure, automatically filter valid
settins before it is being uploaded by lvm2.

For invalid setting issue a warnning informing user how to remove
them.

This solution is used to keep running cached LVs that might had
been created in the past with invalid settings that have been actually
unused due to another code bug.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
30050769b1 filters: fix memleak on mpath filter destroy
Missing free() leaks filter structure.
2021-09-13 12:34:41 +02:00
Zdenek Kabelac
e6f735d411 vdo: read new sysfs path
New versions of kvdo module exposes statistics at new location:
/sys/block/dm-XXX/vdo/statistics/...

Enhance lvm2 to access this location first.
Also if the statistic info is missing - make it 'debug' level info,
so it is not failing 'lvs' command.
2021-09-09 15:24:15 +02:00
Zdenek Kabelac
79427151dc vdo: add support for auto-unsafe writePolicy
This vdoWritePolicy policy missed matching support in lvm2.
2021-09-06 15:19:51 +02:00
Zdenek Kabelac
419c93c873 vdo: support lvcreate with skipped activation
Support creation of VDO LV for 'lvcreate -ky...'.
2021-08-31 22:05:47 +02:00
Zdenek Kabelac
88360b0c51 vdo: skip zeroing for VDO LV
Since VDO is always returns 'zero' on unprovisioned read
and every provisioned block is always 'zeroed' on partial writes,
we can avoid 'zeroing' of such LVs.
2021-08-31 22:05:47 +02:00
David Teigland
0969e90d45 devices: restrict device id types to specific major numbers
Some device id types can only be used with specific device major
numbers, so use this restriction to avoid some comparisions.
This is more efficient, and can avoid some incorrect matches.
2021-08-23 15:54:41 -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
9e79a022ea logging: messages for found metadata 2021-08-20 14:51:09 -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
David Teigland
e5c0562654 toolcontext.h: use bit field in struct
Two recent additions should have used a bit instead
of an entire int.
2021-08-12 15:51:43 -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
3e2827f3b7 cov: add initilizer 2021-07-28 00:49:28 +02:00
Zdenek Kabelac
a4eb378fe4 cov: add explicit check for vg existence
Since we check !vg - add check before accessing ->status.
2021-07-28 00:49:28 +02:00
Zdenek Kabelac
f4b49dae1e cov: raid: no more checks with missing areas
Since ->areas is directly dereferenced we need to stop
validation right here.
2021-07-28 00:49:28 +02:00
Zdenek Kabelac
b2db01b530 cov: dev-mpath: check config_wwids_file
Since config_wwids_file is checked for NULL,
test is also before calling _read_wwid_file()
that is directly dereferencing it.
2021-07-28 00:49:28 +02:00
Zdenek Kabelac
b7edda8a98 cov: guard index
Analyzer wants explicit protect to not underflow index.
2021-07-28 00:49:28 +02:00
Zdenek Kabelac
69379df8f3 cov: remove unneeded includes 2021-07-28 00:49:28 +02:00
Zdenek Kabelac
ec9dd728aa cov: memleak dir descriptor
opendir() missed closedir().
2021-07-28 00:49:22 +02: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
d38fdb25e4 thin: fix component detection of external origin
When check active componet of thinLV with external origin,
we need to check if the external origin isn't already active.
For this however we need to use layered check for -real device.
2021-07-14 12:56:08 +02:00
David Teigland
f8b52f2763 fix multipath component detection for multiple holders
sysfs-based multipath component detection quit if a
device had multiple holders, and in this case would
fail to detect a device was an mpath component.
2021-07-13 11:11:23 -05:00
David Teigland
deaf43d6f0 filter-usable: remove udev dev size check
For the pv_min_size check, always use dev_get_size()
which is commonly used elsewhere, and don't bother
asking libudev for the device size when
external_device_info_source=udev.
2021-07-13 11:11:23 -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
Heming Zhao
db22a389cf toolcontext: fix double free (core dumped) issue
How to trigger:

```
~ # export LVM_SYSTEM_DIR=_
~ # pvscan
  No matching physical volumes found
double free or corruption (!prev)
Aborted (core dumped)
```

when LVM_SYSTEM_DIR is empty, _load_config_file() won't be called.

when LVM_SYSTEM_DIR is not empty, cfl->cft links into cmd->config_files
by _load_config_file()@lib/commands/toolcontext.c

core dumped code: _destroy_config()@lib/commands/toolcontext.c

```
    /* CONFIG_FILE/CONFIG_MERGED_FILES */
    if ((cft = remove_config_tree_by_source(cmd, CONFIG_MERGED_FILES)))
        config_destroy(cft);
    else if ((cft = remove_config_tree_by_source(cmd, CONFIG_FILE)))
        config_destroy(cft); <=== first free the cft

    dm_list_iterate_items(cfl, &cmd->config_files)
        config_destroy(cfl->cft); <=== double free the cft
```

Fixes: c43f2f8ae0

Signed-off-by: Heming Zhao <heming.zhao@suse.com>
2021-07-12 14:10:21 -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
David Teigland
b876dbfc24 scan: move metadata vgname check
There have been two separate checks for metadata
validity: first that the metadata text begins with
a valid VG name, and second the checksum of the
metadata text.  These happen in different places,
which means there have been two separate error paths
for invalid metadata.  This also causes large metadata
to be read in multiple parts, the first part is read
just to check the vgname, and then remaining parts are
read later when the full metadata is needed.

This patch moves the vg name verification so it's
done just before the checksum verification, which
results in a single error path for invalid metadata,
and causes the entire metadata to be read together
rather that in parts from different parts of the code.
2021-07-06 10:10:23 -05:00
David Teigland
e035e32350 scan: retry reading metadata on error
If label_scan encounters bad vg metadata, invalidate
bcache data for the device and reread the mda_header
and metadata text back to back.  With concurrent commands
modifying large metadata, it's possible that the entire
metadata area can be rewritten in the time between a
command reading the mda_header and reading the metadata
text that the header points to.  Since the label_scan
is just assembling an initial overview of devices, it
doesn't use locking to serialize with other commands
that may be modifying the vg metadata at the same time.
2021-07-06 10:10:23 -05:00
David Teigland
d89942d157 scan: don't hold bcache block during scan
This allows data from the bcache block to be
invalidated and reread if needed.
2021-07-06 10:10:23 -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
6e773bb196 lvconvert: fix vdo virtual size when specified
Correctly use virtual size specified by:
lvconvert --type vdo-pool --virtualsize
2021-06-28 20:41:07 +02:00
Zdenek Kabelac
d9cb1d3983 config_settings: typo fix 2021-06-28 18:11:14 +02:00
David Teigland
73a05c8f02 device_id: handle qemu wwid
Ignore made-up wwid values reported for qemu devices
that contain the string "QEMU HARDDISK".  The devname
will be used as the device id.
2021-06-24 11:30:46 -05:00
David Teigland
1139a05939 device_id: handle scsi_debug wwid
Ignore the wwid value reported by scsi_debug devices
that begin "t10.Linux   scsi_debug".  The devname
will be used as the device id.
2021-06-22 13:36:10 -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
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
ca930bd936 devices: don't use deleted loop backing file for device id
check for "(deleted)" in the backing_file string and
fall back to devname for id.

$ cat /sys/block/loop0/loop/backing_file
/root/looptmp (deleted)
2021-06-08 12:16:06 -05:00
David Teigland
c43f2f8ae0 fix empty mem pool leak
of "config" when LVM_SYSTEM_DIR=""
2021-06-03 14:46:33 -05:00
David Teigland
247f69f9aa writecache: fix lv_on_pmem
dev_is_pmem on pv->dev requires a pv segment or it could segfault.
2021-06-02 10:51:12 -05:00
Zdenek Kabelac
b725b5ea6e vdo: fix preload of kvdo
Commit 5bf1dba9eb broke load of kvdo
kernel module - correct it by loading kvdo instead of trying dm-vdo.
2021-05-26 16:12:20 +02:00
David Teigland
4a746f7ffc lvremove: fix removing thin pool with writecache on data 2021-05-24 16:09:35 -05:00
Leo Yan
affe1af148 lib: locking: Parse PV list for IDM locking
For shared VG or LV locking, IDM locking scheme needs to use the PV
list assocated with VG or LV for sending SCSI commands, thus it requires
to use some places to generate PV list.

In reviewing the flow for LVM commands, the best place to generate PV
list is in the locking lib.  So this is why this patch parses PV list as
shown.  It iterates over all the PV nodes one by one, and compare with
the VG name or LV prefix string.  If any PV matches, then the PV is
added into the PV list.  Finally the PV list is sent to lvmlockd daemon.

Here as mentioned, it compares LV prefix string with the format
"lv_name_", the reason is it needs to find out all relevant PVs, e.g.
for the thin pool, it has LVs for metadata, pool, error, and raw LV, so
we can use the prefix string to find out all PVs belonging to the thin
pool.

For the global lock, it's not covered in this patch.  To avoid the egg
and chicken issue, we need to prepare the global lock ahead before any
locking can be used.  So the global lock's PV list is established in
lvmlockd daemon by iterating all drives with partition labeled with
"propeller".

Signed-off-by: Leo Yan <leo.yan@linaro.org>
2021-05-20 16:01:05 -05:00
Leo Yan
ef1c57e68f lib: locking: Add new type "idm"
We can consider the drive firmware a server to handle the locking
request from nodes, this essentially is a client-server model.
DLM uses the kernel as a central place to manage locks, so it also
complies with client-server model for locking operations.  This is
why IDM and DLM are similar with each other for their wrappers.

This patch largely works by generalizing the DLM code paths and then
providing degeneralized functions as wrappers for both IDM and DLM.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
2021-05-20 16:01:05 -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
71933d3496 devices file: recommend removing filter
When the devices file is enabled and the filter is set,
recommand that the user remove the filter from lvm.conf
since it's ignored.
2021-05-05 13:59:42 -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
Zdenek Kabelac
05eb90db68 cleanup: indent 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
6a099707c4 clang: remove unused assignment 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
8f85834a33 cov: convert to code that analyzer may better understand
Switch to code that is problematic to analyzer
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
25b672417e cov: use correct enum type
Correct function declaration.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
395ce6c2bb cov: explicitely ignore return value 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
2b3dcd754f cov: check return value
Log problems on fail path.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
86a3a0c765 cov: fix typo and reduce stack usage
Buffer on stack was for single LV name plus some  short text around.
Use of 50* was a typo so use correly 50+.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
7e13586837 cov: check _insert_dev return value
Although we try later to validate device was inserted,
we can validate return value and early-exit.
2021-04-23 23:00:55 +02:00
Zdenek Kabelac
d7237ca63a cov: add checks to prevent NULL dereference 2021-04-23 23:00:55 +02:00
Zdenek Kabelac
7e77e250a9 cov: set error_vg only when pointer is non null 2021-04-23 22:58:45 +02:00
Zdenek Kabelac
cfe26470e3 dev-cache: change message level to debug
This case happens when i.e. we convert LV to another type,
when we change existing LV into a different type - so change
to debug level and avoid confusing users with message about
Device path  not match.

We may eventually enhnace caching code to drop cached info
after taking lock and reading VG.
2021-04-23 22:58:45 +02:00
Zdenek Kabelac
2b90466f78 devicesfile: use pool memory
Switch to use command mempool instead of zalloc() as relase
part would be required otherwise.
2021-04-23 22:58:45 +02:00
Zdenek Kabelac
80ef913872 device_id: fix memleak and free idname
Remove extra code path used only for 'free()'
and free(idname) on all paths that do not add it to list
and avoid memleak in few cases.
2021-04-23 22:57:08 +02:00
Zdenek Kabelac
5e8307f4bf lvmcache: fix memory leak
With commit 0b18c25d93 there
was introduced  'zalloc()' for allocation of outdates pvs,
but no matching  'free()' is present.
Switch to use cmd mempool instead of adding free() code into
several places.
2021-04-23 22:54:41 +02:00
David Teigland
a616abba03 config: improve description for event_activation 2021-04-19 13:29:17 -05:00
David Teigland
b94f2a8b55 remove unused flag DEV_UDEV_INFO_MISSING 2021-04-16 16:01:19 -05: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
b99f7d0df9 lib: remove unused macros
Internally lvm2 is not using versioning for device-mapper.
2021-04-06 22:02:31 +02:00
Zdenek Kabelac
ff8aaadec9 mirror_percent: support interruptible check
When checking for mirror percentage with WAITEVENT (i.e. during pvmove)
handle intrruption (^C) of such wait.
2021-04-06 22:02:31 +02:00
Zdenek Kabelac
fe4f83171d signals: support also SIGTERM for breaking command
If we are signaled with SIGTERM it should be at least as good
as with SIGINT - as the command should stop ASAP.
So when lvm2 command allows signal handling we also
enable SIGTERM handling. If there are some other signals
we should handle equally -  we could just extend array.
2021-04-06 21:26:57 +02:00
Zdenek Kabelac
287565fd5d lvreduce: support --yes
Missed support for --yes with 'lvreduce' to answer 'y' to prompt.
2021-04-06 21:26:57 +02:00
Samanta Navarro
01d5e4d1ca all: fix typos 2021-03-30 13:08:14 +02:00
Zdenek Kabelac
1cedbaf137 configure: support builds without versioning
Not all libc (like musl, uclibc dietlibc) libraries support full symbol
version resolution in runtime like glibc.
Add support to not generate symbol versions when compiling against them.

Additionally libdevmapper.so was broken when compiled against
uclibc. Runtime linker loader caused calling dm_task_get_info_base()
function recursively, leading to segmentation fault.

Introduce --with-symvers=STYLE option, which allows to choose
between gnu and disabled symbol versioning. By default gnu symbol
versioning is used.
__GNUC__ check is replaced now with GNU_SYMVER.
Additionally ld version script is included only in
case of gnu option, which slightly reduces output size.

Providing --without-symvers to configure script when building against
uclibc library fixes segmentation fault error described above, due to
lack of several versions of the same symbol in libdevmapper.so
library.

Based on:
https://patchwork.kernel.org/project/dm-devel/patch/20180831144817.31207-1-m.niestroj@grinn-global.com/

Suggested-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-03-30 13:06:19 +02:00
Zdenek Kabelac
09621725d0 gcc: declaration of tmpfile shadows a global
Rename tmpfile to tmppath to avoid declaration shadowing of:

/usr/include/stdio.h:174: warning: shadowed declaration is here
2021-03-22 22:35:56 +01:00
Zdenek Kabelac
05920e3818 raid: restore mirror handling in _raid_in_sync
Function is not having the best name since it does check
no just raid LVs to be in sync.

Restore the mirror percentage checking - although without retries,
since only raid target is currently known to need it - for other
types it would be ATM a bug to get inconsistent result.
2021-03-20 10:52:24 +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
d3d28b1b64 cleanup: reduce code dupliction 2021-03-19 23:21:18 +01:00
Zdenek Kabelac
d37b19aaaa gcc: ensure buffer ends with 0 2021-03-19 23:21:18 +01:00
Zdenek Kabelac
79d8d06217 raid: move non dm functions from DEVMAPPER ifdef
When lvm is compiled without device-mapper - this functions
do not need this kernel support so move them from ifdef DEVMAPPER
sections.
2021-03-19 23:20:23 +01:00
Zdenek Kabelac
cc140f68a5 raid: resync cannot lose primary leg
Prohibity droping primary leg while resyncing.
2021-03-19 23:19:31 +01:00
Zdenek Kabelac
076e155697 raid: interruptible usleep when waiting for sync
Whiel waiting for raid to return consistent status,
use interruptible sleep - so command can break quickly.

Use lv_raid_status() to get percentage easily from status.
2021-03-19 23:17:03 +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
b35ef9d67c segtypes: macros for error and zero segtypes 2021-03-18 18:34:57 +01:00
Zdenek Kabelac
22554c3ff0 lvremove: extra code for handling thinpool data
Add some extra code to handle differently sized thin-pool
from thin-pool data volume.

ATM this can't really happen, but once we start to use multiple
commits while resizing stacked LV, we may actually get into
the position, where data LV has been already resized,
but thin-pool stayed with old size.

But for now - report difference as internal error.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
5a73399b73 lvresize: support resize of stacked virtual LV
Update the LV stack with the size also for virtual LVs.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
adc238062d dev_manager: skip also zero targets
Devices made only from 'error' target cannot be used,
but if the device is also combined from 'zero' target
the same rule can be applied as such device cannot be used.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
a9b4acd511 dev_manager: add lv_raid_status
Just like with other segtype use this function to get whole
raid status info available per a single ioctl call.

Also it nicely simplifies read of percentage info about
in_sync portion of raid volume.

TODO: drop use of other calls then lv_raid_status call,
since all such calls could already use status - so it just
adds unnecessary duplication.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
e5a600860c dev_manager: status check with info check included
Reduce ioctl count and avoid separate info check,
when we can get the same info from status ioctl.

When devmanager calls return 0, then the exists value 0
means the reason of failure is missing device in table.
In such case we avoid stack trace.

Swap the flush parameter for the vdo status function
to match thin pool status.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
8cbe4a171e thin: add extra protection
Check explicitely created LV already has thin segment.
As currenlty it's the only user - this patch should have no impact.
2021-03-18 18:34:57 +01:00
Zdenek Kabelac
d682ad619a cleanup: simplier check first 2021-03-18 18:34:57 +01:00
Zdenek Kabelac
8b2cdd8d3a debug: start with upper case
Use upper case letter to start sentence.
Also drop unneded check for vg as it's already non-null.
2021-03-17 00:50:40 +01:00
Zdenek Kabelac
94701b700b cleanup: use dm_strncpy
Use own function.
2021-03-17 00:50:22 +01:00
Zdenek Kabelac
4d75c4f597 device_is_usable: minor improve
Replace allocated buffer with local vg_name which doesn't
pass pointer to allocation.

Join some conditions together.
2021-03-17 00:49:11 +01:00
Zdenek Kabelac
0363e4de70 cleanup: typo 2021-03-15 18:59:15 +01:00
Zdenek Kabelac
8a92f70709 cov: void unused result 2021-03-15 11:13:24 +01:00
Zdenek Kabelac
f69ff4b84a debug: update message 2021-03-15 11:13:24 +01:00
Zdenek Kabelac
6e9ccf7b6f debug: keep microseconds aligned 2021-03-15 11:13:24 +01:00
Zdenek Kabelac
bc1bc4cffc debug: drop stack from regular code flow 2021-03-15 11:13:24 +01:00
Zdenek Kabelac
5edb353062 lvremove: use to_remove for snapshot removal
Reuse similar 'acceleration' as used for dependent volumes also
for snapshot  - so when origin is being removed with all thick
snapshots, don't bother with individual 'COW' detachments
and write&commits, and when possible handle this all within
a single commit.
2021-03-15 11:11:35 +01:00
Zdenek Kabelac
0a2d7c57a1 lvremove: use common routine for prompting
Move code for prompting about removed LV to a single function
and use it also to prompt for removal of origin and all its thick
snapshots and also when removing merging origin.

Function does handle postponed write_and_commit so there is
no 'in-flight' operation while waiting on [y|n] answer.
2021-03-15 11:08:47 +01:00
Zdenek Kabelac
a18409b6d1 vg_validate: fix validation of merging thin origin
Compat code and handle unusual case, where
thin snapshot is also a 'thick snapshot origin' and such
snapshot gets merged into a thin origin.

However since now lv_is_visible() (which is complex function)
replaced &VISIBLE_LV check, the whole this check seems to be
no longer useful as sum of all 3 will always match??
2021-03-15 10:59:09 +01:00
Zdenek Kabelac
ff712987a5 config: correct option name 2021-03-14 16:59:24 +01:00
Zdenek Kabelac
b4dfe026dd config: keep issue_discards in config struct
Avoid quering for this config option and keep it for removing in struct.
Also drop unused cache_vgmetadata variable.
2021-03-14 16:59:24 +01:00
Zdenek Kabelac
fab9987ad7 cleanup: move common condition 2021-03-14 16:34:38 +01:00
Zdenek Kabelac
664d3b0f22 lvremove: drop flushing dm cache before remove
Since cached LV is going to be removed together with its cache,
there is not much to gain if we try to flush cache first.
User may use 'vgcfgrestore' to get back origin + cache.
Assuming user is not using issue_discards.
When data are discarded after remove there is nothing to restore!

This change allows to futher reduce number of commits
during lvremove/vgremove.
2021-03-14 16:34:38 +01:00
Zdenek Kabelac
5141a510bd lv_info: missing check for info.exists
When &info is passed in, user needs to check for exists.
When there is NULL, return value includes check for exists.
2021-03-14 16:34:38 +01:00
Zdenek Kabelac
3608e8aee7 cache: use interruptible_usleep
Reuse code for interruptible sleeping.
2021-03-14 16:34:38 +01:00
Zdenek Kabelac
a3bb8f2ec1 activation: use interruptible_usleep
Support interruption while waiting on device close.
2021-03-14 16:34:38 +01:00
Zdenek Kabelac
941f67ed09 signals: add interruptible usleep
Add small wrapper that temporarily enables signal handling during
usleep() and return  '0' when interrupted.
2021-03-14 16:34:38 +01:00
Zdenek Kabelac
bbac843268 thinpool: correct condition
Actually we do want to flush thin-pool message for particular LV first.
Existing condition evaluated to noop.
2021-03-12 12:59:55 +01:00
Zdenek Kabelac
a654148b76 gcc: adding const 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
c4f5d93122 cleanup: eliminate unused assign 2021-03-11 00:18:01 +01:00
Zdenek Kabelac
f4543aca15 lvremove: support faster removal of thin-pools
When lvremove/vgremove removes thin volumes with its thin-pool as well,
try to skip any updates of such thin-pool, so when everything properly
deactivates, there is no message send to this thin-pool and whole
thin-pool is removed with a single commit.
2021-03-11 00:18:01 +01:00
Zdenek Kabelac
127c2fc6e2 lv_check_not_in_use: correct check
Since lv_info() may return 0 without setting info struct,
make the test correct and even more readable.
2021-03-10 23:32:12 +01:00
Zdenek Kabelac
94712e3233 cov: defined flv 2021-03-10 01:35:02 +01:00
Zdenek Kabelac
a66380ea3e cov: ensure settings is set 2021-03-10 01:35:02 +01:00
Zdenek Kabelac
f7912635a0 cov: ensure buffer is initialized 2021-03-10 01:35:02 +01:00
Zdenek Kabelac
8a03675241 cov: variable initialization 2021-03-10 01:34:58 +01:00
Zdenek Kabelac
bee9b5c1d8 cov: mask uninitialized value
Coverity doesn't track ioctl() too well, so let's just make it quiet.
2021-03-10 01:34:27 +01:00
Zdenek Kabelac
d95c0e977c cov: remove unnecessary headers 2021-03-10 01:29:44 +01:00
Zdenek Kabelac
a6075fe2f2 cov: memleak on error path 2021-03-10 01:29:44 +01:00
Zdenek Kabelac
131ca0eb95 activation: use existing LV as best effort
Returning NULL for lv_committed is basically instant crash,
so instead try with passed LV instead.
It shouldn't matter as this is internall error path anyway,
but coverity should be happier.
2021-03-10 01:29:06 +01:00
Zdenek Kabelac
15c588f931 gcc: match size of holder name to direcnt d_name
As d_name is defined as 256 avoid gcc warning - although
in our case the used size will be much smaller.
2021-03-10 01:28:08 +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
d01c17ff22 debug: more use of display_lvname 2021-03-10 01:11:52 +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
c05077f4d4 cleanup: easier print of historical lv
Drop unneeded macros.
2021-03-10 01:11:52 +01:00
Zdenek Kabelac
177b63becc backup: set in vg_commit
Another step towards better automatic handling of backup,
and automatically setup needs_backup after commit.

In some next step we should reduce number of backups and takem
then only at the command finish with  vg_committed content.
2021-03-10 01:09:46 +01:00
Zdenek Kabelac
88d04e9173 lvm-file: remove duplication of dm_is_empty_dir 2021-03-10 01:09:14 +01:00
Zdenek Kabelac
d2a3bfe6ca vg_write: shift check for exported metadata
Since we now immediatelly use created buffer for CFT creation,
the result needs to be validate before such use.
2021-03-10 01:00:18 +01:00
Zdenek Kabelac
17802084c9 bcache: fix incorrect pointer check
With commit b44db5d1a7
needs to check allocated pointer for failed malloc().

Existing check was actually no checking anything so failing
malloc here would result in segfault (although with very
low chance to ever happen).
2021-03-10 00:59:05 +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
6d6e1ae887 cleanup: compare only LV uuid part
Match VG uuid just once per list of all LVs in VG.

TODO: maybe some more efficeint tree or hash could be better here,
but since it's used not so often, the total benefit is not so great,
so ATM just reducing amount of checked bytes.
2021-03-08 15:43:27 +01:00
Zdenek Kabelac
64447e9d9b cleanup: move code
just evaluate later in code path.
2021-03-08 15:43:27 +01:00
Zdenek Kabelac
e5456c259f cleanup: simpler checks first
Minor optimizatoins...
2021-03-08 15:43:27 +01:00
Zdenek Kabelac
f4200acac2 cleanup: on stack structure instead of allocation 2021-03-08 15:43:27 +01:00