class DoutPrefixProvider {
public:
- virtual string gen_prefix() const = 0;
+ virtual std::ostream& gen_prefix(std::ostream& out) const = 0;
virtual CephContext *get_cct() const = 0;
virtual unsigned get_subsys() const = 0;
virtual ~DoutPrefixProvider() {}
#define ldpp_dout(dpp, v) \
if (dpp) \
dout_impl(dpp->get_cct(), ceph::dout::need_dynamic(dpp->get_subsys()), v) \
- (*_dout << dpp->gen_prefix())
+ dpp->gen_prefix(*_dout)
#define lgeneric_subdout(cct, sub, v) dout_impl(cct, ceph_subsys_##sub, v) *_dout
#define lgeneric_dout(cct, v) dout_impl(cct, ceph_subsys_, v) *_dout
#undef dout_prefix
#define dout_prefix _prefix(_dout, this)
static ostream& _prefix(std::ostream *_dout, ECBackend *pgb) {
- return *_dout << pgb->get_parent()->gen_dbg_prefix();
+ return pgb->get_parent()->gen_dbg_prefix(*_dout);
}
struct ECRecoveryHandle : public PGBackend::RecoveryHandle {
template <class T>
static ostream& _prefix(std::ostream *_dout, T *t)
{
- return *_dout << t->gen_prefix();
+ return t->gen_prefix(*_dout);
}
void PGStateHistory::enter(PG* pg, const utime_t entime, const char* state)
dout(30) << "lock" << dendl;
}
-std::string PG::gen_prefix() const
+std::ostream& PG::gen_prefix(std::ostream& out) const
{
- stringstream out;
OSDMapRef mapref = osdmap_ref;
if (_lock.is_locked_by_me()) {
out << "osd." << osd->whoami
<< " pg_epoch: " << (mapref ? mapref->get_epoch():0)
<< " pg[" << info.pgid << "(unlocked)] ";
}
- return out.str();
+ return out;
}
/********* PG **********/
/*------------ Recovery State Machine----------------*/
#undef dout_prefix
-#define dout_prefix (*_dout << context< RecoveryMachine >().pg->gen_prefix() \
+#define dout_prefix (context< RecoveryMachine >().pg->gen_prefix(*_dout) \
<< "state<" << get_state_name() << ">: ")
/*------Crashed-------*/
/*----RecoveryState::RecoveryMachine Methods-----*/
#undef dout_prefix
-#define dout_prefix *_dout << pg->gen_prefix()
+#define dout_prefix pg->gen_prefix(*_dout)
void PG::RecoveryState::RecoveryMachine::log_enter(const char *state_name)
{
/*---------------------------------------------------*/
#undef dout_prefix
-#define dout_prefix (*_dout << (debug_pg ? debug_pg->gen_prefix() : string()) << " PriorSet: ")
+#define dout_prefix ((debug_pg ? debug_pg->gen_prefix(*_dout) : *_dout) << " PriorSet: ")
void PG::RecoveryState::start_handle(RecoveryCtx *new_ctx) {
assert(!rctx);
class RecoveryCtx;
// -- methods --
- std::string gen_prefix() const override;
+ std::ostream& gen_prefix(std::ostream& out) const override;
CephContext *get_cct() const override {
return cct;
}
is_readable.reset(_is_readable);
is_recoverable.reset(_is_recoverable);
}
- string gen_prefix() const { return pg->gen_prefix(); }
+ std::ostream& gen_prefix(std::ostream& out) const {
+ return pg->gen_prefix(out);
+ }
bool needs_recovery(
const hobject_t &hoid,
eversion_t *v = 0) const {
#undef dout_prefix
#define dout_prefix _prefix(_dout, this)
static ostream& _prefix(std::ostream *_dout, PGBackend *pgb) {
- return *_dout << pgb->get_parent()->gen_dbg_prefix();
+ return pgb->get_parent()->gen_dbg_prefix(*_dout);
}
void PGBackend::recover_delete_object(const hobject_t &oid, eversion_t v,
virtual const set<pg_shard_t> &get_acting_shards() const = 0;
virtual const set<pg_shard_t> &get_backfill_shards() const = 0;
- virtual std::string gen_dbg_prefix() const = 0;
+ virtual std::ostream& gen_dbg_prefix(std::ostream& out) const = 0;
virtual const map<hobject_t, set<pg_shard_t>> &get_missing_loc_shards()
const = 0;
OSDMapRef get_osdmap() const { return get_parent()->pgb_get_osdmap(); }
const pg_info_t &get_info() { return get_parent()->get_info(); }
- std::string gen_prefix() const {
- return parent->gen_dbg_prefix();
+ std::ostream& gen_prefix(std::ostream& out) const {
+ return parent->gen_dbg_prefix(out);
}
/**
static ostream& _prefix(std::ostream *_dout, const PGLog *pglog)
{
- return *_dout << pglog->gen_prefix();
+ return pglog->gen_prefix(*_dout);
}
//////////////////// PGLog::IndexedLog ////////////////////
class CephContext;
struct PGLog : DoutPrefixProvider {
- string gen_prefix() const override {
- return "";
+ std::ostream& gen_prefix(std::ostream& out) const override {
+ return out;
}
unsigned get_subsys() const override {
return static_cast<unsigned>(ceph_subsys_osd);
#define dout_prefix _prefix(_dout, this)
template <typename T>
static ostream& _prefix(std::ostream *_dout, T *pg) {
- return *_dout << pg->gen_prefix();
+ return pg->gen_prefix(*_dout);
}
/*---SnapTrimmer Logging---*/
#undef dout_prefix
-#define dout_prefix *_dout << pg->gen_prefix()
+#define dout_prefix pg->gen_prefix(*_dout)
void PrimaryLogPG::SnapTrimmer::log_enter(const char *state_name)
{
/*---SnapTrimmer states---*/
#undef dout_prefix
-#define dout_prefix (*_dout << context< SnapTrimmer >().pg->gen_prefix() \
+#define dout_prefix (context< SnapTrimmer >().pg->gen_prefix(*_dout) \
<< "SnapTrimmer state<" << get_state_name() << ">: ")
/* NotTrimming */
return backfill_targets;
}
- std::string gen_dbg_prefix() const override { return gen_prefix(); }
-
+ std::ostream& gen_dbg_prefix(std::ostream& out) const override {
+ return gen_prefix(out);
+ }
+
const map<hobject_t, set<pg_shard_t>>
&get_missing_loc_shards() const override {
return missing_loc.get_missing_locs();
#undef dout_prefix
#define dout_prefix _prefix(_dout, this)
static ostream& _prefix(std::ostream *_dout, ReplicatedBackend *pgb) {
- return *_dout << pgb->get_parent()->gen_dbg_prefix();
+ return pgb->get_parent()->gen_dbg_prefix(*_dout);
}
namespace {
static ostream& _prefix(
std::ostream* _dout,
Notify *notify) {
- return *_dout << notify->gen_dbg_prefix();
+ return notify->gen_dbg_prefix(*_dout);
}
Notify::Notify(
static ostream& _prefix(
std::ostream* _dout,
Watch *watch) {
- return *_dout << watch->gen_dbg_prefix();
+ return watch->gen_dbg_prefix(*_dout);
}
class HandleWatchTimeout : public CancelableContext {
#undef dout_prefix
#define dout_prefix _prefix(_dout, this)
-string Watch::gen_dbg_prefix() {
- stringstream ss;
- ss << pg->gen_prefix() << " -- Watch("
- << make_pair(cookie, entity) << ") ";
- return ss.str();
+std::ostream& Watch::gen_dbg_prefix(std::ostream& out) {
+ return pg->gen_prefix(out) << " -- Watch("
+ << make_pair(cookie, entity) << ") ";
}
Watch::Watch(
void unregister_cb();
public:
- string gen_dbg_prefix() {
- stringstream ss;
- ss << "Notify(" << make_pair(cookie, notify_id) << " "
- << " watchers=" << watchers.size()
- << ") ";
- return ss.str();
+ std::ostream& gen_dbg_prefix(std::ostream& out) {
+ return out << "Notify(" << make_pair(cookie, notify_id) << " "
+ << " watchers=" << watchers.size()
+ << ") ";
}
void set_self(NotifyRef _self) {
self = _self;
return entity.num();
}
- string gen_dbg_prefix();
+ std::ostream& gen_dbg_prefix(std::ostream& out);
static WatchRef makeWatchRef(
PrimaryLogPG *pg, OSDService *osd,
ceph::shared_ptr<ObjectContext> obc, uint32_t timeout, uint64_t cookie, entity_name_t entity, const entity_addr_t &addr);
#include "test/unit.cc"
struct mydpp : public DoutPrefixProvider {
- string gen_prefix() const override { return "foo"; }
+ std::ostream& gen_prefix(std::ostream& out) const override { return out << "foo"; }
CephContext *get_cct() const override { return g_ceph_context; }
unsigned get_subsys() const override { return ceph_subsys_osd; }
} dpp;