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

884 Commits

Author SHA1 Message Date
Peter Rajnoha
17f5531df0 Clean up internal mangling interface. 2012-03-05 12:40:34 +00:00
Zdenek Kabelac
462de06d96 Return success for deactivation of thin pool
if the thin_check fail on thin pool - still return successful deactivation,
since lvremove would currently fail.

TODO: find some way to not run check with lvremove.
2012-03-04 17:36:23 +00:00
Zdenek Kabelac
b3103ef328 Remove part of FIXME
(and reindent a code below)
2012-03-04 16:05:42 +00:00
Zdenek Kabelac
7162a25b0b Support 16GB for thin pool metadata
Add some hack math to allow 16GB devices to be passed as thinpool metadata.
Since kernel has put in limit to not allow which are just bigger then
some predefined constant in kernel but not matching 16GB so any device bigger
is rejected.

FIXME: Current code still might need more tweaks to be more generic.
2012-03-02 21:53:17 +00:00
Zdenek Kabelac
4bcaf8086e Purge remaining trim bits from code 2012-03-02 21:43:26 +00:00
Zdenek Kabelac
7e35dfff3d Added dm_tree_node_set_callback() for preload and deactivation hooks
Run users hook after preload for the node is finished,
or after the node has been deactivated.
2012-03-02 17:31:21 +00:00
Zdenek Kabelac
6a5706a3a5 Remove support for TRIM message
It's been unsupporte for now - and it's not going to be
implemented for thin pool kernel driver - so dropping
appearence of TRIM from libdm and lvm.
2012-03-02 13:26:08 +00:00
Petr Rockai
823268475c Use 64 bit integers whenever extracting numbers from daemon replies. 2012-03-01 19:54:53 +00:00
Zdenek Kabelac
d17cd1c385 Missed ; 2012-03-01 10:46:39 +00:00
Zdenek Kabelac
84e16ecdb5 Add cast for ptrdiff_t - cleanup gcc warning 2012-03-01 10:31:35 +00:00
Zdenek Kabelac
521ddeaecc Check for version string buffer
Since lvm seems to call driver_version(NULL, 0)  this would lead
to crash. Though the combination of the code is probably very hard to hit.
If the user doesn't supply version buffer, just skip printing to buffer.
2012-03-01 10:07:38 +00:00
Alasdair Kergon
ebf5552754 Fix empty string warning logic in _find_config_str. (1.02.68)
pvcreate gives
WARNING: Ignoring unsupported value for metadata/pvmetadataignore.

It was warning if there is no config file entry instead of only if the node
exists but is empty.
2012-02-28 17:46:47 +00:00
Zdenek Kabelac
fbf6b89a84 Using enum types for enums
alloc_policy_t, dm_string_mangling_t, percent_range_t, sign_t
2012-02-28 14:24:57 +00:00
Peter Rajnoha
25b25bd1a2 Fix dm_task_set_name to properly resolve path to dm name.
Wrong variable was checked in _dm_task_set_name_from_path.
2012-02-28 08:36:51 +00:00
Zdenek Kabelac
b3d10d7bf1 Introduce dm_strncpy
Should be faster then strncpy - since we could avoid clearing 4KB pages
with each strncpy(...,PATH_MAX).
Also it's easy to check whether string fit - and eventually avoid
to continue working we incomplete string.
2012-02-23 22:45:43 +00:00
Zdenek Kabelac
b5184347b6 Missed dm_free in last commit 2012-02-23 18:19:32 +00:00
Zdenek Kabelac
f72b184e3e Limit number of mem allocs and copies
If we have good enough glibc to return number of needed chars, do not
loop try to reach good size, but use this size directly for allocation,
saving also last strdup.

Since now we start with 16 bytes - skip buffer realloc for shorter string.
2012-02-23 18:05:12 +00:00
Peter Rajnoha
05bfdefdf8 Add DM_DEFAULT_NAME_MANGLING_MODE env. variable to override configured value.
Just in case of emergency when name mangling code causes any problems so
we can override the default value and switch off the mangling globally.
2012-02-15 12:23:15 +00:00
Peter Rajnoha
3eb23ab3d2 Replace any '\' char with '\\' in table specification on input.
Device-mapper in kernel uses '\' as escape character so it's better
to double it to avoid any confusion when using existing device names
with '\' in the table specification.

For example:

dmsetup create x --table "0 8 linear /dev/mapper/a\x20b 0"

should pass just fine now without a need to explicitly escape the '\' char
like this:

dmsetup create x --table "0 8 linear /dev/mapper/a\\x20b 0"
2012-02-15 12:17:34 +00:00
Peter Rajnoha
573e57f83f Unamngle dm device name list automatically on ioctl return.
If dm_task_get_name or dm_task_get_names gets called, these will return
unmangled form of the names so the name mangling stays totally transparent
to any libdevmapper user (unless DM_STRING_MANGLING_NONE is used in which
case the name is not touched and it is is returned as it is in kernel).

For example:

dmsetup create "a b" - will create a\x20b device in kernel and so udev will
create /dev/mapper/a\x20b

dm_task_get_name/names will still return "a b"

In AUTO mode, the libdevmapper user can still query the device by using
the mangled ("a\x20b") or unmangled form of the name when calling dm_task_set_name.
If mangled name is provided, it's detected and the name is kept as it is.
If unmangled name is provided, it will be mangled. IOW in AUTO mode it's
totally transparent and it should not require any changes in the code
using libdevmapper.

However, any libdevmapper user must be aware of the fact that the mangled form
of the name appears in /dev/mapper (udev just can't deal with those blacklisted
characters).
2012-02-15 12:01:28 +00:00
Peter Rajnoha
bd364a70b5 Add dm_task_get_name_mangled/unmangled to libdevmapper.
dm_task_get_name_mangled will always return mangled form of the name while
the dm_task_get_name_unmangled will always return unmangled form of the name
irrespective of the global setting (dm_set/get_name_mangling_mode).

This is handy in situations where we need to detect whether the name is already
mangled or not. Also display functions make use of it.
2012-02-15 11:39:38 +00:00
Peter Rajnoha
2e8c7f2975 Add DEV_NAME macro.
Use the DEV_NAME macro to use the mangled form of the name if present,
use normal name otherwise (we store both forms - mangled and unmangled in
struct dm_task). Mangled form should be always preferred over unmangled
with the exception of the situations where we divide one task into several
others (like "create and load") - we need to avoid mangling the name twice
(because of multiple dm_task_set_name calls)!
2012-02-15 11:33:53 +00:00
Peter Rajnoha
55761e14af Mangle device name on dm_task_set_name/newname call if necessary.
If dm_task_set_name/newname is called, the name provided will be
automatically translated to correct encoded form with the hex enconding
so any character not on udev whitelist will be mangled with \xNN
format where NN is hex value of the character used.

By default, the name mangling mode used is the one set during
configure with the '--with-default-name-mangling' option.
2012-02-15 11:27:01 +00:00
Peter Rajnoha
53f3ebce92 Add configure --with-default-name-mangling.
This option configures the default name mangling mode used, one of:
AUTO, NONE and HEX.

The name mangling is primarily used to support udev character whitelist
(0-9, A-Z, a-z, #*-.:=@_) so any character that is not on udev whitelist
will get translated into an encoded form \xNN where NN is the hex value
of the character.
2012-02-15 11:17:57 +00:00
Jonathan Earl Brassow
ad48a46fc9 Make conversion from a synced 'mirror' to 'raid1' not cause a full resync.
It was not possible to pass down the DM_[FORCE|NO]SYNC flags to
'dm_tree_node_add_raid_target'.  This meant that converting to 'raid1' from
'mirror' would cause a full resync.  (It also meant that '--nosync' was
ineffective when creating a 'raid1' LV.)

I've taken the 'reserved' parameter in 'dm_tree_node_add_raid_target' and
used it for the "flags" parameter.  Now it is possible to pass the sync
flags and any other flags that may come up.
2012-02-13 20:13:39 +00:00
Zdenek Kabelac
c71b47b9e6 Fix missing temp_buf init for error path
In previous commit this was missing, also deallocate in reversed order.
2012-02-13 14:39:24 +00:00
Zdenek Kabelac
820aa36192 Do not write to -1 buffer address
In case of zero bytes would be read from sysfs, it would store '\0' on
temp_buf[-1] address.

Simplify some buffer length calculation and use strcpy if we've just
checked string fits in give buffer.

Replace jump label error: with bad: commonly used in libdm.
2012-02-13 10:49:28 +00:00
Zdenek Kabelac
4d95ccc696 Check for deps pointer before dererence
As _deps() call may return NULL - check for it.
2012-02-10 14:48:28 +00:00
Zdenek Kabelac
3b5834d78b Add validation of name and uuid
Do not accept NULL pointers.
2012-02-10 14:42:28 +00:00
Zdenek Kabelac
2c711a2502 Do not crash for NULL sort_key
Guard against NULL pointer for sort_key and let it behave like an empty
string would have been passed in (i.e. no key).
2012-02-10 14:00:07 +00:00
Zdenek Kabelac
36ddbdbbe2 Return error for failing allocation
Fix case, where final strdup would have failed and it would miss to return
failure for this case and return success and NULL pointer.
2012-02-10 13:56:19 +00:00
Zdenek Kabelac
c046a59e7f Add test for failing allocation
Avoid memcpy to NULL if realloc fails.
2012-02-10 13:52:05 +00:00
Zdenek Kabelac
511a5f3ad8 Add test for memory allocation failures
Replace asserts with test for failing memory allocation.
Add at least stack traces.
Index counter starts from 1 (0 reserved for error), so replacing fingerprint.
2012-02-10 13:49:29 +00:00
Zdenek Kabelac
a13efe5665 Drop unreachable code 2012-02-08 12:59:45 +00:00
Zdenek Kabelac
d707e133d3 Use dm_asprintf to simplify code 2012-02-08 12:59:19 +00:00
Zdenek Kabelac
a6292f2a6d Remove unneeded assignments
Variables have (or will have) those values set.
2012-02-08 11:36:18 +00:00
Zdenek Kabelac
ebc9abf6c0 Set all parameters to 0
Since the function dm_get_next_target() returns NULL as 'next' pointer
so it's not a 'real' error - set 0 to all parameters when NULL is
returned because of missing head.

i.e. one of use case::
do {
	next = dm_get_next_target(dmt, next, &start, &length,
				  &target_type, &params);
	size += length;
} while (next);
2012-02-08 11:25:09 +00:00
Zdenek Kabelac
b6e97cea2c Fix fd resource leak in error path
Use 'goto bad' to cleanup fd on error path.
2012-02-08 11:07:17 +00:00
Zdenek Kabelac
5dfd775384 Ensure strncpy() function always ends with '\0'
Since last character needs to be \0 for string,
pass buffer size smaller by 1 byte.
2012-02-08 11:05:04 +00:00
Zdenek Kabelac
fc5c61df97 Ensure whole info is initialised
Since _create_dm_tree_node is copying whole structure,
make sure all members are initialized.
2012-01-25 21:50:50 +00:00
Zdenek Kabelac
0e6cacbbb6 Fix resource leak of file handle
Introduces when added dm_device_get_name.
Close file handle in all error paths.
2012-01-25 21:47:18 +00:00
Zdenek Kabelac
4173a22832 Thin send messages on activation resume code path
Using PRELOAD part would lead to problems when the problem
would happen before vg_write and vg_commit.
Also this change is necessary for snapshot creation sequence.
2012-01-25 08:46:21 +00:00
Alasdair Kergon
00ab1e3f8b add const 2012-01-23 17:47:36 +00:00
Alasdair Kergon
5c9eae9647 Reorder fns in libdm-deptree.
Tweak dm_config interface and remove FIXMEs.
2012-01-23 17:46:31 +00:00
Zdenek Kabelac
9568f1b5c3 Thin handle empty thin volume case
Report both values as 0 in case the volume is unused.
2012-01-19 15:22:32 +00:00
Zdenek Kabelac
5fd459f0ab Thin use consistentely metadata
Do not shortcut to 'meta' and stay with 'metadata'
Also matches kernel doc for dm API then.
2012-01-19 15:21:23 +00:00
Zdenek Kabelac
e38b557a74 Update for gcc old-style 2012-01-19 15:16:39 +00:00
Peter Rajnoha
26a3549fa0 Move dm_task_set_newname from libdm-iface.c to libdm-common.c 2012-01-17 14:36:58 +00:00
Peter Rajnoha
17c3e42b21 Add dm_device_get_name to get map name or block device name for given devno.
This is accomplished by reading associated sysfs information. For a dm device,
this is /sys/dev/block/major:minor/dm/name (supported in kernel version >= 2.6.29,
for older kernels, the behaviour is the same as for non-dm devices).

For a non-dm device, this is a readlink on /sys/dev/block/major:minor, e.g.
  /sys/dev/block/253:0 --> ../../devices/virtual/block/dm-0.
The last component of the path is a proper kernel name (block device name).

One can request to read only kernel names by setting the 'prefer_kernel_name'
argument if needed.
2012-01-11 12:34:44 +00:00
Alasdair Kergon
2e5ff5d11c Add dm_uuid_prefix/dm_set_uuid_prefix for non-lvm users to override hard-coded
LVM- prefix.

Try harder not to leave stray empty devices around (locally or remotely) when
reverting changes after failures while there are inactive tables.
2012-01-10 02:03:31 +00:00
Zdenek Kabelac
044abcf91b Use sysfs to set/get of read-ahead
If we know major:minor number of device (which is known after resume) we will
try to use  sysfs to set/get read ahead parameters of device.
This avoid potential problem of blocking commands like 'dmsetup info' awaiting
for device being usable for open/close - i.e. overfilled thin pool may block
such command.
2012-01-09 12:26:14 +00:00
Zdenek Kabelac
077c4d1a35 Add Thin API for parsing thin status
Add dm_get_status_thin_pool and dm_get_status_thin functions to
parse 'params' argument which is received via dm_get_next_target.

Returns filed structure allocated from given mempool.
2011-12-21 12:52:38 +00:00
Zdenek Kabelac
99a150fc26 Add dm_config_find_str_allow_empty
Support empty string values.
2011-12-21 12:47:44 +00:00
Petr Rockai
845b1df617 Make a cleaner split between config tree and config file functionality. Move
the latter out of libdm.
2011-12-18 21:56:03 +00:00
Petr Rockai
11e520256b Move dm_config_write out of libdm, back to lib/config, as config_write. 2011-12-11 23:18:20 +00:00
Petr Rockai
864ec23ec0 In the dm_config_*get_* functions, make the actual value retrieval optional
(useful for just checking that a given key is of a given type).
2011-12-11 15:18:32 +00:00
Jonathan Earl Brassow
0c506d9a40 Support the ability to replace specific devices in a RAID array.
RAID is not like traditional LVM mirroring.  LVM mirroring required failed
devices to be removed or the logical volume would simply hang.  RAID arrays can
keep on running with failed devices.  In fact, for RAID types other than RAID1,
removing a device would mean substituting an error target or converting to a
lower level RAID (e.g. RAID6 -> RAID5, or RAID4/5 to RAID0).  Therefore, rather
than removing a failed device unconditionally and potentially allocating a
replacement, RAID allows the user to "replace" a device with a new one.  This
approach is a 1-step solution vs the current 2-step solution.

example> lvconvert --replace <dev_to_remove> vg/lv [possible_replacement_PVs]

'--replace' can be specified more than once.

example> lvconvert --replace /dev/sdb1 --replace /dev/sdc1 vg/lv
2011-11-30 02:02:10 +00:00
Zdenek Kabelac
5392675f4c Check target type name for DM_MAX_TYPE_NAME length
Avoid creation of target type name when it's longer then
DM_MAX_TYPE_NAME (noticed by static analyzer where the
sp.target_type might be missing '\0' at the end.)

Before patch:

$> dmsetup create long
0 1000 looooooooooooooooooooooooooong
^D
device-mapper: reload ioctl failed: Invalid argument

After patch:

$> dmsetup create xxx
0 1000 looooooooooooooooooooooooooong
Target type name looooooooooooooooooooooooooong is too long.
Command failed
2011-11-18 19:34:02 +00:00
Zdenek Kabelac
6744c143a5 Thin remove unused define
Remove DM_THIN_ERROR_DEVICE_ID from API.
Remove API warning.
Drop code that was using DM_THIN_ERROR_DEVICE_ID (already commented)
Remove debug message which slipped in through some previous commit.
2011-11-12 22:44:10 +00:00
Mike Snitzer
eeaf162626 Add missing free() for line that is malloc()'d by getline(). 2011-11-08 19:02:21 +00:00
Mike Snitzer
52f3043f15 Fix _get_proc_number to be tolerant of malformed /proc/misc entries.
Fixes issue reported here: http://lkml.org/lkml/2011/11/8/190
2011-11-08 17:32:10 +00:00
Zdenek Kabelac
19e3f8c30b Thin fix condition check for transation_id
id2 must be checked.
(missed in yesterday commit set).
2011-11-04 12:39:45 +00:00
Zdenek Kabelac
2e732e9628 Thin api change for passing message into libdm
Avoid exposing another struct to the libdm user and
use only simple dm_tree_node_add_thin_pool_message with
2 overloaded uint64_t values.
2011-11-03 14:45:01 +00:00
Zdenek Kabelac
4d25c81bdd Thin api change for dm_tree_node_add_thin_target
A little code shuffling and adding support for
DM_THIN_ERROR_DEVICE_ID which might be eventually be used
for activation of thin which is going to be deleted.
For now we do not need it lvm.
2011-11-03 14:43:21 +00:00
Zdenek Kabelac
25de9addb6 Thin fix compile warns
Test for dm_snprintf < 0.
Add header for moved backup.
2011-10-30 22:52:08 +00:00
Zdenek Kabelac
bbcd37e4b8 Thin segment transaction_id moved
Add a new node flag send_messages that is used to simplify
test when to call _node_send_messages().

Add call to _node_send_messages when pool is deeper in the tree.
2011-10-30 22:04:57 +00:00
Zdenek Kabelac
8009588314 Improve valgrind support when compiled with DEBUG_MEM 2011-10-28 20:37:31 +00:00
Zdenek Kabelac
c590a9cdbc Thin error messages clenaup and some indent 2011-10-28 20:19:26 +00:00
Zdenek Kabelac
4ce43894d2 Trying to fix the retry logic
There should be no need for retry for our internal devices - it would be hinding
our own bug in the tree processing.
Update error messages to show also also device name.
No WHATS_NEW - in release fix.
2011-10-28 20:11:21 +00:00
Zdenek Kabelac
5a6ae6f5aa Fix core on buggy config file
Since fixed within unreleased version so no WHATS_NEW
2011-10-28 20:07:38 +00:00
Zdenek Kabelac
7ad1c43b48 Add find_config_tree_str_allow_empty
Add function to allow read of empty strings as valid arguments.
Add a warning message if string argument has ignored value.
2011-10-28 20:06:49 +00:00
Zdenek Kabelac
35d462dafc Update header comment 2011-10-28 20:04:17 +00:00
Zdenek Kabelac
fd6a1bfb74 Fix usage of DEBUG_ENFORCE_POOL_LOCKING with DEBUG_MEM
Since DEBUG_MEM is storing own extra structure within returned memory chunk,
glibc free must be used directly for posix_memaling() allocated block.
2011-10-23 15:38:02 +00:00
Zdenek Kabelac
e597d5a487 Aling structure chunk on default aling size
Since we use 8 bytes by default for the pool allocation,
keep the structure aligned with this size.
(Somehow it was not applied in previous commit.)
2011-10-20 14:43:33 +00:00
Zdenek Kabelac
3bdcf7c5e6 Mark chunk memory for free as defined again for valgrind
When DEBUG_MEM is used, the memory is trashed with extra pattern before real
free() is called, and as this memory was marked as non accessible when used with
valgrind, make it again usable.
2011-10-20 13:39:57 +00:00
Zdenek Kabelac
e3359201cf Simplify some pointer operations 2011-10-20 13:33:41 +00:00
Zdenek Kabelac
909bc0fff1 Remove unused file from tree 2011-10-20 13:23:52 +00:00
Zdenek Kabelac
3d6782b3ff Just replace stack, return 0 with return_0 2011-10-20 10:39:07 +00:00
Zdenek Kabelac
f857b3064f Cleanup backtraces
Make sure stacks are at the right places when something goes wrong here.
2011-10-20 10:38:04 +00:00
Zdenek Kabelac
ac08d9c028 Add last param 0 for thin-pool
So now the table suppression works for thin-pool.
2011-10-20 10:35:55 +00:00
Zdenek Kabelac
e9156c2bb9 Adapt to thin kernel target API
Since kernel target uses low_water_mark - use this name in libdm as well.
2011-10-20 10:33:30 +00:00
Zdenek Kabelac
7b199dc599 Use const pointers in thin API were appropriate 2011-10-20 10:31:27 +00:00
Zdenek Kabelac
3f53c059e9 Add _BLOCK_ to define
Use DM_THIN_MIN_DATA_BLOCK_SIZE and
DM_THIN_MAX_DATA_BLOCK_SIZE to make it more obvious, for which
this define is useful in thin API.
2011-10-20 10:28:41 +00:00
Zdenek Kabelac
2a0d806b3c Use structure copy
Since the code evolved a bit with current structures we could use C to
copy struct members.
2011-10-19 16:45:02 +00:00
Zdenek Kabelac
759b9592ba Update error message
Drop INTERNAL_ERROR from public API functions.
Improve some messages.
2011-10-19 16:42:14 +00:00
Zdenek Kabelac
11f64f0aeb Use generic name for message sending function
Drop _thin_pool prefix for _node_send_message so it could be extended later.
Replace current_id with trans_id name.
2011-10-19 16:40:59 +00:00
Zdenek Kabelac
97d0f72c92 Just indent changes
Some tabs & spaces.
2011-10-19 16:36:39 +00:00
Zdenek Kabelac
660a42bc78 Add internal expected_errno dm_tast var
Certain errno codes could be expected in some situations thus
add experimental support for them.

When expected errno is set after ioctl error - function skips error
printing and exits succefully.

Currently only useful for thin pool messages.
2011-10-19 16:36:01 +00:00
Zdenek Kabelac
41f09f7124 Use zalloc for malloc,memset 2011-10-17 14:36:06 +00:00
Zdenek Kabelac
25e6ab87d8 Add thin_pool dm message support
Experimental support for kernel message via resume sequence.
2011-10-17 14:16:25 +00:00
Zdenek Kabelac
5668fe04d9 Add _thin_validate_device_id 2011-10-17 14:15:26 +00:00
Zdenek Kabelac
5668fd6a7a Swap parameters
Use metadata uuid first (match kernel target).
2011-10-17 14:15:01 +00:00
Zdenek Kabelac
df6b1b8fe6 Drop old check for transaction_id
(revert)
2011-10-17 14:14:33 +00:00
Milan Broz
ad2432dc68 Fix alignment warning in bitcount calculation for raid segment. 2011-10-17 13:15:35 +00:00
Jonathan Earl Brassow
3b032963d5 cmirrord now returns log name to kernel in CTR so it can be registered
Version 2 of the userspace log protocol accepts return information during the
DM_ULOG_CTR exchange.  The return information contains the name of the log
device that is being used (if there is one).  The kernel can then register the
device via 'dm_get_device'.  Amoung other things, this allows for userspace to
assemble a correct dependency tree of devices - critical for LVM handling of
suspend/resume calls.

Also, update dm-log-userspace.h to match the kernel header associated with
this protocol change.  (Includes a version inc.)
2011-10-14 14:18:49 +00:00
Jonathan Earl Brassow
6635332e1b Update stale libdm/misc/dm-log-userspace.h
The upstream kernel version that this file mirrors has changed, here is the
commit message:

commit 86a54a4802df10d23ccd655e2083e812fe990243
Author: Jonathan Brassow <jbrassow@redhat.com>
Date:   Thu Jan 13 19:59:52 2011 +0000

    dm log userspace: add version number to comms

    This patch adds a 'version' field to the 'dm_ulog_request'
    structure.

    The 'version' field is taken from a portion of the unused
    'padding' field in the 'dm_ulog_request' structure.  This
    was done to avoid changing the size of the structure and
    possibly disrupting backwards compatibility.

    The version number will help notify user-space daemons
    when a change has been made to the kernel/userspace
    log API.

    Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
    Signed-off-by: Mike Snitzer <snitzer@redhat.com>
    Signed-off-by: Alasdair G Kergon <agk@redhat.com>
2011-10-14 14:04:05 +00:00
Zdenek Kabelac
0395dd2250 Use pool for dm_tree allocation
Using the same pool allocation strategy as we use for vg,
so dm_tree structure is part of the pool itself.
2011-10-14 13:34:19 +00:00
Jonathan Earl Brassow
83c606ae30 This patch fixes issues with improper udev flags on sub-LVs.
The current code does not always assign proper udev flags to sub-LVs (e.g.
mirror images and log LVs).  This shows up especially during a splitmirror
operation in which an image is split off from a mirror to form a new LV.

A mirror with a disk log is actually composed of 4 different LVs: the 2
mirror images, the log, and the top-level LV that "glues" them all together.
When a 2-way mirror is split into two linear LVs, two of those LVs must be
removed.  The segments of the image which is not split off to form the new
LV are transferred to the top-level LV.  This is done so that the original
LV can maintain its major/minor, UUID, and name.  The sub-lv from which the
segments were transferred gets an error segment as a transitory process
before it is eventually removed.  (Note that if the error target was not put
in place, a resume_lv would result in two LVs pointing to the same segment!
If the machine crashes before the eventual removal of the sub-LV, the result
would be a residual LV with the same mapping as the original (now linear) LV.)
So, the two LVs that need to be removed are now the log device and the sub-LV
with the error segment.  If udev_flags are not properly set, a resume will
cause the error LV to come up and be scanned by udev.  This causes I/O errors.
Additionally, when udev scans sub-LVs (or former sub-LVs), it can cause races
when we are trying to remove those LVs.  This is especially bad during failure
conditions.

When the mirror is suspended, the top-level along with its sub-LVs are
suspended.  The changes (now 2 linear devices and the yet-to-be-removed log
and error LV) are committed.  When the resume takes place on the original
LV, there are no longer links to the other sub-lvs through the LVM metadata.
The links are implicitly handled by querying the kernel for a list of
dependencies.  This is done in the '_add_dev' function (which is recursively
called for each dependency found) - called through the following chain:
	_add_dev
	dm_tree_add_dev_with_udev_flags
	<*** DM / LVM divide ***>
	_add_dev_to_dtree
	_add_lv_to_dtree
	_create_partial_dtree
	_tree_action
	dev_manager_activate
	_lv_activate_lv
	_lv_resume
	lv_resume_if_active
When udev flags are calculated by '_get_udev_flags', it is done by referencing
the 'logical_volume' structure.  Those flags are then passed down into
'dm_tree_add_dev_with_udev_flags', which in turn passes them to '_add_dev'.
Unfortunately, when '_add_dev' is finding the dependencies, it has no way to
calculate their proper udev_flags.  This is because it is below the DM/LVM
divide - it doesn't have access to the logical_volume structure.  In fact,
'_add_dev' simply reuses the udev_flags given for the initial device!  This
virtually guarentees the udev_flags are wrong for all the dependencies unless
they are reset by some other mechanism.  The current code provides no such
mechanism.  Even if '_add_new_lv_to_dtree' were called on the sub-devices -
which it isn't - entries already in the tree are simply passed over, failing
to reset any udev_flags.  The solution must retain its implicit nature of
discovering dependencies and be able to go back over the dependencies found
to properly set the udev_flags.

My solution simply calls a new function before leaving '_add_new_lv_to_dtree'
that iterates over the dtree nodes to properly reset the udev_flags of any
children.  It is important that this function occur after the '_add_dev' has
done its job of querying the kernel for a list of dependencies.  It is this
list of children that we use to look up their respective LVs and properly
calculate the udev_flags.

This solution has worked for single machine, cluster, and cluster w/ exclusive
activation.
2011-10-06 14:45:40 +00:00
Zdenek Kabelac
565a4bfc49 Move defines to header
Make limits for thin data_block_size and device_id part of public API.

FIXME: read them possible from some kernel header file in the future ?
But we may need to support different values for different versions ?
2011-10-06 11:05:56 +00:00
Zdenek Kabelac
460c599143 Name changes
typo zeroeing->zeroing
add size low_water_mark->low_water_mark_size so it's more obvious its sector
related variable.
2011-10-04 16:22:38 +00:00
Zdenek Kabelac
e0ea24be1f Add intial code to check transaction_id
Fix typy in transaction_id.
Add this as node property, so it could be easily checked on resume.

Code is not yet finished.
2011-10-03 18:34:52 +00:00
Zdenek Kabelac
a5a31ce947 Move priority check in front
Just a minor code mode - make a test for priority before
more complex uuid checks.
2011-10-03 18:29:48 +00:00
Zdenek Kabelac
9a8f192a38 Update error path tracing for _resume_node
dm_task_create & dm_task_set_name produces it's own log_error
Add missing stacks for dm_task_set_cookie, dm_task_run,
dm_task_get_info.
2011-10-03 18:28:25 +00:00
Zdenek Kabelac
1419bf1c98 Transaction_id is property of thin_pool
Remove Transaction_id from thin target.
Store device_id for thin target.
2011-10-03 18:26:07 +00:00
Zdenek Kabelac
4251236efc Add supporting function for thinp
New dm_tree_node_add_thin_pool_target() and  dm_tree_node_add_thin_target()
This API is highly experimental and unstable for now.
2011-09-29 08:53:48 +00:00
Zdenek Kabelac
ee05be0872 Just add warning about potential problem exteding dm_segtypes
Since raid target is using now dm_segtypes also for search purpose.
2011-09-29 08:50:54 +00:00
Alasdair Kergon
10d0d9c7c4 Introduce revert_lv for better pvmove cleanup.
(One further fix needed to remove the stray pvmove LVs left behind.)
2011-09-27 22:43:40 +00:00
Peter Rajnoha
c3e5b4976d Add log_error even for general device in use when we can't do the sysfs checks. 2011-09-26 10:17:51 +00:00
Zdenek Kabelac
807a5a7b13 Remove test for NULL
Since it's internal function and we always check for NULL value
before call - this is safe.

Just for case add nonnull attribute so analyzer might better
catch error.
2011-09-25 19:45:40 +00:00
Zdenek Kabelac
d2c25f02e8 Add missing log_error messages 2011-09-25 19:43:43 +00:00
Zdenek Kabelac
60444f8bff Add backtrace when allocation fails for _type 2011-09-25 19:42:45 +00:00
Zdenek Kabelac
5ce39c67e5 Replace test for NULL of root->child with test for NULL l
It's 100% equivalent test - since it always happen for the first iteration.
But the check for 'l' is understandable with analyzers - since analyzer
is not smart enough to deduce connection between  root->child == NULL.
2011-09-25 19:41:27 +00:00
Zdenek Kabelac
347e1afd53 Simplier attribute format
No need to repeat whole declaration for static function.
2011-09-25 19:40:29 +00:00
Zdenek Kabelac
354a2a6769 Chheck for failing filename strdup 2011-09-25 19:39:38 +00:00
Zdenek Kabelac
f45106b726 Use NULL for pointers 2011-09-25 19:38:59 +00:00
Peter Rajnoha
e8ee29e9c1 readlink does not append a null byte to the output string! 2011-09-24 11:47:53 +00:00
Alasdair Kergon
349b204bc2 explain why we may now retry 2011-09-23 17:16:28 +00:00
Peter Rajnoha
a54dbfb2b3 Initialize 'retryable' variable. 2011-09-22 17:59:58 +00:00
Peter Rajnoha
787200efd6 Add dm_tree_retry_remove to use retry logic for device removal in a dm_tree. 2011-09-22 17:36:50 +00:00
Peter Rajnoha
125712bea0 Replace open_count check with holders/mounted_fs check on lvremove path.
Before, we used to display "Can't remove open logical volume" which was
generic. There 3 possibilities of how a device could be opened:
  - used by another device
  - having a filesystem on that device which is mounted
  - opened directly by an application

With the help of sysfs info, we can distinguish the first two situations.
The third one will be subject to "remove retry" logic - if it's opened
quickly (e.g. a parallel scan from within a udev rule run), this will
finish quickly and we can remove it once it has finished. If it's a
legitimate application that keeps the device opened, we'll do our best
to remove the device, but we will fail finally after a few retries.
2011-09-22 17:33:50 +00:00
Peter Rajnoha
14254bd0be Add dm_device_has_holders fn to to check use of the device by another device.
Add dm_device_has_mounted_fs fn to check mounted filesystem on a device.

This requires sysfs directory to be correctly set via dm_set_sysfs_dir
(/sys by default). If sysfs dir is not used or it's set incorrectly,
dm_device_has_{holders,mounted_fs} will return 0!
2011-09-22 17:23:35 +00:00
Peter Rajnoha
07e237d6f4 Add dm_set_sysfs_dir to libdevmapper to set sysfs location.
Add dm_sysfs_dir to libdevmapper to retrieve sysfs location thas is set.
2011-09-22 17:17:07 +00:00
Peter Rajnoha
355b2224b2 Add dm_task_retry_remove fn to use retry logic for device removal.
This call ensures that the dm device removal is retried several
times before failing.
2011-09-22 17:09:48 +00:00
Zdenek Kabelac
6fe315d412 Fix memory overwrite
Transfer of build_dm_uuid() function into libdm made uuid_prefix as parameter,
thus sizeof() was replaced with strlen() and room for '\0' missed.

As it's only fix in current version - no whatsnew.
2011-09-14 16:07:07 +00:00
Peter Rajnoha
8171b93700 Retry DM_DEVICE_REMOVE ioctl if device is busy.
This is a workaround for long-lasting problem with using the WATCH udev
rule. When trying to remove a DM device, this one can still be opened
while processing the event in parallel (generated based on the WATCH
udev rule).

Let's use this until we have a proper solution.
2011-09-13 15:13:41 +00:00
Zdenek Kabelac
beecb1e160 Remove unused passed parameters 2011-09-07 08:37:48 +00:00
Alasdair Kergon
c82c2bebed Move cascade inside libdm etc.
Makes dumpconfig whole-section output wrong in a different way from before,
but we should be able to merge cft_cmdline properly into cmd->cft now and
remove cascade.
2011-09-02 01:32:08 +00:00
Alasdair Kergon
fe8f5dbeb7 Comments, FIXMEs, name changes. 2011-09-01 21:04:14 +00:00
Alasdair Kergon
79b9c65b6b Add comments & remove always-included header. 2011-09-01 17:58:27 +00:00
Zdenek Kabelac
441edcb50a Use const casting when it's needed
Keep the lookup operation const and use const casting at the dm_ function level.
2011-09-01 14:02:05 +00:00
Zdenek Kabelac
2d70959c86 Mark unreleased memory pools as internal error 2011-09-01 10:19:01 +00:00
Petr Rockai
97a4b5165e Replace const usage of dm_config_find_node with more appropriate value-lookup
functionality. A number of bugs (copied and pasted all over the code) should
disappear:

- most string lookup based on dm_config_find_node would segfault when
  encountering a non-zero integer (the intention there was to print an
  error message instead)
- check for required sections in metadata would have been satisfied by
  values as well (i.e. not sections)
- encountering a section in place of expected flag value would have
  segfaulted (due to assumed but unchecked cn->v != NULL)
2011-08-31 15:19:19 +00:00
Petr Rockai
e68a6fbf20 Fix warnings and constness handling in lvmetad-core (adjusting the
dm_config_find_node to give non-const node pointer, since that better reflects
the contract of that function).
2011-08-31 12:39:58 +00:00
Petr Rockai
e59e2f7c3c Move the core of the lib/config/config.c functionality into libdevmapper,
leaving behind the LVM-specific parts of the code (convenience wrappers that
handle `struct device` and `struct cmd_context`, basically). A number of
functions have been renamed (in addition to getting a dm_ prefix) -- namely,
all of the config interface now has a dm_config_ prefix.
2011-08-30 14:55:15 +00:00
Alasdair Kergon
40e5fd8b3a spaces->tabs 2011-08-19 17:02:48 +00:00
Alasdair Kergon
c3d985c3ad revert incomplete inconsistent log message change for now 2011-08-19 16:49:00 +00:00
Alasdair Kergon
415c0690af restrict dm_tree_node_add_null_area 2011-08-19 16:26:02 +00:00
Jonathan Earl Brassow
a2facf4ad4 Add ability to merge back a RAID1 image that has been split w/ --trackchanges
Argument layout is very similar to the merge command for snapshots.
2011-08-18 19:43:08 +00:00
Jonathan Earl Brassow
f439e65b64 Add support for m-way to n-way up-convert in RAID1 (no linear to n-way yet)
This patch adds the ability to upconvert a raid1 array - say from 2-way to
3-way.  It does not yet support upconverting linear to n-way.

The 'raid' device-mapper target allows for individual components (images) of
an array to be specified for rebuild.  This mechanism is used when adding
new images to the array so that the new images can be resync'ed while the
rest of the images in the array can remain 'in-sync'.  (There is no
mirror-on-mirror layering required.)
2011-08-18 19:41:21 +00:00
Jonathan Earl Brassow
6d04311efa Add the ability to split an image from the mirror and track changes.
~> lvconvert --splitmirrors 1 --trackchanges vg/lv
The '--trackchanges' option allows a user the ability to use an image of
a RAID1 array for the purposes of temporary read-only access.  The image
can be merged back into the array at a later time and only the blocks that
have changed in the array since the split will be resync'ed.  This
operation can be thought of as a partial split.  The image is never completely
extracted from the array, in that the array reserves the position the device
occupied and tracks the differences between the array and the split image via
a bitmap.  The image itself is rendered read-only and the name (<LV>_rimage_*)
cannot be changed.  The user can complete the split (permanently splitting the
image from the array) by re-issuing the 'lvconvert' command without the
'--trackchanges' argument and specifying the '--name' argument.
	~> lvconvert --splitmirrors 1 --name my_split vg/lv
Merging the tracked image back into the array is done with the '--merge'
option (included in a follow-on patch).
	~> lvconvert --merge vg/lv_rimage_<n>

The internal mechanics of this are relatively simple.  The 'raid' device-
mapper target allows for the specification of an empty slot in an array
via '- -'.  This is what will be used if a partial activation of an array
is ever required.  (It would also be possible to use 'error' targets in
place of the '- -'.)  If a RAID image is found to be both read-only and
visible, then it is considered separate from the array and '- -' is used
to hold it's position in the array.  So, all that needs to be done to
temporarily split an image from the array /and/ cause the kernel target's
bitmap to track (aka "mark") changes made is to make the specified image
visible and read-only.  To merge the device back into the array, the image
needs to be returned to the read/write state of the top-level LV and made
invisible.
2011-08-18 19:38:26 +00:00
Zdenek Kabelac
5bedb7a5e0 Fix memleak of geometry buffer
Looks like this function is not used too often - thus leak was discovered
by static analyzis (Coverity).
2011-08-11 20:49:33 +00:00
Jonathan Earl Brassow
b2fa9b43dc Add some log_error msg's and fix potential segfault
Thanks to kabi for spotting these - especially the possibility for
segfault if a loop runs all the way through without finding a match.
2011-08-11 19:17:10 +00:00
Zdenek Kabelac
ed463ccf51 Add memory pool locking functions
Adding debuging functionality to lock and unlock memory pool.

2 ways to debug code:
crc - is default checksum/hash of the locked pool.
      It gets slower when the pool is larger - so the check is only
      made when VG is finaly released and it has been used more then
      once.Thus the result is rather informative.

mprotect - quite fast all the time - but requires more memory and
           currently it is using posix_memalign() - this could be
	   later modified to use dm_malloc() and align internally.
           Tool segfaults when locked memory is modified and core
	   could be examined for faulty code section (backtrace).

Only fast memory pools could use mprotect for now -
so such debug builds cannot be combined with DEBUG_POOL.
2011-08-11 17:29:04 +00:00
Alasdair Kergon
2061c0ec24 Remove support for the original dm ioctl interface version 1.
Leave the basic support for multiple versions in case we have a new version
in future.
2011-08-09 17:56:47 +00:00
Zdenek Kabelac
b23975ee28 Add missing check for allocation failure
Static analyzer discovered missing check.
2011-08-04 17:56:11 +00:00
Zdenek Kabelac
586f310618 Remove meaningless const type qualifiers on cast type
Static analyzis noticed we do not really need them - so removing.
2011-08-04 14:30:51 +00:00
Jonathan Earl Brassow
cac52ca4ce Add basic RAID segment type(s) support.
Implementation described in doc/lvm2-raid.txt.

Basic support includes:
- ability to create RAID 1/4/5/6 arrays
- ability to delete RAID arrays
- ability to display RAID arrays
Notable missing features (not included in this patch):
- ability to clean-up/repair failures
- ability to convert RAID segment types
- ability to monitor RAID segment types
2011-08-02 22:07:20 +00:00
Alasdair Kergon
d3efe22fa2 Fix read-only identical table reload supression. 2011-07-24 23:59:03 +00:00
Alasdair Kergon
b6793963e9 Downgrade error message - it isn't strictly an internal error in the
library, and the known cause within lvm2 got fixed.
2011-07-08 19:13:05 +00:00
Alasdair Kergon
32b7009196 Log cookie values when incrementing/decrementing to give clues about races. 2011-07-08 15:34:47 +00:00
Alasdair Kergon
f92e31558b decode cookie flags in debug msgs 2011-07-05 16:17:14 +00:00
Alasdair Kergon
ba45e1fdee Report internal error if suspending a device using an already-suspended dev.
This catches the recent pvmove problem trapping I/O between layers.
2011-07-02 01:17:09 +00:00
Alasdair Kergon
2243718fae Add framework for validation of ioctls. Doesn't do any checks yet.
dmsetup --checks
libdevmapper: dm_task_enable_checks()
lvm.conf: activation/checks=1
2011-07-01 14:09:19 +00:00
Zdenek Kabelac
812e10ac60 Report internal error when parameters are missing on table load
When some target is passing empty parameters to some dm target,
report this as an internal error to better catch some broken
table construction (some mirror conversions seem to be doing
this for now).
2011-06-30 09:24:58 +00:00
Alasdair Kergon
7cc4a70487 debug log readonly flag with ioctls 2011-06-29 16:08:33 +00:00
Alasdair Kergon
600dc4168c Remove temporary failures now, but continue to give INTERNAL_ERROR. 2011-06-29 11:36:37 +00:00
Alasdair Kergon
9591e7ede1 Temporary conversion to internal error and failure, to see how many
instances of this problem this flushes out.
2011-06-29 08:54:13 +00:00
Alasdair Kergon
7b5e4dcf1f more fixes to readahead etc. 2011-06-28 09:24:13 +00:00
Alasdair Kergon
9032898eb1 Extend debug log messages to distinguish between the 3 states:
trust udev; verify udev; perform dev node operations directly.
2011-06-27 22:38:53 +00:00
Alasdair Kergon
0437bccc3c Move udev_only logic inside stacked node op code.
(We still need to treat add+readhead+del as a no-op.)
Rename udev_fallback to verify_udev_operations.
Rename --udevfallback to --verifyudev
2011-06-27 21:43:58 +00:00
Alasdair Kergon
f4249251cb Return immediately dm_lib_exit() if called more than once.
(Avoiding calling it twice would involve some untangling.)
Decrement the new suspended_counter if removing a suspended device.
2011-06-24 19:33:41 +00:00
Peter Rajnoha
901e7257d1 Add check for library fallback in _deactivate_node.
This fn calls rm_dev_node directly - an exceptional case. It needs to check
the DM_UDEV_DISABLE_LIBRARY_FALLBACK flag directly (it's called in dm_task_run
normally where it's checked already).
2011-06-22 12:56:02 +00:00
Alasdair Kergon
98a0fa72be Fix fields in warning message. 2011-06-13 03:53:02 +00:00
Alasdair Kergon
1840aa0974 Maintain a count of the number of suspended devices in libdevmapper
and use this for the LVM critical section logic.  Also report an error if
code tries to load a table while any device is known to be in the
suspended state.
(If the variety of problems these changes are showing up can't be fixed
before the next release, the error messages can be reduced to debug
level.)
2011-06-13 03:32:45 +00:00
Alasdair Kergon
83e797bc52 Fix 'pvs -o pv_all' to include label fields. (Also removed recursion.) 2011-06-12 19:49:40 +00:00
Alasdair Kergon
0a99713ea4 Fix --mirrorlog mirrored. 2011-06-11 12:55:31 +00:00
Alasdair Kergon
df390f1799 Major pvmove fix to issue ioctls in the correct order when multiple LVs
are affected by the move.  (Currently it's possible for I/O to become
trapped between suspended devices amongst other problems.

The current fix was selected so as to minimise the testing surface.  I
hope eventually to replace it with a cleaner one that extends the
deptree code.

Some lvconvert scenarios still suffer from related problems.
2011-06-11 00:03:06 +00:00
Milan Broz
b39fdcf45b Fix another occurrence of linux kernel version check. 2011-06-09 15:52:59 +00:00
Milan Broz
fa380602cf Accept kernel version 3 (3.0-rc and similar). 2011-06-09 15:07:40 +00:00
Peter Rajnoha
71b29ddcc4 Require libudev >= 143 when compiling with udev support.
Old versions of libudev < 143 were experimental and unstable. Require recent
and stable versions only (version 143 is old enough anyway).
2011-04-22 11:56:41 +00:00
Zdenek Kabelac
a1eba521e3 Fix some unmatching sign comparation gcc warnings
Simple replacement for unsigned type - usually in for() loops.
2011-04-08 14:40:18 +00:00
Zdenek Kabelac
197b5e6dc7 Word alignment for strings
Align strdup char* allocation just on 2 bytes.
It looks like wasting space to align strings on 8 bytes.
(Could be even 1byte - but for hashing it might eventually get better
perfomance - but probably hardly measurable).

TODO: check on various architectures it's not making any problems.
2011-03-30 12:57:03 +00:00
Zdenek Kabelac
01fb91c615 Valgrind updates
Avoid locking sum testing with valgrind compilation.

Make memory unaccessible in the valgrind for dm_pool_abadon_object.

Valgrind hinting should not be needed in _free_chunk for dm_free.
2011-03-30 12:43:32 +00:00
Zdenek Kabelac
73b01e9660 Simplify pool debug initialization
zalloc pool structure and skip zeroing members.
2011-03-30 12:16:15 +00:00
Zdenek Kabelac
b8bdd780d8 Fix 2 signess warnings reported by gcc
Replace int with unsigned counter.
Replace snprintf with dm_snprintf.
2011-03-30 12:14:36 +00:00
Zdenek Kabelac
6460d5a405 Add attribute printf
gcc suggested to add these attributes to instrumentat
printf arguments. Adding it for internal functions as well.
2011-03-29 21:53:46 +00:00
Zdenek Kabelac
f77736cab5 Remove double braces
Clang gives notice about possible confusion as commonly double bracces are
used when some assignment is done inside them.
2011-03-29 20:19:03 +00:00
Alasdair Kergon
76c13d16eb Use hard-coded /dev/mapper/control details for 2.6.36+ kernels and simplify
associated code.  (Some obscure configurations that happened to work before
are no longer supported.)
2011-03-25 23:50:35 +00:00
Alasdair Kergon
129526b826 Fix last checkin - added error message text wrong. 2011-03-20 02:00:52 +00:00
Zdenek Kabelac
681858db90 Improve debug stack trace
dm_check_version reports log_error() - so use return_NULL.
2011-03-18 13:21:02 +00:00
Milan Broz
52a5cd31c4 Mitigate some warnings if running as non-root user.
LVM doesn't behave correctly if running as non-root user,
there is warning when it detects it.

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

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

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

N.B. In future code should support user roles, some more
drastic checks in code are probably contraproductive now.
2011-03-18 12:17:57 +00:00
Zdenek Kabelac
36b9ec636d Keep pool name also for pool-fast
It's cheap to keep this name - and it is useful for 'non pool debug code'
compilation.
2011-03-10 14:49:01 +00:00
Zdenek Kabelac
8b6ce11d02 Use void pointer instead of char for binary key
dm_hash binary functions takes void* key - so there is no need to cast
pointers to char* (also the hash key does not have trailing '\0').

This is slight API change, but presents no change for the API user side
it just allows to write code easier as the casting could be removed.
2011-03-10 12:48:40 +00:00
Zdenek Kabelac
e134ce7c3c Fix reading byte from char params[-1] position
When the ->params string is empty - memory access is made on the byte
before allocated buffer (catched by valgrind) - in the case it would
constain 0x20 - it would even overwrite this buffer.
So fix by checking len > 0 before doing such access.
Also slightly optimise this loop from repeated strlen call.
2011-03-08 22:43:19 +00:00
Milan Broz
688be28794 Move secure flag warning to verbose level.
This feature is not yet upstream and becuase cryptsetup in next version
uses this flag, it will cause a lot of noise on old kernels.
2011-03-05 21:17:19 +00:00
Peter Rajnoha
eb36643cb7 Lower severity of selabel_lookup and matchpathcon failure to log_debug. 2011-03-03 13:05:40 +00:00
Zdenek Kabelac
85a1ca1c4b Indent case part properly 2011-03-02 08:41:55 +00:00
Zdenek Kabelac
63284817c7 Add missing return 2011-03-02 08:40:28 +00:00
Alasdair Kergon
d0e3d474d1 Fix dm_udev_wait calls in dmsetup to occur before readahead display not after.
Include an implicit dm_task_update_nodes() within dm_udev_wait().
2011-03-02 00:29:57 +00:00
Alasdair Kergon
8f91593c25 Fix _create_and_load_v4 not to lose the --addnodeoncreate setting (1.02.62). 2011-03-01 23:27:06 +00:00
Zdenek Kabelac
9afafc7a3c Fix void pointer arithmetic warning in pool debug code 2011-02-28 19:54:30 +00:00
Mike Snitzer
7d9c99e8e7 Add inactive table query support for kernel driver >= 4.11.6 (RHEL 5.7). 2011-02-21 16:26:23 +00:00
Alasdair Kergon
a8d13f9499 Handle decimal digits with --units instead of ignoring them silently.
Fix remaining warnings and compile with -Wpointer-arith.
2011-02-18 23:09:55 +00:00
Zdenek Kabelac
eb4188830e Add debug message for open_count failure
Report  open_count problem as debug.

Function using _node_has_closed_parents decides whether
it's error or could be ignored.
2011-02-18 16:13:56 +00:00
Zdenek Kabelac
2f321615f2 API change - support more const arg
As dm_report_field_string() doesn't modify content of data pointer,
it can be marked as const.

It's slight API change - but doesn't require any change on the user side
and supports wider range of arguments without const casting.
(i.e. we may use as paramater const lv struct this way:  &lv->name)
2011-02-18 14:38:47 +00:00
Zdenek Kabelac
d5e9ddaaee Revert DEBUG_MEM cleanup commit
As functions compiled within this define are apparently stil part of the public API,
(though lvm2 code is never using them unless this define is used for compilation),
keep functions available in the code for now -> revert.
2011-02-08 15:52:00 +00:00
Alasdair Kergon
6c7b95f281 pre-release 2011-02-04 22:07:43 +00:00
Alasdair Kergon
fe7a45c331 Warn if secure data flag requested but not supported by kernel. 2011-02-04 21:26:33 +00:00
Zdenek Kabelac
880507498a Add --addnodeonresume, --addnodeoncreate
Add new function dm_task_set_add_node() to select between 2 types
of node creation in device directory.

DM_ADD_NODE_ON_RESUME is now default and ensures node is created on
resume. Old original behavior is accessible with DM_ADD_NODE_ON_CREATE.
In this case node would be created during dmsetup create --notable.

For the user 2 new options for dmsetup create are added:
[{--addnodeonresume | --addnodeoncreate }]

Properly working node creation on resume is needed for proper operation
stacking and ability to correctly check in which state the device should
after whole udev transation.
2011-02-04 19:33:53 +00:00
Zdenek Kabelac
f5f6dcbc62 Fix operation node stacking for consecutive dm ops
With the ability to stack many operations in one udev transaction -
in same cases we are adding and removing same device at the same time
(i.e. deactivate followed by activate).

This leads to a problem of checking stacked operations:
i.e. remove /dev/node1 followed by create /dev/node1

If the node creation is handled with udev - there is a problem as
stacked operation gives warning about existing node1 and will try to
remove it - while next operation needs to recreate it.

Current code removes all previous stacked operation if the fs op is
FS_DEL - patch adds similar behavior for FS_ADD - it will try to
remove any 'delete' operation if udev is in use.

For FS_RENAME operation it seems to be more complex. But as we
are always stacking FS_READ_AHEAD after FS_ADD operation -
should be safe to remove all previous operation on the node
when udev is running.

Code does same checking for stacking libdm and liblvm operations.

As a very simple optimization counters were added for each stacked ops
type to avoid unneeded list scans if some operation does not exists in
the list.

Enable skipping of fs_unlock() (udev sync) if only DEL operations are staked.
as we do not use lv_info for already deleted nodes.
2011-02-04 19:14:39 +00:00
Milan Broz
2b29daaaa6 Suport DM_SECURE_DATA_FLAG.
It will be user for cryptsetup to ensure buffers are properly
wiped when sending sensitive data (key).
2011-02-04 16:08:11 +00:00
Peter Rajnoha
1e88b1125a Add a debug message when uevent is not generated and we call udev_complete internally. 2011-01-31 11:54:55 +00:00
Zdenek Kabelac
bc49609c6f Compile code for memory debuging only with DEBUG_MEM
When it's not in use - do not compile this code.
Improves lcov code coverage results for this code a lot :)
2011-01-28 16:01:32 +00:00
Zdenek Kabelac
a5c6acf22a Skip NULL check before dm_free
dm_free checks for NULL itself.
2011-01-28 10:16:04 +00:00
Zdenek Kabelac
4b79aeb0ea Initialize pool object for each row
Fix assert abort of dmsetup (when compiled with pool debug)
dmsetup splitname --nameprefixes --noheadings --rows gvg-a2

Move pool begin in the inner loop - otherwise it would using
already 'ended' pool object.
2011-01-25 21:51:30 +00:00
Alasdair Kergon
a8de276520 Replace fs_unlock by sync_local_dev_names to notify local clvmd. (2.02.80)
Introduce sync_local_dev_names and CLVMD_CMD_SYNC_NAMES to issue fs_unlock.
2011-01-12 20:42:50 +00:00
Zdenek Kabelac
b3c6850b1c Define DM_COOKIE_AUTO_CREATE
TODO: Use it also for already written code.
2011-01-10 13:42:31 +00:00
Peter Rajnoha
8d5391f1c3 Export DM_CONTROL_NODE_UMASK and use it while creating /dev/mapper/control. 2011-01-04 14:43:53 +00:00
Zdenek Kabelac
9e06310aab Use const char* for offset calculation
As 'const' types are also passed to macro dm_list_struct_base -
keep offset calculation with const char pointers.
Fixes several gcc constness warnings.
2010-12-20 13:39:12 +00:00
Zdenek Kabelac
303923fbf1 Use const char* const * for dm_regex_create()
Change API interface to accept even completely const array patterns.

This should present no change for libdm users and allows to pass
pattern arrays without cast to const char **.
2010-12-20 13:23:11 +00:00
Peter Rajnoha
7e0db38528 HAVE_SELINUX again 2010-12-13 12:44:09 +00:00
Peter Rajnoha
cb12e3fc9f #ifdef HAVE_SELINUX and #ifdef HAVE_SELINUX_LABEL_H 2010-12-13 12:30:04 +00:00
Peter Rajnoha
c0920fbf2a Missing #elif HAVE_SELINUX 2010-12-13 12:18:38 +00:00
Peter Rajnoha
7dfce0e467 Add new dm_prepare_selinux_context fn to libdevmapper and use it throughout.
Detect existence of new SELinux selabel interface during configure.
Use new dm_prepare_selinux_context instead of dm_set_selinux_context.

We should set the SELinux context before the actual file system object creation.
The new dm_prepare_selinux_context function sets this using the selabel_lookup
fn in conjuction with the setfscreatecon fn. If selinux/label.h interface
(that should be a part of the selinux library) is not found during configure,
we fallback to the original matchpathcon function instead.
2010-12-13 10:43:56 +00:00
Zdenek Kabelac
8865a4c19e Add stack trace for error path
If dm_task_set_cookie() fails print stack trace, but keep going on.
2010-11-30 22:40:19 +00:00
Zdenek Kabelac
5b8abb1240 Add error path stack traces
Check for errors from dm_task_set_name() and dm_task_run().
Add stack traces for error paths.
Return 0 if some error is found.
2010-11-30 22:32:44 +00:00
Zdenek Kabelac
2e3be4f3fd Optimize lookup table read
Reread lookup table only when needed.
2010-11-29 14:25:13 +00:00
Zdenek Kabelac
4cb0f557d9 Remove dead assignment in _step_matcher
'ns' is not used after this assignment and it is reassigned with the following
code, so dropping this assignment.
2010-11-29 12:43:49 +00:00
Zdenek Kabelac
5f3325fcf1 Remove dead assignment in _mirror_emit_segment_line
Remove unused 'r' assignment.
2010-11-29 12:42:10 +00:00
Zdenek Kabelac
cbecd3cd11 Remove dead assignment in dm_tree_node_add_mirror_target_log
'seg' is never used - remove it.
2010-11-29 11:26:00 +00:00
Zdenek Kabelac
8661190736 Cleanup remove test for NULL
dm_free is testing NULL itself
2010-11-29 10:11:50 +00:00
Zdenek Kabelac
f46de65682 Do not call dm_task_destroy with NULL 2010-11-23 18:29:06 +00:00
Zdenek Kabelac
b2594b047b Move va_end(ap) so we do not leave with return -1 without calling it.
Remove unneeded ';'
2010-11-23 15:00:52 +00:00
Alasdair Kergon
ef3d8e18d3 Fix _output_field crash from field_id free with DEBUG_MEM. (Phillip Susi) 2010-11-19 13:17:27 +00:00
Alasdair Kergon
31ed6045f9 lost line 2010-11-02 20:10:35 +00:00
Alasdair Kergon
4b429b6c33 Fix regex optimiser not to ignore RHS of OR nodes in _find_leftmost_common. 2010-11-02 19:56:33 +00:00
Peter Rajnoha
2bea18e504 Use dm_strdup/dm_free instead of strdup/free. 2010-11-01 13:50:51 +00:00
Peter Rajnoha
a83c7816e4 Allocate buffer for reporting functions dynamically to support long outputs.
Fix memory leak of field_id in _output_field function.

There's been a patch added recently to use dynamic allocation for metadata
tags buffer to remove the 4k limit (for writing metadata out). However, when
using reporting commands like vgs and lvs, we still need to fix libdm reporting
functions themselves to support such long outputs. So the buffer used in those
reporting functions is dynamic now.

The patch also includes a fix for field_id memory leak which was found in
the _output_field function.
2010-11-01 13:31:55 +00:00
Zdenek Kabelac
84cc478cc4 Use static indentifier for internal functions
Functions _align_chunk() and  _new_chunk() are used only internally inside
pool-fast.c - so keep them static inside this object file.
2010-10-26 08:59:05 +00:00
Zdenek Kabelac
a636bccaba Use const pointer for return value of dm_basename
Fix return pointer to const as it is created from passed input const pointer.
2010-10-25 13:13:53 +00:00
Alasdair Kergon
1b7750c4bd Use a more-generic name for the new kernel flag so list_devices can share it. 2010-10-25 11:44:20 +00:00
Petr Rockai
d95a85ca36 Implement dmeventd -R, allowing dmeventd to be restarted without losing
monitoring state.
2010-10-20 15:12:12 +00:00
Alasdair Kergon
57a8279442 Add --setuuid to dmsetup rename.
Add dm_task_set_newuuid to set uuid of mapped device post-creation. (pjones)
2010-10-15 01:10:27 +00:00
Alasdair Kergon
ac0252ca07 Add dm_zalloc and use it and dm_pool_zalloc throughout. 2010-09-30 21:06:50 +00:00
Dave Wysochanski
d6fbd0db32 Add macro definitions to report infrastructure for character array length.
Rather than hard code the size of the field, use a #define, so we can re-use.
The #define will be needed in a future patch when we extend the reporting
infrastructure to have 'get' and 'set' functions for each field, allowing
lvm2app functions which query any report field.  In order to provide a
generic lookup based on the field id, we will define a type containing this
field id, and thus, we will need to re-use the length of this string as
it's defined inside libdevmapper.h.
2010-08-20 12:44:30 +00:00
Peter Rajnoha
88b97d8f30 Fix dm-mod autoloading logic to not assume control node is set correctly.
We can't rely on the fact that udev should prepare the node with right major
and minor number to trigger the module autoloading. We have to take into
account that the node could be missing or it could exist with improper
major and minor number assigned (e.g. from previous kernel versions in
an environment with static nodes and without udev). Make any corrections
if needed!
2010-08-18 13:11:56 +00:00
Peter Rajnoha
2d7614322e dm-mod autoloading support is in kernel 2.6.36 actually. 2010-08-16 11:13:18 +00:00
Joe Thornber
0ae41c4412 [REGEX] fix a long standing off-by-one error (found by valgrind-pool) 2010-08-09 10:58:27 +00:00
Joe Thornber
52e1564fdd [MM] Make valgrind aware of the pool allocators
./configure with --enable-valgrind-pool to enable this.
2010-08-09 10:56:01 +00:00
Joe Thornber
fae2c49259 [REGEX] fix bug in matcher that was causing segfault with chars of 0x80 and over. 2010-08-09 10:30:52 +00:00
Joe Thornber
7def56f1e4 [REGEX] Parse regexes that contain chars with value > 0x80
This is a long standing issue.  Fixed by casting a char value to
unsigned char before using it as an index into a bitset.
2010-08-09 10:29:42 +00:00
Zdenek Kabelac
59f8043d7c Fix 'void*' arithmetic warnings in dbg_malloc.c.
Use more readable char[idx] access instead of *char+idx access.
2010-08-03 13:24:07 +00:00
Zdenek Kabelac
30168792f4 Fix 'void*' arithmetic warning in some functions from libdm-iface.c. 2010-08-03 13:16:21 +00:00
Zdenek Kabelac
9f926fd060 Use void parameter for function definition. 2010-08-03 13:06:35 +00:00
Zdenek Kabelac
56081fe97b Clean generated files .exported_symbols_generated, example.conf for distclean. 2010-08-03 13:00:45 +00:00
Peter Rajnoha
d87427446c Add check for kernel semaphore support and disable udev_sync if not available.
udev_sync feature requires semaphores (part of System V IPC) to be configured
in kernel (CONFIG_SYSVIPC). Check whether it is supported and if not, give
a warning message and disable udev synchronisation code automatically to
avoid any further error states and associated problems.

One should use the kernel with System V IPC support enabled or libdevmapper
with udev_sync feature disabled.
2010-08-03 07:56:03 +00:00
Peter Rajnoha
f89f7955fc Revert unsuccessful table load preparation in combined "create, load and resume" scenario.
There was missing "revert" call in _create_and_load_v4 fn while the preparation
for table load ends up with failure in create/load/resume sequence. Otherwise
we could end up with a device being created, but not table-loaded nor resumed.

Even though the table is not loaded and the device is not resumed at this
stage, we still need to synchronize with udev when calling the revert
"remove" ioctl - there's still a remove uevent generated! The "revert"
code does exactly that.
2010-07-28 10:30:28 +00:00
Alasdair Kergon
4cc5adf46c Fix dm_create_lockfile error paths - incorrectly unlinked in-use lockfile.
(Jan Friesse)
2010-07-27 21:56:14 +00:00
Jonathan Earl Brassow
405c4a45d8 It's not enough to check for the kernel module in the case of cluster
mirrors, we must also check that the log daemon (cmirrord) is running.
The log module can be auto-loaded, but the daemon cannot be
"auto-started".  Failing to check for the daemon produces cryptic
messages that customers have a hard time deciphering.  (The system
messages do report that the log daemon is not running, but people
don't seem to find this message easily.)

Here are examples of what is printed when the module is available,
but the log daemon has not been started.

[root@bp-01 LVM2]# lvcreate -m1 -l1 -n lv vg
  Shared cluster mirrors are not available.

[root@bp-01 LVM2]# lvcreate -m1 -l1 -n lv vg -v
    Setting logging type to disk
    Finding volume group "vg"
    Archiving volume group "vg" metadata (seqno 3).
    Creating logical volume lv
    Executing: /sbin/modprobe dm-log-userspace
    Cluster mirror log daemon is not running
  Shared cluster mirrors are not available.
    Creating volume group backup "/etc/lvm/backup/vg" (seqno 4).
2010-07-21 13:40:21 +00:00
Joe Thornber
5b39a977ca [REGEX] calculate dfa states on demand 2010-07-21 12:09:12 +00:00