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

5026 Commits

Author SHA1 Message Date
Zdenek Kabelac
5aade9c402 topology: handle reported sizes smaller then sector
Recent kernel (4.4) start to report values smaller then sector size
(but in reporting size for SSD which support data zeroing on discard).

For now log warning and assume it really means 1 sector.

Addressing RHBZ:
https://bugzilla.redhat.com/show_bug.cgi?id=1313377
2016-03-10 18:38:54 +01:00
Zdenek Kabelac
5c415afd85 cache: check for cache fail during flush
Just WARN if the cache can't be flushed because it's failed.
2016-03-10 18:38:53 +01:00
Peter Rajnoha
9918d95490 metadata: do not issue warning message about PV dev size being 0 when the device has gone just after VG read
There's a window between doing VG read and checking PV device size
against real device size. If the device is removed in this window,
the dev cache still holds struct device and pv->dev still references
that and that PV is not marked as missing. However, if we're trying
to get size for such device, the open fails because that device
doesn't exists anymore.

We called existing pv_dev_size in _check_pv_dev_sizes fn. But
pv_dev_size assigned a size of 0 if the dev_get_size it called failed
(because the device is gone).

So call the dev_get_size directly and check for the return code
in _check_pv_dev_sizes and go further only if we really know the
device size. This is to avoid confusing warning messages like:

  Device /dev/sdd1 has size of 0 sectors which is smaller than corresponding PV size of 31455207 sectors. Was device resized?
  One or more devices used as PVs in VG helter_skelter have changed sizes.
2016-03-10 13:11:15 +01:00
David Teigland
8f01ee3035 remove unused define 2016-03-09 13:38:04 -06:00
Alasdair G Kergon
90c5d470c2 report: Tidy some field names, widths and headings.
Specifying an output width of 0 now leads to a default minimum width
taken from the width of the column heading.  (Most fields should use
this.)

Components of field names are generally separated by underscores (which
are optional at run-time).  (Dropped 3 duplicate fields now covered by
this rule.)

Each field heading must be unique and generally doesn't have spaces
between words (which get capitalised) unless they are already short and
the fields are normally longer or clarity demands it.
2016-03-08 19:50:22 +00:00
David Teigland
a8319e62c0 vgscan: add --notifydbus to send a notification
This command option can be used to trigger a D-Bus
notification independent of the usual notifications
that are sent from other commands as an effect of
changes to PV/VG/LV state.  If lvm is not built with
dbus notification support or if notify_dbus is disabled
in the config, this command will exit with an error.
2016-03-07 10:50:45 -06:00
David Teigland
2d5dc6512e dbus: add notification from commands
When a command modifies a PV or VG, or changes the
activation state of an LV, it will send a dbus
notification when the command is finished.  This
can be enabled/disabled with a config setting.
2016-03-07 10:06:09 -06:00
Heinz Mauelshagen
18cf5e8e67 raid_manip: allow for raid leg to be replaced when not both data and metadata image are on pvs
resolves rhbz#1130329
2016-03-07 15:25:30 +01:00
Peter Rajnoha
d03b1779b4 coverity: fix possible resource leak in _print_historical_lv function
The code in _print_historical_lv function works with temporary
"descendants_buffer" that is allocated and freed within this
function.

When printing text out, we used "outf" macro which called
"out_text" fn and it checked return value and if failed,
the macro called "return_0" automatically. But since we
use the temporary buffer, if any of the out_text calls
fails, we need to deallocate this buffer properly - that's
the "goto_out", otherwise we'll be leaking memory.

So add new "outfgo" helper macro which does the same as "outf",
but it calls "goto_out" instead of "return_0" so we can jump
to a cleanup hook at the end.
2016-03-07 10:43:50 +01:00
Peter Rajnoha
fa06c2263b cleanup: comment in the code for renaming historical LVs 2016-03-04 11:46:29 +01:00
Peter Rajnoha
27245d97e5 lvrename: support renaming historical logical volumes 2016-03-04 11:36:24 +01:00
Peter Rajnoha
b114b4d723 commands: lvdisplay: recognize -H|--history switch 2016-03-04 10:27:45 +01:00
Peter Rajnoha
8a601454e1 metadata: automatically remove invalid (dangling) historical LVs
Historical LV is valid as long as there is at least one live LV among
its ancestors. If we find any invalid (dangling) historical LVs, remove
them automatically.
2016-03-03 13:50:59 +01:00
Peter Rajnoha
1297b0c8be metadata: also validate historical LVs in VG in vg_validate and check_lv_segments 2016-03-03 13:50:59 +01:00
Peter Rajnoha
fc628e92ba metadata: also look at historical LVs when checking LV name availability
Live LVs and historical LVs are in one namespace and the name needs to
be unique in whole VG.
2016-03-03 13:50:59 +01:00
Peter Rajnoha
ff6e124a33 conf: add metadata/lvs_history_timeout configuration setting 2016-03-03 13:50:59 +01:00
Peter Rajnoha
74272e163d metadata: add vg_strip_outdated_historical_lvs fn and call it during VG read
The vg_strip_outdated_historical_lvs iterates over the list of historical LVs
we have and it shoots down the ones which are outdated.

Configuration hook to set the timeout will be in subsequent patch.
2016-03-03 13:50:59 +01:00
Peter Rajnoha
53b064b9ae commands: lvremove: also process historical LVs 2016-03-03 13:50:59 +01:00
Peter Rajnoha
f833a6d074 metadata: add historical_glv_remove 2016-03-03 13:50:57 +01:00
Peter Rajnoha
ccebf3100d conf: add metadata/record_lvs_history configuration setting
The metadata/record_lvs_history is global switch which enables or
disables recording historical LVs in metadata.

If both metadata/record_lvs_history=1 lvm.conf option and
--nohistory command switch is used at the same time, the
--nohistory prevails.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
f545dd5952 metadata: honour 'nohistory' switch when removing thin LVs
When --nohistory switch is used with lvremove, the LV that is removed is
not recorded in metadata as 'historical LV'.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
9a34de9cb9 cmd: add 'nohistory' option and wire it up in cmd_context
The --nohistory switch will cause historical LVs to not be recorded
in metadata on demand.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
8f47119f6f report: add new 'none' lv_layout and 'history' lv_role and mark historical LVs that way
Report proper values for historical LVs in lv_layout and lv_role fields.
Any historical LV doesn't have any layout anymore and the role is "history".

For example:

$ lvs -H -o name,lv_attr,lv_layout,lv_role vg/-lvol1
  LV     Attr       Layout     Role
  -lvol1 ----h----- none       public,history
2016-03-03 13:49:15 +01:00
Peter Rajnoha
0339a5f447 report: add full_descendants field to display descendants with history
Same as lv_full_ancestors, but the other way round in the ancestry chain.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
715f1fb4c4 report: add full_ancestors field to display ancestors with history
The lv_full_ancestors reporting field is just like the existing
lv_ancestors field but it also takes into account any history and
indirect relations recorded.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
f228750386 report: report historical LV names with '-' prefix
All names for historical LVs are prefixed with '-' character to make clear
difference between live and historical LVs. The '-' can't be set by users
for live LV names during lvcreate hence we never get into a conflict with
the names that user defines for live LVs.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
8b9953e8c5 report: display (h)istorical state in lv_attr field
The 'historical' state is displayed as 5th bit ("state") in the lv_attr
field and denoted by new 'h' character.
2016-03-03 13:49:15 +01:00
Peter Rajnoha
2af5971523 report: add lv_historical field to identify historical LVs
The lv_historical reporting field is a simple binary field that reports
whether an LV is historical one ("historical" value or value of "1" displayed)
or not (blank string "" or value of "0" displayed).
2016-03-03 13:49:15 +01:00
Peter Rajnoha
28f96d5ab6 report: display lv_name,lv_uuid,vg_name,lv_time and new lv_time_removed for historical LVs 2016-03-03 13:49:14 +01:00
Peter Rajnoha
f7e0a4cc18 cmd: add '-H|--history' switch and wire it up in cmd_context and processing_handle
This patch adds "include_historical_lvs" field to struct cmd_context to
make it possible for the command to switch between original funcionality
where no historical LVs are processed and functionality where historical
LVs are taken into account (and reported or processed further). The switch
between these modes is done using the '-H|--history' switch on command
line.

The include_historical_lvs state is then passed to process_each_* fns
using the "include_historical_lvs" field within struct processing_handle.
2016-03-03 13:49:14 +01:00
Peter Rajnoha
baee45a103 metadata: add lv_is_historical fn to test if the LV is historical one 2016-03-03 13:49:14 +01:00
Peter Rajnoha
673bc0636c metadata: format_text: interconnect historical LVs among each other and also with live LVs
Interconnect historical LVs in an ancestry chain and also connect the first/last
one with its live ancestor/descendant if it exists.
2016-03-03 13:49:13 +01:00
Peter Rajnoha
a61bc70f62 metadata: add support for interconnection of thin pool LV segment with indirect origin
Add support for making an interconnection between thin LV segment and
its indirect origin (which may be historical or live LV) - add a new
"indirect_origin" argument to attach_pool_lv function.
2016-03-03 13:46:40 +01:00
Peter Rajnoha
c45af2df4e metadata: add find_historical_glv fn
The find_historical_glv is helper function that looks up historical
LV in struct volume_group's historical_lvs list and returns it if
found.
2016-03-03 13:46:39 +01:00
Peter Rajnoha
a0842d1f25 metadata: format_text: import historical LVs
Import historical LV list from metadata and add it to struct
volume_group's historical_lvs list.
2016-03-03 13:46:39 +01:00
Peter Rajnoha
54d3d976c7 metadata: format_text: reuse _print_timestamp fn 2016-03-03 13:46:39 +01:00
Peter Rajnoha
3a0ef77305 metadata: format_text: also export historical LVs
Also export historical LVs when exporting LVM2 metadata.
This is list of all historical LVs listed in
"historical_logical_volumes" metadata section with all
the properties exported for each historical LV.

For example, we have this thin snapshot sequence:

  lvol1 --> lvol2 --> lvol3
                 \
                  --> lvol4

We end up with these metadata:

logical_volume {
  ...
  (lvol1, lvol3 and lvol4 listed here as usual - no change here)
  ...
}

historical_logical_volumes {
  lvol2 {
    id = "S0Dw1U-v5sF-LwAb-W9SI-pNOF-Madd-5dxSv5"
    creation_time = 1456919613      # 2016-03-02 12:53:33 +0100
    removal_time = 1456919620       # 2016-03-02 12:53:40 +0100
    origin = "lvol1"
    descendants = ["lvol3", "lvol4"]
  }
}

By removing lvol1 further, we end up with:

historical_logical_volumes {
  lvol2 {
    id = "S0Dw1U-v5sF-LwAb-W9SI-pNOF-Madd-5dxSv5"
    creation_time = 1456919613      # 2016-03-02 12:53:33 +0100
    removal_time = 1456919620       # 2016-03-02 12:53:40 +0100
    origin = "-lvol1"
    descendants = ["lvol3", "lvol4"]
  }

  lvol1 {
    id = "me0mes-aYnK-nRfT-vNlV-UiR1-GP7r-ojbROr"
    creation_time = 1456919608      # 2016-03-02 12:53:28 +0100
    removal_time = 1456919767       # 2016-03-02 12:56:07 +0100
  }
}
2016-03-03 13:46:18 +01:00
Peter Rajnoha
790b2e8748 metadata: create historical LVs when LVs are removed and interconnect with live LVs
When an LV is being removed, we create an instance of
"struct historical_logical_volume" wrapped up in
"struct generic_logical_volume".

All instances of "struct historical_logical_volume" are then recorded in
"historical_lvs" list which is part of "struct volume_group".

The "historical LV" is then interconnected with "live LVs" to
connect a history chain for the live LV.
2016-03-03 11:26:51 +01:00
Peter Rajnoha
eeaa5a4481 metadata: add add_glv_to_indirect_glvs and remove_glv_from_indirect_glvs
The add_glv_to_indirect_glvs is a helper function that registers a
volume represented by struct generic_logical_volume instance ("glv")
as an indirect user of another volume ("origin_glv") and vice versa -
it also registers the other volume ("origin_glv") as indirect_origin
of user volume ("glv").

The remove_glv_from_indirect_glvs does the opposite.
2016-03-03 11:26:51 +01:00
Peter Rajnoha
937f72b168 metadata: add get_or_create_glv and get_or_create_glvl
The get_or_create_glv is helper function that retrieves any existing
generic_logical_volume wrapper for the LV. If the wrapper does not exist
yet, it's created.

The get_org_create_glvl is the same as get_or_create_glv but it creates
the glv_list wrapper in addition so it can be added to a list.
2016-03-03 11:26:51 +01:00
Peter Rajnoha
e573eca554 metadata: add infrastructure to track LV history
Add new structures and new fields in existing structures to support
tracking history of LVs (the LVs which don't exist - the have been
removed already):

  - new "struct historical_logical_volume"
    This structure keeps information specific to historical LVs
    (historical LV is very reduced form of struct logical_volume +
     it contains a few specific fields to track historical LV
     properties like removal time and connections among other LVs).

  - new "struct generic_logical_volume"
    Wrapper for "struct historical_logical_volume" and
    "struct logical_volume" to make it possible to handle volumes
    in uniform way, no matter if it's live or historical one.

  - new "struct glv_list"
    Wrapper for "struct generic_logical_volume" so it can be
    added to a list.

  - new "indirect_glvs" field in "struct logical_volume"
    List that stores references to all indirect users of this LV - this
    interconnects live LV with historical descendant LVs or even live
    descendant LVs.

  - new "indirect_origin" field in "struct lv_segment"
    Reference to indirect origin of this segment - this interconnects
    live LV (segment) with historical ancestor.

  - new "this_glv" field in "struct logical_volume"
    This references an existing generic_logical_volume wrapper for this
    LV, if used. It can be NULL if not needed - which means we're not
    handling historical LVs at all.

  - new "historical_lvs" field in "struct volume group
    List of all historical LVs read from VG metadata.
2016-03-03 11:26:51 +01:00
Zdenek Kabelac
e04a0184cb cleanup: use lv_is_partial
Check for PARTIAL_LV flag in standard way.
2016-03-03 10:17:03 +01:00
Zdenek Kabelac
a975dc530e cleanup: use _field_string
Make at least some 'advantage' in use local func and do dereference
internally from char pointer and use short list of params.
2016-03-03 10:17:03 +01:00
Zdenek Kabelac
88ce15004e cache: add kernel_cache_policy option
Pair kernel_cache_settings with kernel_cache_policy.
There is very small chance in error case that the value in table
might be differnet from the value stored in metadata
so make it 'checkable'.
2016-03-03 10:14:23 +01:00
David Teigland
57cd94b9e3 pvs: replace 'unknown device' with [unknown]
A config setting can restore the old string.
2016-03-01 11:12:03 -06:00
David Teigland
250b915364 pvs: display VG name [unknown] for used PV without metadata
Rather than displaying a blank field for VG name.
2016-02-29 11:17:55 -06:00
Alasdair G Kergon
9898126596 report: Shift (u)sed pv_attr under (a)llocatable.
Showing 'u' in the pv_attr reporting field is mostly unnecessary because
most PVs are allocatable, and being allocatable implies it is (u)sed,
and this is already obvious from other fields in the default 'pvs'
output like the VG name.

So move the new (u)sed pv_attr from character position 4 to 1, and only
show it in those rare cases when the PV is not (a)llocatable or the
relevant metadata is missing.

(Scripts should not be using pv_attr, but rather pv_allocatable,
pv_exported, pv_missing, pv_in_use etc.)
2016-02-26 15:46:37 +00:00
David Teigland
88530b2ef3 pvcreate: fix data alignment error check
Make the data_alignment variable 64 bits so it
can hold the invalid command line arg used in
pvreate-usage.sh pvcreate --dataalignment 1e.

On 32 bit arches, the smaller variable wouldn't
hold the invalid value so the error would not
trigger as expected by the test.
2016-02-25 17:02:18 -06:00
Zdenek Kabelac
1a9f743eef cleanup: drop unneeded test
dmfree tests for NULL
2016-02-25 23:30:25 +01:00
Zdenek Kabelac
e9b523e304 cleanup: indent
Last update missed to indent params.
2016-02-25 23:30:25 +01:00
David Teigland
172bad0d56 Use a common message for a used PV
Change some inconsistent messages and adopt
the new wording "PV %s is used by" in place
of "PV %s is marked as belonging to"
or "PV %s belongs to".
2016-02-25 14:23:41 -06:00
Peter Rajnoha
42ae586fa7 lvmcache: fix missing free of vginfo->system_id causing mem leak 2016-02-25 16:25:27 +01:00
David Teigland
a77ded3001 replace pvcreate_params with pvcreate_each_params
"pvcreate_each_params" was a temporary name used
to transition from the old "pvcreate_params".

Remove the old pvcreate_params struct and rename the
new pvcreate_each_params struct to pvcreate_params.
Rename various pvcreate_each_params terms to simply
pvcreate_params.
2016-02-25 09:14:10 -06:00
David Teigland
4de6caf5b5 redefine pvcreate structs
New pv_create_args struct contains all the specific
parameters for creating a PV, independent of the
command.
2016-02-25 09:14:10 -06:00
David Teigland
c201ee09bd metadata: add fixme about code used only by liblvm 2016-02-25 09:14:10 -06:00
David Teigland
04d34da706 pvremove: use common toollib processing code
Use the new pvcreate_each_device() function from
toollib.
2016-02-25 09:14:09 -06:00
David Teigland
0cd7d2332c liblvm: replace pvcreate_single with pvcreate_vol
And remove the pvcreate_single wrapper.
2016-02-25 09:14:09 -06:00
David Teigland
a9940bd3c9 vgcreate: use the common toollib pv create
Use the new pvcreate_each_device() function from
toollib, previously added for pvcreate, in place
of the old pvcreate_vol().

This also requires shifting the location where the
lock is acquired for the new VG name.  The lock for
the new VG is supposed to be acquired before pvcreate.
This means splitting the vg_lock_newname() out of
vg_create(), and calling vg_lock_newname() directly
before pvcreate, and then calling the remainder of
vg_create() after pvcreate.

The new function vg_lock_and_create() now does
vg_lock_newname() + vg_create(), like the previous
version of vg_create().

The lock on the new VG name is released before the
pvcreate and reacquired after the pvcreate because
pvcreate needs to reset lvmcache, which doesn't work
when locks are held.  An exception could likely be
made for the new VG name lock, which would allow
vgcreate to hold the new VG name lock across the
pvcreate step.
2016-02-25 09:14:09 -06:00
David Teigland
71671778ab toollib: add two phase pv processing code
This is common code for handling PV create/remove
that can be shared by pvcreate/vgcreate/vgextend/pvremove.
This does not change any commands to use the new code.

- Pull out the hidden equivalent of process_each_pv
  into an actual top level process_each_pv.

- Pull the prompts to the top level, and do not
  run any prompts while locks are held.
  The orphan lock is reacquired after any prompts are
  done, and the devices being created are checked for
  any change made while the lock was not held.

Previously, pvcreate_vol() was the shared function for
creating a PV for pvcreate, vgcreate, vgextend.
Now, it will be toollib function pvcreate_each_device().

pvcreate_vol() was called effectively as a helper, from
within vgcreate and vgextend code paths.
pvcreate_each_device() will be called at the same level
as other process_each functions.

One of the main problems with pvcreate_vol() is that
it included a hidden equivalent of process_each_pv for
each device being created:

  pvcreate_vol() -> _pvcreate_check() ->

   find_pv_by_name() -> get_pvs() ->

     get_pvs_internal() -> _get_pvs() -> get_vgids() ->

       /* equivalent to process_each_pv */
       dm_list_iterate_items(vgids)
         vg = vg_read_internal()
         dm_list_iterate_items(&vg->pvs)

pvcreate_each_device() reorganizes the code so that
each-VG-each-PV loop is done once, and uses the standard
process_each_pv function at the top level of the function.
2016-02-25 09:14:09 -06:00
David Teigland
ff2267012a vgconvert: refactor to avoid pvcreate code
This uses the vg->pv_write_list in place of the
vg->pvs_to_write list, and eliminates the use of
pvcreate_params.  The label remove and zeroing
steps are shifted out of vg_write() to the higher
level like pvcreate will do.
2016-02-25 09:14:09 -06:00
David Teigland
5dd615c41e metadata: use pv_write_list for _check_old_pv_ext_for_vg
The _check_old_pv_ext_for_vg() function only needs to
do pv_write(), so it can use the simpler pv_list structs
on the pv_write_list.
2016-02-25 09:14:09 -06:00
David Teigland
bafbc72c8c metadata: refactor part of add_pv_to_vg
This shifts the use of the 'pv_to_write' struct
and the 'pvcreate_params' struct to the one
caller of add_pv_to_vg, which is made static.
2016-02-25 09:14:09 -06:00
David Teigland
5e5ad77f5f vg_write: add list of pvs to write
The vg->pv_write_list contains pv_list structs for which
vg_write() should call pv_write().

The new list will replace vg->pvs_to_write that contains
vg_to_create structs which are used to perform higher-level
pvcreate-related operations. The higher level pvcreate
operations will be moved out of vg_write() to higher levels.
2016-02-25 09:14:09 -06:00
David Teigland
e793253084 lvmlockd: fix sparse snapshot case
A snapshot can be created without a real origin LV
in this case, so there's no lock to use.
2016-02-23 15:45:25 -06:00
Zdenek Kabelac
9267e0c5e7 cleanup: use braces around macro params 2016-02-23 21:40:17 +01:00
Zdenek Kabelac
63c052b9e2 coverity: ensure thin_pool_seg is not NULL
thin_pool_seg being NULL would be an internal error.
2016-02-23 21:40:17 +01:00
Zdenek Kabelac
ddfec5b51a coverity: use same arithmetic for both major and minor
Run all arithmetic in the same 'dev_t' type.
2016-02-23 21:40:17 +01:00
Zdenek Kabelac
9e3a9eab0e coverity: check for dm_snprintf
Check return state like everywhere else.
2016-02-23 21:40:17 +01:00
Zdenek Kabelac
68955a8102 coverity: ensure non-null pointers are used
Here is too complex for Coverity to guess
those pointers cannot be NULL, but it's
very easy to add little checks here.
2016-02-23 21:40:16 +01:00
Zdenek Kabelac
eaaae185b7 coverity: check for zero length buffer
When get_shared_library_path() would got zero length buffer,
it could have underflow in size calc later.
So just put extra small check for this case.
2016-02-23 21:40:16 +01:00
Zdenek Kabelac
b08eb91df1 coverity: check for info pointer existance
Since we already check in few other places  'info' is not NULL,
do the same for others - however when info would be NULL
it more or less looks like internal error.
2016-02-23 21:40:16 +01:00
David Teigland
eccc91f9b0 lvmlockd: set default result value
The default error value should be set indicating
an error.
2016-02-23 14:35:40 -06:00
Zdenek Kabelac
c0b836e316 gcc: logical-op warning go away
Don't be too much inventive and shutdown gcc6 warning:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602
2016-02-23 14:41:24 +01:00
Zdenek Kabelac
e717ce555b pvremove: add warn when removing PV in use
Reshuffle messages during pvremove.

Always print WARNING: when PV is in use so using options
--force --force doesn't make this important user
notification go away.

Simplify variable 'used' usage (so older gcc doesn't warn
about the use of unitilizied variable).

Add some '.' into messages.
2016-02-23 14:40:30 +01:00
Zdenek Kabelac
7d8a67714f cleanup: drop double ; 2016-02-23 12:25:25 +01:00
Zdenek Kabelac
dbc71dc05e gcc: cleanup some sign warnings
When comparing unsigned with int, the comparision is made
as 'unsigned' type, so make it rather explicit which type
is being compared.
2016-02-23 12:25:25 +01:00
Zdenek Kabelac
293aabe4cd cache: enforce header check
Currently it's been checked for 'zero' header for thin-pool,
but lets use it always for cache as well - since it's relatively 'cheap'
detection of read 'error' problems as thin/cache tools
currently do not work fast enough in this case.
2016-02-23 12:25:25 +01:00
Zdenek Kabelac
f501f083bf thin: fix read size compare
Fix the compare with 'unsigned' sizeof() and error read -1 result.
So the read error is correctly recognized.
2016-02-23 12:22:18 +01:00
Zdenek Kabelac
2d6ef123a6 cleanup: indent changes
Some code indention.
Use dm_strncpy() for simplier code.

TODO: we could possibly use   %32s  for printing pvid...
so maybe adding extra  FMT_PVID....
2016-02-22 14:26:15 +01:00
Zdenek Kabelac
30a73d1604 lvmetad: fix error path
Coverity noticed the internal error path would  be using uninit struct.
So always make sure reply is initilized.
2016-02-22 14:15:53 +01:00
Zdenek Kabelac
eefcbd5b28 thin: fix update_pool_lv error path
When update fails in suspend() (sending of messages
fails because metadata space is full) call resume(),
so the locking sequence works properly for clustering.

Also failing deactivation should unlock memory.
2016-02-19 11:25:56 +01:00
Zdenek Kabelac
42b394c142 thin: fix test for nonexisting status
Check status has right type.
2016-02-18 18:11:29 +01:00
Zdenek Kabelac
f31d596c0d thin: report needs_check and fail state
Fix reporting of Fail thin-pool target status
as attr[8] letter 'F'.

Report  'needs_check' status from thin-pool target via
attr field [4] (letter 'c'/'C'), and also via CheckNeeded field.

TODO: think about better name here?
TODO: lots of prop_not_implemented_set
2016-02-18 16:49:34 +01:00
Zdenek Kabelac
0358ca3aad thin: report PERCENT_INVALID for failed pool
When thin-pool is in failed/error state, we can't
read percentage so report invalid value.
2016-02-18 16:45:42 +01:00
Peter Rajnoha
ecfa465366 metadata: ask for confirmation before really initializing/removing PV that is marked as belonging to a VG
Ask for confirmation when using pvcreate/pvremove on a PV which is
marked as belonging to a VG, just like we do in case of a PV which
belongs to known VG:

$ pvcreate -ff /dev/sda
Really INITIALIZE physical volume "/dev/sda" that is marked as belonging to a VG [y/n]? n
  /dev/sda: physical volume not initialized

$ pvremove -ff /dev/sda
Really WIPE LABELS from physical volume "/dev/sda" that is marked as belonging to a VG [y/n]? n
  /dev/sda: physical volume label not removed
2016-02-18 14:33:54 +01:00
Peter Rajnoha
bc19a16fc7 report: report -1, not 'unkown' for lv_{snapshot_invalid,merge_failed} with --binary
State:
$ lvs -o lv_name,lv_active_locally,lv_snapshot_invalid,lv_merge_failed vg/lvol0
  LV    ActLocal       SnapInvalid     MergeFailed
  lvol0 active locally         unknown         unknown

Now with using --binary switch.

Before this patch (lv_snapshot_invalid and lv_merge_failed not switched into numeric value
where -1 represents 'unknown' value)
$ lvs -o lv_name,lv_active_locally,lv_snapshot_invalid,lv_merge_failed vg/lvol0 --binary
  LV    ActLocal   SnapInvalid     MergeFailed
  lvol0          1         unknown         unknown

With this patch applied:
$ lvs -o lv_name,lv_active_locally,lv_snapshot_invalid,lv_merge_failed vg/lvol0 --binary
  LV    ActLocal   SnapInvalid     MergeFailed
  lvol0          1              -1              -1
2016-02-18 12:10:00 +01:00
Peter Rajnoha
065526c590 metadata: add missing _repair_inconsinstent_vg call during PV ext repair 2016-02-17 10:19:55 +01:00
Peter Rajnoha
b077e7374f metadata: do not repair missing PV_EXT_USED flag for PVs belonging to foreign VG
The host that owns foreign VGs is responsible for fixing up PV_EXT_USED
flag - the same already applies to repairing any inconsistent VG.

This patch also moves the iteration over vg->pvs inside
_check_or_repair_pv_ext fn - it's cleaner this way.
2016-02-17 10:19:24 +01:00
Peter Rajnoha
13f3e92632 refactor: add common _is_foreign_vg fn 2016-02-16 13:44:48 +01:00
Peter Rajnoha
45be3c875f pv: use pv->fmt to check for fake PVs, not pv->vg
pv->vg is not set yet during pvcreate processing. Use pv->fmt instead to
check for these fake PVs (all normal PVs have format defined, devices
which are not PVs don't have this set).

This fixes commit 0000db7f98.
2016-02-15 15:52:13 +01:00
Peter Rajnoha
0000db7f98 pv: mark fake PVs as not used
Some of the PVs are not even orphan PVs - they're fake PVs - this can
happen if we're listing all devices with "pvs -a". Such PV must not
be marked as used.
2016-02-15 14:46:31 +01:00
Peter Rajnoha
abbaeef096 cleanup: use is_used_pv fn to detect whether PV is in use while reporting pv_free field 2016-02-15 13:30:37 +01:00
Peter Rajnoha
8ad93874d6 tests: fix tests checking pv_attr - there's a new bit now 2016-02-15 12:44:46 +01:00
Peter Rajnoha
2f00d57e6f vg: automatically update to newest PV ext version during vg_write 2016-02-15 12:44:46 +01:00
Peter Rajnoha
9b9f1ae772 format: format_text: add pv_needs_rewrite to format_handler and implemention for format_text 2016-02-15 12:44:46 +01:00
Peter Rajnoha
08de88535e report: identify used PVs in pv_attr field with 'u' char 2016-02-15 12:44:46 +01:00
Peter Rajnoha
db494d7d34 report: always display 0 for pv_free field if we don't have any mda and PV is marked as used at the same time 2016-02-15 12:44:46 +01:00
Peter Rajnoha
d84a80afb5 backup: backup_restore_vg: register PVs that need writing via vg->pvs_to_write list
The backup_restore_vg is used directly for restoring the VG from backup.
It's also used to do the VG conversions from one metadata format to
another which means vgconvert calls backup_restore_vg too.

When restoring VG from backup, we need to rewrite/write PV headers as
PVs may have been orphans before and now they're becoming part of some
VG - we need to write the PV_EXT_USED flag at least.

When using the backup_restore_vg for vgconvert, we need to write
completely new PV header in different format.

Avoid the special "pv_write" call and handling that was used before
this patch in vgconvert (vgconvert_single function to be more precise)
and reuse existing internal interface to register PV header for writing
(or rewriting) via vg->pvs_to_write list instead like we do it elsewhere
in the code.

This patch also resolves a problem in which PV headers with target
format were written in the vgconvert_single fn as orphans and VG
metadata were added later on - this was a tiny hack actually.
We can't do this now - we need to write the PV as belonging
to a VG because otherwise the PV_EXT_USED flag won't be written
properly (if the PV header is written as orphan, the PV_EXT_USED
is set to 0, of course, even though metadata are attached later).
So this patch removes this tiny inconsistency which was passing
just fine before because we didn't have any relation to the VG
in PV header before. Now we have the PV_EXT_USED flag which says
the "PV is used in some VG".
2016-02-15 12:44:46 +01:00
Peter Rajnoha
531ced90dc metadata: _vg_read: check if PV_EXT_USED flag is set correctly for non-orphan PVs and do a repair if needed
The same check as we already do for orphan PVs, just the other way
round now: if the PV is surely part of some VG and any PV the VG
contains does not have the PV_EXT_USED flag set, repair it.

For example - /dev/sda here is in VG vg and it's incorrectly not
marked as used by PV_EXT_USED flag:

pvs --binary -o pv_ext_vsn,pv_in_use
  WARNING: Volume Group vg is not consistent.
  WARNING: Repairing Physical Volume /dev/sda that is in Volume Group vg but not marked as used.
  PV         VG     Fmt  Attr PSize   PFree   ExtVsn PInUse
  /dev/sda   vg     lvm2 a--  124.00m 124.00m      2      1
2016-02-15 12:44:46 +01:00
Peter Rajnoha
f75e42c06c report: add pv_ext_vsn field to display PV header extension version used
For example:

$ pvs -o pv_name,vg_name,pv_ext_vsn,pv_in_use
  PV         VG     ExtVsn InUse
  /dev/sda               2
  /dev/sdb   vg          2    used
  /dev/vda2  fedora      1    used
2016-02-15 12:44:46 +01:00