mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
style: Standardise some error paths.
This commit is contained in:
parent
f5a3b05c7a
commit
fb12308416
@ -1445,7 +1445,7 @@ static int disk_status_info(struct log_c *lc, struct dm_ulog_request *rq)
|
|||||||
char *data = (char *)rq->data;
|
char *data = (char *)rq->data;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
if(fstat(lc->disk_fd, &statbuf)) {
|
if (fstat(lc->disk_fd, &statbuf)) {
|
||||||
rq->error = -errno;
|
rq->error = -errno;
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
@ -1508,7 +1508,7 @@ static int disk_status_table(struct log_c *lc, struct dm_ulog_request *rq)
|
|||||||
char *data = (char *)rq->data;
|
char *data = (char *)rq->data;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
if(fstat(lc->disk_fd, &statbuf)) {
|
if (fstat(lc->disk_fd, &statbuf)) {
|
||||||
rq->error = -errno;
|
rq->error = -errno;
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
@ -578,7 +578,7 @@ static void mark_outdated_pv(lvmetad_state *s, const char *vgid, const char *pvi
|
|||||||
!(cft_vgid = make_text_node(outdated_pvs, "vgid", dm_pool_strdup(outdated_pvs->mem, vgid),
|
!(cft_vgid = make_text_node(outdated_pvs, "vgid", dm_pool_strdup(outdated_pvs->mem, vgid),
|
||||||
outdated_pvs->root, NULL)))
|
outdated_pvs->root, NULL)))
|
||||||
abort();
|
abort();
|
||||||
if(!dm_hash_insert(s->vgid_to_outdated_pvs, cft_vgid->v->v.str, outdated_pvs))
|
if (!dm_hash_insert(s->vgid_to_outdated_pvs, cft_vgid->v->v.str, outdated_pvs))
|
||||||
abort();
|
abort();
|
||||||
DEBUGLOG(s, "created outdated_pvs list for VG %s", vgid);
|
DEBUGLOG(s, "created outdated_pvs list for VG %s", vgid);
|
||||||
}
|
}
|
||||||
|
@ -319,10 +319,11 @@ static struct pv_list *_copy_pvl(struct dm_pool *pvmem, struct pv_list *pvl_from
|
|||||||
if (!(pvl_to->pv = dm_pool_alloc(pvmem, sizeof(*pvl_to->pv))))
|
if (!(pvl_to->pv = dm_pool_alloc(pvmem, sizeof(*pvl_to->pv))))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
if(!_copy_pv(pvmem, pvl_to->pv, pvl_from->pv))
|
if (!_copy_pv(pvmem, pvl_to->pv, pvl_from->pv))
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
return pvl_to;
|
return pvl_to;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
dm_pool_free(pvmem, pvl_to);
|
dm_pool_free(pvmem, pvl_to);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -119,8 +119,8 @@ int dm_create_lockfile(const char *lockfile)
|
|||||||
char buffer[50];
|
char buffer[50];
|
||||||
int retries = 0;
|
int retries = 0;
|
||||||
|
|
||||||
if((fd = open(lockfile, O_CREAT | O_WRONLY,
|
if ((fd = open(lockfile, O_CREAT | O_WRONLY,
|
||||||
(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
|
(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) < 0) {
|
||||||
log_error("Cannot open lockfile [%s], error was [%s]",
|
log_error("Cannot open lockfile [%s], error was [%s]",
|
||||||
lockfile, strerror(errno));
|
lockfile, strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -4195,7 +4195,7 @@ static void _destroy_rows(struct dm_report *rh)
|
|||||||
* pool allocation this will also free all subsequently allocated
|
* pool allocation this will also free all subsequently allocated
|
||||||
* rows from the report and any associated string data.
|
* rows from the report and any associated string data.
|
||||||
*/
|
*/
|
||||||
if(rh->first_row)
|
if (rh->first_row)
|
||||||
dm_pool_free(rh->mem, rh->first_row);
|
dm_pool_free(rh->mem, rh->first_row);
|
||||||
rh->first_row = NULL;
|
rh->first_row = NULL;
|
||||||
dm_list_init(&rh->rows);
|
dm_list_init(&rh->rows);
|
||||||
|
@ -105,7 +105,7 @@ static char *_program_id_from_proc(void)
|
|||||||
|
|
||||||
if (!fgets(buf, sizeof(buf), comm)) {
|
if (!fgets(buf, sizeof(buf), comm)) {
|
||||||
log_error("Could not read from %s", PROC_SELF_COMM);
|
log_error("Could not read from %s", PROC_SELF_COMM);
|
||||||
if(fclose(comm))
|
if (fclose(comm))
|
||||||
stack;
|
stack;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ struct dm_stats *dm_stats_create(const char *program_id)
|
|||||||
|
|
||||||
/* FIXME: better hint. */
|
/* FIXME: better hint. */
|
||||||
if (!(dms->mem = dm_pool_create("stats_pool", 4096)))
|
if (!(dms->mem = dm_pool_create("stats_pool", 4096)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
if (!(dms->hist_mem = dm_pool_create("histogram_pool", hist_hint)))
|
if (!(dms->hist_mem = dm_pool_create("histogram_pool", hist_hint)))
|
||||||
return_0;
|
return_0;
|
||||||
@ -169,7 +169,8 @@ struct dm_stats *dm_stats_create(const char *program_id)
|
|||||||
dms->regions = NULL;
|
dms->regions = NULL;
|
||||||
|
|
||||||
return dms;
|
return dms;
|
||||||
out:
|
|
||||||
|
bad:
|
||||||
dm_free(dms);
|
dm_free(dms);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -354,7 +355,7 @@ static char *_build_histogram_arg(struct dm_histogram *bounds, int *precise)
|
|||||||
hist_len += 1 + (size_t) lround(log10(value));
|
hist_len += 1 + (size_t) lround(log10(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(hist_arg = dm_zalloc(hist_len))) {
|
if (!(hist_arg = dm_zalloc(hist_len))) {
|
||||||
log_error("Could not allocate memory for histogram argument.");
|
log_error("Could not allocate memory for histogram argument.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -373,14 +374,16 @@ static char *_build_histogram_arg(struct dm_histogram *bounds, int *precise)
|
|||||||
value = entry->upper / scale;
|
value = entry->upper / scale;
|
||||||
if ((l = dm_snprintf(arg, hist_len - len, FMTu64"%s", value,
|
if ((l = dm_snprintf(arg, hist_len - len, FMTu64"%s", value,
|
||||||
(last) ? "" : ",")) < 0)
|
(last) ? "" : ",")) < 0)
|
||||||
goto out;
|
goto_bad;
|
||||||
len += (size_t) l;
|
len += (size_t) l;
|
||||||
arg += (size_t) l;
|
arg += (size_t) l;
|
||||||
}
|
}
|
||||||
return hist_arg;
|
return hist_arg;
|
||||||
out:
|
|
||||||
|
bad:
|
||||||
log_error("Could not build histogram arguments.");
|
log_error("Could not build histogram arguments.");
|
||||||
dm_free(hist_arg);
|
dm_free(hist_arg);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,16 +395,17 @@ static struct dm_task *_stats_send_message(struct dm_stats *dms, char *msg)
|
|||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
if (!_set_stats_device(dms, dmt))
|
if (!_set_stats_device(dms, dmt))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
if (!dm_task_set_message(dmt, msg))
|
if (!dm_task_set_message(dmt, msg))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
if (!dm_task_run(dmt))
|
if (!dm_task_run(dmt))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
return dmt;
|
return dmt;
|
||||||
out:
|
|
||||||
|
bad:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -425,7 +429,7 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
|
|||||||
|
|
||||||
/* Advance past "histogram:". */
|
/* Advance past "histogram:". */
|
||||||
histogram = strchr(histogram, ':');
|
histogram = strchr(histogram, ':');
|
||||||
if(!histogram) {
|
if (!histogram) {
|
||||||
log_error("Could not parse histogram description.");
|
log_error("Could not parse histogram description.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -444,21 +448,23 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
|
|||||||
hist.region = region;
|
hist.region = region;
|
||||||
hist.dms = dms;
|
hist.dms = dms;
|
||||||
|
|
||||||
if(!dm_pool_grow_object(mem, &hist, sizeof(hist)))
|
if (!dm_pool_grow_object(mem, &hist, sizeof(hist)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
c = histogram;
|
c = histogram;
|
||||||
do {
|
do {
|
||||||
for(v = _valid_chars; *v; v++)
|
for (v = _valid_chars; *v; v++)
|
||||||
if (*c == *v)
|
if (*c == *v)
|
||||||
break;
|
break;
|
||||||
if(!*v)
|
if (!*v) {
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
|
|
||||||
if (*c == ',') {
|
if (*c == ',') {
|
||||||
log_error("Invalid histogram description: %s",
|
log_error("Invalid histogram description: %s",
|
||||||
histogram);
|
histogram);
|
||||||
goto out;
|
goto bad;
|
||||||
} else {
|
} else {
|
||||||
const char *val_start = c;
|
const char *val_start = c;
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
@ -467,15 +473,17 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
|
|||||||
this_val = strtoull(val_start, &endptr, 10);
|
this_val = strtoull(val_start, &endptr, 10);
|
||||||
if (!endptr) {
|
if (!endptr) {
|
||||||
log_error("Could not parse histogram boundary.");
|
log_error("Could not parse histogram boundary.");
|
||||||
goto out;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = endptr; /* Advance to units, comma, or end. */
|
c = endptr; /* Advance to units, comma, or end. */
|
||||||
|
|
||||||
if (*c == ',')
|
if (*c == ',')
|
||||||
c++;
|
c++;
|
||||||
else if (*c || (*c == ' ')) /* Expected ',' or NULL. */
|
else if (*c || (*c == ' ')) { /* Expected ',' or NULL. */
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
|
|
||||||
if (*c == ',')
|
if (*c == ',')
|
||||||
c++;
|
c++;
|
||||||
@ -484,7 +492,7 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
|
|||||||
cur.count = 0;
|
cur.count = 0;
|
||||||
|
|
||||||
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
nr_bins++;
|
nr_bins++;
|
||||||
}
|
}
|
||||||
@ -493,7 +501,7 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
|
|||||||
/* final upper bound. */
|
/* final upper bound. */
|
||||||
cur.upper = UINT64_MAX;
|
cur.upper = UINT64_MAX;
|
||||||
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
region->bounds = dm_pool_end_object(mem);
|
region->bounds = dm_pool_end_object(mem);
|
||||||
|
|
||||||
@ -507,7 +515,7 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
|
|||||||
|
|
||||||
badchar:
|
badchar:
|
||||||
log_error("Invalid character in histogram: '%c' (0x%x)", *c, *c);
|
log_error("Invalid character in histogram: '%c' (0x%x)", *c, *c);
|
||||||
out:
|
bad:
|
||||||
dm_pool_abandon_object(mem);
|
dm_pool_abandon_object(mem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -614,12 +622,12 @@ static int _stats_parse_list(struct dm_stats *dms, const char *resp)
|
|||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
if (!dm_pool_begin_object(mem, 1024))
|
if (!dm_pool_begin_object(mem, 1024))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
while(fgets(line, sizeof(line), list_rows)) {
|
while(fgets(line, sizeof(line), list_rows)) {
|
||||||
|
|
||||||
if (!_stats_parse_list_region(dms, &cur, line))
|
if (!_stats_parse_list_region(dms, &cur, line))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
/* handle holes in the list of region_ids */
|
/* handle holes in the list of region_ids */
|
||||||
if (cur.region_id > max_region) {
|
if (cur.region_id > max_region) {
|
||||||
@ -628,12 +636,12 @@ static int _stats_parse_list(struct dm_stats *dms, const char *resp)
|
|||||||
fill.region_id = DM_STATS_REGION_NOT_PRESENT;
|
fill.region_id = DM_STATS_REGION_NOT_PRESENT;
|
||||||
do {
|
do {
|
||||||
if (!dm_pool_grow_object(mem, &fill, sizeof(fill)))
|
if (!dm_pool_grow_object(mem, &fill, sizeof(fill)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
} while (max_region++ < (cur.region_id - 1));
|
} while (max_region++ < (cur.region_id - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
max_region++;
|
max_region++;
|
||||||
nr_regions++;
|
nr_regions++;
|
||||||
@ -647,10 +655,12 @@ static int _stats_parse_list(struct dm_stats *dms, const char *resp)
|
|||||||
stack;
|
stack;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
out:
|
|
||||||
if(fclose(list_rows))
|
bad:
|
||||||
|
if (fclose(list_rows))
|
||||||
stack;
|
stack;
|
||||||
dm_pool_abandon_object(mem);
|
dm_pool_abandon_object(mem);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,17 +685,17 @@ int dm_stats_list(struct dm_stats *dms, const char *program_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(dmt = _stats_send_message(dms, msg)))
|
if (!(dmt = _stats_send_message(dms, msg)))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
if (!_stats_parse_list(dms, dm_task_get_message_response(dmt))) {
|
if (!_stats_parse_list(dms, dm_task_get_message_response(dmt))) {
|
||||||
log_error("Could not parse @stats_list response.");
|
log_error("Could not parse @stats_list response.");
|
||||||
goto out;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
out:
|
bad:
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -715,15 +725,17 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
memset(&cur, 0, sizeof(cur));
|
memset(&cur, 0, sizeof(cur));
|
||||||
for(v = _valid_chars; *v; v++)
|
for (v = _valid_chars; *v; v++)
|
||||||
if (*c == *v)
|
if (*c == *v)
|
||||||
break;
|
break;
|
||||||
if(!*v)
|
if (!*v) {
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
|
|
||||||
if (*c == ',') {
|
if (*c == ',') {
|
||||||
log_error("Invalid histogram: %s", hist_str);
|
log_error("Invalid histogram: %s", hist_str);
|
||||||
goto out;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
const char *val_start = c;
|
const char *val_start = c;
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
@ -732,15 +744,17 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
this_val = strtoull(val_start, &endptr, 10);
|
this_val = strtoull(val_start, &endptr, 10);
|
||||||
if (!endptr) {
|
if (!endptr) {
|
||||||
log_error("Could not parse histogram value.");
|
log_error("Could not parse histogram value.");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
c = endptr; /* Advance to colon, or end. */
|
c = endptr; /* Advance to colon, or end. */
|
||||||
|
|
||||||
if (*c == ':')
|
if (*c == ':')
|
||||||
c++;
|
c++;
|
||||||
else if (*c & (*c != '\n'))
|
else if (*c & (*c != '\n')) {
|
||||||
/* Expected ':', '\n', or NULL. */
|
/* Expected ':', '\n', or NULL. */
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
|
|
||||||
if (*c == ':')
|
if (*c == ':')
|
||||||
c++;
|
c++;
|
||||||
@ -764,7 +778,6 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
|
|||||||
|
|
||||||
badchar:
|
badchar:
|
||||||
log_error("Invalid character in histogram data: '%c' (0x%x)", *c, *c);
|
log_error("Invalid character in histogram data: '%c' (0x%x)", *c, *c);
|
||||||
out:
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,7 +801,7 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
|
|||||||
region->start = UINT64_MAX;
|
region->start = UINT64_MAX;
|
||||||
|
|
||||||
if (!dm_pool_begin_object(mem, 512))
|
if (!dm_pool_begin_object(mem, 512))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dm_task_get_message_response() returns a 'const char *' but
|
* dm_task_get_message_response() returns a 'const char *' but
|
||||||
@ -796,7 +809,7 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
|
|||||||
*/
|
*/
|
||||||
stats_rows = fmemopen((char *)resp, strlen(resp), "r");
|
stats_rows = fmemopen((char *)resp, strlen(resp), "r");
|
||||||
if (!stats_rows)
|
if (!stats_rows)
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output format for each step-sized area of a region:
|
* Output format for each step-sized area of a region:
|
||||||
@ -844,7 +857,7 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
|
|||||||
&cur.total_read_nsecs, &cur.total_write_nsecs);
|
&cur.total_read_nsecs, &cur.total_write_nsecs);
|
||||||
if (r != 15) {
|
if (r != 15) {
|
||||||
log_error("Could not parse @stats_print row.");
|
log_error("Could not parse @stats_print row.");
|
||||||
goto out;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scale time values up if needed */
|
/* scale time values up if needed */
|
||||||
@ -862,7 +875,7 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
|
|||||||
char *hist_str = strchr(row, ':');
|
char *hist_str = strchr(row, ':');
|
||||||
if (!hist_str) {
|
if (!hist_str) {
|
||||||
log_error("Could not parse histogram value.");
|
log_error("Could not parse histogram value.");
|
||||||
goto out;
|
goto bad;
|
||||||
}
|
}
|
||||||
/* Find space preceding histogram. */
|
/* Find space preceding histogram. */
|
||||||
while (hist_str && *(hist_str - 1) != ' ')
|
while (hist_str && *(hist_str - 1) != ' ')
|
||||||
@ -874,15 +887,15 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
|
|||||||
*/
|
*/
|
||||||
if (!_stats_parse_histogram(dms->hist_mem, hist_str,
|
if (!_stats_parse_histogram(dms->hist_mem, hist_str,
|
||||||
&hist, region))
|
&hist, region))
|
||||||
goto out;
|
goto_bad;
|
||||||
hist->dms = dms;
|
hist->dms = dms;
|
||||||
hist->region = region;
|
hist->region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur.histogram = hist;
|
cur.histogram = hist;
|
||||||
|
|
||||||
if(!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
if (!dm_pool_grow_object(mem, &cur, sizeof(cur)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
if (region->start == UINT64_MAX) {
|
if (region->start == UINT64_MAX) {
|
||||||
region->start = start;
|
region->start = start;
|
||||||
@ -899,12 +912,12 @@ static int _stats_parse_region(struct dm_stats *dms, const char *resp,
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
out:
|
bad:
|
||||||
|
|
||||||
if (stats_rows)
|
if (stats_rows)
|
||||||
if(fclose(stats_rows))
|
if (fclose(stats_rows))
|
||||||
stack;
|
stack;
|
||||||
dm_pool_abandon_object(mem);
|
dm_pool_abandon_object(mem);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1017,7 +1030,7 @@ int dm_stats_get_region_nr_histogram_bins(const struct dm_stats *dms,
|
|||||||
? dms->cur_region : region_id ;
|
? dms->cur_region : region_id ;
|
||||||
|
|
||||||
if (!dms->regions[region_id].bounds)
|
if (!dms->regions[region_id].bounds)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
return dms->regions[region_id].bounds->nr_bins;
|
return dms->regions[region_id].bounds->nr_bins;
|
||||||
}
|
}
|
||||||
@ -1083,7 +1096,7 @@ static int _stats_create_region(struct dm_stats *dms, uint64_t *region_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(dmt = _stats_send_message(dms, msg)))
|
if (!(dmt = _stats_send_message(dms, msg)))
|
||||||
goto out;
|
goto_out;
|
||||||
|
|
||||||
resp = dm_task_get_message_response(dmt);
|
resp = dm_task_get_message_response(dmt);
|
||||||
if (!resp) {
|
if (!resp) {
|
||||||
@ -1101,9 +1114,10 @@ static int _stats_create_region(struct dm_stats *dms, uint64_t *region_id,
|
|||||||
r = 1;
|
r = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if(dmt)
|
if (dmt)
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
dm_free((void *) opt_args);
|
dm_free((void *) opt_args);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1116,9 +1130,8 @@ int dm_stats_create_region(struct dm_stats *dms, uint64_t *region_id,
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
/* Nanosecond counters and histograms both need precise_timestamps. */
|
/* Nanosecond counters and histograms both need precise_timestamps. */
|
||||||
if ((precise || bounds)
|
if ((precise || bounds) && !_stats_check_precise_timestamps(dms))
|
||||||
&& !_stats_check_precise_timestamps(dms))
|
return_0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (bounds) {
|
if (bounds) {
|
||||||
/* _build_histogram_arg enables precise if vals < 1ms. */
|
/* _build_histogram_arg enables precise if vals < 1ms. */
|
||||||
@ -1129,6 +1142,7 @@ int dm_stats_create_region(struct dm_stats *dms, uint64_t *region_id,
|
|||||||
r = _stats_create_region(dms, region_id, start, len, step,
|
r = _stats_create_region(dms, region_id, start, len, step,
|
||||||
precise, hist_arg, program_id, aux_data);
|
precise, hist_arg, program_id, aux_data);
|
||||||
dm_free(hist_arg);
|
dm_free(hist_arg);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -1143,17 +1157,15 @@ int dm_stats_delete_region(struct dm_stats *dms, uint64_t region_id)
|
|||||||
|
|
||||||
if (!dm_snprintf(msg, sizeof(msg), "@stats_delete " FMTu64, region_id)) {
|
if (!dm_snprintf(msg, sizeof(msg), "@stats_delete " FMTu64, region_id)) {
|
||||||
log_error("Could not prepare @stats_delete message.");
|
log_error("Could not prepare @stats_delete message.");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmt = _stats_send_message(dms, msg);
|
dmt = _stats_send_message(dms, msg);
|
||||||
if (!dmt)
|
if (!dmt)
|
||||||
goto_out;
|
return_0;
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
return 1;
|
|
||||||
|
|
||||||
out:
|
return 1;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dm_stats_clear_region(struct dm_stats *dms, uint64_t region_id)
|
int dm_stats_clear_region(struct dm_stats *dms, uint64_t region_id)
|
||||||
@ -1166,17 +1178,17 @@ int dm_stats_clear_region(struct dm_stats *dms, uint64_t region_id)
|
|||||||
|
|
||||||
if (!dm_snprintf(msg, sizeof(msg), "@stats_clear " FMTu64, region_id)) {
|
if (!dm_snprintf(msg, sizeof(msg), "@stats_clear " FMTu64, region_id)) {
|
||||||
log_error("Could not prepare @stats_clear message.");
|
log_error("Could not prepare @stats_clear message.");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmt = _stats_send_message(dms, msg);
|
dmt = _stats_send_message(dms, msg);
|
||||||
if (!dmt)
|
|
||||||
goto_out;
|
|
||||||
dm_task_destroy(dmt);
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
out:
|
if (!dmt)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
|
dm_task_destroy(dmt);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dm_task *_stats_print_region(struct dm_stats *dms,
|
static struct dm_task *_stats_print_region(struct dm_stats *dms,
|
||||||
@ -1194,22 +1206,19 @@ static struct dm_task *_stats_print_region(struct dm_stats *dms,
|
|||||||
if (!dm_snprintf(lines, sizeof(lines),
|
if (!dm_snprintf(lines, sizeof(lines),
|
||||||
lines_fmt, start_line, num_lines)) {
|
lines_fmt, start_line, num_lines)) {
|
||||||
log_error(err_fmt, "row specification");
|
log_error(err_fmt, "row specification");
|
||||||
goto out;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_snprintf(msg, sizeof(msg), msg_fmt, (clear) ? clear_str : "",
|
if (!dm_snprintf(msg, sizeof(msg), msg_fmt, (clear) ? clear_str : "",
|
||||||
region_id, (start_line || num_lines) ? lines : "")) {
|
region_id, (start_line || num_lines) ? lines : "")) {
|
||||||
log_error(err_fmt, "message");
|
log_error(err_fmt, "message");
|
||||||
goto out;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(dmt = _stats_send_message(dms, msg)))
|
if (!(dmt = _stats_send_message(dms, msg)))
|
||||||
goto out;
|
return_NULL;
|
||||||
|
|
||||||
return dmt;
|
return dmt;
|
||||||
|
|
||||||
out:
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *dm_stats_print_region(struct dm_stats *dms, uint64_t region_id,
|
char *dm_stats_print_region(struct dm_stats *dms, uint64_t region_id,
|
||||||
@ -1226,7 +1235,7 @@ char *dm_stats_print_region(struct dm_stats *dms, uint64_t region_id,
|
|||||||
start_line, num_lines, clear);
|
start_line, num_lines, clear);
|
||||||
|
|
||||||
if (!dmt)
|
if (!dmt)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
resp = dm_pool_strdup(dms->mem, dm_task_get_message_response(dmt));
|
resp = dm_pool_strdup(dms->mem, dm_task_get_message_response(dmt));
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
@ -1245,7 +1254,7 @@ void dm_stats_buffer_destroy(struct dm_stats *dms, char *buffer)
|
|||||||
uint64_t dm_stats_get_nr_regions(const struct dm_stats *dms)
|
uint64_t dm_stats_get_nr_regions(const struct dm_stats *dms)
|
||||||
{
|
{
|
||||||
if (!dms || !dms->regions)
|
if (!dms || !dms->regions)
|
||||||
return 0;
|
return_0;
|
||||||
return dms->nr_regions;
|
return dms->nr_regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1255,10 +1264,10 @@ uint64_t dm_stats_get_nr_regions(const struct dm_stats *dms)
|
|||||||
int dm_stats_region_present(const struct dm_stats *dms, uint64_t region_id)
|
int dm_stats_region_present(const struct dm_stats *dms, uint64_t region_id)
|
||||||
{
|
{
|
||||||
if (!dms->regions)
|
if (!dms->regions)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
if (region_id > dms->max_region)
|
if (region_id > dms->max_region)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
return _stats_region_present(&dms->regions[region_id]);
|
return _stats_region_present(&dms->regions[region_id]);
|
||||||
}
|
}
|
||||||
@ -1293,12 +1302,12 @@ int dm_stats_populate(struct dm_stats *dms, const char *program_id,
|
|||||||
|
|
||||||
if (all_regions && !dm_stats_list(dms, program_id)) {
|
if (all_regions && !dm_stats_list(dms, program_id)) {
|
||||||
log_error("Could not parse @stats_list response.");
|
log_error("Could not parse @stats_list response.");
|
||||||
goto out;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* successful list but no regions registered */
|
/* successful list but no regions registered */
|
||||||
if (!dms->nr_regions)
|
if (!dms->nr_regions)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
dm_stats_walk_start(dms);
|
dm_stats_walk_start(dms);
|
||||||
do {
|
do {
|
||||||
@ -1310,12 +1319,12 @@ int dm_stats_populate(struct dm_stats *dms, const char *program_id,
|
|||||||
|
|
||||||
/* obtain all lines and clear counter values */
|
/* obtain all lines and clear counter values */
|
||||||
if (!(dmt = _stats_print_region(dms, region_id, 0, 0, 1)))
|
if (!(dmt = _stats_print_region(dms, region_id, 0, 0, 1)))
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
resp = dm_task_get_message_response(dmt);
|
resp = dm_task_get_message_response(dmt);
|
||||||
if (!_dm_stats_populate_region(dms, region_id, resp)) {
|
if (!_dm_stats_populate_region(dms, region_id, resp)) {
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
goto_out;
|
goto_bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_task_destroy(dmt);
|
dm_task_destroy(dmt);
|
||||||
@ -1325,7 +1334,7 @@ int dm_stats_populate(struct dm_stats *dms, const char *program_id,
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
out:
|
bad:
|
||||||
_stats_regions_destroy(dms);
|
_stats_regions_destroy(dms);
|
||||||
dms->regions = NULL;
|
dms->regions = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
@ -1620,10 +1629,10 @@ int dm_stats_get_service_time(const struct dm_stats *dms, double *svctm,
|
|||||||
double tput;
|
double tput;
|
||||||
|
|
||||||
if (!dm_stats_get_throughput(dms, &tput, region_id, area_id))
|
if (!dm_stats_get_throughput(dms, &tput, region_id, area_id))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
if (!dm_stats_get_utilization(dms, &util, region_id, area_id))
|
if (!dm_stats_get_utilization(dms, &util, region_id, area_id))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
/* avoid NAN with zero counter values */
|
/* avoid NAN with zero counter values */
|
||||||
if ( (uint64_t) tput == 0 || (uint64_t) util == 0) {
|
if ( (uint64_t) tput == 0 || (uint64_t) util == 0) {
|
||||||
@ -1973,23 +1982,26 @@ struct dm_histogram *dm_histogram_bounds_from_string(const char *bounds_str)
|
|||||||
c = bounds_str;
|
c = bounds_str;
|
||||||
|
|
||||||
if (!(dmh = _alloc_dm_histogram(nr_entries)))
|
if (!(dmh = _alloc_dm_histogram(nr_entries)))
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
dmh->nr_bins = nr_entries;
|
dmh->nr_bins = nr_entries;
|
||||||
|
|
||||||
cur = dmh->bins;
|
cur = dmh->bins;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for(v = _valid_chars; *v; v++)
|
for (v = _valid_chars; *v; v++)
|
||||||
if (*c == *v)
|
if (*c == *v)
|
||||||
break;
|
break;
|
||||||
if(!*v)
|
|
||||||
|
if (!*v) {
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
|
|
||||||
if (*c == ',') {
|
if (*c == ',') {
|
||||||
log_error("Empty histogram bin not allowed: %s",
|
log_error("Empty histogram bin not allowed: %s",
|
||||||
bounds_str);
|
bounds_str);
|
||||||
goto out;
|
goto bad;
|
||||||
} else {
|
} else {
|
||||||
const char *val_start = c;
|
const char *val_start = c;
|
||||||
char *endptr = NULL;
|
char *endptr = NULL;
|
||||||
@ -1998,7 +2010,7 @@ struct dm_histogram *dm_histogram_bounds_from_string(const char *bounds_str)
|
|||||||
this_val = strtoull(val_start, &endptr, 10);
|
this_val = strtoull(val_start, &endptr, 10);
|
||||||
if (!endptr) {
|
if (!endptr) {
|
||||||
log_error("Could not parse histogram bound.");
|
log_error("Could not parse histogram bound.");
|
||||||
goto out;
|
goto bad;
|
||||||
}
|
}
|
||||||
c = endptr; /* Advance to units, comma, or end. */
|
c = endptr; /* Advance to units, comma, or end. */
|
||||||
|
|
||||||
@ -2012,13 +2024,17 @@ struct dm_histogram *dm_histogram_bounds_from_string(const char *bounds_str)
|
|||||||
mult = NSEC_PER_USEC;
|
mult = NSEC_PER_USEC;
|
||||||
else if (*c == 'n')
|
else if (*c == 'n')
|
||||||
mult = 1;
|
mult = 1;
|
||||||
else
|
else {
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
c += 2; /* Advance over 'ms', 'us', or 'ns'. */
|
c += 2; /* Advance over 'ms', 'us', or 'ns'. */
|
||||||
} else if (*c == ',')
|
} else if (*c == ',')
|
||||||
c++;
|
c++;
|
||||||
else if (*c) /* Expected ',' or NULL. */
|
else if (*c) { /* Expected ',' or NULL. */
|
||||||
|
stack;
|
||||||
goto badchar;
|
goto badchar;
|
||||||
|
}
|
||||||
|
|
||||||
if (*c == ',')
|
if (*c == ',')
|
||||||
c++;
|
c++;
|
||||||
@ -2035,7 +2051,7 @@ struct dm_histogram *dm_histogram_bounds_from_string(const char *bounds_str)
|
|||||||
|
|
||||||
badchar:
|
badchar:
|
||||||
log_error("Invalid character in histogram: %c", *c);
|
log_error("Invalid character in histogram: %c", *c);
|
||||||
out:
|
bad:
|
||||||
dm_free(dmh);
|
dm_free(dmh);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2121,7 +2137,7 @@ static int _make_bounds_string(char *buf, size_t size, uint64_t lower,
|
|||||||
int bounds = flags & DM_HISTOGRAM_BOUNDS_MASK;
|
int bounds = flags & DM_HISTOGRAM_BOUNDS_MASK;
|
||||||
|
|
||||||
if (!bounds)
|
if (!bounds)
|
||||||
return 0;
|
return_0;
|
||||||
|
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
|
|
||||||
@ -2258,14 +2274,15 @@ const char *dm_histogram_to_string(const struct dm_histogram *dmh, int bin,
|
|||||||
sep);
|
sep);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
goto_out;
|
goto_bad;
|
||||||
|
|
||||||
width = minwidth; /* re-set histogram column width. */
|
width = minwidth; /* re-set histogram column width. */
|
||||||
dm_pool_grow_object(mem, buf, (size_t) len);
|
dm_pool_grow_object(mem, buf, (size_t) len);
|
||||||
}
|
}
|
||||||
dm_pool_grow_object(mem, "\0", 1);
|
dm_pool_grow_object(mem, "\0", 1);
|
||||||
return (const char *) dm_pool_end_object(mem);
|
return (const char *) dm_pool_end_object(mem);
|
||||||
out:
|
|
||||||
|
bad:
|
||||||
dm_pool_abandon_object(mem);
|
dm_pool_abandon_object(mem);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -155,9 +155,8 @@ static struct dm_list *_lvm_list_pvs(lvm_t libh)
|
|||||||
} else {
|
} else {
|
||||||
dm_list_init(&rc->pvslist);
|
dm_list_init(&rc->pvslist);
|
||||||
dm_list_init(&rc->vgslist);
|
dm_list_init(&rc->vgslist);
|
||||||
if( !get_pvs_perserve_vg(cmd, &rc->pvslist, &rc->vgslist) ) {
|
if (!get_pvs_perserve_vg(cmd, &rc->pvslist, &rc->vgslist))
|
||||||
return NULL;
|
return_NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have no PVs we still need to have access to cmd
|
* If we have no PVs we still need to have access to cmd
|
||||||
|
475
tools/dmsetup.c
475
tools/dmsetup.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user