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

2344 Commits

Author SHA1 Message Date
Dave Wysochanski
d144d5eeb7 Add text format specific 'rlocn' ignore flag and access functions.
Adding a flag to the 'rlocn' structure in the mda header of the
text format allows us to flip a bit to ignore an area on disk that
stores the metadata via the text format specific mda_header.
This patch defines the flag and access functions to manage the flag.
Other patches will manage the ignore on a format-independent basis,
by using a flag in the metadata_area structure.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-06-28 20:29:57 +00:00
Dave Wysochanski
7c604e7649 Change 'filler' to 'flags' in on-disk 'raw_locn' structure.
Future patches will make use of a specific flag in the on-disk 'raw_locn'
structure to enable/disable metadata areas, and facilitate metadata
balancing.

Note that 'filler' is always set to '0' (see add_mda() - memset),
so use of this area as a non-zero flags field is a safe way to
provide future code features.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-06-28 20:29:42 +00:00
Jonathan Earl Brassow
68c31a2a36 Fix for bz608048 from Taka...
The same region size is used for both mirror volume and mirrored
log volume, but when the physical extent size is bigger than region size,
the size of mirror leg for mirrored log is smaller than the region size
and lvcreate command fails.

This patch adjusts a region size of mirrored log to a smaller value of
region size or physical extent size.

[This patch ensures that the region_size of the mirrored log does not
exceed the size of the mirrored log itself, which would violate the
kernel constraint: (region_size <= ti->len).]

Signed-off-by: Takahiro Yasui <takahiro.yasui@hds.com>
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-06-28 14:19:41 +00:00
Zdenek Kabelac
d301e5917f Preload libc locale messages.
Preload libc.mo file for localized lvm before taking memory lock - this way
we prevent disk access for some error paths in libdm, that prints localized
errno messages while they are still in memory locked state.
2010-06-24 08:29:30 +00:00
Jonathan Earl Brassow
42f7fd0590 The function that runs to compress a stacked mirror after
converting from 2-way to 3-way mirror (collapse_mirrored_lv)
was calling '_remove_mirror_images' with the 'remove_log'
parameter set.  When the code was put in to fix 599898 to
honor log parameters during conversion, this argument was
suddenly being honored.  Thus, when someone would convert from
a 2-way to 3-way mirror, the log would get removed.

'collapse_mirrored_lv' should not be calling '_remove_mirror_images'
with 'remove_log' set.
2010-06-23 13:57:26 +00:00
Alasdair Kergon
07ae1d4943 Add lv_path to reports to offer full /dev pathname. 2010-06-23 12:32:08 +00:00
Milan Broz
f9e177d281 Fix "allocated" warning typo. 2010-06-22 21:10:53 +00:00
Dave Wysochanski
58f55600d0 Add device name to output of error messages in raw_read_mda_header().
It would be helpful if we had the device name when something like
a mda_header checksum error occurs.

Before:
./tools/lvm pvs -opv_name,vg_name,uuid,mda_count,pv_mda_count_ignored,vg_mda_count,vg_mda_count_ignored,vg_mda_copies
  Incorrect metadata area header checksum
  PV         VG      PV UUID                                #PMda #PMdaIgn #VMda #VMdaIgn #VMdaCps
  /dev/loop0 vgtest2 sVv26t-gjpb-Rcau-uBDO-Cx04-GbRR-6Ssq7e     2        0     4        0        4
  /dev/loop1 vgtest2 zXWStT-qE8F-mbkc-RfgH-aytv-mptF-Y5Ce09     2        0     4        0        4
  /dev/loop2         riCpK9-9G8r-LlIp-i2oh-mb3N-CUzk-u5YpuR     1        0     0        0        0
  /dev/loop3 vgtest  tQCUjm-rmyd-i92d-4eeE-UYBW-v1vQ-kRaA17     2        0     4        2        0
  /dev/loop4 vgtest  ZRvpeI-p8F1-ccVW-BBac-xhl1-aGXU-CbP0oo     2        2     4        2        0

After:
./tools/lvm pvs -opv_name,vg_name,uuid,mda_count,pv_mda_count_ignored,vg_mda_count,vg_mda_count_ignored,vg_mda_copies
  Incorrect metadata area header checksum on /dev/loop2 at offset 4096
  PV         VG      PV UUID                                #PMda #PMdaIgn #VMda #VMdaIgn #VMdaCps
  /dev/loop0 vgtest2 sVv26t-gjpb-Rcau-uBDO-Cx04-GbRR-6Ssq7e     2        0     4        0        4
  /dev/loop1 vgtest2 zXWStT-qE8F-mbkc-RfgH-aytv-mptF-Y5Ce09     2        0     4        0        4
  /dev/loop2         riCpK9-9G8r-LlIp-i2oh-mb3N-CUzk-u5YpuR     1        0     0        0        0
  /dev/loop3 vgtest  tQCUjm-rmyd-i92d-4eeE-UYBW-v1vQ-kRaA17     2        0     4        2        0
  /dev/loop4 vgtest  ZRvpeI-p8F1-ccVW-BBac-xhl1-aGXU-CbP0oo     2        2     4        2        0
2010-06-22 19:18:27 +00:00
Jonathan Earl Brassow
a7d355a28c Mirrors can be layered - as in the case of an converting 2-way
to 3-way mirror.  When conversion operations are performed on
these types of mirrors, log options can be confused/ignored.

In the case of a converting 3-way mirror, we have a top-level
2-way corelog mirror whose legs are 1) a 2-way disk-log mirror
and 2) a linear device.  If we wish to convert this 3-way mirror
to a 2-way mirror, the linear device is removed and the extra
top layer is eliminated.  If we also wished to convert the disk
log to a core log in the same step, ambiguity creeps in.  It is
somewhat obvious what the user wants - a 2-way mirror with a
corelog.  However, looking at the top level mirror before
compression, it seems that the mirror already has a core log.
This is why the operation seemed to fail.

This patch simply re-evaluates what mirrored_seg points to after
a compression and then considers the log argument.

This is a fix for bug 599898.
2010-06-21 16:12:33 +00:00
Alasdair Kergon
b4ee00356b Various cleanups following recent commits. 2010-06-21 15:56:57 +00:00
Milan Broz
d2031f6a16 Clean up cluster lock mode and flags definition.
Code is mixing up internal DLM and LVM definitions of lock
modes and flags.

OpenAIS and singlenode locking do not depend on DLM but
code currently cannot be compiled without libdlm.h!

LCK_* flags is LVM abstraction, used through all the code.
Only low-level backend (clvmd-cman etc) should use DLM definitions,
also this code should do all needed conversions.

Because there are two DLM flags used in generic code
(NOQUEUE, CONVERT) we define it similar way like lock modes.
(So all needed binary-compatible flags are on one place in locking.h)

(Further code cleaning still needed, though:-)
2010-06-17 12:48:54 +00:00
Zdenek Kabelac
b5c2529bf8 Use absolute paths in commands
clvmd restart does not work at all if clvmd binary is not in current
dir.
2010-06-03 13:50:26 +00:00
Dave Wysochanski
e9a87f2e16 Revert _init_rand() to reset errno - restores original init behavior. 2010-06-01 21:47:57 +00:00
Dave Wysochanski
e3a1fc8af3 Do not fail lvm_init() if init_logging() generates an errno.
Revert to original behavior of lvm commands if init_logging() generated an
errno.  Fixes rhbz 592967.
2010-06-01 21:46:29 +00:00
Alasdair Kergon
d01888706d Don't merge unchanged persistent cache file before dumping if tool scanned. 2010-06-01 19:02:12 +00:00
Peter Rajnoha
03023d3965 Fix incorrect memory pool deallocation while using vg_read for files.
We create a separate pool "lvm2 vg_read" for vg_read and we don't use
cmd->mem anymore.
2010-06-01 12:08:50 +00:00
Alasdair Kergon
ba61f84874 Replace strncmp kernel version number checks with proper ones 2010-05-24 23:11:34 +00:00
Alasdair Kergon
ed122a962d Avoid selecting names under /dev/block if there is an alternative. 2010-05-24 22:53:48 +00:00
Alasdair Kergon
5782a38543 Choose between clustered log versions based on kernel version.
Add fixmes for broken strcmp.
2010-05-24 17:46:47 +00:00
Alasdair Kergon
1493f24e3e Update clustered log kernel module name to log-userspace. 2010-05-24 16:30:15 +00:00
Petr Rockai
d345bf2cd3 Account for mirror transient status when doing lvconvert --repair. 2010-05-24 15:32:20 +00:00
Zdenek Kabelac
4ef2bf27a7 Update Copyright date for resently modifed files 2010-05-24 09:04:27 +00:00
Zdenek Kabelac
591fc4d2d1 Replicator: add replicator to dtree
Adding all replicator related LVs to dtree.
Start of one replicator_dev initiate start of all other related.
2010-05-24 09:01:05 +00:00
Zdenek Kabelac
dc7d777606 Replicator: update _create_partial_dtree()
Adding function _add_partial_replicator_to_dtree() to create
partial tree for Replicator target.

Using dm_tree_node_set_presuspend_node() for Replicator.
2010-05-21 14:47:58 +00:00
Zdenek Kabelac
9249fb12b8 Replicator: activate checks for missing vgs
Activation needs to have all remote VGs locked to pass for replicator.
So if activated LV is replicator-dev LV - read all remote VGs.
2010-05-21 14:34:01 +00:00
Zdenek Kabelac
b5f33faf9f Replicator: lock_lv_vol() finds missing VGs
Find and check for all needed VGs before calling lock_vol().
2010-05-21 14:29:49 +00:00
Zdenek Kabelac
65928349e7 Replicator: add read and release VGs for rsites
Add functions to read and release remote VGs for replicator sites
in activation context.
2010-05-21 14:07:16 +00:00
Zdenek Kabelac
f6d7e637c3 Add toolcontext.h header file. 2010-05-21 13:34:09 +00:00
Zdenek Kabelac
49e7eb3570 Remove files from wrong directory 2010-05-21 13:18:25 +00:00
Zdenek Kabelac
4c77dcc4ea Right directory name for replicator files.
My local CVS was placing file in slightly different directory by using
obsolete files.
2010-05-21 13:17:20 +00:00
Zdenek Kabelac
0e6270e308 Hmm - fixing cvs import mistake 2010-05-21 13:14:02 +00:00
Zdenek Kabelac
6222635b38 Replicator: add find_replicator_vgs
Adding find_replicator_vgs() function to find all needed
VGs for replicator-dev LV.

This function is later called before taking lock_vol().
2010-05-21 12:55:25 +00:00
Zdenek Kabelac
12569ccb03 Replicator: add sorted cmd_vg list
Introduce struct cmd_vg to store information about needed
volume group name, vgid, flags and the pointer to opened VG.

Keep VGs list in alphabetical order for locking order.

Introduce functions:
cmd_vg_add() add new cmd_vg entry.
cmd_vg_lookup() search cmd_vgs for vg_name.
cmd_vg_read() open VGs in cmd_vgs list.
cmd_vg_release() close VGs in reversed order.
2010-05-21 12:52:01 +00:00
Zdenek Kabelac
0a02d30ea4 Replicator: extend volume_group with list of VGs and flag
Add pointer to linked list of opened VGs. List temporarily keeps
the information about needed or locked and opened VGs for replicator target.

Also add cmd_missing_vgs flag information for quick check and
also for possible continuos process_each_lv() usage where we need
to detect whether failure has been caused by missing VG or
some other reason.
2010-05-21 12:47:46 +00:00
Zdenek Kabelac
e86e45f7ea Replicator: extend _lv_each_dependency() with dependencies for Replicator devices 2010-05-21 12:45:18 +00:00
Zdenek Kabelac
651cae3c5c Replicator: check replicator segment
Check for possible problems within replicator structures.
Used also by vg_validate.
2010-05-21 12:43:02 +00:00
Zdenek Kabelac
1207106fbc Replicator: new files for Replicator target 2010-05-21 12:40:05 +00:00
Zdenek Kabelac
8fea97b7e7 Replicator: base lvm2 support
Adding configure.in support for Replicators.
Adding basic lib lvm support for Replicators.
Adding flags REPLICATOR and REPLICATOR_LOG.
Adding segments SEG_REPLICATOR and SEG_REPLICATOR_DEV.
Adding basic methods for handling replicator metadata.
2010-05-21 12:36:30 +00:00
Alasdair Kergon
21c56e377b backup->cache 2010-05-20 22:32:44 +00:00
Alasdair Kergon
ae6164cee3 If unable to obtain snapshot percentage leave value blank on reports. 2010-05-20 22:24:33 +00:00
Alasdair Kergon
3399ae320a Add install_system_dirs makefile target.
Add configure options for system and locking directories.
2010-05-20 13:47:21 +00:00
Dave Wysochanski
dd2a0e940d Add find_vgname_from_{pvname|pvid} functions.
Some commands start with a pvname, but we'd like to force users to
start with a vg handle to obtain a pv handle.  Our best option seems
to be providing a way to look up the vgname from the pvname, and then
require them to use vg_read/vg_open.

In addition to the pvname lookup function, this patch also provides a
lookup by pvid.  The lookup by pvid can be used in conjunction with
lvmcache_get_pvids to process all pvs in the system.

The pvid find function first calls lvmcache_vgname_from_pvid, which may
cause the label to be read if it is not in the cache.  If the vgname is
returned is an orphan, we then check to see if there are metadata areas,
and if not, we scan every PV on the system by calling scan_vgs_for_pvs().
In most cases we should not need to do this, and by using the info->mdas
count, we avoid calling pv_read() as prior code did.  So this patch is a
bit cleaner and should allow us to refactor more of the pv code.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-05-19 11:52:37 +00:00
Dave Wysochanski
cfb203e14d Add lvmcache_vgname_from_pvid().
Add lvmcache function to lookup a vgname from a pvid.
2010-05-19 11:52:21 +00:00
Dave Wysochanski
dd4097a6a4 Add pvid_from_devname() lvmcache function.
Add supporting function for mappings from devname -> pvid -> vgname.
2010-05-19 11:52:07 +00:00
Alasdair Kergon
1d837442bf Add is_global_vg and split out from is_orphan_vg. 2010-05-19 02:36:33 +00:00
Alasdair Kergon
34220fe292 Validate orphan and VG_GLOBAL lock order too. 2010-05-19 02:08:50 +00:00
Alasdair Kergon
8c965cafb7 Note that orphan lock is always obtained last 2010-05-19 01:49:08 +00:00
Alasdair Kergon
fa305e2ec6 Accept orphan VG names as parameters to lock_vol() and related functions. 2010-05-19 01:16:40 +00:00
Alasdair Kergon
24d21cfcee Use is_orphan_vg in place of hard-coded prefix tests. 2010-05-19 00:52:55 +00:00
Alasdair Kergon
a988efda46 pre-release 2010-05-17 18:39:01 +00:00
Jonathan Earl Brassow
a932c2b61f Disallow toggling the cluster attribute of a volume group if there
are active mirrors or snapshots.

We don't have the mechanisms in place to change the device-mapper
tables for those targets that have behavioral differences between
cluster and single machine instances.  Allowing users to change
the attribute but not changing the target's behavior can lead to
data corruption.

The following bugs are fixed/avoided by this patch:
235123 - vgchange -c [ny] do not change target types when necessary
289331 - RFE: switching from cluster domain to local domain needs to deactivate volume somehow
289541 - when changing from local to cluster, volumes can not appear to be deactivated
2010-05-14 15:19:42 +00:00
Milan Broz
ea9e387f87 Another one internal device layer fix... 2010-05-14 12:39:52 +00:00
Milan Broz
b8fb120ee0 Fix empty layer detection is scan devices. 2010-05-14 12:30:43 +00:00
Milan Broz
b449f0a188 Fix device_is_usable to properly detect only internal LV names. 2010-05-14 12:03:32 +00:00
Milan Broz
28e2b5b213 Skip also special lvm devices in scan (if ignore suspended is used).
This should avoid various races between dmeventd on multiple nodes
in cluster where one node already repairing device and another
run full scan and locks the device.
2010-05-13 18:38:38 +00:00
Milan Broz
9ad39e546b Currently if clvmd is running and user issues vgscan,
the device cache file is dumped both in vgscan and clvmd process.

Unfortunately, clvmd calls lvmcache_label_scan,
it properly destroys persistent filter, but during
persistent_filter_dump it merges old cache content back!

This causes that change in filters is not properly propagated
into device cache after vgscan on cluster.
(Only new devices are added.)

https://bugzilla.redhat.com/show_bug.cgi?id=591861
2010-05-13 13:04:03 +00:00
Peter Rajnoha
d50c6d4bf5 Add new --sysinit option for vgchange and lvchange.
A shortcut for --ignorelockingfailure, --ignoremonitoring, --poll n options
and LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES environment variable used all at
once in initialisation scripts (e.g. rc.sysinit or initrd).
2010-05-06 11:15:55 +00:00
Zdenek Kabelac
180b3dea11 Install plugins to subdirs
Target install_dm_plugin installs files to libdir/device-mapper.
Target install_lvm2_plugin installs files to libdir/lvm2.

Both targets creates relative links to libdir to keep the code
compatible with current dlopen handling.

Once we will be able to read plugins from subdir, links
could be removed.
2010-05-06 10:07:46 +00:00
Petr Rockai
9409998d71 Suppress duplicate error messages about read failures and missing devices. 2010-05-05 22:37:52 +00:00
Zdenek Kabelac
244646902c Initialise _vginfos list staticaly so there is no problem with using uninitialised
variables in case, lvmcache_destory() is called without lvmcache_init().
2010-04-30 12:54:31 +00:00
Zdenek Kabelac
7147cd9fe5 Release pools for regex if there is error during processing
(fixes error messages about unreleased pools).
2010-04-30 12:37:04 +00:00
Zdenek Kabelac
8889fda53d Show string with invalid pattern
and start error message with capital letter.
2010-04-30 12:31:32 +00:00
Alasdair Kergon
54d7741a3e Remove no-longer-used arg_ptr_value.
Fix -M and --type to use strings not pointers that change on config refresh.
2010-04-29 01:38:12 +00:00
Jonathan Earl Brassow
56a5925aed Fix comment from last commit. Additionally, there is no need
to put a comment into the WHATS_NEW file if it is a regression
that was created and fixed inside the same release window.
2010-04-27 15:26:58 +00:00
Jonathan Earl Brassow
d7c9d72390 Patch to fix bug 586021 and mantain historical behavior of
being able to remove more images from a mirror than the
number of PVs directly specified for removal.

The effort to fix bug 581611 corrected a bug that was unnoticed
at the time.  The loop in _remove_mirror_images that looks over
the specified PVs was allowing devices that were previously
counted and moved to the end of the list to be double-counted.
This resulted in the number of devices needed for removal always
being satisfied - even if the user did not specify enough PVs
for removal to satisfy the request.  When 581611 was fixed, this
double-counting no longer took place and the result was to remove
only the minimum of the number of PVs specified or the number
that was asked to be removed.

By simply always setting 'new_area_count' (as used to be done
only in the else statement), we return to the previous behavior.
Indeed, this is exactly what the double-counting was allowing
to happen before the fix of 581611.
2010-04-27 14:57:49 +00:00
Mike Snitzer
60267bdce8 Disallow the direct removal of a merging snapshot.
Allow lv_remove_with_dependencies() to know the top-level LV that was
requested to be removed (otherwise it recurses and we lose context).

A merging snapshot cannot be removed directly but the associated origin
can be.  Disallow removal of a merging snapshot unless the associated
origin is also being removed.
2010-04-23 19:27:10 +00:00
Peter Rajnoha
6ddb5ecd72 Set appropriate udev flags for reserved LVs.
There's no need for foreign udev rules to touch LVM reserved devices
(snapshot, pvmove, _mlog, _mimage, _vorigin) even if they happen to
be visible. The same applies for /dev/disk content - no need to create
any content for these devices (and so no need to run any "blkid" etc.).
This also prevents setting any inotify "watch" from udev rules on such
devices that is a source of race conditions (the rules need to honor
DM_UDEV_DISABLE_OTHER_RULES_FLAG for this to work though).
2010-04-23 14:16:32 +00:00
Mike Snitzer
1f661c5dd8 When removing a snapshot avoid preloading the origin if the
snapshot-merge target is not active.
2010-04-23 02:57:39 +00:00
Jonathan Earl Brassow
66f79d05eb Disallow the primary mirror image from being removed when the
mirror is not in-sync.  This restriction is not extended to
repair operations (i.e. it will not limit what 'lvconvert --repair'
can do).
2010-04-21 13:55:08 +00:00
Alasdair Kergon
ee90b8197f Move function up file 2010-04-20 12:14:28 +00:00
Peter Rajnoha
1e696b0c15 Do not reset position in metadata ring buffer on vgrename and vgcfgrestore.
We should write metadata into next position in the ring buffer while calling
vgrename and vgcfgrestore. At this code level (_vg_write_raw), we were not able
to determine if this is a rename or not. If yes, then accompanying VG structure
passed here has a new name set, not the old one.

When looking for a location where to put metadata next, we were given a NULL
value because of failed VG name comparison (in _find_vg_rlocn) between the
name in existing metadata and metadata we're just about to write.

This resets the position in the ring buffer, overwriting any existing metadata
(and also incorrectly updates the cache to "orphan" afterwards).

This patch just adds old_name item in struct volume_group that we can check and use
if necessary and detect renames at lower layers as well.

The same applies for vgcfgrestore, but here we're using a special value of
old_name, an empty string, to disable the check with existing metadata totally.
2010-04-14 13:09:16 +00:00
Peter Rajnoha
bda3982016 Use UUIDs instead of names while processing event handlers.
Internally, we used DM names instead of UUIDs while processing event
handlers. This caused problems while trying to vgrename a VG with active LVs
where the names are being changed and so the devices were not found then.
The patch also contains a little bit of refactoring, moving "build_dlid" code
found in dev_manager.c to "build_dm_uuid", now in lvm-string.c (so we have
build_dm_uuid and build_dm_name at one place).
2010-04-14 13:01:38 +00:00
Dave Wysochanski
af46c894d0 Add pv->vg to solidify link between a pv and a vg.
lvm2app needs a link back to the vg in order to use the vg handle for
memory allocations as well as other things.  This patch adds the field
to struct physical_volume, and sets pv->vg when reading a vg from disk or
extending a vg by using the helper function previously added,
add_pvl_to_vgs().  Moves and renames are handled with separate code
inside move_pv() and vgmerge().  Add pv->vg check to vg_validate().

A NULL value in pv->vg signifies membership in the orphan VG.
Note though in the case of pv_read() on a device with metadatacopies == 0,
more devices may need to be read for an authoritative answer.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-13 17:26:36 +00:00
Dave Wysochanski
11647ad01c Use del_pvl_from_vgs() in vgreduce paths.
Somehow these got missed in earlier patches.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-13 17:26:20 +00:00
Dave Wysochanski
0adfbfd5ea Call add_pvl_to_vgs() and del_pvl_from_vgs() from more places.
Now that we have library functions to add/delete a pv from the vg->pvs
list, call them from everywhere.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-13 17:26:03 +00:00
Dave Wysochanski
8cfd64de78 Add del_pvl_from_vgs() and move prototypes into metadata-exported.h
Add a delete function to manage the vg->pvs list.

NOTE: It may be possible to do further cleanup to these add/del functions
by passing a 'pv' as input instead of 'pv_list'.  The pv_list is used for
functions which do allocations (lvcreate) while other places in the code
just manage a list of 'pv' (e.g. import functions, vgextend, etc).

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-13 17:25:44 +00:00
Dave Wysochanski
a6a4941504 Move increment of vg->pv_count from import_pool_vg() to import_pool_pvs().
Move the increment of vg->pv_count next to the place where we add to
vg->pvs.  It looks safe to do this since the only caller of import_pool_vg()
calls import_pool_pvs() immediately afterward, and there is no way
import_pool_vg() can fail (always returns 1).  However, if there's a
memory allocation failure inside import_pool_pvs(), we will end up with
a different count in vg->pv_count that with the original code.  In any
case, vg->pv_count should be as close to dm_list_size(&vg->pvs) as
possible, as is the case everywhere else in the code.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-13 17:25:26 +00:00
Dave Wysochanski
f6644ff8fe Remove unnecessary parameter from import_pool_pvs().
The dm_list * parameter is unnecessary since we are passing in 'vg'
and the only caller of import_pool_pvs() passes '&vg->pvs' in the
dm_list * parameter.  Just use vg->pvs directly in the function.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-13 17:25:13 +00:00
Milan Broz
e4594d9c23 Mask LCK_HOLD flag in cluster VG locks for compatibility reasons. 2010-04-13 14:36:24 +00:00
Alasdair Kergon
68176be18e Add --stripes to lvconvert too. 2010-04-13 01:54:32 +00:00
Alasdair Kergon
0693099223 Don't ignore error if resuming any LV fails in resume_lvs.
Skip closing persistent filter cache file if open failed.
2010-04-12 11:52:53 +00:00
Zdenek Kabelac
23b059e7b7 INSTALL rules updates
Patch is inspired by Debian's extra patch.

- removes OWNER & GROUP make vars they are parts of INSTALL command.
- adds INSTALL_PROGRAM for executable, uses $(INSTALL)
- adds INSTALL_DATA for non-executable data, uses ($INSTALL)
- adds INSTALL_WDATA for writable non-executable data, uses ($INSTALL)
- adds configure option --enable-write_install - to support
  installatin of writable files used by distribution
- replaces usage of ifeq @LIB_SUFFIX@ with $(LIB_SUFFIX)
- installs .a files from static builds without executable flag
- installs .a files to $(usrlibdir) instead of $(libdir)
- installs all static binaries to $(staticdir)
- create .so links for devel package in $(usrlibdir) instead of
  $(libdir)
- makes .so and .so.LIB_VERSION files within builddir
- removes VERSIONED_SHLIB and created versioned LIB_SHARED automagicaly
- install LIB_SHARED via install_lib_shared target
- install plugins via install_lib_shared_plugin target
- prints whole 'install' command during installation instead of less
  informative "Installing  $(something) $(somewhere)"
- install multiple man pages with one INSTALL command
- use DISTCLEAN_TARGETS instead of creating multiple distclean targets
2010-04-09 21:42:48 +00:00
Zdenek Kabelac
c737d34804 Use vpath instead of VPATH.
Usage of VPATH makes troubles when used within $(builddir).
Not only source files are being found through VPATH,
but targets as well. (make --debug=v)

Thus if user builds the code in $(srcdir) and also in some $(builddir)
he gets mangled results as some generated files (i.e. .export.sym)
are 'reused' from $(srcdir) instead of $(builddir).

This patch switches to use vpath were we could explicitly name
suffixes that should be looked via vpath - we must take care,
we do not generate files with these suffixes:
.c, .in, .po, .exported_symbols
2010-04-09 21:34:25 +00:00
Alasdair Kergon
1485ce69c4 Permit mimage LVs to be striped in lvcreate and lvresize. 2010-04-09 01:00:10 +00:00
Dave Wysochanski
fddc256a02 Check for duplicate paths (pvids) on the commandline of vgcreate.
A user specifying duplicate paths on the cmdline of vgcreate will
get a message similar to the following:
vgcreate vgtest2 /dev/loop3 /dev/loop5
  Found duplicate PV jk1lXsKzwyOKlXq6bhaFFKMQQ06oPgu8: using /dev/loop5 not /dev/loop3
  Found duplicate PV jk1lXsKzwyOKlXq6bhaFFKMQQ06oPgu8: using /dev/loop3 not /dev/loop5
  Internal error: Duplicate PV id jk1lXs-Kzwy-OKlX-q6bh-aFFK-MQQ0-6oPgu8 detected for /dev/loop3 in vgtest2.

This is caught by vg_validate(), but it would be good to find
this condition earlier in the vgcreate code.  add_pv_to_vg()
currently checks by pvname, but does not look for duplcate pvids.
This patch adds the check for duplicate pvids and results in new
error output as follows:
vgcreate vgtest2 /dev/loop3 /dev/loop5
  Found duplicate PV jk1lXsKzwyOKlXq6bhaFFKMQQ06oPgu8: using /dev/loop5 not /dev/loop3
  Found duplicate PV jk1lXsKzwyOKlXq6bhaFFKMQQ06oPgu8: using /dev/loop3 not /dev/loop5
  Physical volume '/dev/loop5 (jk1lXs-Kzwy-OKlX-q6bh-aFFK-MQQ0-6oPgu8)' listed more than once.
  Unable to add physical volume '/dev/loop5' to volume group 'vgtest2'.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-08 15:18:35 +00:00
Alasdair Kergon
4d0e07a799 missing ?: 2010-04-08 00:56:26 +00:00
Alasdair Kergon
b3302a0c3c suppress bogus compiler warning 2010-04-08 00:52:41 +00:00
Alasdair Kergon
aab7a3978b Fix pvmove allocation to take existing parallel stripes into account.
When moving parts of striped LVs, pvmove wouldn't care about leaving you with
two stripes on the same disk.  Now --alloc anywhere is needed for that.
(Tried and gave up on two alternative approaches before the one committed here.)
2010-04-08 00:28:57 +00:00
Alasdair Kergon
f55021f487 Fix incorrect removal of symlinks after LV deactivation fails. 2010-04-07 20:04:41 +00:00
Alasdair Kergon
6d25082d65 Fix is_partitioned_dev not to attempt to reopen device. 2010-04-06 17:36:41 +00:00
Dave Wysochanski
9e82787da2 Add add_pvl_to_vgs() - helper function to add a pv to a vg list.
Small refactor of main places in the code where a pv is added to a
vg into a small function which adds the pv to the list and updates
the vg counts.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-06 14:04:54 +00:00
Dave Wysochanski
b4a9a2d313 Refactor format1 vg->pvs list add and vg->pv_count.
Refactor adding to the vg->pvs list and incrementing the count, which
will allow further refactoring.  Should be no functional change.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-06 14:04:20 +00:00
Dave Wysochanski
36e9d03d1b Refactor _read_pv() code that updates vg->extent_count and vg->free_count.
Simple refactor to mov code that updates the vg extent counts from a
single pv's counts close to the code that adds a pv to vg->pvs and
updates vg->pv_count.  No functional change.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-06 14:04:03 +00:00
Dave Wysochanski
53ad3cad14 Add pv to vg->pvs after check for maximum value of vg->extent_count.
In add_pv_to_vg(), we should only add the pv to vg->pvs after all
internal checks have passed.  The check for vg->extent_count exeeding
maximum was after we added the pv to the list, so this function could
return a state of vg->pvs that did not reflect other parameters such
as vg->pv_count.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-04-06 14:03:43 +00:00
Alasdair Kergon
d27c8b5660 remove compiler warning 2010-04-02 01:35:34 +00:00
Alasdair Kergon
6ec52a01ee A few more log_error to log_warn changes for mirrors. 2010-04-01 14:54:37 +00:00
Zdenek Kabelac
ddf19eae0f Better debug message for Un/Locked memory size. 2010-04-01 14:53:47 +00:00
Alasdair Kergon
46bd6d7a2f temporarily downgrade the 'open while suspended' error till we fix it properly 2010-04-01 14:30:51 +00:00
Alasdair Kergon
abb9fb8370 Try to fix tracking of whether or not log extents need allocating. 2010-04-01 13:58:13 +00:00
Zdenek Kabelac
39b6ac476d Set ret value to success initially. 2010-04-01 13:43:12 +00:00
Alasdair Kergon
0c67893ce9 Avoid endless loop if lv->segments list is corrupted 2010-04-01 13:08:06 +00:00
Alasdair Kergon
e7159c828b initialise log_allocated to 0 2010-04-01 12:29:07 +00:00
Alasdair Kergon
d723636d52 Limit number of error messages when checking LV segments. 2010-04-01 12:14:20 +00:00
Alasdair Kergon
a1192f17ba Improve vg_validate to detect some loops in lists. 2010-04-01 11:45:36 +00:00
Alasdair Kergon
0640232acd Improve vg_validate to detect some loops in lists. 2010-04-01 11:43:24 +00:00
Alasdair Kergon
258db3ad8e Change most remaining log_error WARNING messages to log_warn. 2010-04-01 10:34:09 +00:00
Alasdair Kergon
bce2869d92 Attempt to fix non-ALLOC_ANYWHERE allocation code after recent changes broke
The preference given to the PVs with the largest free areas.
2010-03-31 20:26:04 +00:00
Milan Broz
d7cbaae1fd Always use blocking lock for VGs and orphan locks.
Because we have now strong rule for lock ordering:
 - VG locks must be taken in alphabetical order
 - ORPHAN locks must be the last
vgs_locked() is now not needed.

This fixes problem with orphan locking, e.g.
vgremove VG1    |    vgremove VG2
lock(VG1)       |    lock(VG2)
lock(ORPHAN)    |    lock(ORPHAN) -> fail, non-blocking

https://bugzilla.redhat.com/show_bug.cgi?id=578413

(More similar places in code.)
2010-03-31 17:23:56 +00:00
Milan Broz
6733116a19 Fix all segments memory is allocated from vg private mempool.
Physical segments were still allocated from global
command context mempool.

This leads to very high memory usage when
activating large VG (vgchange).
(Memory usage was about 2G when >3000LVs).

Fix it by properly using vg->vgmem private pool,
so all the memory is released early.

New memory pool parameter is needed here for pv_split_segment
function.

Also fix the same problem in some minor allocations
(vg description, lv segment split).
2010-03-31 17:23:18 +00:00
Milan Broz
0423887528 Do not traverse PV segment list twice.
In addition to previous patch, we really do not need
to search for segment which was just allocated in
split request.

Make pv_split_segment function return newly allocated
(split) segment also.

(So after this patch, there is only one user
of slow find_peg_by_pe).
2010-03-31 17:22:26 +00:00
Milan Broz
80b96a8974 Optimise PV segments search.
The function find_peg_by_pe is incredibly inefficient
for Pvs with many segments.

In shiny future there should be binary (or interval) tree
instead of sorted linked list (volunteers?).

Anyway, for now, we can use dirty trick here to optimise this case:

 - Allocations are usually applied from the beginning
 of PV (we have no alloocation policy which allocates areas
 "backwards")

 - The only user of find_peg_by_pe is pv_split_segment()
 call. In *most* cases it need to split *last* PV segment.

So if we search sorted pv segment list backwards, we
hit the requested segment immediatelly.

This patch applies this tiny change.
(and saves >30% of processing time when >3000LVs segments are on one PV!)

To discourage using this inefficient function from other code,
it is moved to pv_manip.c and used static for now:-)
2010-03-31 17:21:40 +00:00
Milan Broz
c8b0988586 Remove vg_validate call when parsing cached metadata.
vg_validate call is an adept to optimisation, it is very
ineeficient and slow.

Anyway, we should call it only before writing data to disk.

The call in lvmcache was just temporary validation,
we realy do not need to revalidate cached metadata
every time.
(Actually, I added that there just to prove that cache works
properly and forgot to remove it.)

Patch removes it from lvmcache completely, this can hit only
internal bug in export function (and this bug must
be detected in any vg_write call anyway before).
2010-03-31 17:20:44 +00:00
Milan Broz
d59a2b6109 Use hash table for quick lv reference when reading metadata.
The _read_vg uses already hash for PVs to optimise
reading of large VGs and avoiding repeated PV list traversing.

Use the same aproach to speed up parsing VG with many LVs.
2010-03-31 17:20:02 +00:00
Mikulas Patocka
655849fb14 A missing space in the error message.
Add missing parentheses to an error message

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
2010-03-31 12:06:30 +00:00
Zdenek Kabelac
5de52e34f0 Count only readable size for memlock stats.
As we mlock() only readable pages, makes statistics only
for readable bytes.
2010-03-30 14:41:58 +00:00
Zdenek Kabelac
3f67b36b35 Update memlock
Code moves initilization of stats values to _memlock_maps().
For dmeventd we need to use mlockall() - so avoid reading config value
and go with _use_mlockall code path.

Patch assumes dmeventd uses C locales!
Patch needs the call or memlock_inc_daemon() before memlock_inc()
(which is our common use case).

Some minor code cleanup patch for _un/_lock_mem_if_needed().
2010-03-30 14:41:23 +00:00
Alasdair Kergon
1dee5eb625 Fix --alloc contiguous policy only to allocate one set of parallel areas. 2010-03-29 17:59:46 +00:00
Zdenek Kabelac
b7be589ed0 Fixing another set of distclean problems where we left some generated files
in clvmd, dmevend, man, tests.

Don't include dependency files for clow and cscope.out targets

Improve dependency tracking for dmeventd and liblvm2cmd sources.
2010-03-29 14:17:59 +00:00
Zdenek Kabelac
b41f5924bf Update cflow file generation - support build dir and use $(top_srcdir)
to obtain sources. Create make.tmpl target for
simplier generation of cflow files with the help of
CFLOW_LIST, CFLOW_LIST_TARGET, CFLOW_TARGET.
Still cflow usage is not perfect.
2010-03-29 14:11:17 +00:00
Zdenek Kabelac
1a91d0914e distclean fixes
Move daemons/ and lib/ subtargets to their Makefiles so we don't get
double cleanup error during execution of distclean target.
Instead of duplicating clean target inside distclean target,
just use it as a subtarget and avoid add duplicating code.
2010-03-29 14:09:25 +00:00
Jonathan Earl Brassow
7a369d3704 Add ability to create mirrored logs for mirror LVs.
This check-in enables the 'mirrored' log type.  It can be specified
by using the '--mirrorlog' option as follows:
#> lvcreate -m1 --mirrorlog mirrored -L 5G -n lv vg

I've also included a couple updates to the testsuite.  These updates
include tests for the new log type, and some fixes to some of the
*lvconvert* tests.
2010-03-26 22:15:43 +00:00
Mike Snitzer
7b0f529d3e Fix clvmd cluster propagation of dmeventd monitoring mode.
clvmd's do_lock_lv() already properly controls dmeventd monitoring based
on LCK_DMEVENTD_MONITOR_MODE in lock_flags -- though one small fix was
needed for this to work: _lock_for_cluster() must treat
dmeventd_monitor_mode()'s return as a tri-state value.

Also cleanup do_lock_lv() to:
- explicitly init_dmeventd_monitor() based on LCK_DMEVENTD_MONITOR_MODE
- no longer reset init_dmeventd_monitor() to default at the end of
  do_lock_lv() -- it is unnecessary
2010-03-26 15:40:13 +00:00
Alasdair Kergon
2abbc07f3c Allow ALLOC_ANYWHERE to split contiguous areas. 2010-03-25 21:19:26 +00:00
Alasdair Kergon
a7ca334681 Add some assertions to allocation code. 2010-03-25 18:16:54 +00:00
Alasdair Kergon
f4cea344b1 improve a few comments in last check-in 2010-03-25 02:40:09 +00:00
Alasdair Kergon
8d6722c8ad Introduce pv_area_used into allocation algorithm and add debug messages.
This is the next preparatory step towards better --alloc anywhere
support and is not intended to break anything that currently works so
please report any problems - segfaults, bogus data in the new debug
messages, or if the code now chooses bizarre allocation layouts.
2010-03-25 02:31:48 +00:00
Mike Snitzer
a6bc975a24 Improve activation monitoring option processing
. Add "monitoring" option to "activation" section of lvm.conf
. Have clvmd consult the lvm.conf "activation/monitoring" too.
. Introduce toollib.c:get_activation_monitoring_mode().
. Error out when both --monitor and --ignoremonitoring are provided.
. Add --monitor and --ignoremonitoring support to lvcreate.  Update
  lvcreate man page accordingly.
. Clarify that '--monitor' controls the start and stop of monitoring in
  the {vg,lv}change man pages.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2010-03-23 22:30:18 +00:00
Petr Rockai
a2b6bbdfb2 Also honour abort_on_internal_errors when log_fn is set. 2010-03-23 18:18:49 +00:00
Alasdair Kergon
36f9d53b60 Allow dynamic extension of array of areas selected as allocation candidates. 2010-03-23 15:07:55 +00:00
Peter Rajnoha
5161ecb98d Autoreconf.
(Strictly require libudev if udev_sync is used)
2010-03-23 14:44:42 +00:00
Dave Wysochanski
15fdc8d3ee Avoid scanning all pvs in the system if operating on a device with mdas.
When we pv_read() a device that has an orphan vgname, we might need to scan
the system to be sure this is true.  However, if the PV has mdas, there's
no way possible for it to have an orphan vgname unless it is a true orphan.
Some areas of the code were optimized to take advantage of this fact, while
others were not (we would still do the expensive scan if a device had mdas
but had an orphan VG).

This patch unifies the code so that every place we are operating on such
a PV, we skip the expensive scan if there are mdas.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Petr Rockai <prockai@redhat.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
2010-03-18 17:29:12 +00:00
Alasdair Kergon
1091650a79 autoreconf & add missing WHATS_NEW entry 2010-03-18 13:24:35 +00:00
Petr Rockai
649c45078f Add infrastructure for running the functional testsuite with locking_type set
to 3, using a local (singlenode) clvmd.
2010-03-18 09:19:30 +00:00
Milan Broz
acb4b5e4de Fix pvcreate device check.
If user try to vgcreate or vgextend non-existent VG,
these messages appears:

# vgcreate xxx /dev/xxx
  Internal error: Volume Group xxx was not unlocked
  Device /dev/xxx not found (or ignored by filtering).
  Unable to add physical volume '/dev/xxx' to volume group 'xxx'.
  Internal error: Attempt to unlock unlocked VG xxx.

(the same with existing VG and non-existing PV & vgextend)
# vgextend vg_test /dev/xxx
...

It is caused because code tries to "refresh" cache if
md filter is switched on using cache destroy.

But we can change filters and rescan even without this
machinery now, just use refresh_filters
(and reset md filter afterwards).

(Patch also  discovers cache alias bug in vgsplit test,
fix it by using better filter line.)
2010-03-17 14:44:18 +00:00
Alasdair Kergon
0a5182fc97 Suppress repeated errors about the same missing PV uuids.
Bypass full device scans when using internally-cached VG metadata.
2010-03-17 02:11:18 +00:00
Alasdair Kergon
f168869702 fix last checkin 2010-03-16 19:06:57 +00:00
Alasdair Kergon
b1f9a2f5d1 Only do one full device scan during each read of text format metadata. 2010-03-16 17:30:00 +00:00
Alasdair Kergon
38220f9fe9 Remove unnecessary full_scan parameter from get_vgids and get_vgnames calls. 2010-03-16 16:57:03 +00:00
Alasdair Kergon
cccae7e633 Look up missing PVs by uuid not dev_name in _pvs_single to avoid invalid stat.
Make find_pv_in_vg_by_uuid() return same type as related functions.
2010-03-16 15:30:48 +00:00
Alasdair Kergon
770dc81b8e Introduce is_missing_pv(). 2010-03-16 14:37:38 +00:00
Alasdair Kergon
415feb2f44 some missing debug messages 2010-03-09 12:31:51 +00:00
Zdenek Kabelac
d0c3da55a0 Update comments for selecting maps
Use dm_snprintf and check result whether we create correct /proc path name
2010-03-09 10:25:50 +00:00
Alasdair Kergon
f0f43bc093 Misc cleanups in the new mlock code, incl. improving some variable names
& messages; using more statics (for now) to avoid redundant
recalculation; validating config file just once on loading; keeping maps
file open.
2010-03-09 03:16:11 +00:00
Zdenek Kabelac
4e27a85a2b Use mlock() only on 'r' memory maps 2010-03-08 17:14:21 +00:00
Zdenek Kabelac
26ade5f27e Unconditionaly ignore also Virtual Dynamically-linked Shared Object
(VDSO on 32bit is VSyscall on 64bit)
It seems it could be locked on 64bit kernels running 32bit binaries,
but it makes troubles on real 32bit machines where mlock() returns
error when trying to lock such map area. (0xffffe000)
Behavior of mlockall() seems to be similar.
2010-03-08 15:55:52 +00:00
Zdenek Kabelac
c900819b4e Use '_' prefix for local static variable. 2010-03-05 15:14:03 +00:00
Zdenek Kabelac
18b82048e4 mlockall() -> mlock()
This patch adds a new implementation of locking function instead
of mlockall() that may lock way too much memory (>100MB).
New function instead uses mlock() system call and selectively locks
memory areas from /proc/self/maps trying to avoid locking areas
unused during lock-ed state.

Patch also adds struct cmd_context to all memlock() calls to have
access to configuration.

For backward compatibility functionality of mlockall()
is preserved with "activation/use_mlockall" flag.

As a simple check, locking and unlocking counts the amount of memory
and compares whether values are matching.
2010-03-05 14:48:33 +00:00
Zdenek Kabelac
539f4a7728 Readline linking update
Modify linking of readline library. Create new  substituted varible
READLINE_LIBS - readline library is linked ONLY with tools that really use
it - i.e. lvm. (Static lvm does not use readlin).
Previous behaviour put this library into the variable LIBS and thus
linked it with all created object files of lvm project (i.e. plugins...).

READLINE detection is simplified.

Termcap library is linked in only if readline library doesn't have its own
dependency (i.e. old distributions).
2010-03-04 11:19:15 +00:00
Zdenek Kabelac
814aebc4e9 Use $(top_builddir) for inclusion of make.tmpl in Makefiles. 2010-03-04 09:51:37 +00:00
Mike Snitzer
c485fe183e Handle a misaligned device that reports a -1 alignment_offset.
The kernel's blk_stack_limits() function may flag a device as
'misaligned'.  If it does the alignment_offset will be -1.

Update set_pe_align_offset() to accommodate this corner case.
2010-03-02 21:56:14 +00:00
Alasdair Kergon
16d9293bd7 Extend core allocation code in preparation for mirrored log areas. 2010-03-01 20:00:20 +00:00
Milan Broz
65752052e1 Remove lvs_in_vg_activated_by_uuid_only call.
There is no difference from lvs_in_vg_activated now,
convert all users to this call.
2010-02-24 20:01:40 +00:00
Milan Broz
ab9663f394 Always query device by uuid only.
lvm2 devices have always UUID set even if imported from lvm1 metadata.

Patch removes name argument from dev_manager_info call and converts
all activation related calls to use query by UUID.

Also it simplifies mknode call (which is the only user on mknodes parameter).
2010-02-24 20:00:56 +00:00
Dave Wysochanski
3c23ff0f2e Add dm_pool_strdup to allocate memory and copy a tag in {lv|vg}_change_tag()
We need to allocate memory for the tag and copy the tag value before we
add it to the list of tags.  We could put this inside lvm2app since the
tools keep their memory around until vg_write/vg_commit is called, but
we put it inside the internal library to minimize code in lvm2app.
We need to copy the tag passed in by the caller to ensure the lifetime of
the memory until the {vg|lv} handle is released.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-02-24 18:15:57 +00:00
Dave Wysochanski
cd69ee7453 Refactor lvchange_tag() to call lv_change_tag() library function.
Similar refactoring to vgchange - pull out common parts and put into
library function for reuse.  Should be no functional change.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-02-24 18:15:49 +00:00
Dave Wysochanski
e17bcc7432 Refactor _vgchange_tag() to vg_change_tag() library function.
Pull out common code to be called from tools as well as lvm2app.
Leave archive() at tool level so we can use from vgcreate
as well as vgchange.  Should be no functional change.
- add stack macro in vgchange

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-02-24 18:15:05 +00:00
Petr Rockai
f59b0f3e07 Add _mlog devices to dependency trees using UUID, not name, in activation. 2010-02-23 15:49:52 +00:00
Mike Snitzer
4bdebfd151 Do not reload origin again in lv_remove_single() if it had a merging
snapshot.  vg_remove_snapshot() will have already performed the required
reload.
2010-02-17 23:36:45 +00:00
Mike Snitzer
a5ec3e3827 Refactor snapshot-merge deptree and device removal to support info-by-uuid
Add a merging snapshot to the deptree, using the "error" target, rather
than avoid adding it entirely.  This allows proper cleanup of the -cow
device without having to rename the -cow to use the origin's name as a
prefix.

Move the preloading of the origin LV, after a merge, from
lv_remove_single() to vg_remove_snapshot().  Having vg_remove_snapshot()
preload the origin allows the -cow device to be released so that it can
be removed via deactivate_lv().  lv_remove_single()'s deactivate_lv()
reliably removes the -cow device because the associated snapshot LV,
that is to be removed when a snapshot-merge completes, is always added
to the deptree (and kernel -- via "error" target).

Now when the snapshot LV is removed both the -cow and -real devices
get removed using uuid rather than device name.  This paves the way
for us to switch over to info-by-uuid queries.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2010-02-17 22:59:46 +00:00
Alasdair Kergon
c97cbf8c08 pre-release 2010-02-15 23:53:15 +00:00
Zdenek Kabelac
d251e86856 Use dm_report_field_int32 instead of dm_report_field_uint64 for printing '-1' 2010-02-15 20:27:33 +00:00
Zdenek Kabelac
810349313a Cleanup float arithmetic gcc warning. 2010-02-15 18:35:06 +00:00
Zdenek Kabelac
88c4995d1d * add more 'const' - fixes gcc constness warning 2010-02-15 18:34:00 +00:00
Peter Rajnoha
b9259173d0 Add LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES environment variable to suppress error
and warning mesages while --ignorelockingfailure is used.
2010-02-15 16:46:56 +00:00
Dave Wysochanski
629efc6a89 Export lvm_pv_get_size(), lvm_pv_get_free(), lvm_pv_get_dev_size in lvm2app.
We add these exports to show the pv_size and pv_free and dev_size
fields.
Fixes rhbz561423.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-02-14 03:21:37 +00:00
Dave Wysochanski
ed3329eb45 Fix off by 512 sizes for lvm2app.
Internally we store sizes in sectors, but lvm2app exports sizes
in bytes.  We could get fancier and allow units configuration but
this fix should do for now.

Fixes rhbz561422.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2010-02-14 03:21:06 +00:00
Mike Snitzer
15816a3b8c Add 'fail_if_percent_unsupported' arg to _percent() and _percent_run().
We unfortunately don't yet _know_, in dev_manager_snapshot_percent(), if
a snapshot-merge target is active (activation is deferred if dev is
open); so we can't short-circuit origin devices based purely on existing
LVM LV attributes.

Set 'fail_if_percent_unsupported' in dev_manager_snapshot_percent() for
a merging origin LV, otherwise passing unsupported LV types to _percent
will lead to a default successful return with percent_range as
PERCENT_100.

For a merging origin, PERCENT_100 will result in a polldaemon that runs
infinitely (because completion is PERCENT_0).
2010-02-10 14:38:24 +00:00
Mike Snitzer
d6bf26af8e Remove false "failed to find tree node for <lv>" error from _cached_info().
When activating a merging origin it is valid, and expected, to not have
a node in the deptree for both the origin and its merging snapshot.  The
_cached_info() caller is only concerned with whether a device is open.
If there isn't a node in the tree the associated device is definitely
not open.
2010-02-08 23:28:06 +00:00
Peter Rajnoha
04fa77c3be This is related to liblvm and its lvm_list_vg_names() and lvm_list_vg_uuids() functions
where we should not expose internal VG names/uuids (the ones with "#" prefix )through the
interface. Otherwise, we could end up with library users opening internal VGs which will
initiate locking mechanism that won't be cleaned up properly.

"#orphans_{lvm1, lvm2, pool}" names are treated in a special way, they are truncated first
to "orphans" and this is used as a part of the lock name then (e.g. while calling lvm_vg_open()).
When library user calls lvm_vg_close(), the original name "orphans_{lvm1, lvm2, pool}"
is used directly and therefore no unlock occurs.

We should exclude internal VG names and uuids in the lists provided by lvmcache:
lvmcache_get_vgids() and lvmcache_get_vgnames().
2010-02-03 14:08:39 +00:00
Dave Wysochanski
8caf272a93 Add copy constructor for struct metadata_area.
Clean up cut&paste code with proper copy constructor.
2010-02-02 16:26:34 +00:00
Milan Broz
4b373907f6 Always query device by using uuid only and not name in clvmd.
Otherwise confusion with the device of the same name
(but different UUID, e.g. non-lvm device) can happen.
2010-01-27 13:23:57 +00:00
Milan Broz
b1ef9cd0ad Fix return code of info callbacks.
In dev_manager_info 0 means error and 1 info is returned,
not that device exists (that value is part of info struct).

Fix query by uuid only (no name) which returns 0 when device
does not exist.
2010-01-26 07:58:23 +00:00
Mike Snitzer
537f7456e2 Eliminate extra ioctls just to check open_count in _add_new_lv_to_dtree.
DM >= 4.7.0 always returns open_count so just use the associated nodes'
existing info.

Introduce _cached_info() to get an LV's cached info.
2010-01-22 15:40:31 +00:00
Mike Snitzer
5cb0d45d18 Removed inactive_table check from _lv_has_target_type. This check
doesn't offer any benefit (that I can recall) and testing validates
that.
2010-01-22 13:28:54 +00:00
Milan Broz
98d85f25be Move error message to locking constructor and print
more descriptive message if locking fails instead of
"Locking type -1 initialisation failed."

Use read-only locking instead of misleading ignorelocking option
in message.
2010-01-22 09:45:29 +00:00
Dave Wysochanski
a7ca101517 Call _alloc_pv() inside _pv_read() and clean up error paths.
We should be consistent with pv constructors so call _alloc_pv()
here as we do from pv_create().
2010-01-21 21:09:23 +00:00
Dave Wysochanski
1d749d01fb Remove useless memory allocation for pv->vg_name in _alloc_pv().
All this seems to do is provide a memory leak so remove it.
The only caller of _alloc_pv() later explicitly sets
pv->vg_name = fmt->orphan_vg_name so clearly this allocation
should be removed.  I also saw no where in the code where
strncpy was used to assign pv->vg_name - only direct assignments
and strdup's.
2010-01-21 21:04:44 +00:00
Dave Wysochanski
2b1446c7d6 Correct 'void *' usage in pvcreate_single.
Remove needless cast.
2010-01-21 21:04:20 +00:00
Mike Snitzer
dfcb905db0 Preload the origin prior to suspend IFF snapshot(s) still exist after a
merge completes.  This narrows the scope of this "hack" (which still
needs a proper fix within the deptree).

This stops dmeventd from trying to access snapshot devices that were
already removed.
2010-01-20 21:53:10 +00:00
Milan Broz
7a96516819 Never scan suspended devices in clvmd.
For mirror repair (and similar tasks) it can happen that full
device rescan is issued from clvmd.

Because code can be in the middle of repair (calling suspend)
clvmd should never try to scan suspended devices
(otherwise it causes deadlock).

Also code must not change ignore_suspended_device flag when
doing refresh_filters (called from lvmcache scan code).
2010-01-19 13:25:00 +00:00
Mike Snitzer
6c1c02dc52 Change dev_manager_mirror_percent()'s 'struct logical_volume *' to be
'const'.  Be consistent with its use (and dev_manager_snapshot_percent()).

Pass 'lv' from dev_manager_snapshot_percent() to _percent() to
_percent_run().  _percent_run() always dereferenced 'lv' (when
initializing segh) even though it may have been NULL (as was the case
until now for dev_manager_snapshot_percent()).

If a "snapshot-origin" LV (snapshot-merge whose merge was deferred
becuase it was open) was passed to _percent_run() it would always return
100%.

Update _percent_run() to NOT return PERCENT_100 et. al. if
->target_percent() wasn't ever called and supplied 'lv' is a merging
origin.  A default return of 100% does not work for snapshot-merge.

Also tweak a related lvconvert log_error() to include "Aborting merge."
2010-01-15 22:58:25 +00:00
Mike Snitzer
eb9454ab68 Detect case of both merging_store and cow_store supplied in
_snap_text_import().
2010-01-15 17:46:08 +00:00
Mike Snitzer
e47a591d76 Improve target type compatibility checking in _percent_run().
Add 'target_status_compatible' method to 'struct segtype_handler'.
2010-01-15 16:35:26 +00:00
Alasdair Kergon
8dc351e8d4 Note some problems still to be addressed. 2010-01-14 14:39:57 +00:00
Zdenek Kabelac
fc28b13c7d Cleanup const compiler warning 2010-01-14 10:17:12 +00:00
Zdenek Kabelac
4269e36315 Move initialization of the 'cmd' member of the struct alloc_handle
before the first potentional return.
2010-01-14 10:09:42 +00:00
Zdenek Kabelac
5f31bc7926 lvol%d is generated for NULL name in lv_create_empty().
So just avoid code duplication.
2010-01-14 10:08:03 +00:00
Milan Broz
43b24f7c61 Fix clvmd automatic target module loading crash. 2010-01-13 17:40:17 +00:00
Mike Snitzer
c52678ee9b Rename segment and lv status flag from SNAPSHOT_MERGE to MERGING.
Eliminate 'merging_snapshot' from 'struct logical_volume' and just use
'snapshot' for origin lv's reference to the merging snapshot; also set
MERGING in the origin lv's status.
2010-01-13 01:56:18 +00:00
Mike Snitzer
c79b425135 Add snapshot merge wrappers to abstract the associations and flags used
to represent merging origin and snapshot volumes.
2010-01-13 01:55:43 +00:00
Mike Snitzer
c582e3c039 Merge on activate support.
If either the origin or snapshot that is to be merged is open the merge
will not start; only the merge metadata will be written.  The merge will
start on the next activation of the origin (or via lvchange --refresh)
IFF both the origin and snapshot are closed.

Merge on activate is particularly important if we want to merge over a
mounted filesystem that cannot be unmounted (until next boot) --- for
example root.
2010-01-13 01:54:34 +00:00
Mike Snitzer
28c3f0354a When turning merging origin into non-merging origin, there is bad sequence:
snapshots are suspended, new origin is created, snapshots are resumed, new
origin is resumed.  So it allocates memory while suspended.

To fix it, move vg_commit after suspend_lv, so that the suspend code will
treat it as precommitted vg and will preload new origin prior to suspend.

NOTE: agk doesn't like this "hack"; need to revisit and fix
2010-01-13 01:52:58 +00:00
Mike Snitzer
3a8d01b6e1 Reload origin if merging has stopped. 2010-01-13 01:51:45 +00:00
Mike Snitzer
c45af88a83 When there is merging snapshot, report percentage on the origin LV.
Because the snapshot LV will be hidden this is needed so the user can
see merging progress with "lvs" command.
2010-01-13 01:49:22 +00:00
Mike Snitzer
3b6a076e1e Report merging snapshot as 'S' instead of 's':
This is useful for when the snapshot is still active and merging hasn't
started yet; it shows a merge is pending.  Once merging starts the
merging snapshot will be hidden but can still be displayed with 'lvs -a'

Report snapshot origin with merging snapshot as 'O' instead of 'o':
Before merge starts this shows that a merge is pending.  While merging
the snapshot will be hidden, 'O' enables a user to see that there is a
snapshot merging.
2010-01-13 01:48:38 +00:00
Mike Snitzer
0b2d216f8e Merging device is loaded with "-cow" suffix and with base name of the
origin.  This is needed so that "-cow" device can be found and removed
when lvremove is performed.
2010-01-13 01:44:37 +00:00
Mike Snitzer
c21b944a35 Conditionally push down either the "snapshot-origin" or
"snapshot-merge" target based on whether the LV is a merging snapshot.

When activating a snapshot-merge target do not attempt to monitor the
LV for events; the polldaemon will monitor the snapshot as it is
merged.

Allow "snapshot-merge" target's usage to be parsed via standard
"snapshot" methods.

NOTE: follow on fixes to the _percent_run change are still needed
2010-01-13 01:43:32 +00:00
Mike Snitzer
aa6f4e51a7 Add support for "snapshot-merge" target.
Introduces new libdevmapper function dm_tree_node_add_snapshot_merge_target

Verifies that the kernel (dm-snapshot) provides the 'snapshot-merge'
target.

Activate origin LV as snapshot-merge target.  Using snapshot-origin
target would be pointless because the origin contains volatile data
while a merge is in progress.

Because snapshot-merge target is activated in place of the
snapshot-origin target it must be resumed after all other snapshots
(just like snapshot-origin does) --- otherwise small window for data
corruption would exist.

Ideally the merging snapshot would not be activated at all but if it is
to be activated (because snapshot was already active) it _must_ be done
after the snapshot-merge.  This insures that DM's snapshot-merge target
will perform exception handover in the proper order (new->resume before
old->resume).  DM's snapshot-merge does support handover if the reverse
sequence is used (old->resume before new->resume) but DM will fail to
resume the old snapshot; leaving it suspended.

To insure the proper activation sequence dm_tree_activate_children() was
updated to accommodate an additional 'activation_priority' level.  All
regular snapshots are 0, snapshot-merge is 1, and merging snapshot is 2.
2010-01-13 01:39:44 +00:00
Mike Snitzer
68e8f5a4a2 Add 'SNAPSHOT_MERGE' lv_segment 'status' flag.
Make 'merging_snapshot' pointer that points from the origin to the
segment that represents the merging snapshot.

Import/export 'merging_store' metadata.

Do not allow creating snapshots while another snapshot is merging.
Snapshot created in this state would certainly contain invalid data.

NOTE: patches at the end of this series will remove 'merging_snapshot'
and will introduce helpful wrappers and cleanups.
2010-01-13 01:35:49 +00:00
Alasdair Kergon
109e6334b0 Fix allocation code not to stop at the first area of a PV that fits.
This spurious 'break' has been here since this code was first committed
in June 2005 and stopped the algorithm behaving as described in the
comment above it and rendered the variable 'already_found_one' useless.
2010-01-12 20:53:20 +00:00
Alasdair Kergon
f3ac7d1b82 Revert so-called "redundant" log until after next release. 2010-01-12 14:00:51 +00:00
Jonathan Earl Brassow
673421ffc2 Testsuite updates and fixes for recently added features.
1. Found bug in 'redundant log' implementation that caused
   problems when converting a linear that spanned multiple
   devices to a mirror (wasn't checking for NULL value of
   provided parameter in _alloc_parallel_area)

2. Testsuite was failing to perform tests when 'not' modifier
   was used.  This allowed a couple issues to slip through.
   Added a 'not_sh' modifier that negates tests performed by
   functions defined in the shell source file.

3. Was initializing a variable to far down, which cause
   previously set value to be overridden.  (This was the
   result of the collision of the "redundant log" and
   lvconvert fix patches.)
2010-01-11 21:20:19 +00:00
Alasdair Kergon
e55df6fee5 Use _LOG_FATAL when aborting on an internal error. 2010-01-11 20:41:39 +00:00
Alasdair Kergon
e995e713f9 Internal errors triggering abort cannot be suppressed. (kabi) 2010-01-11 20:30:32 +00:00
Mike Snitzer
ccd6d287eb remove errant comment fragment 2010-01-11 19:12:25 +00:00
Mike Snitzer
beacd0b303 Reset _vgs_locked in lvmcache_init()
Upon successful fork(), _become_daemon() must assert that the locks that
are currently held belong to the parent, not the child.  All of the
child's internal state saying 'this process holds a lock' has to be
reset.

A proper lvmcache_locking_reset() should follow later.
2010-01-11 19:08:18 +00:00
Peter Rajnoha
a750353641 Add support to disable udev checking: LVM_UDEV_DISABLE_CHECKING=1 env. var.
LVM_UDEV_DISABLE_CHECKING=1 applies for /dev/<vgname> content only.
We still need to define DM_UDEV_DISABLE_CHECKING=1 for /dev/mapper content.
2010-01-11 15:40:03 +00:00
Mike Snitzer
b422bb2187 remove unused variable 'i' that was recently introduced in lv_add_segment 2010-01-10 20:44:09 +00:00
Jonathan Earl Brassow
23f4aabd69 update comment 2010-01-08 23:06:36 +00:00
Jonathan Earl Brassow
77dd1c0e5f Add the new mirror log type "redundant". The options are now:
--mirrorlog core: in-memory log
--mirrorlog disk: persistent log
--mirrorlog redundant: redundant persistent log

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-08 22:32:35 +00:00
Jonathan Earl Brassow
72e0743621 This patch adds the capability to split off a mirror legs.
It is pretty much the same as reducing the number of
mirror legs, but we just don't delete them afterwards.

The following command line interface is enforced:
  prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of images to split off, and
where 'name' is the name of the newly split off logical volume.

If more than one leg is split off, a new mirror will be the
result.  The newly split off mirror will have a 'core' log.
Example:
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
  LV            Copy%  Devices
  lv            100.00 lv_mimage_0(0),lv_mimage_1(0),lv_mimage_2(0),lv_mimage_3(0)
  [lv_mimage_0]        /dev/sdb1(0)
  [lv_mimage_1]        /dev/sdc1(0)
  [lv_mimage_2]        /dev/sdd1(0)
  [lv_mimage_3]        /dev/sde1(0)
  [lv_mlog]            /dev/sdi1(0)
[root@bp-01 LVM2]# lvconvert --splitmirrors 2 --name split vg/lv /dev/sd[ce]1
  Logical volume lv converted.
[root@bp-01 LVM2]# !lvs
lvs -a -o name,copy_percent,devices
  LV               Copy%  Devices
  lv               100.00 lv_mimage_0(0),lv_mimage_2(0)
  [lv_mimage_0]           /dev/sdb1(0)
  [lv_mimage_2]           /dev/sdd1(0)
  [lv_mlog]               /dev/sdi1(0)
  split            100.00 split_mimage_0(0),split_mimage_1(0)
  [split_mimage_0]        /dev/sde1(0)
  [split_mimage_1]        /dev/sdc1(0)

It can be seen that '--splitmirror <n>' is exactly the same
as '--mirrors -<n>' (note the minus sign), except there is the
additional notion to keep the image being detached from the
mirror instead of just throwing it away.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
2010-01-08 22:00:31 +00:00
Zdenek Kabelac
56bb994166 orig_status preserves 64bit status. 2010-01-08 10:50:11 +00:00
Peter Rajnoha
cda69e17ef Add activation/udev_rules config option in lvm.conf.
Add dm_tree_add_dev_with_udev_flags to provide wider support for udev flags.
2010-01-07 19:54:21 +00:00
Zdenek Kabelac
387f47078c Add few const modifiers. 2010-01-07 14:47:57 +00:00
Zdenek Kabelac
a362bb23c0 Use macro outsize() with check for error return value. 2010-01-07 14:46:51 +00:00
Zdenek Kabelac
ea8acabe26 Export function out_text_with_comment() and add outfc() macro that checks
for error.
2010-01-07 14:45:28 +00:00
Zdenek Kabelac
1e13fa7a6a Add macros outsize() for out_size() and outhint() for out_hint() that check
for errors in a similar way as outf() for out_text().
2010-01-07 14:40:46 +00:00
Zdenek Kabelac
c75550f5ba Use offsetof() macro and avoid defining dummy static union for FIELD() macro.
Makes it compilable by clang compiler.
2010-01-07 14:37:11 +00:00
Zdenek Kabelac
f760f97a1f Just add '.' at the end of error message. 2010-01-07 14:29:53 +00:00
Milan Broz
03984e05a3 Rename mirror_device_fault_policy to mirror_image_fault policy 2010-01-06 13:27:06 +00:00
Milan Broz
5d196aa430 Use fixed buffer to prevent stack overflow in persistent filter dump. 2010-01-06 13:25:36 +00:00
Mike Snitzer
5b7f6ad698 Use snapshot metadata usage to determine if snapshot is empty
Version >= 1.8.0 of the DM snapshot target appends metadata sectors used
to a snapshot's status.  This patch allows LVM2 to accurately determine
if the snapshot store is empty.  Knowing when a snapshot store is empty
is important in the context of snapshot-merge (means merge is complete).

Also update LVM2 to be aware of the possibility for "Merge failed" in
the snapshot-merge target's status.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2010-01-05 21:14:04 +00:00
Mike Snitzer
56b3d20462 Add missing 'stack;' for all activate_lv and deactivate_lv callers.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2010-01-05 21:08:34 +00:00
Mike Snitzer
df13cf08d5 Add missing 'stack;' for all suspend_lv and resume_lv callers.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2010-01-05 21:07:31 +00:00
Mike Snitzer
7a8fa6aaab Add a [--poll {y|n}] flag to vgchange and lvchange to control whether
the background polldaemon is allowed to start.  It can be used
standalone or in conjunction with --refresh or --available y.

Control over when the background polldaemon starts will be particularly
important for snapshot-merge of a root filesystem.

Dracut will be updated to activate all LVs with: --poll n

The lvm2-monitor initscript will start polling with: --poll y

NOTE: Because we currently have no way of knowing if a background
polldaemon is active for a given LV the following limitations exist and
have been deemed acceptable:
1) it is not possible to stop an active polldaemon; so the lvm2-monitor
   initscript doesn't stop running polldaemon(s)
2) redundant polldaemon instances will be started for all specified LVs
   if vgchange or lvchange are repeatedly used with '--poll y'

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2010-01-05 20:56:51 +00:00
Milan Broz
0e06c92fdf Propagate commit and revert metadata event to other nodes in cluster.
This patch tries to correctly track changes in lvmcache related to commit/revert.

For vg_commit: if there is cached precommitted metadata, after successfull commit
these metadata must be tracked as committed.

For vg_revert: remote nodes must drop precommitted metadata and its flag in lvmcache.

(N.B. Patch do not touch LV locks here in any way.)

All this machinery is needed to properly solve remote node cache invalidaton which
cause several problems recently observed.
2010-01-05 16:09:33 +00:00
Milan Broz
c9118a1d20 Proper mask lock mode for vg lock.
Lock mode is int masked by LCK_TYPE_MASK, always.

Patch also remove uneccessary masking lock flag on sender side,
if masking is needed, it is don on client side already.
2010-01-05 16:07:56 +00:00
Milan Broz
d37be0b865 Add possibility to handle precommitted metadata in lvmcache.
- Add drop_precommitted flag to force drop precommitted metadata
 - add lvmcache_commit_metadata() which upgrades precommitted metadata in cache

No functional change in this patch - just preparation for following change.
2010-01-05 16:06:42 +00:00
Milan Broz
d7f44761ab Properly decode flags even for VG locks.
And decode flags in humar readable form in client.
And clean some trailing whitespaces.

No functional change in this patch (only debugging messages changed).
2010-01-05 16:03:37 +00:00
Milan Broz
4b1687fb74 Do not set precommitted flag in cache when precommitted metadata does not exist.
The use_precommitted flag indicates, that we want to use precommitted metadata
(used in suspend call to preload table with precommitted data).

But if there are no such data, committed metadata are read but the cache
still contains that precommitted flag.

(The problem is that later possible drop_metadata call will not invalidate
device in cache.)

The wrong precommitted state is stored in on remote nodes during normal
suspend/resume cycle _without_ vg_write/commit.

Use the PRECOMMITTED status flag here instead (which is always set if using
precommited metadata here).
2010-01-05 16:01:22 +00:00
Milan Broz
60494fe74b Resume volumes in reverse order to preserve memlock pairing.
If renaming snapshot with virtual origin, the origin is renamed too.
But the code must resume LVs in reverse order to properly
pair memlock (in cluster locking).

(The resume of snapshot resumes origin too and later resume
is ignored otherwise.)
2010-01-05 15:58:11 +00:00
Milan Broz
cfe30f1df3 Drop metadata cache after device was autorepaired and removed from VG.
All long running processes must reload metadata when some
device becomes orphan after repair.
2009-12-18 12:45:41 +00:00
Milan Broz
aa02928ff7 Remove missing flag if PV reappeared and is empty.
When PV device reappears with old metadata, it is
always updated to new version byt atutomatic metadata
repair.

Remove missing flag if device is empty.

If device contains allocated extents, issue warning that
user must remove volumes and re-add this PV before
manipulating with this volume.

This partially solves bug 547842 when one PV (log) is failed,
dmeventd removes that device and later this device reappears and
is wrongly added into VG marked missing.
2009-12-18 12:44:20 +00:00
Petr Rockai
fbcb06145b Revert another unintended change that snuck in. 2009-12-17 15:59:53 +00:00
Petr Rockai
dff5da2d64 Fix removal of multiple devices from a mirror (+ regression test). 2009-12-17 15:38:29 +00:00
Petr Rockai
207542b40e Revert unintended change that slipped in with last checkin. 2009-12-16 19:26:20 +00:00
Petr Rockai
550cae2340 #define an INTERNAL_ERROR macro and use it throughout LVM. 2009-12-16 19:22:11 +00:00
Zdenek Kabelac
b1ebf028de Cleanup returns for void functions. 2009-12-11 13:16:37 +00:00
Zdenek Kabelac
735308699c Destroy allocated mempool in _vg_read_orphans() error path. 2009-12-11 13:14:44 +00:00
Milan Broz
34de60e4d4 Call explicitly suspend for temporary mirror layer.
The memlock_inc() fix is wrong, memlock count is not
propagated to long living process (clvmd) and just
it underflow there.
Also suspend is needed to pre-load precommited metadata
on other nodes (remapping to error taget in this case).

With explicit suspend we generate lock request and code
can update memlock count.

(Infinitely "locked" memory caused that fs_unlock() was not
called properly and on cluster nodes remains
old links in /dev/mapper for not active devices.)

(N.B. failing of suspend call here is not handled as fatal
error - the LV is going to be removed later anyway.)
2009-12-09 19:53:39 +00:00
Milan Broz
adee669441 Use more descriptive variable name for temporary layer lv. 2009-12-09 19:43:39 +00:00
Milan Broz
0fa0e6addf Allow manipulation with precommited metadata even when a PV is missing.
The new recovery code first tries to repair LV and then removes failed PV
from VG. It means that during operation there can be VG with PV missing,
and vg_read code handles it like not consistent VG.

We already allows returning "inconsistent" commited metadata,
for mirror repair we need this for precommited too.
(The suspend call prepares precommited metadata to inactive table on
other cluster nodes.)

"Inconsistent" here means - correct metadata, just with some metadata areas
not found (obviously on missing or failed PVs).
2009-12-09 19:29:04 +00:00
Milan Broz
7251c8f3a5 Get rid of magic masks in cluster locking code.
Patch should not cause any problems, only real change is
removing LCK_LOCAL bit from lock type flag, it is never used there.
(LCK_LOCAL is part arg[1] bits anyway.)
2009-12-09 18:28:27 +00:00
Milan Broz
f9f8cd08b3 Get rid of hardcoded 0xffdf cluster lock flag.
There is hidded change - the upper flags (0xffff0000)
and now not cleared, but there are unused anyway.
2009-12-09 18:16:38 +00:00
Milan Broz
f72a06ccf7 Remove newly created log volume if initial deactivation fails.
If there is problem deactivate LV and
_init_mirror_log is called with remove_on_failure = 1,
remove the newly created log LV from metadata.

(This can happen if there is active device with the same name
but different UUID.)

The main reason for this "workaround" patch is to
 - do not keep _mlog volume in metadata, so user can repeat the action
 - print better error message describing the real problem

# lvcreate -m 2 -n lv1 -l 1 --nosync vg_bar
  WARNING: New mirror won't be synchronised. Don't read what you didn't write!
  /dev/vg_bar/lv1_mlog: not found: device not cleared
  Aborting. Failed to wipe mirror log.
  Error locking on node bar-01: Input/output error
  Unable to deactivate mirror log LV. Manual intervention required.
  Failed to create mirror log.

# lvcreate -m 2 -n lv1 -l 1 --nosync vg_bar
  WARNING: New mirror won't be synchronised. Don't read what you didn't write!
  Aborting. Unable to deactivate mirror log.
  Failed to initialise mirror log.
2009-12-09 18:09:52 +00:00
Dave Wysochanski
59baeb838c Update a few more uint64_t's related to the 64-bit status change.
At this point they probably do not matter but going forward they
may - depends on future patches for replicator, etc.  I think
these probably got missed because they were 'flags' so I changed
the name to 'status' to be consistent.  So the on-disk
things 'flags' and the in structure 'status' (bits).
NOTE: WHATS_NEW already has entry for this in current release.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Mike Snitzer <snitzer@redhat.com>
2009-12-04 17:48:32 +00:00
Milan Broz
63ae0d1464 Fix memory lock imbalance in lv_suspend if already suspended.
pvmove suspends all moved LVs + pvmoveX mirrored LV itself.

This suspends even underlying pvmoveX and following explicit
suspend call is just noop.

But in resume the pvmoveX volume is no longer underlying
device for moved LVs, so it performs full resume with memlock
decrease.

Code must call memlock_inc() if suspend is requested, volume
is already suspended and error is not requested.
2009-12-03 19:23:40 +00:00
Milan Broz
fec4de9563 Fix tools to report error when stopped by user.
(And do not produce internal error message.)
2009-12-03 19:18:33 +00:00
Zdenek Kabelac
60184834b5 minor indent change 2009-12-03 10:01:30 +00:00
Zdenek Kabelac
6c8ffd0362 skip cast from (void*) 2009-12-03 09:59:54 +00:00
Zdenek Kabelac
08e64ce5e9 minor whitespace indentation 2009-12-03 09:58:30 +00:00
Dave Wysochanski
c053fb62bc Fix setting of readahead in lvcreate.
The default comes from the configuration settings, with possible
commandline override.
2009-12-03 01:47:33 +00:00
Milan Broz
0548bcc2dc Fix memory leak in lv_info_by_lvid
The lv_from_lvid calls internally vg_read(),
we must release vg structure afterwards.

Code is called only from clvmd.
2009-12-01 19:10:23 +00:00
Petr Rockai
f1a4ec40fc If aborting due to an internal error, always print the message causing this. 2009-12-01 13:54:27 +00:00
Petr Rockai
99a304bc17 Optionally abort on internal errors (and leverage this option in the
testsuite). (This is showing a problem in the pvmove test for me, so I expect
the tests to start failing -- this needs to be fixed separately though.)
2009-11-30 17:17:11 +00:00
Milan Broz
5800aa5c07 Do not allow creating mirrors of more than 8 images.
This is kernel limitation in all kernel versions,
so better detect this early.
2009-11-27 14:35:38 +00:00
Dave Wysochanski
ccb601a3cb Remove unnecessary / duplicate dm_list macros and functions.
These are no longer used by anyone.  The dm_list defines are all in
libdevmapper.h and libdm/datastruct/list.c contains any function definitions.
There is some code in "old-tests" that still use this but this code is not
being maintained.

Thanks to Zdenek for spotting this.
2009-11-25 20:44:07 +00:00
Mike Snitzer
a2552d4f59 Switch status from 32-bit to 64-bit
The physical_volume, volume_group, logical_volume and lv_segment
structures' 'status' member is now uint64_t.

The alignment of these structures was also audited to remove holes.  The
movement of some members in 'volume_group' and 'lv_segment' eliminates
holes.  The 'physical_volume' structure still has one 4-byte hole after
'pe_size'; the other structures no longer have any holes.  Each
structures' size has not changed.
2009-11-24 22:55:55 +00:00
Milan Broz
cd501dd440 Move persistent filter dump to more appropriate place.
After context_refresh is cache empty, the cache flush
does nothing.

Call it after lvmcache full rescan if running from
log lived process.
2009-11-24 16:11:37 +00:00
Milan Broz
e1ab01e3ad Refresh device filters before full device rescan in lvmcache.
The sysfs filter initialise hash of available devices using
scan of /sys/block. We need to refresh even this hash
when performing full scan otherwise the newly appeared
device could be rejected, because there is no entry
in sysfs filter.

This easily could happen when attaching new device
to cluster node. (Only force refresh of context
in clvmd -R works here now).

Unfortunately consequences of this are much worse,
missing device part on that node is replaced with missing segment
(even when no partial arg is selected) and this directly
lead to data corruption.

See https://bugzilla.redhat.com/show_bug.cgi?id=538515

Simply fix it by refreshing device filters in lvmcache
before performing the full device scan.
2009-11-24 16:10:25 +00:00
Milan Broz
6b8304ab43 Fix memory lock imbalance in locking code.
(This affects only cluster locking because only cluster
locking module set LCK_PRE_MEMLOCK.)

With currect code you get
# vgchange -a n
  Internal error: _memlock_count has dropped below 0.
when using cluster locking.

It is caused by _unlock_memory calls here

  if ((flags & (LCK_SCOPE_MASK | LCK_TYPE_MASK)) == LCK_LV_RESUME)
     memlock_dec();

Unfortunately it is also (wrongly) called in immediate unlock
(when LCK_HOLD is not set) from lock_vol
(LCK_UNLOCK is misinterpreted as LCK_LV_RESUME).

Avoid this by comparing original flags and provide memlock
code type of operation (suspend/resume).
2009-11-23 10:55:14 +00:00
Milan Broz
a4893bc377 Revert vg_read_internal change, clvmd cannot use vg_read now. (2.02.55) 2009-11-23 10:44:50 +00:00
Petr Rockai
4e11dfe3ca In case we refuse to continue due to missing PVs, print a hint about using
vgreduce --removemissing to remedy the situation.
2009-11-19 13:44:37 +00:00
Petr Rockai
e2683aafe6 The double resume in remove_mirror_images does not happen *always*. Only call
memlock_inc() when it actually does happen.
2009-11-19 13:42:38 +00:00
Petr Rockai
090585a8f4 Un-export vg_read_internal. 2009-11-19 12:13:37 +00:00
Petr Rockai
2f1d6f7f0c Add a missing #include (fix compiler warning). 2009-11-19 12:09:53 +00:00
Petr Rockai
4514bdcfa2 Fix another bug in memlock handling, this time the "global" dmeventd memlock
was preventing device scans in lvconvert --repair running from inside dmeventd.
2009-11-19 01:11:57 +00:00
Petr Rockai
c85222c461 Add an extra memlock_inc() to _remove_mirror_images to properly balance
reference counting (see code comment for details).
2009-11-18 18:23:46 +00:00
Petr Rockai
39b1e58979 Issue an Internal error message whenever _memlock_count drops below 0. 2009-11-18 18:22:32 +00:00
Milan Broz
20babc7b4f Fix pvmove region_size overflow for very large PVs.
Fixes problem reported in
https://www.redhat.com/archives/dm-devel/2009-November/msg00104.html

The region size multiplication can overflow when using 32bit integer.
2009-11-18 16:48:10 +00:00
Milan Broz
6ddadf4023 Fix compilation warning:
activate/dev_manager.c:362: warning: combined_percent_range may be used uninitialized in this function
2009-11-04 14:56:35 +00:00
Zdenek Kabelac
7fb52b9c39 Export functions out_inc_indent(), out_dec_indent() for creating
indented metadata lines.

Macro outnl() is using exported out_newline() instead of direct
call f->fn(), that required the visibility of the internal
struct formatter.
2009-11-03 11:00:46 +00:00
Zdenek Kabelac
61c146fb97 Add fflush for the case the log is redirected to the buffered file.
Without this patch it have not been obvious, why the application
waits on the stdin as the prompt might be still buffered in memory.
2009-11-03 10:50:57 +00:00
Dave Wysochanski
a42efe6bdf Rename validate_vg_create_params to vgcreate_params_validate. 2009-11-01 20:05:17 +00:00
Dave Wysochanski
accb17389c Rename pvcreate_params processing functions to better match <object><action>.
Rename fill_default_pvcreate_params to pvcreate_params_set_defaults.
Rename pvcreate_validate_restore_params to pvcreate_restore_params_validate.
Rename pvcreate_validate_params to pvcreate_params_validate.
2009-11-01 19:51:54 +00:00
Dave Wysochanski
0e6c4e93da Add vg_set_clustered() - move logic from vgchange.
Similar to other vg_set_* functions, we create a vg_set_clustered() function
which does a few checks and sets a flag.  This is where we check for
any limitations of clusters.
2009-10-31 17:30:52 +00:00
Dave Wysochanski
29aa56df68 Add vg_mda_count library function. 2009-10-31 17:26:13 +00:00
Alasdair Kergon
75b37a1147 Insert some missing stack macros into activation code. 2009-10-30 13:07:49 +00:00
Milan Broz
4059d2219c Recognise DRBD device part and handle it similar to MD devices.
The DRBD uses underlying device so code should prefer top
device if duplicate is found.

Patch also introduce
        dev_subsystem_part_major and dev_subsytem_name
functions to easily handle all these replication susbystems
and not hardcode md_major call.

See https://bugzilla.redhat.com/show_bug.cgi?id=530881
for full problem description.
2009-10-27 17:00:44 +00:00
Peter Rajnoha
421671b1c2 Several changes to udev support code:
- we have these levels when the udev rules are processed:
   10-dm.rules --> [11-dm-<subsystem>.rules] --> [12-dm-permissions.rules] -->
   13-dm-disk.rules --> [...all the other foreign rules...] --> 95-dm-notify.rules

 - each level can be disabled now by
   DM_UDEV_DISABLE_{DM, SUBSYSTEM, DISK, OTHER}_RULES_FLAG

 - add DM_UDEV_DISABLE_DM_RULES_FLAG to disable 10-dm.rules

 - add DM_UDEV_DISABLE_OTHER_RULES_FLAG to disable all the other (non-dm) rules.
   We cutoff these rules by using the 'last_rule', so this one should really be
   used with great care and in well-founded situations. We use this for lvm's
   hidden and layer devices now.

 - add a parameter for add_dev_node, rm_dev_node and rename_dev_node so it's
   possible to switch on/off udev checks

 - use DM_UDEV_DISABLE_DM_RULES_FLAG and DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG
   if there's no cookie set and we have resume, remove and rename ioctl.
   This could happen when someone uses the libdevmapper that is compiled with
   udev_sync but the software does not make use of it. This way we can switch
   off the rules and fallback to libdevmapper node creation so there's no
   udev/libdevmapper race.
2009-10-26 14:29:33 +00:00
Alasdair Kergon
984abde146 Permit snapshots of mirrors. (brassow) 2009-10-26 10:01:56 +00:00
Alasdair Kergon
06bb53b1e8 Remember to clear 'global lock held during cache refresh' state after use. 2009-10-22 17:33:09 +00:00
Peter Rajnoha
f16aea9ebd Use udev flags support in LVM and provide dm_tree_add_new_dev_with_udev_flags wrapper for dm_tree_add_new_dev. 2009-10-22 13:00:07 +00:00
Petr Rockai
6ce24f679a Fix the "const discarded" warnings introduced in the unknown segment patch. 2009-10-22 10:38:07 +00:00
Petr Rockai
b4048242f5 Handle metadata with unknown segment types more gracefully. 2009-10-16 17:41:49 +00:00
Jonathan Earl Brassow
a1bb606aab I saw this in a bug report:
[root@xxxx-01 ~]# lvconvert -m 1 --corelog VG/cmirror
  Unable to convert the log of inactive cluster mirror cmirror

I've tried to clean-up the message a little more, so the name
of the mirror stands out more while preserving the sense that
it's not a problem with the specific device, but the fact that
it is inactive that is causing the problem.

New msg:
  Unable to convert the log of an inactive cluster mirror, cmirror
2009-10-14 14:55:44 +00:00
Fabio M. Di Nitto
89044bc0fe Disable realtime support by default.
This code is used only in a under development feature and it's not used
anywhere in the tree.

Allow to build it conditionally.
2009-10-12 16:59:20 +00:00
Fabio M. Di Nitto
2cec0e4562 Merge Debian patch 05 debian: keep libdm-abi consistent.
This appears to be the only user visible feature that can change libdm ABI
at build time.

Thanks to Bastian Blank for the patch.
2009-10-12 04:06:42 +00:00
Dave Wysochanski
21e094d9df Cleanup comment and some whitespace. 2009-10-06 16:00:38 +00:00
Dave Wysochanski
36a1d8166c Refactor pvcreate - split pvcreate_validate_params into recovery/non-recovery.
Split pvcreate_validate_params into recovery and non-recovery parameters.
This is necessary so we can call the non-recovery validate function from
vgextend / vgcreate.  Note in the pvcreate tool case, we must call the
recovery validation function first (see treatment of pe_start and --zero),
and that we add a call to fill_default_pvcreate_params before the validation
functions.
2009-10-05 20:03:25 +00:00
Dave Wysochanski
c24a4ff2cc Allow calling fill_default_pvcreate_params from tools.
We need defaults for pvcreate_params at a higher level - this will
allow us to use a common function from the tools to take defaults,
then fill in any non-defaults from the commandline.

Future patches will refactor vgcreate/vgextend to call this function
if one or more pvcreate parameters are given on the commandline.
2009-10-05 20:03:08 +00:00
Dave Wysochanski
29123aa652 Add pvcreate_params to vg_extend.
Another refactoring for implicit pvcreate support.  We need to get
the pvcreate parameters somehow to the vg_extend routine.  Options
seemed to be:
1. Attach the parameters to struct volume_group.  I personally
did not like this idea in most cases, though one could make an
agrument why it might be ok at least for some of the parameters
(e.g. metadatacopies).
2. Pass them in to the extend routine.  This second route seemed
to be the best approach given the constraints.

Future patches will parse the command line and fill in the actual
values for the pvcreate_single call.
Should be no functional change.
2009-10-05 20:02:48 +00:00
Dave Wysochanski
acb4073eed Add pvcreate_params to vg_extend_single_pv.
Should be no functional change.  If this parameter is set to NULL, just fail
the extend if the device is not already a PV.  If non-NULL, try pvcreate_single
before failing.  Note that pvcreate_single() handles the log_error in case
of failure so we just return 0 if pvcreate_single() fails.
2009-10-05 20:02:30 +00:00
Dave Wysochanski
a80fc69320 Refactor vg_extend - add vg_extend_single_pv.
Simple refactor to setup future changes related to implicit pvcreates.
Should be no functional change.
2009-10-05 20:02:04 +00:00
Alasdair Kergon
437219e27d More makefile cleaning up and fixing. (gentoo) 2009-10-05 13:46:00 +00:00
Alasdair Kergon
cf65a124e6 Correct example.conf to indicate that lvm2 not lvm1 is the default format.
Remove an unused stray LVM1_SUPPORT ifdef.
2009-10-05 12:44:20 +00:00
Alasdair Kergon
db8b5af9d9 Allow for a build directory separate from the source. 2009-10-02 19:10:31 +00:00
Christine Caulfield
5f3dc21dba Add LCK_CONVERT flag I missed on the last checkin. 2009-10-01 14:15:34 +00:00
Alasdair Kergon
3d32c5f88b Add percent_range to copy_percent too. 2009-10-01 01:04:27 +00:00
Alasdair Kergon
78ad1549a5 Introduce percent_range_t and centralise snapshot full/mirror in-sync checks. 2009-10-01 00:35:29 +00:00
Alasdair Kergon
8e4858ccd1 Distinguish between powers of 1000 and powers of 1024 in unit suffixes. 2009-09-30 14:19:00 +00:00
Alasdair Kergon
64a950108c Don't attempt to deactivate an LV if any of its snapshots are in use. 2009-09-29 18:50:28 +00:00
Milan Broz
89a6cdfd4c Return fail if lv_deactivate did not removed device from kernel.
lv_deactivate now returns always success, because tree deactivation
functions (see dm_tree_deactivate_children) always returns success.

Because code should return failure in lv_deactivate at least,
fix it by checking for device existence after real deactivation call.

(After discussion this was prefered solution to dm tree function rewrite
which affects snapshots and mirrors.)
2009-09-29 15:17:54 +00:00
Alasdair Kergon
a0f9708e49 Provide alternative implementation of obsolete siginterrupt(). 2009-09-28 21:23:02 +00:00
Alasdair Kergon
d557773841 Consolidate LV allocation into alloc_lv(). 2009-09-28 17:46:15 +00:00
Alasdair Kergon
673ecf73cf Treat input units of both 's' and 'S' as 512-byte sectors. (2.02.49)
's' and 'S' are special suffixes representing sectors and are always 512 bytes,
regardless of whether you're using powers of 1000 or 1024.
2009-09-28 16:36:03 +00:00
Alasdair Kergon
95eaa68309 Add global/si_unit_consistency to enable cleaned-up use of units in output.
Add configure --enable-units-compat to set si_unit_consistency off by default.

Use standard output units for 'PE Size' and 'Stripe size' in pv/lvdisplay.
2009-09-28 16:23:44 +00:00
Peter Rajnoha
96e46b8edb Use the same default umask for /dev dirs (DM_DEV_DIR_UMASK). 2009-09-25 11:58:00 +00:00
Dave Wysochanski
68fac97a07 Add vg_is_resizeable() and cleanup references.
Clean up VG_RESIZEABLE flag by creating vg_is_resizeable().
Update comment - we no longer have ALLOW_RESIZEABLE.
Also use vg_is_exported() in one place missed by earlier patch.
Should be no functional change.
2009-09-15 18:35:13 +00:00
Alasdair Kergon
663bf8f7f6 pre-release cleanup 2009-09-15 13:49:10 +00:00
Alasdair Kergon
90c8088760 More cmirror makefile fixes from Fabio. 2009-09-14 22:57:46 +00:00
Alasdair Kergon
651ff9b328 Add lots of missing stack debug messages to tools.
Make readonly locking available as locking type 4.
Fix readonly locking to permit writeable global locks (for vgscan). (2.02.49)
2009-09-14 22:47:49 +00:00
Dave Wysochanski
905240f91d Use vg_is_exported(vg) macro everywhere.
This patch is all just cleanup and no other patch depends on it.
Replace explicit dereference and check with vg_is_exported().
Update a few copyrights and remove unnecessary whitespace.
Should be no functional change.
2009-09-14 19:44:15 +00:00
Dave Wysochanski
fca434258a Add most relevant vg_attr fields as lvm2app 'get' functions.
Of the vgs field vg_attr, a few of the most likely to be used attributes
are clustered, exported, and partial.  This patch adds the following 3
functions:
uint64_t lvm_vg_is_clustered(const vg_t vg)
uint64_t lvm_vg_is_exported(const vg_t vg)
uint64_t lvm_vg_is_partial(const vg_t vg)
2009-09-14 19:43:11 +00:00
Dave Wysochanski
8c7946664c Add max_pv and max_lv vg 'get' lvm2app exports. 2009-09-14 15:45:23 +00:00
Dave Wysochanski
43a1ea4e2f Update vg_remove_single_* functions to use the removed_pvs list.
Now that we've split vg_remove_single into two routines, in the first routine
that only manipulates memory, we move the PVs from the vg->pvs list to the
vg->removed_pvs list.  Then later, we iterate through this list to write the
removed PVs to disk, which removes them from the volume group and places them
into the internal ORPHAN VG.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-09-02 21:39:49 +00:00
Dave Wysochanski
d50795ed09 Split vg_remove_single into 2 functions - the second part commits to disk.
Split vg_remove_single into vg_remove_check (mandatory checks before
vgremove) and vg_remove (do actual remove by committing to disk).

In liblvm, we'd like to provide an consistent API that allows multiple
changes in memory, then let lvm_vg_write() control the commit to disk.  In
some cases (for example, lvresize calls fsadm) this may not be possible.
However, since we are using an object model and dividing things into small
operations, the most logical model seems to be the lvm_vg_write model, and
handling the special cases as they arrive.  So as best as possible
we move towards this end.

A possible optimization would be to consolidate vg_remove (committing)
code with vgreduce code.  A second possible optimization is making vgreduce
of the last device equivalent to vgremove.  Today, lvm_vg_reduce fails if
vgreduce is called with the last device, but from an object model perspective
we could view this as equivalent to vgremove and allow it.  My gut feel is
we do not want to do this though.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-09-02 21:39:29 +00:00
Dave Wysochanski
940077d030 Rename internal library function vg_remove to vg_remove_mdas.
Later patches should consolidate the vgremove / vgreduce functions but for
now let's clarify what vg_remove actually does by changing the name.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-09-02 21:39:07 +00:00
Dave Wysochanski
3de6df8410 Enforce an alphabetical lock ordering for vgname locks.
Add a new constraint that vgname locks must be obtained in
alphabetical order.  At this point, we have test coverage for
the 3 commands affected - vgsplit, vgmerge, and vgrename.
Tests have been updated to cover these commands.
Going forward any command or library call that must obtain
more than one vgname lock must do so in alphabetical order.
Future patches will update lvm2app to enforce this ordering.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-09-02 21:34:11 +00:00
Petr Rockai
74aa6b5620 Implement write lock prioritisation for file locking and make it default. 2009-09-02 14:47:39 +00:00
Alasdair Kergon
66fd45290c change clogd to cmirrord
make pidfile locn configurable
2009-08-28 20:51:40 +00:00
Alasdair Kergon
a946372e50 Rewrite clvmd configuration code. 2009-08-28 19:22:05 +00:00
Milan Broz
c2d4398d47 Fix uuid warning in pvcreate to use terminated (and dash formatted) UUID string.
# pvcreate -u udwxr7-BoKY-EeKM-r033-xK6o-4og7-F13sGi /dev/sdc
   uuid udwxr7BoKYEeKMr033xK6o4og7F13sGi|��� already in use on "/dev/sdb1"
 is now
# pvcreate -u udwxr7-BoKY-EeKM-r033-xK6o-4og7-F13sGi /dev/sdc
   uuid udwxr7-BoKY-EeKM-r033-xK6o-4og7-F13sGi already in use on "/dev/sdb1"
2009-08-20 07:03:02 +00:00
Mike Snitzer
3d37e976bf Fix pvcreate on a partition (regressed in 2.02.51).
Eliminate busy loop during pvcreate of a "normal" partition.
_md_sysfs_attribute_snprintf() would busy loop if the device it was
given was not a blkext-based MD partition.

Rather than being cute with a busy-loop prone 'goto check_md_major' in
_md_sysfs_attribute_snprintf(): explicitly check if the provided device
is a blkext-based partition (blkext_major()); and then check that the
get_primary_dev() determined parent is an MD device (md_major()).
2009-08-19 15:34:33 +00:00
Jonathan Earl Brassow
03c65b7ade mirror table generating code: Properly handle 'block_on_errors' and 'cluster' features
The device-mapper mirror CTR table has been changing over time.  This has
now been corrected to handle the old and new methods for invoking the
'block_on_errors' and 'cluster' features.  (The code that does this was
accidentally committed in the previous check-in.  This check-in finishes
the job.)
2009-08-13 19:36:04 +00:00
Petr Rockai
5d5e2bf8f6 Refactor file locking, lifting the flock wrapper code into separate
functions. Also fixes a bug, where a nonblocking lock could, in certain race
situations, succeed without actually obtaining the lock.
2009-08-13 13:23:51 +00:00
Dave Wysochanski
b521cadd66 Remove useless _pv_write wrapper. 2009-08-10 17:15:01 +00:00
Peter Rajnoha
56aba8dc9d Forgotten '%s' in one of _mk_link warning messages. 2009-08-05 09:12:44 +00:00
Alasdair Kergon
a83b7adc28 detect udev mk_link problems 2009-08-04 21:44:20 +00:00
Alasdair Kergon
cf8235e0aa Add activation/udev_sync to lvm.conf. 2009-08-04 15:36:13 +00:00
Alasdair Kergon
2ad32d9518 Add warnings to check udev did what it was meant to. 2009-08-03 18:31:53 +00:00
Alasdair Kergon
aaa01e3488 Only create LV symlinks on ACTIVATE not PRELOAD.
(This is the udev behaviour - but does this change break anything?)
2009-08-03 18:09:25 +00:00
Alasdair Kergon
a74be32bf6 Manage without dm_udev_cleanup? 2009-08-03 18:01:45 +00:00
Alasdair Kergon
f86117e3d5 cleanup some ignored return values & 'stack's 2009-08-03 11:20:15 +00:00
Petr Rockai
0e867038da Allow LV suspend while --ignorelockingfailure is in force. 2009-08-02 21:03:09 +00:00
Mike Snitzer
098c16c9df Fix error handling of device-related stat() calls to be ENOENT aware.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-08-01 17:14:52 +00:00
Mike Snitzer
e92d56a94d Retrieve MD sysfs attributes for MD partitions
Rename private _primary_dev() to a public get_primary_dev() and reuse it
to allow retrieval of the MD sysfs attributes (raid level, etc) for MD
partitions.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-08-01 17:11:02 +00:00
Mike Snitzer
bb2a46b218 Improve ability to lookup primary device associated with a partition
Improve lib/device/device.c:_primary_dev()'s ability to look up the
primary device associated with all partitions; including blkext
(e.g. partitions directly on MD).  The same will also work for obscure
sysfs paths; e.g.: paths with mangled names like the HP cciss driver
uses: /sys/block/cciss!c0d0/cciss!c0d0p1/

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-08-01 17:09:48 +00:00
Mike Snitzer
2aabcc1c1c Add devices/data_alignment_detection to lvm.conf.
Adds 'data_alignment_detection' config option to the devices section of
lvm.conf.  If your kernel provides topology information in sysfs (linux
>= 2.6.31) for the Physical Volume, the start of data area will be
aligned on a multiple of the ’minimum_io_size’ or ’optimal_io_size’
exposed in sysfs.

minimum_io_size is used if optimal_io_size is undefined (0).  If both
md_chunk_alignment and data_alignment_detection are enabled the result
of data_alignment_detection is used.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-08-01 17:08:43 +00:00
Mike Snitzer
57b660356e Add devices/data_alignment_offset_detection to lvm.conf.
If the pvcreate --dataalignmentoffset option is not specified the start
of a PV's aligned data area will be shifted by the associated
'alignment_offset' exposed in sysfs (unless
devices/data_alignment_offset_detection is disabled in lvm.conf).

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-08-01 17:07:36 +00:00
Alasdair Kergon
bd90c6b2c2 Set cookies in activation code and wait for udev to complete processing. 2009-07-31 18:30:31 +00:00
Mike Snitzer
9607eba5c2 Fix compile warnings from recently added log_very_verbose() in _text_pv_write() 2009-07-31 14:23:06 +00:00
Alasdair Kergon
5d518f1f18 Prepare for udev synchronisation code. (options don't work yet) 2009-07-31 11:49:53 +00:00
Mike Snitzer
377b6a5843 Disable the "new pe_start policy"
Documented which use-cases force the reinstatement of the nuanced
handling of pe_start.  As soon as orphan PVs are eliminated much of this
will no longer be a concern ('preserve_pe_start' can be reenabled in
.pv_setup).

Added defensive 'if (pv->pe_align)' check in _text_pv_write()'s pe_start
loop.
2009-07-30 21:15:17 +00:00
Mike Snitzer
733bd656b2 Revert 'preserve_pe_start' related code in _text_pv_setup
If pv_setup was given a non-zero pe_start it would short-circuit
establishing a default pv->pe_align.  pv->pe_align=0 would result
in a divide by zero in _mda_setup().  'vgconvert -M2 $vgname' hit this.

.pv_write still properly preserves pe_start if it was supplied.
2009-07-30 18:40:22 +00:00
Mike Snitzer
04b2a4bdcf Add --dataalignmentoffset to pvcreate to shift start of aligned data area
Adds pe_align_offset to 'struct physical_volume'; is initialized with
set_pe_align_offset().  After pe_start is established pe_align_offset is
added to it.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-07-30 17:45:28 +00:00
Mike Snitzer
d01a37f597 Preserve pe_start in .pv_setup and .pv_write if pe_start was supplied.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-07-30 17:42:33 +00:00
Mike Snitzer
c8a4e489c1 Remove legacy support for preserving pe_start if a PV already has data
areas.

This preserved pe_start would quickly be readjusted to follow the first
mda anyway.  An example use-case that hit this code path is: running
pvcreate on an already existing PV _without_ a preceeding pvremove.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-07-30 17:41:01 +00:00
Mike Snitzer
ad273af9c7 Fix _mda_setup() to not check first mda's size before pe_align rounding.
Without this fix rounding the end of the first mda to a pe_align
boundary could silently exceed the disk_size.

Final 'if (start1 + mda_size1 > disk_size)' block serves as a safety
net.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-07-30 17:19:31 +00:00
Mike Snitzer
2143b169b1 Formalize pe_start policy as split between .pv_setup and .pv_write.
Document existing pe_start policy.
Fix issue in _text_pv_setup() where existing pe_start case could have
the pv->pe_start set to pv->pe_align even though pe_start shouldn't ever
change.

vgconvert and pvcreate have a facility to preserve the existing start
of the on-disk data extents, known as pe_start.
They indicate this by passing the existing value to the pvsetup function
which must preserve it.

This patch avoids one particular case where the value could get
changed incorrectly now that the alignment settings are configurable.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
2009-07-30 17:18:03 +00:00
Alasdair Kergon
9e813cc93b Remove pv_t, vg_t & lv_t handles from lib. Only liblvm uses them.
Rename lvm.h to lvm2app.h for now.
2009-07-29 13:26:01 +00:00
Alasdair Kergon
8762493eb8 \n 2009-07-28 20:41:41 +00:00
Dave Wysochanski
afcd9399a9 Add an open_mode to the vg struct for liblvm - enforce read / write semantics.
For now, a simple way to enforce the read/write semantics is to just save the
open mode of the VG.  If the caller uses lvm_vg_create, the mode is write.
The caller using lvm_vg_open can use either read or write to open the VG.
Once we have this, we enforce the permissions on each API call and don't allow
a caller to modify a VG that has not been opened properly.

This may be better combined with the locking mode, but I view that as future
cleanup, past this initial release.  The intial release should enforce the
basic object semantics though, as described in the lvm.h file.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-28 15:14:56 +00:00
Dave Wysochanski
9ac1af7160 Add lvm_vg_get_seqno, updating lvm.h and unit test.
Adding the ability to get the seqno is important for an application to
determine if something has changed in a VG.  Otherwise, the only way to
know is to open the VG with write permission and hold the handle.
2009-07-28 13:17:04 +00:00
Dave Wysochanski
9085c301e0 Rename _override_settings into override_config_tree_from_string and move.
Move _override_settings from tools/lvmcmdline.c into lib/config/config.c
and export so we can re-use in liblvm.
2009-07-27 21:01:56 +00:00
Dave Wysochanski
1bd72d90a4 Add vg_reduce to metadata.c and metadata-exported.h
This function behaves a little bit different than vg_reduce_single, because
it allowes to remove even the latest pv. This has been done to be consistent
to lvm_vg_create, which creates an empty vg.

removed_pvs has been added to the volume_group struct. vg_reduce adds remove
pvs to this list to be able to commit the changes for the pvs in lvm_vg_comm
in liblvm2app.

Initialize removed_pvs list in format-specific volume_group constructors.
Ideally, we should have a base constructor here that initializes the general
non-format specific members of struct volume_group.  But until then, there
are multiple places to initialize these members.  Maybe a better patch would
be a base constructor patch for struct volume_group.  That is more work
though.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Thomas Woerner <twoerner@redhat.com>


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-27 17:43:39 +00:00
Dave Wysochanski
0589e19fd7 Update error return and comments for lvm_list_vg_names/uuids.
The two liblvm functions that return a list of vgnames and vguuids use
cmd->mem to allocate the list.  Make it clear to the caller that this
memory will be freed when the LVM handle is freed.

Clean up and clarify the return value of the functions.  In the
case of a memory allocation error, add a couple log_errnos to the internal
code, and make it clear that memory allocation returns a NULL pointer.
If there are no VGs in the system, the list returned is an empty list.

Make a note of the fact that currently we return hidden VG names, how
these can be detected (always start with "#"), and that they should
not be used.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-27 11:00:17 +00:00
Dave Wysochanski
c8fb043a01 Update display.c to use vg_free(vg) instead of duplicating the calculation.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-27 10:18:31 +00:00
Dave Wysochanski
8b3755a679 Use vg_size in vg_set_extent_size.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 12:41:36 +00:00
Dave Wysochanski
483a7cb6d5 Refactor a few report field calculations into separate functions.
For liblvm 'get' functions, we should share code with the reporting functions.
This means we need common code to return the values for the fields.
In this patch we refactor a few of the fields needed in liblvm.
Unfortunately, for the simple fields that do derefernces of structure
members (for example, vg_extent_count), we cannot call the common function
from the reporting infrastructure without more refactoring.  The reason is
that the dereference of the simple fields is done deep inside the reporting
code (to get the generic "data" pointer), and the display function is a
generic 'size32' function.  We can fix these issues later with more
refactoring.

Should be no functional change and the testsuite should cover any possible
regressions.  The only fields in the report affected by this patch are:
vg_size, vg_free, and pv_mda_count.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 12:41:09 +00:00
Dave Wysochanski
8c38c9642c Rename vg_size to vgsize to avoid naming conflicts.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 12:40:27 +00:00
Dave Wysochanski
9963d0710e Move extents_from_size from lvcreate into internal library so we can reuse.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 02:34:09 +00:00
Dave Wysochanski
c42b235610 Move _lvcreate into the internal library and rename to lv_create_single.
After some refactorings, we can now move the bulk of _lvcreate into the
internal library, and we can call from liblvm.  In the future, we should
refactor lv_create_single further, probably by segtype, to reduce the
size of struct lvcreate_params.  For now this is a reasonable refactor
and allows us to re-use the function from liblvm.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 02:33:35 +00:00
Dave Wysochanski
c9b4604ba6 Remove use of void * from pvcreate_single.
We should use struct pvcreate_params to utilize compiler typechecking.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 02:02:22 +00:00
Dave Wysochanski
aa496e4c23 Move ORPHAN_VG lock outside pvcreate_single.
The implicit pvcreate require either moving the ORPHAN_VG lock outside
pvcreate_single or somehow having the function know or detect whether
the ORPHAN_VG lock is already held.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 01:54:20 +00:00
Dave Wysochanski
89777f9cec Change pvcreate_single to return pv_t and update function description.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 01:53:57 +00:00
Dave Wysochanski
9d5a318ac6 Allow pvcreate_single to be called with NULL for default pvcreate params.
Passing NULL for pvcreate parameters gives you default parameters for
pvcreate_single.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 01:53:30 +00:00
Dave Wysochanski
d4b6a8aa2a Move bulk of pvcreate logic into library.
In preparation for implicit pvcreate during vgcreate / vgextend,
move bulk of pvcreate logic inside library.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 01:53:09 +00:00
Dave Wysochanski
beeba64080 Remove unneeded pv_create wrapper function.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-26 01:52:19 +00:00
Alasdair Kergon
1cc59fa4ac Add global/wait_for_locks to lvm.conf so blocking on locks can be disabled. 2009-07-24 23:28:55 +00:00
Alasdair Kergon
2918b433a3 remove no-longer-needed NONBLOCK 2009-07-24 18:26:42 +00:00
Alasdair Kergon
c07d773e67 All LV locks are non-blocking so remove LCK_NONBLOCK from separate macros. 2009-07-24 18:15:06 +00:00
Dave Wysochanski
fce6fb489f Eliminate compile warning introduced by previous commit. 2009-07-24 15:15:26 +00:00
Dave Wysochanski
e6923120b9 Revert previous patch that moved VG_ORPHAN lock inside vg_extend.
We must hold the VG_ORPHAN lock until we commit to disk.  Otherwise,
we risk a race condition on vgcreate / vgextend.  Reverts the following
commit:

commit 72a41480ba
Author: Dave Wysochanski <dwysocha@redhat.com>
Date:   Fri Jul 10 20:09:21 2009 +0000

    Move orphan lock obtain/release inside vg_extend().

    With this change we now have vgcreate/vgextend liblvm functions.
    Note that this changes the lock order of the following functions as the
    orphan lock is now obtained first.  With our policy of non-blocking
    second locks, this should not be a problem.

    Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-24 15:01:43 +00:00
Alasdair Kergon
bf45614685 Add an API version number, LVM_LIBAPI, to the VERSION string. 2009-07-22 20:01:28 +00:00
Mikulas Patocka
df4b9706da Pass struct cmd_context as a first argument to init_multiple_segtypes.
Remove redundant assignment seglib.cmd = cmd (done already at the beginning
of the function).

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
2009-07-21 20:00:02 +00:00
Mike Snitzer
69c7e1f754 Cast MINOR() in _md_sysfs_attribute_snprintf()'s dm_snprintf() call. 2009-07-20 18:44:13 +00:00
Mike Snitzer
6111e048a3 Cast MAJOR() and MINOR() to int when used with "%d" in dm_snprintf() call.
Fixes SEGV in _md_sysfs_attribute_snprintf() on 32-bit systems.
2009-07-20 18:33:16 +00:00
Dave Wysochanski
2206eb2409 Remove 'is already' message from vg_set_* functions.
These messages are unnecessary in the set functions.  We check for this
condition and print a message in the vgchange tool but not the library
functions.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-16 20:18:16 +00:00
Alasdair Kergon
c791c54e5b Fix so only log_error and log_fatal set EUNCLASSIFIED. 2009-07-16 13:13:33 +00:00
Dave Wysochanski
e0bd7c7645 Remove extraneous messages for extent_size and alloc_policy upon vgcreate.
When converting to the new liblvm functions, the vgcreate code path
changed to create a new vg, then set values.  As a result of this
change, and the fact that we give a user a message if they try to
set the same value of a VG attribute (extent_size, alloc_policy, etc),
you'll see these 2 extraneous "is already" messages with vgcreate:
tools/lvm vgcreate vg2 /dev/loop2
  Physical extent size of VG vg2 is already 4.00 MB
  Volume group allocation policy is already normal
  Volume group "vg2" successfully created

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-16 03:25:26 +00:00
Dave Wysochanski
a0b1b1872e Change default errno value to 0 (no error) and add prototypes in lvm.h
Since we are using errno values, we should use '0' as a default value
which indicates a non-error, rather than defining some made-up default
value that is not defined in errno.  If we need to deviate from errno
values, this will most likely indicate a flaw in our design.

Add prototypes for lvm_errno and lvm_errmsg inside lvm.h and provide
a basic description of their function.  This fixes a couple compile
warnings.


Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-16 03:07:45 +00:00
Alasdair Kergon
9fac443591 Add log_errno to set a specific errno and replace log_error in due course. 2009-07-16 00:52:06 +00:00
Alasdair Kergon
d917192f00 Add lvm_errno and lvm_errmsg to liblvm to obtain failure information.
Change create_toolcontext to still return an object if it fails part-way.
Add EUNCLASSIFIED (-1) as the default LVM errno code.
2009-07-16 00:36:59 +00:00
Alasdair Kergon
d614646157 Store any errno and error messages issued while processing each command.
(Enabled by default while we test it, but in due course we'll only store
the error messages when we need to.)
2009-07-15 23:57:54 +00:00
Alasdair Kergon
b8f47d5f69 Use log_error macro consistently throughout in place of log_err. 2009-07-15 20:02:46 +00:00
Alasdair Kergon
99a5d8a9c4 Revert broken commit:
2009-07-15 06:10:51  Un-export vg_read_internal.

lvm-functions.c:774: warning: implicit declaration of function 'vg_read_internal'
2009-07-15 17:26:26 +00:00
Petr Rockai
746bb69067 Fix warning. 2009-07-15 06:11:25 +00:00
Petr Rockai
0d7bacf56e Un-export vg_read_internal. 2009-07-15 06:10:51 +00:00
Petr Rockai
ee2e742ae3 Fix bad prototype from previous checkin. 2009-07-15 05:57:11 +00:00
Petr Rockai
21a98eda88 Port process_each_pv to new vg_read. 2009-07-15 05:50:22 +00:00
Petr Rockai
6ee7d2aa53 Remove lockingfailed().
We provide a lock type that behaves like no_locking, but is not
  clustered. Moreover, it also forbids any write locks. This magically (and
  consistently) prevents use of clustered VGs, or changing local VGs with
  --ignorelockingfailure. As a bonus, we can remove the special hacks in a few
  places. Of course, people looking for trouble can always set their locking_type
  to 0 to override.
2009-07-15 05:49:47 +00:00
Petr Rockai
19089ba331 Refuse to open VG with MISSING_PVs for update unless handles_missing_pvs is set. 2009-07-15 05:47:55 +00:00
Milan Broz
8d9fb97582 Enable use of new multi-segment registration for static registration too.
so it allows this use:

#ifdef MYNEWSEG_INTERNAL
        if (!init_mynewseg_segtypes(&seglib))
                        return 0;
#endif
2009-07-14 12:17:14 +00:00
Alasdair Kergon
7beb03dd2a Exclude VG_GLOBAL from vg_write_lock_held so scans open devs read-only again. (mbroz) 2009-07-14 11:01:26 +00:00
Dave Wysochanski
39d6ccdfc7 Define handles to liblvm objects for pv, vg, lv, lvseg, pvseg.
Define the 5 main liblvm objects to be the pv, vg, lv, lvseg, and pvseg.
We need handles defined to all these objects in order for liblvm to be
equivalent to the reporting commands pvs, vgs, and lvs.

- move vg_t, lv_t, and pv_t from metadata-exported.h into lvm.h
- move lv_segment and pv_segment forward declarations into lvm.h
- add lvseg_t and pvseg_t to lvm.h

NOTE: We currently have an inconsistency in handle definitions.
lvm_t is defined as a pointer, while these other handles are just
structures.  We should pick one scheme and be consistent - perhaps
define all handles as pointers (this is what I've seen elsewhere).

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
2009-07-14 03:00:30 +00:00
Dave Wysochanski
cec2a2dacc Remove READ_REQUIRE_RESIZEABLE flag from vg_read() interface - no users.
The checks for RESIZEABLE_VG should now be inside the various functions that
have to do such operations.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
2009-07-14 02:19:19 +00:00
Dave Wysochanski
ffc12b3fc1 Remove READ_REQUIRE_RESIZEABLE flag from vgsplit.
Remove READ_REQUIRE_RESIZEABLE flag from vgsplit similar to the removal from
vgextend.  Move the check inside the functions that actually move pvs from
one vg structure to another.  Should be no functional change.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
2009-07-14 02:16:05 +00:00
Dave Wysochanski
6452d4ae9d Refactor vgsplit - move move_pvs_used_by_lv and move_pv inside library.
In the future we may export these functions or something like them in liblvm
For now this helps in cleaning up the checks for RESIZEABLE since we can
use the internal library function vg_bad_status_bits.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
2009-07-14 02:15:21 +00:00
Dave Wysochanski
5b57e82508 Remove READ_REQUIRE_RESIZEABLE from vgextend by moving check inside vg_extend.
Move the check for the RESIZEABLE flag inside the vg_extend function.
When we consolidated the vg locking, reading, and status flag checking,
we tied the check for the RESIZEABLE flag to the vg_read() call.  The problem
with this is you cannot know what other APIs the application my or may not
call after a vg_read() call.  Thus the READ_REQUIRE_RESIZEABLE flag is not
really ideal - ideally we should be checking for this flag on a specific
operation, not inside the vg_read() call.  This patch moves one check inside
the library.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Alasdair G Kergon <agk@redhat.com>
2009-07-14 02:14:04 +00:00
Mikulas Patocka
3395d72881 Change exit() to _exit() in the child process. exit flushes stdio file buffers,
_exit doesn't. If there were some open files, an error in exec and subsequent
exit() would cause the buffers to be flushed twice.

Example:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{
	printf("buu");
	if (!fork()) {
		execl("/bin/true-not-exists", "/bin/true", NULL);
		exit(1);
	}
	wait(NULL);
	return 0;
}

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com

---
 daemons/dmeventd/libdevmapper-event.c |    2 +-
 lib/misc/lvm-exec.c                   |    2 +-
 test/harness.c                        |    3 ++-
 tools/dmsetup.c                       |    2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
2009-07-13 21:26:41 +00:00
Mikulas Patocka
f4b2b84904 Suppress warning on 64-bit big-endian computers (Sparc 64).
xlate64 produces unsigned long long type, but PRIu64 is defined
to accept argument unsigned long type (on 64-bit machines).

On existing machines, both types have the same size, so it works,
but it is still wrong and produces a warning.

Fix it by using a cast to uint64_t --- according to the standard,
PRIu64 argument matches type uint64_t.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
2009-07-13 21:23:48 +00:00
Alasdair Kergon
7f355587f5 Make cmd->cmd_line const. 2009-07-13 19:49:48 +00:00
Dave Wysochanski
85d2f1811a Remove unused code vg_lock_and_read() and related flags.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-10 21:19:37 +00:00
Dave Wysochanski
7fa91ec044 Move orphan lock obtain/release inside vg_extend().
With this change we now have vgcreate/vgextend liblvm functions.
Note that this changes the lock order of the following functions as the
orphan lock is now obtained first.  With our policy of non-blocking
second locks, this should not be a problem.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-10 20:09:21 +00:00
Dave Wysochanski
03660b3045 Move orphan lock inside vg_remove_single.
Move the vg orphan lock inside vg_remove_single, now a complete liblvm
function.  Note that this changes the order of the locks - originally
VG_ORPHAN was obtained first, then the vgname lock.  With the current
policy of non-blocking second locks, this could mean we get a failure
obtaining the orphan lock.  In the case of a vg with lvs being removed,
this could result in the lvs being removed but not the vg.  Such a
scenario could have happened prior though with a different failure.
Other tools were examined for side-effects, and no major problems
were noted.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-10 20:08:37 +00:00
Dave Wysochanski
42ae96fa3d Remove force parameter from vg_remove_single, now the liblvm function.
Move check for active LVs outside of library function.  The vgremove
liblvm function function will fail if there are active LVs.  It will
be the application's responsibility to check this condition and remove
the LVs individually before calling vgremove.  Note also that we've
duplicated the EXPORTED_VG check in vgremove_single (tools) and
vg_remove_single (library).  Duplication seemed the only option here
since we don't want to do the automatic removal of LVs (in the tools)
if the vg is exported, and we still need to protect the library call
from removal if the vg is exported.

We still need to deal with the ORPHAN lock but vg_remove_single is now
very close to our liblvm function.

TODO: Refactor lvremove in a similar way.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-10 20:07:02 +00:00
Dave Wysochanski
a6ad9c6166 Remove unnecessary parameters from vg_remove_single().
Use vg_t instead of struct volume_group.
Should be no functional change.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-10 20:05:29 +00:00
Alasdair Kergon
a9cb6969b0 Add dm_log_with_errno and dm_log_with_errno_init, deprecating the old
Change plog to use dm_log_with_errno unless deprecated dm_log_init was used.
Rename plog macro to LOG_LINE and use in dm_dump_memory_debug.
2009-07-10 09:59:37 +00:00
Mike Snitzer
f1c90ec108 Check MD devices for a partition table during device scan. 2009-07-09 22:50:45 +00:00
Mike Snitzer
08f0d365fd Add extended device (blkext) and MD partition (mdp) types to filters.
Both types were added with a 'max_partitions' of 1 because these devices
are _not_ partitionable (they are the partitions).
2009-07-09 22:34:02 +00:00
Milan Broz
d09a7dfc6e Fix and precise metadata read errors for segment areas. 2009-07-09 11:29:41 +00:00
Milan Broz
25497e2fa5 Fix confusing metadata syntax error messages.
If there is syntax error in metadata, it now prints messages
like:
  Couldn't read 'start_extent' for segment 'extent_count'.
  Couldn't read all logical volumes for volume group vg_test.

The segment specification is wrong and confusing.

Patch fixes it by introducing "parent" member in config_node which
points to parent section and config_parent_name function, which
provides pointer to node section name.

Also it adds several LV references where possible.
2009-07-09 11:29:00 +00:00
Milan Broz
7fdf112457 Fix segment import functions to print segment name and logical volume name. 2009-07-09 11:28:09 +00:00
Dave Wysochanski
10a27bdfb6 Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function.  Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now.  Needs some cleanup though and I've
noted "FIXME" in the code.

Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring.  We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky.  Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one.  Now vg_create()
calls vg_lock_newname, so we first try to create the VG.  If this
fails with FAILED_EXIST, we can then do the vg_read.  If the
create succeeds, we check the input parameters and set any new
values on the VG.

TODO in future patches:
1. The VG_ORPHAN lock needs some thought.  We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend).  Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go.  I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
Dave Wysochanski
5d623bde94 Add vg_set_alloc_policy() liblvm function and move vgchange logic inside.
NOTE: vg_set_alloc_policy() returns success if you try to set a value that
is already stored.  The behavior of vgchange is the same though - it fails.
There is a fixme noted in the code about this inconsistency, which should
be resolved if possible.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:08:54 +00:00
Dave Wysochanski
dba458ae9a Add vg_set_max_pv() liblvm function and move vgchange logic inside.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:07:47 +00:00
Dave Wysochanski
a88bfbcb13 Add vg_set_max_lv() liblvm function and move vgchange logic inside.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:06:00 +00:00
Dave Wysochanski
3f6a21ead4 Rename vg_change_pesize to vg_set_extent_size and use vg_t.
In liblvm, we will reserve the word 'change' to mean an API that
both sets one or more values, and commits to disk.  This will be
consistent with the LVM commandline.  The existing vg_change_pesize()
function does not commit to disk, but just changes the extent_size
and ensures all internal structures are updated.  This logic should
be contained in a function that sets the value.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:04:52 +00:00
Dave Wysochanski
b1278ba1b8 Remove unused 'cmd' from vg_change_pesize().
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:03:37 +00:00
Dave Wysochanski
de5dfec56b Update vg_change_pesize() to contain all validity checks.
It would be nice to have one function that does all the validation
and setting of the VG's pesize.  However, currently some checks
are in the higher-level function _vgchange_pesize(), and some
checks are in the lower function vg_change_pesize().
This patch moves most of the higher-level checks inside
vg_change_pesize.  In one case a failure return code is
changed from ECMD_FAILED to EINVALID_CMD_LINE.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:02:15 +00:00
Dave Wysochanski
9af5a142d0 Add defines for default vgcreate parameters. 2009-07-09 10:00:36 +00:00
Dave Wysochanski
6e7d597a50 Make exit paths more robust when some init function fails.
Author: Dave Wysochanski <dwysocha@redhat.com>
2009-07-08 22:18:32 +00:00
Dave Wysochanski
f882633886 Fix segfault in persistent_filter_dump() if lvm init fails.
Just return_0 in persistent_filter_dump() if passed a NULL filter;
2009-07-08 18:13:32 +00:00
Dave Wysochanski
71e41d9139 Make destroy_toolcontext() better able to handle NULL pointers.
Part of twoerner's log_error() patches.

Signed-off-by: Thomas Woerner <twoerner@redhat.com>
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-08 18:12:08 +00:00
Dave Wysochanski
4c35d6dee6 Remove unneeded LOCK_NONBLOCKING from vg_read() API.
Remove unneeded LOCK_NONBLOCKING from vg_read() API and tools that
use it.  We no longer need this flag anywhere since we now automatically
set LCK_NONBLOCK inside lock_vol() if vgs_locked().
For further details, see:
commit d52b3fd3fe
Author: Dave Wysochanski <dwysocha@redhat.com>
Date:   Wed May 13 13:02:52 2009 +0000

    Remove NON_BLOCKING lock flag from tools and set a policy to auto-set.

    As a simplification to the tools and further liblvm, this patch pushes
    the setting of NON_BLOCKING lock flag inside the lock_vol() call.
    The policy we set is if any existing VGs are currently locked, we
    set the NON_BLOCKING flag.

At some point it may make sense to add this flag back if we get an
RFE from a liblvm user, but for now let's keep it as simple as
possible.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-08 14:33:17 +00:00
Dave Wysochanski
b251e09035 Remove READ_CHECK_EXISTENCE and vg_might_exist().
Remove READ_CHECK_EXISTENCE and vg_might_exist().
This flag and API is no longer used now that we have a separate
API to check for existence.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-08 14:31:17 +00:00
Dave Wysochanski
cd082bbea7 Remove unneeded LOCK_KEEP from vg_read() interface.
Remove unneeded LOCK_KEEP from vg_read() interface.
Update comment to clarify cases where _vg_lock_and_read() may return
with an error but the lock held.  Would be nice to make the vg_read()
interface consistent with regards to lock held and error behavior.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-08 14:28:30 +00:00
Alasdair Kergon
dd1d42d5d0 Permit several segment types to be registered by a single shared object. 2009-07-08 12:36:01 +00:00
Mike Snitzer
3d425215a8 Continue to make --units and --size consistent (in code and man pages):
Update units_to_bytes() to support (S)ectors: 500 bytes.
- 500 byte (S)ectors is of questionable value but it adds to consistency
  if a user happens to use --units S.  This seems better than an error.

Updated test/t-covercmd.sh to test --units [hS]

Document the units that can be displayed via --units uniformly.
- (p)etabytes and (e)xabytes were missing in pvs, vgs and lvs man pages.

Made lvreduce man page "... in units of megabytes." consistent (with the
lvextend and lvresize man pages).
2009-07-07 19:28:57 +00:00
Mike Snitzer
bb6a3a9608 Use the MD device's stripe-width, instead of chunk_size, to align the
data blocks of a Physical Volume that is placed directly upon an MD
device.
2009-07-06 19:04:24 +00:00
Dave Wysochanski
b91eb158d4 Don't segfault in vg_release when vg->cmd is NULL.
Sun May  3 13:06:14 CEST 2009  Petr Rockai <me@mornfall.net>
  * Don't segfault in vg_release when vg->cmd is NULL.


Author: Petr Rockai <prockai@redhat.com>
Committer: Dave Wysochanski <dwysocha@redhat.com>
2009-07-01 17:03:38 +00:00
Dave Wysochanski
13e8c7e434 Rework the toollib interface (process_each_*) on top of new vg_read.
Sun May  3 12:32:30 CEST 2009  Petr Rockai <me@mornfall.net>
  * Rework the toollib interface (process_each_*) on top of new vg_read.

Rebased 6/26/09 by Dave W.
- Add skipping message to process_each_lv
- Remove inconsistent_t.
2009-07-01 17:00:50 +00:00
Alasdair Kergon
476d463348 pre-release tidy up 2009-06-30 18:39:31 +00:00
Milan Broz
6391d03f54 Fix backward compatibility for major:minor query.
Is an application uses query and set major:minor
to device, it should not fallback to default major by default.

Add new function whoich allows that (and use it in lvm2).
2009-06-17 20:55:24 +00:00
Milan Broz
be0938ad3c Properly destroy toolcontext.
(fixes previous commit)
2009-06-17 20:54:20 +00:00
Milan Broz
38ddfe7be5 Fix memory leaks in toolcontext error path.
E.g.
 # vgscan
  Parse error at byte 2360 (line 54): expected a value
  Failed to load config file /etc/lvm/lvm.conf
You have a memory leak (not released memory pool):
 [0x818c788] library (12 bytes)

...
2009-06-15 11:56:31 +00:00
Milan Broz
5cc66af8d6 Re-instate partial activation support in clustered mode. (mornfall) 2009-06-12 08:30:19 +00:00
Petr Rockai
11ee855e40 Allow metadata correction even when PVs are missing. 2009-06-10 20:17:32 +00:00
Dave Wysochanski
fe2b3ea0d4 In the new _vg_read_for_update(), we always do the check for CLUSTERED vg
status flag after reading the volume group.  Thus, no need to set the flag
in vg_read() or clear it later before calling _vg_bad_status_bits().

Also, add back in the !lockingfailed() as part of the CLUSTERED flag check.
It's unclear why it was removed when the check was moved from
_vg_bad_status_bits() to inside _vg_lock_and_read().
There was an open question about the last check in the 'if' stmt for
lockingfailed() with a previous patch submitted.  However, I would
defer that right now as it is a separate item and this patch should
be no functional change by including the !lockingfailed().

Petr acked this patch on 5/26 I just forgot to check it in.

Acked-by: Petr Rockai <prockai@redhat.com>
2009-06-10 16:14:40 +00:00
Dave Wysochanski
07b0c948ee Add vg_lock_newname() library function.
Various tools need to check for existence of a VG before doing something
(vgsplit, vgrename, vgcreate).  Currently we don't have an interface to
check for existence, but the existence check is part of the vg_read* call(s).
This patch is an attempt to pull out some of that functionality into a
separate function, and hopefully simplify our vg_read interface, and
move those patches along.

vg_lock_newname() is only concerned about checking whether a vg exists in
the system.  Unfortunately, we cannot just scan the system, but we must first
obtain a lock.  Since we are reserving a vgname, we take a WRITE lock on
the vgname.  Once obtained, we scan the system to ensure the name does
not exist.  The return codes and behavior is in the function header.
You might think of this function as similar to an open() call with
O_CREAT and O_EXCL flags (returns failure with -EEXIST if file already
exists).

NOTE: I think including the word "lock" in the function name is important,
as it clearly states the function obtains a lock and makes the code more
readable, especially when it comes to cleanup / unlocking.  The ultimate
function name is somewhat open for debate though so later we may rename.
2009-06-09 14:29:10 +00:00
Milan Broz
a908d0030c Suspend virtual origin before real snapshot.
Because preload of table for snapshot can produce snapshot
metadata (in kernel cow header) read.

Code should suspend origin first to avoid possible deadlock
when preloading (thus calling snapshot in-kernel constructor)
for origin with suspended cow device.

(fixes previous commit)
2009-06-06 16:37:15 +00:00
Milan Broz
66086ce962 Fix double releasing of vg when repairing of vg is requested.
Several commands calls process_each_vg() and in provided
callback it explicitly recovers VG if inconsistent.
(vgchange, vgconvert, vgscan)

It means that old VG is released and reread  but the function
above (process_one_vg) tries to unlock and release old VG.

Patch moves the repair logic into _process_one_vg() function.

It always tries to read vg (even inconsistent) and then decides
what to do according new defined parameter.

Also patch unifies inconsistent error messages.

The only slight change if for vgremove command, where
it now tries to repair VG before it removes if force arg is given.
(It works similar way before, just the order of operation changed).
2009-06-05 20:00:52 +00:00
Milan Broz
c26488d348 Use lvconvert --repair instead of vgreduce in mirror dmeventd DSO (mornfall)
Introduce lvconvert --use_policies (mornfall)
2009-06-04 12:01:15 +00:00
Milan Broz
b6deac338f Build shared parts with 'make' command (mpatocka)
When some parts of lvm are built as shared libraries (for example with
--with-snapshots=shared), the 'make' command does not build these parts.
The shared parts are built with 'make install' command.

This bug can be seen if you go to 'lib' subdirectory and type 'make'.
If you type 'make', the shared libraries are not built, if you type
'make all', the shared libraries are built.

The reason for the bug is the line $(SUBDIRS): $(LIB_STATIC)
If make is executed without any arguments, it makes the first target
in the Makefile. If the first target is '$(SUBDIRS): $(LIB_STATIC)',
it only builds static libraries.

This patch moves '$(SUBDIRS): $(LIB_STATIC)' after
include $(top_srcdir)/make.tmpl. make.tmpl contains the 'all' target
as its first target, so 'make' will be equivalent to 'make all' and
shared libraries will be build with 'make' command.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
2009-06-03 11:31:06 +00:00
Milan Broz
771e191e99 Fix rename of active snapshot with virtual origin.
Code must suspend/resume virtual origin too when renaming
snaphsot otherwise in kernel old name remains.
2009-06-01 15:55:06 +00:00
Milan Broz
31f55a07db Fix convert polling to ignore LV with different UUID.
When mirror convert polling is started (mainly as backgound process,
in lvchange -a y or in lvconvert itself) it tries to read VG
and LV identified by its name.

Unfortunatelly, the VG can have already different LV under the same name,
and various more or less funny things can happen (note that
_finish_lvconvert_mirror suspends the volume for example).

(the typical example is our testing script which continuously recreates
LVs under the same name in the same VG.)

This patch adds optional uuid parameter which helps to properly
select the monitoring object. For lvconvert polling it is set to LV UUID
and both _get_lvconvert_vg and _get_lvconvert_lv uses it to read proper VG/LV.

(In the pvmove case it is NULL, here we poll for physical volume name).
2009-06-01 14:43:27 +00:00
Milan Broz
59d06d4dc7 Fix log allocation segfault (fix previous commits).
If there is no free area for log, code should break the loop.
(Otherwise it uses uninitializes areas later.)

Easily reproducible using lvconvert --repair
 - kill device with log
 - run lvconvert --repair vg/lv (with no PV usable for log)
2009-06-01 14:23:38 +00:00
Milan Broz
c1fdeec999 Fix readahead calculation problems.
During vgreduce is failed mirror image replaced with error segment,
this segmant type has always area_count == 0.
Current code expects that there is at least one area with device,
patch fixes it by additional check (fixes segfault during vgreduce).

Also do not calculate readahead in every lv_info call, we only need
to cache PV readahead before activation calls which locks memory.
2009-06-01 12:43:31 +00:00
Alasdair Kergon
eca971ca6c Remove verbose 'visited' messages. 2009-05-30 01:54:29 +00:00