crimson/osd, osd: don't use VLA in cls_log() anymore.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
This commit is contained in:
Radoslaw Zarzynski 2022-03-08 01:51:09 +00:00
parent f62329f9a4
commit 45c7b4b51a
2 changed files with 14 additions and 12 deletions

View File

@ -3,6 +3,7 @@
#include <cstdarg> #include <cstdarg>
#include <cstring> #include <cstring>
#include <boost/container/small_vector.hpp>
#include "common/ceph_context.h" #include "common/ceph_context.h"
#include "common/ceph_releases.h" #include "common/ceph_releases.h"
#include "common/config.h" #include "common/config.h"
@ -536,16 +537,16 @@ int cls_cxx_get_gathered_data(cls_method_context_t hctx, std::map<std::string, b
// the classical OSD, it's different b/c of how the dout macro expands. // the classical OSD, it's different b/c of how the dout macro expands.
int cls_log(int level, const char *format, ...) int cls_log(int level, const char *format, ...)
{ {
int size = 256; size_t size = 256;
va_list ap; va_list ap;
while (1) { while (1) {
char buf[size]; boost::container::small_vector<char, 256> buf(size);
va_start(ap, format); va_start(ap, format);
int n = vsnprintf(buf, size, format, ap); int n = vsnprintf(buf.data(), size, format, ap);
va_end(ap); va_end(ap);
#define MAX_SIZE 8196 #define MAX_SIZE 8196UL
if ((n > -1 && n < size) || size > MAX_SIZE) { if ((n > -1 && static_cast<size_t>(n) < size) || size > MAX_SIZE) {
dout(ceph::dout::need_dynamic(level)) << buf << dendl; dout(ceph::dout::need_dynamic(level)) << buf.data() << dendl;
return n; return n;
} }
size *= 2; size *= 2;

View File

@ -2,6 +2,7 @@
// vim: ts=8 sw=2 smarttab // vim: ts=8 sw=2 smarttab
#include <cstdarg> #include <cstdarg>
#include <boost/container/small_vector.hpp>
#include "common/ceph_context.h" #include "common/ceph_context.h"
#include "common/ceph_releases.h" #include "common/ceph_releases.h"
#include "common/config.h" #include "common/config.h"
@ -753,16 +754,16 @@ int cls_cxx_get_gathered_data(cls_method_context_t hctx, std::map<std::string, b
// crimson-osd, it's different b/c of how the dout macro expands. // crimson-osd, it's different b/c of how the dout macro expands.
int cls_log(int level, const char *format, ...) int cls_log(int level, const char *format, ...)
{ {
int size = 256; size_t size = 256;
va_list ap; va_list ap;
while (1) { while (1) {
char buf[size]; boost::container::small_vector<char, 256> buf(size);
va_start(ap, format); va_start(ap, format);
int n = vsnprintf(buf, size, format, ap); int n = vsnprintf(buf.data(), size, format, ap);
va_end(ap); va_end(ap);
#define MAX_SIZE 8196 #define MAX_SIZE 8196UL
if ((n > -1 && n < size) || size > MAX_SIZE) { if ((n > -1 && static_cast<size_t>(n) < size) || size > MAX_SIZE) {
dout(ceph::dout::need_dynamic(level)) << buf << dendl; dout(ceph::dout::need_dynamic(level)) << buf.data() << dendl;
return n; return n;
} }
size *= 2; size *= 2;