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