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