mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
virlog: Convert virLogFilters to a list of pointers to filters
Same as with outputs; since the operations will be further divided into smaller tasks, creating a filter will become a separate operation that will return a reference to a newly created filter. Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
+26
-19
@@ -90,8 +90,8 @@ typedef struct _virLogFilter virLogFilter;
|
|||||||
typedef virLogFilter *virLogFilterPtr;
|
typedef virLogFilter *virLogFilterPtr;
|
||||||
|
|
||||||
static int virLogFiltersSerial = 1;
|
static int virLogFiltersSerial = 1;
|
||||||
static virLogFilterPtr virLogFilters;
|
static virLogFilterPtr *virLogFilters;
|
||||||
static int virLogNbFilters;
|
static size_t virLogNbFilters;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Outputs are used to emit the messages retained
|
* Outputs are used to emit the messages retained
|
||||||
@@ -245,8 +245,10 @@ virLogResetFilters(void)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < virLogNbFilters; i++)
|
for (i = 0; i < virLogNbFilters; i++) {
|
||||||
VIR_FREE(virLogFilters[i].match);
|
VIR_FREE(virLogFilters[i]->match);
|
||||||
|
VIR_FREE(virLogFilters[i]);
|
||||||
|
}
|
||||||
VIR_FREE(virLogFilters);
|
VIR_FREE(virLogFilters);
|
||||||
virLogNbFilters = 0;
|
virLogNbFilters = 0;
|
||||||
virLogFiltersSerial++;
|
virLogFiltersSerial++;
|
||||||
@@ -274,6 +276,7 @@ virLogDefineFilter(const char *match,
|
|||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *mdup = NULL;
|
char *mdup = NULL;
|
||||||
|
virLogFilterPtr filter = NULL;
|
||||||
|
|
||||||
virCheckFlags(VIR_LOG_STACK_TRACE, -1);
|
virCheckFlags(VIR_LOG_STACK_TRACE, -1);
|
||||||
|
|
||||||
@@ -286,8 +289,8 @@ virLogDefineFilter(const char *match,
|
|||||||
|
|
||||||
virLogLock();
|
virLogLock();
|
||||||
for (i = 0; i < virLogNbFilters; i++) {
|
for (i = 0; i < virLogNbFilters; i++) {
|
||||||
if (STREQ(virLogFilters[i].match, match)) {
|
if (STREQ(virLogFilters[i]->match, match)) {
|
||||||
virLogFilters[i].priority = priority;
|
virLogFilters[i]->priority = priority;
|
||||||
ret = i;
|
ret = i;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@@ -295,21 +298,25 @@ virLogDefineFilter(const char *match,
|
|||||||
|
|
||||||
if (VIR_STRDUP_QUIET(mdup, match) < 0)
|
if (VIR_STRDUP_QUIET(mdup, match) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (VIR_REALLOC_N_QUIET(virLogFilters, virLogNbFilters + 1)) {
|
|
||||||
|
if (VIR_ALLOC_QUIET(filter) < 0) {
|
||||||
VIR_FREE(mdup);
|
VIR_FREE(mdup);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret = virLogNbFilters;
|
|
||||||
virLogFilters[i].match = mdup;
|
filter->match = mdup;
|
||||||
virLogFilters[i].priority = priority;
|
filter->priority = priority;
|
||||||
virLogFilters[i].flags = flags;
|
filter->flags = flags;
|
||||||
virLogNbFilters++;
|
|
||||||
|
if (VIR_APPEND_ELEMENT_QUIET(virLogFilters, virLogNbFilters, filter) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
virLogFiltersSerial++;
|
virLogFiltersSerial++;
|
||||||
cleanup:
|
cleanup:
|
||||||
virLogUnlock();
|
virLogUnlock();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return ret;
|
return virLogNbFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -475,9 +482,9 @@ virLogSourceUpdate(virLogSourcePtr source)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < virLogNbFilters; i++) {
|
for (i = 0; i < virLogNbFilters; i++) {
|
||||||
if (strstr(source->name, virLogFilters[i].match)) {
|
if (strstr(source->name, virLogFilters[i]->match)) {
|
||||||
priority = virLogFilters[i].priority;
|
priority = virLogFilters[i]->priority;
|
||||||
flags = virLogFilters[i].flags;
|
flags = virLogFilters[i]->flags;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1335,12 +1342,12 @@ virLogGetFilters(void)
|
|||||||
virLogLock();
|
virLogLock();
|
||||||
for (i = 0; i < virLogNbFilters; i++) {
|
for (i = 0; i < virLogNbFilters; i++) {
|
||||||
const char *sep = ":";
|
const char *sep = ":";
|
||||||
if (virLogFilters[i].flags & VIR_LOG_STACK_TRACE)
|
if (virLogFilters[i]->flags & VIR_LOG_STACK_TRACE)
|
||||||
sep = ":+";
|
sep = ":+";
|
||||||
virBufferAsprintf(&filterbuf, "%d%s%s ",
|
virBufferAsprintf(&filterbuf, "%d%s%s ",
|
||||||
virLogFilters[i].priority,
|
virLogFilters[i]->priority,
|
||||||
sep,
|
sep,
|
||||||
virLogFilters[i].match);
|
virLogFilters[i]->match);
|
||||||
}
|
}
|
||||||
virLogUnlock();
|
virLogUnlock();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user