From 386f0bfb4fc164f35e340592450cd817f2b0af0b Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 4 Mar 2024 11:51:56 +0100 Subject: [PATCH] thin: lock fs when converting to external origin Ensure suspend is locking fs, when converting LV to external origin. --- lib/activate/activate.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 8605e5293..14adc7320 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -2193,16 +2193,23 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s, /* FIXME Consider aborting here */ stack; - if (!laopts->origin_only && - (lv_is_origin(lv_pre) || lv_is_cow(lv_pre))) - lockfs = 1; - - /* Converting non-thin LV to thin external origin ? */ - if (!lv_is_thin_volume(lv) && lv_is_thin_volume(lv_pre)) - lockfs = 1; /* Sync before conversion */ - + /* Require fs synchronization when taking a thin snapshot */ if (laopts->origin_only && lv_is_thin_volume(lv) && lv_is_thin_volume(lv_pre)) lockfs = 1; + /* Require fs synchronization when taking a thick snapshot */ + else if (!laopts->origin_only && + (lv_is_origin(lv_pre) || lv_is_cow(lv_pre))) + lockfs = 1; + /* Require fs synchronization when converting a non-thin LV to a thin LV or + * a non/thin LV with/out external origin to a thin LV with external origin LV. */ + else if (!laopts->origin_only && + lv_is_thin_volume(lv_pre) && /* new LV is a Thin */ + (!lv_is_thin_volume(lv) || /* and either the existing LV is NOT a Thin */ + (first_seg(lv_pre)->external_lv && /* or the existing LV IS Thin and the new LV is Thin with the external origin */ + (!first_seg(lv)->external_lv || /* and check if existing Thin is either without the external origin */ + memcmp(&first_seg(lv_pre)->external_lv->lvid.id[1], /* or it uses a different external origin */ + &first_seg(lv)->external_lv->lvid.id[1], ID_LEN) != 0)))) + lockfs = 1; if (!lv_is_locked(lv) && lv_is_locked(lv_pre) && (pvmove_lv = find_pvmove_lv_in_lv(lv_pre))) {