Commit 03593c44 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

log: allow globbing when setting/clearing log flags



When debugging, it's often useful to enable logs from multiple related
modules, e.g. nvmf and nvmf_tcp.  Now, glob patterns can be used to
enable (or disable) multiple flags.  So, instead of -L nvmf -L nvmf_tcp,
it's possible to do -L nvmf*.

While here, changed spdk_log_{set,clear}_flag() to return negative errno
on failure instead of -1.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Suggested-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
Change-Id: I860ffb97be10e46fc0fc5d2659a4724b8b7d5310
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20450


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent b07cae7f
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -255,20 +255,22 @@ struct spdk_log_flag *spdk_log_get_next_flag(struct spdk_log_flag *flag);
bool spdk_log_get_flag(const char *flag);

/**
 * Enable the log flag.
 * Enable the log flag.  The name of the flag can be a glob pattern (as expanded by fnmatch(3)), in
 * which case all matching flags will be set.
 *
 * \param flag Log flag to be enabled.
 *
 * \return 0 on success, -1 on failure.
 * \return 0 on success, negative errno on failure.
 */
int spdk_log_set_flag(const char *flag);

/**
 * Clear a log flag.
 * Clear a log flag.  The name of the flag can be a glob pattern (as expanded by fnmatch(3)), in
 * which case all matching flags will be cleared.
 *
 * \param flag Log flag to clear.
 *
 * \return 0 on success, -1 on failure.
 * \return 0 on success, negative errno on failure.
 */
int spdk_log_clear_flag(const char *flag);

+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ extern "C" {
#include <arpa/inet.h>
#include <dirent.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <glob.h>
#include <ifaddrs.h>
#include <libgen.h>
+1 −1
Original line number Diff line number Diff line
@@ -1180,7 +1180,7 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
		case LOGFLAG_OPT_IDX:
			rc = spdk_log_set_flag(optarg);
			if (rc < 0) {
				SPDK_ERRLOG("unknown flag\n");
				SPDK_ERRLOG("unknown flag: %s\n", optarg);
				usage(app_usage);
				goto out;
			}
+7 −6
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ static int
log_set_flag(const char *name, bool value)
{
	struct spdk_log_flag *flag;
	int rc = -EINVAL;

	if (strcasecmp(name, "all") == 0) {
		TAILQ_FOREACH(flag, &g_log_flags, tailq) {
@@ -74,14 +75,14 @@ log_set_flag(const char *name, bool value)
		return 0;
	}

	flag = get_log_flag(name);
	if (flag == NULL) {
		return -1;
	}

	TAILQ_FOREACH(flag, &g_log_flags, tailq) {
		if (fnmatch(name, flag->name, FNM_CASEFOLD) == 0) {
			flag->enabled = value;
			rc = 0;
		}
	}

	return 0;
	return rc;
}

int