2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 struct lvresize_params
{
28 const struct segment_type
*segtype
;
34 percent_type_t percent
;
49 static int _validate_stripesize(struct cmd_context
*cmd
,
50 const struct volume_group
*vg
,
51 struct lvresize_params
*lp
)
53 if (arg_sign_value(cmd
, stripesize_ARG
, SIGN_NONE
) == SIGN_MINUS
) {
54 log_error("Stripesize may not be negative.");
58 if (arg_uint64_value(cmd
, stripesize_ARG
, 0) > STRIPE_SIZE_LIMIT
* 2) {
59 log_error("Stripe size cannot be larger than %s",
60 display_size(cmd
, (uint64_t) STRIPE_SIZE_LIMIT
));
64 if (!(vg
->fid
->fmt
->features
& FMT_SEGMENTS
))
65 log_warn("Varied stripesize not supported. Ignoring.");
66 else if (arg_uint_value(cmd
, stripesize_ARG
, 0) > (uint64_t) vg
->extent_size
* 2) {
67 log_error("Reducing stripe size %s to maximum, "
68 "physical extent size %s",
70 (uint64_t) arg_uint_value(cmd
, stripesize_ARG
, 0)),
71 display_size(cmd
, (uint64_t) vg
->extent_size
));
72 lp
->stripe_size
= vg
->extent_size
;
74 lp
->stripe_size
= arg_uint_value(cmd
, stripesize_ARG
, 0);
76 if (lp
->stripe_size
& (lp
->stripe_size
- 1)) {
77 log_error("Stripe size must be power of 2");
84 static int _request_confirmation(struct cmd_context
*cmd
,
85 const struct volume_group
*vg
,
86 const struct logical_volume
*lv
,
87 const struct lvresize_params
*lp
)
91 memset(&info
, 0, sizeof(info
));
93 if (!lv_info(cmd
, lv
, 0, &info
, 1, 0) && driver_version(NULL
, 0)) {
94 log_error("lv_info failed: aborting");
100 log_error("Logical volume %s must be activated "
101 "before resizing filesystem", lp
->lv_name
);
110 log_warn("WARNING: Reducing active%s logical volume to %s",
111 info
.open_count
? " and open" : "",
112 display_size(cmd
, (uint64_t) lp
->extents
* vg
->extent_size
));
114 log_warn("THIS MAY DESTROY YOUR DATA (filesystem etc.)");
116 if (!arg_count(cmd
, force_ARG
)) {
117 if (yes_no_prompt("Do you really want to reduce %s? [y/n]: ",
118 lp
->lv_name
) == 'n') {
119 log_error("Logical volume %s NOT reduced", lp
->lv_name
);
129 enum fsadm_cmd_e
{ FSADM_CMD_CHECK
, FSADM_CMD_RESIZE
};
130 #define FSADM_CMD "fsadm"
131 #define FSADM_CMD_MAX_ARGS 6
132 #define FSADM_CHECK_FAILS_FOR_MOUNTED 3 /* shell exist status code */
135 * FSADM_CMD --dry-run --verbose --force check lv_path
136 * FSADM_CMD --dry-run --verbose --force resize lv_path size
138 static int _fsadm_cmd(struct cmd_context
*cmd
,
139 const struct volume_group
*vg
,
140 const struct lvresize_params
*lp
,
141 enum fsadm_cmd_e fcmd
,
144 char lv_path
[PATH_MAX
];
145 char size_buf
[SIZE_BUF
];
146 const char *argv
[FSADM_CMD_MAX_ARGS
+ 2];
149 argv
[i
++] = FSADM_CMD
;
152 argv
[i
++] = "--dry-run";
154 if (verbose_level() >= _LOG_NOTICE
)
155 argv
[i
++] = "--verbose";
157 if (arg_count(cmd
, force_ARG
))
158 argv
[i
++] = "--force";
160 argv
[i
++] = (fcmd
== FSADM_CMD_RESIZE
) ? "resize" : "check";
165 if (dm_snprintf(lv_path
, PATH_MAX
, "%s%s/%s", cmd
->dev_dir
, lp
->vg_name
,
167 log_error("Couldn't create LV path for %s", lp
->lv_name
);
173 if (fcmd
== FSADM_CMD_RESIZE
) {
174 if (dm_snprintf(size_buf
, SIZE_BUF
, "%" PRIu64
"K",
175 (uint64_t) lp
->extents
* vg
->extent_size
/ 2) < 0) {
176 log_error("Couldn't generate new LV size string");
180 argv
[i
++] = size_buf
;
185 return exec_cmd(cmd
, argv
, status
, 1);
188 static int _lvresize_params(struct cmd_context
*cmd
, int argc
, char **argv
,
189 struct lvresize_params
*lp
)
191 const char *cmd_name
;
193 unsigned dev_dir_found
= 0;
194 int use_policy
= arg_count(cmd
, use_policies_ARG
);
196 lp
->sign
= SIGN_NONE
;
199 cmd_name
= command_name(cmd
);
200 if (!strcmp(cmd_name
, "lvreduce"))
201 lp
->resize
= LV_REDUCE
;
202 if (!strcmp(cmd_name
, "lvextend"))
203 lp
->resize
= LV_EXTEND
;
206 /* do nothing; _lvresize will handle --use-policies itself */
208 lp
->sign
= SIGN_PLUS
;
209 lp
->percent
= PERCENT_LV
;
212 * Allow omission of extents and size if the user has given us
213 * one or more PVs. Most likely, the intent was "resize this
214 * LV the best you can with these PVs"
216 if ((arg_count(cmd
, extents_ARG
) + arg_count(cmd
, size_ARG
) == 0) &&
219 lp
->percent
= PERCENT_PVS
;
220 lp
->sign
= SIGN_PLUS
;
221 } else if ((arg_count(cmd
, extents_ARG
) +
222 arg_count(cmd
, size_ARG
) != 1)) {
223 log_error("Please specify either size or extents but not "
228 if (arg_count(cmd
, extents_ARG
)) {
229 lp
->extents
= arg_uint_value(cmd
, extents_ARG
, 0);
230 lp
->sign
= arg_sign_value(cmd
, extents_ARG
, SIGN_NONE
);
231 lp
->percent
= arg_percent_value(cmd
, extents_ARG
, PERCENT_NONE
);
234 /* Size returned in kilobyte units; held in sectors */
235 if (arg_count(cmd
, size_ARG
)) {
236 lp
->size
= arg_uint64_value(cmd
, size_ARG
, 0);
237 lp
->sign
= arg_sign_value(cmd
, size_ARG
, SIGN_NONE
);
238 lp
->percent
= PERCENT_NONE
;
242 if (lp
->resize
== LV_EXTEND
&& lp
->sign
== SIGN_MINUS
) {
243 log_error("Negative argument not permitted - use lvreduce");
247 if (lp
->resize
== LV_REDUCE
&& lp
->sign
== SIGN_PLUS
) {
248 log_error("Positive sign not permitted - use lvextend");
252 lp
->resizefs
= arg_is_set(cmd
, resizefs_ARG
);
253 lp
->nofsck
= arg_is_set(cmd
, nofsck_ARG
);
256 log_error("Please provide the logical volume name");
260 lp
->lv_name
= argv
[0];
264 if (!(lp
->lv_name
= skip_dev_dir(cmd
, lp
->lv_name
, &dev_dir_found
)) ||
265 !(lp
->vg_name
= extract_vgname(cmd
, lp
->lv_name
))) {
266 log_error("Please provide a volume group name");
270 if (!validate_name(lp
->vg_name
)) {
271 log_error("Volume group name %s has invalid characters",
276 if ((st
= strrchr(lp
->lv_name
, '/')))
277 lp
->lv_name
= st
+ 1;
285 static int _adjust_policy_params(struct cmd_context
*cmd
,
286 struct logical_volume
*lv
, struct lvresize_params
*lp
)
289 int policy_threshold
, policy_amount
;
291 if (lv_is_thin_pool(lv
)) {
293 find_config_tree_int(cmd
, "activation/thin_pool_autoextend_threshold",
294 DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD
) * PERCENT_1
;
296 find_config_tree_int(cmd
, "activation/thin_pool_autoextend_percent",
297 DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT
);
300 find_config_tree_int(cmd
, "activation/snapshot_autoextend_threshold",
301 DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD
) * PERCENT_1
;
303 find_config_tree_int(cmd
, "activation/snapshot_autoextend_percent",
304 DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT
);
307 if (policy_threshold
>= PERCENT_100
)
308 return 1; /* nothing to do */
310 if (lv_is_thin_pool(lv
)) {
311 if (!lv_thin_pool_percent(lv
, 1, &percent
))
313 if (percent
> policy_threshold
) {
314 /* FIXME: metadata resize support missing */
315 log_error("Resize for %s/%s is not yet supported.",
316 lp
->vg_name
, lp
->lv_name
);
320 if (!lv_thin_pool_percent(lv
, 0, &percent
))
322 if (!(PERCENT_0
< percent
&& percent
<= PERCENT_100
) ||
323 percent
<= policy_threshold
)
324 return 1; /* nothing to do */
326 if (!lv_snapshot_percent(lv
, &percent
))
328 if (!(PERCENT_0
< percent
&& percent
< PERCENT_100
) || percent
<= policy_threshold
)
329 return 1; /* nothing to do */
332 lp
->extents
= policy_amount
;
337 static uint32_t lvseg_get_stripes(struct lv_segment
*seg
, uint32_t *stripesize
)
340 struct lv_segment
*seg_mirr
;
342 /* If segment mirrored, check if images are striped */
343 if (seg_is_mirrored(seg
))
344 for (s
= 0; s
< seg
->area_count
; s
++) {
345 if (seg_type(seg
, s
) != AREA_LV
)
347 seg_mirr
= first_seg(seg_lv(seg
, s
));
349 if (seg_is_striped(seg_mirr
)) {
356 if (seg_is_striped(seg
)) {
357 *stripesize
= seg
->stripe_size
;
358 return seg
->area_count
;
365 static int _lvresize(struct cmd_context
*cmd
, struct volume_group
*vg
,
366 struct lvresize_params
*lp
)
368 struct logical_volume
*lv
;
370 uint32_t stripesize_extents
;
371 uint32_t seg_stripes
= 0, seg_stripesize
= 0, seg_size
;
372 uint32_t seg_mirrors
= 0;
373 uint32_t extents_used
;
375 uint32_t pv_extent_count
;
376 alloc_policy_t alloc
;
377 struct logical_volume
*lock_lv
;
379 struct lv_segment
*seg
, *uninitialized_var(mirr_seg
);
380 uint32_t seg_extents
;
383 struct dm_list
*pvh
= NULL
;
384 int use_policy
= arg_count(cmd
, use_policies_ARG
);
387 if (!(lvl
= find_lv_in_vg(vg
, lp
->lv_name
))) {
388 log_error("Logical volume %s not found in volume group %s",
389 lp
->lv_name
, lp
->vg_name
);
393 if (lvl
->lv
->status
& (RAID_IMAGE
| RAID_META
)) {
394 log_error("Cannot resize a RAID %s directly",
395 (lvl
->lv
->status
& RAID_IMAGE
) ? "image" :
400 if (lv_is_raid_with_tracking(lvl
->lv
)) {
401 log_error("Cannot resize %s while it is tracking a split image",
406 if (arg_count(cmd
, stripes_ARG
)) {
407 if (vg
->fid
->fmt
->features
& FMT_SEGMENTS
)
408 lp
->stripes
= arg_uint_value(cmd
, stripes_ARG
, 1);
410 log_warn("Varied striping not supported. Ignoring.");
413 if (arg_count(cmd
, mirrors_ARG
)) {
414 if (vg
->fid
->fmt
->features
& FMT_SEGMENTS
)
415 lp
->mirrors
= arg_uint_value(cmd
, mirrors_ARG
, 1) + 1;
417 log_warn("Mirrors not supported. Ignoring.");
418 if (arg_sign_value(cmd
, mirrors_ARG
, SIGN_NONE
) == SIGN_MINUS
) {
419 log_error("Mirrors argument may not be negative");
420 return EINVALID_CMD_LINE
;
424 if (arg_count(cmd
, stripesize_ARG
) &&
425 !_validate_stripesize(cmd
, vg
, lp
))
426 return EINVALID_CMD_LINE
;
431 if (!lv_is_cow(lv
) &&
432 !lv_is_thin_pool(lv
)) {
433 log_error("Policy-based resize is supported only for snapshot and thin pool volumes.");
436 if (!_adjust_policy_params(cmd
, lv
, lp
))
440 if (!lv_is_visible(lv
)) {
441 log_error("Can't resize internal logical volume %s", lv
->name
);
445 if (lv
->status
& LOCKED
) {
446 log_error("Can't resize locked LV %s", lv
->name
);
450 if (lv
->status
& CONVERTING
) {
451 log_error("Can't resize %s while lvconvert in progress", lv
->name
);
455 alloc
= (alloc_policy_t
) arg_uint_value(cmd
, alloc_ARG
, lv
->alloc
);
458 * First adjust to an exact multiple of extent size.
459 * When extending by a relative amount we round that amount up.
460 * When reducing by a relative amount we remove at most that amount.
461 * When changing to an absolute size, we round that size up.
464 if (lp
->size
% vg
->extent_size
) {
465 if (lp
->sign
== SIGN_MINUS
)
466 lp
->size
-= lp
->size
% vg
->extent_size
;
468 lp
->size
+= vg
->extent_size
-
469 (lp
->size
% vg
->extent_size
);
471 log_print("Rounding size to boundary between physical extents: %s",
472 display_size(cmd
, lp
->size
));
475 lp
->extents
= lp
->size
/ vg
->extent_size
;
478 if (!(pvh
= lp
->argc
? create_pv_list(cmd
->mem
, vg
, lp
->argc
,
479 lp
->argv
, 1) : &vg
->pvs
)) {
484 switch(lp
->percent
) {
486 lp
->extents
= percent_of_extents(lp
->extents
, vg
->extent_count
,
487 (lp
->sign
!= SIGN_MINUS
));
490 lp
->extents
= percent_of_extents(lp
->extents
, vg
->free_count
,
491 (lp
->sign
!= SIGN_MINUS
));
494 lp
->extents
= percent_of_extents(lp
->extents
, lv
->le_count
,
495 (lp
->sign
!= SIGN_MINUS
));
499 pv_extent_count
= pv_list_extents_free(pvh
);
500 lp
->extents
= percent_of_extents(lp
->extents
, pv_extent_count
,
501 (lp
->sign
!= SIGN_MINUS
));
503 lp
->extents
= percent_of_extents(lp
->extents
, vg
->extent_count
,
504 (lp
->sign
!= SIGN_MINUS
));
507 if (!lv_is_cow(lv
)) {
508 log_error("Specified LV does not have an origin LV.");
509 return EINVALID_CMD_LINE
;
511 lp
->extents
= percent_of_extents(lp
->extents
, origin_from_cow(lv
)->le_count
,
512 (lp
->sign
!= SIGN_MINUS
));
518 if (lp
->sign
== SIGN_PLUS
) {
519 if (lp
->extents
>= (MAX_EXTENT_COUNT
- lv
->le_count
)) {
520 log_error("Unable to extend %s by %u extents, exceeds limit (%u).",
521 lp
->lv_name
, lv
->le_count
, MAX_EXTENT_COUNT
);
522 return EINVALID_CMD_LINE
;
524 lp
->extents
+= lv
->le_count
;
527 if (lp
->sign
== SIGN_MINUS
) {
528 if (lp
->extents
>= lv
->le_count
) {
529 log_error("Unable to reduce %s below 1 extent",
531 return EINVALID_CMD_LINE
;
534 lp
->extents
= lv
->le_count
- lp
->extents
;
538 log_error("New size of 0 not permitted");
539 return EINVALID_CMD_LINE
;
542 if (lp
->extents
== lv
->le_count
) {
544 return ECMD_PROCESSED
; /* Nothing to do. */
546 log_error("New size (%d extents) matches existing size "
547 "(%d extents)", lp
->extents
, lv
->le_count
);
548 return EINVALID_CMD_LINE
;
550 lp
->resize
= LV_EXTEND
; /* lets pretend zero size extension */
553 seg_size
= lp
->extents
- lv
->le_count
;
555 /* Use segment type of last segment */
556 dm_list_iterate_items(seg
, &lv
->segments
) {
557 lp
->segtype
= seg
->segtype
;
560 /* FIXME Support LVs with mixed segment types */
561 if (lp
->segtype
!= get_segtype_from_string(cmd
, arg_str_value(cmd
, type_ARG
,
562 lp
->segtype
->name
))) {
563 log_error("VolumeType does not match (%s)", lp
->segtype
->name
);
564 return EINVALID_CMD_LINE
;
567 /* If extending, find mirrors of last segment */
568 if ((lp
->extents
> lv
->le_count
)) {
570 * Has the user specified that they would like the additional
571 * extents of a mirror not to have an initial sync?
573 if (seg_is_mirrored(first_seg(lv
)) && arg_count(cmd
, nosync_ARG
))
574 lv
->status
|= LV_NOTSYNCED
;
576 dm_list_iterate_back_items(mirr_seg
, &lv
->segments
) {
577 if (seg_is_mirrored(mirr_seg
))
578 seg_mirrors
= lv_mirror_count(mirr_seg
->lv
);
583 if (!arg_count(cmd
, mirrors_ARG
) && seg_mirrors
) {
584 log_print("Extending %" PRIu32
" mirror images.",
586 lp
->mirrors
= seg_mirrors
;
588 if ((arg_count(cmd
, mirrors_ARG
) || seg_mirrors
) &&
589 (lp
->mirrors
!= seg_mirrors
)) {
590 log_error("Cannot vary number of mirrors in LV yet.");
591 return EINVALID_CMD_LINE
;
595 /* If extending, find stripes, stripesize & size of last segment */
596 if ((lp
->extents
> lv
->le_count
) &&
597 !(lp
->stripes
== 1 || (lp
->stripes
> 1 && lp
->stripe_size
))) {
598 /* FIXME Don't assume mirror seg will always be AREA_LV */
599 /* FIXME We will need to support resize for metadata LV as well,
600 * and data LV could be any type (i.e. mirror)) */
601 dm_list_iterate_items(seg
, seg_mirrors
? &seg_lv(mirr_seg
, 0)->segments
:
602 lv_is_thin_pool(lv
) ? &seg_lv(first_seg(lv
), 0)->segments
: &lv
->segments
) {
603 if (!seg_is_striped(seg
))
606 sz
= seg
->stripe_size
;
607 str
= seg
->area_count
;
609 if ((seg_stripesize
&& seg_stripesize
!= sz
&&
610 sz
&& !lp
->stripe_size
) ||
611 (seg_stripes
&& seg_stripes
!= str
&& !lp
->stripes
)) {
612 log_error("Please specify number of "
613 "stripes (-i) and stripesize (-I)");
614 return EINVALID_CMD_LINE
;
622 lp
->stripes
= seg_stripes
;
624 if (!lp
->stripe_size
&& lp
->stripes
> 1) {
625 if (seg_stripesize
) {
626 log_print("Using stripesize of last segment %s",
627 display_size(cmd
, (uint64_t) seg_stripesize
));
628 lp
->stripe_size
= seg_stripesize
;
631 find_config_tree_int(cmd
,
632 "metadata/stripesize",
633 DEFAULT_STRIPESIZE
) * 2;
634 log_print("Using default stripesize %s",
635 display_size(cmd
, (uint64_t) lp
->stripe_size
));
640 /* If reducing, find stripes, stripesize & size of last segment */
641 if (lp
->extents
< lv
->le_count
) {
644 if (lp
->stripes
|| lp
->stripe_size
|| lp
->mirrors
)
645 log_error("Ignoring stripes, stripesize and mirrors "
646 "arguments when reducing");
648 dm_list_iterate_items(seg
, &lv
->segments
) {
649 seg_extents
= seg
->len
;
651 /* Check for underlying stripe sizes */
652 seg_stripes
= lvseg_get_stripes(seg
, &seg_stripesize
);
654 if (seg_is_mirrored(seg
))
655 seg_mirrors
= lv_mirror_count(seg
->lv
);
659 if (lp
->extents
<= extents_used
+ seg_extents
)
662 extents_used
+= seg_extents
;
665 seg_size
= lp
->extents
- extents_used
;
666 lp
->stripe_size
= seg_stripesize
;
667 lp
->stripes
= seg_stripes
;
668 lp
->mirrors
= seg_mirrors
;
671 if (lp
->stripes
> 1 && !lp
->stripe_size
) {
672 log_error("Stripesize for striped segment should not be 0!");
673 return EINVALID_CMD_LINE
;
676 if (lp
->stripes
> 1) {
677 if (lp
->stripe_size
< STRIPE_SIZE_MIN
) {
678 log_error("Invalid stripe size %s",
679 display_size(cmd
, (uint64_t) lp
->stripe_size
));
680 return EINVALID_CMD_LINE
;
683 if (!(stripesize_extents
= lp
->stripe_size
/ vg
->extent_size
))
684 stripesize_extents
= 1;
686 size_rest
= seg_size
% (lp
->stripes
* stripesize_extents
);
687 /* Round toward the original size. */
689 ((lp
->extents
< lv
->le_count
) ||
691 (vg
->free_count
>= (lp
->extents
- lv
->le_count
- size_rest
+
692 (lp
->stripes
* stripesize_extents
))))) {
693 log_print("Rounding size (%d extents) up to stripe "
694 "boundary size for segment (%d extents)",
695 lp
->extents
, lp
->extents
- size_rest
+
696 (lp
->stripes
* stripesize_extents
));
697 lp
->extents
= lp
->extents
- size_rest
+
698 (lp
->stripes
* stripesize_extents
);
699 } else if (size_rest
) {
700 log_print("Rounding size (%d extents) down to stripe "
701 "boundary size for segment (%d extents)",
702 lp
->extents
, lp
->extents
- size_rest
);
703 lp
->extents
= lp
->extents
- size_rest
;
707 if (lp
->extents
< lv
->le_count
) {
708 if (lp
->resize
== LV_EXTEND
) {
709 log_error("New size given (%d extents) not larger "
710 "than existing size (%d extents)",
711 lp
->extents
, lv
->le_count
);
712 return EINVALID_CMD_LINE
;
714 lp
->resize
= LV_REDUCE
;
715 } else if (lp
->extents
> lv
->le_count
) {
716 if (lp
->resize
== LV_REDUCE
) {
717 log_error("New size given (%d extents) not less than "
718 "existing size (%d extents)", lp
->extents
,
720 return EINVALID_CMD_LINE
;
722 lp
->resize
= LV_EXTEND
;
723 } else if (lp
->extents
== lv
->le_count
) {
725 return ECMD_PROCESSED
; /* Nothing to do. */
727 log_error("New size (%d extents) matches existing size "
728 "(%d extents)", lp
->extents
, lv
->le_count
);
729 return EINVALID_CMD_LINE
;
731 lp
->resize
= LV_EXTEND
;
734 if (lv_is_origin(lv
)) {
735 if (lp
->resize
== LV_REDUCE
) {
736 log_error("Snapshot origin volumes cannot be reduced "
741 memset(&info
, 0, sizeof(info
));
743 if (lv_info(cmd
, lv
, 0, &info
, 0, 0) && info
.exists
) {
744 log_error("Snapshot origin volumes can be resized "
745 "only while inactive: try lvchange -an");
750 if (lv_is_thin_pool(lv
)) {
751 if (lp
->resize
== LV_REDUCE
) {
752 log_error("Thin pool volumes cannot be reduced in size yet.");
757 log_warn("Thin pool volumes do not have filesystem.");
762 if ((lp
->resize
== LV_REDUCE
) && lp
->argc
)
763 log_warn("Ignoring PVs on command line when reducing");
765 /* Request confirmation before operations that are often mistakes. */
766 if ((lp
->resizefs
|| (lp
->resize
== LV_REDUCE
)) &&
767 !_request_confirmation(cmd
, vg
, lv
, lp
)) {
774 !_fsadm_cmd(cmd
, vg
, lp
, FSADM_CMD_CHECK
, &status
)) {
775 if (status
!= FSADM_CHECK_FAILS_FOR_MOUNTED
) {
776 log_error("Filesystem check failed.");
779 /* some filesystems supports online resize */
782 if ((lp
->resize
== LV_REDUCE
) &&
783 !_fsadm_cmd(cmd
, vg
, lp
, FSADM_CMD_RESIZE
, NULL
)) {
784 log_error("Filesystem resize failed.");
794 log_print("%sing logical volume %s to %s",
795 (lp
->resize
== LV_REDUCE
) ? "Reduc" : "Extend",
797 display_size(cmd
, (uint64_t) lp
->extents
* vg
->extent_size
));
799 if (lp
->resize
== LV_REDUCE
) {
800 if (!lv_reduce(lv
, lv
->le_count
- lp
->extents
)) {
804 } else if ((lp
->extents
> lv
->le_count
) && /* Ensure we extend */
805 !lv_extend(lv
, lp
->segtype
,
806 lp
->stripes
, lp
->stripe_size
,
807 lp
->mirrors
, first_seg(lv
)->region_size
,
808 lp
->extents
- lv
->le_count
, NULL
,
814 /* store vg on disk(s) */
820 /* If snapshot, must suspend all associated devices */
822 lock_lv
= origin_from_cow(lv
);
826 if (!suspend_lv(cmd
, lock_lv
)) {
827 log_error("Failed to suspend %s", lp
->lv_name
);
833 if (!vg_commit(vg
)) {
835 if (!resume_lv(cmd
, lock_lv
))
841 if (!resume_lv(cmd
, lock_lv
)) {
842 log_error("Problem reactivating %s", lp
->lv_name
);
850 * Update lvm pool metadata (drop messages) if the pool has been
851 * resumed and do a pool active/deactivate in other case.
853 * Note: Active thin pool can be waiting for resize.
855 * FIXME: Activate only when thin volume is active
857 if (lv_is_thin_pool(lv
) &&
858 !update_pool_lv(lv
, !lv_is_active(lv
))) {
863 log_print("Logical volume %s successfully resized", lp
->lv_name
);
865 if (lp
->resizefs
&& (lp
->resize
== LV_EXTEND
) &&
866 !_fsadm_cmd(cmd
, vg
, lp
, FSADM_CMD_RESIZE
, NULL
)) {
871 return ECMD_PROCESSED
;
874 int lvresize(struct cmd_context
*cmd
, int argc
, char **argv
)
876 struct lvresize_params lp
;
877 struct volume_group
*vg
;
880 memset(&lp
, 0, sizeof(lp
));
882 if (!_lvresize_params(cmd
, argc
, argv
, &lp
))
883 return EINVALID_CMD_LINE
;
885 log_verbose("Finding volume group %s", lp
.vg_name
);
886 vg
= vg_read_for_update(cmd
, lp
.vg_name
, NULL
, 0);
887 if (vg_read_error(vg
)) {
893 if (!(r
= _lvresize(cmd
, vg
, &lp
)))
896 unlock_and_release_vg(cmd
, vg
, lp
.vg_name
);