From 2e732e9628d07071e392cd25fe9b10679cef805f Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 3 Nov 2011 14:45:01 +0000 Subject: [PATCH] Thin api change for passing message into libdm Avoid exposing another struct to the libdm user and use only simple dm_tree_node_add_thin_pool_message with 2 overloaded uint64_t values. --- lib/thin/thin.c | 30 ++++++++++--------- libdm/libdevmapper.h | 37 +++++------------------- libdm/libdm-deptree.c | 67 +++++++++++++++++++++++++++++++------------ 3 files changed, 72 insertions(+), 62 deletions(-) diff --git a/lib/thin/thin.c b/lib/thin/thin.c index 01f7e18c0..0a90e78aa 100644 --- a/lib/thin/thin.c +++ b/lib/thin/thin.c @@ -222,7 +222,6 @@ static int _thin_pool_add_target_line(struct dev_manager *dm, { char *metadata_dlid, *pool_dlid; const struct lv_thin_message *lmsg; - struct dm_thin_message dmsg; if (!(metadata_dlid = build_dm_uuid(mem, seg->pool_metadata_lv->lvid.s, NULL))) { log_error("Failed to build uuid for metadata LV %s.", @@ -243,27 +242,30 @@ static int _thin_pool_add_target_line(struct dev_manager *dm, return_0; dm_list_iterate_items(lmsg, &seg->thin_messages) { - dmsg.type = lmsg->type; switch (lmsg->type) { case DM_THIN_MESSAGE_CREATE_SNAP: /* FIXME: to be implemented */ log_debug("Thin pool create_snap %s.", lmsg->u.lv->name); - dmsg.u.m_create_snap.device_id = first_seg(lmsg->u.lv)->device_id; - dmsg.u.m_create_snap.origin_id = 0;//first_seg(first_seg(lmsg->u.lv)->origin)->device_id; - if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) + if (!dm_tree_node_add_thin_pool_message(node, + lmsg->type, + first_seg(lmsg->u.lv)->device_id, + 0))//first_seg(first_seg(lmsg->u.lv)->origin)->device_id; return_0; log_error("Sorry SNAPSHOT is not yet supported."); return 0; case DM_THIN_MESSAGE_CREATE_THIN: log_debug("Thin pool create_thin %s.", lmsg->u.lv->name); - dmsg.u.m_create_thin.device_id = first_seg(lmsg->u.lv)->device_id; - if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) + if (!dm_tree_node_add_thin_pool_message(node, + lmsg->type, + first_seg(lmsg->u.lv)->device_id, + 0)) return_0; break; case DM_THIN_MESSAGE_DELETE: log_debug("Thin pool delete %u.", lmsg->u.delete_id); - dmsg.u.m_delete.device_id = lmsg->u.delete_id; - if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) + if (!dm_tree_node_add_thin_pool_message(node, + lmsg->type, + lmsg->u.delete_id, 0)) return_0; break; case DM_THIN_MESSAGE_TRIM: @@ -278,11 +280,11 @@ static int _thin_pool_add_target_line(struct dev_manager *dm, if (!dm_list_empty(&seg->thin_messages)) { /* Messages were passed, modify transaction_id as the last one */ - log_debug("Thin pool set_transaction_id %" PRIu64 ".", seg->transaction_id); - dmsg.type = DM_THIN_MESSAGE_SET_TRANSACTION_ID; - dmsg.u.m_set_transaction_id.current_id = seg->transaction_id - 1; - dmsg.u.m_set_transaction_id.new_id = seg->transaction_id; - if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) + log_debug("Thin pool set transaction id %" PRIu64 ".", seg->transaction_id); + if (!dm_tree_node_add_thin_pool_message(node, + DM_THIN_MESSAGE_SET_TRANSACTION_ID, + seg->transaction_id - 1, + seg->transaction_id)) return_0; } diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 1399c3570..c865f6fd6 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -555,39 +555,16 @@ int dm_tree_node_add_thin_pool_target(struct dm_tree_node *node, /* Supported messages for thin provision target */ typedef enum { - DM_THIN_MESSAGE_CREATE_SNAP, - DM_THIN_MESSAGE_CREATE_THIN, - DM_THIN_MESSAGE_DELETE, - DM_THIN_MESSAGE_SET_TRANSACTION_ID, - DM_THIN_MESSAGE_TRIM + DM_THIN_MESSAGE_CREATE_SNAP, /* device_id, origin_id */ + DM_THIN_MESSAGE_CREATE_THIN, /* device_id */ + DM_THIN_MESSAGE_DELETE, /* device_id */ + DM_THIN_MESSAGE_SET_TRANSACTION_ID, /* current_id, new_id */ + DM_THIN_MESSAGE_TRIM /* device_id, new_size */ } dm_thin_message_t; -struct dm_thin_message { - dm_thin_message_t type; - union { - struct { - uint32_t device_id; - uint32_t origin_id; - } m_create_snap; - struct { - uint32_t device_id; - } m_create_thin; - struct { - uint32_t device_id; - } m_delete; - struct { - uint64_t current_id; - uint64_t new_id; - } m_set_transaction_id; - struct { - uint32_t device_id; - uint64_t new_size; - } m_trim; - } u; -}; - int dm_tree_node_add_thin_pool_message(struct dm_tree_node *node, - const struct dm_thin_message *message); + dm_thin_message_t type, + uint64_t id1, uint64_t id2); /* * FIXME: Defines bellow are based on kernel's dm-thin.c defines diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index 2baf82fdc..31981decd 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -108,6 +108,30 @@ struct seg_area { uint32_t flags; /* Replicator sync log flags */ }; +struct dm_thin_message { + dm_thin_message_t type; + union { + struct { + uint32_t device_id; + uint32_t origin_id; + } m_create_snap; + struct { + uint32_t device_id; + } m_create_thin; + struct { + uint32_t device_id; + } m_delete; + struct { + uint64_t current_id; + uint64_t new_id; + } m_set_transaction_id; + struct { + uint32_t device_id; + uint64_t new_size; + } m_trim; + } u; +}; + struct thin_message { struct dm_list list; struct dm_thin_message message; @@ -2901,7 +2925,8 @@ int dm_tree_node_add_thin_pool_target(struct dm_tree_node *node, } int dm_tree_node_add_thin_pool_message(struct dm_tree_node *node, - const struct dm_thin_message *message) + dm_thin_message_t type, + uint64_t id1, uint64_t id2) { struct load_segment *seg; struct thin_message *tm; @@ -2923,49 +2948,55 @@ int dm_tree_node_add_thin_pool_message(struct dm_tree_node *node, return 0; } - switch (message->type) { + switch (type) { case DM_THIN_MESSAGE_CREATE_SNAP: /* If the thin origin is active, it must be suspend first! */ - if (message->u.m_create_snap.device_id == message->u.m_create_snap.origin_id) { + if (id1 == id2) { log_error("Cannot use same device id for origin and its snapshot."); return 0; } - if (!_thin_validate_device_id(message->u.m_create_snap.device_id) || - !_thin_validate_device_id(message->u.m_create_snap.origin_id)) + if (!_thin_validate_device_id(id1) || + !_thin_validate_device_id(id2)) return_0; - tm->message.u.m_create_snap = message->u.m_create_snap; + tm->message.u.m_create_snap.device_id = id1; + tm->message.u.m_create_snap.origin_id = id2; break; case DM_THIN_MESSAGE_CREATE_THIN: - if (!_thin_validate_device_id(message->u.m_create_thin.device_id)) + if (!_thin_validate_device_id(id1)) return_0; - tm->message.u.m_create_thin = message->u.m_create_thin; + tm->message.u.m_create_thin.device_id = id1; tm->expected_errno = EEXIST; break; case DM_THIN_MESSAGE_DELETE: - if (!_thin_validate_device_id(message->u.m_delete.device_id)) + if (!_thin_validate_device_id(id1)) return_0; - tm->message.u.m_delete = message->u.m_delete; + tm->message.u.m_delete.device_id = id1; tm->expected_errno = ENODATA; break; case DM_THIN_MESSAGE_TRIM: - if (!_thin_validate_device_id(message->u.m_trim.device_id)) + if (!_thin_validate_device_id(id1)) return_0; - tm->message.u.m_trim = message->u.m_trim; + tm->message.u.m_trim.device_id = id1; + tm->message.u.m_trim.new_size = id2; break; case DM_THIN_MESSAGE_SET_TRANSACTION_ID: - if (message->u.m_set_transaction_id.current_id != - (message->u.m_set_transaction_id.new_id - 1)) { - log_error("New transaction_id must be sequential."); + if ((id1 + 1) != id2) { + log_error("New transaction id must be sequential."); return 0; /* FIXME: Maybe too strict here? */ } - tm->message.u.m_set_transaction_id = message->u.m_set_transaction_id; + if (id1 != seg->transaction_id) { + log_error("Current transaction id is different from thin pool."); + return 0; /* FIXME: Maybe too strict here? */ + } + tm->message.u.m_set_transaction_id.current_id = id1; + tm->message.u.m_set_transaction_id.new_id = id2; break; default: - log_error("Unsupported message type %d.", (int) message->type); + log_error("Unsupported message type %d.", (int) type); return 0; } - tm->message.type = message->type; + tm->message.type = type; dm_list_add(&seg->thin_messages, &tm->list); return 1;