1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-12-24 16:23:50 +03:00

Compare commits

..

145 Commits

Author SHA1 Message Date
Alasdair Kergon
32d9126094 . 2006-10-12 17:42:40 +00:00
Alasdair Kergon
db43314e50 missing mesg 2006-10-12 17:41:21 +00:00
Alasdair Kergon
68d2baeb65 pre-release 2006-10-12 17:37:42 +00:00
Alasdair Kergon
1fd5f562d3 noflush code fixes: missing debug log; non-standard variable name 2006-10-12 17:29:05 +00:00
Alasdair Kergon
48e02f2086 remove unused variable 2006-10-12 17:18:40 +00:00
Alasdair Kergon
eab7b2b581 fix dmsetup usage display (missing \n and --noflush wrong place) 2006-10-12 17:09:09 +00:00
Alasdair Kergon
45abade7fc Add suspend noflush support.
Add basic dmsetup loop support.
2006-10-12 15:42:25 +00:00
Alasdair Kergon
5372fc4b43 Test message to lvm-devel list. 2006-10-10 17:20:40 +00:00
Patrick Caulfield
4e2f240c98 Add clvmd call to return the cluster name. 2006-10-09 14:11:57 +00:00
Alasdair Kergon
bb3605518d add cling allocation policy 2006-10-08 12:01:13 +00:00
Alasdair Kergon
3ef6d37f27 . 2006-10-07 23:42:03 +00:00
Alasdair Kergon
88e9f2f7f4 check_contiguous to use for_each_pv 2006-10-07 23:40:36 +00:00
Alasdair Kergon
704a447df9 More work towards pv->size always holding the same value in internal metadata.
Store it in external text metadata as dev_size, and estimate it if not
present when metadata is read back in.
2006-10-07 23:17:17 +00:00
Alasdair Kergon
a5fcb26a33 rely on pv_setup functions to fix up pe_count 2006-10-07 23:06:18 +00:00
Alasdair Kergon
2491a61481 Accept regionsize with lvconvert. 2006-10-07 23:04:36 +00:00
Alasdair Kergon
91831d51ed more refactoring 2006-10-07 16:00:28 +00:00
Alasdair Kergon
174f0c19f7 Extend _for_each_pv() to allow termination without error. 2006-10-07 12:41:06 +00:00
Alasdair Kergon
de6fadfb4f abstract _is_contiguous() 2006-10-07 11:34:53 +00:00
Alasdair Kergon
f946db3e00 move _for_each_pv() 2006-10-07 11:23:22 +00:00
Alasdair Kergon
8d05e5bc31 Remove duplicated pv arg from _check_contiguous(). 2006-10-07 11:00:09 +00:00
Alasdair Kergon
cfb46820e4 Accept regionsize with lvconvert 2006-10-07 10:47:05 +00:00
Alasdair Kergon
081f1cbcc2 Correct regionsize default on lvcreate man page (MB). 2006-10-07 10:43:40 +00:00
Alasdair Kergon
7bc6da326f Add report columns with underscore before field names ending 'size'. 2006-10-07 10:42:27 +00:00
Patrick Caulfield
cd95a0df7b Use strncpy rather than strcpy 2006-10-06 10:06:37 +00:00
Patrick Caulfield
82fa497c16 Fix clvmd bug that could cause it to die when a node with a long name crashed. 2006-10-06 10:06:10 +00:00
Alasdair Kergon
44fd345206 Fix format_text mda_setup pv->size and pv_setup pe_count calculations.
(This area of the code needs a lot more work.)
2006-10-05 22:02:52 +00:00
Alasdair Kergon
088e1c9db4 Fix _for_each_pv() for mirror with core log. 2006-10-05 21:24:48 +00:00
Alasdair Kergon
d4f16e666e Add lvm_dump.sh script to create a tarball of debugging info from a system. 2006-10-05 18:42:33 +00:00
Patrick Caulfield
8233cfd371 Vastly improve the errors returned to the user from clvmd.
It now captures the error messages that are generated and returns them
in the reply packet rather than just telling the user to check syslog.
2006-10-05 13:55:50 +00:00
Alasdair Kergon
ff05e2e30d Remove unused #defines from filter-md.c. 2006-10-04 16:03:17 +00:00
Patrick Caulfield
a8ea7dd3fb Make clvmd restart init script wait until clvmd has died before starting it. 2006-10-04 08:42:14 +00:00
Patrick Caulfield
96f70a5303 Update man page for clvmd -R 2006-10-04 08:28:17 +00:00
Patrick Caulfield
f1604c3e69 Add -R switch to clvmd.
This option will instruct all the clvmd daemons in the cluster to reload their device cache
2006-10-04 08:22:16 +00:00
Alasdair Kergon
c42c8c5192 Test. Future commit messages should now also go to the dm-devel list
(450 subscribers) for discussion as well as the read-only dm-cvs list
(just 15 subscribers).
2006-10-03 21:51:28 +00:00
Alasdair Kergon
5facb53a41 exclude targets that are always built-in 2006-10-03 18:02:06 +00:00
Alasdair Kergon
d039ce89af Add LV column to reports listing kernel modules needed for activation. 2006-10-03 17:55:20 +00:00
Alasdair Kergon
bc7605103f Show available fields if report given invalid field. (e.g. lvs -o list) 2006-10-02 16:46:27 +00:00
Alasdair Kergon
d305d655d4 Fix compiler warnings in percent arg. [pjc] 2006-10-02 16:15:03 +00:00
Alasdair Kergon
4ef1220b16 Add timestamp functions with --disable-realtime configure option. [AJ] 2006-09-30 20:02:02 +00:00
Alasdair Kergon
a4fef143cd Add %VG, %LV and %FREE suffices to lvcreate/lvresize --extents arg.
e.g. lvcreate -l 100%FREE to create an LV using all available space.
     lvextend -l 50%LV to increase an LV by 50% of its existing size.
     lvcreate -l 20%VG to create an LV using 20% of the total VG size.
2006-09-26 09:35:43 +00:00
Alasdair Kergon
74ecb724a9 Fix two potential NULL pointer derefs in error cases in vg_read(). 2006-09-21 20:25:54 +00:00
Alasdair Kergon
af235897ab Separate --enable-cluster from locking lib options in lvmconf.sh. 2006-09-20 17:36:47 +00:00
Alasdair Kergon
5ec4e458b5 Supply missing comma. [via Debian] 2006-09-19 20:20:40 +00:00
Alasdair Kergon
2dae63ce21 post-release 2006-09-19 19:36:59 +00:00
Alasdair Kergon
be748fe33b pre-release 2006-09-19 19:15:10 +00:00
Alasdair Kergon
7408340b6a Fix lvconvert mirror change case detection logic.
Fix mirror log detachment so it correctly becomes a standalone LV.
2006-09-19 19:13:41 +00:00
Alasdair Kergon
29eb92446e post-release 2006-09-19 17:50:58 +00:00
Alasdair Kergon
ae6918742e pre-release 2006-09-19 17:43:03 +00:00
Alasdair Kergon
863484bb65 Reorder mm bounds_check code to reduce window for a dmeventd race. (dm_free_aux) 2006-09-19 17:30:04 +00:00
Alasdair Kergon
1cd7ebce4c Extend _check_contiguous() to detect single-area LVs.
Include mirror log (untested) in _for_each_pv() processing.
Use MIRROR_LOG_SIZE constant.
Remove struct seg_pvs from _for_each_pv() for generalisation.
Avoid adding duplicates to list of parallel PVs to avoid.
2006-09-11 21:14:56 +00:00
Alasdair Kergon
eef8c7862e Fix several incorrect comparisons in parallel area avoidance code.
Fix segment lengths when flattening existing parallel areas.
Log existing parallel areas prior to allocation.
Fix mirror log creation when activation disabled.
2006-09-11 14:24:58 +00:00
Alasdair Kergon
b52375d446 fix vgreduce clustered check 2006-09-07 23:23:45 +00:00
Alasdair Kergon
6e2babc2ce When using local file locking, skip clustered VGs.
Add fallback_to_clustered_locking and fallback_to_local_locking parameters.
2006-09-02 01:18:17 +00:00
Alasdair Kergon
08e253bed1 lvm.static uses built-in cluster locking instead of external locking.
Don't attempt to load shared libraries if built statically.
2006-08-31 22:21:00 +00:00
Alasdair Kergon
c6661477a2 Change default locking_lib to liblvm2clusterlock.so. 2006-08-31 20:56:33 +00:00
Alasdair Kergon
415cfd99a0 Add skip_dev_dir() to process command line VGs. 2006-08-25 23:02:33 +00:00
Patrick Caulfield
8c2e37381a Stop clvmd complaining about nodes that have left the cluster 2006-08-24 12:45:05 +00:00
Alasdair Kergon
45df79feba stub.h shouldn't be here 2006-08-22 15:56:06 +00:00
Patrick Caulfield
5824f992b7 Add needed new parameter to create_toolcontext(). 2006-08-22 09:49:20 +00:00
Alasdair Kergon
b0b60fafd5 Move lvm_snprintf into libdevmapper. 2006-08-21 12:54:53 +00:00
Alasdair Kergon
8d98b02ba2 Add dm_snprintf 2006-08-21 12:52:39 +00:00
Alasdair Kergon
a93fe79bc4 Add dm_split_words() and dm_split_lvm_name() to libdevmapper. 2006-08-21 12:07:03 +00:00
Alasdair Kergon
4aebd7be37 fix lvm.conf (5) refs 2006-08-18 22:35:59 +00:00
Alasdair Kergon
3170a5db32 mirror man page tweaks 2006-08-18 22:27:01 +00:00
Alasdair Kergon
3605b9eef6 Add mirroring into man pages 2006-08-18 21:49:19 +00:00
Alasdair Kergon
a945f1fde2 reorder bounds check code 2006-08-18 21:38:58 +00:00
Alasdair Kergon
461a997b5b Prevent mirror renames. 2006-08-18 21:19:54 +00:00
Alasdair Kergon
a80afd7b4e Move CMDLIB code into separate file and record whether static build. 2006-08-18 21:17:18 +00:00
Alasdair Kergon
aad2b51d85 post 2006-08-17 20:04:38 +00:00
Alasdair Kergon
36a9a81ff1 wrappers files 2006-08-17 19:56:28 +00:00
Alasdair Kergon
42c88546ae pre-release 2006-08-17 19:55:50 +00:00
Alasdair Kergon
0f0e86ef9b Fix PE_ALIGN for pagesize over 32KB. 2006-08-17 19:53:36 +00:00
Alasdair Kergon
98efd9a857 wrap PE_ALIGN 2006-08-17 19:30:59 +00:00
Alasdair Kergon
a0c27d95b7 Separate out LVM1_PE_ALIGN. 2006-08-17 19:15:27 +00:00
Alasdair Kergon
984651d99d Add lvm_getpagesize wrapper. 2006-08-17 18:23:44 +00:00
Alasdair Kergon
c6f7370b30 Add --maxphysicalvolumes to vgchange. 2006-08-16 14:41:42 +00:00
Alasdair Kergon
3e4b8e8985 post-release 2006-08-15 19:13:06 +00:00
Alasdair Kergon
73f08b98d2 pre-release 2006-08-15 19:06:09 +00:00
Alasdair Kergon
8607a74206 post-release 2006-08-15 17:43:10 +00:00
Alasdair Kergon
8339f3ceb3 pre-release 2006-08-15 17:38:38 +00:00
Alasdair Kergon
c0c9f3cc19 fix getopt_long error check 2006-08-10 20:53:21 +00:00
Alasdair Kergon
81f4813c29 Add --table argument to dmsetup for a one-line table.
Abort if errors are found during cmdline option processing.
2006-08-10 14:11:03 +00:00
Alasdair Kergon
94f57745b9 Add checks for duplicate LV name, lvid and PV id before writing metadata.
Report all sanity check failures, not just the first.
2006-08-09 19:33:25 +00:00
Alasdair Kergon
54fb2ebbe0 Add lockfs indicator to debug output. 2006-08-08 21:22:31 +00:00
Alasdair Kergon
02d122b65b Fix missing lockfs on first snapshot creation. 2006-08-08 21:20:00 +00:00
Alasdair Kergon
df0a5561a1 Add --trustcache option to reporting commands in preparation for supporting
event-driven model.  Without changes to the way the cache gets updated, the
option is currently unreliable without a global lock to prevent any lvm2
commands from running concurrently.
2006-08-01 14:56:33 +00:00
Alasdair Kergon
f7c55da7d0 Fix locking for mimage removal. 2006-07-20 20:37:10 +00:00
Alasdair Kergon
b385f701ce Fix clvmd_init_rhel4 'status' exit code. 2006-07-19 18:55:58 +00:00
Alasdair Kergon
05dd42f443 post-release 2006-07-17 14:39:54 +00:00
Alasdair Kergon
36d816d5cb pre-release 2006-07-17 14:32:00 +00:00
Alasdair Kergon
92a6746e70 Fix activation logic in lvchange --persistent. 2006-07-10 19:39:14 +00:00
Alasdair Kergon
1728848a39 Don't ignore persistent minor numbers when activating. 2006-07-10 19:17:40 +00:00
Alasdair Kergon
f9eb4e7487 test 2006-07-05 21:07:35 +00:00
Alasdair Kergon
d0b9f33aeb test 2006-07-05 21:03:15 +00:00
Alasdair Kergon
718583b241 Append full patch to checkin emails. 2006-07-05 21:01:06 +00:00
Alasdair Kergon
6737127e9a Avoid duplicate dmeventd subdir with 'make distclean'. 2006-07-05 17:29:12 +00:00
Alasdair Kergon
19a7b4479b add dlerror to another error path 2006-07-05 17:26:36 +00:00
Alasdair Kergon
c340647502 Differentiate between the two 'log device failed' cases in vgreduce. 2006-07-04 19:52:47 +00:00
Alasdair Kergon
0f987d2982 Use RTLD_GLOBAL when loading shared libraries. 2006-07-04 19:40:27 +00:00
Alasdair Kergon
52bcaed169 Add some forgotten memlock checks to _vg_read to protect against full scans. 2006-07-04 19:36:49 +00:00
Alasdair Kergon
177bd565ac Add mutex to dmeventd_mirror to avoid concurrent execution. 2006-07-04 18:57:27 +00:00
Alasdair Kergon
c801c32fc5 If VG is already consistent with --removemissing, return success not failure. 2006-07-04 18:51:59 +00:00
Alasdair Kergon
d090cf3058 force remove fixes 2006-06-18 11:51:46 +00:00
Alasdair Kergon
1e4b82cc94 Add --force to dmsetup remove* to load error target. [Untested.]
Update dmsetup man page.
2006-06-18 11:35:04 +00:00
Alasdair Kergon
3426f31184 dmsetup remove_all also performs mknodes. 2006-06-17 16:12:41 +00:00
Alasdair Kergon
b4fb7af1df Don't suppress identical table reloads if permission changes. 2006-06-14 22:00:03 +00:00
Alasdair Kergon
b36647598b Fix return code if VG specified on command line is not found. 2006-06-14 20:27:15 +00:00
Alasdair Kergon
fd6b94f20e Fix PV tools to include orphaned PVs in default output again. 2006-06-14 20:11:22 +00:00
Alasdair Kergon
296dc0ed8a test checkin 2006-06-12 17:34:20 +00:00
Alasdair Kergon
4f869e14d6 test checkin 2006-06-12 17:32:43 +00:00
Alasdair Kergon
5704270e9d test checkin 2006-06-12 17:30:29 +00:00
Alasdair Kergon
505b381e85 checkin test 2006-06-12 17:18:31 +00:00
Patrick Caulfield
da6cb15393 Fix "Unaligned access" when using clvm
bz#194626
2006-06-12 09:46:35 +00:00
Alasdair Kergon
16843f6cc8 Fix an extra dev_close in a label_read error path. 2006-06-08 22:15:49 +00:00
Alasdair Kergon
64f3ad1fd4 change two files in different directories 2006-06-06 17:44:11 +00:00
Alasdair Kergon
ff4c4f99b3 test 2006-06-06 17:42:20 +00:00
Alasdair Kergon
f5d2e09569 test one change 2006-06-06 17:41:30 +00:00
Alasdair Kergon
f2bdbe0d4d Fix target_register_events args. 2006-05-25 13:32:26 +00:00
Alasdair Kergon
c51a13caa6 Prevent snapshots of mirrors. 2006-05-24 13:58:14 +00:00
Alasdair Kergon
7840c78a23 Add DISTCLEAN_TARGETS to make template for configure.h.
More fixes to error paths.
2006-05-16 20:53:13 +00:00
Alasdair Kergon
c706f3246b fix error path 2006-05-16 20:42:01 +00:00
Alasdair Kergon
608eedf88d Fix lvcreate corelog validation.
Add --config for overriding most config file settings from cmdline.
  Quote arguments when printing command line.
  Remove linefeed from 'initialising logging' message.
  Add 'Completed' debug message.
  Don't attempt library exit after reloading config files.
  Always compile with libdevmapper, even if device-mapper is disabled.
2006-05-16 16:48:31 +00:00
Alasdair Kergon
a564ca82be Fix corelog segment line.
Suppress some compiler warnings.
2006-05-16 16:20:29 +00:00
Patrick Caulfield
c868b1fee2 Add needed include. 2006-05-15 12:32:08 +00:00
Alasdair Kergon
22374f718f fix compile 2006-05-15 11:56:15 +00:00
Alasdair Kergon
abe3cfcf41 post-release 2006-05-12 20:32:39 +00:00
Alasdair Kergon
59db4b50cd fix dev->device 2006-05-12 19:47:40 +00:00
Alasdair Kergon
bdae38765d not reqd 2006-05-12 19:44:42 +00:00
Alasdair Kergon
66d3ceeb61 pre-release 2006-05-12 19:41:43 +00:00
Alasdair Kergon
445dd17db3 Add --monitor to vgcreate and lvcreate to control dmeventd registration.
Propagate --monitor around cluster.
Filter LCK_NONBLOCK in clvmd lock_vg.
2006-05-12 19:16:48 +00:00
Alasdair Kergon
cff78a2577 fix compile 2006-05-12 13:33:22 +00:00
Alasdair Kergon
6a09e64195 Pre-release. 2006-05-11 20:24:07 +00:00
Alasdair Kergon
22eabe5eab M for unsynced mirror 2006-05-11 20:17:17 +00:00
Alasdair Kergon
b69ba36c2d Add --nosync to lvcreate with LV flag NOTSYNCED. 2006-05-11 20:03:40 +00:00
Alasdair Kergon
5240aad22b Use mirror's uuid for a core log. 2006-05-11 19:47:53 +00:00
Alasdair Kergon
2897eb3cb3 Add mirror log fault-handling policy. 2006-05-11 19:45:53 +00:00
Alasdair Kergon
d3f2f00c25 Add DM_CORELOG flag to dm_tree_node_add_mirror_target(). 2006-05-11 19:10:55 +00:00
Alasdair Kergon
bacfb913a0 Avoid a dmeventd compiler warning. 2006-05-11 19:08:02 +00:00
Alasdair Kergon
c99d0236a0 Propagate nosync flag around cluster. 2006-05-11 19:05:21 +00:00
Alasdair Kergon
aac2b655f7 Allow vgreduce to handle mirror log failures. 2006-05-11 19:01:11 +00:00
Alasdair Kergon
126c41e73a Check in-sync status before changing disk log. 2006-05-11 18:56:55 +00:00
Alasdair Kergon
359ee54f0d Add --corelog to lvcreate and lvconvert. 2006-05-11 18:54:04 +00:00
Alasdair Kergon
28ab560907 Create a log header for replacement in-sync mirror log.
Use set_lv() and dev_set() to wipe sections of devices.
Add mirror_in_sync() flag to avoid unnecessary resync on activation.
2006-05-11 18:39:24 +00:00
Alasdair Kergon
ead252fee4 Add mirror_library description to example.conf.
More compile-time cleanup.
2006-05-11 17:58:58 +00:00
Alasdair Kergon
abf67914c4 post-release 2006-05-10 20:46:28 +00:00
152 changed files with 4623 additions and 1689 deletions

View File

@@ -38,6 +38,7 @@ ifeq ($(MAKECMDGOALS),distclean)
lib/snapshot \
po \
test/mm test/device test/format1 test/regex test/filters
DISTCLEAN_TARGETS += lib/misc/configure.h
endif
include make.tmpl

View File

@@ -1 +1 @@
2.02.06-cvs (2006-04-21)
2.02.11-cvs (2006-09-19)

114
WHATS_NEW
View File

@@ -1,5 +1,115 @@
Version 2.02.06 -
=================================
Version 2.02.11 -
=====================================
Add clvmd function to return the cluster name. not used by LVM yet.
Add cling allocation policy.
Change _check_contiguous() to use _for_each_pv().
Extend _for_each_pv() to allow termination without error.
Abstract _is_contiguous().
Remove duplicated pv arg from _check_contiguous().
Accept regionsize with lvconvert.
Add report columns with underscore before field names ending 'size'.
Correct regionsize default on lvcreate man page (MB).
Fix clvmd bug that could cause it to die when a node with a long name crashed.
Add device size to text metadata.
Fix format_text mda_setup pv->size and pv_setup pe_count calculations.
Fix _for_each_pv() for mirror with core log.
Add lvm_dump.sh script to create a tarball of debugging info from a system.
Capture error messages in clvmd and pass them back to the user.
Remove unused #defines from filter-md.c.
Make clvmd restart init script wait until clvmd has died before starting it.
Add -R to clvmd which tells running clvmds to reload their device cache.
Add LV column to reports listing kernel modules needed for activation.
Show available fields if report given invalid field. (e.g. lvs -o list)
Add timestamp functions with --disable-realtime configure option.
Add %VG, %LV and %FREE suffices to lvcreate/lvresize --extents arg.
Fix two potential NULL pointer derefs in error cases in vg_read().
Separate --enable-cluster from locking lib options in lvmconf.sh.
Add a missing comma in lvcreate man page.
Version 2.02.10 - 19th September 2006
=====================================
Fix lvconvert mirror change case detection logic.
Fix mirror log detachment so it correctly becomes a standalone LV.
Extend _check_contiguous() to detect single-area LVs.
Include mirror log (untested) in _for_each_pv() processing.
Use MIRROR_LOG_SIZE constant.
Remove struct seg_pvs from _for_each_pv() to generalise.
Avoid adding duplicates to list of parallel PVs to avoid.
Fix several incorrect comparisons in parallel area avoidance code.
Fix segment lengths when flattening existing parallel areas.
Log existing parallel areas prior to allocation.
Fix mirror log creation when activation disabled.
Don't attempt automatic recovery without proper locking.
When using local file locking, skip clustered VGs.
Add fallback_to_clustered_locking and fallback_to_local_locking parameters.
lvm.static uses built-in cluster locking instead of external locking.
Don't attempt to load shared libraries if built statically.
Change default locking_lib to liblvm2clusterlock.so.
Add skip_dev_dir() to process command line VGs.
Stop clvmd complaining about nodes that have left the cluster.
Move lvm_snprintf(), split_words() and split_dm_name() into libdevmapper.
Add lvconvert man page.
Add mirror options to man pages.
Prevent mirror renames.
Move CMDLIB code into separate file and record whether static build.
Version 2.02.09 - 17th August 2006
==================================
Fix PE_ALIGN for pagesize over 32KB.
Separate out LVM1_PE_ALIGN and pe_align().
Add lvm_getpagesize wrapper.
Add --maxphysicalvolumes to vgchange.
Version 2.02.08 - 15th August 2006
==================================
Add checks for duplicate LV name, lvid and PV id before writing metadata.
Report all sanity check failures, not just the first.
Fix missing lockfs on first snapshot creation.
Add unreliable --trustcache option to reporting commands.
Fix locking for mimage removal.
Fix clvmd_init_rhel4 'status' exit code.
Version 2.02.07 - 17th July 2006
================================
Fix activation logic in lvchange --persistent.
Don't ignore persistent minor numbers when activating.
Use RTLD_GLOBAL when loading shared libraries.
Add some forgotten memlock checks to _vg_read to protect against full scans.
Add mutex to dmeventd_mirror to avoid concurrent execution.
Fix vgreduce --removemissing to return success if VG is already consistent.
Fix return code if VG specified on command line is not found.
Fix PV tools to include orphaned PVs in default output again.
Fixed unaligned access when using clvm.
Fix an extra dev_close in a label_read error path.
Append patches to commit emails.
Fix target_register_events args.
Prevent snapshots of mirrors.
Add DISTCLEAN_TARGETS to make template for configure.h.
More fixes to error paths.
Fix lvcreate corelog validation.
Add --config for overriding most config file settings from cmdline.
Quote arguments when printing command line.
Remove linefeed from 'initialising logging' message.
Add 'Completed' debug message.
Don't attempt library exit after reloading config files.
Always compile with libdevmapper, even if device-mapper is disabled.
Version 2.02.06 - 12th May 2006
===============================
Propagate --monitor around cluster.
Add --monitor to vgcreate and lvcreate to control dmeventd registration.
Filter LCK_NONBLOCK in clvmd lock_vg.
Add --nosync to lvcreate with LV flag NOTSYNCED.
Use mirror's uuid for a core log.
Add mirror log fault-handling policy.
Improve mirror warning messages and tidy dmeventd syslog output.
Propagate nosync flag around cluster.
Allow vgreduce to handle mirror log failures.
Add --corelog to lvcreate and lvconvert.
Create a log header for replacement in-sync mirror log.
Use set_lv() and dev_set() to wipe sections of devices.
Add mirror_in_sync() flag to avoid unnecessary resync on activation.
Add mirror_library description to example.conf.
Fix uuid_from_num() buffer overrun.
Make SIZE_SHORT the default for display_size().
Fix some memory leaks in error paths found by coverity.

View File

@@ -1,3 +1,36 @@
Version 1.02.11 - 12 Oct 2006
==============================
Add suspend noflush support.
Add basic dmsetup loop support.
Switch dmsetup to use dm_malloc and dm_free.
Version 1.02.10 - 19 Sep 2006
=============================
Add dm_snprintf(), dm_split_words() and dm_split_lvm_name() to libdevmapper.
Reorder mm bounds_check code to reduce window for a dmeventd race.
Version 1.02.09 - 15 Aug 2006
=============================
Add --table argument to dmsetup for a one-line table.
Abort if errors are found during cmdline option processing.
Add lockfs indicator to debug output.
Version 1.02.08 - 17 July 2006
==============================
Append full patch to check in emails.
Avoid duplicate dmeventd subdir with 'make distclean'.
Update dmsetup man page.
Add --force to dmsetup remove* to load error target.
dmsetup remove_all also performs mknodes.
Don't suppress identical table reloads if permission changes.
Fix corelog segment line.
Suppress some compiler warnings.
Version 1.02.07 - 11 May 2006
=============================
Add DM_CORELOG flag to dm_tree_node_add_mirror_target().
Avoid a dmeventd compiler warning.
Version 1.02.06 - 10 May 2006
=============================
Move DEFS into configure.h.

157
configure vendored
View File

@@ -310,7 +310,7 @@ ac_includes_default="\
#endif"
ac_default_prefix=/usr
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB CFLOW_CMD CSCOPE_CMD CPP EGREP ALLOCA LIBOBJS POW_LIB MSGFMT MODPROBE_CMD JOBS STATIC_LINK LVM1 POOL SNAPSHOTS MIRRORS OWNER GROUP COPTIMISE_FLAG CLDFLAGS CLDWHOLEARCHIVE CLDNOWHOLEARCHIVE LDDEPS LIB_SUFFIX LVM_VERSION LVM1_FALLBACK DEBUG DEVMAPPER HAVE_LIBDL HAVE_SELINUX CMDLIB LOCALEDIR CONFDIR STATICDIR INTL_PACKAGE INTL CLVMD CLUSTER FSADM DMEVENTD LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB CFLOW_CMD CSCOPE_CMD CPP EGREP ALLOCA LIBOBJS POW_LIB MSGFMT MODPROBE_CMD JOBS STATIC_LINK LVM1 POOL SNAPSHOTS MIRRORS OWNER GROUP COPTIMISE_FLAG CLDFLAGS CLDWHOLEARCHIVE CLDNOWHOLEARCHIVE LDDEPS LIB_SUFFIX LVM_VERSION LVM1_FALLBACK DEBUG DEVMAPPER HAVE_LIBDL HAVE_SELINUX HAVE_REALTIME CMDLIB LOCALEDIR CONFDIR STATICDIR INTL_PACKAGE INTL CLVMD CLUSTER FSADM DMEVENTD LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@@ -853,6 +853,7 @@ Optional Features:
statically. Default is dynamic linking
--enable-readline Enable readline support
--disable-selinux Disable selinux support
--disable-realtime Disable realtime clock support
--enable-debug Enable debugging
--disable-devmapper Disable device-mapper interaction
--disable-o_direct Disable O_DIRECT
@@ -1459,6 +1460,7 @@ case "$host_os" in
DEVMAPPER=yes
ODIRECT=yes
SELINUX=yes
REALTIME=yes
CLUSTER=internal
FSADM=no ;;
darwin*)
@@ -1473,6 +1475,7 @@ case "$host_os" in
DEVMAPPER=yes
ODIRECT=no
SELINUX=no
REALTIME=no
CLUSTER=none
FSADM=no ;;
esac
@@ -7431,6 +7434,17 @@ fi;
echo "$as_me:$LINENO: result: $SELINUX" >&5
echo "${ECHO_T}$SELINUX" >&6
################################################################################
echo "$as_me:$LINENO: checking whether to enable realtime support" >&5
echo $ECHO_N "checking whether to enable realtime support... $ECHO_C" >&6
# Check whether --enable-realtime or --disable-realtime was given.
if test "${enable_realtime+set}" = set; then
enableval="$enable_realtime"
REALTIME=$enableval
fi;
echo "$as_me:$LINENO: result: $REALTIME" >&5
echo "${ECHO_T}$REALTIME" >&6
################################################################################
echo "$as_me:$LINENO: checking whether to build cluster LVM daemon" >&5
echo $ECHO_N "checking whether to build cluster LVM daemon... $ECHO_C" >&6
@@ -7534,14 +7548,6 @@ fi;
echo "$as_me:$LINENO: result: $CMDLIB" >&5
echo "${ECHO_T}$CMDLIB" >&6
if test x$CMDLIB = xyes; then
cat >>confdefs.h <<\_ACEOF
#define CMDLIB 1
_ACEOF
fi
################################################################################
echo "$as_me:$LINENO: checking whether to build fsadm" >&5
echo $ECHO_N "checking whether to build fsadm... $ECHO_C" >&6
@@ -8428,6 +8434,96 @@ echo "$as_me: WARNING: Disabling selinux" >&2;}
fi
fi
################################################################################
if test x$REALTIME = xyes; then
echo "$as_me:$LINENO: checking for clock_gettime function" >&5
echo $ECHO_N "checking for clock_gettime function... $ECHO_C" >&6
echo "$as_me:$LINENO: checking for clock_gettime in -lrt" >&5
echo $ECHO_N "checking for clock_gettime in -lrt... $ECHO_C" >&6
if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lrt $LIBS"
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char clock_gettime ();
int
main ()
{
clock_gettime ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_cv_lib_rt_clock_gettime=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_lib_rt_clock_gettime=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
echo "$as_me:$LINENO: result: $ac_cv_lib_rt_clock_gettime" >&5
echo "${ECHO_T}$ac_cv_lib_rt_clock_gettime" >&6
if test $ac_cv_lib_rt_clock_gettime = yes; then
HAVE_REALTIME=yes
else
HAVE_REALTIME=no
fi
echo "$as_me:$LINENO: result: $HAVE_REALTIME" >&5
echo "${ECHO_T}$HAVE_REALTIME" >&6
if test x$HAVE_REALTIME = xyes; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_REALTIME 1
_ACEOF
LIBS="-lrt $LIBS"
else
{ echo "$as_me:$LINENO: WARNING: Disabling realtime clock" >&5
echo "$as_me: WARNING: Disabling realtime clock" >&2;}
fi
fi
################################################################################
for ac_header in getopt.h
@@ -10699,7 +10795,6 @@ done
fi
if test x$DEVMAPPER = xyes; then
for ac_header in libdevmapper.h
do
@@ -10854,7 +10949,6 @@ fi
done
fi
if test x$HAVE_SELINUX = xyes; then
@@ -11053,45 +11147,6 @@ else
echo "${ECHO_T}no" >&6
fi
# Extract the first word of "ifconfig", so it can be a program name with args.
set dummy ifconfig; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_path_MODPROBE_CMD+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
case $MODPROBE_CMD in
[\\/]* | ?:[\\/]*)
ac_cv_path_MODPROBE_CMD="$MODPROBE_CMD" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_MODPROBE_CMD="$as_dir/$ac_word$ac_exec_ext"
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
;;
esac
fi
MODPROBE_CMD=$ac_cv_path_MODPROBE_CMD
if test -n "$MODPROBE_CMD"; then
echo "$as_me:$LINENO: result: $MODPROBE_CMD" >&5
echo "${ECHO_T}$MODPROBE_CMD" >&6
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
if test x$MODPROBE_CMD != x; then
@@ -11144,6 +11199,7 @@ fi
################################################################################
@@ -11838,6 +11894,7 @@ s,@DEBUG@,$DEBUG,;t t
s,@DEVMAPPER@,$DEVMAPPER,;t t
s,@HAVE_LIBDL@,$HAVE_LIBDL,;t t
s,@HAVE_SELINUX@,$HAVE_SELINUX,;t t
s,@HAVE_REALTIME@,$HAVE_REALTIME,;t t
s,@CMDLIB@,$CMDLIB,;t t
s,@LOCALEDIR@,$LOCALEDIR,;t t
s,@CONFDIR@,$CONFDIR,;t t

View File

@@ -42,6 +42,7 @@ case "$host_os" in
DEVMAPPER=yes
ODIRECT=yes
SELINUX=yes
REALTIME=yes
CLUSTER=internal
FSADM=no ;;
darwin*)
@@ -56,6 +57,7 @@ case "$host_os" in
DEVMAPPER=yes
ODIRECT=no
SELINUX=no
REALTIME=no
CLUSTER=none
FSADM=no ;;
esac
@@ -282,6 +284,13 @@ AC_ARG_ENABLE(selinux, [ --disable-selinux Disable selinux support],
SELINUX=$enableval)
AC_MSG_RESULT($SELINUX)
################################################################################
dnl -- Disable realtime clock support
AC_MSG_CHECKING(whether to enable realtime support)
AC_ARG_ENABLE(realtime, [ --disable-realtime Disable realtime clock support],
REALTIME=$enableval)
AC_MSG_RESULT($REALTIME)
################################################################################
dnl -- Build cluster LVM daemon
AC_MSG_CHECKING(whether to build cluster LVM daemon)
@@ -351,10 +360,6 @@ AC_ARG_ENABLE(cmdlib, [ --enable-cmdlib Build shared command library],
CMDLIB=$enableval, CMDLIB=no)
AC_MSG_RESULT($CMDLIB)
if test x$CMDLIB = xyes; then
AC_DEFINE([CMDLIB], 1, [Define to 1 to build the shared command library.])
fi
################################################################################
dnl -- Enable fsadm
AC_MSG_CHECKING(whether to build fsadm)
@@ -453,6 +458,21 @@ if test x$SELINUX = xyes; then
fi
fi
################################################################################
dnl -- Check for realtime clock support
if test x$REALTIME = xyes; then
AC_MSG_CHECKING(for clock_gettime function)
AC_CHECK_LIB(rt, clock_gettime, HAVE_REALTIME=yes, HAVE_REALTIME=no)
AC_MSG_RESULT($HAVE_REALTIME)
if test x$HAVE_REALTIME = xyes; then
AC_DEFINE([HAVE_REALTIME], 1, [Define to 1 to include support for realtime clock.])
LIBS="-lrt $LIBS"
else
AC_MSG_WARN(Disabling realtime clock)
fi
fi
################################################################################
dnl -- Check for getopt
AC_CHECK_HEADERS(getopt.h, AC_DEFINE([HAVE_GETOPTLONG], 1, [Define to 1 to if getopt_long is available.]))
@@ -538,9 +558,7 @@ if test x$INTL = xyes; then
AC_CHECK_HEADERS(libintl.h,,AC_MSG_ERROR(bailing out))
fi
if test x$DEVMAPPER = xyes; then
AC_CHECK_HEADERS(libdevmapper.h,,AC_MSG_ERROR(bailing out))
fi
AC_CHECK_HEADERS(libdevmapper.h,,AC_MSG_ERROR(bailing out))
if test x$HAVE_SELINUX = xyes; then
AC_CHECK_HEADERS(selinux/selinux.h,,AC_MSG_ERROR(bailing out))
@@ -584,6 +602,7 @@ AC_SUBST(DEBUG)
AC_SUBST(DEVMAPPER)
AC_SUBST(HAVE_LIBDL)
AC_SUBST(HAVE_SELINUX)
AC_SUBST(HAVE_REALTIME)
AC_SUBST(CMDLIB)
AC_SUBST(MSGFMT)
AC_SUBST(LOCALEDIR)

View File

@@ -19,6 +19,7 @@ SOURCES = \
clvmd-command.c \
clvmd.c \
lvm-functions.c \
refresh_clvmd.c \
system-lv.c
ifeq ("@CLVMD@", "gulm")
@@ -59,9 +60,7 @@ ifeq ("@DMEVENTD@", "yes")
LVMLIBS += -ldevmapper-event
endif
ifeq ("@DEVMAPPER@", "yes")
LVMLIBS += -ldevmapper
endif
LVMLIBS += -ldevmapper
DEFS += -D_REENTRANT
CFLAGS += -fno-strict-aliasing

View File

@@ -63,4 +63,8 @@ static const char CLVMD_SOCKNAME[] = "\0clvmd";
#define CLVMD_CMD_LOCK_LV 50
#define CLVMD_CMD_LOCK_VG 51
/* Misc functions */
#define CLVMD_CMD_REFRESH 40
#define CLVMD_CMD_GET_CLUSTERNAME 41
#endif

View File

@@ -137,7 +137,7 @@ static int _cluster_send_message(void *buf, int msglen, char *csid, const char *
if (cman_send_data(c_handle, buf, msglen, 0, CLUSTER_PORT_CLVMD, nodeid) <= 0)
{
log_error(errtext);
log_error(errtext);
}
return msglen;
}
@@ -152,16 +152,18 @@ static void _get_our_csid(char *csid)
/* Call a callback routine for each node is that known (down means not running a clvmd) */
static int _cluster_do_node_callback(struct local_client *client,
void (*callback) (struct local_client *, char *,
int))
void (*callback) (struct local_client *, char *,
int))
{
int i;
int somedown = 0;
for (i = 0; i < _get_num_nodes(); i++) {
callback(client, (char *)&nodes[i].cn_nodeid, node_updown[nodes[i].cn_nodeid]);
if (!node_updown[nodes[i].cn_nodeid])
somedown = -1;
if (nodes[i].cn_member) {
callback(client, (char *)&nodes[i].cn_nodeid, node_updown[nodes[i].cn_nodeid]);
if (!node_updown[nodes[i].cn_nodeid])
somedown = -1;
}
}
return somedown;
}
@@ -170,7 +172,7 @@ static int _cluster_do_node_callback(struct local_client *client,
this currently just means that a node has stopped listening on our port */
static void event_callback(cman_handle_t handle, void *private, int reason, int arg)
{
char namebuf[MAX_CLUSTER_NAME_LEN];
char namebuf[MAX_CLUSTER_MEMBER_NAME_LEN];
switch (reason) {
case CMAN_REASON_PORTCLOSED:
@@ -205,7 +207,7 @@ static void event_callback(cman_handle_t handle, void *private, int reason, int
static struct local_client *cman_client;
static int _cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid,
struct local_client **new_client)
struct local_client **new_client)
{
/* Save this for data_callback */
@@ -243,7 +245,7 @@ static void _add_up_node(char *csid)
max_updown_nodes);
} else {
log_error
("Realloc failed. Node status for clvmd will be wrong. quitting\n");
("Realloc failed. Node status for clvmd will be wrong. quitting\n");
exit(999);
}
}
@@ -297,36 +299,37 @@ static void get_members()
return;
}
/* Not enough room for new nodes list ? */
if (num_nodes > count_nodes && nodes) {
free(nodes);
nodes = NULL;
}
/* Not enough room for new nodes list ? */
if (num_nodes > count_nodes && nodes) {
free(nodes);
nodes = NULL;
}
if (nodes == NULL) {
count_nodes = num_nodes + 10; /* Overallocate a little */
if (nodes == NULL) {
count_nodes = num_nodes + 10; /* Overallocate a little */
nodes = malloc(count_nodes * sizeof(struct cman_node));
if (!nodes) {
log_error("Unable to allocate nodes array\n");
exit(5);
}
if (!nodes) {
log_error("Unable to allocate nodes array\n");
exit(5);
}
}
status = cman_get_nodes(c_handle, count_nodes, &retnodes, nodes);
if (status < 0) {
log_error("Unable to get node details");
exit(6);
}
if (node_updown == NULL) {
node_updown =
(int *) malloc(sizeof(int) *
max(num_nodes, max_updown_nodes));
memset(node_updown, 0,
sizeof(int) * max(num_nodes, max_updown_nodes));
}
log_error("Unable to get node details");
exit(6);
}
if (node_updown == NULL) {
node_updown =
(int *) malloc(sizeof(int) *
max(num_nodes, max_updown_nodes));
memset(node_updown, 0,
sizeof(int) * max(num_nodes, max_updown_nodes));
}
}
/* Convert a node name to a CSID */
static int _csid_from_name(char *csid, char *name)
{
@@ -468,6 +471,18 @@ static int _sync_unlock(const char *resource /* UNUSED */, int lockid)
}
static int _get_cluster_name(char *buf, int buflen)
{
cman_cluster_t cluster_info;
int status;
status = cman_get_cluster(c_handle, &cluster_info);
if (!status) {
strncpy(buf, cluster_info.ci_name, buflen);
}
return status;
}
static struct cluster_ops _cluster_cman_ops = {
.cluster_init_completed = _cluster_init_completed,
.cluster_send_message = _cluster_send_message,
@@ -481,6 +496,7 @@ static struct cluster_ops _cluster_cman_ops = {
.get_our_csid = _get_our_csid,
.add_up_node = _add_up_node,
.cluster_closedown = _cluster_closedown,
.get_cluster_name = _get_cluster_name,
.sync_lock = _sync_lock,
.sync_unlock = _sync_unlock,
};

View File

@@ -75,6 +75,8 @@
#include "clvmd.h"
#include "libdlm.h"
extern struct cluster_ops *clops;
/* This is where all the real work happens:
NOTE: client will be NULL when this is executed on a remote node */
int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
@@ -117,11 +119,21 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
if (status == EIO) {
*retlen =
1 + snprintf(*buf, buflen,
"Internal lvm error, check syslog");
get_last_lvm_error());
return EIO;
}
break;
case CLVMD_CMD_REFRESH:
do_refresh_cache();
break;
case CLVMD_CMD_GET_CLUSTERNAME:
status = clops->get_cluster_name(*buf, buflen);
if (!status)
*retlen = strlen(*buf);
break;
default:
/* Won't get here because command is validated in pre_command */
break;
@@ -180,7 +192,7 @@ static int lock_vg(struct local_client *client)
}
else {
status = sync_lock(lockname, (int)lock_cmd, (int)lock_flags, &lkid);
status = sync_lock(lockname, (int)lock_cmd, (lock_flags & LCK_NONBLOCK) ? LKF_NOQUEUE : 0, &lkid);
if (status)
status = errno;
else
@@ -222,6 +234,10 @@ int do_pre_command(struct local_client *client)
status = pre_lock_lv(lock_cmd, lock_flags, lockname);
break;
case CLVMD_CMD_REFRESH:
case CLVMD_CMD_GET_CLUSTERNAME:
break;
default:
log_error("Unknown command %d received\n", header->cmd);
status = EINVAL;

View File

@@ -43,6 +43,8 @@ struct cluster_ops {
void (*reread_config) (void);
void (*cluster_closedown) (void);
int (*get_cluster_name)(char *buf, int buflen);
int (*sync_lock) (const char *resource, int mode, int flags, int *lockid);
int (*sync_unlock) (const char *resource, int lockid);

View File

@@ -973,6 +973,12 @@ static int _cluster_send_message(void *buf, int msglen, char *csid, const char *
return gulm_cluster_send_message(buf, msglen, csid, errtext);
}
static int _get_cluster_name(char *buf, int buflen)
{
strncpy(buf, cluster_name, buflen);
return 0;
}
static struct cluster_ops _cluster_gulm_ops = {
.cluster_init_completed = NULL,
.cluster_send_message = _cluster_send_message,
@@ -987,6 +993,7 @@ static struct cluster_ops _cluster_gulm_ops = {
.add_up_node = gulm_add_up_node,
.reread_config = _reread_config,
.cluster_closedown = _cluster_closedown,
.get_cluster_name = _get_cluster_name,
.sync_lock = _sync_lock,
.sync_unlock = _sync_unlock,
};

View File

@@ -42,6 +42,7 @@
#include "clvm.h"
#include "version.h"
#include "clvmd.h"
#include "refresh_clvmd.h"
#include "libdlm.h"
#include "system-lv.h"
#include "list.h"
@@ -66,7 +67,7 @@ static struct local_client local_client_head;
static unsigned short global_xid = 0; /* Last transaction ID issued */
static struct cluster_ops *clops = NULL;
struct cluster_ops *clops = NULL;
static char our_csid[MAX_CSID_LEN];
static unsigned max_csid_len;
@@ -143,6 +144,7 @@ static void usage(char *prog, FILE *file)
fprintf(file, " -V Show version of clvmd\n");
fprintf(file, " -h Show this help information\n");
fprintf(file, " -d Don't fork, run in the foreground\n");
fprintf(file, " -R Tell all running clvmds in the cluster to reload their device cache\n");
fprintf(file, " -t<secs> Command timeout (default 60 seconds)\n");
fprintf(file, "\n");
}
@@ -173,7 +175,7 @@ int main(int argc, char *argv[])
/* Deal with command-line arguments */
opterr = 0;
optind = 0;
while ((opt = getopt(argc, argv, "?vVhdt:")) != EOF) {
while ((opt = getopt(argc, argv, "?vVhdt:R")) != EOF) {
switch (opt) {
case 'h':
usage(argv[0], stdout);
@@ -183,6 +185,9 @@ int main(int argc, char *argv[])
usage(argv[0], stderr);
exit(0);
case 'R':
return refresh_clvmd();
case 'd':
debug++;
break;
@@ -1684,6 +1689,7 @@ static void *lvm_thread_fn(void *arg)
}
pthread_mutex_unlock(&lvm_thread_mutex);
}
return NULL;
}
/* Pass down some work to the LVM thread */

View File

@@ -45,16 +45,23 @@
#include "log.h"
#include "activate.h"
#include "locking.h"
#include "defaults.h"
static struct cmd_context *cmd = NULL;
static struct dm_hash_table *lv_hash = NULL;
static pthread_mutex_t lv_hash_lock;
static char last_error[1024];
struct lv_info {
int lock_id;
int lock_mode;
};
char *get_last_lvm_error()
{
return last_error;
}
/* Return the mode a lock is currently held at (or -1 if not held) */
static int get_current_lock(char *resource)
{
@@ -200,8 +207,17 @@ static int do_activate_lv(char *resource, unsigned char lock_flags, int mode)
/* Try to get the lock if it's a clustered volume group */
if (lock_flags & LCK_CLUSTER_VG) {
status = hold_lock(resource, mode, LKF_NOQUEUE);
if (status)
if (status) {
/* Return an LVM-sensible error for this.
* Forcing EIO makes the upper level return this text
* rather than the strerror text for EAGAIN.
*/
if (errno == EAGAIN) {
sprintf(last_error, "Volume is busy on another node");
errno = EIO;
}
return errno;
}
}
/* If it's suspended then resume it */
@@ -306,6 +322,12 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
if (lock_flags & LCK_PARTIAL_MODE)
init_partial(1);
if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
init_mirror_in_sync(1);
if (!(lock_flags & LCK_DMEVENTD_REGISTER_MODE))
init_dmeventd_register(0);
switch (command) {
case LCK_LV_EXCLUSIVE:
status = do_activate_lv(resource, lock_flags, LKM_EXMODE);
@@ -337,6 +359,12 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
if (lock_flags & LCK_PARTIAL_MODE)
init_partial(0);
if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
init_mirror_in_sync(0);
if (!(lock_flags & LCK_DMEVENTD_REGISTER_MODE))
init_dmeventd_register(DEFAULT_DMEVENTD_MONITOR);
/* clean the pool for another command */
dm_pool_empty(cmd->mem);
@@ -403,6 +431,13 @@ int do_check_lvm1(char *vgname)
return status == 1 ? 0 : EBUSY;
}
int do_refresh_cache()
{
DEBUGLOG("Refreshing context\n");
log_notice("Refreshing context");
return refresh_toolcontext(cmd)==1?0:-1;
}
/* Only called at gulm startup. Drop any leftover VG or P_orphan locks
that might be hanging around if we died for any reason
@@ -492,12 +527,26 @@ static void *get_initial_state()
return NULL;
}
static void lvm2_log_fn(int level, const char *file, int line,
const char *message)
{
/*
* Ignore non-error messages, but store the latest one for returning
* to the user.
*/
if (level != _LOG_ERR && level != _LOG_FATAL)
return;
strncpy(last_error, message, sizeof(last_error));
last_error[sizeof(last_error)-1] = '\0';
}
/* This checks some basic cluster-LVM configuration stuff */
static void check_config()
{
int locking_type;
locking_type = find_config_int(cmd->cft->root, "global/locking_type", 1);
locking_type = find_config_tree_int(cmd, "global/locking_type", 1);
if (locking_type == 3) /* compiled-in cluster support */
return;
@@ -505,7 +554,7 @@ static void check_config()
if (locking_type == 2) { /* External library, check name */
const char *libname;
libname = find_config_str(cmd->cft->root, "global/locking_library",
libname = find_config_tree_str(cmd, "global/locking_library",
"");
if (strstr(libname, "liblvm2clusterlock.so"))
return;
@@ -526,7 +575,7 @@ void init_lvhash()
/* Called to initialise the LVM context of the daemon */
int init_lvm(int using_gulm)
{
if (!(cmd = create_toolcontext(NULL))) {
if (!(cmd = create_toolcontext(NULL, 0))) {
log_error("Failed to allocate command context");
return 0;
}
@@ -544,5 +593,8 @@ int init_lvm(int using_gulm)
get_initial_state();
/* Trap log messages so we can pass them back to the user */
init_log_fn(lvm2_log_fn);
return 1;
}

View File

@@ -25,11 +25,13 @@ extern int do_lock_lv(unsigned char lock_cmd, unsigned char lock_flags,
extern int post_lock_lv(unsigned char lock_cmd, unsigned char lock_flags,
char *resource);
extern int do_check_lvm1(char *vgname);
extern int do_refresh_cache(void);
extern int init_lvm(int using_gulm);
extern void init_lvhash(void);
extern int hold_unlock(char *resource);
extern int hold_lock(char *resource, int mode, int flags);
extern void unlock_all(void);
extern char *get_last_lvm_error(void);
#endif

View File

@@ -0,0 +1,334 @@
/*
* Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Tell all clvmds in a cluster to refresh their toolcontext
*
*/
#include <stddef.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <unistd.h>
#include <libdevmapper.h>
#include <stdint.h>
#include <stdio.h>
#include "clvm.h"
#include "refresh_clvmd.h"
typedef struct lvm_response {
char node[255];
char *response;
int status;
int len;
} lvm_response_t;
/*
* This gets stuck at the start of memory we allocate so we
* can sanity-check it at deallocation time
*/
#define LVM_SIGNATURE 0x434C564D
static int _clvmd_sock = -1;
/* Open connection to the Cluster Manager daemon */
static int _open_local_sock(void)
{
int local_socket;
struct sockaddr_un sockaddr;
/* Open local socket */
if ((local_socket = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "Local socket creation failed: %s", strerror(errno));
return -1;
}
memset(&sockaddr, 0, sizeof(sockaddr));
memcpy(sockaddr.sun_path, CLVMD_SOCKNAME, sizeof(CLVMD_SOCKNAME));
sockaddr.sun_family = AF_UNIX;
if (connect(local_socket,(struct sockaddr *) &sockaddr,
sizeof(sockaddr))) {
int saved_errno = errno;
fprintf(stderr, "connect() failed on local socket: %s\n",
strerror(errno));
if (close(local_socket))
return -1;
errno = saved_errno;
return -1;
}
return local_socket;
}
/* Send a request and return the status */
static int _send_request(char *inbuf, int inlen, char **retbuf)
{
char outbuf[PIPE_BUF];
struct clvm_header *outheader = (struct clvm_header *) outbuf;
int len;
int off;
int buflen;
int err;
/* Send it to CLVMD */
rewrite:
if ( (err = write(_clvmd_sock, inbuf, inlen)) != inlen) {
if (err == -1 && errno == EINTR)
goto rewrite;
fprintf(stderr, "Error writing data to clvmd: %s", strerror(errno));
return 0;
}
/* Get the response */
reread:
if ((len = read(_clvmd_sock, outbuf, sizeof(struct clvm_header))) < 0) {
if (errno == EINTR)
goto reread;
fprintf(stderr, "Error reading data from clvmd: %s", strerror(errno));
return 0;
}
if (len == 0) {
fprintf(stderr, "EOF reading CLVMD");
errno = ENOTCONN;
return 0;
}
/* Allocate buffer */
buflen = len + outheader->arglen;
*retbuf = dm_malloc(buflen);
if (!*retbuf) {
errno = ENOMEM;
return 0;
}
/* Copy the header */
memcpy(*retbuf, outbuf, len);
outheader = (struct clvm_header *) *retbuf;
/* Read the returned values */
off = 1; /* we've already read the first byte */
while (off <= outheader->arglen && len > 0) {
len = read(_clvmd_sock, outheader->args + off,
buflen - off - offsetof(struct clvm_header, args));
if (len > 0)
off += len;
}
/* Was it an error ? */
if (outheader->status != 0) {
errno = outheader->status;
/* Only return an error here if there are no node-specific
errors present in the message that might have more detail */
if (!(outheader->flags & CLVMD_FLAG_NODEERRS)) {
fprintf(stderr, "cluster request failed: %s\n", strerror(errno));
return 0;
}
}
return 1;
}
/* Build the structure header and parse-out wildcard node names */
static void _build_header(struct clvm_header *head, int cmd, const char *node,
int len)
{
head->cmd = cmd;
head->status = 0;
head->flags = 0;
head->clientid = 0;
head->arglen = len;
if (node) {
/*
* Allow a couple of special node names:
* "*" for all nodes,
* "." for the local node only
*/
if (strcmp(node, "*") == 0) {
head->node[0] = '\0';
} else if (strcmp(node, ".") == 0) {
head->node[0] = '\0';
head->flags = CLVMD_FLAG_LOCAL;
} else
strcpy(head->node, node);
} else
head->node[0] = '\0';
}
/*
* Send a message to a(or all) node(s) in the cluster and wait for replies
*/
static int _cluster_request(char cmd, const char *node, void *data, int len,
lvm_response_t ** response, int *num)
{
char outbuf[sizeof(struct clvm_header) + len + strlen(node) + 1];
int *outptr;
char *inptr;
char *retbuf = NULL;
int status;
int i;
int num_responses = 0;
struct clvm_header *head = (struct clvm_header *) outbuf;
lvm_response_t *rarray;
*num = 0;
if (_clvmd_sock == -1)
_clvmd_sock = _open_local_sock();
if (_clvmd_sock == -1)
return 0;
_build_header(head, cmd, node, len);
memcpy(head->node + strlen(head->node) + 1, data, len);
status = _send_request(outbuf, sizeof(struct clvm_header) +
strlen(head->node) + len, &retbuf);
if (!status)
goto out;
/* Count the number of responses we got */
head = (struct clvm_header *) retbuf;
inptr = head->args;
while (inptr[0]) {
num_responses++;
inptr += strlen(inptr) + 1;
inptr += sizeof(int);
inptr += strlen(inptr) + 1;
}
/*
* Allocate response array.
* With an extra pair of INTs on the front to sanity
* check the pointer when we are given it back to free
*/
outptr = dm_malloc(sizeof(lvm_response_t) * num_responses +
sizeof(int) * 2);
if (!outptr) {
errno = ENOMEM;
status = 0;
goto out;
}
*response = (lvm_response_t *) (outptr + 2);
outptr[0] = LVM_SIGNATURE;
outptr[1] = num_responses;
rarray = *response;
/* Unpack the response into an lvm_response_t array */
inptr = head->args;
i = 0;
while (inptr[0]) {
strcpy(rarray[i].node, inptr);
inptr += strlen(inptr) + 1;
memcpy(&rarray[i].status, inptr, sizeof(int));
inptr += sizeof(int);
rarray[i].response = dm_malloc(strlen(inptr) + 1);
if (rarray[i].response == NULL) {
/* Free up everything else and return error */
int j;
for (j = 0; j < i; j++)
dm_free(rarray[i].response);
free(outptr);
errno = ENOMEM;
status = -1;
goto out;
}
strcpy(rarray[i].response, inptr);
rarray[i].len = strlen(inptr);
inptr += strlen(inptr) + 1;
i++;
}
*num = num_responses;
*response = rarray;
out:
if (retbuf)
dm_free(retbuf);
return status;
}
/* Free reply array */
static int _cluster_free_request(lvm_response_t * response)
{
int *ptr = (int *) response - 2;
int i;
int num;
/* Check it's ours to free */
if (response == NULL || *ptr != LVM_SIGNATURE) {
errno = EINVAL;
return 0;
}
num = ptr[1];
for (i = 0; i < num; i++) {
dm_free(response[i].response);
}
dm_free(ptr);
return 1;
}
int refresh_clvmd()
{
int num_responses;
char args[1]; // No args really.
lvm_response_t *response;
int saved_errno;
int status;
int i;
status = _cluster_request(CLVMD_CMD_REFRESH, "*", args, 0, &response, &num_responses);
/* If any nodes were down then display them and return an error */
for (i = 0; i < num_responses; i++) {
if (response[i].status == EHOSTDOWN) {
fprintf(stderr, "clvmd not running on node %s",
response[i].node);
status = 0;
errno = response[i].status;
} else if (response[i].status) {
fprintf(stderr, "Error resetting node %s: %s",
response[i].node,
response[i].response[0] ?
response[i].response :
strerror(response[i].status));
status = 0;
errno = response[i].status;
}
}
saved_errno = errno;
_cluster_free_request(response);
errno = saved_errno;
return status;
}

View File

@@ -0,0 +1,2 @@
int refresh_clvmd(void);

View File

@@ -1213,14 +1213,14 @@ static void sig_alarm(int signum)
/* Init thread signal handling. */
static void init_thread_signals(void)
{
sigset_t sigset;
sigset_t my_sigset;
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = sig_alarm;
sigaction(SIGALRM, &act, NULL);
sigfillset(&sigset);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
sigfillset(&my_sigset);
pthread_sigmask(SIG_BLOCK, &my_sigset, NULL);
}
static int daemonize(void)

View File

@@ -31,6 +31,8 @@
#define ME_INSYNC 1
#define ME_FAILURE 2
static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
/* FIXME: We may need to lock around operations to these */
static int register_count = 0;
static struct dm_pool *mem_pool = NULL;
@@ -46,7 +48,7 @@ static int _get_mirror_event(char *params)
char *p;
int log_argc, num_devs, num_failures=0;
if (max_args <= split_words(params, max_args, args)) {
if (max_args <= dm_split_words(params, max_args, 0, args)) {
syslog(LOG_ERR, "Unable to split mirror parameters: Arg list too long");
return -E2BIG;
}
@@ -99,10 +101,13 @@ static int _get_mirror_event(char *params)
return rtn;
}
static void _temporary_log_fn(int level, const char *file, int line, const char *format)
static void _temporary_log_fn(int level, const char *file,
int line, const char *format)
{
return;
syslog(LOG_DEBUG, "%s", format);
if (!strncmp(format, "WARNING: ", 9) && (level < 5))
syslog(LOG_CRIT, "%s", format);
else
syslog(LOG_DEBUG, "%s", format);
}
static int _remove_failed_devices(const char *device)
@@ -116,7 +121,7 @@ static int _remove_failed_devices(const char *device)
if (strlen(device) > 200)
return -ENAMETOOLONG;
if (!split_dm_name(mem_pool, device, &vg, &lv, &layer)) {
if (!dm_split_lvm_name(mem_pool, device, &vg, &lv, &layer)) {
syslog(LOG_ERR, "Unable to determine VG name from %s",
device);
return -ENOMEM;
@@ -147,6 +152,10 @@ void process_event(const char *device, enum dm_event_type event)
char *target_type = NULL;
char *params;
if (pthread_mutex_trylock(&_lock)) {
syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
pthread_mutex_lock(&_lock);
}
/* FIXME Move inside libdevmapper */
if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) {
syslog(LOG_ERR, "Unable to create dm_task.\n");
@@ -201,11 +210,12 @@ void process_event(const char *device, enum dm_event_type event)
fail:
if (dmt)
dm_task_destroy(dmt);
pthread_mutex_unlock(&_lock);
}
int register_device(const char *device)
{
syslog(LOG_INFO, "Monitoring %s for events\n", device);
syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device);
/*
* Need some space for allocations. 1024 should be more
@@ -224,8 +234,6 @@ int register_device(const char *device)
int unregister_device(const char *device)
{
syslog(LOG_INFO, "Stopped monitoring %s for events\n", device);
if (!(--register_count)) {
dm_pool_destroy(mem_pool);
mem_pool = NULL;

View File

@@ -31,6 +31,8 @@
#define ME_INSYNC 1
#define ME_FAILURE 2
static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
/* FIXME: We may need to lock around operations to these */
static int register_count = 0;
static struct dm_pool *mem_pool = NULL;
@@ -46,7 +48,7 @@ static int _get_mirror_event(char *params)
char *p;
int log_argc, num_devs, num_failures=0;
if (max_args <= split_words(params, max_args, args)) {
if (max_args <= dm_split_words(params, max_args, 0, args)) {
syslog(LOG_ERR, "Unable to split mirror parameters: Arg list too long");
return -E2BIG;
}
@@ -99,10 +101,13 @@ static int _get_mirror_event(char *params)
return rtn;
}
static void _temporary_log_fn(int level, const char *file, int line, const char *format)
static void _temporary_log_fn(int level, const char *file,
int line, const char *format)
{
return;
syslog(LOG_DEBUG, "%s", format);
if (!strncmp(format, "WARNING: ", 9) && (level < 5))
syslog(LOG_CRIT, "%s", format);
else
syslog(LOG_DEBUG, "%s", format);
}
static int _remove_failed_devices(const char *device)
@@ -116,7 +121,7 @@ static int _remove_failed_devices(const char *device)
if (strlen(device) > 200)
return -ENAMETOOLONG;
if (!split_dm_name(mem_pool, device, &vg, &lv, &layer)) {
if (!dm_split_lvm_name(mem_pool, device, &vg, &lv, &layer)) {
syslog(LOG_ERR, "Unable to determine VG name from %s",
device);
return -ENOMEM;
@@ -147,6 +152,10 @@ void process_event(const char *device, enum dm_event_type event)
char *target_type = NULL;
char *params;
if (pthread_mutex_trylock(&_lock)) {
syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
pthread_mutex_lock(&_lock);
}
/* FIXME Move inside libdevmapper */
if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) {
syslog(LOG_ERR, "Unable to create dm_task.\n");
@@ -201,11 +210,12 @@ void process_event(const char *device, enum dm_event_type event)
fail:
if (dmt)
dm_task_destroy(dmt);
pthread_mutex_unlock(&_lock);
}
int register_device(const char *device)
{
syslog(LOG_INFO, "Monitoring %s for events\n", device);
syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device);
/*
* Need some space for allocations. 1024 should be more
@@ -224,8 +234,6 @@ int register_device(const char *device)
int unregister_device(const char *device)
{
syslog(LOG_INFO, "Stopped monitoring %s for events\n", device);
if (!(--register_count)) {
dm_pool_destroy(mem_pool);
mem_pool = NULL;

View File

@@ -207,11 +207,26 @@ global {
# Location of proc filesystem
proc = "/proc"
# Type of locking to use. Defaults to file-based locking (1).
# Type of locking to use. Defaults to local file-based locking (1).
# Turn locking off by setting to 0 (dangerous: risks metadata corruption
# if LVM2 commands get run concurrently).
# Type 2 uses the external shared library locking_library.
# Type 3 uses built-in clustered locking.
locking_type = 1
# If using external locking (type 2) and initialisation fails,
# with this set to 1 an attempt will be made to use the built-in
# clustered locking.
# If you are using a customised locking_library you should set this to 0.
fallback_to_clustered_locking = 1
# If an attempt to initialise type 2 or type 3 locking failed, perhaps
# because cluster components such as clvmd are not running, with this set
# to 1 an attempt will be made to use local file-based locking (type 1).
# If this succeeds, only commands against local volume groups will proceed.
# Volume Groups marked as clustered will be ignored.
fallback_to_local_locking = 1
# Local non-LV directory that holds file-based locks while commands are
# in progress. A directory like /tmp that may get wiped on reboot is OK.
locking_dir = "/var/lock/lvm"
@@ -223,6 +238,9 @@ global {
# Search this directory first for shared libraries.
# library_dir = "/lib"
# The external locking library to load if locking_type is set to 2.
# locking_library = "liblvm2clusterlock.so"
}
activation {
@@ -232,9 +250,6 @@ activation {
# target or make it return zeros.
missing_stripe_filler = "/dev/ioerror"
# Size (in KB) of each copy operation when mirroring
mirror_region_size = 512
# How much stack (in KB) to reserve for use while devices suspended
reserved_stack = 256
@@ -251,6 +266,54 @@ activation {
# "@*" matches if any tag defined on the host is also set in the LV or VG
#
# volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
# Size (in KB) of each copy operation when mirroring
mirror_region_size = 512
# 'mirror_image_fault_policy' and 'mirror_log_fault_policy' define
# how a device failure affecting a mirror is handled.
# A mirror is composed of mirror images (copies) and a log.
# A disk log ensures that a mirror does not need to be re-synced
# (all copies made the same) every time a machine reboots or crashes.
#
# In the event of a failure, the specified policy will be used to
# determine what happens:
#
# "remove" - Simply remove the faulty device and run without it. If
# the log device fails, the mirror would convert to using
# an in-memory log. This means the mirror will not
# remember its sync status across crashes/reboots and
# the entire mirror will be re-synced. If a
# mirror image fails, the mirror will convert to a
# non-mirrored device if there is only one remaining good
# copy.
#
# "allocate" - Remove the faulty device and try to allocate space on
# a new device to be a replacement for the failed device.
# Using this policy for the log is fast and maintains the
# ability to remember sync state through crashes/reboots.
# Using this policy for a mirror device is slow, as it
# requires the mirror to resynchronize the devices, but it
# will preserve the mirror characteristic of the device.
# This policy acts like "remove" if no suitable device and
# space can be allocated for the replacement.
# Currently this is not implemented properly and behaves
# similarly to:
#
# "allocate_anywhere" - Operates like "allocate", but it does not
# require that the new space being allocated be on a
# device is not part of the mirror. For a log device
# failure, this could mean that the log is allocated on
# the same device as a mirror device. For a mirror
# device, this could mean that the mirror device is
# allocated on the same device as another mirror device.
# This policy would not be wise for mirror devices
# because it would break the redundant nature of the
# mirror. This policy acts like "remove" if no suitable
# device and space can be allocated for the replacement.
mirror_log_fault_policy = "allocate"
mirror_device_fault_policy = "remove"
}
@@ -291,7 +354,13 @@ activation {
# Event daemon
#
#dmeventd {
# dmeventd {
# mirror_library is the library used when monitoring a mirror device.
#
# "libdevmapper-event-lvm2mirror.so" attempts to recover from failures.
# It removes failed devices from a volume group and reconfigures a
# mirror as necessary.
#
# mirror_library = "libdevmapper-event-lvm2mirror.so"
#}

View File

@@ -41,6 +41,7 @@
../lib/misc/lvm-exec.h
../lib/misc/lvm-file.h
../lib/misc/lvm-string.h
../lib/misc/lvm-wrappers.h
../lib/misc/sharedlib.h
../lib/regex/matcher.h
../lib/report/report.h

View File

@@ -78,6 +78,8 @@ SOURCES =\
misc/lvm-exec.c \
misc/lvm-file.c \
misc/lvm-string.c \
misc/lvm-wrappers.c \
misc/timestamp.c \
mm/memlock.c \
regex/matcher.c \
regex/parse_rx.c \

View File

@@ -39,7 +39,7 @@ int lvm1_present(struct cmd_context *cmd)
{
char path[PATH_MAX];
if (lvm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
if (dm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
< 0) {
log_error("LVM1 proc global snprintf failed");
return 0;
@@ -51,6 +51,66 @@ int lvm1_present(struct cmd_context *cmd)
return 0;
}
int list_segment_modules(struct dm_pool *mem, const struct lv_segment *seg,
struct list *modules)
{
unsigned int s;
struct lv_segment *seg2, *snap_seg;
struct list *snh;
if (seg->segtype->ops->modules_needed &&
!seg->segtype->ops->modules_needed(mem, seg, modules)) {
log_error("module string allocation failed");
return 0;
}
if (lv_is_origin(seg->lv))
list_iterate(snh, &seg->lv->snapshot_segs)
if (!list_lv_modules(mem,
list_struct_base(snh,
struct lv_segment,
origin_list)->cow,
modules))
return_0;
if (lv_is_cow(seg->lv)) {
snap_seg = find_cow(seg->lv);
if (snap_seg->segtype->ops->modules_needed &&
!snap_seg->segtype->ops->modules_needed(mem, snap_seg,
modules)) {
log_error("snap_seg module string allocation failed");
return 0;
}
}
for (s = 0; s < seg->area_count; s++) {
switch (seg_type(seg, s)) {
case AREA_LV:
seg2 = find_seg_by_le(seg_lv(seg, s), seg_le(seg, s));
if (seg2 && !list_segment_modules(mem, seg2, modules))
return_0;
break;
case AREA_PV:
case AREA_UNASSIGNED:
;
}
}
return 1;
}
int list_lv_modules(struct dm_pool *mem, const struct logical_volume *lv,
struct list *modules)
{
struct lv_segment *seg;
list_iterate_items(seg, &lv->segments)
if (!list_segment_modules(mem, seg, modules))
return_0;
return 1;
}
#ifndef DEVMAPPER_SUPPORT
void set_activation(int act)
{
@@ -152,11 +212,16 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
}
int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
struct volume_group *vg)
struct volume_group *vg)
{
return 0;
}
void activation_release(void)
{
return;
}
void activation_exit(void)
{
return;
@@ -193,7 +258,7 @@ static int _passes_activation_filter(struct cmd_context *cmd,
char *str;
char path[PATH_MAX];
if (!(cn = find_config_node(cmd->cft->root, "activation/volume_list"))) {
if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
/* If no host tags defined, activate */
if (list_empty(&cmd->tags))
return 1;
@@ -252,9 +317,9 @@ static int _passes_activation_filter(struct cmd_context *cmd,
continue;
}
/* vgname/lvname */
if (lvm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
if (dm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
lv->name) < 0) {
log_error("lvm_snprintf error from %s/%s", lv->vg->name,
log_error("dm_snprintf error from %s/%s", lv->vg->name,
lv->name);
continue;
}
@@ -337,7 +402,7 @@ int target_present(const char *target_name, int use_modprobe)
if (target_version(target_name, &maj, &min, &patchlevel))
return 1;
if (lvm_snprintf(module, sizeof(module), "dm-%s", target_name)
if (dm_snprintf(module, sizeof(module), "dm-%s", target_name)
< 0) {
log_error("target_present module name too long: %s",
target_name);
@@ -523,7 +588,7 @@ static int _lv_deactivate(struct logical_volume *lv)
return r;
}
static int _lv_suspend_lv(struct logical_volume *lv)
static int _lv_suspend_lv(struct logical_volume *lv, int lockfs)
{
int r;
struct dev_manager *dm;
@@ -531,7 +596,7 @@ static int _lv_suspend_lv(struct logical_volume *lv)
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
return_0;
if (!(r = dev_manager_suspend(dm, lv)))
if (!(r = dev_manager_suspend(dm, lv, lockfs)))
stack;
dev_manager_destroy(dm);
@@ -574,14 +639,29 @@ int lvs_in_vg_opened(struct volume_group *vg)
return count;
}
static int _register_dev_for_events(struct cmd_context *cmd,
struct logical_volume *lv, int do_reg)
/*
* register_dev_for_events
*
* This function uses proper error codes (but breaks convention)
* to return:
* -1 on error
* 0 if the lv's targets don't do event [un]registration
* 0 if the lv is already [un]registered -- FIXME: not implemented
* 1 if the lv had a segment which was [un]registered
*
* Returns: -1 on error
*/
int register_dev_for_events(struct cmd_context *cmd,
struct logical_volume *lv, int do_reg)
{
#ifdef DMEVENTD
int r = 0;
struct list *tmp;
struct lv_segment *seg;
int (*reg) (struct dm_pool *mem, struct lv_segment *,
struct config_tree *cft, int events);
int (*reg) (struct lv_segment *, int events);
if (do_reg && !dmeventd_register_mode())
return 1;
list_iterate(tmp, &lv->segments) {
seg = list_item(tmp, struct lv_segment);
@@ -595,17 +675,21 @@ static int _register_dev_for_events(struct cmd_context *cmd,
reg = seg->segtype->ops->target_unregister_events;
if (!reg)
return_0;
continue;
/* FIXME specify events */
if (!reg(cmd->mem, seg, cmd->cft, 0)) {
/* FIXME specify events */
if (!reg(seg, 0)) {
stack;
return 0;
return -1;
}
r = 1;
}
#endif
return r;
#else
return 1;
#endif
}
static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
@@ -613,6 +697,7 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
{
struct logical_volume *lv, *lv_pre;
struct lvinfo info;
int lockfs = 0;
if (!activation())
return 1;
@@ -643,12 +728,16 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
}
}
if (!_register_dev_for_events(cmd, lv, 0))
if (register_dev_for_events(cmd, lv, 0) != 1)
/* FIXME Consider aborting here */
stack;
memlock_inc();
if (!_lv_suspend_lv(lv)) {
if (lv_is_origin(lv_pre) || lv_is_cow(lv_pre))
lockfs = 1;
if (!_lv_suspend_lv(lv, lockfs)) {
memlock_dec();
fs_unlock();
return 0;
@@ -697,7 +786,7 @@ static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
memlock_dec();
fs_unlock();
if (!_register_dev_for_events(cmd, lv, 1))
if (register_dev_for_events(cmd, lv, 1) != 1)
stack;
return 1;
@@ -743,7 +832,7 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
return 0;
}
if (!_register_dev_for_events(cmd, lv, 0))
if (register_dev_for_events(cmd, lv, 0) != 1)
stack;
memlock_inc();
@@ -816,7 +905,7 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
memlock_dec();
fs_unlock();
if (!_register_dev_for_events(cmd, lv, 1))
if (!register_dev_for_events(cmd, lv, 1) != 1)
stack;
return r;
@@ -862,28 +951,21 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
* Does PV use VG somewhere in its construction?
* Returns 1 on failure.
*/
int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
struct volume_group *vg)
int pv_uses_vg(struct physical_volume *pv,
struct volume_group *vg)
{
struct dev_manager *dm;
int r;
if (!activation())
return 0;
if (!dm_is_dm_major(MAJOR(pv->dev->dev)))
return 0;
if (!(dm = dev_manager_create(cmd, vg->name))) {
stack;
return 1;
}
return dev_manager_device_uses_vg(pv->dev, vg);
}
r = dev_manager_device_uses_vg(dm, pv->dev, vg);
dev_manager_destroy(dm);
return r;
void activation_release(void)
{
dev_manager_release();
}
void activation_exit(void)

View File

@@ -39,7 +39,12 @@ int lvm1_present(struct cmd_context *cmd);
int target_present(const char *target_name, int use_modprobe);
int target_version(const char *target_name, uint32_t *maj,
uint32_t *min, uint32_t *patchlevel);
int list_segment_modules(struct dm_pool *mem, const struct lv_segment *seg,
struct list *modules);
int list_lv_modules(struct dm_pool *mem, const struct logical_volume *lv,
struct list *modules);
void activation_release(void);
void activation_exit(void);
int lv_suspend(struct cmd_context *cmd, const char *lvid_s);
@@ -80,10 +85,14 @@ int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
int lvs_in_vg_activated(struct volume_group *vg);
int lvs_in_vg_opened(struct volume_group *vg);
int register_dev_for_events(struct cmd_context *cmd,
struct logical_volume *lv, int do_reg);
/*
* Returns 1 if PV has a dependency tree that uses anything in VG.
*/
int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
int pv_uses_vg(struct physical_volume *pv,
struct volume_group *vg);
#endif

View File

@@ -37,6 +37,7 @@ typedef enum {
ACTIVATE,
DEACTIVATE,
SUSPEND,
SUSPEND_WITH_LOCKFS,
CLEAN
} action_t;
@@ -329,7 +330,7 @@ static int _percent_run(struct dev_manager *dm, const char *name,
if (segtype->ops->target_percent &&
!segtype->ops->target_percent(&dm->target_state, dm->mem,
dm->cmd->cft, seg, params,
dm->cmd, seg, params,
&total_numerator,
&total_denominator,
percent))
@@ -401,7 +402,7 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
dm->mem = mem;
if (!stripe_filler) {
stripe_filler = find_config_str(cmd->cft->root,
stripe_filler = find_config_tree_str(cmd,
"activation/missing_stripe_filler",
DEFAULT_STRIPE_FILLER);
}
@@ -426,6 +427,11 @@ void dev_manager_destroy(struct dev_manager *dm)
dm_pool_destroy(dm->mem);
}
void dev_manager_release(void)
{
dm_lib_release();
}
void dev_manager_exit(void)
{
dm_lib_exit();
@@ -679,7 +685,7 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
(seg_type(seg, s) == AREA_LV && !seg_lv(seg, s)))
dm_tree_node_add_target_area(node,
dm->stripe_filler,
NULL, 0);
NULL, UINT64_C(0));
else if (seg_type(seg, s) == AREA_PV)
dm_tree_node_add_target_area(node,
dev_name(seg_dev(seg, s)),
@@ -704,7 +710,6 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
}
static int _add_origin_target_to_dtree(struct dev_manager *dm,
struct dm_tree *dtree,
struct dm_tree_node *dnode,
struct logical_volume *lv)
{
@@ -720,7 +725,6 @@ static int _add_origin_target_to_dtree(struct dev_manager *dm,
}
static int _add_snapshot_target_to_dtree(struct dev_manager *dm,
struct dm_tree *dtree,
struct dm_tree_node *dnode,
struct logical_volume *lv)
{
@@ -749,7 +753,6 @@ static int _add_snapshot_target_to_dtree(struct dev_manager *dm,
}
static int _add_target_to_dtree(struct dev_manager *dm,
struct dm_tree *dtree,
struct dm_tree_node *dnode,
struct lv_segment *seg)
{
@@ -761,7 +764,7 @@ static int _add_target_to_dtree(struct dev_manager *dm,
return 0;
}
return seg->segtype->ops->add_target_line(dm, dm->mem, dm->cmd->cft,
return seg->segtype->ops->add_target_line(dm, dm->mem, dm->cmd,
&dm->target_state, seg,
dnode,
extent_size * seg->len,
@@ -814,12 +817,12 @@ static int _add_segment_to_dtree(struct dev_manager *dm,
/* Now we've added its dependencies, we can add the target itself */
if (lv_is_origin(seg->lv) && !layer) {
if (!_add_origin_target_to_dtree(dm, dtree, dnode, seg->lv))
if (!_add_origin_target_to_dtree(dm, dnode, seg->lv))
return_0;
} else if (lv_is_cow(seg->lv) && !layer) {
if (!_add_snapshot_target_to_dtree(dm, dtree, dnode, seg->lv))
if (!_add_snapshot_target_to_dtree(dm, dnode, seg->lv))
return_0;
} else if (!_add_target_to_dtree(dm, dtree, dnode, seg))
} else if (!_add_target_to_dtree(dm, dnode, seg))
return_0;
if (lv_is_origin(seg->lv) && !layer)
@@ -864,10 +867,10 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
* Major/minor settings only apply to the visible layer.
*/
if (!(dnode = dm_tree_add_new_dev(dtree, name, dlid,
layer ? lv->major : 0,
layer ? lv->minor : 0,
layer ? UINT32_C(0) : (uint32_t) lv->major,
layer ? UINT32_C(0) : (uint32_t) lv->minor,
_read_only_lv(lv),
lv->vg->status & PRECOMMITTED,
(lv->vg->status & PRECOMMITTED) ? 1 : 0,
lvlayer)))
return_0;
@@ -909,7 +912,7 @@ static int _create_lv_symlinks(struct dev_manager *dm, struct dm_tree_node *root
name = dm_tree_node_get_name(child);
if (name && lvlayer->old_name && *lvlayer->old_name && strcmp(name, lvlayer->old_name)) {
if (!split_dm_name(dm->mem, lvlayer->old_name, &vgname, &lvname, &layer)) {
if (!dm_split_lvm_name(dm->mem, lvlayer->old_name, &vgname, &lvname, &layer)) {
log_error("_create_lv_symlinks: Couldn't split up old device name %s", lvlayer->old_name);
return 0;
}
@@ -921,7 +924,7 @@ static int _create_lv_symlinks(struct dev_manager *dm, struct dm_tree_node *root
return r;
}
static int _clean_tree(struct dev_manager *dm, struct logical_volume *lv, struct dm_tree_node *root)
static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root)
{
void *handle = NULL;
struct dm_tree_node *child;
@@ -935,7 +938,7 @@ static int _clean_tree(struct dev_manager *dm, struct logical_volume *lv, struct
if (!(uuid = dm_tree_node_get_uuid(child)))
continue;
if (!split_dm_name(dm->mem, name, &vgname, &lvname, &layer)) {
if (!dm_split_lvm_name(dm->mem, name, &vgname, &lvname, &layer)) {
log_error("_clean_tree: Couldn't split up device name %s.", name);
return 0;
}
@@ -973,7 +976,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
switch(action) {
case CLEAN:
/* Deactivate any unused non-toplevel nodes */
if (!_clean_tree(dm, lv, root))
if (!_clean_tree(dm, root))
goto_out;
break;
case DEACTIVATE:
@@ -982,8 +985,8 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
goto_out;
break;
case SUSPEND:
if (!lv_is_origin(lv) && !lv_is_cow(lv))
dm_tree_skip_lockfs(root);
dm_tree_skip_lockfs(root);
case SUSPEND_WITH_LOCKFS:
if (!dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1))
goto_out;
break;
@@ -1047,16 +1050,17 @@ int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv)
return r;
}
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv)
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv,
int lockfs)
{
return _tree_action(dm, lv, SUSPEND);
return _tree_action(dm, lv, lockfs ? SUSPEND_WITH_LOCKFS : SUSPEND);
}
/*
* Does device use VG somewhere in its construction?
* Returns 1 if uncertain.
*/
int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
int dev_manager_device_uses_vg(struct device *dev,
struct volume_group *vg)
{
struct dm_tree *dtree;
@@ -1069,7 +1073,7 @@ int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
return r;
}
if (!dm_tree_add_dev(dtree, MAJOR(dev->dev), MINOR(dev->dev))) {
if (!dm_tree_add_dev(dtree, (uint32_t) MAJOR(dev->dev), (uint32_t) MINOR(dev->dev))) {
log_error("Failed to add device %s (%" PRIu32 ":%" PRIu32") to dtree",
dev_name(dev), (uint32_t) MAJOR(dev->dev), (uint32_t) MINOR(dev->dev));
goto out;

View File

@@ -29,6 +29,7 @@ struct device;
struct dev_manager *dev_manager_create(struct cmd_context *cmd,
const char *vg_name);
void dev_manager_destroy(struct dev_manager *dm);
void dev_manager_release(void);
void dev_manager_exit(void);
/*
@@ -46,7 +47,8 @@ int dev_manager_snapshot_percent(struct dev_manager *dm,
int dev_manager_mirror_percent(struct dev_manager *dm,
struct logical_volume *lv, int wait,
float *percent, uint32_t *event_nr);
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv);
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv,
int lockfs);
int dev_manager_activate(struct dev_manager *dm, struct logical_volume *lv);
int dev_manager_preload(struct dev_manager *dm, struct logical_volume *lv);
int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv);
@@ -59,7 +61,7 @@ int dev_manager_lv_rmnodes(const struct logical_volume *lv);
*/
int dev_manager_execute(struct dev_manager *dm);
int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
int dev_manager_device_uses_vg(struct device *dev,
struct volume_group *vg);
#endif

View File

@@ -30,7 +30,7 @@ static int _mk_dir(const char *dev_dir, const char *vg_name)
{
char vg_path[PATH_MAX];
if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
dev_dir, vg_name) == -1) {
log_error("Couldn't construct name of volume "
"group directory.");
@@ -53,7 +53,7 @@ static int _rm_dir(const char *dev_dir, const char *vg_name)
{
char vg_path[PATH_MAX];
if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
dev_dir, vg_name) == -1) {
log_error("Couldn't construct name of volume "
"group directory.");
@@ -87,7 +87,7 @@ static void _rm_blks(const char *dir)
if (!strcmp(name, ".") || !strcmp(name, ".."))
continue;
if (lvm_snprintf(path, sizeof(path), "%s/%s", dir, name) == -1) {
if (dm_snprintf(path, sizeof(path), "%s/%s", dir, name) == -1) {
log_error("Couldn't create path for %s", name);
continue;
}
@@ -109,28 +109,28 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
char vg_path[PATH_MAX];
struct stat buf;
if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
dev_dir, vg_name) == -1) {
log_error("Couldn't create path for volume group dir %s",
vg_name);
return 0;
}
if (lvm_snprintf(lv_path, sizeof(lv_path), "%s/%s", vg_path,
if (dm_snprintf(lv_path, sizeof(lv_path), "%s/%s", vg_path,
lv_name) == -1) {
log_error("Couldn't create source pathname for "
"logical volume link %s", lv_name);
return 0;
}
if (lvm_snprintf(link_path, sizeof(link_path), "%s/%s",
if (dm_snprintf(link_path, sizeof(link_path), "%s/%s",
dm_dir(), dev) == -1) {
log_error("Couldn't create destination pathname for "
"logical volume link for %s", lv_name);
return 0;
}
if (lvm_snprintf(lvm1_group_path, sizeof(lvm1_group_path), "%s/group",
if (dm_snprintf(lvm1_group_path, sizeof(lvm1_group_path), "%s/group",
vg_path) == -1) {
log_error("Couldn't create pathname for LVM1 group file for %s",
vg_name);
@@ -190,7 +190,7 @@ static int _rm_link(const char *dev_dir, const char *vg_name,
struct stat buf;
char lv_path[PATH_MAX];
if (lvm_snprintf(lv_path, sizeof(lv_path), "%s%s/%s",
if (dm_snprintf(lv_path, sizeof(lv_path), "%s%s/%s",
dev_dir, vg_name, lv_name) == -1) {
log_error("Couldn't determine link pathname.");
return 0;

22
lib/cache/lvmcache.c vendored
View File

@@ -50,7 +50,7 @@ int lvmcache_init(void)
return 1;
}
void lvmcache_lock_vgname(const char *vgname, int read_only)
void lvmcache_lock_vgname(const char *vgname, int read_only __attribute((unused)))
{
if (!_lock_hash && !lvmcache_init()) {
log_error("Internal cache initialisation failed");
@@ -169,14 +169,18 @@ struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid)
const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid)
{
struct lvmcache_vginfo *vginfo;
const char *vgname = NULL;
if ((vginfo = vginfo_from_vgid(vgid))) {
if (mem)
return dm_pool_strdup(mem, vginfo->vgname);
return vginfo->vgname;
}
if (!*vgid)
vgname = ORPHAN;
return NULL;
if ((vginfo = vginfo_from_vgid(vgid)))
vgname = vginfo->vgname;
if (mem && vgname)
return dm_pool_strdup(mem, vgname);
return vgname;
}
struct lvmcache_info *info_from_pvid(const char *pvid)
@@ -237,7 +241,7 @@ int lvmcache_label_scan(struct cmd_context *cmd, int full_scan)
goto out;
}
if (!(iter = dev_iter_create(cmd->filter, (full_scan == 2) ? 1: 0))) {
if (!(iter = dev_iter_create(cmd->filter, (full_scan == 2) ? 1 : 0))) {
log_error("dev_iter creation failed");
goto out;
}
@@ -857,7 +861,7 @@ static void _lvmcache_destroy_vgnamelist(struct lvmcache_vginfo *vginfo)
} while ((vginfo = next));
}
static void _lvmcache_destroy_lockname(int present)
static void _lvmcache_destroy_lockname(int present __attribute((unused)))
{
/* Nothing to do */
}

View File

@@ -67,7 +67,7 @@ static int _get_env_vars(struct cmd_context *cmd)
/* Set to "" to avoid using any system directory */
if ((e = getenv("LVM_SYSTEM_DIR"))) {
if (lvm_snprintf(cmd->sys_dir, sizeof(cmd->sys_dir),
if (dm_snprintf(cmd->sys_dir, sizeof(cmd->sys_dir),
"%s", e) < 0) {
log_error("LVM_SYSTEM_DIR environment variable "
"is too long.");
@@ -84,10 +84,11 @@ static void _init_logging(struct cmd_context *cmd)
time_t t;
const char *log_file;
char timebuf[26];
/* Syslog */
cmd->default_settings.syslog =
find_config_int(cmd->cft->root, "log/syslog", DEFAULT_SYSLOG);
find_config_tree_int(cmd, "log/syslog", DEFAULT_SYSLOG);
if (cmd->default_settings.syslog != 1)
fin_syslog();
@@ -96,37 +97,37 @@ static void _init_logging(struct cmd_context *cmd)
/* Debug level for log file output */
cmd->default_settings.debug =
find_config_int(cmd->cft->root, "log/level", DEFAULT_LOGLEVEL);
find_config_tree_int(cmd, "log/level", DEFAULT_LOGLEVEL);
init_debug(cmd->default_settings.debug);
/* Verbose level for tty output */
cmd->default_settings.verbose =
find_config_int(cmd->cft->root, "log/verbose", DEFAULT_VERBOSE);
find_config_tree_int(cmd, "log/verbose", DEFAULT_VERBOSE);
init_verbose(cmd->default_settings.verbose + VERBOSE_BASE_LEVEL);
/* Log message formatting */
init_indent(find_config_int(cmd->cft->root, "log/indent",
init_indent(find_config_tree_int(cmd, "log/indent",
DEFAULT_INDENT));
cmd->default_settings.msg_prefix = find_config_str(cmd->cft->root,
cmd->default_settings.msg_prefix = find_config_tree_str(cmd,
"log/prefix",
DEFAULT_MSG_PREFIX);
init_msg_prefix(cmd->default_settings.msg_prefix);
cmd->default_settings.cmd_name = find_config_int(cmd->cft->root,
cmd->default_settings.cmd_name = find_config_tree_int(cmd,
"log/command_names",
DEFAULT_CMD_NAME);
init_cmd_name(cmd->default_settings.cmd_name);
/* Test mode */
cmd->default_settings.test =
find_config_int(cmd->cft->root, "global/test", 0);
find_config_tree_int(cmd, "global/test", 0);
/* Settings for logging to file */
if (find_config_int(cmd->cft->root, "log/overwrite", DEFAULT_OVERWRITE))
if (find_config_tree_int(cmd, "log/overwrite", DEFAULT_OVERWRITE))
append = 0;
log_file = find_config_str(cmd->cft->root, "log/file", 0);
log_file = find_config_tree_str(cmd, "log/file", 0);
if (log_file) {
release_log_memory();
@@ -134,15 +135,17 @@ static void _init_logging(struct cmd_context *cmd)
init_log_file(log_file, append);
}
log_file = find_config_str(cmd->cft->root, "log/activate_file", 0);
log_file = find_config_tree_str(cmd, "log/activate_file", 0);
if (log_file)
init_log_direct(log_file, append);
init_log_while_suspended(find_config_int(cmd->cft->root,
init_log_while_suspended(find_config_tree_int(cmd,
"log/activation", 0));
t = time(NULL);
log_verbose("Logging initialised at %s", ctime(&t));
ctime_r(&t, &timebuf[0]);
timebuf[24] = '\0';
log_verbose("Logging initialised at %s", timebuf);
/* Tell device-mapper about our logging */
#ifdef DEVMAPPER_SUPPORT
@@ -155,7 +158,7 @@ static int _process_config(struct cmd_context *cmd)
mode_t old_umask;
/* umask */
cmd->default_settings.umask = find_config_int(cmd->cft->root,
cmd->default_settings.umask = find_config_tree_int(cmd,
"global/umask",
DEFAULT_UMASK);
@@ -164,8 +167,8 @@ static int _process_config(struct cmd_context *cmd)
log_verbose("Set umask to %04o", cmd->default_settings.umask);
/* dev dir */
if (lvm_snprintf(cmd->dev_dir, sizeof(cmd->dev_dir), "%s/",
find_config_str(cmd->cft->root, "devices/dir",
if (dm_snprintf(cmd->dev_dir, sizeof(cmd->dev_dir), "%s/",
find_config_tree_str(cmd, "devices/dir",
DEFAULT_DEV_DIR)) < 0) {
log_error("Device directory given in config file too long");
return 0;
@@ -175,8 +178,8 @@ static int _process_config(struct cmd_context *cmd)
#endif
/* proc dir */
if (lvm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
find_config_str(cmd->cft->root, "global/proc",
if (dm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
find_config_tree_str(cmd, "global/proc",
DEFAULT_PROC_DIR)) < 0) {
log_error("Device directory given in config file too long");
return 0;
@@ -189,17 +192,17 @@ static int _process_config(struct cmd_context *cmd)
}
/* activation? */
cmd->default_settings.activation = find_config_int(cmd->cft->root,
cmd->default_settings.activation = find_config_tree_int(cmd,
"global/activation",
DEFAULT_ACTIVATION);
set_activation(cmd->default_settings.activation);
cmd->default_settings.suffix = find_config_int(cmd->cft->root,
cmd->default_settings.suffix = find_config_tree_int(cmd,
"global/suffix",
DEFAULT_SUFFIX);
if (!(cmd->default_settings.unit_factor =
units_to_bytes(find_config_str(cmd->cft->root,
units_to_bytes(find_config_tree_str(cmd,
"global/units",
DEFAULT_UNITS),
&cmd->default_settings.unit_type))) {
@@ -316,7 +319,7 @@ static int _load_config_file(struct cmd_context *cmd, const char *tag)
if (*tag)
filler = "_";
if (lvm_snprintf(config_file, sizeof(config_file), "%s/lvm%s%s.conf",
if (dm_snprintf(config_file, sizeof(config_file), "%s/lvm%s%s.conf",
cmd->sys_dir, filler, tag) < 0) {
log_error("LVM_SYSTEM_DIR or tag was too long");
return 0;
@@ -469,7 +472,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
return 0;
}
if (!(cn = find_config_node(cmd->cft->root, "devices/scan"))) {
if (!(cn = find_config_tree_node(cmd, "devices/scan"))) {
if (!dev_cache_add_dir("/dev")) {
log_error("Failed to add /dev to internal "
"device cache");
@@ -494,7 +497,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
}
}
if (!(cn = find_config_node(cmd->cft->root, "devices/loopfiles")))
if (!(cn = find_config_tree_node(cmd, "devices/loopfiles")))
return 1;
for (cv = cn->v; cv; cv = cv->next) {
@@ -536,14 +539,14 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
* Listed first because it's very efficient at eliminating
* unavailable devices.
*/
if (find_config_bool(cmd->cft->root, "devices/sysfs_scan",
if (find_config_tree_bool(cmd, "devices/sysfs_scan",
DEFAULT_SYSFS_SCAN)) {
if ((filters[nr_filt] = sysfs_filter_create(cmd->proc_dir)))
nr_filt++;
}
/* regex filter. Optional. */
if (!(cn = find_config_node(cmd->cft->root, "devices/filter")))
if (!(cn = find_config_tree_node(cmd, "devices/filter")))
log_very_verbose("devices/filter not found in config file: "
"no regex filter installed");
@@ -553,14 +556,14 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
}
/* device type filter. Required. */
cn = find_config_node(cmd->cft->root, "devices/types");
cn = find_config_tree_node(cmd, "devices/types");
if (!(filters[nr_filt++] = lvm_type_filter_create(cmd->proc_dir, cn))) {
log_error("Failed to create lvm type filter");
return NULL;
}
/* md component filter. Optional, non-critical. */
if (find_config_bool(cmd->cft->root, "devices/md_component_detection",
if (find_config_tree_bool(cmd, "devices/md_component_detection",
DEFAULT_MD_COMPONENT_DETECTION)) {
init_md_filtering(1);
if ((filters[nr_filt] = md_filter_create()))
@@ -584,14 +587,14 @@ static int _init_filters(struct cmd_context *cmd)
if (!(f3 = _init_filter_components(cmd)))
return 0;
if (lvm_snprintf(cache_file, sizeof(cache_file),
if (dm_snprintf(cache_file, sizeof(cache_file),
"%s/.cache", cmd->sys_dir) < 0) {
log_error("Persistent cache filename too long ('%s/.cache').",
cmd->sys_dir);
return 0;
}
dev_cache = find_config_str(cmd->cft->root, "devices/cache",
dev_cache = find_config_tree_str(cmd, "devices/cache",
cache_file);
if (!(f4 = persistent_filter_create(f3, dev_cache))) {
log_error("Failed to create persistent device filter");
@@ -599,7 +602,7 @@ static int _init_filters(struct cmd_context *cmd)
}
/* Should we ever dump persistent filter state? */
if (find_config_int(cmd->cft->root, "devices/write_cache_state", 1))
if (find_config_tree_int(cmd, "devices/write_cache_state", 1))
cmd->dump_filter = 1;
if (!*cmd->sys_dir)
@@ -643,8 +646,9 @@ static int _init_formats(struct cmd_context *cmd)
#endif
#ifdef HAVE_LIBDL
/* Load any formats in shared libs */
if ((cn = find_config_node(cmd->cft->root, "global/format_libraries"))) {
/* Load any formats in shared libs if not static */
if (!cmd->is_static &&
(cn = find_config_tree_node(cmd, "global/format_libraries"))) {
struct config_value *cv;
struct format_type *(*init_format_fn) (struct cmd_context *);
@@ -656,7 +660,7 @@ static int _init_formats(struct cmd_context *cmd)
"global/format_libraries");
return 0;
}
if (!(lib = load_shared_library(cmd->cft, cv->v.str,
if (!(lib = load_shared_library(cmd, cv->v.str,
"format", 0))) {
stack;
return 0;
@@ -684,7 +688,7 @@ static int _init_formats(struct cmd_context *cmd)
cmd->fmt_backup = fmt;
format = find_config_str(cmd->cft->root, "global/format",
format = find_config_tree_str(cmd, "global/format",
DEFAULT_FORMAT);
list_iterate_items(fmt, &cmd->formats) {
@@ -737,8 +741,9 @@ static int _init_segtypes(struct cmd_context *cmd)
#endif
#ifdef HAVE_LIBDL
/* Load any formats in shared libs */
if ((cn = find_config_node(cmd->cft->root, "global/segment_libraries"))) {
/* Load any formats in shared libs unless static */
if (!cmd->is_static &&
(cn = find_config_tree_node(cmd, "global/segment_libraries"))) {
struct config_value *cv;
struct segment_type *(*init_segtype_fn) (struct cmd_context *);
@@ -752,7 +757,7 @@ static int _init_segtypes(struct cmd_context *cmd)
"global/segment_libraries");
return 0;
}
if (!(lib = load_shared_library(cmd->cft, cv->v.str,
if (!(lib = load_shared_library(cmd, cv->v.str,
"segment type", 0))) {
stack;
return 0;
@@ -827,16 +832,16 @@ static int _init_backup(struct cmd_context *cmd)
/* set up archiving */
cmd->default_settings.archive =
find_config_bool(cmd->cft->root, "backup/archive",
find_config_tree_bool(cmd, "backup/archive",
DEFAULT_ARCHIVE_ENABLED);
days = (uint32_t) find_config_int(cmd->cft->root, "backup/retain_days",
days = (uint32_t) find_config_tree_int(cmd, "backup/retain_days",
DEFAULT_ARCHIVE_DAYS);
min = (uint32_t) find_config_int(cmd->cft->root, "backup/retain_min",
min = (uint32_t) find_config_tree_int(cmd, "backup/retain_min",
DEFAULT_ARCHIVE_NUMBER);
if (lvm_snprintf
if (dm_snprintf
(default_dir, sizeof(default_dir), "%s/%s", cmd->sys_dir,
DEFAULT_ARCHIVE_SUBDIR) == -1) {
log_err("Couldn't create default archive path '%s/%s'.",
@@ -844,7 +849,7 @@ static int _init_backup(struct cmd_context *cmd)
return 0;
}
dir = find_config_str(cmd->cft->root, "backup/archive_dir",
dir = find_config_tree_str(cmd, "backup/archive_dir",
default_dir);
if (!archive_init(cmd, dir, days, min)) {
@@ -854,10 +859,10 @@ static int _init_backup(struct cmd_context *cmd)
/* set up the backup */
cmd->default_settings.backup =
find_config_bool(cmd->cft->root, "backup/backup",
find_config_tree_bool(cmd, "backup/backup",
DEFAULT_BACKUP_ENABLED);
if (lvm_snprintf
if (dm_snprintf
(default_dir, sizeof(default_dir), "%s/%s", cmd->sys_dir,
DEFAULT_BACKUP_SUBDIR) == -1) {
log_err("Couldn't create default backup path '%s/%s'.",
@@ -865,7 +870,7 @@ static int _init_backup(struct cmd_context *cmd)
return 0;
}
dir = find_config_str(cmd->cft->root, "backup/backup_dir", default_dir);
dir = find_config_tree_str(cmd, "backup/backup_dir", default_dir);
if (!backup_init(cmd, dir)) {
log_debug("backup_init failed.");
@@ -876,7 +881,7 @@ static int _init_backup(struct cmd_context *cmd)
}
/* Entry point */
struct cmd_context *create_toolcontext(struct arg *the_args)
struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static)
{
struct cmd_context *cmd;
@@ -899,6 +904,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
}
memset(cmd, 0, sizeof(*cmd));
cmd->args = the_args;
cmd->is_static = is_static;
cmd->hosttags = 0;
list_init(&cmd->formats);
list_init(&cmd->segtypes);
@@ -921,7 +927,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
if (!(cmd->libmem = dm_pool_create("library", 4 * 1024))) {
log_error("Library memory pool creation failed");
return 0;
goto error;
}
if (!_init_lvm_conf(cmd))
@@ -1021,7 +1027,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
persistent_filter_dump(cmd->filter);
}
activation_exit();
activation_release();
lvmcache_destroy();
label_exit();
_destroy_segtypes(&cmd->segtypes);

View File

@@ -64,6 +64,7 @@ struct cmd_context {
struct command *command;
struct arg *args;
char **argv;
unsigned is_static; /* Static binary? */
struct dev_filter *filter;
int dump_filter; /* Dump filter when exiting? */
@@ -71,6 +72,7 @@ struct cmd_context {
struct list config_files;
int config_valid;
struct config_tree *cft;
struct config_tree *cft_override;
struct config_info default_settings;
struct config_info current_settings;
@@ -86,7 +88,7 @@ struct cmd_context {
char proc_dir[PATH_MAX];
};
struct cmd_context *create_toolcontext(struct arg *the_args);
struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static);
void destroy_toolcontext(struct cmd_context *cmd);
int refresh_toolcontext(struct cmd_context *cmd);
int config_files_changed(struct cmd_context *cmd);

View File

@@ -41,10 +41,10 @@ enum {
};
struct parser {
char *fb, *fe; /* file limits */
const char *fb, *fe; /* file limits */
int t; /* token limits and type */
char *tb, *te;
const char *tb, *te;
int fd; /* descriptor for file being parsed */
int line; /* line number we are on */
@@ -77,7 +77,7 @@ static const int sep = '/';
#define match(t) do {\
if (!_match_aux(p, (t))) {\
log_error("Parse error at line %d: unexpected token", p->line); \
log_error("Parse error at byte %d (line %d): unexpected token", p->tb - p->fb + 1, p->line); \
return 0;\
} \
} while(0);
@@ -101,12 +101,12 @@ struct config_tree *create_config_tree(const char *filename)
struct dm_pool *mem = dm_pool_create("config", 10 * 1024);
if (!mem) {
stack;
log_error("Failed to allocate config pool.");
return 0;
}
if (!(c = dm_pool_zalloc(mem, sizeof(*c)))) {
stack;
log_error("Failed to allocate config tree.");
dm_pool_destroy(mem);
return 0;
}
@@ -125,6 +125,46 @@ void destroy_config_tree(struct config_tree *cft)
dm_pool_destroy(((struct cs *) cft)->mem);
}
static int _parse_config_file(struct parser *p, struct config_tree *cft)
{
p->tb = p->te = p->fb;
p->line = 1;
_get_token(p, TOK_SECTION_E);
if (!(cft->root = _file(p)))
return_0;
return 1;
}
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings)
{
struct cs *c;
struct config_tree *cft;
struct parser *p;
if (!(cft = create_config_tree(NULL)))
return_NULL;
c = (struct cs *) cft;
if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) {
log_error("Failed to allocate config tree parser.");
destroy_config_tree(cft);
return NULL;
}
p->mem = c->mem;
p->fb = config_settings;
p->fe = config_settings + strlen(config_settings);
if (!_parse_config_file(p, cft)) {
destroy_config_tree(cft);
return_NULL;
}
return cft;
}
int read_config_fd(struct config_tree *cft, struct device *dev,
off_t offset, size_t size, off_t offset2, size_t size2,
checksum_fn_t checksum_fn, uint32_t checksum)
@@ -134,6 +174,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
int r = 0;
int use_mmap = 1;
off_t mmap_offset = 0;
char *buf;
if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) {
stack;
@@ -146,7 +187,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
use_mmap = 0;
if (use_mmap) {
mmap_offset = offset % getpagesize();
mmap_offset = offset % lvm_getpagesize();
/* memory map the file */
p->fb = mmap((caddr_t) 0, size + mmap_offset, PROT_READ,
MAP_PRIVATE, dev_fd(dev), offset - mmap_offset);
@@ -156,22 +197,23 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
}
p->fb = p->fb + mmap_offset;
} else {
if (!(p->fb = dm_malloc(size + size2))) {
if (!(buf = dm_malloc(size + size2))) {
stack;
return 0;
}
if (!dev_read(dev, (uint64_t) offset, size, p->fb)) {
if (!dev_read(dev, (uint64_t) offset, size, buf)) {
log_error("Read from %s failed", dev_name(dev));
goto out;
}
if (size2) {
if (!dev_read(dev, (uint64_t) offset2, size2,
p->fb + size)) {
buf + size)) {
log_error("Circular read from %s failed",
dev_name(dev));
goto out;
}
}
p->fb = buf;
}
if (checksum_fn && checksum !=
@@ -183,11 +225,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
p->fe = p->fb + size + size2;
/* parse */
p->tb = p->te = p->fb;
p->line = 1;
_get_token(p, TOK_SECTION_E);
if (!(cft->root = _file(p))) {
if (!_parse_config_file(p, cft)) {
stack;
goto out;
}
@@ -196,7 +234,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
out:
if (!use_mmap)
dm_free(p->fb);
dm_free(buf);
else {
/* unmap the file */
if (munmap((char *) (p->fb - mmap_offset), size + mmap_offset)) {
@@ -529,7 +567,7 @@ static struct config_value *_type(struct parser *p)
break;
default:
log_error("Parse error at line %d: expected a value", p->line);
log_error("Parse error at byte %d (line %d): expected a value", p->tb - p->fb + 1, p->line);
return 0;
}
return v;
@@ -721,8 +759,8 @@ static char *_dup_tok(struct parser *p)
/*
* utility functions
*/
struct config_node *find_config_node(const struct config_node *cn,
const char *path)
static struct config_node *_find_config_node(const struct config_node *cn,
const char *path)
{
const char *e;
@@ -753,10 +791,32 @@ struct config_node *find_config_node(const struct config_node *cn,
return (struct config_node *) cn;
}
const char *find_config_str(const struct config_node *cn,
const char *path, const char *fail)
static struct config_node *_find_first_config_node(const struct config_node *cn1,
const struct config_node *cn2,
const char *path)
{
const struct config_node *n = find_config_node(cn, path);
struct config_node *cn;
if (cn1 && (cn = _find_config_node(cn1, path)))
return cn;
if (cn2 && (cn = _find_config_node(cn2, path)))
return cn;
return NULL;
}
struct config_node *find_config_node(const struct config_node *cn,
const char *path)
{
return _find_config_node(cn, path);
}
static const char *_find_config_str(const struct config_node *cn1,
const struct config_node *cn2,
const char *path, const char *fail)
{
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
/* Empty strings are ignored */
if ((n && n->v->type == CFG_STRING) && (*n->v->v.str)) {
@@ -770,9 +830,17 @@ const char *find_config_str(const struct config_node *cn,
return fail;
}
int find_config_int(const struct config_node *cn, const char *path, int fail)
const char *find_config_str(const struct config_node *cn,
const char *path, const char *fail)
{
const struct config_node *n = find_config_node(cn, path);
return _find_config_str(cn, NULL, path, fail);
}
static int _find_config_int(const struct config_node *cn1,
const struct config_node *cn2,
const char *path, int fail)
{
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
if (n && n->v->type == CFG_INT) {
log_very_verbose("Setting %s to %d", path, n->v->v.i);
@@ -784,10 +852,16 @@ int find_config_int(const struct config_node *cn, const char *path, int fail)
return fail;
}
float find_config_float(const struct config_node *cn, const char *path,
float fail)
int find_config_int(const struct config_node *cn, const char *path, int fail)
{
const struct config_node *n = find_config_node(cn, path);
return _find_config_int(cn, NULL, path, fail);
}
static float _find_config_float(const struct config_node *cn1,
const struct config_node *cn2,
const char *path, float fail)
{
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
if (n && n->v->type == CFG_FLOAT) {
log_very_verbose("Setting %s to %f", path, n->v->v.r);
@@ -801,6 +875,36 @@ float find_config_float(const struct config_node *cn, const char *path,
}
float find_config_float(const struct config_node *cn, const char *path,
float fail)
{
return _find_config_float(cn, NULL, path, fail);
}
struct config_node *find_config_tree_node(struct cmd_context *cmd,
const char *path)
{
return _find_first_config_node(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path);
}
const char *find_config_tree_str(struct cmd_context *cmd,
const char *path, const char *fail)
{
return _find_config_str(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
}
int find_config_tree_int(struct cmd_context *cmd, const char *path,
int fail)
{
return _find_config_int(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
}
float find_config_tree_float(struct cmd_context *cmd, const char *path,
float fail)
{
return _find_config_float(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
}
static int _str_in_array(const char *str, const char *values[])
{
int i;
@@ -827,9 +931,11 @@ static int _str_to_bool(const char *str, int fail)
return fail;
}
int find_config_bool(const struct config_node *cn, const char *path, int fail)
static int _find_config_bool(const struct config_node *cn1,
const struct config_node *cn2,
const char *path, int fail)
{
const struct config_node *n = find_config_node(cn, path);
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
struct config_value *v;
if (!n)
@@ -848,6 +954,16 @@ int find_config_bool(const struct config_node *cn, const char *path, int fail)
return fail;
}
int find_config_bool(const struct config_node *cn, const char *path, int fail)
{
return _find_config_bool(cn, NULL, path, fail);
}
int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail)
{
return _find_config_bool(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
}
int get_config_uint32(const struct config_node *cn, const char *path,
uint32_t *result)
{

View File

@@ -54,9 +54,11 @@ struct config_tree_list {
};
struct config_tree *create_config_tree(const char *filename);
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings);
void destroy_config_tree(struct config_tree *cft);
typedef uint32_t (*checksum_fn_t) (uint32_t initial, void *buf, uint32_t size);
typedef uint32_t (*checksum_fn_t) (uint32_t initial, const void *buf, uint32_t size);
int read_config_fd(struct config_tree *cft, struct device *dev,
off_t offset, size_t size, off_t offset2, size_t size2,
@@ -71,20 +73,30 @@ int merge_config_tree(struct cmd_context *cmd, struct config_tree *cft,
struct config_node *find_config_node(const struct config_node *cn,
const char *path);
const char *find_config_str(const struct config_node *cn, const char *path,
const char *fail);
int find_config_int(const struct config_node *cn, const char *path, int fail);
float find_config_float(const struct config_node *cn, const char *path,
float fail);
/*
* These versions check an override tree, if present, first.
*/
struct config_node *find_config_tree_node(struct cmd_context *cmd,
const char *path);
const char *find_config_tree_str(struct cmd_context *cmd,
const char *path, const char *fail);
int find_config_tree_int(struct cmd_context *cmd, const char *path,
int fail);
float find_config_tree_float(struct cmd_context *cmd, const char *path,
float fail);
/*
* Understands (0, ~0), (y, n), (yes, no), (on,
* off), (true, false).
*/
int find_config_bool(const struct config_node *cn, const char *path, int fail);
int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail);
int get_config_uint32(const struct config_node *cn, const char *path,
uint32_t *result);

View File

@@ -32,9 +32,14 @@
#define DEFAULT_MD_COMPONENT_DETECTION 1
#define DEFAULT_LOCK_DIR "/var/lock/lvm"
#define DEFAULT_LOCKING_LIB "lvm2_locking.so"
#define DEFAULT_LOCKING_LIB "liblvm2clusterlock.so"
#define DEFAULT_FALLBACK_TO_LOCAL_LOCKING 1
#define DEFAULT_FALLBACK_TO_CLUSTERED_LOCKING 1
#define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate"
#define DEFAULT_MIRROR_DEV_FAULT_POLICY "remove"
#define DEFAULT_DMEVENTD_MIRROR_LIB "libdevmapper-event-lvm2mirror.so"
#define DEFAULT_DMEVENTD_MONITOR 1
#define DEFAULT_UMASK 0077

View File

@@ -645,8 +645,7 @@ struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
return NULL;
}
if (dev_scan) {
if (dev_scan && !trust_cache()) {
/* Flag gets reset between each command */
if (!full_scan_done())
persistent_filter_wipe(f); /* Calls _full_scan(1) */

View File

@@ -176,7 +176,7 @@ static int _aligned_io(struct device_area *where, void *buffer,
}
if (!block_size)
block_size = getpagesize();
block_size = lvm_getpagesize();
_widen_region(block_size, where, &widened);
@@ -602,7 +602,7 @@ int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer)
return _aligned_io(&where, buffer, 1);
}
int dev_zero(struct device *dev, uint64_t offset, size_t len)
int dev_set(struct device *dev, uint64_t offset, size_t len, int value)
{
size_t s;
char buffer[4096];
@@ -620,7 +620,7 @@ int dev_zero(struct device *dev, uint64_t offset, size_t len)
" sectors", dev_name(dev), offset >> SECTOR_SHIFT,
len >> SECTOR_SHIFT);
memset(buffer, 0, sizeof(buffer));
memset(buffer, value, sizeof(buffer));
while (1) {
s = len > sizeof(buffer) ? sizeof(buffer) : len;
if (!dev_write(dev, offset, s, buffer))

View File

@@ -62,7 +62,7 @@ static int _has_partition_table(struct device *dev)
return -1;
}
if (!dev_read(dev, 0, sizeof(buf), &buf)) {
if (!dev_read(dev, UINT64_C(0), sizeof(buf), &buf)) {
stack;
goto out;
}

View File

@@ -80,7 +80,7 @@ const char *dev_name(const struct device *dev);
int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer);
int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer);
int dev_append(struct device *dev, size_t len, void *buffer);
int dev_zero(struct device *dev, uint64_t offset, size_t len);
int dev_set(struct device *dev, uint64_t offset, size_t len, int value);
void dev_flush(struct device *dev);
struct device *dev_create_file(const char *filename, struct device *dev,

View File

@@ -30,6 +30,7 @@ static struct {
} _policies[] = {
{
ALLOC_CONTIGUOUS, "contiguous"}, {
ALLOC_CLING, "cling"}, {
ALLOC_NORMAL, "normal"}, {
ALLOC_ANYWHERE, "anywhere"}, {
ALLOC_INHERIT, "inherit"}

View File

@@ -23,6 +23,7 @@
#include "targets.h"
#include "lvm-string.h"
#include "activate.h"
#include "str_list.h"
static const char *_errseg_name(const struct lv_segment *seg)
{
@@ -38,11 +39,13 @@ static int _errseg_merge_segments(struct lv_segment *seg1, struct lv_segment *se
}
#ifdef DEVMAPPER_SUPPORT
static int _errseg_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct lv_segment *seg,
static int _errseg_add_target_line(struct dev_manager *dm __attribute((unused)),
struct dm_pool *mem __attribute((unused)),
struct cmd_context *cmd __attribute((unused)),
void **target_state __attribute((unused)),
struct lv_segment *seg __attribute((unused)),
struct dm_tree_node *node, uint64_t len,
uint32_t *pvmove_mirror_count)
uint32_t *pvmove_mirror_count __attribute((unused)))
{
return dm_tree_node_add_error_target(node, len);
}
@@ -62,9 +65,21 @@ static int _errseg_target_present(void)
}
#endif
static int _errseg_modules_needed(struct dm_pool *mem,
const struct lv_segment *seg,
struct list *modules)
{
if (!str_list_add(mem, modules, "error")) {
log_error("error module string list allocation failed");
return 0;
}
return 1;
}
static void _errseg_destroy(const struct segment_type *segtype)
{
dm_free((void *) segtype);
dm_free((void *)segtype);
}
static struct segtype_handler _error_ops = {
@@ -74,6 +89,7 @@ static struct segtype_handler _error_ops = {
.add_target_line = _errseg_add_target_line,
.target_present = _errseg_target_present,
#endif
.modules_needed = _errseg_modules_needed,
.destroy = _errseg_destroy,
};

View File

@@ -18,14 +18,6 @@
#ifdef linux
/* Lifted from <linux/raid/md_p.h> because of difficulty including it */
#define MD_SB_MAGIC 0xa92b4efc
#define MD_RESERVED_BYTES (64 * 1024)
#define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
#define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) \
- MD_RESERVED_SECTORS)
static int _ignore_md(struct dev_filter *f, struct device *dev)
{
int ret;

View File

@@ -32,7 +32,7 @@ static int _locate_sysfs_blocks(const char *proc, char *path, size_t len)
return 0;
}
if (lvm_snprintf(proc_mounts, sizeof(proc_mounts),
if (dm_snprintf(proc_mounts, sizeof(proc_mounts),
"%s/mounts", proc) < 0) {
log_error("Failed to create /proc/mounts string");
return 0;
@@ -44,9 +44,9 @@ static int _locate_sysfs_blocks(const char *proc, char *path, size_t len)
}
while (fgets(buffer, sizeof(buffer), fp)) {
if (split_words(buffer, 4, split) == 4 &&
if (dm_split_words(buffer, 4, 0, split) == 4 &&
!strcmp(split[2], "sysfs")) {
if (lvm_snprintf(path, len, "%s/%s", split[1],
if (dm_snprintf(path, len, "%s/%s", split[1],
"block") >= 0) {
r = 1;
}
@@ -183,7 +183,7 @@ static int _read_devs(struct dev_set *ds, const char *dir)
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
if (lvm_snprintf(path, sizeof(path), "%s/%s", dir,
if (dm_snprintf(path, sizeof(path), "%s/%s", dir,
d->d_name) < 0) {
log_error("sysfs path name too long: %s in %s",
d->d_name, dir);

View File

@@ -145,7 +145,7 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn)
/* All types unrecognised initially */
memset(_max_partitions_by_major, 0, sizeof(int) * NUMBER_OF_MAJORS);
if (lvm_snprintf(proc_devices, sizeof(proc_devices),
if (dm_snprintf(proc_devices, sizeof(proc_devices),
"%s/devices", proc) < 0) {
log_error("Failed to create /proc/devices string");
return 0;

View File

@@ -458,7 +458,7 @@ static void _add_pv_to_list(struct list *head, struct disk_list *data)
/*
* Build a list of pv_d's structures, allocated from mem.
* We keep track of the first object allocated form the pool
* We keep track of the first object allocated from the pool
* so we can free off all the memory if something goes wrong.
*/
int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
@@ -576,7 +576,7 @@ static int _write_lvs(struct disk_list *data)
pos = data->pvd.lv_on_disk.base;
if (!dev_zero(data->dev, pos, data->pvd.lv_on_disk.size)) {
if (!dev_set(data->dev, pos, data->pvd.lv_on_disk.size, 0)) {
log_error("Couldn't zero lv area on device '%s'",
dev_name(data->dev));
return 0;

View File

@@ -172,6 +172,7 @@ struct disk_list {
* Layout constants.
*/
#define METADATA_ALIGN 4096UL
#define LVM1_PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
#define METADATA_BASE 0UL
#define PV_SIZE 1024UL

View File

@@ -408,7 +408,7 @@ static int _format1_pv_write(const struct format_type *fmt, struct physical_volu
/* Ensure any residual PE structure is gone */
pv->pe_size = pv->pe_count = 0;
pv->pe_start = PE_ALIGN;
pv->pe_start = LVM1_PE_ALIGN;
if (!(mem = dm_pool_create("lvm1 pv_write", 1024))) {
stack;
@@ -431,7 +431,7 @@ static int _format1_pv_write(const struct format_type *fmt, struct physical_volu
dev_write in order to make other disk tools happy */
dl->pvd.pv_on_disk.base = METADATA_BASE;
dl->pvd.pv_on_disk.size = PV_SIZE;
dl->pvd.pe_on_disk.base = PE_ALIGN << SECTOR_SHIFT;
dl->pvd.pe_on_disk.base = LVM1_PE_ALIGN << SECTOR_SHIFT;
list_add(&pvs, &dl->list);
if (!write_disks(fmt, &pvs)) {

View File

@@ -103,7 +103,7 @@ int import_pv(struct dm_pool *mem, struct device *dev,
static int _system_id(struct cmd_context *cmd, char *s, const char *prefix)
{
if (lvm_snprintf(s, NAME_LEN, "%s%s%lu",
if (dm_snprintf(s, NAME_LEN, "%s%s%lu",
prefix, cmd->hostname, time(NULL)) < 0) {
log_error("Generated system_id too long");
return 0;

View File

@@ -153,7 +153,7 @@ int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
if (pe_start && end < pe_start)
end = pe_start;
pvd->pe_start = _round_up(end, PE_ALIGN);
pvd->pe_start = _round_up(end, LVM1_PE_ALIGN);
} while ((pvd->pe_start + (pvd->pe_total * extent_size))
> pv->size);

View File

@@ -277,7 +277,7 @@ int archive_vg(struct volume_group *vg,
}
for (i = 0; i < 10; i++) {
if (lvm_snprintf(archive_name, sizeof(archive_name),
if (dm_snprintf(archive_name, sizeof(archive_name),
"%s/%s_%05u.vg", dir, vg->name, ix) < 0) {
log_error("Archive file name too long.");
return 0;

View File

@@ -190,7 +190,7 @@ static int __backup(struct volume_group *vg)
return 0;
}
if (lvm_snprintf(name, sizeof(name), "%s/%s",
if (dm_snprintf(name, sizeof(name), "%s/%s",
vg->cmd->backup_params->dir, vg->name) < 0) {
log_error("Failed to generate volume group metadata backup "
"filename.");
@@ -233,7 +233,7 @@ int backup_remove(struct cmd_context *cmd, const char *vg_name)
{
char path[PATH_MAX];
if (lvm_snprintf(path, sizeof(path), "%s/%s",
if (dm_snprintf(path, sizeof(path), "%s/%s",
cmd->backup_params->dir, vg_name) < 0) {
log_err("Failed to generate backup filename (for removal).");
return 0;
@@ -342,7 +342,7 @@ int backup_restore(struct cmd_context *cmd, const char *vg_name)
{
char path[PATH_MAX];
if (lvm_snprintf(path, sizeof(path), "%s/%s",
if (dm_snprintf(path, sizeof(path), "%s/%s",
cmd->backup_params->dir, vg_name) < 0) {
log_err("Failed to generate backup filename (for restore).");
return 0;
@@ -397,7 +397,7 @@ void check_current_backup(struct volume_group *vg)
if ((vg->status & PARTIAL_VG) || (vg->status & EXPORTED_VG))
return;
if (lvm_snprintf(path, sizeof(path), "%s/%s",
if (dm_snprintf(path, sizeof(path), "%s/%s",
vg->cmd->backup_params->dir, vg->name) < 0) {
log_debug("Failed to generate backup filename.");
return;

View File

@@ -183,7 +183,8 @@ static int _out_with_comment_file(struct formatter *f, const char *comment,
return 1;
}
static int _out_with_comment_raw(struct formatter *f, const char *comment,
static int _out_with_comment_raw(struct formatter *f,
const char *comment __attribute((unused)),
const char *fmt, va_list ap)
{
int n;
@@ -232,7 +233,7 @@ static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s)
for (i = 0; (d > 1024.0) && _units[i]; i++)
d /= 1024.0;
return lvm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0;
return dm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0;
}
/*
@@ -281,7 +282,7 @@ int out_text(struct formatter *f, const char *fmt, ...)
}
static int _print_header(struct formatter *f,
struct volume_group *vg, const char *desc)
const char *desc)
{
time_t t;
@@ -408,6 +409,11 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg)
outf(f, "tags = %s", buffer);
}
if (!out_size(f, pv->size, "dev_size = %" PRIu64, pv->size)) {
stack;
return 0;
}
outf(f, "pe_start = %" PRIu64, pv->pe_start);
if (!out_size(f, vg->extent_size * (uint64_t) pv->pe_count,
"pe_count = %u", pv->pe_count)) {
@@ -612,46 +618,27 @@ static int _build_pv_names(struct formatter *f, struct volume_group *vg)
struct physical_volume *pv;
char buffer[32], *name;
if (!(f->mem = dm_pool_create("text pv_names", 512))) {
stack;
goto bad;
}
if (!(f->mem = dm_pool_create("text pv_names", 512)))
return_0;
if (!(f->pv_names = dm_hash_create(128))) {
stack;
goto bad;
}
if (!(f->pv_names = dm_hash_create(128)))
return_0;
list_iterate_items(pvl, &vg->pvs) {
pv = pvl->pv;
/* FIXME But skip if there's already an LV called pv%d ! */
if (lvm_snprintf(buffer, sizeof(buffer), "pv%d", count++) < 0) {
stack;
goto bad;
}
if (dm_snprintf(buffer, sizeof(buffer), "pv%d", count++) < 0)
return_0;
if (!(name = dm_pool_strdup(f->mem, buffer))) {
stack;
goto bad;
}
if (!(name = dm_pool_strdup(f->mem, buffer)))
return_0;
if (!dm_hash_insert(f->pv_names, dev_name(pv->dev), name)) {
stack;
goto bad;
}
if (!dm_hash_insert(f->pv_names, dev_name(pv->dev), name))
return_0;
}
return 1;
bad:
if (f->mem)
dm_pool_destroy(f->mem);
if (f->pv_names)
dm_hash_destroy(f->pv_names);
return 0;
}
static int _text_vg_export(struct formatter *f,
@@ -663,35 +650,33 @@ static int _text_vg_export(struct formatter *f,
stack;
goto out;
}
#define fail do {stack; goto out;} while(0)
if (f->header && !_print_header(f, vg, desc))
fail;
if (f->header && !_print_header(f, desc))
goto_out;
if (!out_text(f, "%s {", vg->name))
fail;
goto_out;
_inc_indent(f);
if (!_print_vg(f, vg))
fail;
goto_out;
outnl(f);
if (!_print_pvs(f, vg))
fail;
goto_out;
outnl(f);
if (!_print_lvs(f, vg))
fail;
goto_out;
_dec_indent(f);
if (!out_text(f, "}"))
fail;
goto_out;
if (!f->header && !_print_header(f, vg, desc))
fail;
if (!f->header && !_print_header(f, desc))
goto_out;
#undef fail
r = 1;
out:

View File

@@ -53,6 +53,7 @@ static struct flag _lv_flags[] = {
{VISIBLE_LV, "VISIBLE"},
{PVMOVE, "PVMOVE"},
{LOCKED, "LOCKED"},
{MIRROR_NOTSYNCED, "NOTSYNCED"},
{MIRROR_IMAGE, NULL},
{MIRROR_LOG, NULL},
{MIRRORED, NULL},

View File

@@ -69,7 +69,8 @@ struct text_context {
* NOTE: Currently there can be only one vg per text file.
*/
static int _text_vg_setup(struct format_instance *fid, struct volume_group *vg)
static int _text_vg_setup(struct format_instance *fid __attribute((unused)),
struct volume_group *vg)
{
if (vg->extent_size & (vg->extent_size - 1)) {
log_error("Extent size must be power of 2");
@@ -79,7 +80,8 @@ static int _text_vg_setup(struct format_instance *fid, struct volume_group *vg)
return 1;
}
static int _text_lv_setup(struct format_instance *fid, struct logical_volume *lv)
static int _text_lv_setup(struct format_instance *fid __attribute((unused)),
struct logical_volume *lv)
{
/******** FIXME Any LV size restriction?
uint64_t max_size = UINT_MAX;
@@ -851,7 +853,7 @@ static int _scan_file(const struct format_type *fmt)
tmp != dirent->d_name + strlen(dirent->d_name)
- 4)) {
vgname = dirent->d_name;
if (lvm_snprintf(path, PATH_MAX, "%s/%s",
if (dm_snprintf(path, PATH_MAX, "%s/%s",
dl->dir, vgname) < 0) {
log_error("Name too long %s/%s",
dl->dir, vgname);
@@ -992,7 +994,7 @@ static int _text_scan(const struct format_type *fmt)
}
/* For orphan, creates new mdas according to policy.
Always have an mda between end-of-label and PE_ALIGN boundary */
Always have an mda between end-of-label and pe_align() boundary */
static int _mda_setup(const struct format_type *fmt,
uint64_t pe_start, uint64_t pe_end,
int pvmetadatacopies,
@@ -1003,15 +1005,12 @@ static int _mda_setup(const struct format_type *fmt,
uint64_t start1, mda_size1; /* First area - start of disk */
uint64_t start2, mda_size2; /* Second area - end of disk */
uint64_t wipe_size = 8 << SECTOR_SHIFT;
size_t pagesize = getpagesize();
size_t pagesize = lvm_getpagesize();
if (!pvmetadatacopies) {
/* Space available for PEs */
pv->size -= PE_ALIGN;
if (!pvmetadatacopies)
return 1;
}
alignment = PE_ALIGN << SECTOR_SHIFT;
alignment = pe_align() << SECTOR_SHIFT;
disk_size = pv->size << SECTOR_SHIFT;
pe_start <<= SECTOR_SHIFT;
pe_end <<= SECTOR_SHIFT;
@@ -1025,9 +1024,6 @@ static int _mda_setup(const struct format_type *fmt,
/* Requested metadatasize */
mda_size1 = pvmetadatasize << SECTOR_SHIFT;
/* Space available for PEs (before any mdas created) */
pv->size -= LABEL_SCAN_SECTORS;
/* Place mda straight after label area at start of disk */
start1 = LABEL_SCAN_SIZE;
@@ -1035,11 +1031,8 @@ static int _mda_setup(const struct format_type *fmt,
if ((!pe_start && !pe_end) ||
((pe_start > start1) && (pe_start - start1 >= MDA_SIZE_MIN))) {
mda_adjustment = start1 % pagesize;
if (mda_adjustment) {
if (mda_adjustment)
start1 += (pagesize - mda_adjustment);
pv->size -= ((pagesize - mda_adjustment) >>
SECTOR_SHIFT);
}
}
/* Ensure it's not going to be bigger than the disk! */
@@ -1053,7 +1046,7 @@ static int _mda_setup(const struct format_type *fmt,
pvmetadatacopies = 1;
}
/* Round up to PE_ALIGN boundary */
/* Round up to pe_align() boundary */
mda_adjustment = (mda_size1 + start1) % alignment;
if (mda_adjustment)
mda_size1 += (alignment - mda_adjustment);
@@ -1069,16 +1062,16 @@ static int _mda_setup(const struct format_type *fmt,
/* FIXME If creating new mdas, wipe them! */
if (mda_size1) {
if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start1,
mda_size1)) return 0;
mda_size1))
return 0;
if (!dev_zero((struct device *) pv->dev, start1,
(size_t) (mda_size1 >
wipe_size ? : mda_size1))) {
if (!dev_set((struct device *) pv->dev, start1,
(size_t) (mda_size1 >
wipe_size ? : mda_size1), 0)) {
log_error("Failed to wipe new metadata area");
return 0;
}
pv->size -= mda_size1 >> SECTOR_SHIFT;
if (pvmetadatacopies == 1)
return 1;
} else
@@ -1117,13 +1110,12 @@ static int _mda_setup(const struct format_type *fmt,
if (mda_size2) {
if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start2,
mda_size2)) return 0;
if (!dev_zero(pv->dev, start2,
(size_t) (mda_size1 >
wipe_size ? : mda_size1))) {
if (!dev_set(pv->dev, start2,
(size_t) (mda_size1 >
wipe_size ? : mda_size1), 0)) {
log_error("Failed to wipe new metadata area");
return 0;
}
pv->size -= mda_size2 >> SECTOR_SHIFT;
} else
return 0;
@@ -1187,22 +1179,22 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
/* Set pe_start to first aligned sector after any metadata
* areas that begin before pe_start */
pv->pe_start = PE_ALIGN;
pv->pe_start = pe_align();
list_iterate_items(mda, &info->mdas) {
mdac = (struct mda_context *) mda->metadata_locn;
if (pv->dev == mdac->area.dev &&
(mdac->area.start < (pv->pe_start << SECTOR_SHIFT)) &&
(mdac->area.start <= (pv->pe_start << SECTOR_SHIFT)) &&
(mdac->area.start + mdac->area.size >
(pv->pe_start << SECTOR_SHIFT))) {
pv->pe_start = (mdac->area.start + mdac->area.size)
>> SECTOR_SHIFT;
adjustment = pv->pe_start % PE_ALIGN;
adjustment = pv->pe_start % pe_align();
if (adjustment)
pv->pe_start += (PE_ALIGN - adjustment);
pv->pe_start += (pe_align() - adjustment);
}
}
if (!add_da
(fmt, NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) {
(NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) {
stack;
return 0;
}
@@ -1339,7 +1331,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
return 1;
}
static void _text_destroy_instance(struct format_instance *fid)
static void _text_destroy_instance(struct format_instance *fid __attribute((unused)))
{
return;
}
@@ -1372,7 +1364,7 @@ static void _text_destroy(const struct format_type *fmt)
dm_free(fmt->private);
}
dm_free((void *) fmt);
dm_free((void *)fmt);
}
static struct metadata_area_ops _metadata_text_file_ops = {
@@ -1414,8 +1406,8 @@ static int _text_pv_setup(const struct format_type *fmt,
struct lvmcache_info *info;
int found;
uint64_t pe_end = 0;
/* FIXME if vg, adjust start/end of pe area to avoid mdas! */
unsigned mda_count = 0;
uint64_t mda_size2 = 0;
/* FIXME Cope with pvchange */
/* FIXME Merge code with _text_create_text_instance */
@@ -1426,11 +1418,16 @@ static int _text_pv_setup(const struct format_type *fmt,
if ((info = info_from_pvid(pv->dev->pvid))) {
pvmdas = &info->mdas;
list_iterate_items(mda, pvmdas) {
mda_count++;
mdac =
(struct mda_context *) mda->metadata_locn;
/* FIXME Check it isn't already in use */
/* Reduce usable device size */
if (mda_count > 1)
mda_size2 = mdac->area.size >> SECTOR_SHIFT;
/* Ensure it isn't already on list */
found = 0;
list_iterate_items(mda2, mdas) {
@@ -1468,6 +1465,17 @@ static int _text_pv_setup(const struct format_type *fmt,
}
}
/* FIXME Cope with genuine pe_count 0 */
/* If missing, estimate pv->size from file-based metadata */
if (!pv->size && pv->pe_count)
pv->size = pv->pe_count * (uint64_t) vg->extent_size +
pv->pe_start + mda_size2;
/* Recalculate number of extents that will fit */
if (!pv->pe_count)
pv->pe_count = (pv->size - pv->pe_start - mda_size2) / vg->extent_size;
/* Unlike LVM1, we don't store this outside a VG */
/* FIXME Default from config file? vgextend cmdline flag? */
pv->status |= ALLOCATABLE_PV;
@@ -1531,7 +1539,7 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
dir_list = &((struct mda_lists *) fmt->private)->dirs;
list_iterate_items(dl, dir_list) {
if (lvm_snprintf(path, PATH_MAX, "%s/%s",
if (dm_snprintf(path, PATH_MAX, "%s/%s",
dl->dir, vgname) < 0) {
log_error("Name too long %s/%s", dl->dir,
vgname);
@@ -1781,7 +1789,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
return NULL;
}
if ((cn = find_config_node(cmd->cft->root, "metadata/dirs"))) {
if ((cn = find_config_tree_node(cmd, "metadata/dirs"))) {
for (cv = cn->v; cv; cv = cv->next) {
if (cv->type != CFG_STRING) {
log_error("Invalid string in config file: "
@@ -1797,7 +1805,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
}
}
if ((cn = find_config_node(cmd->cft->root, "metadata/disk_areas"))) {
if ((cn = find_config_tree_node(cmd, "metadata/disk_areas"))) {
for (cn = cn->child; cn; cn = cn->sib) {
if (!_get_config_disk_area(cmd, cn, &mda_lists->raws))
goto err;

View File

@@ -46,7 +46,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt);
int pvhdr_read(struct device *dev, char *buf);
int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
int add_da(struct dm_pool *mem, struct list *das,
uint64_t start, uint64_t size);
void del_das(struct list *das);

View File

@@ -129,6 +129,6 @@ struct volume_group *text_vg_import_file(struct format_instance *fid,
const char *file,
time_t *when, char **desc)
{
return text_vg_import_fd(fid, file, NULL, 0, 0, 0, 0, NULL, 0,
return text_vg_import_fd(fid, file, NULL, (off_t)0, 0, (off_t)0, 0, NULL, 0,
when, desc);
}

View File

@@ -179,6 +179,9 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
return 0;
}
/* Late addition */
_read_int64(pvn, "dev_size", &pv->size);
if (!_read_int64(pvn, "pe_start", &pv->pe_start)) {
log_error("Couldn't read extent size for volume group.");
return 0;
@@ -206,7 +209,7 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
vg->free_count += pv->pe_count;
pv->pe_size = vg->extent_size;
pv->size = vg->extent_size * (uint64_t) pv->pe_count;
pv->pe_alloc_count = 0;
pv->fmt = fid->fmt;

View File

@@ -83,6 +83,6 @@ struct mda_context {
#define FMTT_VERSION 1
#define MDA_HEADER_SIZE 512
#define LVM2_LABEL "LVM2 001"
#define MDA_SIZE_MIN (8 * (unsigned) getpagesize())
#define MDA_SIZE_MIN (8 * (unsigned) lvm_getpagesize())
#endif

View File

@@ -23,7 +23,9 @@
#include <sys/stat.h>
#include <fcntl.h>
static int _text_can_handle(struct labeller *l, char *buf, uint64_t sector)
static int _text_can_handle(struct labeller *l __attribute((unused)),
char *buf,
uint64_t sector __attribute((unused)))
{
struct label_header *lh = (struct label_header *) buf;
@@ -86,7 +88,7 @@ static int _text_write(struct label *label, char *buf)
return 1;
}
int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
int add_da(struct dm_pool *mem, struct list *das,
uint64_t start, uint64_t size)
{
struct data_area_list *dal;
@@ -179,7 +181,8 @@ void del_mdas(struct list *mdas)
}
}
static int _text_initialise_label(struct labeller *l, struct label *label)
static int _text_initialise_label(struct labeller *l __attribute((unused)),
struct label *label)
{
strncpy(label->type, LVM2_LABEL, sizeof(label->type));
@@ -220,7 +223,7 @@ static int _text_read(struct labeller *l, struct device *dev, char *buf,
/* Data areas holding the PEs */
dlocn_xl = pvhdr->disk_areas_xl;
while ((offset = xlate64(dlocn_xl->offset))) {
add_da(info->fmt, NULL, &info->das, offset,
add_da(NULL, &info->das, offset,
xlate64(dlocn_xl->size));
dlocn_xl++;
}
@@ -248,7 +251,8 @@ static int _text_read(struct labeller *l, struct device *dev, char *buf,
return 1;
}
static void _text_destroy_label(struct labeller *l, struct label *label)
static void _text_destroy_label(struct labeller *l __attribute((unused)),
struct label *label)
{
struct lvmcache_info *info = (struct lvmcache_info *) label->info;

View File

@@ -271,7 +271,7 @@ int label_read(struct device *dev, struct label **result)
lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN,
0, NULL);
goto out;
return r;
}
if (!(l = _find_labeller(dev, buf, &sector)))

View File

@@ -256,7 +256,7 @@ static int _cluster_request(char cmd, const char *node, void *data, int len,
strcpy(rarray[i].node, inptr);
inptr += strlen(inptr) + 1;
rarray[i].status = *(int *) inptr;
memcpy(&rarray[i].status, inptr, sizeof(int));
inptr += sizeof(int);
rarray[i].response = dm_malloc(strlen(inptr) + 1);
@@ -333,6 +333,12 @@ static int _lock_for_cluster(unsigned char cmd, unsigned int flags, char *name)
if (partial_mode())
args[1] |= LCK_PARTIAL_MODE;
if (mirror_in_sync())
args[1] |= LCK_MIRROR_NOSYNC_MODE;
if (dmeventd_register_mode())
args[1] |= LCK_DMEVENTD_REGISTER_MODE;
/*
* VG locks are just that: locks, and have no side effects
* so we only need to do them on the local node because all
@@ -392,9 +398,9 @@ int lock_resource(struct cmd_context *cmd, const char *resource, int flags)
case LCK_VG:
/* If the VG name is empty then lock the unused PVs */
if (!*resource)
lvm_snprintf(lockname, sizeof(lockname), "P_orphans");
dm_snprintf(lockname, sizeof(lockname), "P_orphans");
else
lvm_snprintf(lockname, sizeof(lockname), "V_%s",
dm_snprintf(lockname, sizeof(lockname), "V_%s",
resource);
cluster_cmd = CLVMD_CMD_LOCK_VG;
@@ -446,7 +452,7 @@ void reset_locking(void)
}
#ifdef CLUSTER_LOCKING_INTERNAL
int init_cluster_locking(struct locking_type *locking, struct config_tree *cft)
int init_cluster_locking(struct locking_type *locking, struct cmd_context *cmd)
{
locking->lock_resource = _lock_resource;
locking->fin_locking = _locking_end;

View File

@@ -17,6 +17,7 @@
#include "locking_types.h"
#include "defaults.h"
#include "sharedlib.h"
#include "toolcontext.h"
static void *_locking_lib = NULL;
static void (*_reset_fn) (void) = NULL;
@@ -55,7 +56,7 @@ static void _reset_external_locking(void)
_reset_fn();
}
int init_external_locking(struct locking_type *locking, struct config_tree *cft)
int init_external_locking(struct locking_type *locking, struct cmd_context *cmd)
{
const char *libname;
@@ -69,10 +70,10 @@ int init_external_locking(struct locking_type *locking, struct config_tree *cft)
locking->reset_locking = _reset_external_locking;
locking->flags = 0;
libname = find_config_str(cft->root, "global/locking_library",
DEFAULT_LOCKING_LIB);
libname = find_config_tree_str(cmd, "global/locking_library",
DEFAULT_LOCKING_LIB);
if (!(_locking_lib = load_shared_library(cft, libname, "locking", 1))) {
if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1))) {
stack;
return 0;
}
@@ -90,5 +91,5 @@ int init_external_locking(struct locking_type *locking, struct config_tree *cft)
}
log_verbose("Loaded external locking library %s", libname);
return _init_fn(2, cft, &locking->flags);
return _init_fn(2, cmd->cft, &locking->flags);
}

View File

@@ -105,7 +105,7 @@ static void _remove_ctrl_c_handler()
log_sys_error("signal", "_remove_ctrl_c_handler");
}
static void _trap_ctrl_c(int sig)
static void _trap_ctrl_c(int sig __attribute((unused)))
{
_remove_ctrl_c_handler();
log_error("CTRL-c detected: giving up waiting for lock");
@@ -212,10 +212,10 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
switch (flags & LCK_SCOPE_MASK) {
case LCK_VG:
if (!*resource)
lvm_snprintf(lockfile, sizeof(lockfile),
dm_snprintf(lockfile, sizeof(lockfile),
"%s/P_orphans", _lock_dir);
else
lvm_snprintf(lockfile, sizeof(lockfile),
dm_snprintf(lockfile, sizeof(lockfile),
"%s/V_%s", _lock_dir, resource);
if (!_lock_file(lockfile, flags))
@@ -271,7 +271,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
return 1;
}
int init_file_locking(struct locking_type *locking, struct config_tree *cft)
int init_file_locking(struct locking_type *locking, struct cmd_context *cmd)
{
locking->lock_resource = _file_lock_resource;
locking->reset_locking = _reset_file_locking;
@@ -279,8 +279,8 @@ int init_file_locking(struct locking_type *locking, struct config_tree *cft)
locking->flags = 0;
/* Get lockfile directory from config file */
strncpy(_lock_dir, find_config_str(cft->root, "global/locking_dir",
DEFAULT_LOCK_DIR),
strncpy(_lock_dir, find_config_tree_str(cmd, "global/locking_dir",
DEFAULT_LOCK_DIR),
sizeof(_lock_dir));
if (!create_dir(_lock_dir))

View File

@@ -20,6 +20,7 @@
#include "activate.h"
#include "toolcontext.h"
#include "memlock.h"
#include "defaults.h"
#include <signal.h>
#include <sys/stat.h>
@@ -33,7 +34,7 @@ static int _vg_lock_count = 0; /* Number of locks held */
static int _vg_write_lock_held = 0; /* VG write lock held? */
static int _signals_blocked = 0;
static void _block_signals(int flags)
static void _block_signals(int flags __attribute((unused)))
{
sigset_t set;
@@ -122,36 +123,43 @@ static void _update_vg_lock_count(int flags)
/*
* Select a locking type
*/
int init_locking(int type, struct config_tree *cft)
int init_locking(int type, struct cmd_context *cmd)
{
init_lockingfailed(0);
switch (type) {
case 0:
init_no_locking(&_locking, cft);
init_no_locking(&_locking, cmd);
log_print("WARNING: Locking disabled. Be careful! "
"This could corrupt your metadata.");
return 1;
case 1:
if (!init_file_locking(&_locking, cft))
log_very_verbose("File-based locking selected.");
if (!init_file_locking(&_locking, cmd))
break;
log_very_verbose("File-based locking enabled.");
return 1;
#ifdef HAVE_LIBDL
case 2:
if (!init_external_locking(&_locking, cft))
if (!cmd->is_static) {
log_very_verbose("External locking selected.");
if (!init_external_locking(&_locking, cmd))
break;
return 1;
}
if (!find_config_tree_int(cmd, "locking/fallback_to_clustered_locking",
DEFAULT_FALLBACK_TO_CLUSTERED_LOCKING))
break;
log_very_verbose("External locking enabled.");
return 1;
log_very_verbose("Falling back to clustered locking.");
/* Fall through */
#endif
#ifdef CLUSTER_LOCKING_INTERNAL
case 3:
if (!init_cluster_locking(&_locking, cft))
log_very_verbose("Cluster locking selected.");
if (!init_cluster_locking(&_locking, cmd))
break;
log_very_verbose("Cluster locking enabled.");
return 1;
#endif
@@ -160,13 +168,23 @@ int init_locking(int type, struct config_tree *cft)
return 0;
}
if ((type == 2 || type == 3) &&
find_config_tree_int(cmd, "locking/fallback_to_local_locking",
DEFAULT_FALLBACK_TO_LOCAL_LOCKING)) {
log_print("WARNING: Falling back to local file-based locking.");
log_print("Volume Groups with the clustered attribute will "
"be inaccessible.");
if (init_file_locking(&_locking, cmd))
return 1;
}
if (!ignorelockingfailure())
return 0;
/* FIXME Ensure only read ops are permitted */
log_verbose("Locking disabled - only read operations permitted.");
init_no_locking(&_locking, cft);
init_no_locking(&_locking, cmd);
init_lockingfailed(1);
return 1;
@@ -189,7 +207,7 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname)
if (!*vgname)
return 1;
if (lvm_snprintf(path, sizeof(path), "%s/lvm/VGs/%s", cmd->proc_dir,
if (dm_snprintf(path, sizeof(path), "%s/lvm/VGs/%s", cmd->proc_dir,
vgname) < 0) {
log_error("LVM1 proc VG pathname too long for %s", vgname);
return 0;

View File

@@ -19,7 +19,7 @@
#include "uuid.h"
#include "config.h"
int init_locking(int type, struct config_tree *cf);
int init_locking(int type, struct cmd_context *cmd);
void fin_locking(void);
void reset_locking(void);
int vg_write_lock_held(void);
@@ -74,6 +74,9 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
* Additional lock bits for cluster communication
*/
#define LCK_PARTIAL_MODE 0x00000001 /* Running in partial mode */
#define LCK_MIRROR_NOSYNC_MODE 0x00000002 /* Mirrors don't require sync */
#define LCK_DMEVENTD_REGISTER_MODE 0x00000004 /* Register with dmeventd */
/*
* Common combinations

View File

@@ -36,10 +36,10 @@ struct locking_type {
/*
* Locking types
*/
int init_no_locking(struct locking_type *locking, struct config_tree *cf);
int init_no_locking(struct locking_type *locking, struct cmd_context *cmd);
int init_file_locking(struct locking_type *locking, struct config_tree *cf);
int init_file_locking(struct locking_type *locking, struct cmd_context *cmd);
int init_external_locking(struct locking_type *locking, struct config_tree *cf);
int init_external_locking(struct locking_type *locking, struct cmd_context *cmd);
int init_cluster_locking(struct locking_type *locking, struct config_tree *cf);
int init_cluster_locking(struct locking_type *locking, struct cmd_context *cmd);

View File

@@ -76,7 +76,7 @@ static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
return 1;
}
int init_no_locking(struct locking_type *locking, struct config_tree *cft)
int init_no_locking(struct locking_type *locking, struct cmd_context *cmd)
{
locking->lock_resource = _no_lock_resource;
locking->reset_locking = _no_reset_locking;

View File

@@ -17,6 +17,7 @@
#include "device.h"
#include "memlock.h"
#include "lvm-string.h"
#include "defaults.h"
#include <stdarg.h>
#include <syslog.h>
@@ -31,6 +32,7 @@ static int _partial = 0;
static int _md_filtering = 0;
static int _pvmove = 0;
static int _full_scan_done = 0; /* Restrict to one full scan during each cmd */
static int _trust_cache = 0; /* Don't scan when incomplete VGs encountered */
static int _debug_level = 0;
static int _syslog = 0;
static int _log_to_file = 0;
@@ -45,6 +47,8 @@ static int _security_level = SECURITY_LEVEL;
static char _cmd_name[30] = "";
static char _msg_prefix[30] = " ";
static int _already_logging = 0;
static int _mirror_in_sync = 0;
static int _dmeventd_register = DEFAULT_DMEVENTD_MONITOR;
static lvm2_log_fn_t _lvm2_log_fn = NULL;
@@ -160,6 +164,11 @@ void init_full_scan_done(int level)
_full_scan_done = level;
}
void init_trust_cache(int trustcache)
{
_trust_cache = trustcache;
}
void init_ignorelockingfailure(int level)
{
_ignorelockingfailure = level;
@@ -175,6 +184,16 @@ void init_security_level(int level)
_security_level = level;
}
void init_mirror_in_sync(int in_sync)
{
_mirror_in_sync = in_sync;
}
void init_dmeventd_register(int reg)
{
_dmeventd_register = reg;
}
void init_cmd_name(int status)
{
_log_cmd_name = status;
@@ -224,6 +243,11 @@ int full_scan_done()
return _full_scan_done;
}
int trust_cache()
{
return _trust_cache;
}
int lockingfailed()
{
return _lockingfailed;
@@ -239,6 +263,16 @@ int security_level()
return _security_level;
}
int mirror_in_sync(void)
{
return _mirror_in_sync;
}
int dmeventd_register_mode(void)
{
return _dmeventd_register;
}
void init_debug(int level)
{
_debug_level = level;
@@ -284,7 +318,7 @@ void print_log(int level, const char *file, int line, const char *format, ...)
log_it:
if (!_log_suppress) {
if (_verbose_level > _LOG_DEBUG)
lvm_snprintf(locn, sizeof(locn), "#%s:%d ",
dm_snprintf(locn, sizeof(locn), "#%s:%d ",
file, line);
else
locn[0] = '\0';
@@ -379,7 +413,7 @@ void print_log(int level, const char *file, int line, const char *format, ...)
_already_logging = 1;
memset(&buf, ' ', sizeof(buf));
bufused = 0;
if ((n = lvm_snprintf(buf, sizeof(buf) - bufused - 1,
if ((n = dm_snprintf(buf, sizeof(buf) - bufused - 1,
"%s:%d %s%s", file, line, _cmd_name,
_msg_prefix)) == -1)
goto done;

View File

@@ -66,6 +66,7 @@ void init_partial(int level);
void init_md_filtering(int level);
void init_pvmove(int level);
void init_full_scan_done(int level);
void init_trust_cache(int trustcache);
void init_debug(int level);
void init_cmd_name(int status);
void init_msg_prefix(const char *prefix);
@@ -73,6 +74,8 @@ void init_indent(int indent);
void init_ignorelockingfailure(int level);
void init_lockingfailed(int level);
void init_security_level(int level);
void init_mirror_in_sync(int in_sync);
void init_dmeventd_register(int reg);
void set_cmd_name(const char *cmd_name);
@@ -81,10 +84,13 @@ int partial_mode(void);
int md_filtering(void);
int pvmove_mode(void);
int full_scan_done(void);
int trust_cache(void);
int debug_level(void);
int ignorelockingfailure(void);
int lockingfailed(void);
int security_level(void);
int mirror_in_sync(void);
int dmeventd_register_mode(void);
/* Suppress messages to stdout/stderr (1) or everywhere (2) */
/* Returns previous setting */

View File

@@ -158,7 +158,7 @@ void release_lv_segment_area(struct lv_segment *seg, uint32_t s,
}
if (seg_lv(seg, s)->status & MIRROR_IMAGE) {
lv_reduce(seg_lv(seg, s), area_reduction);
lv_reduce(seg_lv(seg, s), area_reduction);
return;
}
@@ -398,6 +398,7 @@ struct alloced_area {
* Details of an allocation attempt
*/
struct alloc_handle {
struct cmd_context *cmd;
struct dm_pool *mem;
alloc_policy_t alloc; /* Overall policy */
@@ -417,7 +418,8 @@ struct alloc_handle {
/*
* Preparation for a specific allocation attempt
*/
static struct alloc_handle *_alloc_init(struct dm_pool *mem,
static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
struct dm_pool *mem,
const struct segment_type *segtype,
alloc_policy_t alloc,
uint32_t mirrors,
@@ -464,6 +466,8 @@ static struct alloc_handle *_alloc_init(struct dm_pool *mem,
if (segtype_is_virtual(segtype))
return ah;
ah->cmd = cmd;
if (!(ah->mem = dm_pool_create("allocation", 1024))) {
log_error("allocation pool creation failed");
return NULL;
@@ -490,6 +494,49 @@ void alloc_destroy(struct alloc_handle *ah)
dm_pool_destroy(ah->mem);
}
static int _log_parallel_areas(struct dm_pool *mem, struct list *parallel_areas)
{
struct seg_pvs *spvs;
struct pv_list *pvl;
char *pvnames;
if (!parallel_areas)
return 1;
if (!dm_pool_begin_object(mem, 256)) {
log_error("dm_pool_begin_object failed");
return 0;
}
list_iterate_items(spvs, parallel_areas) {
list_iterate_items(pvl, &spvs->pvs) {
if (!dm_pool_grow_object(mem, dev_name(pvl->pv->dev), strlen(dev_name(pvl->pv->dev)))) {
log_error("dm_pool_grow_object failed");
dm_pool_abandon_object(mem);
return 0;
}
if (!dm_pool_grow_object(mem, " ", 1)) {
log_error("dm_pool_grow_object failed");
dm_pool_abandon_object(mem);
return 0;
}
}
if (!dm_pool_grow_object(mem, "\0", 1)) {
log_error("dm_pool_grow_object failed");
dm_pool_abandon_object(mem);
return 0;
}
pvnames = dm_pool_end_object(mem);
log_debug("Parallel PVs at LE %" PRIu32 " length %" PRIu32 ": %s",
spvs->le, spvs->len, pvnames);
dm_pool_free(mem, pvnames);
}
return 1;
}
static int _setup_alloced_segment(struct logical_volume *lv, uint32_t status,
uint32_t area_count,
uint32_t stripe_size,
@@ -498,7 +545,7 @@ static int _setup_alloced_segment(struct logical_volume *lv, uint32_t status,
struct physical_volume *mirrored_pv,
uint32_t mirrored_pe,
uint32_t region_size,
struct logical_volume *log_lv)
struct logical_volume *log_lv __attribute((unused)))
{
uint32_t s, extents, area_multiple, extra_areas = 0;
struct lv_segment *seg;
@@ -614,7 +661,7 @@ static int _alloc_parallel_area(struct alloc_handle *ah, uint32_t needed,
if (log_area) {
ah->log_area.pv = log_area->map->pv;
ah->log_area.pe = log_area->start;
ah->log_area.len = 1; /* FIXME Calculate & check this */
ah->log_area.len = MIRROR_LOG_SIZE; /* FIXME Calculate & check this */
consume_pv_area(log_area, ah->log_area.len);
}
@@ -623,6 +670,82 @@ static int _alloc_parallel_area(struct alloc_handle *ah, uint32_t needed,
return 1;
}
/*
* Call fn for each AREA_PV used by the LV segment at lv:le of length *max_seg_len.
* If any constituent area contains more than one segment, max_seg_len is
* reduced to cover only the first.
* fn should return 0 on error, 1 to continue scanning or >1 to terminate without error.
* In the last case, this function passes on the return code.
*/
static int _for_each_pv(struct cmd_context *cmd, struct logical_volume *lv,
uint32_t le, uint32_t len, uint32_t *max_seg_len,
uint32_t first_area, uint32_t max_areas,
int top_level_area_index,
int only_single_area_segments,
int (*fn)(struct cmd_context *cmd,
struct pv_segment *peg, uint32_t s,
void *data),
void *data)
{
struct lv_segment *seg;
uint32_t s;
uint32_t remaining_seg_len, area_len, area_multiple;
int r = 1;
if (!(seg = find_seg_by_le(lv, le))) {
log_error("Failed to find segment for %s extent %" PRIu32,
lv->name, le);
return 0;
}
/* Remaining logical length of segment */
remaining_seg_len = seg->len - (le - seg->le);
if (remaining_seg_len > len)
remaining_seg_len = len;
if (max_seg_len && *max_seg_len > remaining_seg_len)
*max_seg_len = remaining_seg_len;
area_multiple = segtype_is_striped(seg->segtype) ? seg->area_count : 1;
area_len = remaining_seg_len / area_multiple ? : 1;
for (s = first_area;
s < seg->area_count && (!max_areas || s <= max_areas);
s++) {
if (seg_type(seg, s) == AREA_LV) {
if (!(r = _for_each_pv(cmd, seg_lv(seg, s),
seg_le(seg, s) +
(le - seg->le) / area_multiple,
area_len, max_seg_len,
only_single_area_segments ? 0 : 0,
only_single_area_segments ? 1 : 0,
top_level_area_index != -1 ? top_level_area_index : s,
only_single_area_segments, fn,
data)))
stack;
} else if (seg_type(seg, s) == AREA_PV)
if (!(r = fn(cmd, seg_pvseg(seg, s), top_level_area_index != -1 ? top_level_area_index : s, data)))
stack;
if (r != 1)
return r;
}
/* FIXME only_single_area_segments used as workaround to skip log LV - needs new param? */
if (!only_single_area_segments && seg_is_mirrored(seg) && seg->log_lv) {
if (!(r = _for_each_pv(cmd, seg->log_lv, 0, MIRROR_LOG_SIZE,
NULL, 0, 0, 0, only_single_area_segments,
fn, data)))
stack;
if (r != 1)
return r;
}
/* FIXME Add snapshot cow LVs etc. */
return 1;
}
static int _comp_area(const void *l, const void *r)
{
const struct pv_area *lhs = *((const struct pv_area **) l);
@@ -637,33 +760,114 @@ static int _comp_area(const void *l, const void *r)
return 0;
}
/*
* Search for pvseg that matches condition
*/
struct pv_match {
int (*condition)(struct pv_segment *pvseg, struct pv_area *pva);
struct pv_area **areas;
struct pv_area *pva;
uint32_t areas_size;
int s; /* Area index of match */
};
/*
* Is PV area on the same PV?
*/
static int _is_same_pv(struct pv_segment *pvseg, struct pv_area *pva)
{
if (pvseg->pv != pva->map->pv)
return 0;
return 1;
}
/*
* Is PV area contiguous to PV segment?
*/
static int _is_contiguous(struct pv_segment *pvseg, struct pv_area *pva)
{
if (pvseg->pv != pva->map->pv)
return 0;
if (pvseg->pe + pvseg->len != pva->start)
return 0;
return 1;
}
static int _is_condition(struct cmd_context *cmd,
struct pv_segment *pvseg, uint32_t s,
void *data)
{
struct pv_match *pvmatch = data;
if (!pvmatch->condition(pvseg, pvmatch->pva))
return 1; /* Continue */
if (s >= pvmatch->areas_size)
return 1;
pvmatch->areas[s] = pvmatch->pva;
return 2; /* Finished */
}
/*
* Is pva on same PV as any existing areas?
*/
static int _check_cling(struct cmd_context *cmd,
struct lv_segment *prev_lvseg, struct pv_area *pva,
struct pv_area **areas, uint32_t areas_size)
{
struct pv_match pvmatch;
int r;
pvmatch.condition = _is_same_pv;
pvmatch.areas = areas;
pvmatch.areas_size = areas_size;
pvmatch.pva = pva;
/* FIXME Cope with stacks by flattening */
if (!(r = _for_each_pv(cmd, prev_lvseg->lv,
prev_lvseg->le + prev_lvseg->len - 1, 1, NULL,
0, 0, -1, 1,
_is_condition, &pvmatch)))
stack;
if (r != 2)
return 0;
return 1;
}
/*
* Is pva contiguous to any existing areas or on the same PV?
*/
static int _check_contiguous(struct lv_segment *prev_lvseg,
struct physical_volume *pv, struct pv_area *pva,
struct pv_area **areas)
static int _check_contiguous(struct cmd_context *cmd,
struct lv_segment *prev_lvseg, struct pv_area *pva,
struct pv_area **areas, uint32_t areas_size)
{
struct pv_segment *prev_pvseg;
uint32_t s;
struct pv_match pvmatch;
int r;
for (s = 0; s < prev_lvseg->area_count; s++) {
if (seg_type(prev_lvseg, s) != AREA_PV)
continue; /* FIXME Broken */
pvmatch.condition = _is_contiguous;
pvmatch.areas = areas;
pvmatch.areas_size = areas_size;
pvmatch.pva = pva;
if (!(prev_pvseg = seg_pvseg(prev_lvseg, s)))
continue; /* FIXME Broken */
/* FIXME Cope with stacks by flattening */
if (!(r = _for_each_pv(cmd, prev_lvseg->lv,
prev_lvseg->le + prev_lvseg->len - 1, 1, NULL,
0, 0, -1, 1,
_is_condition, &pvmatch)))
stack;
if ((prev_pvseg->pv != pv))
continue;
if (r != 2)
return 0;
if (prev_pvseg->pe + prev_pvseg->len == pva->start) {
areas[s] = pva;
return 1;
}
}
return 0;
return 1;
}
/*
@@ -679,9 +883,9 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
struct pv_area *pva;
struct pv_list *pvl;
unsigned already_found_one = 0;
unsigned contiguous = 0, contiguous_count = 0;
unsigned contiguous = 0, cling = 0, preferred_count = 0;
unsigned ix;
unsigned ix_offset = 0; /* Offset for non-contiguous allocations */
unsigned ix_offset = 0; /* Offset for non-preferred allocations */
uint32_t max_parallel; /* Maximum extents to allocate */
uint32_t next_le;
struct seg_pvs *spvs;
@@ -691,9 +895,14 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
/* FIXME Select log PV appropriately if there isn't one yet */
/* Are there any preceding segments we must follow on from? */
if ((alloc == ALLOC_CONTIGUOUS) && prev_lvseg) {
contiguous = 1;
if (prev_lvseg) {
ix_offset = prev_lvseg->area_count;
if ((alloc == ALLOC_CONTIGUOUS))
contiguous = 1;
else if ((alloc == ALLOC_CLING))
cling = 1;
else
ix_offset = 0;
}
/* FIXME This algorithm needs a lot of cleaning up! */
@@ -702,6 +911,7 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
/* ix holds the number of areas found on other PVs */
do {
ix = 0;
preferred_count = 0;
parallel_pvs = NULL;
max_parallel = needed;
@@ -711,14 +921,15 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
* the maximum we can allocate in one go accordingly.
*/
if (ah->parallel_areas) {
next_le = (prev_lvseg ? prev_lvseg->le + prev_lvseg->len : 0) + *allocated / ah->area_multiple;
list_iterate_items(spvs, ah->parallel_areas) {
next_le = (prev_lvseg ? prev_lvseg->le + prev_lvseg->len : 0) + *allocated;
if (next_le >= spvs->le) {
if (next_le + max_parallel > spvs->le + spvs->len)
max_parallel = (spvs->le + spvs->len - next_le) * ah->area_multiple;
parallel_pvs = &spvs->pvs;
break;
}
if (next_le >= spvs->le + spvs->len)
continue;
if (max_parallel > (spvs->le + spvs->len) * ah->area_multiple)
max_parallel = (spvs->le + spvs->len) * ah->area_multiple;
parallel_pvs = &spvs->pvs;
break;
}
}
@@ -750,17 +961,30 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
list_iterate_items(pva, &pvm->areas) {
if (contiguous) {
if (prev_lvseg &&
_check_contiguous(prev_lvseg,
pvm->pv,
pva, areas)) {
contiguous_count++;
_check_contiguous(ah->cmd,
prev_lvseg,
pva, areas,
areas_size)) {
preferred_count++;
goto next_pv;
}
continue;
}
if (cling) {
if (prev_lvseg &&
_check_cling(ah->cmd,
prev_lvseg,
pva, areas,
areas_size)) {
preferred_count++;
}
goto next_pv;
}
/* Is it big enough on its own? */
if ((pva->count < max_parallel - *allocated) &&
if (pva->count * ah->area_multiple <
max_parallel - *allocated &&
((!can_split && !ah->log_count) ||
(already_found_one &&
!(alloc == ALLOC_ANYWHERE))))
@@ -781,7 +1005,7 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
break;
}
if (contiguous && (contiguous_count < ix_offset))
if ((contiguous || cling) && (preferred_count < ix_offset))
break;
/* Only allocate log_area the first time around */
@@ -853,6 +1077,9 @@ static int _allocate(struct alloc_handle *ah,
return 0;
}
if (!_log_parallel_areas(ah->mem, ah->parallel_areas))
stack;
areas_size = list_size(pvms);
if (areas_size < ah->area_count + ah->log_count) {
if (ah->alloc != ALLOC_ANYWHERE) {
@@ -887,6 +1114,18 @@ static int _allocate(struct alloc_handle *ah,
(!can_split && (allocated != old_allocated)))
goto finished;
old_allocated = allocated;
if (!_find_parallel_space(ah, ALLOC_CLING, pvms, areas,
areas_size, can_split,
prev_lvseg, &allocated, new_extents)) {
stack;
goto out;
}
if ((allocated == new_extents) || (ah->alloc == ALLOC_CLING) ||
(!can_split && (allocated != old_allocated)))
goto finished;
old_allocated = allocated;
if (!_find_parallel_space(ah, ALLOC_NORMAL, pvms, areas,
areas_size, can_split,
@@ -982,7 +1221,7 @@ struct alloc_handle *allocate_extents(struct volume_group *vg,
if (alloc == ALLOC_INHERIT)
alloc = vg->alloc;
if (!(ah = _alloc_init(vg->cmd->mem, segtype, alloc, mirrors,
if (!(ah = _alloc_init(vg->cmd, vg->cmd->mem, segtype, alloc, mirrors,
stripes, log_count, mirrored_pv,
mirrored_pe, parallel_areas))) {
stack;
@@ -1102,7 +1341,7 @@ int lv_add_mirror_segment(struct alloc_handle *ah,
struct lv_segment *seg;
uint32_t m;
if (list_empty(&log_lv->segments)) {
if (log_lv && list_empty(&log_lv->segments)) {
log_error("Log LV %s is empty.", log_lv->name);
return 0;
}
@@ -1213,7 +1452,7 @@ int lv_extend(struct logical_volume *lv,
log_error("Aborting. Failed to extend %s.",
seg_lv(seg, m)->name);
return 0;
}
}
}
seg->area_len += extents;
seg->len += extents;
@@ -1240,7 +1479,7 @@ char *generate_lv_name(struct volume_group *vg, const char *format,
high = i;
}
if (lvm_snprintf(buffer, len, format, high + 1) < 0)
if (dm_snprintf(buffer, len, format, high + 1) < 0)
return NULL;
return buffer;
@@ -1326,58 +1565,16 @@ struct logical_volume *lv_create_empty(struct format_instance *fi,
return lv;
}
/* Recursively process each PV used by part of an LV */
static int _for_each_pv(struct cmd_context *cmd, struct logical_volume *lv,
uint32_t le, uint32_t len,
int (*fn)(struct cmd_context *cmd, struct pv_segment *peg, struct seg_pvs *spvs),
struct seg_pvs *spvs)
{
struct lv_segment *seg;
uint32_t s;
uint32_t remaining_seg_len, area_len, area_multiple;
if (!(seg = find_seg_by_le(lv, le))) {
log_error("Failed to find segment for %s extent %" PRIu32,
lv->name, le);
return 0;
}
/* Remaining logical length of segment */
remaining_seg_len = seg->len - (le - seg->le);
if (len > remaining_seg_len)
remaining_seg_len = len;
if (spvs->len > remaining_seg_len)
spvs->len = remaining_seg_len;
area_multiple = segtype_is_striped(seg->segtype) ? seg->area_count : 1;
area_len = remaining_seg_len / area_multiple;
for (s = 0; s < seg->area_count; s++) {
if (seg_type(seg, s) == AREA_LV) {
if (!_for_each_pv(cmd, seg_lv(seg, s),
seg_le(seg, s) + (le - seg->le) / area_multiple,
area_len, fn, spvs)) {
stack;
return 0;
}
} else if (seg_type(seg, s) == AREA_PV) {
if (!fn(cmd, seg_pvseg(seg, s), spvs)) {
stack;
return 0;
}
}
}
return 1;
}
static int _add_pvs(struct cmd_context *cmd, struct pv_segment *peg, struct seg_pvs *spvs)
static int _add_pvs(struct cmd_context *cmd, struct pv_segment *peg,
uint32_t s __attribute((unused)), void *data)
{
struct seg_pvs *spvs = (struct seg_pvs *) data;
struct pv_list *pvl;
/* FIXME Don't add again if it's already on the list! */
/* Don't add again if it's already on list. */
list_iterate_items(pvl, &spvs->pvs)
if (pvl->pv == peg->pv)
return 1;
if (!(pvl = dm_pool_alloc(cmd->mem, sizeof(*pvl)))) {
log_error("pv_list allocation failed");
@@ -1386,11 +1583,8 @@ static int _add_pvs(struct cmd_context *cmd, struct pv_segment *peg, struct seg_
pvl->pv = peg->pv;
/* FIXME Use ordered list to facilitate comparison */
list_add(&spvs->pvs, &pvl->list);
/* FIXME Add mirror logs, snapshot cow LVs etc. */
return 1;
}
@@ -1426,7 +1620,8 @@ struct list *build_parallel_areas_from_lv(struct cmd_context *cmd,
/* Find next segment end */
/* FIXME Unnecessary nesting! */
if (!_for_each_pv(cmd, lv, current_le, lv->le_count, _add_pvs, spvs)) {
if (!_for_each_pv(cmd, lv, current_le, spvs->len, &spvs->len,
0, 0, -1, 0, _add_pvs, (void *) spvs)) {
stack;
return NULL;
}

View File

@@ -24,6 +24,13 @@
#include "pv_alloc.h"
#include "activate.h"
#include <sys/param.h>
unsigned long pe_align(void)
{
return MAX(65536UL, lvm_getpagesize()) >> SECTOR_SHIFT;
}
static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
const char *pv_name)
{
@@ -60,7 +67,7 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
}
/* Ensure PV doesn't depend on another PV already in the VG */
if (pv_uses_vg(fid->fmt->cmd, pv, vg)) {
if (pv_uses_vg(pv, vg)) {
log_error("Physical volume %s might be constructed from same "
"volume group %s", pv_name, vg->name);
return 0;
@@ -78,15 +85,12 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
/* FIXME Do proper rounding-up alignment? */
/* Reserved space for label; this holds 0 for PVs created by LVM1 */
if (pv->pe_start < PE_ALIGN)
pv->pe_start = PE_ALIGN;
if (pv->pe_start < pe_align())
pv->pe_start = pe_align();
/*
* The next two fields should be corrected
* by fid->pv_setup.
* pe_count must always be calculated by pv_setup
*/
pv->pe_count = (pv->size - pv->pe_start) / vg->extent_size;
pv->pe_alloc_count = 0;
if (!fid->fmt->ops->pv_setup(fid->fmt, UINT64_C(0), 0,
@@ -722,23 +726,70 @@ int vg_remove(struct volume_group *vg)
int vg_validate(struct volume_group *vg)
{
struct lv_list *lvl;
struct pv_list *pvl, *pvl2;
struct lv_list *lvl, *lvl2;
char uuid[64];
int r = 1;
/* FIXME Also check there's no data/metadata overlap */
list_iterate_items(pvl, &vg->pvs) {
list_iterate_items(pvl2, &vg->pvs) {
if (pvl == pvl2)
break;
if (id_equal(&pvl->pv->id,
&pvl2->pv->id)) {
if (!id_write_format(&pvl->pv->id, uuid,
sizeof(uuid)))
stack;
log_error("Internal error: Duplicate PV id "
"%s detected for %s in %s.",
uuid, dev_name(pvl->pv->dev),
vg->name);
r = 0;
}
}
}
if (!check_pv_segments(vg)) {
log_error("Internal error: PV segments corrupted in %s.",
vg->name);
return 0;
r = 0;
}
list_iterate_items(lvl, &vg->lvs) {
list_iterate_items(lvl2, &vg->lvs) {
if (lvl == lvl2)
break;
if (!strcmp(lvl->lv->name, lvl2->lv->name)) {
log_error("Internal error: Duplicate LV name "
"%s detected in %s.", lvl->lv->name,
vg->name);
r = 0;
}
if (id_equal(&lvl->lv->lvid.id[1],
&lvl2->lv->lvid.id[1])) {
if (!id_write_format(&lvl->lv->lvid.id[1], uuid,
sizeof(uuid)))
stack;
log_error("Internal error: Duplicate LV id "
"%s detected for %s and %s in %s.",
uuid, lvl->lv->name, lvl2->lv->name,
vg->name);
r = 0;
}
}
}
list_iterate_items(lvl, &vg->lvs) {
if (!check_lv_segments(lvl->lv, 1)) {
log_error("Internal error: LV segments corrupted in %s.",
lvl->lv->name);
return 0;
r = 0;
}
}
return 1;
return r;
}
/*
@@ -992,12 +1043,16 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
if (correct_vg) {
if (list_size(&correct_vg->pvs) != list_size(pvids)) {
log_debug("Cached VG %s had incorrect PV list",
vg->name);
correct_vg = NULL;
vgname);
if (memlock())
inconsistent = 1;
else
correct_vg = NULL;
} else list_iterate_items(pvl, &correct_vg->pvs) {
if (!str_list_match_item(pvids, pvl->pv->dev->pvid)) {
log_debug("Cached VG %s had incorrect PV list",
vg->name);
vgname);
correct_vg = NULL;
break;
}
@@ -1008,6 +1063,10 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
if (!correct_vg) {
inconsistent = 0;
if (memlock()) {
stack;
return NULL;
}
lvmcache_label_scan(cmd, 2);
if (!(fmt = fmt_from_vgname(vgname, vgid))) {
stack;
@@ -1149,7 +1208,8 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
if (!consistent) {
log_error("Volume group %s metadata is "
"inconsistent", vginfo->vgname);
return NULL;
if (!partial_mode())
return NULL;
}
return vg;
}
@@ -1342,7 +1402,7 @@ struct list *get_pvs(struct cmd_context *cmd)
return results;
}
int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
int pv_write(struct cmd_context *cmd __attribute((unused)), struct physical_volume *pv,
struct list *mdas, int64_t label_sector)
{
if (!pv->fmt->ops->pv_write) {

View File

@@ -29,12 +29,12 @@
#define MAX_STRIPES 128U
#define SECTOR_SHIFT 9L
#define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
#define STRIPE_SIZE_MIN ( (unsigned) getpagesize() >> SECTOR_SHIFT) /* PAGESIZE in sectors */
#define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT) /* PAGESIZE in sectors */
#define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
#define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
#define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
#define PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
#define MAX_RESTRICTED_LVS 255 /* Used by FMT_RESTRICTED_LVIDS */
#define MIRROR_LOG_SIZE 1 /* Extents */
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
@@ -58,8 +58,9 @@
#define VIRTUAL 0x00010000U /* LV - internal use only */
#define MIRROR_LOG 0x00020000U /* LV */
#define MIRROR_IMAGE 0x00040000U /* LV */
#define ACTIVATE_EXCL 0x00080000U /* LV - internal use only */
#define PRECOMMITTED 0x00100000U /* VG - internal use only */
#define MIRROR_NOTSYNCED 0x00080000U /* LV */
#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */
#define PRECOMMITTED 0x00200000U /* VG - internal use only */
#define LVM_READ 0x00000100U /* LV VG */
#define LVM_WRITE 0x00000200U /* LV VG */
@@ -81,6 +82,7 @@ typedef enum {
ALLOC_INVALID = 0,
ALLOC_INHERIT,
ALLOC_CONTIGUOUS,
ALLOC_CLING,
ALLOC_NORMAL,
ALLOC_ANYWHERE
} alloc_policy_t;
@@ -402,6 +404,7 @@ struct format_handler {
/*
* Utility functions
*/
unsigned long pe_align(void);
int vg_validate(struct volume_group *vg);
int vg_write(struct volume_group *vg);
int vg_commit(struct volume_group *vg);
@@ -580,6 +583,8 @@ int add_mirror_layers(struct alloc_handle *ah,
int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
struct list *removable_pvs, int remove_log);
int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
struct list *removable_pvs, int remove_log);
/*
* Given mirror image or mirror log segment, find corresponding mirror segment
*/

View File

@@ -23,6 +23,13 @@
#include "lvm-string.h"
#include "locking.h" /* FIXME Should not be used in this file */
#include "defaults.h" /* FIXME: should this be defaults.h? */
/* These are the flags that represent the mirror failure restoration policies */
#define MIRROR_REMOVE 0
#define MIRROR_ALLOCATE 1
#define MIRROR_ALLOCATE_ANYWHERE 2
struct lv_segment *find_mirror_seg(struct lv_segment *seg)
{
return seg->mirror_seg;
@@ -154,9 +161,11 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
remove_log = 1;
}
if (remove_log) {
if (remove_log && mirrored_seg->log_lv) {
log_lv = mirrored_seg->log_lv;
mirrored_seg->log_lv = NULL;
log_lv->status &= ~MIRROR_LOG;
log_lv->status |= VISIBLE_LV;
}
/*
@@ -192,6 +201,12 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
/* Delete the 'orphan' LVs */
for (m = num_mirrors; m < old_area_count; m++) {
/* LV is now independent of the mirror so must acquire lock. */
if (!activate_lv(mirrored_seg->lv->vg->cmd, seg_lv(mirrored_seg, m))) {
stack;
return 0;
}
if (!deactivate_lv(mirrored_seg->lv->vg->cmd, seg_lv(mirrored_seg, m))) {
stack;
return 0;
@@ -204,6 +219,11 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
}
if (lv1) {
if (!activate_lv(mirrored_seg->lv->vg->cmd, lv1)) {
stack;
return 0;
}
if (!deactivate_lv(mirrored_seg->lv->vg->cmd, lv1)) {
stack;
return 0;
@@ -216,6 +236,11 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
}
if (log_lv) {
if (!activate_lv(mirrored_seg->lv->vg->cmd, log_lv)) {
stack;
return 0;
}
if (!deactivate_lv(mirrored_seg->lv->vg->cmd, log_lv)) {
stack;
return 0;
@@ -230,6 +255,163 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
return 1;
}
static int get_mirror_fault_policy(struct cmd_context *cmd, int log_policy)
{
const char *policy;
if (log_policy)
policy = find_config_str(NULL, "activation/mirror_log_fault_policy",
DEFAULT_MIRROR_LOG_FAULT_POLICY);
else
policy = find_config_str(NULL, "activation/mirror_device_fault_policy",
DEFAULT_MIRROR_DEV_FAULT_POLICY);
if (!strcmp(policy, "remove"))
return MIRROR_REMOVE;
else if (!strcmp(policy, "allocate"))
return MIRROR_ALLOCATE;
else if (!strcmp(policy, "allocate_anywhere"))
return MIRROR_ALLOCATE_ANYWHERE;
if (log_policy)
log_error("Bad activation/mirror_log_fault_policy");
else
log_error("Bad activation/mirror_device_fault_policy");
return MIRROR_REMOVE;
}
static int get_mirror_log_fault_policy(struct cmd_context *cmd)
{
return get_mirror_fault_policy(cmd, 1);
}
static int get_mirror_device_fault_policy(struct cmd_context *cmd)
{
return get_mirror_fault_policy(cmd, 0);
}
/*
* replace_mirror_images
* @mirrored_seg: segment (which may be linear now) to restore
* @num_mirrors: number of copies we should end up with
* @replace_log: replace log if not present
* @in_sync: was the original mirror in-sync?
*
* in_sync will be set to 0 if new mirror devices are being added
* In other words, it is only useful if the log (and only the log)
* is being restored.
*
* Returns: 0 on failure, 1 on reconfig, -1 if no reconfig done
*/
static int replace_mirror_images(struct lv_segment *mirrored_seg,
uint32_t num_mirrors,
int log_policy, int in_sync)
{
int r = -1;
struct logical_volume *lv = mirrored_seg->lv;
/* FIXME: Use lvconvert rather than duplicating its code */
if (mirrored_seg->area_count < num_mirrors) {
log_error("WARNING: Failed to replace mirror device in %s/%s",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
if ((mirrored_seg->area_count > 1) && !mirrored_seg->log_lv)
log_error("WARNING: Use 'lvconvert -m %d %s/%s --corelog' to replace failed devices",
num_mirrors - 1, lv->vg->name, lv->name);
else
log_error("WARNING: Use 'lvconvert -m %d %s/%s' to replace failed devices",
num_mirrors - 1, lv->vg->name, lv->name);
r = 0;
/* REMEMBER/FIXME: set in_sync to 0 if a new mirror device was added */
in_sync = 0;
}
/*
* FIXME: right now, we ignore the allocation policy specified to
* allocate the new log.
*/
if ((mirrored_seg->area_count > 1) && !mirrored_seg->log_lv &&
(log_policy != MIRROR_REMOVE)) {
log_error("WARNING: Failed to replace mirror log device in %s/%s",
lv->vg->name, lv->name);
log_error("WARNING: Use 'lvconvert -m %d %s/%s' to replace failed devices",
mirrored_seg->area_count - 1 , lv->vg->name, lv->name);
r = 0;
}
return r;
}
int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
struct list *removable_pvs, int remove_log)
{
int r;
int insync = 0;
int log_policy, dev_policy;
uint32_t old_num_mirrors = mirrored_seg->area_count;
int had_log = (mirrored_seg->log_lv) ? 1 : 0;
float sync_percent = 0;
/* was the mirror in-sync before problems? */
if (!lv_mirror_percent(mirrored_seg->lv->vg->cmd,
mirrored_seg->lv, 0, &sync_percent, NULL))
log_error("WARNING: Unable to determine mirror sync status of %s/%s.",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
else if (sync_percent >= 100.0)
insync = 1;
/*
* While we are only removing devices, we can have sync set.
* Setting this is only useful if we are moving to core log
* otherwise the disk log will contain the sync information
*/
init_mirror_in_sync(insync);
r = remove_mirror_images(mirrored_seg, num_mirrors,
removable_pvs, remove_log);
if (!r)
/* Unable to remove bad devices */
return 0;
log_print("WARNING: Bad device removed from mirror volume, %s/%s",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
log_policy = get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
dev_policy = get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
r = replace_mirror_images(mirrored_seg,
(dev_policy != MIRROR_REMOVE) ?
old_num_mirrors : num_mirrors,
log_policy, insync);
if (!r)
/* Failed to replace device(s) */
log_error("WARNING: Unable to find substitute device for mirror volume, %s/%s",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
else if (r > 0)
/* Success in replacing device(s) */
log_print("WARNING: Mirror volume, %s/%s restored - substitute for failed device found.",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
else
/* Bad device removed, but not replaced because of policy */
if (mirrored_seg->area_count == 1) {
log_print("WARNING: Mirror volume, %s/%s converted to linear due to device failure.",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
} else if (had_log && !mirrored_seg->log_lv) {
log_print("WARNING: Mirror volume, %s/%s disk log removed due to device failure.",
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
}
/*
* If we made it here, we at least removed the bad device.
* Consider this success.
*/
return 1;
}
static int _create_layers_for_mirror(struct alloc_handle *ah,
uint32_t first_area,
uint32_t num_mirrors,
@@ -248,7 +430,7 @@ static int _create_layers_for_mirror(struct alloc_handle *ah,
return 0;
}
if (lvm_snprintf(img_name, len, "%s_mimage_%%d", lv->name) < 0) {
if (dm_snprintf(img_name, len, "%s_mimage_%%d", lv->name) < 0) {
log_error("img_name allocation failed. "
"Remove new LV and retry.");
return 0;

View File

@@ -67,23 +67,22 @@ struct segtype_handler {
int (*merge_segments) (struct lv_segment * seg1,
struct lv_segment * seg2);
int (*add_target_line) (struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct cmd_context *cmd, void **target_state,
struct lv_segment *seg,
struct dm_tree_node *node, uint64_t len,
uint32_t *pvmove_mirror_count);
int (*target_percent) (void **target_state, struct dm_pool * mem,
struct config_tree * cft,
struct lv_segment * seg, char *params,
struct cmd_context *cmd,
struct lv_segment *seg, char *params,
uint64_t *total_numerator,
uint64_t *total_denominator, float *percent);
int (*target_present) (void);
int (*modules_needed) (struct dm_pool *mem,
const struct lv_segment *seg,
struct list *modules);
void (*destroy) (const struct segment_type * segtype);
int (*target_register_events) (struct dm_pool *mem,
struct lv_segment *seg,
struct config_tree *cft, int events);
int (*target_unregister_events) (struct dm_pool *mem,
struct lv_segment *seg,
struct config_tree *cft, int events);
int (*target_register_events) (struct lv_segment *seg, int events);
int (*target_unregister_events) (struct lv_segment *seg, int events);
};
struct segment_type *get_segtype_from_string(struct cmd_context *cmd,

View File

@@ -26,6 +26,7 @@
#include "targets.h"
#include "activate.h"
#include "sharedlib.h"
#include "str_list.h"
#ifdef DMEVENTD
# include <libdevmapper-event.h>
@@ -154,7 +155,7 @@ static int _mirrored_text_export(const struct lv_segment *seg, struct formatter
#ifdef DEVMAPPER_SUPPORT
static struct mirror_state *_mirrored_init_target(struct dm_pool *mem,
struct config_tree *cft)
struct cmd_context *cmd)
{
struct mirror_state *mirr_state;
@@ -164,7 +165,7 @@ static struct mirror_state *_mirrored_init_target(struct dm_pool *mem,
}
mirr_state->default_region_size = 2 *
find_config_int(cft->root,
find_config_tree_int(cmd,
"activation/mirror_region_size",
DEFAULT_MIRROR_REGION_SIZE);
@@ -172,9 +173,10 @@ static struct mirror_state *_mirrored_init_target(struct dm_pool *mem,
}
static int _mirrored_target_percent(void **target_state, struct dm_pool *mem,
struct config_tree *cft, struct lv_segment *seg,
struct cmd_context *cmd, struct lv_segment *seg,
char *params, uint64_t *total_numerator,
uint64_t *total_denominator, float *percent)
uint64_t *total_denominator,
float *percent __attribute((unused)))
{
struct mirror_state *mirr_state;
uint64_t numerator, denominator;
@@ -183,7 +185,7 @@ static int _mirrored_target_percent(void **target_state, struct dm_pool *mem,
char *pos = params;
if (!*target_state)
*target_state = _mirrored_init_target(mem, cft);
*target_state = _mirrored_init_target(mem, cmd);
mirr_state = *target_state;
@@ -237,13 +239,26 @@ static int _add_log(struct dev_manager *dm, struct lv_segment *seg,
(seg->lv->vg->status & CLUSTERED)))
clustered = 1;
if (seg->log_lv &&
!(log_dlid = build_dlid(dm, seg->log_lv->lvid.s, NULL))) {
log_error("Failed to build uuid for log LV %s.",
seg->log_lv->name);
return 0;
if (seg->log_lv) {
/* If disk log, use its UUID */
if (!(log_dlid = build_dlid(dm, seg->log_lv->lvid.s, NULL))) {
log_error("Failed to build uuid for log LV %s.",
seg->log_lv->name);
return 0;
}
} else {
/* If core log, use mirror's UUID and set DM_CORELOG flag */
if (!(log_dlid = build_dlid(dm, seg->lv->lvid.s, NULL))) {
log_error("Failed to build uuid for mirror LV %s.",
seg->lv->name);
return 0;
}
log_flags |= DM_CORELOG;
}
if (mirror_in_sync() && !(seg->status & PVMOVE))
log_flags |= DM_NOSYNC;
if (_block_on_error_available && !(seg->status & PVMOVE))
log_flags |= DM_BLOCK_ON_ERROR;
@@ -251,7 +266,7 @@ static int _add_log(struct dev_manager *dm, struct lv_segment *seg,
}
static int _mirrored_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct cmd_context *cmd, void **target_state,
struct lv_segment *seg,
struct dm_tree_node *node, uint64_t len,
uint32_t *pvmove_mirror_count)
@@ -264,7 +279,7 @@ static int _mirrored_add_target_line(struct dev_manager *dm, struct dm_pool *mem
int r;
if (!*target_state)
*target_state = _mirrored_init_target(mem, cft);
*target_state = _mirrored_init_target(mem, cmd);
mirr_state = *target_state;
@@ -353,7 +368,7 @@ static int _mirrored_target_present(void)
}
#ifdef DMEVENTD
static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
static int _setup_registration(struct dm_pool *mem, struct cmd_context *cmd,
char **dso)
{
char *path;
@@ -364,10 +379,10 @@ static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
return 0;
}
libpath = find_config_str(cft->root, "dmeventd/mirror_library",
DEFAULT_DMEVENTD_MIRROR_LIB);
libpath = find_config_tree_str(cmd, "dmeventd/mirror_library",
DEFAULT_DMEVENTD_MIRROR_LIB);
get_shared_library_path(cft, libpath, path, PATH_MAX);
get_shared_library_path(cmd, libpath, path, PATH_MAX);
*dso = path;
@@ -376,9 +391,8 @@ static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
/* FIXME This gets run while suspended and performs banned operations. */
/* FIXME Merge these two functions */
static int _target_register_events(struct dm_pool *mem,
struct lv_segment *seg,
struct config_tree *cft, int events)
static int _target_register_events(struct lv_segment *seg,
int events)
{
char *dso, *name;
struct logical_volume *lv;
@@ -387,12 +401,12 @@ static int _target_register_events(struct dm_pool *mem,
lv = seg->lv;
vg = lv->vg;
if (!_setup_registration(mem, cft, &dso)) {
if (!_setup_registration(vg->cmd->mem, vg->cmd, &dso)) {
stack;
return 0;
}
if (!(name = build_dm_name(mem, vg->name, lv->name, NULL)))
if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL)))
return_0;
/* FIXME Save a returned handle here so we can unregister it later */
@@ -404,9 +418,8 @@ static int _target_register_events(struct dm_pool *mem,
return 1;
}
static int _target_unregister_events(struct dm_pool *mem,
struct lv_segment *seg,
struct config_tree *cft, int events)
static int _target_unregister_events(struct lv_segment *seg,
int events)
{
char *dso;
char *name;
@@ -417,10 +430,10 @@ static int _target_unregister_events(struct dm_pool *mem,
vg = lv->vg;
/* FIXME Remove this and use handle to avoid config file race */
if (!_setup_registration(mem, cft, &dso))
if (!_setup_registration(vg->cmd->mem, vg->cmd, &dso))
return_0;
if (!(name = build_dm_name(mem, vg->name, lv->name, NULL)))
if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL)))
return_0;
/* FIXME Use handle returned by registration function instead of dso */
@@ -435,6 +448,28 @@ static int _target_unregister_events(struct dm_pool *mem,
#endif /* DMEVENTD */
#endif /* DEVMAPPER_SUPPORT */
static int _mirrored_modules_needed(struct dm_pool *mem,
const struct lv_segment *seg,
struct list *modules)
{
if (seg->log_lv &&
!list_segment_modules(mem, first_seg(seg->log_lv), modules))
return_0;
if ((seg->lv->vg->status & CLUSTERED) &&
!str_list_add(mem, modules, "clog")) {
log_error("cluster log string list allocation failed");
return 0;
}
if (!str_list_add(mem, modules, "mirror")) {
log_error("mirror string list allocation failed");
return 0;
}
return 1;
}
static void _mirrored_destroy(const struct segment_type *segtype)
{
dm_free((void *) segtype);
@@ -455,6 +490,7 @@ static struct segtype_handler _mirrored_ops = {
.target_unregister_events = _target_unregister_events,
#endif
#endif
.modules_needed = _mirrored_modules_needed,
.destroy = _mirrored_destroy,
};

View File

@@ -1,430 +0,0 @@
/* lib/misc/configure.h. Generated by configure. */
/* lib/misc/configure.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if the `closedir' function returns void instead of `int'. */
/* #undef CLOSEDIR_VOID */
/* Define to 1 to include built-in support for clustered LVM locking. */
/* #undef CLUSTER_LOCKING_INTERNAL */
/* Define to 1 to build the shared command library. */
/* #undef CMDLIB */
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
/* #undef CRAY_STACKSEG_END */
/* Define to 1 if using `alloca.c'. */
/* #undef C_ALLOCA */
/* Define to 1 to enable device-mapper interaction. */
#define DEVMAPPER_SUPPORT 1
/* Define to 1 to enable the device-mapper event daemon. */
/* #undef DMEVENTD */
/* Define to 1 if you have `alloca', as a function or macro. */
#define HAVE_ALLOCA 1
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
#define HAVE_ALLOCA_H 1
/* Define to 1 if you have the <asm/byteorder.h> header file. */
/* #undef HAVE_ASM_BYTEORDER_H */
/* Define to 1 if you have the <assert.h> header file. */
#define HAVE_ASSERT_H 1
/* Define to 1 if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#define HAVE_DIRENT_H 1
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
/* #undef HAVE_DOPRNT */
/* Define to 1 if you have the `dup2' function. */
/* #undef HAVE_DUP2 */
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the `fork' function. */
#define HAVE_FORK 1
/* Define to 1 if you have the <fstab.h> header file. */
/* #undef HAVE_FSTAB_H */
/* Define to 1 if you have the `gethostname' function. */
#define HAVE_GETHOSTNAME 1
/* Define to 1 if you have the `getmntent' function. */
/* #undef HAVE_GETMNTENT */
/* Define to 1 to if getopt_long is available. */
#define HAVE_GETOPTLONG 1
/* Define to 1 if you have the <getopt.h> header file. */
#define HAVE_GETOPT_H 1
/* Define to 1 if you have the `getpagesize' function. */
#define HAVE_GETPAGESIZE 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <libdevmapper.h> header file. */
#define HAVE_LIBDEVMAPPER_H 1
/* Define to 1 if dynamic libraries are available. */
#define HAVE_LIBDL 1
/* Define to 1 if you have the <libgen.h> header file. */
#define HAVE_LIBGEN_H 1
/* Define to 1 if you have the <libintl.h> header file. */
/* #undef HAVE_LIBINTL_H */
/* Define to 1 if you have the `readline' library (-lreadline). */
/* #undef HAVE_LIBREADLINE */
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <linux/fs.h> header file. */
/* #undef HAVE_LINUX_FS_H */
/* Define to 1 if you have the <locale.h> header file. */
#define HAVE_LOCALE_H 1
/* Define to 1 if `lstat' has the bug that it succeeds when given the
zero-length file name argument. */
/* #undef HAVE_LSTAT_EMPTY_STRING_BUG */
/* Define to 1 if you have the <machine/endian.h> header file. */
#define HAVE_MACHINE_ENDIAN_H 1
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#define HAVE_MALLOC 1
/* Define to 1 if you have the <malloc.h> header file. */
/* #undef HAVE_MALLOC_H */
/* Define to 1 if you have the `memmove' function. */
/* #undef HAVE_MEMMOVE */
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the `mkdir' function. */
#define HAVE_MKDIR 1
/* Define to 1 if you have a working `mmap' system call. */
#define HAVE_MMAP 1
/* Define to 1 if you have the <mntent.h> header file. */
/* #undef HAVE_MNTENT_H */
/* Define to 1 if you have the `munmap' function. */
#define HAVE_MUNMAP 1
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
/* #undef HAVE_NDIR_H */
/* Define to 1 if you have the <netdb.h> header file. */
/* #undef HAVE_NETDB_H */
/* Define to 1 if you have the <netinet/in.h> header file. */
/* #undef HAVE_NETINET_IN_H */
/* Define to 1 if you have the <pthread.h> header file. */
/* #undef HAVE_PTHREAD_H */
/* Define to 1 if you have the <readline/history.h> header file. */
/* #undef HAVE_READLINE_HISTORY_H */
/* Define to 1 if you have the <readline/readline.h> header file. */
/* #undef HAVE_READLINE_READLINE_H */
/* Define to 1 if rl_completion_matches() is available. */
/* #undef HAVE_RL_COMPLETION_MATCHES */
/* Define to 1 if you have the `rmdir' function. */
#define HAVE_RMDIR 1
/* Define to 1 if you have the <search.h> header file. */
/* #undef HAVE_SEARCH_H */
/* Define to 1 if you have the `select' function. */
/* #undef HAVE_SELECT */
/* Define to 1 to include support for selinux. */
/* #undef HAVE_SELINUX */
/* Define to 1 if you have the <selinux/selinux.h> header file. */
/* #undef HAVE_SELINUX_SELINUX_H */
/* Define to 1 if you have the `setlocale' function. */
#define HAVE_SETLOCALE 1
/* Define to 1 if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1
/* Define to 1 if you have the `socket' function. */
/* #undef HAVE_SOCKET */
/* Define to 1 if `stat' has the bug that it succeeds when given the
zero-length file name argument. */
/* #undef HAVE_STAT_EMPTY_STRING_BUG */
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strcasecmp' function. */
#define HAVE_STRCASECMP 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the `strncasecmp' function. */
#define HAVE_STRNCASECMP 1
/* Define to 1 if you have the `strrchr' function. */
#define HAVE_STRRCHR 1
/* Define to 1 if you have the `strstr' function. */
#define HAVE_STRSTR 1
/* Define to 1 if you have the `strtol' function. */
#define HAVE_STRTOL 1
/* Define to 1 if you have the `strtoul' function. */
#define HAVE_STRTOUL 1
/* Define to 1 if `st_rdev' is member of `struct stat'. */
#define HAVE_STRUCT_STAT_ST_RDEV 1
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
#define HAVE_ST_RDEV 1
/* Define to 1 if you have the <syslog.h> header file. */
#define HAVE_SYSLOG_H 1
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
/* #undef HAVE_SYS_DIR_H */
/* Define to 1 if you have the <sys/disk.h> header file. */
#define HAVE_SYS_DISK_H 1
/* Define to 1 if you have the <sys/file.h> header file. */
#define HAVE_SYS_FILE_H 1
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define to 1 if you have the <sys/mman.h> header file. */
#define HAVE_SYS_MMAN_H 1
/* Define to 1 if you have the <sys/mount.h> header file. */
/* #undef HAVE_SYS_MOUNT_H */
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
/* #undef HAVE_SYS_NDIR_H */
/* Define to 1 if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
/* Define to 1 if you have the <sys/select.h> header file. */
/* #undef HAVE_SYS_SELECT_H */
/* Define to 1 if you have the <sys/socket.h> header file. */
/* #undef HAVE_SYS_SOCKET_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <sys/uio.h> header file. */
/* #undef HAVE_SYS_UIO_H */
/* Define to 1 if you have the <sys/un.h> header file. */
/* #undef HAVE_SYS_UN_H */
/* Define to 1 if you have the <sys/utsname.h> header file. */
#define HAVE_SYS_UTSNAME_H 1
/* Define to 1 if you have the <sys/vfs.h> header file. */
/* #undef HAVE_SYS_VFS_H */
/* Define to 1 if you have the <sys/wait.h> header file. */
#define HAVE_SYS_WAIT_H 1
/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define to 1 if you have the `uname' function. */
#define HAVE_UNAME 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the <utmpx.h> header file. */
/* #undef HAVE_UTMPX_H */
/* Define to 1 if you have the `vfork' function. */
#define HAVE_VFORK 1
/* Define to 1 if you have the <vfork.h> header file. */
/* #undef HAVE_VFORK_H */
/* Define to 1 if you have the `vprintf' function. */
#define HAVE_VPRINTF 1
/* Define to 1 if `fork' works. */
#define HAVE_WORKING_FORK 1
/* Define to 1 if `vfork' works. */
#define HAVE_WORKING_VFORK 1
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */
/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
/* Define to 1 if 'lvm' should fall back to using LVM1 binaries if
device-mapper is missing from the kernel */
/* #undef LVM1_FALLBACK */
/* Define to 1 to include built-in support for LVM1 metadata. */
#define LVM1_INTERNAL 1
/* Define to 1 to include built-in support for mirrors. */
#define MIRRORED_INTERNAL 1
/* The path to 'modprobe', if available. */
#define MODPROBE_CMD "/sbin/ifconfig"
/* Define to 1 to enable O_DIRECT support. */
/* #undef O_DIRECT_SUPPORT */
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME ""
/* Define to the full name and version of this package. */
#define PACKAGE_STRING ""
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""
/* Define to the version of this package. */
#define PACKAGE_VERSION ""
/* Define to 1 to include built-in support for GFS pool metadata. */
#define POOL_INTERNAL 1
/* Define to 1 to include the LVM readline shell. */
/* #undef READLINE_SUPPORT */
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
/* Define to the type of arg 1 for `select'. */
/* #undef SELECT_TYPE_ARG1 */
/* Define to the type of args 2, 3 and 4 for `select'. */
/* #undef SELECT_TYPE_ARG234 */
/* Define to the type of arg 5 for `select'. */
/* #undef SELECT_TYPE_ARG5 */
/* Define to 1 to include built-in support for snapshots. */
#define SNAPSHOT_INTERNAL 1
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
/* #undef TM_IN_SYS_TIME */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to rpl_malloc if the replacement function should be used. */
/* #undef malloc */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef mode_t */
/* Define to `long' if <sys/types.h> does not define. */
/* #undef off_t */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef pid_t */
/* Define to `unsigned' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define as `fork' if `vfork' does not work. */
/* #undef vfork */

View File

@@ -174,6 +174,9 @@
/* Define to 1 if you have the <selinux/selinux.h> header file. */
#undef HAVE_SELINUX_SELINUX_H
/* define to 1 to include support for realtime clock */
#undef HAVE_REALTIME
/* Define to 1 if you have the `setlocale' function. */
#undef HAVE_SETLOCALE

View File

@@ -18,7 +18,7 @@
#include "crc.h"
/* Calculate an endian-independent CRC of supplied buffer */
uint32_t calc_crc(uint32_t initial, void *buf, uint32_t size)
uint32_t calc_crc(uint32_t initial, const void *buf, uint32_t size)
{
static const uint32_t crctab[] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
@@ -27,7 +27,7 @@ uint32_t calc_crc(uint32_t initial, void *buf, uint32_t size)
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
uint32_t i, crc = initial;
uint8_t *data = (uint8_t *) buf;
const uint8_t *data = (const uint8_t *) buf;
for (i = 0; i < size; i++) {
crc ^= *data++;

View File

@@ -18,6 +18,6 @@
#define INITIAL_CRC 0xf597a6cf
uint32_t calc_crc(uint32_t initial, void *buf, uint32_t size);
uint32_t calc_crc(uint32_t initial, const void *buf, uint32_t size);
#endif

View File

@@ -28,6 +28,7 @@
#include "log.h"
#include "intl.h"
#include "lvm-types.h"
#include "lvm-wrappers.h"
#include <libdevmapper.h>

View File

@@ -50,7 +50,7 @@ int create_temp_name(const char *dir, char *buffer, size_t len, int *fd)
for (i = 0; i < 20; i++, num++) {
if (lvm_snprintf(buffer, len, "%s/.lvm_%s_%d_%d",
if (dm_snprintf(buffer, len, "%s/.lvm_%s_%d_%d",
dir, hostname, pid, num) == -1) {
log_err("Not enough space to build temporary file "
"string.");

View File

@@ -14,33 +14,10 @@
*/
#include "lib.h"
#include "lvm-types.h"
#include "lvm-string.h"
#include <ctype.h>
/*
* On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small;
* From glibc 2.1 it returns number of chars (excl. trailing null) that would
* have been written had there been room.
*
* lvm_snprintf reverts to the old behaviour.
*/
int lvm_snprintf(char *buf, size_t bufsize, const char *format, ...)
{
int n;
va_list ap;
va_start(ap, format);
n = vsnprintf(buf, bufsize, format, ap);
va_end(ap);
if (n < 0 || (n > bufsize - 1))
return -1;
return n;
}
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
{
int n;
@@ -58,47 +35,6 @@ int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
return 1;
}
/*
* consume characters while they match the predicate function.
*/
static char *_consume(char *buffer, int (*fn) (int))
{
while (*buffer && fn(*buffer))
buffer++;
return buffer;
}
static int _isword(int c)
{
return !isspace(c);
}
/*
* Split buffer into NULL-separated words in argv.
* Returns number of words.
*/
int split_words(char *buffer, unsigned max, char **argv)
{
unsigned arg;
for (arg = 0; arg < max; arg++) {
buffer = _consume(buffer, isspace);
if (!*buffer)
break;
argv[arg] = buffer;
buffer = _consume(buffer, _isword);
if (*buffer) {
*buffer = '\0';
buffer++;
}
}
return arg;
}
/*
* Device layer names are all of the form <vg>-<lv>-<layer>, any
* other hyphens that appear in these names are quoted with yet
@@ -169,47 +105,6 @@ char *build_dm_name(struct dm_pool *mem, const char *vgname,
return r;
}
/*
* Remove hyphen quoting from a component of a name.
* NULL-terminates the component and returns start of next component.
*/
static char *_unquote(char *component)
{
char *c = component;
char *o = c;
char *r;
while (*c) {
if (*(c + 1)) {
if (*c == '-') {
if (*(c + 1) == '-')
c++;
else
break;
}
}
*o = *c;
o++;
c++;
}
r = (*c) ? c + 1 : c;
*o = '\0';
return r;
}
int split_dm_name(struct dm_pool *mem, const char *dmname,
char **vgname, char **lvname, char **layer)
{
if (!(*vgname = dm_pool_strdup(mem, dmname)))
return 0;
_unquote(*layer = _unquote(*lvname = _unquote(*vgname)));
return 1;
}
int validate_name(const char *n)
{
register char c;

View File

@@ -23,25 +23,11 @@
struct pool;
/*
* On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small;
* From glibc 2.1 it returns number of chars (excl. trailing null) that would
* have been written had there been room.
*
* lvm_snprintf reverts to the old behaviour.
*/
int lvm_snprintf(char *buf, size_t bufsize, const char *format, ...);
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...);
int split_words(char *buffer, unsigned max, char **argv);
char *build_dm_name(struct dm_pool *mem, const char *vg,
const char *lv, const char *layer);
int split_dm_name(struct dm_pool *mem, const char *dmname,
char **vgname, char **lvname, char **layer);
int validate_name(const char *n);
#endif

22
lib/misc/lvm-wrappers.c Normal file
View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) 2006 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include <unistd.h>
int lvm_getpagesize(void)
{
return getpagesize();
}

21
lib/misc/lvm-wrappers.h Normal file
View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_WRAPPERS_H
#define _LVM_WRAPPERS_H
int lvm_getpagesize(void);
#endif

View File

@@ -17,12 +17,13 @@
#include "config.h"
#include "lvm-string.h"
#include "sharedlib.h"
#include "toolcontext.h"
#include <limits.h>
#include <sys/stat.h>
#include <dlfcn.h>
void get_shared_library_path(struct config_tree *cft, const char *libname,
void get_shared_library_path(struct cmd_context *cmd, const char *libname,
char *path, size_t path_len)
{
struct stat info;
@@ -31,29 +32,35 @@ void get_shared_library_path(struct config_tree *cft, const char *libname,
/* If libname doesn't begin with '/' then use lib_dir/libname,
* if present */
if (libname[0] == '/' ||
!(lib_dir = find_config_str(cft->root, "global/library_dir", 0)) ||
(lvm_snprintf(path, path_len, "%s/%s", lib_dir,
!(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
(dm_snprintf(path, path_len, "%s/%s", lib_dir,
libname) == -1) || stat(path, &info) == -1)
strncpy(path, libname, path_len);
}
void *load_shared_library(struct config_tree *cft, const char *libname,
void *load_shared_library(struct cmd_context *cmd, const char *libname,
const char *desc, int silent)
{
char path[PATH_MAX];
void *library;
get_shared_library_path(cft, libname, path, sizeof(path));
if (cmd->is_static) {
log_error("Not loading shared %s library %s in static mode.",
desc, libname);
return NULL;
}
get_shared_library_path(cmd, libname, path, sizeof(path));
log_very_verbose("Opening shared %s library %s", desc, path);
if (!(library = dlopen(path, RTLD_LAZY))) {
if (!(library = dlopen(path, RTLD_LAZY | RTLD_GLOBAL))) {
if (silent && ignorelockingfailure())
log_verbose("Unable to open external %s library %s",
desc, path);
log_verbose("Unable to open external %s library %s: %s",
desc, path, dlerror());
else
log_error("Unable to open external %s library %s",
desc, path);
log_error("Unable to open external %s library %s: %s",
desc, path, dlerror());
}
return library;

View File

@@ -19,9 +19,9 @@
#include "config.h"
#include <dlfcn.h>
void get_shared_library_path(struct config_tree *cft, const char *libname,
void get_shared_library_path(struct cmd_context *cmd, const char *libname,
char *path, size_t path_len);
void *load_shared_library(struct config_tree *cf, const char *libname,
void *load_shared_library(struct cmd_context *cmd, const char *libname,
const char *what, int silent);
#endif

130
lib/misc/timestamp.c Normal file
View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2006 Rackable Systems All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Abstract out the time methods used so they can be adjusted later -
* the results of these routines should stay in-core. This implementation
* requires librt.
*/
#include "lib.h"
#include <stdlib.h>
#include "timestamp.h"
/*
* The realtime section uses clock_gettime with the CLOCK_MONOTONIC
* parameter to prevent issues with time warps
*/
#ifdef HAVE_REALTIME
#include <time.h>
#include <bits/time.h>
struct timestamp {
struct timespec t;
};
struct timestamp *get_timestamp(void)
{
struct timestamp *ts = NULL;
if (!(ts = dm_malloc(sizeof(*ts))))
return_NULL;
if (clock_gettime(CLOCK_MONOTONIC, &ts->t)) {
log_sys_error("clock_gettime", "get_timestamp");
return NULL;
}
return ts;
}
/* cmp_timestamp: Compare two timestamps
*
* Return: -1 if t1 is less than t2
* 0 if t1 is equal to t2
* 1 if t1 is greater than t2
*/
int cmp_timestamp(struct timestamp *t1, struct timestamp *t2)
{
if(t1->t.tv_sec < t2->t.tv_sec)
return -1;
if(t1->t.tv_sec > t2->t.tv_sec)
return 1;
if(t1->t.tv_nsec < t2->t.tv_nsec)
return -1;
if(t1->t.tv_nsec > t2->t.tv_nsec)
return 1;
return 0;
}
#else /* ! HAVE_REALTIME */
/*
* The !realtime section just uses gettimeofday and is therefore subject
* to ntp-type time warps - not sure if should allow that.
*/
#include <sys/time.h>
struct timestamp {
struct timeval t;
};
struct timestamp *get_timestamp(void)
{
struct timestamp *ts = NULL;
if (!(ts = dm_malloc(sizeof(*ts))))
return_NULL;
if (gettimeofday(&ts->t, NULL)) {
log_sys_error("gettimeofday", "get_timestamp");
return NULL;
}
return ts;
}
/* cmp_timestamp: Compare two timestamps
*
* Return: -1 if t1 is less than t2
* 0 if t1 is equal to t2
* 1 if t1 is greater than t2
*/
int cmp_timestamp(struct timestamp *t1, struct timestamp *t2)
{
if(t1->t.tv_sec < t2->t.tv_sec)
return -1;
if(t1->t.tv_sec > t2->t.tv_sec)
return 1;
if(t1->t.tv_usec < t2->t.tv_usec)
return -1;
if(t1->t.tv_usec > t2->t.tv_usec)
return 1;
return 0;
}
#endif /* HAVE_REALTIME */
void destroy_timestamp(struct timestamp *t)
{
if (t)
dm_free(t);
}

33
lib/misc/timestamp.h Normal file
View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2006 Rackable Systems All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_TIMESTAMP_H
#define _LVM_TIMESTAMP_H
struct timestamp;
struct timestamp *get_timestamp(void);
/* cmp_timestamp: Compare two timestamps
*
* Return: -1 if t1 is less than t2
* 0 if t1 is equal to t2
* 1 if t1 is greater than t2
*/
int cmp_timestamp(struct timestamp *t1, struct timestamp *t2);
void destroy_timestamp(struct timestamp *t);
#endif /* _LVM_TIMESTAMP_H */

View File

@@ -58,7 +58,7 @@ static int _default_priority;
static void _touch_memory(void *mem, size_t size)
{
size_t pagesize = getpagesize();
size_t pagesize = lvm_getpagesize();
void *pos = mem;
void *end = mem + size - sizeof(long);
@@ -144,13 +144,13 @@ int memlock(void)
void memlock_init(struct cmd_context *cmd)
{
_size_stack = find_config_int(cmd->cft->root,
_size_stack = find_config_tree_int(cmd,
"activation/reserved_stack",
DEFAULT_RESERVED_STACK) * 1024;
_size_malloc_tmp = find_config_int(cmd->cft->root,
_size_malloc_tmp = find_config_tree_int(cmd,
"activation/reserved_memory",
DEFAULT_RESERVED_MEMORY) * 1024;
_default_priority = find_config_int(cmd->cft->root,
_default_priority = find_config_tree_int(cmd,
"activation/process_priority",
DEFAULT_PROCESS_PRIORITY);
}

View File

@@ -33,6 +33,7 @@ FIELD(LVS, lv, NUM, "Copy%", lvid, 6, copypercent, "copy_percent")
FIELD(LVS, lv, STR, "Move", lvid, 4, movepv, "move_pv")
FIELD(LVS, lv, STR, "LV Tags", tags, 7, tags, "lv_tags")
FIELD(LVS, lv, STR, "Log", lvid, 3, loglv, "mirror_log")
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, "modules")
FIELD(PVS, pv, STR, "Fmt", id, 3, pvfmt, "pv_fmt")
FIELD(PVS, pv, STR, "PV UUID", id, 38, uuid, "pv_uuid")
@@ -68,8 +69,11 @@ FIELD(VGS, vg, STR, "VG Tags", tags, 7, tags, "vg_tags")
FIELD(SEGS, seg, STR, "Type", list, 4, segtype, "segtype")
FIELD(SEGS, seg, NUM, "#Str", area_count, 4, uint32, "stripes")
FIELD(SEGS, seg, NUM, "Stripe", stripe_size, 6, size32, "stripesize")
FIELD(SEGS, seg, NUM, "Stripe", stripe_size, 6, size32, "stripe_size")
FIELD(SEGS, seg, NUM, "Chunk", list, 5, chunksize, "chunksize")
FIELD(SEGS, seg, NUM, "Chunk", list, 5, chunksize, "chunk_size")
FIELD(SEGS, seg, NUM, "Region", region_size, 6, size32, "regionsize")
FIELD(SEGS, seg, NUM, "Region", region_size, 6, size32, "region_size")
FIELD(SEGS, seg, NUM, "Start", list, 5, segstart, "seg_start")
FIELD(SEGS, seg, NUM, "SSize", list, 5, segsize, "seg_size")
FIELD(SEGS, seg, STR, "Seg Tags", tags, 8, tags, "seg_tags")

View File

@@ -21,6 +21,7 @@
#include "display.h"
#include "activate.h"
#include "segtype.h"
#include "str_list.h"
/*
* For macro use
@@ -103,6 +104,8 @@ static char _alloc_policy_char(alloc_policy_t alloc)
switch (alloc) {
case ALLOC_CONTIGUOUS:
return 'c';
case ALLOC_CLING:
return 'C';
case ALLOC_NORMAL:
return 'n';
case ALLOC_ANYWHERE:
@@ -172,9 +175,9 @@ static int _devices_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(extent_str, sizeof(extent_str), "(%" PRIu32
if (dm_snprintf(extent_str, sizeof(extent_str), "(%" PRIu32
")", extent) < 0) {
log_error("Extent number lvm_snprintf failed");
log_error("Extent number dm_snprintf failed");
return 0;
}
@@ -200,6 +203,7 @@ static int _devices_disp(struct report_handle *rh, struct field *field,
return 1;
}
static int _tags_disp(struct report_handle *rh, struct field *field,
const void *data)
{
@@ -230,6 +234,23 @@ static int _tags_disp(struct report_handle *rh, struct field *field,
return 1;
}
static int _modules_disp(struct report_handle *rh, struct field *field,
const void *data)
{
const struct logical_volume *lv = (const struct logical_volume *) data;
struct list *modules;
if (!(modules = str_list_create(rh->mem))) {
log_error("modules str_list allocation failed");
return 0;
}
if (!list_lv_modules(rh->mem, lv, modules))
return_0;
return _tags_disp(rh, field, modules);
}
static int _vgfmt_disp(struct report_handle *rh, struct field *field,
const void *data)
{
@@ -276,7 +297,7 @@ static int _int_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(repstr, 12, "%d", value) < 0) {
if (dm_snprintf(repstr, 12, "%d", value) < 0) {
log_error("int too big: %d", value);
return 0;
}
@@ -333,9 +354,12 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field,
if (lv->status & PVMOVE)
repstr[0] = 'p';
else if (lv->status & MIRRORED)
repstr[0] = 'm';
else if (lv->status & MIRROR_IMAGE)
else if (lv->status & MIRRORED) {
if (lv->status & MIRROR_NOTSYNCED)
repstr[0] = 'M';
else
repstr[0] = 'm';
}else if (lv->status & MIRROR_IMAGE)
repstr[0] = 'i';
else if (lv->status & MIRROR_LOG)
repstr[0] = 'l';
@@ -472,7 +496,8 @@ static int _vgstatus_disp(struct report_handle *rh, struct field *field,
return 1;
}
static int _segtype_disp(struct report_handle *rh, struct field *field,
static int _segtype_disp(struct report_handle *rh __attribute((unused)),
struct field *field,
const void *data)
{
const struct lv_segment *seg = (const struct lv_segment *) data;
@@ -536,7 +561,7 @@ static int _lvname_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(repstr, len, "[%s]", lv->name) < 0) {
if (dm_snprintf(repstr, len, "[%s]", lv->name) < 0) {
log_error("lvname snprintf failed");
return 0;
}
@@ -780,7 +805,7 @@ static int _uint32_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(repstr, 11, "%u", value) < 0) {
if (dm_snprintf(repstr, 11, "%u", value) < 0) {
log_error("uint32 too big: %u", value);
return 0;
}
@@ -809,7 +834,7 @@ static int _int32_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(repstr, 12, "%d", value) < 0) {
if (dm_snprintf(repstr, 12, "%d", value) < 0) {
log_error("int32 too big: %d", value);
return 0;
}
@@ -866,7 +891,7 @@ static int _snpercent_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(repstr, 7, "%.2f", snap_percent) < 0) {
if (dm_snprintf(repstr, 7, "%.2f", snap_percent) < 0) {
log_error("snapshot percentage too large");
return 0;
}
@@ -906,7 +931,7 @@ static int _copypercent_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (lvm_snprintf(repstr, 7, "%.2f", percent) < 0) {
if (dm_snprintf(repstr, 7, "%.2f", percent) < 0) {
log_error("copy percentage too large");
return 0;
}
@@ -944,6 +969,44 @@ static struct {
const unsigned int _num_fields = sizeof(_fields) / sizeof(_fields[0]);
static void _display_fields(void)
{
uint32_t f;
const char *type, *last_type = "";
for (f = 0; f < _num_fields; f++) {
switch (_fields[f].type) {
case PVS:
type = "Physical Volume";
break;
case LVS:
type = "Logical Volume";
break;
case VGS:
type = "Volume Group";
break;
case SEGS:
type = "Logical Volume Segment";
break;
case PVSEGS:
type = "Physical Volume Segment";
break;
default:
type = " ";
}
if (type != last_type) {
if (*last_type)
log_print(" ");
log_print("%s Fields", type);
}
log_print("- %s", _fields[f].id);
last_type = type;
}
}
/*
* Initialise report handle
*/
@@ -1076,6 +1139,8 @@ static int _parse_options(struct report_handle *rh, const char *format)
while (*we && *we != ',')
we++;
if (!_field_match(rh, ws, (size_t) (we - ws))) {
_display_fields();
log_print(" ");
log_error("Unrecognised field: %.*s", (int) (we - ws),
ws);
return 0;
@@ -1320,7 +1385,7 @@ static int _report_headings(void *handle)
heading = _fields[fp->field_num].heading;
if (rh->flags & RH_ALIGNED) {
if (lvm_snprintf(buf, sizeof(buf), "%-*.*s",
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
fp->width, fp->width, heading) < 0) {
log_error("snprintf heading failed");
dm_pool_end_object(rh->mem);
@@ -1463,7 +1528,7 @@ int report_output(void *handle)
strlen(repstr)))
goto bad;
} else if (field->props->flags & FLD_ALIGN_LEFT) {
if (lvm_snprintf(buf, sizeof(buf), "%-*.*s",
if (dm_snprintf(buf, sizeof(buf), "%-*.*s",
width, width, repstr) < 0) {
log_error("snprintf repstr failed");
dm_pool_end_object(rh->mem);
@@ -1472,7 +1537,7 @@ int report_output(void *handle)
if (!dm_pool_grow_object(rh->mem, buf, width))
goto bad;
} else if (field->props->flags & FLD_ALIGN_RIGHT) {
if (lvm_snprintf(buf, sizeof(buf), "%*.*s",
if (dm_snprintf(buf, sizeof(buf), "%*.*s",
width, width, repstr) < 0) {
log_error("snprintf repstr failed");
dm_pool_end_object(rh->mem);

View File

@@ -20,6 +20,7 @@
#include "text_export.h"
#include "config.h"
#include "activate.h"
#include "str_list.h"
static const char *_snap_name(const struct lv_segment *seg)
{
@@ -27,7 +28,7 @@ static const char *_snap_name(const struct lv_segment *seg)
}
static int _snap_text_import(struct lv_segment *seg, const struct config_node *sn,
struct dm_hash_table *pv_hash)
struct dm_hash_table *pv_hash __attribute((unused)))
{
uint32_t chunk_size;
const char *org_name, *cow_name;
@@ -87,8 +88,10 @@ static int _snap_text_export(const struct lv_segment *seg, struct formatter *f)
}
#ifdef DEVMAPPER_SUPPORT
static int _snap_target_percent(void **target_state, struct dm_pool *mem,
struct config_tree *cft, struct lv_segment *seg,
static int _snap_target_percent(void **target_state __attribute((unused)),
struct dm_pool *mem __attribute((unused)),
struct cmd_context *cmd __attribute((unused)),
struct lv_segment *seg __attribute((unused)),
char *params, uint64_t *total_numerator,
uint64_t *total_denominator, float *percent)
{
@@ -124,9 +127,21 @@ static int _snap_target_present(void)
}
#endif
static int _snap_modules_needed(struct dm_pool *mem,
const struct lv_segment *seg,
struct list *modules)
{
if (!str_list_add(mem, modules, "snapshot")) {
log_error("snapshot string list allocation failed");
return 0;
}
return 1;
}
static void _snap_destroy(const struct segment_type *segtype)
{
dm_free((void *) segtype);
dm_free((void *)segtype);
}
static struct segtype_handler _snapshot_ops = {
@@ -137,6 +152,7 @@ static struct segtype_handler _snapshot_ops = {
.target_percent = _snap_target_percent,
.target_present = _snap_target_present,
#endif
.modules_needed = _snap_modules_needed,
.destroy = _snap_destroy,
};

View File

@@ -151,11 +151,13 @@ static int _striped_merge_segments(struct lv_segment *seg1, struct lv_segment *s
}
#ifdef DEVMAPPER_SUPPORT
static int _striped_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
static int _striped_add_target_line(struct dev_manager *dm,
struct dm_pool *mem __attribute((unused)),
struct cmd_context *cmd __attribute((unused)),
void **target_state __attribute((unused)),
struct lv_segment *seg,
struct dm_tree_node *node, uint64_t len,
uint32_t *pvmove_mirror_count)
uint32_t *pvmove_mirror_count __attribute((unused)))
{
if (!seg->area_count) {
log_error("Internal error: striped add_target_line called "
@@ -189,7 +191,7 @@ static int _striped_target_present(void)
static void _striped_destroy(const struct segment_type *segtype)
{
dm_free((void *) segtype);
dm_free((void *)segtype);
}
static struct segtype_handler _striped_ops = {

View File

@@ -40,7 +40,7 @@ static int _zero_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2
#ifdef DEVMAPPER_SUPPORT
static int _zero_add_target_line(struct dev_manager *dm __attribute((unused)),
struct dm_pool *mem __attribute((unused)),
struct config_tree *cft __attribute((unused)),
struct cmd_context *cmd __attribute((unused)),
void **target_state __attribute((unused)),
struct lv_segment *seg __attribute((unused)),
struct dm_tree_node *node,uint64_t len,
@@ -63,6 +63,18 @@ static int _zero_target_present(void)
}
#endif
static int _zero_modules_needed(struct dm_pool *mem,
const struct lv_segment *seg,
struct list *modules)
{
if (!str_list_add(mem, modules, "zero")) {
log_error("zero module string list allocation failed");
return 0;
}
return 1;
}
static void _zero_destroy(const struct segment_type *segtype)
{
dm_free((void *) segtype);
@@ -75,6 +87,7 @@ static struct segtype_handler _zero_ops = {
.add_target_line = _zero_add_target_line,
.target_present = _zero_target_present,
#endif
.modules_needed = _zero_modules_needed,
.destroy = _zero_destroy,
};

View File

@@ -28,6 +28,7 @@ dm_task_set_gid
dm_task_set_mode
dm_task_suppress_identical_reload
dm_task_add_target
dm_task_no_flush
dm_task_no_open_count
dm_task_skip_lockfs
dm_task_update_nodes
@@ -109,3 +110,6 @@ dm_hash_get_first
dm_hash_get_next
dm_set_selinux_context
dm_task_set_geometry
dm_split_lvm_name
dm_split_words
dm_snprintf

View File

@@ -23,6 +23,7 @@ SOURCES =\
libdm-common.c \
libdm-file.c \
libdm-deptree.c \
libdm-string.c \
mm/dbg_malloc.c \
mm/pool.c \
$(interface)/libdm-iface.c

View File

@@ -1026,6 +1026,13 @@ int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char
return 1;
}
int dm_task_no_flush(struct dm_task *dmt)
{
dmt->no_flush = 1;
return 1;
}
int dm_task_no_open_count(struct dm_task *dmt)
{
dmt->no_open_count = 1;
@@ -1270,6 +1277,8 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
if (dmt->type == DM_DEVICE_SUSPEND)
dmi->flags |= DM_SUSPEND_FLAG;
if (dmt->no_flush)
dmi->flags |= DM_NOFLUSH_FLAG;
if (dmt->read_only)
dmi->flags |= DM_READONLY_FLAG;
if (dmt->skip_lockfs)
@@ -1461,7 +1470,6 @@ static int _reload_with_suppression_v4(struct dm_task *dmt)
{
struct dm_task *task;
struct target *t1, *t2;
int matches = 1;
int r;
/* New task to get existing table information */
@@ -1491,6 +1499,9 @@ static int _reload_with_suppression_v4(struct dm_task *dmt)
return r;
}
if ((task->dmi.v4->flags & DM_READONLY_FLAG) ? 1 : 0 != dmt->read_only)
goto no_match;
t1 = dmt->head;
t2 = task->head;
@@ -1498,21 +1509,20 @@ static int _reload_with_suppression_v4(struct dm_task *dmt)
if ((t1->start != t2->start) ||
(t1->length != t2->length) ||
(strcmp(t1->type, t2->type)) ||
(strcmp(t1->params, t2->params))) {
matches = 0;
break;
}
(strcmp(t1->params, t2->params)))
goto no_match;
t1 = t1->next;
t2 = t2->next;
}
if (matches && !t1 && !t2) {
if (!t1 && !t2) {
dmt->dmi.v4 = task->dmi.v4;
task->dmi.v4 = NULL;
dm_task_destroy(task);
return 1;
}
no_match:
dm_task_destroy(task);
/* Now do the original reload */
@@ -1542,7 +1552,7 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
dmi->flags |= DM_SKIP_BDGET_FLAG;
log_debug("dm %s %s %s%s%s %s%.0d%s%.0d%s"
"%s%c %.0llu %s [%u]",
"%s%c%c%s %.0llu %s [%u]",
_cmd_data_v4[dmt->type].name,
dmi->name, dmi->uuid, dmt->newname ? " " : "",
dmt->newname ? dmt->newname : "",
@@ -1553,6 +1563,8 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
dmt->major > 0 && dmt->minor == 0 ? "0" : "",
dmt->major > 0 ? ") " : "",
dmt->no_open_count ? 'N' : 'O',
dmt->no_flush ? 'N' : 'F',
dmt->skip_lockfs ? "S " : "",
dmt->sector, dmt->message ? dmt->message : "",
dmi->data_size);
#ifdef DM_IOCTLS

View File

@@ -52,6 +52,7 @@ struct dm_task {
char *message;
char *geometry;
uint64_t sector;
int no_flush;
int no_open_count;
int skip_lockfs;
int suppress_identical_reload;

View File

@@ -17,6 +17,7 @@
#define LIB_DEVICE_MAPPER_H
#include <inttypes.h>
#include <stdarg.h>
#include <sys/types.h>
#ifdef linux
@@ -150,6 +151,7 @@ int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr);
int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, const char *sectors, const char *start);
int dm_task_set_message(struct dm_task *dmt, const char *message);
int dm_task_set_sector(struct dm_task *dmt, uint64_t sector);
int dm_task_no_flush(struct dm_task *dmt);
int dm_task_no_open_count(struct dm_task *dmt);
int dm_task_skip_lockfs(struct dm_task *dmt);
int dm_task_suppress_identical_reload(struct dm_task *dmt);
@@ -350,6 +352,7 @@ int dm_tree_node_add_mirror_target(struct dm_tree_node *node,
#define DM_NOSYNC 0x00000001 /* Known already in sync */
#define DM_FORCESYNC 0x00000002 /* Force resync */
#define DM_BLOCK_ON_ERROR 0x00000004 /* On error, suspend I/O */
#define DM_CORELOG 0x00000008 /* In-memory log */
int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
uint32_t region_size,
@@ -581,4 +584,28 @@ struct dm_hash_node *dm_hash_get_next(struct dm_hash_table *t, struct dm_hash_no
*********/
int dm_set_selinux_context(const char *path, mode_t mode);
/*********************
* string manipulation
*********************/
/*
* Break up the name of a mapped device into its constituent
* Volume Group, Logical Volume and Layer (if present).
*/
int dm_split_lvm_name(struct dm_pool *mem, const char *dmname,
char **vgname, char **lvname, char **layer);
/*
* Destructively split buffer into NULL-separated words in argv.
* Returns number of words.
*/
int dm_split_words(char *buffer, unsigned max,
unsigned ignore_comments, /* Not implemented */
char **argv);
/*
* Returns -1 if buffer too small
*/
int dm_snprintf(char *buf, size_t bufsize, const char *format, ...);
#endif /* LIB_DEVICE_MAPPER_H */

View File

@@ -1242,9 +1242,12 @@ static int _emit_segment_line(struct dm_task *dmt, struct load_segment *seg, uin
log_parm_count = 1; /* Region size */
log_parm_count += hweight32(seg->flags); /* [no]sync, block_on_error etc. */
if (seg->flags & DM_CORELOG)
log_parm_count--; /* DM_CORELOG does not count in the param list */
if (seg->clustered) {
if (seg->uuid)
log_parm_count++; /* uuid */
log_parm_count++;
if ((tw = _dm_snprintf(params + pos, paramsize - pos, "clustered_")) < 0) {
stack; /* Out of space */
return -1;
@@ -1701,18 +1704,19 @@ int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
seg = list_item(list_last(&node->props.segs), struct load_segment);
if (log_uuid) {
if (!(log_node = dm_tree_find_node_by_uuid(node->dtree, log_uuid))) {
log_error("Couldn't find mirror log uuid %s.", log_uuid);
return 0;
}
if (!_link_tree_nodes(node, log_node))
return_0;
if (!(seg->uuid = dm_pool_strdup(node->dtree->mem, log_uuid))) {
log_error("log uuid pool_strdup failed");
return 0;
}
if (!(flags & DM_CORELOG)) {
if (!(log_node = dm_tree_find_node_by_uuid(node->dtree, log_uuid))) {
log_error("Couldn't find mirror log uuid %s.", log_uuid);
return 0;
}
if (!_link_tree_nodes(node, log_node))
return_0;
}
}
seg->log = log_node;

Some files were not shown because too many files have changed in this diff Show More