2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2011 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
, 0) == 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) > 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";
162 if (dm_snprintf(lv_path
, PATH_MAX
, "%s%s/%s", cmd
->dev_dir
, lp
->vg_name
,
164 log_error("Couldn't create LV path for %s", lp
->lv_name
);
170 if (fcmd
== FSADM_CMD_RESIZE
) {
171 if (dm_snprintf(size_buf
, SIZE_BUF
, "%" PRIu64
"K",
172 (uint64_t) lp
->extents
* vg
->extent_size
/ 2) < 0) {
173 log_error("Couldn't generate new LV size string");
177 argv
[i
++] = size_buf
;
182 return exec_cmd(cmd
, argv
, status
, 1);
185 static int _lvresize_params(struct cmd_context
*cmd
, int argc
, char **argv
,
186 struct lvresize_params
*lp
)
188 const char *cmd_name
;
190 unsigned dev_dir_found
= 0;
191 int use_policy
= arg_count(cmd
, use_policies_ARG
);
193 lp
->sign
= SIGN_NONE
;
196 cmd_name
= command_name(cmd
);
197 if (!strcmp(cmd_name
, "lvreduce"))
198 lp
->resize
= LV_REDUCE
;
199 if (!strcmp(cmd_name
, "lvextend"))
200 lp
->resize
= LV_EXTEND
;
203 /* do nothing; _lvresize will handle --use-policies itself */
205 lp
->sign
= SIGN_PLUS
;
206 lp
->percent
= PERCENT_LV
;
209 * Allow omission of extents and size if the user has given us
210 * one or more PVs. Most likely, the intent was "resize this
211 * LV the best you can with these PVs"
213 if ((arg_count(cmd
, extents_ARG
) + arg_count(cmd
, size_ARG
) == 0) &&
216 lp
->percent
= PERCENT_PVS
;
217 lp
->sign
= SIGN_PLUS
;
218 } else if ((arg_count(cmd
, extents_ARG
) +
219 arg_count(cmd
, size_ARG
) != 1)) {
220 log_error("Please specify either size or extents but not "
225 if (arg_count(cmd
, extents_ARG
)) {
226 lp
->extents
= arg_uint_value(cmd
, extents_ARG
, 0);
227 lp
->sign
= arg_sign_value(cmd
, extents_ARG
, SIGN_NONE
);
228 lp
->percent
= arg_percent_value(cmd
, extents_ARG
, PERCENT_NONE
);
231 /* Size returned in kilobyte units; held in sectors */
232 if (arg_count(cmd
, size_ARG
)) {
233 lp
->size
= arg_uint64_value(cmd
, size_ARG
, 0);
234 lp
->sign
= arg_sign_value(cmd
, size_ARG
, SIGN_NONE
);
235 lp
->percent
= PERCENT_NONE
;
239 if (lp
->resize
== LV_EXTEND
&& lp
->sign
== SIGN_MINUS
) {
240 log_error("Negative argument not permitted - use lvreduce");
244 if (lp
->resize
== LV_REDUCE
&& lp
->sign
== SIGN_PLUS
) {
245 log_error("Positive sign not permitted - use lvextend");
249 lp
->resizefs
= arg_is_set(cmd
, resizefs_ARG
);
250 lp
->nofsck
= arg_is_set(cmd
, nofsck_ARG
);
253 log_error("Please provide the logical volume name");
257 lp
->lv_name
= argv
[0];
261 if (!(lp
->lv_name
= skip_dev_dir(cmd
, lp
->lv_name
, &dev_dir_found
)) ||
262 !(lp
->vg_name
= extract_vgname(cmd
, lp
->lv_name
))) {
263 log_error("Please provide a volume group name");
267 if (!validate_name(lp
->vg_name
)) {
268 log_error("Volume group name %s has invalid characters",
273 if ((st
= strrchr(lp
->lv_name
, '/')))
274 lp
->lv_name
= st
+ 1;
282 static int _adjust_policy_params(struct cmd_context
*cmd
,
283 struct logical_volume
*lv
, struct lvresize_params
*lp
)
286 int policy_threshold
, policy_amount
;
288 if (lv_is_thin_pool(lv
)) {
290 find_config_tree_int(cmd
, "activation/thin_pool_autoextend_threshold",
291 DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD
) * PERCENT_1
;
293 find_config_tree_int(cmd
, "activation/thin_pool_autoextend_percent",
294 DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT
);
297 find_config_tree_int(cmd
, "activation/snapshot_autoextend_threshold",
298 DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD
) * PERCENT_1
;
300 find_config_tree_int(cmd
, "activation/snapshot_autoextend_percent",
301 DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT
);
304 if (policy_threshold
>= PERCENT_100
)
305 return 1; /* nothing to do */
307 if (lv_is_thin_pool(lv
)) {
308 if (!lv_thin_pool_percent(lv
, &percent
))
310 if (!(PERCENT_0
< percent
&& percent
<= PERCENT_100
) ||
311 percent
<= policy_threshold
)
312 return 1; /* nothing to do */
314 if (!lv_snapshot_percent(lv
, &percent
))
316 if (!(PERCENT_0
< percent
&& percent
< PERCENT_100
) || percent
<= policy_threshold
)
317 return 1; /* nothing to do */
320 lp
->extents
= policy_amount
;
325 static uint32_t lvseg_get_stripes(struct lv_segment
*seg
, uint32_t *stripesize
)
328 struct lv_segment
*seg_mirr
;
330 /* If segment mirrored, check if images are striped */
331 if (seg_is_mirrored(seg
))
332 for (s
= 0; s
< seg
->area_count
; s
++) {
333 if (seg_type(seg
, s
) != AREA_LV
)
335 seg_mirr
= first_seg(seg_lv(seg
, s
));
337 if (seg_is_striped(seg_mirr
)) {
344 if (seg_is_striped(seg
)) {
345 *stripesize
= seg
->stripe_size
;
346 return seg
->area_count
;
353 static int _lvresize(struct cmd_context
*cmd
, struct volume_group
*vg
,
354 struct lvresize_params
*lp
)
356 struct logical_volume
*lv
;
358 uint32_t stripesize_extents
= 0;
359 uint32_t seg_stripes
= 0, seg_stripesize
= 0, seg_size
= 0;
360 uint32_t seg_mirrors
= 0;
361 uint32_t extents_used
= 0;
363 uint32_t pv_extent_count
= 0;
364 alloc_policy_t alloc
;
365 struct logical_volume
*lock_lv
;
367 struct lv_segment
*seg
, *uninitialized_var(mirr_seg
);
368 uint32_t seg_extents
;
371 struct dm_list
*pvh
= NULL
;
372 int use_policy
= arg_count(cmd
, use_policies_ARG
);
375 if (!(lvl
= find_lv_in_vg(vg
, lp
->lv_name
))) {
376 log_error("Logical volume %s not found in volume group %s",
377 lp
->lv_name
, lp
->vg_name
);
381 if (lvl
->lv
->status
& (RAID_IMAGE
| RAID_META
)) {
382 log_error("Cannot resize a RAID %s directly",
383 (lvl
->lv
->status
& RAID_IMAGE
) ? "image" :
388 if (lv_is_raid_with_tracking(lvl
->lv
)) {
389 log_error("Cannot resize %s while it is tracking a split image",
394 if (arg_count(cmd
, stripes_ARG
)) {
395 if (vg
->fid
->fmt
->features
& FMT_SEGMENTS
)
396 lp
->stripes
= arg_uint_value(cmd
, stripes_ARG
, 1);
398 log_warn("Varied striping not supported. Ignoring.");
401 if (arg_count(cmd
, mirrors_ARG
)) {
402 if (vg
->fid
->fmt
->features
& FMT_SEGMENTS
)
403 lp
->mirrors
= arg_uint_value(cmd
, mirrors_ARG
, 1) + 1;
405 log_warn("Mirrors not supported. Ignoring.");
406 if (arg_sign_value(cmd
, mirrors_ARG
, 0) == SIGN_MINUS
) {
407 log_error("Mirrors argument may not be negative");
408 return EINVALID_CMD_LINE
;
412 if (arg_count(cmd
, stripesize_ARG
) &&
413 !_validate_stripesize(cmd
, vg
, lp
))
414 return EINVALID_CMD_LINE
;
419 if (!lv_is_cow(lv
) &&
420 !lv_is_thin_pool(lv
)) {
421 log_error("Policy-based resize is supported only for snapshot and thin pool volumes.");
424 _adjust_policy_params(cmd
, lv
, lp
);
427 if (!lv_is_visible(lv
)) {
428 log_error("Can't resize internal logical volume %s", lv
->name
);
432 if (lv
->status
& LOCKED
) {
433 log_error("Can't resize locked LV %s", lv
->name
);
437 if (lv
->status
& CONVERTING
) {
438 log_error("Can't resize %s while lvconvert in progress", lv
->name
);
442 alloc
= arg_uint_value(cmd
, alloc_ARG
, lv
->alloc
);
445 if (lp
->size
% vg
->extent_size
) {
446 if (lp
->sign
== SIGN_MINUS
)
447 lp
->size
-= lp
->size
% vg
->extent_size
;
449 lp
->size
+= vg
->extent_size
-
450 (lp
->size
% vg
->extent_size
);
452 log_print("Rounding up size to full physical extent %s",
453 display_size(cmd
, (uint64_t) lp
->size
));
456 lp
->extents
= lp
->size
/ vg
->extent_size
;
459 if (!(pvh
= lp
->argc
? create_pv_list(cmd
->mem
, vg
, lp
->argc
,
460 lp
->argv
, 1) : &vg
->pvs
)) {
465 switch(lp
->percent
) {
467 lp
->extents
= percent_of_extents(lp
->extents
, vg
->extent_count
);
470 lp
->extents
= percent_of_extents(lp
->extents
, vg
->free_count
);
473 lp
->extents
= percent_of_extents(lp
->extents
, lv
->le_count
);
477 pv_extent_count
= pv_list_extents_free(pvh
);
478 lp
->extents
= percent_of_extents(lp
->extents
, pv_extent_count
);
480 lp
->extents
= percent_of_extents(lp
->extents
, vg
->extent_count
);
483 if (!lv_is_cow(lv
)) {
484 log_error("Specified LV does not have an origin LV.");
485 return EINVALID_CMD_LINE
;
487 lp
->extents
= percent_of_extents(lp
->extents
, origin_from_cow(lv
)->le_count
);
493 if (lp
->sign
== SIGN_PLUS
) {
494 if (lp
->extents
>= (MAX_EXTENT_COUNT
- lv
->le_count
)) {
495 log_error("Unable to extend %s by %u extents, exceeds limit (%u).",
496 lp
->lv_name
, lv
->le_count
, MAX_EXTENT_COUNT
);
497 return EINVALID_CMD_LINE
;
499 lp
->extents
+= lv
->le_count
;
502 if (lp
->sign
== SIGN_MINUS
) {
503 if (lp
->extents
>= lv
->le_count
) {
504 log_error("Unable to reduce %s below 1 extent",
506 return EINVALID_CMD_LINE
;
509 lp
->extents
= lv
->le_count
- lp
->extents
;
513 log_error("New size of 0 not permitted");
514 return EINVALID_CMD_LINE
;
517 if (lp
->extents
== lv
->le_count
) {
519 return ECMD_PROCESSED
; /* Nothing to do. */
521 log_error("New size (%d extents) matches existing size "
522 "(%d extents)", lp
->extents
, lv
->le_count
);
523 return EINVALID_CMD_LINE
;
525 lp
->resize
= LV_EXTEND
; /* lets pretend zero size extension */
528 seg_size
= lp
->extents
- lv
->le_count
;
530 /* Use segment type of last segment */
531 dm_list_iterate_items(seg
, &lv
->segments
) {
532 lp
->segtype
= seg
->segtype
;
535 /* FIXME Support LVs with mixed segment types */
536 if (lp
->segtype
!= get_segtype_from_string(cmd
, arg_str_value(cmd
, type_ARG
,
537 lp
->segtype
->name
))) {
538 log_error("VolumeType does not match (%s)", lp
->segtype
->name
);
539 return EINVALID_CMD_LINE
;
542 /* If extending, find mirrors of last segment */
543 if ((lp
->extents
> lv
->le_count
)) {
545 * Has the user specified that they would like the additional
546 * extents of a mirror not to have an initial sync?
548 if (seg_is_mirrored(first_seg(lv
)) && arg_count(cmd
, nosync_ARG
))
549 lv
->status
|= LV_NOTSYNCED
;
551 dm_list_iterate_back_items(mirr_seg
, &lv
->segments
) {
552 if (seg_is_mirrored(mirr_seg
))
553 seg_mirrors
= lv_mirror_count(mirr_seg
->lv
);
558 if (!arg_count(cmd
, mirrors_ARG
) && seg_mirrors
) {
559 log_print("Extending %" PRIu32
" mirror images.",
561 lp
->mirrors
= seg_mirrors
;
563 if ((arg_count(cmd
, mirrors_ARG
) || seg_mirrors
) &&
564 (lp
->mirrors
!= seg_mirrors
)) {
565 log_error("Cannot vary number of mirrors in LV yet.");
566 return EINVALID_CMD_LINE
;
570 /* If extending, find stripes, stripesize & size of last segment */
571 if ((lp
->extents
> lv
->le_count
) &&
572 !(lp
->stripes
== 1 || (lp
->stripes
> 1 && lp
->stripe_size
))) {
573 /* FIXME Don't assume mirror seg will always be AREA_LV */
574 dm_list_iterate_items(seg
, seg_mirrors
? &seg_lv(mirr_seg
, 0)->segments
: &lv
->segments
) {
575 if (!seg_is_striped(seg
))
578 sz
= seg
->stripe_size
;
579 str
= seg
->area_count
;
581 if ((seg_stripesize
&& seg_stripesize
!= sz
&&
582 sz
&& !lp
->stripe_size
) ||
583 (seg_stripes
&& seg_stripes
!= str
&& !lp
->stripes
)) {
584 log_error("Please specify number of "
585 "stripes (-i) and stripesize (-I)");
586 return EINVALID_CMD_LINE
;
594 lp
->stripes
= seg_stripes
;
596 if (!lp
->stripe_size
&& lp
->stripes
> 1) {
597 if (seg_stripesize
) {
598 log_print("Using stripesize of last segment %s",
599 display_size(cmd
, (uint64_t) seg_stripesize
));
600 lp
->stripe_size
= seg_stripesize
;
603 find_config_tree_int(cmd
,
604 "metadata/stripesize",
605 DEFAULT_STRIPESIZE
) * 2;
606 log_print("Using default stripesize %s",
607 display_size(cmd
, (uint64_t) lp
->stripe_size
));
612 /* If reducing, find stripes, stripesize & size of last segment */
613 if (lp
->extents
< lv
->le_count
) {
616 if (lp
->stripes
|| lp
->stripe_size
|| lp
->mirrors
)
617 log_error("Ignoring stripes, stripesize and mirrors "
618 "arguments when reducing");
620 dm_list_iterate_items(seg
, &lv
->segments
) {
621 seg_extents
= seg
->len
;
623 /* Check for underlying stripe sizes */
624 seg_stripes
= lvseg_get_stripes(seg
, &seg_stripesize
);
626 if (seg_is_mirrored(seg
))
627 seg_mirrors
= lv_mirror_count(seg
->lv
);
631 if (lp
->extents
<= extents_used
+ seg_extents
)
634 extents_used
+= seg_extents
;
637 seg_size
= lp
->extents
- extents_used
;
638 lp
->stripe_size
= seg_stripesize
;
639 lp
->stripes
= seg_stripes
;
640 lp
->mirrors
= seg_mirrors
;
643 if (lp
->stripes
> 1 && !lp
->stripe_size
) {
644 log_error("Stripesize for striped segment should not be 0!");
645 return EINVALID_CMD_LINE
;
648 if (lp
->stripes
> 1) {
649 if (!(stripesize_extents
= lp
->stripe_size
/ vg
->extent_size
))
650 stripesize_extents
= 1;
652 size_rest
= seg_size
% (lp
->stripes
* stripesize_extents
);
653 /* Round toward the original size. */
654 if (size_rest
&& lp
->extents
< lv
->le_count
) {
655 log_print("Rounding size (%d extents) up to stripe "
656 "boundary size for segment (%d extents)",
657 lp
->extents
, lp
->extents
- size_rest
+
658 (lp
->stripes
* stripesize_extents
));
659 lp
->extents
= lp
->extents
- size_rest
+
660 (lp
->stripes
* stripesize_extents
);
661 } else if (size_rest
) {
662 log_print("Rounding size (%d extents) down to stripe "
663 "boundary size for segment (%d extents)",
664 lp
->extents
, lp
->extents
- size_rest
);
665 lp
->extents
= lp
->extents
- size_rest
;
668 if (lp
->stripe_size
< STRIPE_SIZE_MIN
) {
669 log_error("Invalid stripe size %s",
670 display_size(cmd
, (uint64_t) lp
->stripe_size
));
671 return EINVALID_CMD_LINE
;
675 if (lp
->extents
< lv
->le_count
) {
676 if (lp
->resize
== LV_EXTEND
) {
677 log_error("New size given (%d extents) not larger "
678 "than existing size (%d extents)",
679 lp
->extents
, lv
->le_count
);
680 return EINVALID_CMD_LINE
;
682 lp
->resize
= LV_REDUCE
;
683 } else if (lp
->extents
> lv
->le_count
) {
684 if (lp
->resize
== LV_REDUCE
) {
685 log_error("New size given (%d extents) not less than "
686 "existing size (%d extents)", lp
->extents
,
688 return EINVALID_CMD_LINE
;
690 lp
->resize
= LV_EXTEND
;
693 if (lv_is_origin(lv
)) {
694 if (lp
->resize
== LV_REDUCE
) {
695 log_error("Snapshot origin volumes cannot be reduced "
700 memset(&info
, 0, sizeof(info
));
702 if (lv_info(cmd
, lv
, 0, &info
, 0, 0) && info
.exists
) {
703 log_error("Snapshot origin volumes can be resized "
704 "only while inactive: try lvchange -an");
709 if (lv_is_thin_pool(lv
)) {
710 if (lp
->resize
== LV_REDUCE
) {
711 log_error("Thin pool volumes cannot be reduced in size yet.");
716 log_warn("Thin pool volumes do not have filesystem.");
721 /* Try to use the same strip settings for underlying pool data LV */
722 lp
->stripes
= last_seg(seg_lv(first_seg(lv
), 0))->area_count
;
723 if (!lp
->stripe_size
)
724 lp
->stripe_size
= last_seg(seg_lv(first_seg(lv
), 0))->stripe_size
;
728 if ((lp
->resize
== LV_REDUCE
) && lp
->argc
)
729 log_warn("Ignoring PVs on command line when reducing");
731 /* Request confirmation before operations that are often mistakes. */
732 if ((lp
->resizefs
|| (lp
->resize
== LV_REDUCE
)) &&
733 !_request_confirmation(cmd
, vg
, lv
, lp
)) {
740 !_fsadm_cmd(cmd
, vg
, lp
, FSADM_CMD_CHECK
, &status
)) {
741 if (status
!= FSADM_CHECK_FAILS_FOR_MOUNTED
) {
742 log_error("Filesystem check failed.");
745 /* some filesystems supports online resize */
748 if ((lp
->resize
== LV_REDUCE
) &&
749 !_fsadm_cmd(cmd
, vg
, lp
, FSADM_CMD_RESIZE
, NULL
)) {
750 log_error("Filesystem resize failed.");
760 log_print("%sing logical volume %s to %s",
761 (lp
->resize
== LV_REDUCE
) ? "Reduc" : "Extend",
763 display_size(cmd
, (uint64_t) lp
->extents
* vg
->extent_size
));
765 if (lp
->resize
== LV_REDUCE
) {
766 if (!lv_reduce(lv
, lv
->le_count
- lp
->extents
)) {
770 } else if ((lp
->extents
> lv
->le_count
) && /* Ensure we extend */
771 !lv_extend(lv
, lp
->segtype
,
772 lp
->stripes
, lp
->stripe_size
,
773 lp
->mirrors
, first_seg(lv
)->region_size
,
774 lp
->extents
- lv
->le_count
, NULL
,
780 /* store vg on disk(s) */
786 /* If snapshot, must suspend all associated devices */
788 lock_lv
= origin_from_cow(lv
);
792 if (!suspend_lv(cmd
, lock_lv
)) {
793 log_error("Failed to suspend %s", lp
->lv_name
);
799 if (!vg_commit(vg
)) {
801 if (!resume_lv(cmd
, lock_lv
))
807 if (!resume_lv(cmd
, lock_lv
)) {
808 log_error("Problem reactivating %s", lp
->lv_name
);
816 * Update lvm pool metadata (drop messages) if the pool has been
817 * resumed and do a pool active/deactivate in other case.
819 * Note: Active thin pool can be waiting for resize.
821 * FIXME: Activate only when thin volume is active
823 if (lv_is_thin_pool(lv
) &&
824 !update_pool_lv(lv
, !lv_is_active(lv
))) {
829 log_print("Logical volume %s successfully resized", lp
->lv_name
);
831 if (lp
->resizefs
&& (lp
->resize
== LV_EXTEND
) &&
832 !_fsadm_cmd(cmd
, vg
, lp
, FSADM_CMD_RESIZE
, NULL
)) {
837 return ECMD_PROCESSED
;
840 int lvresize(struct cmd_context
*cmd
, int argc
, char **argv
)
842 struct lvresize_params lp
;
843 struct volume_group
*vg
;
846 memset(&lp
, 0, sizeof(lp
));
848 if (!_lvresize_params(cmd
, argc
, argv
, &lp
))
849 return EINVALID_CMD_LINE
;
851 log_verbose("Finding volume group %s", lp
.vg_name
);
852 vg
= vg_read_for_update(cmd
, lp
.vg_name
, NULL
, 0);
853 if (vg_read_error(vg
)) {
859 if (!(r
= _lvresize(cmd
, vg
, &lp
)))
862 unlock_and_release_vg(cmd
, vg
, lp
.vg_name
);