Commit f387b7fe authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

log: Increase max printable size of spdk_vlog/vflog() on demand



JSON RPC logging is supported and it utilizes sppdk_vlog/vflog().
Maximal printable size of spdk_vlog/vflog() is limited and the output
may be truncated. vasprintf() can allocate a string large enough
to hold the output. To avoid truncation as much as possible, use
vasprintf().

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I26b2fae4cd521b6b93ccaa02d86be78d526f778d
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20831


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent ea1a6608
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -136,8 +136,9 @@ spdk_vlog(enum spdk_log_level level, const char *file, const int line, const cha
	  const char *format, va_list ap)
{
	int severity = LOG_INFO;
	char buf[MAX_TMPBUF];
	char *buf, _buf[MAX_TMPBUF], *ext_buf = NULL;
	char timestamp[64];
	int rc;

	if (g_log) {
		g_log(level, file, line, func, format, ap);
@@ -153,7 +154,20 @@ spdk_vlog(enum spdk_log_level level, const char *file, const int line, const cha
		return;
	}

	vsnprintf(buf, sizeof(buf), format, ap);
	buf = _buf;

	rc = vsnprintf(_buf, sizeof(_buf), format, ap);
	if (rc > MAX_TMPBUF) {
		/* The output including the terminating was more than MAX_TMPBUF bytes.
		 * Try allocating memory large enough to hold the output.
		 */
		rc = vasprintf(&ext_buf, format, ap);
		if (rc < 0) {
			/* Failed to allocate memory. Allow output to be truncated. */
		} else {
			buf = ext_buf;
		}
	}

	if (level <= g_spdk_log_print_level) {
		get_timestamp_prefix(timestamp, sizeof(timestamp));
@@ -171,6 +185,8 @@ spdk_vlog(enum spdk_log_level level, const char *file, const int line, const cha
			syslog(severity, "%s", buf);
		}
	}

	free(ext_buf);
}

void