From 8de912b677a24ba6a517832be03916835f8ccd15 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 19 Oct 2011 16:39:09 +0000 Subject: [PATCH] Simple validation of messages in mda Check we do not combine multiple messages for same LV target and switch to use 'delete_id' to make it clear for what this device_id is being used. --- lib/metadata/metadata.h | 2 +- lib/metadata/thin_manip.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index b71be4cee..11cac5701 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -455,7 +455,7 @@ int attach_pool_data_lv(struct lv_segment *seg, int attach_pool_lv(struct lv_segment *seg, struct logical_volume *pool_lv); int detach_pool_lv(struct lv_segment *seg); int attach_pool_message(struct lv_segment *seg, dm_thin_message_t type, - struct logical_volume *lv, uint32_t device_id, + struct logical_volume *lv, uint32_t delete_id, int read_only); int detach_pool_messages(struct lv_segment *seg); diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c index ef16d270c..afa762806 100644 --- a/lib/metadata/thin_manip.c +++ b/lib/metadata/thin_manip.c @@ -81,11 +81,36 @@ int detach_pool_lv(struct lv_segment *seg) } int attach_pool_message(struct lv_segment *seg, dm_thin_message_t type, - struct logical_volume *lv, uint32_t device_id, + struct logical_volume *lv, uint32_t delete_id, int read_only) { struct lv_thin_message *tmsg; + dm_list_iterate_items(tmsg, &seg->thin_messages) { + if (tmsg->type == type) { + switch (tmsg->type) { + case DM_THIN_MESSAGE_CREATE_SNAP: + case DM_THIN_MESSAGE_CREATE_THIN: + case DM_THIN_MESSAGE_TRIM: + if (tmsg->u.lv == lv) { + log_error("Message referring LV %s already queued for %s.", + tmsg->u.lv->name, seg->lv->name); + return 0; + } + break; + case DM_THIN_MESSAGE_DELETE: + if (tmsg->u.delete_id == delete_id) { + log_error("Delete of device %u already queued for %s.", + tmsg->u.delete_id, seg->lv->name); + return 0; + } + break; + default: + break; + } + } + } + if (!(tmsg = dm_pool_alloc(seg->lv->vg->vgmem, sizeof(*tmsg)))) { log_error("Failed to allocate memory for message."); return 0; @@ -98,7 +123,7 @@ int attach_pool_message(struct lv_segment *seg, dm_thin_message_t type, tmsg->u.lv = lv; break; case DM_THIN_MESSAGE_DELETE: - tmsg->u.delete_id = device_id; + tmsg->u.delete_id = delete_id; break; default: log_error(INTERNAL_ERROR "Unsupported message type %d", type);