2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "lvm-string.h"
25 #include "toolcontext.h"
26 #include "dev_manager.h"
31 #include "sharedlib.h"
37 #define _skip(fmt, args...) log_very_verbose("Skipping: " fmt , ## args)
39 int lvm1_present(struct cmd_context *cmd)
43 if (dm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
45 log_error("LVM1 proc global snprintf failed");
49 if (path_exists(path))
55 int list_segment_modules(struct dm_pool *mem, const struct lv_segment *seg,
56 struct dm_list *modules)
59 struct lv_segment *seg2, *snap_seg;
62 if (seg->segtype->ops->modules_needed &&
63 !seg->segtype->ops->modules_needed(mem, seg, modules)) {
64 log_error("module string allocation failed");
68 if (lv_is_origin(seg->lv))
69 dm_list_iterate(snh, &seg->lv->snapshot_segs)
70 if (!list_lv_modules(mem,
71 dm_list_struct_base(snh,
77 if (lv_is_cow(seg->lv)) {
78 snap_seg = find_cow(seg->lv);
79 if (snap_seg->segtype->ops->modules_needed &&
80 !snap_seg->segtype->ops->modules_needed(mem, snap_seg,
82 log_error("snap_seg module string allocation failed");
87 for (s = 0; s < seg->area_count; s++) {
88 switch (seg_type(seg, s)) {
90 seg2 = find_seg_by_le(seg_lv(seg, s), seg_le(seg, s));
91 if (seg2 && !list_segment_modules(mem, seg2, modules))
103 int list_lv_modules(struct dm_pool *mem, const struct logical_volume *lv,
104 struct dm_list *modules)
106 struct lv_segment *seg;
108 dm_list_iterate_items(seg, &lv->segments)
109 if (!list_segment_modules(mem, seg, modules))
115 #ifndef DEVMAPPER_SUPPORT
116 void set_activation(int act)
118 static int warned = 0;
123 log_error("Compiled without libdevmapper support. "
124 "Can't enable activation.");
132 int library_version(char *version, size_t size)
136 int driver_version(char *version, size_t size)
140 int target_version(const char *target_name, uint32_t *maj,
141 uint32_t *min, uint32_t *patchlevel)
145 int target_present(struct cmd_context *cmd, const char *target_name,
150 int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, unsigned origin_only,
151 struct lvinfo *info, int with_open_count, int with_read_ahead)
155 int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
156 unsigned origin_only,
157 struct lvinfo *info, int with_open_count, int with_read_ahead)
161 int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
165 int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
166 int wait, percent_t *percent, uint32_t *event_nr)
170 int lvs_in_vg_activated(struct volume_group *vg)
174 int lvs_in_vg_opened(struct volume_group *vg)
179 int lv_suspend(struct cmd_context *cmd, const char *lvid_s)
184 int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s)
188 int lv_resume(struct cmd_context *cmd, const char *lvid_s)
192 int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s)
196 int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
200 int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
205 int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive)
209 int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive)
214 int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
219 int pv_uses_vg(struct physical_volume *pv,
220 struct volume_group *vg)
225 void activation_release(void)
230 void activation_exit(void)
235 #else /* DEVMAPPER_SUPPORT */
237 static int _activation = 1;
239 void set_activation(int act)
241 if (act == _activation)
246 log_verbose("Activation enabled. Device-mapper kernel "
247 "driver will be used.");
249 log_warn("WARNING: Activation disabled. No device-mapper "
250 "interaction will be attempted.");
258 static int _passes_activation_filter(struct cmd_context *cmd,
259 struct logical_volume *lv)
261 const struct config_node *cn;
262 const struct config_value *cv;
266 if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
267 log_verbose("activation/volume_list configuration setting "
268 "not defined, checking only host tags for %s/%s",
269 lv->vg->name, lv->name);
271 /* If no host tags defined, activate */
272 if (dm_list_empty(&cmd->tags))
275 /* If any host tag matches any LV or VG tag, activate */
276 if (str_list_match_list(&cmd->tags, &lv->tags, NULL) ||
277 str_list_match_list(&cmd->tags, &lv->vg->tags, NULL))
280 log_verbose("No host tag matches %s/%s",
281 lv->vg->name, lv->name);
287 log_verbose("activation/volume_list configuration setting "
288 "defined, checking the list to match %s/%s",
289 lv->vg->name, lv->name);
291 for (cv = cn->v; cv; cv = cv->next) {
292 if (cv->type != CFG_STRING) {
293 log_error("Ignoring invalid string in config file "
294 "activation/volume_list");
299 log_error("Ignoring empty string in config file "
300 "activation/volume_list");
309 log_error("Ignoring empty tag in config file "
310 "activation/volume_list");
313 /* If any host tag matches any LV or VG tag, activate */
314 if (!strcmp(str, "*")) {
315 if (str_list_match_list(&cmd->tags, &lv->tags, NULL)
316 || str_list_match_list(&cmd->tags,
317 &lv->vg->tags, NULL))
322 /* If supplied tag matches LV or VG tag, activate */
323 if (str_list_match_item(&lv->tags, str) ||
324 str_list_match_item(&lv->vg->tags, str))
329 if (!strchr(str, '/')) {
330 /* vgname supplied */
331 if (!strcmp(str, lv->vg->name))
337 if (dm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
339 log_error("dm_snprintf error from %s/%s", lv->vg->name,
343 if (!strcmp(path, str))
347 log_verbose("No item supplied in activation/volume_list configuration "
348 "setting matches %s/%s", lv->vg->name, lv->name);
353 int library_version(char *version, size_t size)
358 return dm_get_library_version(version, size);
361 int driver_version(char *version, size_t size)
366 log_very_verbose("Getting driver version");
368 return dm_driver_version(version, size);
371 int target_version(const char *target_name, uint32_t *maj,
372 uint32_t *min, uint32_t *patchlevel)
376 struct dm_versions *target, *last_target;
378 log_very_verbose("Getting target version for %s", target_name);
379 if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)))
382 if (!dm_task_run(dmt)) {
383 log_debug("Failed to get %s target version", target_name);
384 /* Assume this was because LIST_VERSIONS isn't supported */
388 target = dm_task_get_versions(dmt);
391 last_target = target;
393 if (!strcmp(target_name, target->name)) {
395 *maj = target->version[0];
396 *min = target->version[1];
397 *patchlevel = target->version[2];
401 target = (struct dm_versions *)((char *) target + target->next);
402 } while (last_target != target);
405 dm_task_destroy(dmt);
410 int module_present(struct cmd_context *cmd, const char *target_name)
417 if (dm_snprintf(module, sizeof(module), "dm-%s", target_name) < 0) {
418 log_error("module_present module name too long: %s",
423 argv[0] = MODPROBE_CMD;
427 ret = exec_cmd(cmd, argv, NULL);
432 int target_present(struct cmd_context *cmd, const char *target_name,
435 uint32_t maj, min, patchlevel;
442 if (target_version(target_name, &maj, &min, &patchlevel))
445 if (!module_present(cmd, target_name))
450 return target_version(target_name, &maj, &min, &patchlevel);
454 * Returns 1 if info structure populated, else 0 on failure.
456 int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, unsigned origin_only,
457 struct lvinfo *info, int with_open_count, int with_read_ahead)
459 struct dm_info dminfo;
464 if (!dev_manager_info(lv->vg->cmd->mem, lv, origin_only ? "real" : NULL, with_open_count,
465 with_read_ahead, &dminfo, &info->read_ahead))
468 info->exists = dminfo.exists;
469 info->suspended = dminfo.suspended;
470 info->open_count = dminfo.open_count;
471 info->major = dminfo.major;
472 info->minor = dminfo.minor;
473 info->read_only = dminfo.read_only;
474 info->live_table = dminfo.live_table;
475 info->inactive_table = dminfo.inactive_table;
480 int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
481 unsigned origin_only,
482 struct lvinfo *info, int with_open_count, int with_read_ahead)
485 struct logical_volume *lv;
487 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
490 if (!lv_is_origin(lv))
493 r = lv_info(cmd, lv, origin_only, info, with_open_count, with_read_ahead);
500 * Returns 1 if percent set, else 0 on failure.
502 int lv_check_transient(struct logical_volume *lv)
505 struct dev_manager *dm;
510 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
513 if (!(r = dev_manager_transient(dm, lv)))
516 dev_manager_destroy(dm);
522 * Returns 1 if percent set, else 0 on failure.
524 int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
527 struct dev_manager *dm;
532 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
535 if (!(r = dev_manager_snapshot_percent(dm, lv, percent)))
538 dev_manager_destroy(dm);
543 /* FIXME Merge with snapshot_percent */
544 int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
545 int wait, percent_t *percent, uint32_t *event_nr)
548 struct dev_manager *dm;
551 /* If mirrored LV is temporarily shrinked to 1 area (= linear),
552 * it should be considered in-sync. */
553 if (dm_list_size(&lv->segments) == 1 && first_seg(lv)->area_count == 1) {
554 *percent = PERCENT_100;
561 if (!lv_info(cmd, lv, 0, &info, 0, 0))
567 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
570 if (!(r = dev_manager_mirror_percent(dm, lv, wait, percent, event_nr)))
573 dev_manager_destroy(dm);
578 static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv)
582 if (!lv_info(cmd, lv, 0, &info, 0, 0)) {
590 static int _lv_open_count(struct cmd_context *cmd, struct logical_volume *lv)
594 if (!lv_info(cmd, lv, 0, &info, 1, 0)) {
599 return info.open_count;
602 static int _lv_activate_lv(struct logical_volume *lv, unsigned origin_only)
605 struct dev_manager *dm;
607 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
610 if (!(r = dev_manager_activate(dm, lv, origin_only)))
613 dev_manager_destroy(dm);
617 static int _lv_preload(struct logical_volume *lv, unsigned origin_only, int *flush_required)
620 struct dev_manager *dm;
622 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
625 if (!(r = dev_manager_preload(dm, lv, origin_only, flush_required)))
628 dev_manager_destroy(dm);
632 static int _lv_deactivate(struct logical_volume *lv)
635 struct dev_manager *dm;
637 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
640 if (!(r = dev_manager_deactivate(dm, lv)))
643 dev_manager_destroy(dm);
647 static int _lv_suspend_lv(struct logical_volume *lv, unsigned origin_only, int lockfs, int flush_required)
650 struct dev_manager *dm;
652 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
655 if (!(r = dev_manager_suspend(dm, lv, origin_only, lockfs, flush_required)))
658 dev_manager_destroy(dm);
663 * These two functions return the number of visible LVs in the state,
666 int lvs_in_vg_activated(struct volume_group *vg)
674 dm_list_iterate_items(lvl, &vg->lvs) {
675 if (lv_is_visible(lvl->lv))
676 count += (_lv_active(vg->cmd, lvl->lv) == 1);
682 int lvs_in_vg_opened(const struct volume_group *vg)
684 const struct lv_list *lvl;
690 dm_list_iterate_items(lvl, &vg->lvs) {
691 if (lv_is_visible(lvl->lv))
692 count += (_lv_open_count(vg->cmd, lvl->lv) > 0);
699 * Determine whether an LV is active locally or in a cluster.
700 * Assumes vg lock held.
702 * 0 - not active locally or on any node in cluster
703 * 1 - active either locally or some node in the cluster
705 int lv_is_active(struct logical_volume *lv)
709 if (_lv_active(lv->vg->cmd, lv))
712 if (!vg_is_clustered(lv->vg))
715 if ((ret = remote_lock_held(lv->lvid.s)) >= 0)
719 * Old compatibility code if locking doesn't support lock query
720 * FIXME: check status to not deactivate already activate device
722 if (activate_lv_excl(lv->vg->cmd, lv)) {
723 if (!deactivate_lv(lv->vg->cmd, lv))
729 * Exclusive local activation failed so assume it is active elsewhere.
735 static struct dm_event_handler *_create_dm_event_handler(struct cmd_context *cmd, const char *dmuuid, const char *dso,
736 const int timeout, enum dm_event_mask mask)
738 struct dm_event_handler *dmevh;
740 if (!(dmevh = dm_event_handler_create()))
743 if (dm_event_handler_set_dmeventd_path(dmevh, find_config_tree_str(cmd, "dmeventd/executable", NULL)))
746 if (dm_event_handler_set_dso(dmevh, dso))
749 if (dm_event_handler_set_uuid(dmevh, dmuuid))
752 dm_event_handler_set_timeout(dmevh, timeout);
753 dm_event_handler_set_event_mask(dmevh, mask);
758 dm_event_handler_destroy(dmevh);
762 char *get_monitor_dso_path(struct cmd_context *cmd, const char *libpath)
766 if (!(path = dm_pool_alloc(cmd->mem, PATH_MAX))) {
767 log_error("Failed to allocate dmeventd library path.");
771 get_shared_library_path(cmd, libpath, path, PATH_MAX);
776 int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso,
777 struct logical_volume *lv, int *pending)
780 enum dm_event_mask evmask = 0;
781 struct dm_event_handler *dmevh;
788 /* We always monitor the "real" device, never the "snapshot-origin" itself. */
789 if (!(uuid = build_dm_uuid(cmd->mem, lv->lvid.s, lv_is_origin(lv) ? "real" : NULL)))
792 if (!(dmevh = _create_dm_event_handler(cmd, uuid, dso, 0, DM_EVENT_ALL_ERRORS)))
795 if (dm_event_get_registered_device(dmevh, 0)) {
796 dm_event_handler_destroy(dmevh);
800 evmask = dm_event_handler_get_event_mask(dmevh);
801 if (evmask & DM_EVENT_REGISTRATION_PENDING) {
803 evmask &= ~DM_EVENT_REGISTRATION_PENDING;
806 dm_event_handler_destroy(dmevh);
811 int target_register_events(struct cmd_context *cmd, const char *dso, struct logical_volume *lv,
812 int evmask __attribute__((unused)), int set, int timeout)
815 struct dm_event_handler *dmevh;
821 /* We always monitor the "real" device, never the "snapshot-origin" itself. */
822 if (!(uuid = build_dm_uuid(cmd->mem, lv->lvid.s, lv_is_origin(lv) ? "real" : NULL)))
825 if (!(dmevh = _create_dm_event_handler(cmd, uuid, dso, timeout,
826 DM_EVENT_ALL_ERRORS | (timeout ? DM_EVENT_TIMEOUT : 0))))
829 r = set ? dm_event_register_handler(dmevh) : dm_event_unregister_handler(dmevh);
831 dm_event_handler_destroy(dmevh);
836 log_info("%s %s for events", set ? "Monitored" : "Unmonitored", uuid);
844 * Returns 0 if an attempt to (un)monitor the device failed.
845 * Returns 1 otherwise.
847 int monitor_dev_for_events(struct cmd_context *cmd, struct logical_volume *lv,
848 unsigned origin_only, int monitor)
851 int i, pending = 0, monitored;
853 struct dm_list *tmp, *snh, *snht;
854 struct lv_segment *seg;
855 struct lv_segment *log_seg;
856 int (*monitor_fn) (struct lv_segment *s, int e);
859 /* skip dmeventd code altogether */
860 if (dmeventd_monitor_mode() == DMEVENTD_MONITOR_IGNORE)
864 * Nothing to do if dmeventd configured not to be used.
866 if (monitor && !dmeventd_monitor_mode())
870 * In case of a snapshot device, we monitor lv->snapshot->lv,
871 * not the actual LV itself.
873 if (lv_is_cow(lv) && !lv_is_merging_cow(lv))
874 return monitor_dev_for_events(cmd, lv->snapshot->lv, 0, monitor);
877 * In case this LV is a snapshot origin, we instead monitor
878 * each of its respective snapshots. The origin itself may
879 * also need to be monitored if it is a mirror, for example.
881 if (!origin_only && lv_is_origin(lv))
882 dm_list_iterate_safe(snh, snht, &lv->snapshot_segs)
883 if (!monitor_dev_for_events(cmd, dm_list_struct_base(snh,
884 struct lv_segment, origin_list)->cow, 0, monitor))
888 * If the volume is mirrored and its log is also mirrored, monitor
889 * the log volume as well.
891 if ((seg = first_seg(lv)) != NULL && seg->log_lv != NULL &&
892 (log_seg = first_seg(seg->log_lv)) != NULL &&
893 seg_is_mirrored(log_seg))
894 if (!monitor_dev_for_events(cmd, seg->log_lv, 0, monitor))
897 dm_list_iterate(tmp, &lv->segments) {
898 seg = dm_list_item(tmp, struct lv_segment);
900 /* Recurse for AREA_LV */
901 for (s = 0; s < seg->area_count; s++) {
902 if (seg_type(seg, s) != AREA_LV)
904 if (!monitor_dev_for_events(cmd, seg_lv(seg, s), 0,
906 log_error("Failed to %smonitor %s",
908 seg_lv(seg, s)->name);
913 if (!seg_monitored(seg) || (seg->status & PVMOVE))
918 /* Check monitoring status */
919 if (seg->segtype->ops->target_monitored)
920 monitored = seg->segtype->ops->target_monitored(seg, &pending);
922 continue; /* segtype doesn't support registration */
925 * FIXME: We should really try again if pending
927 monitored = (pending) ? 0 : monitored;
931 log_verbose("%s/%s already monitored.", lv->vg->name, lv->name);
932 else if (seg->segtype->ops->target_monitor_events)
933 monitor_fn = seg->segtype->ops->target_monitor_events;
936 log_verbose("%s/%s already not monitored.", lv->vg->name, lv->name);
937 else if (seg->segtype->ops->target_unmonitor_events)
938 monitor_fn = seg->segtype->ops->target_unmonitor_events;
945 log_verbose("%sonitoring %s/%s%s", monitor ? "M" : "Not m", lv->vg->name, lv->name,
946 test_mode() ? " [Test mode: skipping this]" : "");
948 /* FIXME Test mode should really continue a bit further. */
952 /* FIXME specify events */
953 if (!monitor_fn(seg, 0)) {
954 log_error("%s/%s: %s segment monitoring function failed.",
955 lv->vg->name, lv->name, seg->segtype->name);
959 /* Check [un]monitor results */
960 /* Try a couple times if pending, but not forever... */
961 for (i = 0; i < 10; i++) {
963 monitored = seg->segtype->ops->target_monitored(seg, &pending);
965 (!monitored && monitor) ||
966 (monitored && !monitor))
967 log_very_verbose("%s/%s %smonitoring still pending: waiting...",
968 lv->vg->name, lv->name, monitor ? "" : "un");
975 r = (monitored && monitor) || (!monitored && !monitor);
984 static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
985 unsigned origin_only, int error_if_not_suspended)
987 struct logical_volume *lv = NULL, *lv_pre = NULL;
989 int r = 0, lockfs = 0, flush_required = 0;
994 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
997 /* Use precommitted metadata if present */
998 if (!(lv_pre = lv_from_lvid(cmd, lvid_s, 1)))
1001 /* Ignore origin_only unless LV is origin in both old and new metadata */
1002 if (!lv_is_origin(lv) || !lv_is_origin(lv_pre))
1006 _skip("Suspending %s%s.", lv->name, origin_only ? " origin without snapshots" : "");
1011 if (!lv_info(cmd, lv, origin_only, &info, 0, 0))
1014 if (!info.exists || info.suspended) {
1015 if (!error_if_not_suspended) {
1023 if (!lv_read_replicator_vgs(lv))
1026 lv_calculate_readahead(lv, NULL);
1028 /* If VG was precommitted, preload devices for the LV */
1029 if ((lv_pre->vg->status & PRECOMMITTED)) {
1030 if (!_lv_preload(lv_pre, origin_only, &flush_required)) {
1031 /* FIXME Revert preloading */
1036 if (!monitor_dev_for_events(cmd, lv, origin_only, 0))
1037 /* FIXME Consider aborting here */
1043 (lv_is_origin(lv_pre) || lv_is_cow(lv_pre)))
1046 if (!_lv_suspend_lv(lv, origin_only, lockfs, flush_required)) {
1055 free_vg(lv_pre->vg);
1057 lv_release_replicator_vgs(lv);
1064 /* Returns success if the device is not active */
1065 int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
1067 return _lv_suspend(cmd, lvid_s, origin_only, 0);
1070 /* No longer used */
1072 int lv_suspend(struct cmd_context *cmd, const char *lvid_s)
1074 return _lv_suspend(cmd, lvid_s, 1);
1078 static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
1079 unsigned origin_only,
1080 int error_if_not_active)
1082 struct logical_volume *lv;
1089 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
1092 if (!lv_is_origin(lv))
1096 _skip("Resuming %s%s.", lv->name, origin_only ? " without snapshots" : "");
1101 if (!lv_info(cmd, lv, origin_only, &info, 0, 0))
1104 if (!info.exists || !info.suspended) {
1105 if (error_if_not_active)
1111 if (!_lv_activate_lv(lv, origin_only))
1117 if (!monitor_dev_for_events(cmd, lv, origin_only, 1))
1128 /* Returns success if the device is not active */
1129 int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
1131 return _lv_resume(cmd, lvid_s, origin_only, 0);
1134 int lv_resume(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
1136 return _lv_resume(cmd, lvid_s, origin_only, 1);
1139 static int _lv_has_open_snapshots(struct logical_volume *lv)
1141 struct lv_segment *snap_seg;
1145 dm_list_iterate_items_gen(snap_seg, &lv->snapshot_segs, origin_list) {
1146 if (!lv_info(lv->vg->cmd, snap_seg->cow, 0, &info, 1, 0)) {
1151 if (info.exists && info.open_count) {
1152 log_error("LV %s/%s has open snapshot %s: "
1153 "not deactivating", lv->vg->name, lv->name,
1154 snap_seg->cow->name);
1162 int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
1164 struct logical_volume *lv;
1171 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
1175 _skip("Deactivating '%s'.", lv->name);
1180 if (!lv_info(cmd, lv, 0, &info, 1, 0))
1188 if (lv_is_visible(lv)) {
1189 if (info.open_count) {
1190 log_error("LV %s/%s in use: not deactivating",
1191 lv->vg->name, lv->name);
1194 if (lv_is_origin(lv) && _lv_has_open_snapshots(lv))
1198 if (!lv_read_replicator_vgs(lv))
1201 lv_calculate_readahead(lv, NULL);
1203 if (!monitor_dev_for_events(cmd, lv, 0, 0))
1207 r = _lv_deactivate(lv);
1211 if (!lv_info(cmd, lv, 0, &info, 1, 0) || info.exists)
1215 lv_release_replicator_vgs(lv);
1222 /* Test if LV passes filter */
1223 int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
1226 struct logical_volume *lv;
1229 if (!activation()) {
1234 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
1237 if (!_passes_activation_filter(cmd, lv)) {
1238 log_verbose("Not activating %s/%s since it does not pass "
1239 "activation filter.", lv->vg->name, lv->name);
1251 static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
1252 int exclusive, int filter)
1254 struct logical_volume *lv;
1261 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
1264 if (filter && !_passes_activation_filter(cmd, lv)) {
1265 log_error("Not activating %s/%s since it does not pass "
1266 "activation filter.", lv->vg->name, lv->name);
1270 if ((!lv->vg->cmd->partial_activation) && (lv->status & PARTIAL_LV)) {
1271 log_error("Refusing activation of partial LV %s. Use --partial to override.",
1276 if (lv_has_unknown_segments(lv)) {
1277 log_error("Refusing activation of LV %s containing "
1278 "an unrecognised segment.", lv->name);
1283 _skip("Activating '%s'.", lv->name);
1288 if (!lv_info(cmd, lv, 0, &info, 0, 0))
1291 if (info.exists && !info.suspended && info.live_table) {
1296 if (!lv_read_replicator_vgs(lv))
1299 lv_calculate_readahead(lv, NULL);
1302 lv->status |= ACTIVATE_EXCL;
1305 if (!(r = _lv_activate_lv(lv, 0)))
1310 if (r && !monitor_dev_for_events(cmd, lv, 0, 1))
1315 lv_release_replicator_vgs(lv);
1323 int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive)
1325 if (!_lv_activate(cmd, lvid_s, exclusive, 0))
1331 /* Activate LV only if it passes filter */
1332 int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive)
1334 if (!_lv_activate(cmd, lvid_s, exclusive, 1))
1340 int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
1345 r = dm_mknodes(NULL);
1353 r = dev_manager_mknodes(lv);
1361 * Does PV use VG somewhere in its construction?
1362 * Returns 1 on failure.
1364 int pv_uses_vg(struct physical_volume *pv,
1365 struct volume_group *vg)
1370 if (!dm_is_dm_major(MAJOR(pv->dev->dev)))
1373 return dev_manager_device_uses_vg(pv->dev, vg);
1376 void activation_release(void)
1378 dev_manager_release();
1381 void activation_exit(void)