]> sourceware.org Git - lvm2.git/blob - tools/lvchange.c
thin: tighten discard string conversions
[lvm2.git] / tools / lvchange.c
1 /*
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
4 *
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 Lesser General Public License v.2.1.
10 *
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
14 */
15
16 #include "tools.h"
17
18 static int lvchange_permission(struct cmd_context *cmd,
19 struct logical_volume *lv)
20 {
21 uint32_t lv_access;
22 struct lvinfo info;
23 int r = 0;
24
25 lv_access = arg_uint_value(cmd, permission_ARG, 0);
26
27 if ((lv_access & LVM_WRITE) && (lv->status & LVM_WRITE)) {
28 log_error("Logical volume \"%s\" is already writable",
29 lv->name);
30 return 0;
31 }
32
33 if (!(lv_access & LVM_WRITE) && !(lv->status & LVM_WRITE)) {
34 log_error("Logical volume \"%s\" is already read only",
35 lv->name);
36 return 0;
37 }
38
39 if ((lv->status & MIRRORED) && (vg_is_clustered(lv->vg)) &&
40 lv_info(cmd, lv, 0, &info, 0, 0) && info.exists) {
41 log_error("Cannot change permissions of mirror \"%s\" "
42 "while active.", lv->name);
43 return 0;
44 }
45
46 /* Not allowed to change permissions on RAID sub-LVs directly */
47 if ((lv->status & RAID_META) || (lv->status & RAID_IMAGE)) {
48 log_error("Cannot change permissions of RAID %s \"%s\"",
49 (lv->status & RAID_IMAGE) ? "image" :
50 "metadata area", lv->name);
51 return 0;
52 }
53
54 if (lv_access & LVM_WRITE) {
55 lv->status |= LVM_WRITE;
56 log_verbose("Setting logical volume \"%s\" read/write",
57 lv->name);
58 } else {
59 lv->status &= ~LVM_WRITE;
60 log_verbose("Setting logical volume \"%s\" read-only",
61 lv->name);
62 }
63
64 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
65 if (!vg_write(lv->vg))
66 return_0;
67
68 if (!suspend_lv(cmd, lv)) {
69 log_error("Failed to lock %s", lv->name);
70 vg_revert(lv->vg);
71 goto out;
72 }
73
74 if (!vg_commit(lv->vg)) {
75 if (!resume_lv(cmd, lv))
76 stack;
77 goto_out;
78 }
79
80 log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
81 if (!resume_lv(cmd, lv)) {
82 log_error("Problem reactivating %s", lv->name);
83 goto out;
84 }
85
86 r = 1;
87 out:
88 backup(lv->vg);
89 return r;
90 }
91
92 static int lvchange_pool_update(struct cmd_context *cmd,
93 struct logical_volume *lv)
94 {
95 int r = 0;
96 int update = 0;
97 unsigned val;
98 thin_discard_t discard;
99
100 if (!lv_is_thin_pool(lv)) {
101 log_error("Logical volume \"%s\" is not a thinpool.", lv->name);
102 return 0;
103 }
104
105 if (arg_count(cmd, discard_ARG)) {
106 discard = arg_uint_value(cmd, discard_ARG, 0);
107 if (discard != first_seg(lv)->discard) {
108 if (((discard == THIN_DISCARD_IGNORE) ||
109 (first_seg(lv)->discard == THIN_DISCARD_IGNORE)) &&
110 lv_is_active(lv))
111 log_error("Cannot change discard state for active "
112 "logical volume \"%s\".", lv->name);
113 else {
114 first_seg(lv)->discard = discard;
115 update++;
116 }
117 } else
118 log_error("Logical volume \"%s\" already uses discard %s.",
119 lv->name, get_pool_discard_name(discard));
120 }
121
122 if (arg_count(cmd, zero_ARG)) {
123 val = arg_uint_value(cmd, zero_ARG, 1);
124 if (val != first_seg(lv)->zero_new_blocks) {
125 first_seg(lv)->zero_new_blocks = val;
126 update++;
127 } else
128 log_error("Logical volume \"%s\" already %szero new blocks.",
129 lv->name, val ? "" : "does not ");
130 }
131
132 if (!update)
133 return 0;
134
135 log_very_verbose("Updating logical volume \"%s\" on disk(s).", lv->name);
136 if (!vg_write(lv->vg))
137 return_0;
138
139 if (!suspend_lv_origin(cmd, lv)) {
140 log_error("Failed to update active %s/%s (deactivation is needed).",
141 lv->vg->name, lv->name);
142 vg_revert(lv->vg);
143 goto out;
144 }
145
146 if (!vg_commit(lv->vg)) {
147 if (!resume_lv_origin(cmd, lv))
148 stack;
149 goto_out;
150 }
151
152 if (!resume_lv_origin(cmd, lv)) {
153 log_error("Problem reactivating %s.", lv->name);
154 goto out;
155 }
156
157 r = 1;
158 out:
159 backup(lv->vg);
160 return r;
161 }
162
163 static int lvchange_monitoring(struct cmd_context *cmd,
164 struct logical_volume *lv)
165 {
166 struct lvinfo info;
167
168 if (!lv_info(cmd, lv, lv_is_thin_pool(lv) ? 1 : 0,
169 &info, 0, 0) || !info.exists) {
170 log_error("Logical volume, %s, is not active", lv->name);
171 return 0;
172 }
173
174 /* do not monitor pvmove lv's */
175 if (lv->status & PVMOVE)
176 return 1;
177
178 if ((dmeventd_monitor_mode() != DMEVENTD_MONITOR_IGNORE) &&
179 !monitor_dev_for_events(cmd, lv, 0, dmeventd_monitor_mode()))
180 return_0;
181
182 return 1;
183 }
184
185 static int lvchange_background_polling(struct cmd_context *cmd,
186 struct logical_volume *lv)
187 {
188 struct lvinfo info;
189
190 if (!lv_info(cmd, lv, 0, &info, 0, 0) || !info.exists) {
191 log_error("Logical volume, %s, is not active", lv->name);
192 return 0;
193 }
194
195 if (background_polling())
196 lv_spawn_background_polling(cmd, lv);
197
198 return 1;
199 }
200
201 static int _lvchange_activate(struct cmd_context *cmd, struct logical_volume *lv)
202 {
203 int activate;
204
205 activate = arg_uint_value(cmd, activate_ARG, 0);
206
207 if (lv_is_cow(lv) && !lv_is_virtual_origin(origin_from_cow(lv)))
208 lv = origin_from_cow(lv);
209
210 if (activate == CHANGE_AAY) {
211 if (!lv_passes_auto_activation_filter(cmd, lv))
212 return 1;
213 activate = CHANGE_ALY;
214 }
215
216 if (activate == CHANGE_ALN) {
217 log_verbose("Deactivating logical volume \"%s\" locally",
218 lv->name);
219 if (!deactivate_lv_local(cmd, lv))
220 return_0;
221 } else if (activate == CHANGE_AN) {
222 log_verbose("Deactivating logical volume \"%s\"", lv->name);
223 if (!deactivate_lv(cmd, lv))
224 return_0;
225 } else {
226 if ((activate == CHANGE_AE) ||
227 lv_is_origin(lv) ||
228 lv_is_thin_type(lv)) {
229 log_verbose("Activating logical volume \"%s\" "
230 "exclusively", lv->name);
231 if (!activate_lv_excl(cmd, lv))
232 return_0;
233 } else if (activate == CHANGE_ALY) {
234 log_verbose("Activating logical volume \"%s\" locally",
235 lv->name);
236 if (!activate_lv_local(cmd, lv))
237 return_0;
238 } else {
239 log_verbose("Activating logical volume \"%s\"",
240 lv->name);
241 if (!activate_lv(cmd, lv))
242 return_0;
243 }
244
245 if (background_polling())
246 lv_spawn_background_polling(cmd, lv);
247 }
248
249 return 1;
250 }
251
252 static int lvchange_refresh(struct cmd_context *cmd, struct logical_volume *lv)
253 {
254 log_verbose("Refreshing logical volume \"%s\" (if active)", lv->name);
255
256 return lv_refresh(cmd, lv);
257 }
258
259 static int lvchange_resync(struct cmd_context *cmd,
260 struct logical_volume *lv)
261 {
262 int active = 0;
263 int monitored;
264 struct lvinfo info;
265 struct logical_volume *log_lv;
266
267 if (!(lv->status & MIRRORED)) {
268 log_error("Unable to resync %s because it is not mirrored.",
269 lv->name);
270 return 1;
271 }
272
273 if (lv->status & PVMOVE) {
274 log_error("Unable to resync pvmove volume %s", lv->name);
275 return 0;
276 }
277
278 if (lv->status & LOCKED) {
279 log_error("Unable to resync locked volume %s", lv->name);
280 return 0;
281 }
282
283 if (lv_info(cmd, lv, 0, &info, 1, 0)) {
284 if (info.open_count) {
285 log_error("Can't resync open logical volume \"%s\"",
286 lv->name);
287 return 0;
288 }
289
290 if (info.exists) {
291 if (!arg_count(cmd, yes_ARG) &&
292 yes_no_prompt("Do you really want to deactivate "
293 "logical volume %s to resync it? [y/n]: ",
294 lv->name) == 'n') {
295 log_error("Logical volume \"%s\" not resynced",
296 lv->name);
297 return 0;
298 }
299
300 if (sigint_caught())
301 return 0;
302
303 active = 1;
304 }
305 }
306
307 /* Activate exclusively to ensure no nodes still have LV active */
308 monitored = dmeventd_monitor_mode();
309 init_dmeventd_monitor(0);
310
311 if (!deactivate_lv(cmd, lv)) {
312 log_error("Unable to deactivate %s for resync", lv->name);
313 return 0;
314 }
315
316 if (vg_is_clustered(lv->vg) && lv_is_active(lv)) {
317 log_error("Can't get exclusive access to clustered volume %s",
318 lv->name);
319 return 0;
320 }
321
322 init_dmeventd_monitor(monitored);
323
324 log_lv = first_seg(lv)->log_lv;
325
326 log_very_verbose("Starting resync of %s%s%s mirror \"%s\"",
327 (active) ? "active " : "",
328 vg_is_clustered(lv->vg) ? "clustered " : "",
329 (log_lv) ? "disk-logged" : "core-logged",
330 lv->name);
331
332 /*
333 * If this mirror has a core log (i.e. !log_lv),
334 * then simply deactivating/activating will cause
335 * it to reset the sync status. We only need to
336 * worry about persistent logs.
337 */
338 if (!log_lv && !(lv->status & LV_NOTSYNCED)) {
339 if (active && !activate_lv(cmd, lv)) {
340 log_error("Failed to reactivate %s to resynchronize "
341 "mirror", lv->name);
342 return 0;
343 }
344 return 1;
345 }
346
347 lv->status &= ~LV_NOTSYNCED;
348
349 if (log_lv) {
350 /* Separate mirror log so we can clear it */
351 detach_mirror_log(first_seg(lv));
352
353 if (!vg_write(lv->vg)) {
354 log_error("Failed to write intermediate VG metadata.");
355 if (!attach_mirror_log(first_seg(lv), log_lv))
356 stack;
357 if (active && !activate_lv(cmd, lv))
358 stack;
359 return 0;
360 }
361
362 if (!vg_commit(lv->vg)) {
363 log_error("Failed to commit intermediate VG metadata.");
364 if (!attach_mirror_log(first_seg(lv), log_lv))
365 stack;
366 if (active && !activate_lv(cmd, lv))
367 stack;
368 return 0;
369 }
370
371 backup(lv->vg);
372
373 if (!activate_lv(cmd, log_lv)) {
374 log_error("Unable to activate %s for mirror log resync",
375 log_lv->name);
376 return 0;
377 }
378
379 log_very_verbose("Clearing log device %s", log_lv->name);
380 if (!set_lv(cmd, log_lv, log_lv->size, 0)) {
381 log_error("Unable to reset sync status for %s", lv->name);
382 if (!deactivate_lv(cmd, log_lv))
383 log_error("Failed to deactivate log LV after "
384 "wiping failed");
385 return 0;
386 }
387
388 if (!deactivate_lv(cmd, log_lv)) {
389 log_error("Unable to deactivate log LV %s after wiping "
390 "for resync", log_lv->name);
391 return 0;
392 }
393
394 /* Put mirror log back in place */
395 if (!attach_mirror_log(first_seg(lv), log_lv))
396 stack;
397 }
398
399 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
400 if (!vg_write(lv->vg) || !vg_commit(lv->vg)) {
401 log_error("Failed to update metadata on disk.");
402 return 0;
403 }
404
405 if (active && !activate_lv(cmd, lv)) {
406 log_error("Failed to reactivate %s after resync", lv->name);
407 return 0;
408 }
409
410 return 1;
411 }
412
413 static int lvchange_alloc(struct cmd_context *cmd, struct logical_volume *lv)
414 {
415 int want_contiguous = 0;
416 alloc_policy_t alloc;
417
418 want_contiguous = strcmp(arg_str_value(cmd, contiguous_ARG, "n"), "n");
419 alloc = want_contiguous ? ALLOC_CONTIGUOUS : ALLOC_INHERIT;
420 alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, alloc);
421
422 if (alloc == lv->alloc) {
423 log_error("Allocation policy of logical volume \"%s\" is "
424 "already %s", lv->name, get_alloc_string(alloc));
425 return 0;
426 }
427
428 lv->alloc = alloc;
429
430 /* FIXME If contiguous, check existing extents already are */
431
432 log_verbose("Setting contiguous allocation policy for \"%s\" to %s",
433 lv->name, get_alloc_string(alloc));
434
435 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
436
437 /* No need to suspend LV for this change */
438 if (!vg_write(lv->vg) || !vg_commit(lv->vg))
439 return_0;
440
441 backup(lv->vg);
442
443 return 1;
444 }
445
446 static int lvchange_readahead(struct cmd_context *cmd,
447 struct logical_volume *lv)
448 {
449 unsigned read_ahead = 0;
450 unsigned pagesize = (unsigned) lvm_getpagesize() >> SECTOR_SHIFT;
451 int r = 0;
452
453 read_ahead = arg_uint_value(cmd, readahead_ARG, 0);
454
455 if (read_ahead != DM_READ_AHEAD_AUTO &&
456 (lv->vg->fid->fmt->features & FMT_RESTRICTED_READAHEAD) &&
457 (read_ahead < 2 || read_ahead > 120)) {
458 log_error("Metadata only supports readahead values between 2 and 120.");
459 return 0;
460 }
461
462 if (read_ahead != DM_READ_AHEAD_AUTO &&
463 read_ahead != DM_READ_AHEAD_NONE && read_ahead % pagesize) {
464 if (read_ahead < pagesize)
465 read_ahead = pagesize;
466 else
467 read_ahead = (read_ahead / pagesize) * pagesize;
468 log_warn("WARNING: Overriding readahead to %u sectors, a multiple "
469 "of %uK page size.", read_ahead, pagesize >> 1);
470 }
471
472 if (lv->read_ahead == read_ahead) {
473 if (read_ahead == DM_READ_AHEAD_AUTO)
474 log_error("Read ahead is already auto for \"%s\"", lv->name);
475 else
476 log_error("Read ahead is already %u for \"%s\"",
477 read_ahead, lv->name);
478 return 0;
479 }
480
481 lv->read_ahead = read_ahead;
482
483 log_verbose("Setting read ahead to %u for \"%s\"", read_ahead,
484 lv->name);
485
486 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
487 if (!vg_write(lv->vg))
488 return_0;
489
490 if (!suspend_lv(cmd, lv)) {
491 log_error("Failed to lock %s", lv->name);
492 vg_revert(lv->vg);
493 goto out;
494 }
495
496 if (!vg_commit(lv->vg)) {
497 if (!resume_lv(cmd, lv))
498 stack;
499 goto_out;
500 }
501
502 log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
503 if (!resume_lv(cmd, lv)) {
504 log_error("Problem reactivating %s", lv->name);
505 goto out;
506 }
507
508 r = 1;
509 out:
510 backup(lv->vg);
511 return r;
512 }
513
514 static int lvchange_persistent(struct cmd_context *cmd,
515 struct logical_volume *lv)
516 {
517 struct lvinfo info;
518 int active = 0;
519 int32_t major, minor;
520
521 if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) {
522 if (!(lv->status & FIXED_MINOR)) {
523 log_error("Minor number is already not persistent "
524 "for \"%s\"", lv->name);
525 return 0;
526 }
527 lv->status &= ~FIXED_MINOR;
528 lv->minor = -1;
529 lv->major = -1;
530 log_verbose("Disabling persistent device number for \"%s\"",
531 lv->name);
532 } else {
533 if (!arg_count(cmd, minor_ARG) && lv->minor < 0) {
534 log_error("Minor number must be specified with -My");
535 return 0;
536 }
537 if (arg_count(cmd, major_ARG) > 1) {
538 log_error("Option -j/--major may not be repeated.");
539 return 0;
540 }
541 if (arg_count(cmd, minor_ARG) > 1) {
542 log_error("Option --minor may not be repeated.");
543 return 0;
544 }
545 if (!arg_count(cmd, major_ARG) && lv->major < 0) {
546 log_error("Major number must be specified with -My");
547 return 0;
548 }
549 if (lv_info(cmd, lv, 0, &info, 0, 0) && info.exists)
550 active = 1;
551
552 major = arg_int_value(cmd, major_ARG, lv->major);
553 minor = arg_int_value(cmd, minor_ARG, lv->minor);
554 if (!major_minor_valid(cmd, lv->vg->fid->fmt, major, minor))
555 return 0;
556
557 if (active && !arg_count(cmd, force_ARG) &&
558 yes_no_prompt("Logical volume %s will be "
559 "deactivated temporarily. "
560 "Continue? [y/n]: ", lv->name) == 'n') {
561 log_error("%s device number not changed.",
562 lv->name);
563 return 0;
564 }
565
566 if (sigint_caught())
567 return 0;
568
569 log_verbose("Ensuring %s is inactive.", lv->name);
570 if (!deactivate_lv(cmd, lv)) {
571 log_error("%s: deactivation failed", lv->name);
572 return 0;
573 }
574 lv->status |= FIXED_MINOR;
575 lv->minor = minor;
576 lv->major = major;
577 log_verbose("Setting persistent device number to (%d, %d) "
578 "for \"%s\"", lv->major, lv->minor, lv->name);
579
580 }
581
582 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
583 if (!vg_write(lv->vg) || !vg_commit(lv->vg))
584 return_0;
585
586 backup(lv->vg);
587
588 if (active) {
589 log_verbose("Re-activating logical volume \"%s\"", lv->name);
590 if (!activate_lv(cmd, lv)) {
591 log_error("%s: reactivation failed", lv->name);
592 return 0;
593 }
594 }
595
596 return 1;
597 }
598
599 static int lvchange_tag(struct cmd_context *cmd, struct logical_volume *lv, int arg)
600 {
601 if (!change_tag(cmd, NULL, lv, NULL, arg))
602 return_0;
603
604 log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
605
606 /* No need to suspend LV for this change */
607 if (!vg_write(lv->vg) || !vg_commit(lv->vg))
608 return_0;
609
610 backup(lv->vg);
611
612 return 1;
613 }
614
615 static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
616 void *handle __attribute__((unused)))
617 {
618 int doit = 0, docmds = 0;
619 int archived = 0;
620 struct logical_volume *origin;
621 char snaps_msg[128];
622
623 if (!(lv->vg->status & LVM_WRITE) &&
624 (arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
625 arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
626 arg_count(cmd, discard_ARG) ||
627 arg_count(cmd, zero_ARG) ||
628 arg_count(cmd, alloc_ARG))) {
629 log_error("Only -a permitted with read-only volume "
630 "group \"%s\"", lv->vg->name);
631 return EINVALID_CMD_LINE;
632 }
633
634 if (lv_is_origin(lv) &&
635 (arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
636 arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
637 arg_count(cmd, alloc_ARG))) {
638 log_error("Can't change logical volume \"%s\" under snapshot",
639 lv->name);
640 return ECMD_FAILED;
641 }
642
643 if (lv_is_cow(lv) && !lv_is_virtual_origin(origin = origin_from_cow(lv)) &&
644 arg_count(cmd, activate_ARG)) {
645 if (origin->origin_count < 2)
646 snaps_msg[0] = '\0';
647 else if (dm_snprintf(snaps_msg, sizeof(snaps_msg),
648 " and %u other snapshot(s)",
649 origin->origin_count - 1) < 0) {
650 log_error("Failed to prepare message.");
651 return ECMD_FAILED;
652 }
653
654 if (!arg_count(cmd, yes_ARG) &&
655 (yes_no_prompt("Change of snapshot %s will also change its"
656 " origin %s%s. Proceed? [y/n]: ", lv->name,
657 origin->name, snaps_msg) == 'n')) {
658 log_error("Logical volume %s not changed.", lv->name);
659 return ECMD_FAILED;
660 }
661 }
662
663 if (lv->status & PVMOVE) {
664 log_error("Unable to change pvmove LV %s", lv->name);
665 if (arg_count(cmd, activate_ARG))
666 log_error("Use 'pvmove --abort' to abandon a pvmove");
667 return ECMD_FAILED;
668 }
669
670 if (lv->status & MIRROR_LOG) {
671 log_error("Unable to change mirror log LV %s directly", lv->name);
672 return ECMD_FAILED;
673 }
674
675 if (lv->status & MIRROR_IMAGE) {
676 log_error("Unable to change mirror image LV %s directly",
677 lv->name);
678 return ECMD_FAILED;
679 }
680
681 /* If LV is sparse, activate origin instead */
682 if (arg_count(cmd, activate_ARG) && lv_is_cow(lv) &&
683 lv_is_virtual_origin(origin = origin_from_cow(lv)))
684 lv = origin;
685
686 if (!(lv_is_visible(lv)) && !lv_is_virtual_origin(lv)) {
687 log_error("Unable to change internal LV %s directly",
688 lv->name);
689 return ECMD_FAILED;
690 }
691
692 /*
693 * FIXME: DEFAULT_BACKGROUND_POLLING should be "unspecified".
694 * If --poll is explicitly provided use it; otherwise polling
695 * should only be started if the LV is not already active. So:
696 * 1) change the activation code to say if the LV was actually activated
697 * 2) make polling of an LV tightly coupled with LV activation
698 *
699 * Do not initiate any polling if --sysinit option is used.
700 */
701 init_background_polling(arg_count(cmd, sysinit_ARG) ? 0 :
702 arg_int_value(cmd, poll_ARG,
703 DEFAULT_BACKGROUND_POLLING));
704
705 /* access permission change */
706 if (arg_count(cmd, permission_ARG)) {
707 if (!archive(lv->vg)) {
708 stack;
709 return ECMD_FAILED;
710 }
711 archived = 1;
712 doit += lvchange_permission(cmd, lv);
713 docmds++;
714 }
715
716 /* allocation policy change */
717 if (arg_count(cmd, contiguous_ARG) || arg_count(cmd, alloc_ARG)) {
718 if (!archived && !archive(lv->vg)) {
719 stack;
720 return ECMD_FAILED;
721 }
722 archived = 1;
723 doit += lvchange_alloc(cmd, lv);
724 docmds++;
725 }
726
727 /* read ahead sector change */
728 if (arg_count(cmd, readahead_ARG)) {
729 if (!archived && !archive(lv->vg)) {
730 stack;
731 return ECMD_FAILED;
732 }
733 archived = 1;
734 doit += lvchange_readahead(cmd, lv);
735 docmds++;
736 }
737
738 /* persistent device number change */
739 if (arg_count(cmd, persistent_ARG)) {
740 if (!archived && !archive(lv->vg)) {
741 stack;
742 return ECMD_FAILED;
743 }
744 archived = 1;
745 doit += lvchange_persistent(cmd, lv);
746 docmds++;
747 if (sigint_caught()) {
748 stack;
749 return ECMD_FAILED;
750 }
751 }
752
753 if (arg_count(cmd, discard_ARG) ||
754 arg_count(cmd, zero_ARG)) {
755 if (!archived && !archive(lv->vg)) {
756 stack;
757 return ECMD_FAILED;
758 }
759 archived = 1;
760 doit += lvchange_pool_update(cmd, lv);
761 docmds++;
762 }
763
764 /* add tag */
765 if (arg_count(cmd, addtag_ARG)) {
766 if (!archived && !archive(lv->vg)) {
767 stack;
768 return ECMD_FAILED;
769 }
770 archived = 1;
771 doit += lvchange_tag(cmd, lv, addtag_ARG);
772 docmds++;
773 }
774
775 /* del tag */
776 if (arg_count(cmd, deltag_ARG)) {
777 if (!archived && !archive(lv->vg)) {
778 stack;
779 return ECMD_FAILED;
780 }
781 archived = 1;
782 doit += lvchange_tag(cmd, lv, deltag_ARG);
783 docmds++;
784 }
785
786 if (doit)
787 log_print("Logical volume \"%s\" changed", lv->name);
788
789 if (arg_count(cmd, resync_ARG))
790 if (!lvchange_resync(cmd, lv)) {
791 stack;
792 return ECMD_FAILED;
793 }
794
795 /* activation change */
796 if (arg_count(cmd, activate_ARG)) {
797 if (!_lvchange_activate(cmd, lv)) {
798 stack;
799 return ECMD_FAILED;
800 }
801 }
802
803 if (arg_count(cmd, refresh_ARG))
804 if (!lvchange_refresh(cmd, lv)) {
805 stack;
806 return ECMD_FAILED;
807 }
808
809 if (!arg_count(cmd, activate_ARG) &&
810 !arg_count(cmd, refresh_ARG) &&
811 arg_count(cmd, monitor_ARG)) {
812 if (!lvchange_monitoring(cmd, lv)) {
813 stack;
814 return ECMD_FAILED;
815 }
816 }
817
818 if (!arg_count(cmd, activate_ARG) &&
819 !arg_count(cmd, refresh_ARG) &&
820 arg_count(cmd, poll_ARG)) {
821 if (!lvchange_background_polling(cmd, lv)) {
822 stack;
823 return ECMD_FAILED;
824 }
825 }
826
827 if (doit != docmds) {
828 stack;
829 return ECMD_FAILED;
830 }
831
832 return ECMD_PROCESSED;
833 }
834
835 int lvchange(struct cmd_context *cmd, int argc, char **argv)
836 {
837 int update = /* options other than -a, --refresh, --monitor or --poll */
838 arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
839 arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
840 arg_count(cmd, addtag_ARG) || arg_count(cmd, deltag_ARG) ||
841 arg_count(cmd, resync_ARG) || arg_count(cmd, alloc_ARG) ||
842 arg_count(cmd, discard_ARG) ||
843 arg_count(cmd, zero_ARG);
844
845 if (!update &&
846 !arg_count(cmd, activate_ARG) && !arg_count(cmd, refresh_ARG) &&
847 !arg_count(cmd, monitor_ARG) && !arg_count(cmd, poll_ARG)) {
848 log_error("Need 1 or more of -a, -C, -M, -p, -r, "
849 "--resync, --refresh, --alloc, --addtag, --deltag, "
850 "--monitor or --poll");
851 return EINVALID_CMD_LINE;
852 }
853
854 if (arg_count(cmd, activate_ARG) && arg_count(cmd, refresh_ARG)) {
855 log_error("Only one of -a and --refresh permitted.");
856 return EINVALID_CMD_LINE;
857 }
858
859 if ((arg_count(cmd, ignorelockingfailure_ARG) ||
860 arg_count(cmd, sysinit_ARG)) && update) {
861 log_error("Only -a permitted with --ignorelockingfailure and --sysinit");
862 return EINVALID_CMD_LINE;
863 }
864
865 if (!update)
866 cmd->handles_missing_pvs = 1;
867
868 if (!argc) {
869 log_error("Please give logical volume path(s)");
870 return EINVALID_CMD_LINE;
871 }
872
873 if ((arg_count(cmd, minor_ARG) || arg_count(cmd, major_ARG)) &&
874 !arg_count(cmd, persistent_ARG)) {
875 log_error("--major and --minor require -My");
876 return EINVALID_CMD_LINE;
877 }
878
879 if (arg_count(cmd, minor_ARG) && argc != 1) {
880 log_error("Only give one logical volume when specifying minor");
881 return EINVALID_CMD_LINE;
882 }
883
884 if (arg_count(cmd, contiguous_ARG) && arg_count(cmd, alloc_ARG)) {
885 log_error("Only one of --alloc and --contiguous permitted");
886 return EINVALID_CMD_LINE;
887 }
888
889 if (arg_count(cmd, poll_ARG) && arg_count(cmd, sysinit_ARG)) {
890 log_error("Only one of --poll and --sysinit permitted");
891 return EINVALID_CMD_LINE;
892 }
893
894 if (arg_count(cmd, sysinit_ARG) && lvmetad_active() &&
895 arg_uint_value(cmd, activate_ARG, 0) == CHANGE_AAY) {
896 log_warn("lvmetad is active while using --sysinit -a ay, "
897 "skipping manual activation");
898 return ECMD_PROCESSED;
899 }
900
901 return process_each_lv(cmd, argc, argv,
902 update ? READ_FOR_UPDATE : 0, NULL,
903 &lvchange_single);
904 }
This page took 0.203238 seconds and 5 git commands to generate.