lvm2/bug-1158628_09-lvconvert-improve-validation-thin-and-cache-pool-con.patch
Gang He 7f9b3f4598 Accepting request 755483 from home:hmzhao:branches:openSUSE:Factory
- backport patches for lvm2 to avoid software abnormal work (bsc#1158861)
  + bug-1158861_01-config-remove-filter-typo.patch
  + bug-1158861_02-config-Fix-default-option-which-makes-no-sense.patch
  + bug-1158861_03-vgchange-don-t-fail-monitor-command-if-vg-is-exporte.patch
  + bug-1158861_04-fix-duplicate-pv-size-check.patch
  + bug-1158861_05-hints-fix-copy-of-filter.patch
  + bug-1158861_06-fix-segfault-for-invalid-characters-in-vg-name.patch
  + bug-1158861_07-vgck-let-updatemetadata-repair-mismatched-metadata.patch
  + bug-1158861_08-hints-fix-mem-leaking-buffers.patch
  + bug-1158861_09-pvcreate-pvremove-fix-reacquiring-global-lock-after.patch
- add necessary patches for passing lvm2 testsuite (bsc#1158628)
  + bug-1158628_01-tests-replaces-grep-q-usage.patch
  + bug-1158628_02-tests-fix-ra-checking.patch
  + bug-1158628_03-tests-simplify-some-var-settings.patch
  + bug-1158628-04-pvmove-correcting-read_ahead-setting.patch
  + bug-1158628_05-activation-add-synchronization-point.patch
  + bug-1158628_06-pvmove-add-missing-synchronization.patch
  + bug-1158628_07-activation-extend-handling-of-pending_delete.patch
  + bug-1158628_08-lv_manip-add-synchronizations.patch
  + bug-1158628_09-lvconvert-improve-validation-thin-and-cache-pool-con.patch
  + bug-1158628_10-thin-activate-layer-pool-aas-read-only-LV.patch
  + bug-1158628_11-tests-mdadm-stop-in-test-cleanup.patch
  + bug-1158628_12-test-increase-size-of-raid10-LV-allowing-tests-to-su.patch
  + bug-1158628_13-lvconvert-fix-return-value-when-zeroing-fails.patch
  + bug-1158628_14-tests-add-extra-settle.patch
  + bug-1158628_15-test-Fix-handling-leftovers-from-previous-tests.patch

OBS-URL: https://build.opensuse.org/request/show/755483
OBS-URL: https://build.opensuse.org/package/show/Base:System/lvm2?expand=0&rev=260
2019-12-10 09:29:09 +00:00

91 lines
2.5 KiB
Diff

From 7612c21f5511c58bac81fc46e304bd9f4cd2cd75 Mon Sep 17 00:00:00 2001
From: Zdenek Kabelac <zkabelac@redhat.com>
Date: Fri, 6 Sep 2019 18:09:40 +0200
Subject: [PATCH] lvconvert: improve validation thin and cache pool conversion
Limit convertible LVs to thin-pool and cache-pools.
Also fix return code on interal error path to return ECMD_FAILED.
---
tools/lvconvert.c | 52 ++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 31f9296769..d64ab224aa 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -4455,24 +4455,66 @@ static int _lvconvert_to_pool_or_swap_metadata_single(struct cmd_context *cmd,
struct dm_list *use_pvh = NULL;
int to_thinpool = 0;
int to_cachepool = 0;
+ int lvt_enum = get_lvt_enum(lv);
+ struct lv_type *lvtype;
switch (cmd->command->command_enum) {
case lvconvert_to_thinpool_or_swap_metadata_CMD:
+ if (lv_is_cache(lv))
+ /* For cached LV check the cache origin LV type */
+ lvt_enum = get_lvt_enum(seg_lv(first_seg(lv), 0));
to_thinpool = 1;
break;
case lvconvert_to_cachepool_or_swap_metadata_CMD:
+ if (lv_is_cache(lv))
+ goto_bad; /* Cache over cache is not supported */
to_cachepool = 1;
break;
default:
- log_error(INTERNAL_ERROR "Invalid lvconvert pool command");
- return 0;
- };
+ log_error(INTERNAL_ERROR "Invalid lvconvert pool command.");
+ return ECMD_FAILED;
+ }
+
+ switch (lvt_enum) {
+ case thinpool_LVT:
+ if (!to_thinpool)
+ goto_bad; /* can't accept cache-pool */
+ break; /* swap thin-pool */
+ case cachepool_LVT:
+ if (!to_cachepool)
+ goto_bad; /* can't accept thin-pool */
+ break; /* swap cache-pool */
+ case linear_LVT:
+ case raid_LVT:
+ case striped_LVT:
+ case zero_LVT:
+ break;
+ default:
+bad:
+ lvtype = get_lv_type(lvt_enum);
+ log_error("LV %s with type %s cannot be used as a %s pool LV.",
+ display_lvname(lv), lvtype ? lvtype->name : "unknown",
+ to_thinpool ? "thin" : "cache");
+ return ECMD_FAILED;
+ }
if (lv_is_origin(lv)) {
log_error("Cannot convert logical volume %s under snapshot.",
display_lvname(lv));
- return 0;
- };
+ return ECMD_FAILED;
+ }
+
+ if (!lv_is_visible(lv)) {
+ log_error("Can't convert internal LV %s.",
+ display_lvname(lv));
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_locked(lv)) {
+ log_error("Can't convert locked LV %s.",
+ display_lvname(lv));
+ return ECMD_FAILED;
+ }
if (cmd->position_argc > 1) {
/* First pos arg is required LV, remaining are optional PVs. */
--
2.24.0