]> sourceware.org Git - lvm2.git/blame - tools/lvresize.c
Make warnings go to stderr. Adds log_warn macro for that purpose,
[lvm2.git] / tools / lvresize.c
CommitLineData
03a8a07d 1/*
1832f310 2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
6606c3ae 3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
03a8a07d 4 *
6606c3ae 5 * This file is part of LVM2.
03a8a07d 6 *
6606c3ae
AK
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 General Public License v.2.
03a8a07d
AK
10 *
11 * You should have received a copy of the GNU General Public License
6606c3ae
AK
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
03a8a07d
AK
14 */
15
16#include "tools.h"
17
1a9ea74d
AK
18#define SIZE_BUF 128
19
241913fe 20struct lvresize_params {
8ef2b021 21 const char *vg_name;
241913fe
AK
22 const char *lv_name;
23
24 uint32_t stripes;
25 uint32_t stripe_size;
ffb0e538 26 uint32_t mirrors;
241913fe 27
72b2cb61 28 const struct segment_type *segtype;
241913fe 29
241913fe
AK
30 /* size */
31 uint32_t extents;
32 uint64_t size;
33 sign_t sign;
34fadac4 34 percent_t percent;
03a8a07d
AK
35
36 enum {
37 LV_ANY = 0,
38 LV_REDUCE = 1,
39 LV_EXTEND = 2
241913fe
AK
40 } resize;
41
1a9ea74d
AK
42 int resizefs;
43 int nofsck;
44
241913fe
AK
45 int argc;
46 char **argv;
47};
48
8a2fc586
AK
49static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
50 struct lvresize_params *lp)
241913fe
AK
51{
52 const char *cmd_name;
53 char *st;
54
55 lp->sign = SIGN_NONE;
56 lp->resize = LV_ANY;
03a8a07d 57
60274aba 58 cmd_name = command_name(cmd);
03a8a07d 59 if (!strcmp(cmd_name, "lvreduce"))
241913fe 60 lp->resize = LV_REDUCE;
03a8a07d 61 if (!strcmp(cmd_name, "lvextend"))
241913fe 62 lp->resize = LV_EXTEND;
03a8a07d 63
6fda126d 64 if (arg_count(cmd, extents_ARG) + arg_count(cmd, size_ARG) != 1) {
03a8a07d 65 log_error("Please specify either size or extents (not both)");
241913fe 66 return 0;
03a8a07d
AK
67 }
68
6fda126d 69 if (arg_count(cmd, extents_ARG)) {
241913fe
AK
70 lp->extents = arg_uint_value(cmd, extents_ARG, 0);
71 lp->sign = arg_sign_value(cmd, extents_ARG, SIGN_NONE);
34fadac4 72 lp->percent = arg_percent_value(cmd, extents_ARG, PERCENT_NONE);
03a8a07d
AK
73 }
74
1832f310 75 /* Size returned in kilobyte units; held in sectors */
6fda126d 76 if (arg_count(cmd, size_ARG)) {
241913fe
AK
77 lp->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)) * 2;
78 lp->sign = arg_sign_value(cmd, size_ARG, SIGN_NONE);
34fadac4 79 lp->percent = PERCENT_NONE;
03a8a07d
AK
80 }
81
241913fe 82 if (lp->resize == LV_EXTEND && lp->sign == SIGN_MINUS) {
03a8a07d 83 log_error("Negative argument not permitted - use lvreduce");
241913fe 84 return 0;
03a8a07d
AK
85 }
86
241913fe 87 if (lp->resize == LV_REDUCE && lp->sign == SIGN_PLUS) {
03a8a07d 88 log_error("Positive sign not permitted - use lvextend");
241913fe 89 return 0;
03a8a07d
AK
90 }
91
1a9ea74d
AK
92 lp->resizefs = arg_count(cmd, resizefs_ARG) ? 1 : 0;
93 lp->nofsck = arg_count(cmd, nofsck_ARG) ? 1 : 0;
94
03a8a07d
AK
95 if (!argc) {
96 log_error("Please provide the logical volume name");
241913fe 97 return 0;
03a8a07d
AK
98 }
99
241913fe 100 lp->lv_name = argv[0];
03a8a07d
AK
101 argv++;
102 argc--;
103
241913fe 104 if (!(lp->vg_name = extract_vgname(cmd, lp->lv_name))) {
03a8a07d 105 log_error("Please provide a volume group name");
241913fe 106 return 0;
03a8a07d
AK
107 }
108
241913fe
AK
109 if ((st = strrchr(lp->lv_name, '/')))
110 lp->lv_name = st + 1;
03a8a07d 111
241913fe
AK
112 lp->argc = argc;
113 lp->argv = argv;
114
115 return 1;
116}
7d0e6e80 117
241913fe
AK
118static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
119{
120 struct volume_group *vg;
121 struct logical_volume *lv;
241913fe
AK
122 struct lvinfo info;
123 uint32_t stripesize_extents = 0;
124 uint32_t seg_stripes = 0, seg_stripesize = 0, seg_size = 0;
ffb0e538 125 uint32_t seg_mirrors = 0;
241913fe
AK
126 uint32_t extents_used = 0;
127 uint32_t size_rest;
a0a23eff 128 alloc_policy_t alloc;
0fb173aa 129 struct logical_volume *lock_lv;
241913fe
AK
130 struct lv_list *lvl;
131 int consistent = 1;
132 struct lv_segment *seg;
133 uint32_t seg_extents;
134 uint32_t sz, str;
7f0dc9c4 135 struct list *pvh = NULL;
1a9ea74d
AK
136 char size_buf[SIZE_BUF];
137 char lv_path[PATH_MAX];
241913fe 138
a5fe5a7c 139 if (!(vg = vg_read(cmd, lp->vg_name, NULL, &consistent))) {
241913fe 140 log_error("Volume group %s doesn't exist", lp->vg_name);
7f0dc9c4 141 return ECMD_FAILED;
03a8a07d
AK
142 }
143
c221b0bc 144 if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
dc4d7417 145 return ECMD_FAILED;
f53c6aa6 146
03a8a07d 147 /* does LV exist? */
241913fe 148 if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) {
03a8a07d 149 log_error("Logical volume %s not found in volume group %s",
241913fe 150 lp->lv_name, lp->vg_name);
7f0dc9c4 151 return ECMD_FAILED;
03a8a07d
AK
152 }
153
25b73380
AK
154 if (arg_count(cmd, stripes_ARG)) {
155 if (vg->fid->fmt->features & FMT_SEGMENTS)
241913fe 156 lp->stripes = arg_uint_value(cmd, stripes_ARG, 1);
25b73380
AK
157 else
158 log_print("Varied striping not supported. Ignoring.");
159 }
160
ffb0e538
AK
161 if (arg_count(cmd, mirrors_ARG)) {
162 if (vg->fid->fmt->features & FMT_SEGMENTS)
163 lp->mirrors = arg_uint_value(cmd, mirrors_ARG, 1) + 1;
164 else
165 log_print("Mirrors not supported. Ignoring.");
7424de5b
AK
166 if (arg_sign_value(cmd, mirrors_ARG, 0) == SIGN_MINUS) {
167 log_error("Mirrors argument may not be negative");
168 return 0;
169 }
ffb0e538
AK
170 }
171
25b73380 172 if (arg_count(cmd, stripesize_ARG)) {
fdd4f3c0
AK
173 if (arg_sign_value(cmd, stripesize_ARG, 0) == SIGN_MINUS) {
174 log_error("Stripesize may not be negative.");
7f0dc9c4 175 return ECMD_FAILED;
fdd4f3c0 176 }
12de747d
AK
177
178 if (arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT) {
179 log_error("Stripe size cannot be larger than %s",
72b2cb61 180 display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT));
12de747d
AK
181 return 0;
182 }
183
184 if (!(vg->fid->fmt->features & FMT_SEGMENTS))
185 log_print("Varied stripesize not supported. Ignoring.");
186 else if (arg_uint_value(cmd, stripesize_ARG, 0) > vg->extent_size) {
187 log_error("Reducing stripe size %s to maximum, "
188 "physical extent size %s",
189 display_size(cmd,
72b2cb61
AK
190 (uint64_t) arg_uint_value(cmd, stripesize_ARG, 0) * 2),
191 display_size(cmd, (uint64_t) vg->extent_size));
12de747d
AK
192 lp->stripe_size = vg->extent_size;
193 } else
241913fe
AK
194 lp->stripe_size = 2 * arg_uint_value(cmd,
195 stripesize_ARG, 0);
12de747d 196
ffb0e538
AK
197 if (lp->mirrors) {
198 log_error("Mirrors and striping cannot be combined yet.");
199 return ECMD_FAILED;
200 }
12de747d
AK
201 if (lp->stripe_size & (lp->stripe_size - 1)) {
202 log_error("Stripe size must be power of 2");
203 return 0;
204 }
25b73380
AK
205 }
206
f868d635 207 lv = lvl->lv;
03a8a07d 208
6e03b44c
AK
209 if (lv->status & LOCKED) {
210 log_error("Can't resize locked LV %s", lv->name);
7f0dc9c4 211 return ECMD_FAILED;
6e03b44c
AK
212 }
213
72b2cb61 214 alloc = arg_uint_value(cmd, alloc_ARG, lv->alloc);
7f0dc9c4 215
241913fe
AK
216 if (lp->size) {
217 if (lp->size % vg->extent_size) {
218 if (lp->sign == SIGN_MINUS)
219 lp->size -= lp->size % vg->extent_size;
03a8a07d 220 else
241913fe
AK
221 lp->size += vg->extent_size -
222 (lp->size % vg->extent_size);
03a8a07d
AK
223
224 log_print("Rounding up size to full physical extent %s",
72b2cb61 225 display_size(cmd, (uint64_t) lp->size));
03a8a07d
AK
226 }
227
241913fe 228 lp->extents = lp->size / vg->extent_size;
03a8a07d
AK
229 }
230
34fadac4
AK
231 switch(lp->percent) {
232 case PERCENT_VG:
233 lp->extents = lp->extents * vg->extent_count / 100;
234 break;
235 case PERCENT_FREE:
236 lp->extents = lp->extents * vg->free_count / 100;
237 break;
238 case PERCENT_LV:
239 lp->extents = lp->extents * lv->le_count / 100;
240 break;
241 case PERCENT_NONE:
242 break;
243 }
244
241913fe
AK
245 if (lp->sign == SIGN_PLUS)
246 lp->extents += lv->le_count;
03a8a07d 247
241913fe
AK
248 if (lp->sign == SIGN_MINUS) {
249 if (lp->extents >= lv->le_count) {
03a8a07d 250 log_error("Unable to reduce %s below 1 extent",
241913fe 251 lp->lv_name);
7f0dc9c4 252 return EINVALID_CMD_LINE;
03a8a07d
AK
253 }
254
241913fe 255 lp->extents = lv->le_count - lp->extents;
03a8a07d
AK
256 }
257
241913fe 258 if (!lp->extents) {
03a8a07d 259 log_error("New size of 0 not permitted");
7f0dc9c4 260 return EINVALID_CMD_LINE;
03a8a07d
AK
261 }
262
241913fe 263 if (lp->extents == lv->le_count) {
03a8a07d 264 log_error("New size (%d extents) matches existing size "
241913fe 265 "(%d extents)", lp->extents, lv->le_count);
7f0dc9c4 266 return EINVALID_CMD_LINE;
03a8a07d
AK
267 }
268
241913fe 269 seg_size = lp->extents - lv->le_count;
25b73380 270
1832f310
AK
271 /* Use segment type of last segment */
272 list_iterate_items(seg, &lv->segments) {
241913fe 273 lp->segtype = seg->segtype;
1832f310
AK
274 }
275
276 /* FIXME Support LVs with mixed segment types */
72b2cb61 277 if (lp->segtype != arg_ptr_value(cmd, type_ARG, lp->segtype)) {
241913fe 278 log_error("VolumeType does not match (%s)", lp->segtype->name);
7f0dc9c4 279 return EINVALID_CMD_LINE;
1832f310
AK
280 }
281
52dc2139 282 /* If extending, find stripes, stripesize & size of last segment */
241913fe
AK
283 if ((lp->extents > lv->le_count) &&
284 !(lp->stripes == 1 || (lp->stripes > 1 && lp->stripe_size))) {
f2b7349e 285 list_iterate_items(seg, &lv->segments) {
32469fb2 286 if (!seg_is_striped(seg))
1832f310 287 continue;
b8c919b4 288
579944d3 289 sz = seg->stripe_size;
b8c919b4 290 str = seg->area_count;
52dc2139 291
da4e57f2 292 if ((seg_stripesize && seg_stripesize != sz
241913fe
AK
293 && !lp->stripe_size) ||
294 (seg_stripes && seg_stripes != str && !lp->stripes)) {
52dc2139
AK
295 log_error("Please specify number of "
296 "stripes (-i) and stripesize (-I)");
7f0dc9c4 297 return EINVALID_CMD_LINE;
52dc2139
AK
298 }
299
300 seg_stripesize = sz;
301 seg_stripes = str;
302 }
303
241913fe
AK
304 if (!lp->stripes)
305 lp->stripes = seg_stripes;
52dc2139 306
241913fe 307 if (!lp->stripe_size && lp->stripes > 1) {
25b73380 308 if (seg_stripesize) {
12de747d 309 log_print("Using stripesize of last segment %s",
72b2cb61 310 display_size(cmd, (uint64_t) seg_stripesize));
241913fe 311 lp->stripe_size = seg_stripesize;
25b73380 312 } else {
7f0dc9c4 313 lp->stripe_size =
2293567c 314 find_config_tree_int(cmd,
8ef2b021 315 "metadata/stripesize",
8ef2b021 316 DEFAULT_STRIPESIZE) * 2;
12de747d 317 log_print("Using default stripesize %s",
72b2cb61 318 display_size(cmd, (uint64_t) lp->stripe_size));
25b73380
AK
319 }
320 }
52dc2139
AK
321 }
322
ffb0e538
AK
323 /* If extending, find mirrors of last segment */
324 if ((lp->extents > lv->le_count)) {
325 list_iterate_back_items(seg, &lv->segments) {
326 if (seg_is_mirrored(seg))
327 seg_mirrors = seg->area_count;
328 else
329 seg_mirrors = 0;
330 break;
331 }
332 if (!arg_count(cmd, mirrors_ARG) && seg_mirrors) {
333 log_print("Extending %" PRIu32 " mirror images.",
334 seg_mirrors);
335 lp->mirrors = seg_mirrors;
336 }
337 if ((arg_count(cmd, mirrors_ARG) || seg_mirrors) &&
338 (lp->mirrors != seg_mirrors)) {
339 log_error("Cannot vary number of mirrors in LV yet.");
340 return EINVALID_CMD_LINE;
341 }
342 }
343
52dc2139 344 /* If reducing, find stripes, stripesize & size of last segment */
241913fe 345 if (lp->extents < lv->le_count) {
25b73380 346 extents_used = 0;
52dc2139 347
ffb0e538
AK
348 if (lp->stripes || lp->stripe_size || lp->mirrors)
349 log_error("Ignoring stripes, stripesize and mirrors "
350 "arguments when reducing");
52dc2139 351
f2b7349e 352 list_iterate_items(seg, &lv->segments) {
579944d3
AK
353 seg_extents = seg->len;
354
32469fb2 355 if (seg_is_striped(seg)) {
b8c919b4
AK
356 seg_stripesize = seg->stripe_size;
357 seg_stripes = seg->area_count;
358 }
52dc2139 359
ffb0e538
AK
360 if (seg_is_mirrored(seg))
361 seg_mirrors = seg->area_count;
362 else
363 seg_mirrors = 0;
364
241913fe 365 if (lp->extents <= extents_used + seg_extents)
52dc2139
AK
366 break;
367
368 extents_used += seg_extents;
369 }
370
241913fe
AK
371 seg_size = lp->extents - extents_used;
372 lp->stripe_size = seg_stripesize;
373 lp->stripes = seg_stripes;
ffb0e538 374 lp->mirrors = seg_mirrors;
52dc2139
AK
375 }
376
241913fe 377 if (lp->stripes > 1 && !lp->stripe_size) {
25b73380 378 log_error("Stripesize for striped segment should not be 0!");
7f0dc9c4 379 return EINVALID_CMD_LINE;
d4e5f63e 380 }
5a52dca9 381
241913fe
AK
382 if ((lp->stripes > 1)) {
383 if (!(stripesize_extents = lp->stripe_size / vg->extent_size))
d4e5f63e
AK
384 stripesize_extents = 1;
385
241913fe 386 if ((size_rest = seg_size % (lp->stripes * stripesize_extents))) {
d4e5f63e
AK
387 log_print("Rounding size (%d extents) down to stripe "
388 "boundary size for segment (%d extents)",
241913fe
AK
389 lp->extents, lp->extents - size_rest);
390 lp->extents = lp->extents - size_rest;
d4e5f63e 391 }
12de747d
AK
392
393 if (lp->stripe_size < STRIPE_SIZE_MIN) {
394 log_error("Invalid stripe size %s",
72b2cb61 395 display_size(cmd, (uint64_t) lp->stripe_size));
12de747d
AK
396 return 0;
397 }
da4e57f2 398 }
52dc2139 399
241913fe 400 if (lp->extents == lv->le_count) {
52dc2139 401 log_error("New size (%d extents) matches existing size "
241913fe 402 "(%d extents)", lp->extents, lv->le_count);
7f0dc9c4 403 return EINVALID_CMD_LINE;
52dc2139
AK
404 }
405
241913fe
AK
406 if (lp->extents < lv->le_count) {
407 if (lp->resize == LV_EXTEND) {
03a8a07d
AK
408 log_error("New size given (%d extents) not larger "
409 "than existing size (%d extents)",
241913fe 410 lp->extents, lv->le_count);
7f0dc9c4 411 return EINVALID_CMD_LINE;
03a8a07d 412 } else
241913fe 413 lp->resize = LV_REDUCE;
03a8a07d
AK
414 }
415
241913fe
AK
416 if (lp->extents > lv->le_count) {
417 if (lp->resize == LV_REDUCE) {
03a8a07d 418 log_error("New size given (%d extents) not less than "
241913fe 419 "existing size (%d extents)", lp->extents,
03a8a07d 420 lv->le_count);
7f0dc9c4 421 return EINVALID_CMD_LINE;
03a8a07d 422 } else
241913fe 423 lp->resize = LV_EXTEND;
03a8a07d
AK
424 }
425
f5190ed4 426 if (lp->mirrors && activation() &&
f894b4b1 427 lv_info(cmd, lv, &info, 0) && info.exists) {
f5190ed4
AK
428 log_error("Mirrors cannot be resized while active yet.");
429 return ECMD_FAILED;
430 }
864de9ce
AK
431
432 if (lv_is_origin(lv)) {
433 if (lp->resize == LV_REDUCE) {
434 log_error("Snapshot origin volumes cannot be reduced "
435 "in size yet.");
436 return ECMD_FAILED;
437 }
438
439 memset(&info, 0, sizeof(info));
440
f894b4b1 441 if (lv_info(cmd, lv, &info, 0) && info.exists) {
864de9ce
AK
442 log_error("Snapshot origin volumes can be resized "
443 "only while inactive: try lvchange -an");
444 return ECMD_FAILED;
445 }
446 }
447
241913fe
AK
448 if (lp->resize == LV_REDUCE) {
449 if (lp->argc)
03a8a07d 450 log_print("Ignoring PVs on command line when reducing");
1a9ea74d 451 } else if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc,
eabaa339 452 lp->argv, 1) : &vg->pvs)) {
1a9ea74d
AK
453 stack;
454 return ECMD_FAILED;
455 }
03a8a07d 456
1a9ea74d 457 if (lp->resize == LV_REDUCE || lp->resizefs) {
25b73380
AK
458 memset(&info, 0, sizeof(info));
459
f894b4b1 460 if (!lv_info(cmd, lv, &info, 1) && driver_version(NULL, 0)) {
25b73380 461 log_error("lv_info failed: aborting");
7f0dc9c4 462 return ECMD_FAILED;
41967a02
AK
463 }
464
1a9ea74d
AK
465 if (lp->resizefs && !info.exists) {
466 log_error("Logical volume %s must be activated "
467 "before resizing filesystem", lp->lv_name);
468 return ECMD_FAILED;
469 }
470
471 if (info.exists && !lp->resizefs && (lp->resize == LV_REDUCE)) {
03a8a07d 472 log_print("WARNING: Reducing active%s logical volume "
41967a02 473 "to %s", info.open_count ? " and open" : "",
241913fe 474 display_size(cmd, (uint64_t) lp->extents *
72b2cb61 475 vg->extent_size));
03a8a07d
AK
476
477 log_print("THIS MAY DESTROY YOUR DATA "
478 "(filesystem etc.)");
03a8a07d 479
1a9ea74d
AK
480 if (!arg_count(cmd, force_ARG)) {
481 if (yes_no_prompt("Do you really want to "
482 "reduce %s? [y/n]: ",
483 lp->lv_name) == 'n') {
484 log_print("Logical volume %s NOT "
485 "reduced", lp->lv_name);
486 return ECMD_FAILED;
487 }
7379c678
PR
488 if (sigint_caught())
489 return ECMD_FAILED;
03a8a07d
AK
490 }
491 }
1a9ea74d 492 }
03a8a07d 493
1a9ea74d 494 if (lp->resizefs) {
0550c1b6 495 if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", cmd->dev_dir,
1a9ea74d
AK
496 lp->vg_name, lp->lv_name) < 0) {
497 log_error("Couldn't create LV path for %s",
498 lp->lv_name);
7f0dc9c4 499 return ECMD_FAILED;
241913fe 500 }
614a4508 501
0550c1b6 502 if (dm_snprintf(size_buf, SIZE_BUF, "%" PRIu64,
1a9ea74d
AK
503 (uint64_t) lp->extents * vg->extent_size / 2)
504 < 0) {
505 log_error("Couldn't generate new LV size string");
7f0dc9c4 506 return ECMD_FAILED;
1a9ea74d 507 }
03a8a07d 508
1a9ea74d
AK
509 if (!lp->nofsck) {
510 if (!exec_cmd("fsadm", "check", lv_path, NULL)) {
511 stack;
512 return ECMD_FAILED;
513 }
8ef2b021
AK
514 }
515
1a9ea74d
AK
516 if (lp->resize == LV_REDUCE) {
517 if (!exec_cmd("fsadm", "resize", lv_path, size_buf)) {
518 stack;
519 return ECMD_FAILED;
520 }
241913fe 521 }
1a9ea74d 522 }
614a4508 523
1a9ea74d
AK
524 if (!archive(vg)) {
525 stack;
526 return ECMD_FAILED;
527 }
03a8a07d 528
1a9ea74d
AK
529 log_print("%sing logical volume %s to %s",
530 (lp->resize == LV_REDUCE) ? "Reduc" : "Extend",
531 lp->lv_name,
72b2cb61 532 display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
1a9ea74d
AK
533
534 if (lp->resize == LV_REDUCE) {
32469fb2 535 if (!lv_reduce(lv, lv->le_count - lp->extents)) {
7f0dc9c4
AK
536 stack;
537 return ECMD_FAILED;
241913fe 538 }
32469fb2 539 } else if (!lv_extend(lv, lp->segtype, lp->stripes,
ffb0e538 540 lp->stripe_size, lp->mirrors,
32469fb2
AK
541 lp->extents - lv->le_count,
542 NULL, 0u, 0u, pvh, alloc)) {
1a9ea74d
AK
543 stack;
544 return ECMD_FAILED;
03a8a07d
AK
545 }
546
03a8a07d 547 /* store vg on disk(s) */
25b73380 548 if (!vg_write(vg)) {
914c9723 549 stack;
7f0dc9c4 550 return ECMD_FAILED;
cc8b2cd7 551 }
03a8a07d 552
6fda126d 553 backup(vg);
cc219483 554
914c9723 555 /* If snapshot, must suspend all associated devices */
2cd0aa72
AK
556 if (lv_is_cow(lv))
557 lock_lv = origin_from_cow(lv);
914c9723 558 else
0fb173aa 559 lock_lv = lv;
914c9723 560
0fb173aa 561 if (!suspend_lv(cmd, lock_lv)) {
241913fe 562 log_error("Failed to suspend %s", lp->lv_name);
914c9723 563 vg_revert(vg);
7f0dc9c4 564 return ECMD_FAILED;
914c9723
AK
565 }
566
567 if (!vg_commit(vg)) {
568 stack;
0fb173aa 569 resume_lv(cmd, lock_lv);
7f0dc9c4 570 return ECMD_FAILED;
914c9723
AK
571 }
572
0fb173aa 573 if (!resume_lv(cmd, lock_lv)) {
241913fe 574 log_error("Problem reactivating %s", lp->lv_name);
7f0dc9c4 575 return ECMD_FAILED;
cc8b2cd7 576 }
03a8a07d 577
241913fe 578 log_print("Logical volume %s successfully resized", lp->lv_name);
03a8a07d 579
1a9ea74d
AK
580 if (lp->resizefs && (lp->resize == LV_EXTEND)) {
581 if (!exec_cmd("fsadm", "resize", lv_path, size_buf)) {
582 stack;
583 return ECMD_FAILED;
584 }
585 }
586
cfb7bfc7 587 return ECMD_PROCESSED;
03a8a07d 588}
241913fe
AK
589
590int lvresize(struct cmd_context *cmd, int argc, char **argv)
591{
592 struct lvresize_params lp;
593 int r;
594
595 memset(&lp, 0, sizeof(lp));
596
8a2fc586 597 if (!_lvresize_params(cmd, argc, argv, &lp))
241913fe
AK
598 return EINVALID_CMD_LINE;
599
600 log_verbose("Finding volume group %s", lp.vg_name);
601 if (!lock_vol(cmd, lp.vg_name, LCK_VG_WRITE)) {
602 log_error("Can't get lock for %s", lp.vg_name);
603 return ECMD_FAILED;
604 }
605
606 if (!(r = _lvresize(cmd, &lp)))
607 stack;
608
609 unlock_vg(cmd, lp.vg_name);
610
611 return r;
612}
This page took 0.125893 seconds and 5 git commands to generate.