From 2bc25b546a42b49bea3cd1e2c97d79dcb87e8700 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 7 Jan 2002 22:28:36 +0000 Subject: [PATCH] Support for read-only. --- lib/activate/activate.c | 35 +++++++++++++++++++++++++++++++++-- lib/activate/activate.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 42f957b93..931a93d1a 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -73,6 +73,21 @@ int lv_active(struct logical_volume *lv) return info.exists; } +int lv_suspended(struct logical_volume *lv) +{ + int r = -1; + struct dm_info info; + + if (!lv_info(lv, &info)) { + stack; + return r; + } + + log_very_verbose("%s is%s suspended", lv->name, + info.suspended ? "":" not"); + return info.suspended; +} + int lv_open_count(struct logical_volume *lv) { int r = -1; @@ -163,6 +178,11 @@ int _load(struct logical_volume *lv, int task) } } + if (!(lv->status & LVM_WRITE) && !dm_task_set_ro(dmt)) + log_error("Failed to set %s read-only during activation.", + lv->name); + + if (!(r = dm_task_run(dmt))) stack; @@ -211,7 +231,7 @@ int lv_reactivate(struct logical_volume *lv) if (test_mode()) return 0; - if (!_suspend(lv, 1)) { + if (!lv_suspended(lv) && !_suspend(lv, 1)) { stack; return 0; } @@ -267,7 +287,18 @@ int activate_lvs_in_vg(struct volume_group *vg) int lv_update_write_access(struct logical_volume *lv) { - return 0; + struct dm_info info; + + if (!lv_info(lv, &info)) { + stack; + return 0; + } + + if (!info.exists || info.suspended) + /* Noop */ + return 1; + + return lv_reactivate(lv); } int deactivate_lvs_in_vg(struct volume_group *vg) diff --git a/lib/activate/activate.h b/lib/activate/activate.h index e03efe172..170af0959 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -12,6 +12,7 @@ /* FIXME Snapshot handling? */ int lv_active(struct logical_volume *lv); +int lv_suspended(struct logical_volume *lv); int lv_open_count(struct logical_volume *lv); int lv_info(struct logical_volume *lv, struct dm_info *info);