]> sourceware.org Git - lvm2.git/blame - lib/activate/activate.c
Add details to format1 'Invalid LV in extent map' error message.
[lvm2.git] / lib / activate / activate.c
CommitLineData
b1713d28 1/*
6606c3ae 2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5f4b2acf 3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
b1713d28 4 *
6606c3ae
AK
5 * This file is part of LVM2.
6 *
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 General Public License v.2.
10 *
11 * You should have received a copy of the GNU 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
b1713d28
JT
14 */
15
d1d9800e 16#include "lib.h"
a381c45a 17#include "metadata.h"
b1713d28 18#include "activate.h"
914c9723 19#include "memlock.h"
78125be9 20#include "display.h"
f7a14956 21#include "fs.h"
f894b4b1 22#include "lvm-exec.h"
7d1552c9 23#include "lvm-file.h"
41b2fd5f 24#include "lvm-string.h"
413cc918 25#include "toolcontext.h"
de6c9183 26#include "dev_manager.h"
de17d760 27#include "str_list.h"
4922197a 28#include "config.h"
352a99b9 29#include "filter.h"
15d91f5a 30#include "segtype.h"
12137231
JT
31
32#include <limits.h>
5986ec94 33#include <fcntl.h>
914c9723 34#include <unistd.h>
12137231 35
6d52fb46 36#define _skip(fmt, args...) log_very_verbose("Skipping: " fmt , ## args)
b1713d28 37
7d1552c9
AK
38int lvm1_present(struct cmd_context *cmd)
39{
40 char path[PATH_MAX];
41
42 if (lvm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
43 < 0) {
44 log_error("LVM1 proc global snprintf failed");
45 return 0;
46 }
47
48 if (path_exists(path))
49 return 1;
50 else
51 return 0;
52}
53
199e490e
AK
54#ifndef DEVMAPPER_SUPPORT
55void set_activation(int act)
56{
f2046e0a
AK
57 static int warned = 0;
58
59 if (warned || !act)
60 return;
61
62 log_error("Compiled without libdevmapper support. "
63 "Can't enable activation.");
64
65 warned = 1;
199e490e
AK
66}
67int activation(void)
68{
69 return 0;
70}
71int library_version(char *version, size_t size)
72{
73 return 0;
74}
75int driver_version(char *version, size_t size)
76{
77 return 0;
78}
d1f4953a
AK
79int target_present(const char *target_name)
80{
81 return 0;
82}
f894b4b1 83int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info,
e9c761b8 84 int with_open_count)
199e490e
AK
85{
86 return 0;
87}
4bd9480d 88int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
e9c761b8 89 struct lvinfo *info, int with_open_count)
4bd9480d
AK
90{
91 return 0;
92}
199e490e
AK
93int lv_snapshot_percent(struct logical_volume *lv, float *percent)
94{
95 return 0;
96}
914c9723
AK
97int lv_mirror_percent(struct logical_volume *lv, int wait, float *percent,
98 uint32_t *event_nr)
10b29b8d
AK
99{
100 return 0;
101}
199e490e
AK
102int lvs_in_vg_activated(struct volume_group *vg)
103{
104 return 0;
105}
106int lvs_in_vg_opened(struct volume_group *vg)
107{
108 return 0;
109}
658b5812
AK
110int lv_suspend(struct cmd_context *cmd, const char *lvid_s)
111{
112 return 1;
113}
199e490e
AK
114int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s)
115{
116 return 1;
117}
658b5812
AK
118int lv_resume(struct cmd_context *cmd, const char *lvid_s)
119{
120 return 1;
121}
199e490e
AK
122int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s)
123{
124 return 1;
125}
126int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
127{
128 return 1;
129}
658b5812
AK
130int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
131 int *activate_lv)
132{
133 return 1;
134}
07d31831 135int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive)
199e490e
AK
136{
137 return 1;
138}
07d31831 139int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive)
658b5812
AK
140{
141 return 1;
142}
f7dd6d84
AK
143
144int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
145{
146 return 1;
147}
148
352a99b9
AK
149int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
150 struct volume_group *vg)
151{
152 return 0;
153}
154
914c9723
AK
155void activation_exit(void)
156{
157 return;
158}
199e490e
AK
159
160#else /* DEVMAPPER_SUPPORT */
161
d1d9800e
AK
162static int _activation = 1;
163
8ef2b021 164void set_activation(int act)
d1d9800e 165{
8ef2b021 166 if (act == _activation)
d1d9800e
AK
167 return;
168
8ef2b021 169 _activation = act;
d1d9800e
AK
170 if (_activation)
171 log_verbose("Activation enabled. Device-mapper kernel "
172 "driver will be used.");
173 else
174 log_verbose("Activation disabled. No device-mapper "
175 "interaction will be attempted.");
176}
177
8ef2b021 178int activation(void)
d1d9800e
AK
179{
180 return _activation;
181}
182
de17d760
AK
183static int _passes_activation_filter(struct cmd_context *cmd,
184 struct logical_volume *lv)
185{
25579907 186 const struct config_node *cn;
de17d760
AK
187 struct config_value *cv;
188 char *str;
189 char path[PATH_MAX];
190
814643d8 191 if (!(cn = find_config_node(cmd->cft->root, "activation/volume_list"))) {
25579907 192 /* If no host tags defined, activate */
de17d760
AK
193 if (list_empty(&cmd->tags))
194 return 1;
195
196 /* If any host tag matches any LV or VG tag, activate */
197 if (str_list_match_list(&cmd->tags, &lv->tags) ||
198 str_list_match_list(&cmd->tags, &lv->vg->tags))
199 return 1;
200
201 /* Don't activate */
202 return 0;
203 }
204
205 for (cv = cn->v; cv; cv = cv->next) {
206 if (cv->type != CFG_STRING) {
207 log_error("Ignoring invalid string in config file "
208 "activation/volume_list");
209 continue;
210 }
211 str = cv->v.str;
212 if (!*str) {
213 log_error("Ignoring empty string in config file "
214 "activation/volume_list");
215 continue;
216 }
217
218 /* Tag? */
219 if (*str == '@') {
220 str++;
221 if (!*str) {
222 log_error("Ignoring empty tag in config file "
223 "activation/volume_list");
224 continue;
225 }
226 /* If any host tag matches any LV or VG tag, activate */
227 if (!strcmp(str, "*")) {
228 if (str_list_match_list(&cmd->tags, &lv->tags)
229 || str_list_match_list(&cmd->tags,
230 &lv->vg->tags))
231 return 1;
232 else
233 continue;
234 }
235 /* If supplied tag matches LV or VG tag, activate */
236 if (str_list_match_item(&lv->tags, str) ||
237 str_list_match_item(&lv->vg->tags, str))
238 return 1;
239 else
240 continue;
241 }
242 if (!index(str, '/')) {
243 /* vgname supplied */
244 if (!strcmp(str, lv->vg->name))
245 return 1;
246 else
247 continue;
248 }
249 /* vgname/lvname */
250 if (lvm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
251 lv->name) < 0) {
252 log_error("lvm_snprintf error from %s/%s", lv->vg->name,
253 lv->name);
254 continue;
255 }
256 if (!strcmp(path, str))
257 return 1;
258 }
259
260 return 0;
261}
262
fae0c576
AK
263int library_version(char *version, size_t size)
264{
d1d9800e
AK
265 if (!activation())
266 return 0;
267
f894b4b1 268 return dm_get_library_version(version, size);
fae0c576
AK
269}
270
fae0c576
AK
271int driver_version(char *version, size_t size)
272{
d1d9800e
AK
273 if (!activation())
274 return 0;
275
fae0c576 276 log_very_verbose("Getting driver version");
fae0c576 277
f894b4b1 278 return dm_driver_version(version, size);
fae0c576
AK
279}
280
f894b4b1 281static int _target_present(const char *target_name)
d1f4953a
AK
282{
283 int r = 0;
284 struct dm_task *dmt;
285 struct dm_versions *target, *last_target;
286
d1f4953a 287 log_very_verbose("Getting target version for %s", target_name);
5f4b2acf
AK
288 if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)))
289 return_0;
d1f4953a
AK
290
291 if (!dm_task_run(dmt)) {
292 log_debug("Failed to get %s target version", target_name);
293 /* Assume this was because LIST_VERSIONS isn't supported */
294 return 1;
295 }
296
297 target = dm_task_get_versions(dmt);
298
299 do {
300 last_target = target;
301
302 if (!strcmp(target_name, target->name)) {
303 r = 1;
304 goto out;
305 }
306
307 target = (void *) target + target->next;
308 } while (last_target != target);
309
310 out:
311 dm_task_destroy(dmt);
312
313 return r;
314}
315
5f4b2acf 316int target_present(const char *target_name, int use_modprobe)
f894b4b1 317{
03b49fe1 318#ifdef MODPROBE_CMD
f894b4b1 319 char module[128];
03b49fe1 320#endif
f894b4b1
AK
321
322 if (!activation())
323 return 0;
324
325#ifdef MODPROBE_CMD
5f4b2acf
AK
326 if (use_modprobe) {
327 if (_target_present(target_name))
328 return 1;
f894b4b1 329
5f4b2acf
AK
330 if (lvm_snprintf(module, sizeof(module), "dm-%s", target_name)
331 < 0) {
332 log_error("target_present module name too long: %s",
333 target_name);
334 return 0;
335 }
f894b4b1 336
5f4b2acf
AK
337 if (!exec_cmd(MODPROBE_CMD, module, "", ""))
338 return_0;
f894b4b1
AK
339 }
340#endif
341
342 return _target_present(target_name);
343}
344
de6c9183
JT
345/*
346 * Returns 1 if info structure populated, else 0 on failure.
347 */
f894b4b1 348static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, int with_mknodes,
e9c761b8 349 struct lvinfo *info, int with_open_count)
37ed70b9 350{
199e490e 351 struct dm_info dminfo;
f894b4b1 352 char *name;
4a624ca0 353
d1d9800e
AK
354 if (!activation())
355 return 0;
356
5f4b2acf
AK
357 if (!(name = build_dm_name(cmd->mem, lv->vg->name, lv->name, NULL)))
358 return_0;
4a624ca0 359
f894b4b1 360 log_debug("Getting device info for %s", name);
03b49fe1
AK
361 if (!dev_manager_info(lv->vg->cmd->mem, name, lv, with_mknodes,
362 with_open_count, &dminfo)) {
f894b4b1 363 dm_pool_free(cmd->mem, name);
5f4b2acf 364 return_0;
f894b4b1 365 }
4a624ca0 366
199e490e
AK
367 info->exists = dminfo.exists;
368 info->suspended = dminfo.suspended;
369 info->open_count = dminfo.open_count;
370 info->major = dminfo.major;
371 info->minor = dminfo.minor;
372 info->read_only = dminfo.read_only;
5f4b2acf
AK
373 info->live_table = dminfo.live_table;
374 info->inactive_table = dminfo.inactive_table;
199e490e 375
f894b4b1
AK
376 dm_pool_free(cmd->mem, name);
377 return 1;
de6c9183 378}
a62ee8ad 379
f894b4b1 380int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info,
e9c761b8 381 int with_open_count)
8c0388e4 382{
f894b4b1 383 return _lv_info(cmd, lv, 0, info, with_open_count);
8c0388e4
AK
384}
385
4bd9480d 386int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
e9c761b8 387 struct lvinfo *info, int with_open_count)
4bd9480d
AK
388{
389 struct logical_volume *lv;
390
7a593325 391 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
4bd9480d
AK
392 return 0;
393
f894b4b1 394 return _lv_info(cmd, lv, 0, info, with_open_count);
4bd9480d
AK
395}
396
1951dba9
AL
397/*
398 * Returns 1 if percent set, else 0 on failure.
399 */
c826c0d1 400int lv_snapshot_percent(struct logical_volume *lv, float *percent)
1951dba9
AL
401{
402 int r;
403 struct dev_manager *dm;
404
d1d9800e
AK
405 if (!activation())
406 return 0;
407
5f4b2acf
AK
408 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
409 return_0;
1951dba9 410
c826c0d1 411 if (!(r = dev_manager_snapshot_percent(dm, lv, percent)))
1951dba9 412 stack;
c826c0d1 413
1951dba9
AL
414 dev_manager_destroy(dm);
415
416 return r;
417}
418
10b29b8d 419/* FIXME Merge with snapshot_percent */
f894b4b1 420int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv, int wait, float *percent,
10b29b8d
AK
421 uint32_t *event_nr)
422{
423 int r;
424 struct dev_manager *dm;
b65b777d 425 struct lvinfo info;
10b29b8d
AK
426
427 if (!activation())
428 return 0;
429
5f4b2acf
AK
430 if (!lv_info(cmd, lv, &info, 0))
431 return_0;
b65b777d
AK
432
433 if (!info.exists)
434 return 0;
435
5f4b2acf
AK
436 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
437 return_0;
10b29b8d
AK
438
439 if (!(r = dev_manager_mirror_percent(dm, lv, wait, percent, event_nr)))
440 stack;
441
442 dev_manager_destroy(dm);
443
444 return r;
445}
446
f894b4b1 447static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv)
2ba80b43 448{
199e490e 449 struct lvinfo info;
2ba80b43 450
f894b4b1 451 if (!lv_info(cmd, lv, &info, 0)) {
2ba80b43 452 stack;
de6c9183 453 return -1;
2ba80b43
JT
454 }
455
de6c9183 456 return info.exists;
2ba80b43
JT
457}
458
f894b4b1 459static int _lv_open_count(struct cmd_context *cmd, struct logical_volume *lv)
5986ec94 460{
199e490e 461 struct lvinfo info;
5986ec94 462
f894b4b1 463 if (!lv_info(cmd, lv, &info, 1)) {
5986ec94 464 stack;
de6c9183 465 return -1;
5986ec94
JT
466 }
467
de6c9183 468 return info.open_count;
5986ec94
JT
469}
470
658b5812 471static int _lv_activate_lv(struct logical_volume *lv)
b1713d28 472{
6d52fb46 473 int r;
de6c9183 474 struct dev_manager *dm;
b1713d28 475
5f4b2acf
AK
476 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
477 return_0;
ae2bb665 478
0fe3a2c5 479 if (!(r = dev_manager_activate(dm, lv)))
6d52fb46 480 stack;
ae2bb665 481
de6c9183 482 dev_manager_destroy(dm);
ae2bb665 483 return r;
b1713d28 484}
a381c45a 485
5f4b2acf 486static int _lv_preload(struct logical_volume *lv)
0a5e4a14 487{
de6c9183
JT
488 int r;
489 struct dev_manager *dm;
37ed70b9 490
5f4b2acf
AK
491 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
492 return_0;
493
494 if (!(r = dev_manager_preload(dm, lv)))
6d52fb46 495 stack;
5f4b2acf
AK
496
497 dev_manager_destroy(dm);
498 return r;
499}
500
501static int _lv_deactivate(struct logical_volume *lv)
502{
503 int r;
504 struct dev_manager *dm;
505
506 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
507 return_0;
37ed70b9 508
de6c9183 509 if (!(r = dev_manager_deactivate(dm, lv)))
37ed70b9 510 stack;
37ed70b9 511
de6c9183
JT
512 dev_manager_destroy(dm);
513 return r;
37ed70b9
JT
514}
515
658b5812 516static int _lv_suspend_lv(struct logical_volume *lv)
4a624ca0 517{
20c5fcf7
AK
518 int r;
519 struct dev_manager *dm;
c2d72fd4 520
5f4b2acf
AK
521 if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
522 return_0;
0a5e4a14 523
20c5fcf7 524 if (!(r = dev_manager_suspend(dm, lv)))
37ed70b9 525 stack;
0a5e4a14 526
20c5fcf7
AK
527 dev_manager_destroy(dm);
528 return r;
6d52fb46 529}
4a624ca0 530
8c013da4 531/*
f75c11ed 532 * These two functions return the number of visible LVs in the state,
8c013da4
AK
533 * or -1 on error.
534 */
f047219b
AK
535int lvs_in_vg_activated(struct volume_group *vg)
536{
60f13f01 537 struct lv_list *lvl;
94b8220f 538 int count = 0;
37ed70b9 539
d1d9800e
AK
540 if (!activation())
541 return 0;
542
60f13f01
AK
543 list_iterate_items(lvl, &vg->lvs) {
544 if (lvl->lv->status & VISIBLE_LV)
f894b4b1 545 count += (_lv_active(vg->cmd, lvl->lv) == 1);
37ed70b9
JT
546 }
547
548 return count;
f047219b 549}
2ba80b43
JT
550
551int lvs_in_vg_opened(struct volume_group *vg)
552{
60f13f01 553 struct lv_list *lvl;
94b8220f 554 int count = 0;
2ba80b43 555
d1d9800e
AK
556 if (!activation())
557 return 0;
558
60f13f01
AK
559 list_iterate_items(lvl, &vg->lvs) {
560 if (lvl->lv->status & VISIBLE_LV)
f894b4b1 561 count += (_lv_open_count(vg->cmd, lvl->lv) > 0);
2ba80b43
JT
562 }
563
564 return count;
565}
413cc918 566
15d91f5a
AK
567#ifdef DMEVENTD
568static int _register_dev(struct cmd_context *cmd, struct logical_volume *lv,
569 int do_reg)
570{
571
572 struct list *tmp;
573 struct lv_segment *seg;
574 int (*reg) (struct dm_pool *mem, struct lv_segment *,
575 struct config_tree *cft, int events);
576
577 list_iterate(tmp, &lv->segments) {
578 seg = list_item(tmp, struct lv_segment);
579
e6493477
AK
580 if (do_reg) {
581 if (seg->segtype->ops->target_register_events)
582 reg = seg->segtype->ops->target_register_events;
583 } else if(seg->setype->ops->target_unregister_events)
584 reg = seg->segtype->ops->target_unregister_events;
15d91f5a
AK
585
586 if (reg)
587 /* FIXME specify events */
588 if (!reg(cmd->mem, seg, cmd->cft, 0)) {
589 stack;
590 return 0;
591 }
592 }
e6493477 593
15d91f5a
AK
594 return 1;
595}
596#endif
597
658b5812
AK
598static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
599 int error_if_not_suspended)
413cc918
AK
600{
601 struct logical_volume *lv;
199e490e 602 struct lvinfo info;
413cc918 603
d1d9800e
AK
604 if (!activation())
605 return 1;
606
7a593325
AK
607 /* Use precommitted metadata if present */
608 if (!(lv = lv_from_lvid(cmd, lvid_s, 1)))
413cc918
AK
609 return 0;
610
20c5fcf7
AK
611 if (test_mode()) {
612 _skip("Suspending '%s'.", lv->name);
711f7fc6 613 return 1;
20c5fcf7
AK
614 }
615
5f4b2acf
AK
616 if (!lv_info(cmd, lv, &info, 0))
617 return_0;
41967a02 618
914c9723 619 if (!info.exists || info.suspended)
658b5812 620 return error_if_not_suspended ? 0 : 1;
914c9723 621
5f4b2acf
AK
622 /* If VG was precommitted, preload devices for the LV */
623 if ((lv->vg->status & PRECOMMITTED)) {
624 if (!_lv_preload(lv)) {
625 /* FIXME Revert preloading */
626 return_0;
627 }
628 }
629
15d91f5a
AK
630#ifdef DMEVENTD
631 _register_dev(cmd, lv, 0);
632#endif
914c9723 633 memlock_inc();
658b5812 634 if (!_lv_suspend_lv(lv)) {
914c9723
AK
635 memlock_dec();
636 fs_unlock();
637 return 0;
638 }
8c013da4 639
413cc918
AK
640 return 1;
641}
642
658b5812
AK
643/* Returns success if the device is not active */
644int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s)
645{
646 return _lv_suspend(cmd, lvid_s, 0);
647}
648
649int lv_suspend(struct cmd_context *cmd, const char *lvid_s)
650{
651 return _lv_suspend(cmd, lvid_s, 1);
652}
653
654static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
655 int error_if_not_active)
413cc918
AK
656{
657 struct logical_volume *lv;
199e490e 658 struct lvinfo info;
413cc918 659
d1d9800e
AK
660 if (!activation())
661 return 1;
662
7a593325 663 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
413cc918
AK
664 return 0;
665
20c5fcf7
AK
666 if (test_mode()) {
667 _skip("Resuming '%s'.", lv->name);
711f7fc6 668 return 1;
20c5fcf7
AK
669 }
670
5f4b2acf
AK
671 if (!lv_info(cmd, lv, &info, 0))
672 return_0;
41967a02 673
914c9723 674 if (!info.exists || !info.suspended)
658b5812 675 return error_if_not_active ? 0 : 1;
914c9723 676
658b5812 677 if (!_lv_activate_lv(lv))
914c9723
AK
678 return 0;
679
680 memlock_dec();
681 fs_unlock();
413cc918 682
15d91f5a
AK
683#ifdef DMEVENTD
684 _register_dev(cmd, lv, 1);
685#endif
686
413cc918
AK
687 return 1;
688}
689
658b5812
AK
690/* Returns success if the device is not active */
691int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s)
692{
693 return _lv_resume(cmd, lvid_s, 0);
694}
695
696int lv_resume(struct cmd_context *cmd, const char *lvid_s)
697{
698 return _lv_resume(cmd, lvid_s, 1);
699}
700
be326a2f 701int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
f4cbeaf0
AK
702{
703 struct logical_volume *lv;
199e490e 704 struct lvinfo info;
914c9723 705 int r;
f4cbeaf0 706
d1d9800e
AK
707 if (!activation())
708 return 1;
709
7a593325 710 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
f4cbeaf0
AK
711 return 0;
712
20c5fcf7
AK
713 if (test_mode()) {
714 _skip("Deactivating '%s'.", lv->name);
711f7fc6 715 return 1;
20c5fcf7
AK
716 }
717
5f4b2acf
AK
718 if (!lv_info(cmd, lv, &info, 1))
719 return_0;
41967a02 720
914c9723
AK
721 if (!info.exists)
722 return 1;
f4cbeaf0 723
c1f50521 724 if (info.open_count && (lv->status & VISIBLE_LV)) {
5f4b2acf 725 log_error("LV %s/%s in use: not deactivating", lv->vg->name,
0cf96f33
AK
726 lv->name);
727 return 0;
728 }
729
15d91f5a
AK
730#ifdef DMEVENTD
731 _register_dev(cmd, lv, 0);
732#endif
733
914c9723
AK
734 memlock_inc();
735 r = _lv_deactivate(lv);
736 memlock_dec();
737 fs_unlock();
738
739 return r;
f4cbeaf0
AK
740}
741
658b5812
AK
742/* Test if LV passes filter */
743int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
744 int *activate_lv)
745{
746 struct logical_volume *lv;
747
748 if (!activation())
749 goto activate;
750
7a593325 751 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
658b5812
AK
752 return 0;
753
754 if (!_passes_activation_filter(cmd, lv)) {
755 log_verbose("Not activating %s/%s due to config file settings",
756 lv->vg->name, lv->name);
757 *activate_lv = 0;
758 return 1;
759 }
760
761 activate:
762 *activate_lv = 1;
763 return 1;
764}
765
07d31831
AK
766static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
767 int exclusive, int filter)
f4cbeaf0
AK
768{
769 struct logical_volume *lv;
199e490e 770 struct lvinfo info;
914c9723 771 int r;
f4cbeaf0 772
d1d9800e
AK
773 if (!activation())
774 return 1;
775
7a593325 776 if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
f4cbeaf0
AK
777 return 0;
778
658b5812 779 if (filter && !_passes_activation_filter(cmd, lv)) {
de17d760
AK
780 log_verbose("Not activating %s/%s due to config file settings",
781 lv->vg->name, lv->name);
782 return 0;
783 }
784
20c5fcf7
AK
785 if (test_mode()) {
786 _skip("Activating '%s'.", lv->name);
711f7fc6 787 return 1;
20c5fcf7
AK
788 }
789
5f4b2acf
AK
790 if (!lv_info(cmd, lv, &info, 0))
791 return_0;
8c013da4 792
5f4b2acf 793 if (info.exists && !info.suspended && info.live_table)
914c9723 794 return 1;
f4cbeaf0 795
07d31831
AK
796 if (exclusive)
797 lv->status |= ACTIVATE_EXCL;
798
914c9723 799 memlock_inc();
658b5812 800 r = _lv_activate_lv(lv);
914c9723
AK
801 memlock_dec();
802 fs_unlock();
803
15d91f5a
AK
804#ifdef DMEVENTD
805 _register_dev(cmd, lv, 1);
806#endif
807
914c9723 808 return r;
f4cbeaf0 809}
199e490e 810
658b5812 811/* Activate LV */
07d31831 812int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive)
658b5812 813{
07d31831 814 return _lv_activate(cmd, lvid_s, exclusive, 0);
658b5812
AK
815}
816
817/* Activate LV only if it passes filter */
07d31831 818int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive)
658b5812 819{
07d31831 820 return _lv_activate(cmd, lvid_s, exclusive, 1);
658b5812
AK
821}
822
f7dd6d84
AK
823int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
824{
825 struct lvinfo info;
826 int r = 1;
827
8b076648 828 if (!lv) {
2262b320 829 r = dm_mknodes(NULL);
8b076648
AK
830 fs_unlock();
831 return r;
832 }
833
5f4b2acf
AK
834 if (!_lv_info(cmd, lv, 1, &info, 0))
835 return_0;
f7dd6d84
AK
836
837 if (info.exists)
f09fe0ad 838 r = dev_manager_lv_mknodes(lv);
f7dd6d84 839 else
f09fe0ad 840 r = dev_manager_lv_rmnodes(lv);
f7dd6d84
AK
841
842 fs_unlock();
843
844 return r;
845}
846
352a99b9
AK
847/*
848 * Does PV use VG somewhere in its construction?
849 * Returns 1 on failure.
850 */
851int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
852 struct volume_group *vg)
853{
854 struct dev_manager *dm;
855 int r;
856
857 if (!activation())
858 return 0;
859
860 if (!dm_is_dm_major(MAJOR(pv->dev->dev)))
861 return 0;
862
863 if (!(dm = dev_manager_create(cmd, vg->name))) {
864 stack;
865 return 1;
866 }
867
868 r = dev_manager_device_uses_vg(dm, pv->dev, vg);
869
870 dev_manager_destroy(dm);
871
872 return r;
873}
874
914c9723
AK
875void activation_exit(void)
876{
877 dev_manager_exit();
878}
199e490e 879#endif
This page took 0.139464 seconds and 5 git commands to generate.