1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 20:25:52 +03:00
Commit Graph

2307 Commits

Author SHA1 Message Date
Jonathan Earl Brassow
be226be635 Fix unhandled condition in _move_lv_segments
If _move_lv_segments is passed a 'lv_from' that does not yet
have any segments, it will screw things up because the code
that does the segment copy assumes there is at least one
segment.  See copy code here:
        lv_to->segments = lv_from->segments;
        lv_to->segments.n->p = &lv_to->segments;
        lv_to->segments.p->n = &lv_to->segments;

If 'segments' is an empty list, the first statement copies over
the values, but the next two reset those values to point to the
other LV's list structure.  'lv_to' now appears to have one
segment, but it is really an ill-set pointer.
2011-03-25 22:02:27 +00:00
Jonathan Earl Brassow
58bdd1654b Replace malloc with zalloc when creating segment_type's 2011-03-25 21:59:42 +00:00
Petr Rockai
5ef2808bc7 In some cases, we could end up with a mirrored LV without a MIRRORED flag. In
other cases, the code could wind up removing wrong number of mirrors. In yet
other cases, we could remove the right number of mirrors, but fail to respect
the removal preferences (i.e. keep an image that was requested to be removed
while removing an image that was requested to be kept). Under some
circumstances, remove_mirror_images could also get stuck in an infinite loop.

This patch should fix all of the above undesirable behaviours.

Signed-off-by: Petr Rockai <prockai@redhat.com>
Reviewed-by: Jonathan Brassow <jbrassow@redhat.com>
2011-03-24 12:28:02 +00:00
Milan Broz
52a5cd31c4 Mitigate some warnings if running as non-root user.
LVM doesn't behave correctly if running as non-root user,
there is warning when it detects it.

Despite this, it produces many error messages, saying nothing.
See https://bugzilla.redhat.com/show_bug.cgi?id=620571

This patch fixes two things:
1) Removes eror message from device_is_usable() which has no
information value anyway (real warning is printed inside it).

2) it fixes device-mapper initialization, if we support
core dm module autoload and device node is present, it should
fail early and not try recreate existing and correct node.
(non-root == permission denied here)

N.B. In future code should support user roles, some more
drastic checks in code are probably contraproductive now.
2011-03-18 12:17:57 +00:00
Zdenek Kabelac
b8ccce3500 Add missing \0 for grown debug object
Attach \0 for proper char* display - otherwise somewhat random message could
be displayed in debug more and read of unpredictable read of uninitilized
memory values could happen.
2011-03-14 17:00:57 +00:00
Zdenek Kabelac
612e606392 Revert this commit
This buffer allocation must have been problem somewhere else.
(as sizeof() already has the 'extra' '\0' included).
For now reverting this commit.
2011-03-13 23:18:30 +00:00
Zdenek Kabelac
844b75f4d6 Fix allocation of system_id
As code uses strncpy(system_id, NAME_LEN) and doesn't set '\0'
Fix it by always allocating NAME_LEN + 1 buffer size and with zalloc
we always get '\0' as the last byte.

This bug may trigger some unexpected behavior of the string operation
code - depends on the pool allocator.

FIXME: refactor this code to alloc_vg.
2011-03-13 23:05:48 +00:00
Zdenek Kabelac
e1cb521dd9 Use proper size of strncpy
Avoid reading extra character if we expect to have there '\0'.
2011-03-13 23:01:08 +00:00
Zdenek Kabelac
c9c1730705 Fix buffer allocation size for uuid string
We have 3 components and traling '\0' so allocate proper room for all of them.
Problem was nicely hidden by allocation from pool and allocation aligment
offset - so to trigger real problem with this one is actually hard.
2011-03-13 22:57:51 +00:00
Zdenek Kabelac
218f657794 Fix usage of readlink
Return value of readlink limits valid string size.
Characters after returned size present some garbage to printf.
Fix it by placing '\0' on the return size value.
2011-03-13 22:52:16 +00:00
Peter Rajnoha
ff4479414c Use format instance mempool where possible and adequate. 2011-03-11 15:10:16 +00:00
Peter Rajnoha
e8d4946ec7 Various cleanups for fid mem and ref_count changes.
Missing free_vg on error_path in lvmcache_get_vg fn. Call destroy_instance
only if the fid is not part of the vg in backup_read_vg fn (otherwise it's
part of the VG we're returning and we definitely don't want to destroy it!).
2011-03-11 15:08:31 +00:00
Peter Rajnoha
2feb2a66fd Call destroy_instance for any PVs found in VG structure during vg_free call.
This is necessary for proper format instance ref_count support. We iterate
over vg->pvs and vg->removed_pvs list and the ref_count is decremented and
then it is destroyed if not referenced anymore.
2011-03-11 15:06:13 +00:00
Peter Rajnoha
84f48499a3 Add new free_pv_fid fn and use it throughout to free all attached fids.
Since format instances will use own memory pool, it's necessary to properly
deallocate it. For now, only fid is deallocated. The PV structure itself
still uses cmd mempool mostly, but anytime we'd like to add a mempool
in the struct physical_volume, we can just rename this fn to free_pv and
add the code (like we have free_vg fn for VGs).
2011-03-11 14:56:56 +00:00
Peter Rajnoha
1307ddf4cf Use only vg_set_fid and new pv_set_fid fn to assign the format instance.
This is essential for proper format instance ref_count support. We must
use these functions to set the fid everywhere from now on, even the NULL
value!
2011-03-11 14:50:13 +00:00
Peter Rajnoha
293481107f Make create_text_context fn static and move it inside create_instance fn.
We'd like to use the fid mempool for text_context that is stored
in the instance (we used cmd mempool before, so the order of
initialisation was not a matter, but now it is since we need to
create the fid mempool first which happens in create_instance fn).

The text_context initialisation is not needed anywhere outside the
create_instance fn so move it there.
2011-03-11 14:45:17 +00:00
Peter Rajnoha
a1bec4e685 Add mem and ref_count fields to struct format_instance for own mempool use.
Format instances can be created anytime on demand and it contains
metadata area information mostly (at least for now, but in the future,
we may store more things here to update/edit in a PV/VG). In case we
have lots of metadata areas, memory consumption will rise. Using cmd
context mempool is not quite optimal here because it is destroyed too
late. So let's use a separate mempool for format instances.

Reference counting is used because fids could be shared, e.g. each PV
has either a PV-based fid or VG-based fid. If it's VG-based, each PV has
a shared fid with the VG - a reference to VG's fid.
2011-03-11 14:38:38 +00:00
Peter Rajnoha
56f5b12eed Use new alloc_fid fn for common format instance initialisation. 2011-03-11 14:30:27 +00:00
Zdenek Kabelac
a6f38f9d6a Missed merge fix in vg_validate patch 2011-03-10 22:39:36 +00:00
Zdenek Kabelac
027a55d0fb Optimise _eat_space and _get_token
Makes the code more readable and has a smaller number of memory
accesses thus it's small optimisation as well.

For _get_token() optimize number parsing. Check for '.' char only
if it's not a digit. Move pointer incrementation into one place.

For _eat_space() check only p->te for '\0' in skipping of comment line.
Avoid check for '\0' when we know it is space. Also master while loop
doesn't need checking p->tb for '\0'. We just need to check p->tb
isn't already at the end of buffer. This could give 'extra' loop cycle
if we are already there - but safes memory access in every other case.
2011-03-10 14:51:35 +00:00
Zdenek Kabelac
442dbf9ad8 Refactor code for _lv_postoder
Add _lv_postorder_vg() - for calling _lv_postorder() for every LV from VG.
We use this in 2 places -  vg_mark_partial_lvs() and vg_validate()
so make it as a one function.

Benefit here is - to use only one cleanup code and avoid
potentially duplicate scans of same LVs.
2011-03-10 14:40:32 +00:00
Zdenek Kabelac
4ee2b4965f Use hash tables for validating names
Accelerate validation loop by using lvname, lvid, pvid hash tables.
Also merge pvl loop into one cycle now - no need to scan the list twice.
List scan is stopped when dm_hash_insert fails.

The error message with loop_counter1 is no longer provided - however
the message has been misleading anyway.
2011-03-10 13:11:59 +00:00
Zdenek Kabelac
3019419e95 Refactor vg allocation code
Create new function alloc_vg() to allocate VG structure.

It takes pool_name (for easier debugging).
and also take vg_name to futher simplify code.

Move remainder of _build_vg_from_pds  to _pool_vg_read
and use vg memory pool for import functions.
(it's been using smem -> fid mempool -> cmd mempool)
(FIXME: remove mempool parameter for import functions and use vg).

Move remainder of the _build_vg to _format1_vg_read
2011-03-10 12:43:29 +00:00
Alasdair Kergon
9cfdf8031e Avoid possible endless loop in _free_vginfo when 4 or more VGs have same name. 2011-03-10 03:03:03 +00:00
Alasdair Kergon
2f25c320fb Use empty string instead of /dev// for LV path when there's no VG.
Don't allocate unused VG mempool in _pvsegs_sub_single.
2011-03-09 12:44:42 +00:00
Zdenek Kabelac
2bd6583a34 Use lvm_getpagesize wrapper 2011-03-06 17:52:07 +00:00
Milan Broz
affd9c086d Fix hardcoded page size, fixing test fails with 8k page and new kernel. 2011-03-06 16:47:43 +00:00
Zdenek Kabelac
55f6627427 Fix reading of released memory
lvseg_segtype_dup used memory pool vg memory pool for strind duplication.
However this one gets released before reporting happens so the command like:

pvs -o segtype

prints data from already released memory pool. Thanks to the fact there
is not much allocation happing after the VG is released, the memory
stays unmodified and correct result is printed.

Fix adds support for mempool passed parameter (like other similar
query commands) and uses dm_report memory pool for string duplication.
2011-03-05 12:14:00 +00:00
Milan Broz
be3510b204 PE size overflows, on most architectures it is catch by "PE cannot be 0"
but s390x unfortunately return something usable.

Always use unit64 in inital parameter check.
2011-03-02 20:00:09 +00:00
Peter Rajnoha
15b9215534 Use a copy if moving an mda from pv fid to vg fid.
We'll destroy the pv fid (with all mdas in it) after merging all pv mdas to
a vg in _text_pv_setup fn, hence we need to use a copy here!
2011-03-02 10:23:29 +00:00
Peter Rajnoha
0b100565ae Make add_metadata_area_to_pv/remove_metadata_area_from_pv static.
No need to put these in format-text.h, it's not used anywhere else actually.
2011-03-02 10:19:14 +00:00
Milan Broz
cbedb99e4c Fix some compile warnings on RHEL5
- returned char not needed to be explicitly const
- warn if pipe() fails in clvmd (more fixes here needed for error paths...)
- assign (and ignore) read() output in drain buffer
2011-03-01 20:17:56 +00:00
Milan Broz
0cb777d642 Rephrase backup message. 2011-02-28 20:50:01 +00:00
Zdenek Kabelac
36653e8903 Add fall through comments
Add comments to switch case construct.
2011-02-28 19:53:03 +00:00
Peter Rajnoha
150e43a05c Use pv->vg_name directly instead of pv->vg->name in _text_pv_write.
This also prevents a possible segfault during an automatic repair
when the PV does not belong to a VG anymore and we call pv_write_orphan.
2011-02-28 17:05:48 +00:00
Peter Rajnoha
3b97e8d643 Allow non-orphan PVs with two metadata areas to be resized.
We allow writing non-orphan PVs only for resize now. The "orphan PV" assert
in pv_write fn uses the "allow_non_orphan" parameter to control this assert.
However, we should find a more elaborate solution so we can remove this
restriction altogether (pv_write together with vg_write is not atomic, we
need to find a safe mechanism so there's an easy revert possible in case of
an error).
2011-02-28 13:19:02 +00:00
Alasdair Kergon
1a52fa6858 Fix check for log-only allocation in new alloc normal loop. 2011-02-27 01:16:52 +00:00
Alasdair Kergon
92ffcda183 Various changes to the allocation algorithms: Expect some fallout.
There is a lot to test.

Two new config settings added that are intended to make the code behave
closely to the way it did before - worth a try if you find problems.
2011-02-27 00:38:31 +00:00
Peter Rajnoha
4b8f066c19 vgconvert is fixed now to work with the changes in metadata area handling - enable the tests.
Add a small fix that preserves pe_start for lvm1 PVs when being converted.

(this fix needs to be replaced with something more clever, but let's have this working now)
2011-02-25 14:12:14 +00:00
Peter Rajnoha
4a304dc1d8 Allow only orphan PVs to be resized even with two metadata areas. 2011-02-25 14:08:54 +00:00
Peter Rajnoha
f74bd57ec9 Revert the patch for vgconvert to work with recent changes in metadata area handling.
This should work now with the help of the patch from previous commit.
2011-02-25 14:02:53 +00:00
Peter Rajnoha
38b0564cab Read PV metadata information from cache if pv_setup called with pv->fid == vg->fid.
If the PV is already part of the VG (so the pv->fid == vg->fid), it makes no
sense to attach the mdas information from PV to a VG. Instead, we read new
PV metadata information from cache and attach it to the VG fid.
2011-02-25 13:59:47 +00:00
Peter Rajnoha
ea4a41e961 Fix a bug in metadata location calculation, cleanup pv_add_metadata_area fn.
This bug (a missing line) caused the 2nd MDA area location to be calculated
incorrectly and it didn't fit the disk size properly.

(https://www.redhat.com/archives/lvm-devel/2011-February/msg00127.html)
2011-02-25 13:50:02 +00:00
Peter Rajnoha
c901a92aa5 %ld -> PRIu64 2011-02-21 13:09:27 +00:00
Peter Rajnoha
9c0035c129 Fix metadata balance code to work with recent changes in metadata handling
interface (with the changes in format_instance).
2011-02-21 12:33:16 +00:00
Peter Rajnoha
51aed1992f Add old_uuid field to struct physical_volume so we can still reference a PV
with its old UUID when we're changig it (the cache as well as metadata area
index has the old uuid that we need to use to access the information!)
2011-02-21 12:31:28 +00:00
Peter Rajnoha
6bdc80743e Fix vgconvert code to work with changes in metadata area handling and changes
in format_instance. Add new 'vg_convert' function.
2011-02-21 12:29:21 +00:00
Peter Rajnoha
cb2396730a Change pvresize code to work with new metadata handling interface and allow
resizing a PV with two metadata areas.
2011-02-21 12:27:26 +00:00
Peter Rajnoha
17ad2b1115 Change pv_write code to work with the changes in metadata handling interface
and changes in format_instance.
2011-02-21 12:26:27 +00:00
Peter Rajnoha
903d7db050 Remove unused _mda_setup fn. This functionality is covered by new pv_add_metadata_area fn. 2011-02-21 12:25:16 +00:00