1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Zdenek Kabelac 2011-11-03 14:45:01 +00:00
parent 4d25c81bdd
commit 2e732e9628
3 changed files with 72 additions and 62 deletions

View File

@ -222,7 +222,6 @@ static int _thin_pool_add_target_line(struct dev_manager *dm,
{ {
char *metadata_dlid, *pool_dlid; char *metadata_dlid, *pool_dlid;
const struct lv_thin_message *lmsg; 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))) { if (!(metadata_dlid = build_dm_uuid(mem, seg->pool_metadata_lv->lvid.s, NULL))) {
log_error("Failed to build uuid for metadata LV %s.", 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; return_0;
dm_list_iterate_items(lmsg, &seg->thin_messages) { dm_list_iterate_items(lmsg, &seg->thin_messages) {
dmsg.type = lmsg->type;
switch (lmsg->type) { switch (lmsg->type) {
case DM_THIN_MESSAGE_CREATE_SNAP: case DM_THIN_MESSAGE_CREATE_SNAP:
/* FIXME: to be implemented */ /* FIXME: to be implemented */
log_debug("Thin pool create_snap %s.", lmsg->u.lv->name); 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; if (!dm_tree_node_add_thin_pool_message(node,
dmsg.u.m_create_snap.origin_id = 0;//first_seg(first_seg(lmsg->u.lv)->origin)->device_id; lmsg->type,
if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) first_seg(lmsg->u.lv)->device_id,
0))//first_seg(first_seg(lmsg->u.lv)->origin)->device_id;
return_0; return_0;
log_error("Sorry SNAPSHOT is not yet supported."); log_error("Sorry SNAPSHOT is not yet supported.");
return 0; return 0;
case DM_THIN_MESSAGE_CREATE_THIN: case DM_THIN_MESSAGE_CREATE_THIN:
log_debug("Thin pool create_thin %s.", lmsg->u.lv->name); 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,
if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) lmsg->type,
first_seg(lmsg->u.lv)->device_id,
0))
return_0; return_0;
break; break;
case DM_THIN_MESSAGE_DELETE: case DM_THIN_MESSAGE_DELETE:
log_debug("Thin pool delete %u.", lmsg->u.delete_id); 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,
if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) lmsg->type,
lmsg->u.delete_id, 0))
return_0; return_0;
break; break;
case DM_THIN_MESSAGE_TRIM: 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)) { if (!dm_list_empty(&seg->thin_messages)) {
/* Messages were passed, modify transaction_id as the last one */ /* Messages were passed, modify transaction_id as the last one */
log_debug("Thin pool set_transaction_id %" PRIu64 ".", seg->transaction_id); log_debug("Thin pool set transaction id %" PRIu64 ".", seg->transaction_id);
dmsg.type = DM_THIN_MESSAGE_SET_TRANSACTION_ID; if (!dm_tree_node_add_thin_pool_message(node,
dmsg.u.m_set_transaction_id.current_id = seg->transaction_id - 1; DM_THIN_MESSAGE_SET_TRANSACTION_ID,
dmsg.u.m_set_transaction_id.new_id = seg->transaction_id; seg->transaction_id - 1,
if (!dm_tree_node_add_thin_pool_message(node, &dmsg)) seg->transaction_id))
return_0; return_0;
} }

View File

@ -555,39 +555,16 @@ int dm_tree_node_add_thin_pool_target(struct dm_tree_node *node,
/* Supported messages for thin provision target */ /* Supported messages for thin provision target */
typedef enum { typedef enum {
DM_THIN_MESSAGE_CREATE_SNAP, DM_THIN_MESSAGE_CREATE_SNAP, /* device_id, origin_id */
DM_THIN_MESSAGE_CREATE_THIN, DM_THIN_MESSAGE_CREATE_THIN, /* device_id */
DM_THIN_MESSAGE_DELETE, DM_THIN_MESSAGE_DELETE, /* device_id */
DM_THIN_MESSAGE_SET_TRANSACTION_ID, DM_THIN_MESSAGE_SET_TRANSACTION_ID, /* current_id, new_id */
DM_THIN_MESSAGE_TRIM DM_THIN_MESSAGE_TRIM /* device_id, new_size */
} dm_thin_message_t; } 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, 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 * FIXME: Defines bellow are based on kernel's dm-thin.c defines

View File

@ -108,6 +108,30 @@ struct seg_area {
uint32_t flags; /* Replicator sync log flags */ 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 thin_message {
struct dm_list list; struct dm_list list;
struct dm_thin_message message; 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, 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 load_segment *seg;
struct thin_message *tm; struct thin_message *tm;
@ -2923,49 +2948,55 @@ int dm_tree_node_add_thin_pool_message(struct dm_tree_node *node,
return 0; return 0;
} }
switch (message->type) { switch (type) {
case DM_THIN_MESSAGE_CREATE_SNAP: case DM_THIN_MESSAGE_CREATE_SNAP:
/* If the thin origin is active, it must be suspend first! */ /* 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."); log_error("Cannot use same device id for origin and its snapshot.");
return 0; return 0;
} }
if (!_thin_validate_device_id(message->u.m_create_snap.device_id) || if (!_thin_validate_device_id(id1) ||
!_thin_validate_device_id(message->u.m_create_snap.origin_id)) !_thin_validate_device_id(id2))
return_0; 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; break;
case DM_THIN_MESSAGE_CREATE_THIN: 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; 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; tm->expected_errno = EEXIST;
break; break;
case DM_THIN_MESSAGE_DELETE: case DM_THIN_MESSAGE_DELETE:
if (!_thin_validate_device_id(message->u.m_delete.device_id)) if (!_thin_validate_device_id(id1))
return_0; return_0;
tm->message.u.m_delete = message->u.m_delete; tm->message.u.m_delete.device_id = id1;
tm->expected_errno = ENODATA; tm->expected_errno = ENODATA;
break; break;
case DM_THIN_MESSAGE_TRIM: case DM_THIN_MESSAGE_TRIM:
if (!_thin_validate_device_id(message->u.m_trim.device_id)) if (!_thin_validate_device_id(id1))
return_0; 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; break;
case DM_THIN_MESSAGE_SET_TRANSACTION_ID: case DM_THIN_MESSAGE_SET_TRANSACTION_ID:
if (message->u.m_set_transaction_id.current_id != if ((id1 + 1) != id2) {
(message->u.m_set_transaction_id.new_id - 1)) { log_error("New transaction id must be sequential.");
log_error("New transaction_id must be sequential.");
return 0; /* FIXME: Maybe too strict here? */ 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; break;
default: default:
log_error("Unsupported message type %d.", (int) message->type); log_error("Unsupported message type %d.", (int) type);
return 0; return 0;
} }
tm->message.type = message->type; tm->message.type = type;
dm_list_add(&seg->thin_messages, &tm->list); dm_list_add(&seg->thin_messages, &tm->list);
return 1; return 1;