[libvirt] [PATCH v2 17/20] virlog: Remove functions that aren't used anywhere anymore

John Ferlan jferlan at redhat.com
Wed Sep 21 19:39:35 UTC 2016



On 08/18/2016 07:47 AM, Erik Skultety wrote:
> This is mainly virLogAddOutputTo* which were replaced by virLogNewOutputTo* and
> the previously poorly named ones virLogParseAndDefine* functions. All of these
> are unnecessary now, since all the original callers were transparently switched
> to the new model of separate parsing and defining logic.
> 
> Signed-off-by: Erik Skultety <eskultet at redhat.com>
> ---
>  src/libvirt_private.syms |   4 -
>  src/util/virlog.c        | 427 -----------------------------------------------
>  src/util/virlog.h        |  12 --
>  3 files changed, 443 deletions(-)
> 
NOTE:

My git am -3 failed on this patch:

Applying: virlog: Remove functions that aren't used anywhere anymore
fatal: sha1 information is lacking or useless (src/libvirt_private.syms).
error: could not build fake ancestor
Patch failed at 0017 virlog: Remove functions that aren't used anywhere
anymore
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

I'm really not sure why, but I

NOTE: Existing, but IS_SPACE isn't used either.

ACK - you could/should remove IS_SPACE separately and use this implied ACK

John

> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index fec0b8b..58d0d7e 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1842,9 +1842,7 @@ virLockSpaceReleaseResourcesForOwner;
>  
>  
>  # util/virlog.h
> -virLogDefineFilter;
>  virLogDefineFilters;
> -virLogDefineOutput;
>  virLogDefineOutputs;
>  virLogFilterFree;
>  virLogFilterListFree;
> @@ -1864,8 +1862,6 @@ virLogNewOutputToSyslog;
>  virLogOutputFree;
>  virLogOutputListFree;
>  virLogOutputNew;
> -virLogParseAndDefineFilters;
> -virLogParseAndDefineOutputs;
>  virLogParseDefaultPriority;
>  virLogParseFilter;
>  virLogParseFilters;
> diff --git a/src/util/virlog.c b/src/util/virlog.c
> index 36c3a38..12e6d94 100644
> --- a/src/util/virlog.c
> +++ b/src/util/virlog.c
> @@ -279,70 +279,6 @@ virLogFilterListFree(virLogFilterPtr *list, int count)
>  
>  
>  /**
> - * virLogDefineFilter:
> - * @match: the pattern to match
> - * @priority: the priority to give to messages matching the pattern
> - * @flags: extra flags, see virLogFilterFlags enum
> - *
> - * Defines a pattern used for log filtering, it allow to select or
> - * reject messages independently of the default priority.
> - * The filter defines a rules that will apply only to messages matching
> - * the pattern (currently if @match is a substring of the message category)
> - *
> - * Returns -1 in case of failure or the filter number if successful
> - */
> -int
> -virLogDefineFilter(const char *match,
> -                   virLogPriority priority,
> -                   unsigned int flags)
> -{
> -    size_t i;
> -    int ret = -1;
> -    char *mdup = NULL;
> -    virLogFilterPtr filter = NULL;
> -
> -    virCheckFlags(VIR_LOG_STACK_TRACE, -1);
> -
> -    if (virLogInitialize() < 0)
> -        return -1;
> -
> -    if ((match == NULL) || (priority < VIR_LOG_DEBUG) ||
> -        (priority > VIR_LOG_ERROR))
> -        return -1;
> -
> -    virLogLock();
> -    for (i = 0; i < virLogNbFilters; i++) {
> -        if (STREQ(virLogFilters[i]->match, match)) {
> -            virLogFilters[i]->priority = priority;
> -            ret = i;
> -            goto cleanup;
> -        }
> -    }
> -
> -    if (VIR_STRDUP_QUIET(mdup, match) < 0)
> -        goto cleanup;
> -
> -    if (VIR_ALLOC_QUIET(filter) < 0) {
> -        VIR_FREE(mdup);
> -        goto cleanup;
> -    }
> -
> -    filter->match = mdup;
> -    filter->priority = priority;
> -    filter->flags = flags;
> -
> -    if (VIR_APPEND_ELEMENT_QUIET(virLogFilters, virLogNbFilters, filter) < 0)
> -        goto cleanup;
> -
> -    virLogFiltersSerial++;
> - cleanup:
> -    virLogUnlock();
> -    if (ret < 0)
> -        virReportOOMError();
> -    return virLogNbFilters;
> -}
> -
> -/**
>   * virLogResetOutputs:
>   *
>   * Removes the set of logging output defined.
> @@ -390,73 +326,6 @@ virLogOutputListFree(virLogOutputPtr *list, int count)
>  }
>  
>  
> -/**
> - * virLogDefineOutput:
> - * @f: the function to call to output a message
> - * @c: the function to call to close the output (or NULL)
> - * @data: extra data passed as first arg to the function
> - * @priority: minimal priority for this filter, use 0 for none
> - * @dest: where to send output of this priority
> - * @name: optional name data associated with an output
> - * @flags: extra flag, currently unused
> - *
> - * Defines an output function for log messages. Each message once
> - * gone though filtering is emitted through each registered output.
> - *
> - * Returns -1 in case of failure or the output number if successful
> - */
> -int
> -virLogDefineOutput(virLogOutputFunc f,
> -                   virLogCloseFunc c,
> -                   void *data,
> -                   virLogPriority priority,
> -                   virLogDestination dest,
> -                   const char *name,
> -                   unsigned int flags)
> -{
> -    char *ndup = NULL;
> -    virLogOutputPtr output = NULL;
> -
> -    virCheckFlags(0, -1);
> -
> -    if (virLogInitialize() < 0)
> -        return -1;
> -
> -    if (f == NULL)
> -        return -1;
> -
> -    if (dest == VIR_LOG_TO_SYSLOG || dest == VIR_LOG_TO_FILE) {
> -        if (!name) {
> -            virReportOOMError();
> -            return -1;
> -        }
> -        if (VIR_STRDUP(ndup, name) < 0)
> -            return -1;
> -    }
> -
> -    if (VIR_ALLOC_QUIET(output) < 0) {
> -        VIR_FREE(ndup);
> -        return -1;
> -    }
> -
> -    output->logInitMessage = true;
> -    output->f = f;
> -    output->c = c;
> -    output->data = data;
> -    output->priority = priority;
> -    output->dest = dest;
> -    output->name = ndup;
> -
> -    virLogLock();
> -    if (VIR_APPEND_ELEMENT_QUIET(virLogOutputs, virLogNbOutputs, output))
> -        goto cleanup;
> -
> - cleanup:
> -    virLogUnlock();
> -    return virLogNbOutputs;
> -}
> -
> -
>  static int
>  virLogFormatString(char **msg,
>                     int linenr,
> @@ -770,16 +639,6 @@ virLogCloseFd(void *data)
>  }
>  
>  
> -static int
> -virLogAddOutputToStderr(virLogPriority priority)
> -{
> -    if (virLogDefineOutput(virLogOutputToFd, NULL, (void *)2L, priority,
> -                           VIR_LOG_TO_STDERR, NULL, 0) < 0)
> -        return -1;
> -    return 0;
> -}
> -
> -
>  virLogOutputPtr
>  virLogNewOutputToStderr(virLogPriority priority)
>  {
> @@ -788,25 +647,6 @@ virLogNewOutputToStderr(virLogPriority priority)
>  }
>  
>  
> -static int
> -virLogAddOutputToFile(virLogPriority priority,
> -                      const char *file)
> -{
> -    int fd;
> -
> -    fd = open(file, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR);
> -    if (fd < 0)
> -        return -1;
> -    if (virLogDefineOutput(virLogOutputToFd, virLogCloseFd,
> -                           (void *)(intptr_t)fd,
> -                           priority, VIR_LOG_TO_FILE, file, 0) < 0) {
> -        VIR_FORCE_CLOSE(fd);
> -        return -1;
> -    }
> -    return 0;
> -}
> -
> -
>  virLogOutputPtr
>  virLogNewOutputToFile(virLogPriority priority,
>                        const char *file)
> @@ -893,28 +733,6 @@ virLogCloseSyslog(void *data ATTRIBUTE_UNUSED)
>  }
>  
>  
> -static int
> -virLogAddOutputToSyslog(virLogPriority priority,
> -                        const char *ident)
> -{
> -    /*
> -     * ident needs to be kept around on Solaris
> -     */
> -    VIR_FREE(current_ident);
> -    if (VIR_STRDUP(current_ident, ident) < 0)
> -        return -1;
> -
> -    openlog(current_ident, 0, 0);
> -    if (virLogDefineOutput(virLogOutputToSyslog, virLogCloseSyslog, NULL,
> -                           priority, VIR_LOG_TO_SYSLOG, ident, 0) < 0) {
> -        closelog();
> -        VIR_FREE(current_ident);
> -        return -1;
> -    }
> -    return 0;
> -}
> -
> -
>  virLogOutputPtr
>  virLogNewOutputToSyslog(virLogPriority priority,
>                          const char *ident)
> @@ -1162,22 +980,6 @@ static void virLogCloseJournald(void *data ATTRIBUTE_UNUSED)
>  }
>  
>  
> -static int virLogAddOutputToJournald(int priority)
> -{
> -    if ((journalfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
> -        return -1;
> -    if (virSetInherit(journalfd, false) < 0) {
> -        VIR_LOG_CLOSE(journalfd);
> -        return -1;
> -    }
> -    if (virLogDefineOutput(virLogOutputToJournald, virLogCloseJournald, NULL,
> -                           priority, VIR_LOG_TO_JOURNALD, NULL, 0) < 0) {
> -        return -1;
> -    }
> -    return 0;
> -}
> -
> -
>  virLogOutputPtr
>  virLogNewOutputToJournald(int priority)
>  {
> @@ -1233,235 +1035,6 @@ int virLogPriorityFromSyslog(int priority ATTRIBUTE_UNUSED)
>       (*cur == '\r') || (*cur == '\\'))
>  
>  
> -static int
> -virLogParseAndDefineOutput(const char *src)
> -{
> -    int ret = -1;
> -    char **tokens = NULL;
> -    char *abspath = NULL;
> -    size_t count = 0;
> -    virLogPriority prio;
> -    int dest;
> -    bool isSUID = virIsSUID();
> -
> -    if (!src)
> -        return -1;
> -
> -    VIR_DEBUG("output=%s", src);
> -
> -    /* split our format prio:destination:additional_data to tokens and parse
> -     * them individually
> -     */
> -    if (!(tokens = virStringSplitCount(src, ":", 0, &count)))
> -        return -1;
> -
> -    if (virStrToLong_uip(tokens[0], NULL, 10, &prio) < 0 ||
> -        (prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
> -        goto cleanup;
> -
> -    if ((dest = virLogDestinationTypeFromString(tokens[1])) < 0)
> -        goto cleanup;
> -
> -    if (((dest == VIR_LOG_TO_STDERR ||
> -          dest == VIR_LOG_TO_JOURNALD) && count != 2) ||
> -        ((dest == VIR_LOG_TO_FILE ||
> -          dest == VIR_LOG_TO_SYSLOG) && count != 3))
> -        goto cleanup;
> -
> -    /* if running with setuid, only 'stderr' is allowed */
> -    if (isSUID && dest != VIR_LOG_TO_STDERR)
> -        goto cleanup;
> -
> -    switch ((virLogDestination) dest) {
> -    case VIR_LOG_TO_STDERR:
> -        ret = virLogAddOutputToStderr(prio);
> -        break;
> -    case VIR_LOG_TO_SYSLOG:
> -#if HAVE_SYSLOG_H
> -        ret = virLogAddOutputToSyslog(prio, tokens[2]);
> -#endif
> -        break;
> -    case VIR_LOG_TO_FILE:
> -        if (virFileAbsPath(tokens[2], &abspath) < 0)
> -            goto cleanup;
> -        ret = virLogAddOutputToFile(prio, abspath);
> -        VIR_FREE(abspath);
> -        break;
> -    case VIR_LOG_TO_JOURNALD:
> -#if USE_JOURNALD
> -        ret = virLogAddOutputToJournald(prio);
> -#endif
> -        break;
> -    case VIR_LOG_TO_OUTPUT_LAST:
> -        break;
> -    }
> -
> - cleanup:
> -    if (ret < 0)
> -        virReportError(VIR_ERR_INTERNAL_ERROR,
> -                       _("Failed to parse and define log output %s"), src);
> -    virStringFreeList(tokens);
> -    return ret;
> -}
> -
> -
> -/**
> - * virLogParseAndDefineOutputs:
> - * @outputs: string defining a (set of) output(s)
> - *
> - * The format for an output can be:
> - *    x:stderr
> - *       output goes to stderr
> - *    x:syslog:name
> - *       use syslog for the output and use the given name as the ident
> - *    x:file:file_path
> - *       output to a file, with the given filepath
> - * In all case the x prefix is the minimal level, acting as a filter
> - *    1: DEBUG
> - *    2: INFO
> - *    3: WARNING
> - *    4: ERROR
> - *
> - * Multiple output can be defined in a single @output, they just need to be
> - * separated by spaces.
> - *
> - * If running in setuid mode, then only the 'stderr' output will
> - * be allowed
> - *
> - * Returns the number of output parsed or -1 in case of error.
> - */
> -int
> -virLogParseAndDefineOutputs(const char *src)
> -{
> -    int ret = -1;
> -    int count = 0;
> -    size_t i;
> -    char **strings = NULL;
> -
> -    if (!src)
> -        return -1;
> -
> -    VIR_DEBUG("outputs=%s", src);
> -
> -    if (!(strings = virStringSplit(src, " ", 0)))
> -        goto cleanup;
> -
> -    for (i = 0; strings[i]; i++) {
> -        /* virStringSplit may return empty strings */
> -        if (STREQ(strings[i], ""))
> -            continue;
> -
> -        if (virLogParseAndDefineOutput(strings[i]) < 0)
> -            goto cleanup;
> -
> -        count++;
> -    }
> -
> -    ret = count;
> - cleanup:
> -    virStringFreeList(strings);
> -    return ret;
> -}
> -
> -
> -static int
> -virLogParseAndDefineFilter(const char *filter)
> -{
> -    int ret = -1;
> -    size_t count = 0;
> -    virLogPriority prio;
> -    char **tokens = NULL;
> -    unsigned int flags = 0;
> -    char *ref = NULL;
> -
> -    if (!filter)
> -        return -1;
> -
> -    VIR_DEBUG("filter=%s", filter);
> -
> -    if (!(tokens = virStringSplitCount(filter, ":", 0, &count)))
> -        return -1;
> -
> -    if (count != 2)
> -        goto cleanup;
> -
> -    if (virStrToLong_uip(tokens[0], NULL, 10, &prio) < 0 ||
> -        (prio < VIR_LOG_DEBUG) || (prio > VIR_LOG_ERROR))
> -        goto cleanup;
> -
> -    ref = tokens[1];
> -    if (ref[0] == '+') {
> -        flags |= VIR_LOG_STACK_TRACE;
> -        ref++;
> -    }
> -
> -    if (!*ref)
> -        goto cleanup;
> -
> -    if (virLogDefineFilter(ref, prio, flags) < 0)
> -        goto cleanup;
> -
> -    ret = 0;
> - cleanup:
> -    if (ret < 0)
> -        virReportError(VIR_ERR_INTERNAL_ERROR,
> -                       _("Failed to parse and define log filter %s"), filter);
> -    virStringFreeList(tokens);
> -    return ret;
> -}
> -
> -/**
> - * virLogParseAndDefineFilters:
> - * @filters: string defining a (set of) filter(s)
> - *
> - * The format for a filter is:
> - *    x:name
> - *       where name is a match string
> - * the x prefix is the minimal level where the messages should be logged
> - *    1: DEBUG
> - *    2: INFO
> - *    3: WARNING
> - *    4: ERROR
> - *
> - * Multiple filter can be defined in a single @filters, they just need to be
> - * separated by spaces.
> - *
> - * Returns the number of filter parsed or -1 in case of error.
> - */
> -int
> -virLogParseAndDefineFilters(const char *filters)
> -{
> -    int ret = -1;
> -    int count = 0;
> -    size_t i;
> -    char **strings = NULL;
> -
> -    if (!filters)
> -        return -1;
> -
> -    VIR_DEBUG("filters=%s", filters);
> -
> -    if (!(strings = virStringSplit(filters, " ", 0)))
> -        goto cleanup;
> -
> -    for (i = 0; strings[i]; i++) {
> -        /* virStringSplit may return empty strings */
> -        if (STREQ(strings[i], ""))
> -            continue;
> -
> -        if (virLogParseAndDefineFilter(strings[i]) < 0)
> -            goto cleanup;
> -
> -        count++;
> -    }
> -
> -    ret = count;
> - cleanup:
> -    virStringFreeList(strings);
> -    return ret;
> -}
> -
> -
>  /**
>   * virLogGetDefaultPriority:
>   *
> diff --git a/src/util/virlog.h b/src/util/virlog.h
> index 2f88f2f..6f5af2c 100644
> --- a/src/util/virlog.h
> +++ b/src/util/virlog.h
> @@ -183,16 +183,6 @@ char *virLogGetOutputs(void);
>  virLogPriority virLogGetDefaultPriority(void);
>  int virLogSetDefaultPriority(virLogPriority priority);
>  void virLogSetFromEnv(void);
> -int virLogDefineFilter(const char *match,
> -                   virLogPriority priority,
> -                   unsigned int flags);
> -int virLogDefineOutput(virLogOutputFunc f,
> -                   virLogCloseFunc c,
> -                   void *data,
> -                   virLogPriority priority,
> -                   virLogDestination dest,
> -                   const char *name,
> -                   unsigned int flags);
>  void virLogOutputFree(virLogOutputPtr output);
>  void virLogOutputListFree(virLogOutputPtr *list, int count);
>  void virLogFilterFree(virLogFilterPtr filter);
> @@ -208,8 +198,6 @@ void virLogLock(void);
>  void virLogUnlock(void);
>  int virLogReset(void);
>  int virLogParseDefaultPriority(const char *priority);
> -int virLogParseAndDefineFilters(const char *filters);
> -int virLogParseAndDefineOutputs(const char *output);
>  int virLogPriorityFromSyslog(int priority);
>  void virLogMessage(virLogSourcePtr source,
>                 virLogPriority priority,
> 




More information about the libvir-list mailing list