mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-19 14:04:17 +03:00
libdm: relocate parsing of thin-pool status
Use single routine for parsing status. Internally we do not need to allocate pool memory for passed struct.
This commit is contained in:
parent
5ce334923f
commit
a3c7e326c3
@ -1,5 +1,6 @@
|
||||
Version 1.02.107 -
|
||||
===================================
|
||||
Parse thin-pool status with one single routine internally.
|
||||
Fix devmapper.pc pkgconfig file to not reference non-existent rt.pc file.
|
||||
Reinstate dm_task_get_info@Base to libdevmapper exports. (1.02.106)
|
||||
|
||||
|
@ -1427,7 +1427,50 @@ static int _suspend_node(const char *name, uint32_t major, uint32_t minor,
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _thin_pool_status_transaction_id(struct dm_tree_node *dnode, uint64_t *transaction_id)
|
||||
static int _thin_pool_parse_status(const char *params,
|
||||
struct dm_status_thin_pool *s)
|
||||
{
|
||||
int pos;
|
||||
|
||||
if (!params) {
|
||||
log_error("Failed to parse invalid thin params.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: add support for held metadata root */
|
||||
if (sscanf(params, FMTu64 " " FMTu64 "/" FMTu64 " " FMTu64 "/" FMTu64 "%n",
|
||||
&s->transaction_id,
|
||||
&s->used_metadata_blocks,
|
||||
&s->total_metadata_blocks,
|
||||
&s->used_data_blocks,
|
||||
&s->total_data_blocks, &pos) < 5) {
|
||||
log_error("Failed to parse thin pool params: %s.", params);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* New status flags */
|
||||
if (strstr(params + pos, "no_discard_passdown"))
|
||||
s->discards = DM_THIN_DISCARDS_NO_PASSDOWN;
|
||||
else if (strstr(params + pos, "ignore_discard"))
|
||||
s->discards = DM_THIN_DISCARDS_IGNORE;
|
||||
else /* default discard_passdown */
|
||||
s->discards = DM_THIN_DISCARDS_PASSDOWN;
|
||||
|
||||
if (strstr(params + pos, "ro "))
|
||||
s->read_only = 1;
|
||||
else if (strstr(params + pos, "fail"))
|
||||
s->fail = 1;
|
||||
else if (strstr(params + pos, "out_of_data_space"))
|
||||
s->out_of_data_space = 1;
|
||||
|
||||
if (strstr(params + pos, "error_if_no_space"))
|
||||
s->error_if_no_space = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _thin_pool_get_status(struct dm_tree_node *dnode,
|
||||
struct dm_status_thin_pool *s)
|
||||
{
|
||||
struct dm_task *dmt;
|
||||
int r = 0;
|
||||
@ -1458,14 +1501,12 @@ static int _thin_pool_status_transaction_id(struct dm_tree_node *dnode, uint64_t
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!params || (sscanf(params, FMTu64, transaction_id) != 1)) {
|
||||
log_error("Failed to parse transaction_id from %s.", params);
|
||||
goto out;
|
||||
}
|
||||
if (!_thin_pool_parse_status(params, s))
|
||||
goto_out;
|
||||
|
||||
log_debug_activation("Found transaction id %" PRIu64 " for thin pool %s "
|
||||
"with status line: %s.",
|
||||
*transaction_id, _node_name(dnode), params);
|
||||
s->transaction_id, _node_name(dnode), params);
|
||||
|
||||
r = 1;
|
||||
out:
|
||||
@ -1553,7 +1594,7 @@ static int _node_send_messages(struct dm_tree_node *dnode,
|
||||
{
|
||||
struct load_segment *seg;
|
||||
struct thin_message *tmsg;
|
||||
uint64_t trans_id;
|
||||
struct dm_status_thin_pool stp = { 0 };
|
||||
const char *uuid;
|
||||
int have_messages;
|
||||
|
||||
@ -1572,23 +1613,23 @@ static int _node_send_messages(struct dm_tree_node *dnode,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!_thin_pool_status_transaction_id(dnode, &trans_id))
|
||||
if (!_thin_pool_get_status(dnode, &stp))
|
||||
return_0;
|
||||
|
||||
have_messages = !dm_list_empty(&seg->thin_messages) ? 1 : 0;
|
||||
if (trans_id == seg->transaction_id) {
|
||||
if (stp.transaction_id == seg->transaction_id) {
|
||||
dnode->props.send_messages = 0; /* messages already committed */
|
||||
if (have_messages)
|
||||
log_debug_activation("Thin pool %s transaction_id matches %"
|
||||
PRIu64 ", skipping messages.",
|
||||
_node_name(dnode), trans_id);
|
||||
_node_name(dnode), stp.transaction_id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Error if there are no stacked messages or id mismatches */
|
||||
if ((trans_id + 1) != seg->transaction_id) {
|
||||
if ((stp.transaction_id + 1) != seg->transaction_id) {
|
||||
log_error("Thin pool %s transaction_id is %" PRIu64 ", while expected %" PRIu64 ".",
|
||||
_node_name(dnode), trans_id, seg->transaction_id - have_messages);
|
||||
_node_name(dnode), stp.transaction_id, seg->transaction_id - have_messages);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1599,12 +1640,12 @@ static int _node_send_messages(struct dm_tree_node *dnode,
|
||||
if (!(_thin_pool_node_message(dnode, tmsg)))
|
||||
return_0;
|
||||
if (tmsg->message.type == DM_THIN_MESSAGE_SET_TRANSACTION_ID) {
|
||||
if (!_thin_pool_status_transaction_id(dnode, &trans_id))
|
||||
if (!_thin_pool_get_status(dnode, &stp))
|
||||
return_0;
|
||||
if (trans_id != tmsg->message.u.m_set_transaction_id.new_id) {
|
||||
if (stp.transaction_id != tmsg->message.u.m_set_transaction_id.new_id) {
|
||||
log_error("Thin pool %s transaction_id is %" PRIu64
|
||||
" and does not match expected %" PRIu64 ".",
|
||||
_node_name(dnode), trans_id,
|
||||
_node_name(dnode), stp.transaction_id,
|
||||
tmsg->message.u.m_set_transaction_id.new_id);
|
||||
return 0;
|
||||
}
|
||||
@ -4003,48 +4044,17 @@ int dm_get_status_thin_pool(struct dm_pool *mem, const char *params,
|
||||
struct dm_status_thin_pool **status)
|
||||
{
|
||||
struct dm_status_thin_pool *s;
|
||||
int pos;
|
||||
|
||||
if (!params) {
|
||||
log_error("Failed to parse invalid thin pool params.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(s = dm_pool_zalloc(mem, sizeof(struct dm_status_thin_pool)))) {
|
||||
log_error("Failed to allocate thin_pool status structure.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: add support for held metadata root */
|
||||
if (sscanf(params, FMTu64 " " FMTu64 "/" FMTu64 " " FMTu64 "/" FMTu64 "%n",
|
||||
&s->transaction_id,
|
||||
&s->used_metadata_blocks,
|
||||
&s->total_metadata_blocks,
|
||||
&s->used_data_blocks,
|
||||
&s->total_data_blocks, &pos) < 5) {
|
||||
if (!_thin_pool_parse_status(params, s)) {
|
||||
dm_pool_free(mem, s);
|
||||
log_error("Failed to parse thin pool params: %s.", params);
|
||||
return 0;
|
||||
return_0;
|
||||
}
|
||||
|
||||
/* New status flags */
|
||||
if (strstr(params + pos, "no_discard_passdown"))
|
||||
s->discards = DM_THIN_DISCARDS_NO_PASSDOWN;
|
||||
else if (strstr(params + pos, "ignore_discard"))
|
||||
s->discards = DM_THIN_DISCARDS_IGNORE;
|
||||
else /* default discard_passdown */
|
||||
s->discards = DM_THIN_DISCARDS_PASSDOWN;
|
||||
|
||||
if (strstr(params + pos, "ro "))
|
||||
s->read_only = 1;
|
||||
else if (strstr(params + pos, "fail"))
|
||||
s->fail = 1;
|
||||
else if (strstr(params + pos, "out_of_data_space"))
|
||||
s->out_of_data_space = 1;
|
||||
|
||||
if (strstr(params + pos, "error_if_no_space"))
|
||||
s->error_if_no_space = 1;
|
||||
|
||||
*status = s;
|
||||
|
||||
return 1;
|
||||
@ -4055,11 +4065,6 @@ int dm_get_status_thin(struct dm_pool *mem, const char *params,
|
||||
{
|
||||
struct dm_status_thin *s;
|
||||
|
||||
if (!params) {
|
||||
log_error("Failed to parse invalid thin params.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(s = dm_pool_zalloc(mem, sizeof(struct dm_status_thin)))) {
|
||||
log_error("Failed to allocate thin status structure.");
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user