1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-23 21:35:29 +03:00

Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit).

This commit is contained in:
Peter Rajnoha 2010-09-20 14:23:20 +00:00
parent 4f60a6ea02
commit f900ddb544
4 changed files with 45 additions and 21 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.74 -
==================================
Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit).
Add random suffix to archive file names to prevent races when being created.
Reinitialize archive and backup handling on toolcontext refresh.
Fix opprobriously slow I/O to cluster mirrors created with --nosync.

View File

@ -366,6 +366,7 @@ static int _print_flag_config(struct formatter *f, uint64_t status, int type)
static int _print_vg(struct formatter *f, struct volume_group *vg)
{
char buffer[4096];
char *tag_buffer = NULL;
if (!id_write_format(&vg->id, buffer, sizeof(buffer)))
return_0;
@ -378,9 +379,10 @@ static int _print_vg(struct formatter *f, struct volume_group *vg)
return_0;
if (!dm_list_empty(&vg->tags)) {
if (!print_tags(&vg->tags, buffer, sizeof(buffer)))
if (!(tag_buffer = alloc_printed_tags(&vg->tags)))
return_0;
outf(f, "tags = %s", buffer);
outf(f, "tags = %s", tag_buffer);
dm_free(tag_buffer);
}
if (vg->system_id && *vg->system_id)
@ -426,7 +428,7 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg)
struct pv_list *pvl;
struct physical_volume *pv;
char buffer[4096];
char *buf;
char *buf, *tag_buffer = NULL;
const char *name;
outf(f, "physical_volumes {");
@ -461,9 +463,10 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg)
return_0;
if (!dm_list_empty(&pv->tags)) {
if (!print_tags(&pv->tags, buffer, sizeof(buffer)))
if (!(tag_buffer = alloc_printed_tags(&pv->tags)))
return_0;
outf(f, "tags = %s", buffer);
outf(f, "tags = %s", tag_buffer);
dm_free(tag_buffer);
}
outsize(f, pv->size, "dev_size = %" PRIu64, pv->size);
@ -484,7 +487,7 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg)
static int _print_segment(struct formatter *f, struct volume_group *vg,
int count, struct lv_segment *seg)
{
char buffer[4096];
char *tag_buffer = NULL;
outf(f, "segment%u {", count);
_inc_indent(f);
@ -497,9 +500,10 @@ static int _print_segment(struct formatter *f, struct volume_group *vg,
outf(f, "type = \"%s\"", seg->segtype->name);
if (!dm_list_empty(&seg->tags)) {
if (!print_tags(&seg->tags, buffer, sizeof(buffer)))
if (!(tag_buffer = alloc_printed_tags(&seg->tags)))
return_0;
outf(f, "tags = %s", buffer);
outf(f, "tags = %s", tag_buffer);
dm_free(tag_buffer);
}
if (seg->segtype->ops->text_export &&
@ -553,6 +557,7 @@ static int _print_lv(struct formatter *f, struct logical_volume *lv)
{
struct lv_segment *seg;
char buffer[4096];
char *tag_buffer = NULL;
int seg_count;
outnl(f);
@ -569,9 +574,10 @@ static int _print_lv(struct formatter *f, struct logical_volume *lv)
return_0;
if (!dm_list_empty(&lv->tags)) {
if (!print_tags(&lv->tags, buffer, sizeof(buffer)))
if (!(tag_buffer = alloc_printed_tags(&lv->tags)))
return_0;
outf(f, "tags = %s", buffer);
outf(f, "tags = %s", tag_buffer);
dm_free(tag_buffer);
}
if (lv->alloc != ALLOC_INHERIT)

View File

@ -61,7 +61,7 @@ struct text_vg_version_ops *text_vg_vsn1_init(void);
int print_flags(uint64_t status, int type, char *buffer, size_t size);
int read_flags(uint64_t *status, int type, struct config_value *cv);
int print_tags(struct dm_list *tags, char *buffer, size_t size);
char *alloc_printed_tags(struct dm_list *tags);
int read_tags(struct dm_pool *mem, struct dm_list *tags, struct config_value *cv);
int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp);

View File

@ -19,29 +19,46 @@
#include "str_list.h"
#include "lvm-string.h"
int print_tags(struct dm_list *tags, char *buffer, size_t size)
char *alloc_printed_tags(struct dm_list *tags)
{
struct str_list *sl;
int first = 1;
size_t size = 0;
char *buffer, *buf;
if (!emit_to_buffer(&buffer, &size, "["))
return_0;
dm_list_iterate_items(sl, tags)
/* '"' + tag + '"' + ',' + ' ' */
size += strlen(sl->str) + 4;
/* '[' + ']' + '\0' */
size += 3;
if (!(buffer = buf = dm_malloc(size))) {
log_error("Could not allocate memory for tag list buffer.");
return NULL;
}
if (!emit_to_buffer(&buf, &size, "["))
goto bad;
dm_list_iterate_items(sl, tags) {
if (!first) {
if (!emit_to_buffer(&buffer, &size, ", "))
return_0;
if (!emit_to_buffer(&buf, &size, ", "))
goto bad;
} else
first = 0;
if (!emit_to_buffer(&buffer, &size, "\"%s\"", sl->str))
return_0;
if (!emit_to_buffer(&buf, &size, "\"%s\"", sl->str))
goto bad;
}
if (!emit_to_buffer(&buffer, &size, "]"))
return_0;
if (!emit_to_buffer(&buf, &size, "]"))
goto bad;
return 1;
return buffer;
bad:
dm_free(buffer);
return_NULL;
}
int read_tags(struct dm_pool *mem, struct dm_list *tags, struct config_value *cv)