From d0618739e64f5bd82cd362a5cd1f1c88a666cc7d Mon Sep 17 00:00:00 2001 From: Andrew Hanushevsky Date: Wed, 2 Nov 2016 22:28:53 -0700 Subject: [PATCH] Vector debug and tracing messages via the logger to allow forwarding. --- src/XrdSsi.cmake | 1 - src/XrdSsi/XrdSsiClient.cc | 82 +++++++++++++++++++++----------- src/XrdSsi/XrdSsiDebug.cc | 36 -------------- src/XrdSsi/XrdSsiDebug.hh | 88 ----------------------------------- src/XrdSsi/XrdSsiFileReq.cc | 3 +- src/XrdSsi/XrdSsiFileSess.cc | 3 +- src/XrdSsi/XrdSsiLogger.cc | 22 ++++++--- src/XrdSsi/XrdSsiLogger.hh | 12 +++++ src/XrdSsi/XrdSsiSessReal.cc | 17 ++++--- src/XrdSsi/XrdSsiSfs.cc | 5 +- src/XrdSsi/XrdSsiSfsConfig.cc | 9 ++-- src/XrdSsi/XrdSsiTaskReal.cc | 44 ++++++++++-------- src/XrdSsi/XrdSsiTrace.hh | 26 +++++------ 13 files changed, 135 insertions(+), 213 deletions(-) delete mode 100644 src/XrdSsi/XrdSsiDebug.cc delete mode 100644 src/XrdSsi/XrdSsiDebug.hh diff --git a/src/XrdSsi.cmake b/src/XrdSsi.cmake index 8067136ba10..5cab3015b4d 100644 --- a/src/XrdSsi.cmake +++ b/src/XrdSsi.cmake @@ -20,7 +20,6 @@ add_library( XrdSsi/XrdSsiClient.cc XrdSsi/XrdSsiCluster.hh XrdSsi/XrdSsiCms.cc XrdSsi/XrdSsiCms.hh -XrdSsi/XrdSsiDebug.cc XrdSsi/XrdSsiDebug.hh XrdSsi/XrdSsiErrInfo.hh XrdSsi/XrdSsiEvent.cc XrdSsi/XrdSsiEvent.hh XrdSsi/XrdSsiLogger.cc XrdSsi/XrdSsiLogger.hh diff --git a/src/XrdSsi/XrdSsiClient.cc b/src/XrdSsi/XrdSsiClient.cc index 3bac7c8eb54..9500d04e0a9 100644 --- a/src/XrdSsi/XrdSsiClient.cc +++ b/src/XrdSsi/XrdSsiClient.cc @@ -40,13 +40,16 @@ #include "XrdNet/XrdNetAddr.hh" #include "XrdSsi/XrdSsiAtomics.hh" -#include "XrdSsi/XrdSsiDebug.hh" +#include "XrdSsi/XrdSsiLogger.hh" #include "XrdSsi/XrdSsiProvider.hh" #include "XrdSsi/XrdSsiServReal.hh" +#include "XrdSsi/XrdSsiTrace.hh" #include "XrdSys/XrdSysLogger.hh" +#include "XrdSys/XrdSysLogging.hh" #include "XrdSys/XrdSysError.hh" #include "XrdSys/XrdSysPthread.hh" +#include "XrdSys/XrdSysTrace.hh" /******************************************************************************/ /* N a m e S p a c e G l o b a l s */ @@ -54,15 +57,21 @@ namespace XrdSsi { -XrdSysMutex clMutex; -XrdScheduler *schedP = 0; -XrdCl::Env *clEnvP = 0; -short maxTCB = 300; -short maxCLW = 30; -Atomic(bool) initDone(false); -bool dsTTLSet = false; -bool reqTOSet = false; -bool strTOSet = false; +extern XrdSysError Log; +extern XrdSysLogger *Logger; +extern XrdSysTrace Trace; +extern XrdSsiLogger::MCB_t *msgCB; +extern XrdSsiLogger::MCB_t *msgCBCl; + + XrdSysMutex clMutex; + XrdScheduler *schedP = 0; + XrdCl::Env *clEnvP = 0; + short maxTCB = 300; + short maxCLW = 30; + Atomic(bool) initDone(false); + bool dsTTLSet = false; + bool reqTOSet = false; + bool strTOSet = false; } using namespace XrdSsi; @@ -100,6 +109,7 @@ virtual void SetTimeout(tmoType what, int tmoval); virtual ~XrdSsiClientProvider() {} private: +void SetLogger(); void SetScheduler(); }; @@ -121,6 +131,7 @@ XrdSsiService *XrdSsiClientProvider::GetService(XrdSsiErrInfo &eInfo, // if (!Atomic_GET(initDone)) {clMutex.Lock(); + if (!Logger) SetLogger(); if (!schedP) SetScheduler(); if (!clEnvP) clEnvP = XrdCl::DefaultEnv::GetEnv(); if (!dsTTLSet) clEnvP->PutInt("DataServerTTL", maxTMO); @@ -168,21 +179,13 @@ void XrdSsiClientProvider::SetCBThreads(int cbNum, int ntNum) clMutex.UnLock(); } } - + /******************************************************************************/ -/* X r d S s i C l i e n t P r o v i d e r : : S e t S c h e d u l e r */ +/* X r d S s i C l i e n t P r o v i d e r : : S e t L o g g e r */ /******************************************************************************/ - -namespace -{ -XrdSysError myLog(0, "Ssi"); - -XrdOucTrace myTrc(&myLog); -} -void XrdSsiClientProvider::SetScheduler() +void XrdSsiClientProvider::SetLogger() { - XrdSysLogger *logP; int eFD; // Get a file descriptor mirroring standard error @@ -196,16 +199,41 @@ void XrdSsiClientProvider::SetScheduler() // Now we need to get a logger object. We make this a real dumb one. // - logP = new XrdSysLogger(eFD, 0); - myLog.logger(logP); + Logger = new XrdSysLogger(eFD, 0); + Log.logger(Logger); + Trace.SetLogger(Logger); + if (getenv("XRDSSIDEBUG") != 0) Trace.What = TRACESSI_Debug; + +// Check for a message callback object. This must be set at global init time. +// + if (msgCBCl) + {XrdSysLogging::Parms logParms; + msgCB = msgCBCl; + logParms.logpi = msgCBCl; + logParms.bufsz = 0; + XrdSysLogging::Configure(*Logger, logParms); + } +} + +/******************************************************************************/ +/* X r d S s i C l i e n t P r o v i d e r : : S e t S c h e d u l e r */ +/******************************************************************************/ + +// This may not be called before the logger object is created! + +void XrdSsiClientProvider::SetScheduler() +{ + static XrdOucTrace myTrc(&Log); -// Now construct the proper trace object +// Now construct the proper trace object (note that we do not set tracing if +// message forwarding is on because these messages will not be forwarded). +// This must be fixed when xrootd starts using XrdSysTrace!!! // - if (XrdSsi::DeBug.isON) myTrc.What = TRACE_SCHED; + if (!msgCBCl && Trace.What & TRACESSI_Debug) myTrc.What = TRACE_SCHED; // We can now set allocate a scheduler // - XrdSsi::schedP = new XrdScheduler(&myLog, &myTrc); + XrdSsi::schedP = new XrdScheduler(&Log, &myTrc); // Set thread count for callbacks // @@ -242,7 +270,7 @@ void XrdSsiClientProvider::SetTimeout(XrdSsiProvider::tmoType what, int tmoval) // Set requested timeout // switch(what) - {case connect_N: clEnvP->PutInt("onnectionRetry", tmoval); + {case connect_N: clEnvP->PutInt("ConnectionRetry", tmoval); break; case connect_T: clEnvP->PutInt("ConnectionWindow", tmoval); break; diff --git a/src/XrdSsi/XrdSsiDebug.cc b/src/XrdSsi/XrdSsiDebug.cc deleted file mode 100644 index 851302dece8..00000000000 --- a/src/XrdSsi/XrdSsiDebug.cc +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************/ -/* */ -/* X r d S s i D e b u g . c c */ -/* */ -/* (c) 2015 by the Board of Trustees of the Leland Stanford, Jr., University */ -/* All Rights Reserved */ -/* Produced by Andrew Hanushevsky for Stanford University under contract */ -/* DE-AC02-76-SFO0515 with the Department of Energy */ -/* */ -/* This file is part of the XRootD software suite. */ -/* */ -/* XRootD is free software: you can redistribute it and/or modify it under */ -/* the terms of the GNU Lesser General Public License as published by the */ -/* Free Software Foundation, either version 3 of the License, or (at your */ -/* option) any later version. */ -/* */ -/* XRootD is distributed in the hope that it will be useful, but WITHOUT */ -/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ -/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ -/* License for more details. */ -/* */ -/* You should have received a copy of the GNU Lesser General Public License */ -/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ -/* COPYING (GPL license). If not, see . */ -/* */ -/* The copyright holder's institutional names and contributor's names may not */ -/* be used to endorse or promote products derived from this software without */ -/* specific prior written permission of the institution or contributor. */ -/******************************************************************************/ - -#include "XrdSsi/XrdSsiDebug.hh" - -namespace XrdSsi -{ -XrdSsiDebug DeBug; -} diff --git a/src/XrdSsi/XrdSsiDebug.hh b/src/XrdSsi/XrdSsiDebug.hh deleted file mode 100644 index 450626cf1c7..00000000000 --- a/src/XrdSsi/XrdSsiDebug.hh +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef _XRDSSI_DEBUG_H -#define _XRDSSI_DEBUG_H -/******************************************************************************/ -/* */ -/* X r d S s i D e b u g . h h */ -/* */ -/* (c) 2015 by the Board of Trustees of the Leland Stanford, Jr., University */ -/* All Rights Reserved */ -/* Produced by Andrew Hanushevsky for Stanford University under contract */ -/* DE-AC02-76-SFO0515 with the Department of Energy */ -/* */ -/* This file is part of the XRootD software suite. */ -/* */ -/* XRootD is free software: you can redistribute it and/or modify it under */ -/* the terms of the GNU Lesser General Public License as published by the */ -/* Free Software Foundation, either version 3 of the License, or (at your */ -/* option) any later version. */ -/* */ -/* XRootD is distributed in the hope that it will be useful, but WITHOUT */ -/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ -/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ -/* License for more details. */ -/* */ -/* You should have received a copy of the GNU Lesser General Public License */ -/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ -/* COPYING (GPL license). If not, see . */ -/* */ -/* The copyright holder's institutional names and contributor's names may not */ -/* be used to endorse or promote products derived from this software without */ -/* specific prior written permission of the institution or contributor. */ -/******************************************************************************/ - -#include -#include -#include - -// This class is used by the client to perform tracing. The server uses the -// XrdSsiTrace.hh to implement tracing due to infrastructure differences. -// -class XrdSsiDebug -{ -public: - -bool isON; - -void Beg(const char *epname=0) - {pthread_mutex_lock(&debugMutex); - if (epname) std::cerr < #include #include +#include #include "XrdVersion.hh" #include "XrdCl/XrdClDefaultEnv.hh" #include "XrdCl/XrdClLog.hh" #include "XrdOuc/XrdOucEnv.hh" #include "XrdOuc/XrdOucStream.hh" -#include "XrdOuc/XrdOucTrace.hh" #include "XrdSsi/XrdSsiSfsConfig.hh" #include "XrdSsi/XrdSsiLogger.hh" #include "XrdSys/XrdSysError.hh" #include "XrdSys/XrdSysHeaders.hh" #include "XrdSys/XrdSysLogger.hh" -#include "XrdSys/XrdSysLogPI.hh" -#include "XrdSys/XrdSysPlugin.hh" #include "XrdSys/XrdSysPthread.hh" +#include "XrdSys/XrdSysTrace.hh" /******************************************************************************/ /* G l o b a l O b j e c t s */ @@ -54,10 +53,11 @@ namespace XrdSsi { - XrdSysError Log(0); - XrdSysLogger *Logger; - XrdOucTrace Trace(&Log); - XrdSsiLogger::MCB_t *msgCB = 0; + XrdSysError Log(0, "ssi_"); + XrdSysLogger *Logger = 0; + XrdSysTrace Trace("Ssi", Logger); + XrdSsiLogger::MCB_t *msgCB = 0; + XrdSsiLogger::MCB_t *msgCBCl = 0; } using namespace XrdSsi; @@ -170,6 +170,13 @@ void XrdSsiLogger::Msgv(const char *pfx, const char *fmt, va_list aP) else Log.Say(buffer); } +/******************************************************************************/ + +void XrdSsiLogger::Msgv(struct iovec *iovP, int iovN) +{ + Logger->Put(iovN, iovP); +} + /******************************************************************************/ /* S e t M C B */ /******************************************************************************/ @@ -188,6 +195,7 @@ bool XrdSsiLogger::SetMCB(XrdSsiLogger::MCB_t &mcbP, {XrdCl::Log *logP = XrdCl::DefaultEnv::GetLog(); if (!logP) return false; logP->SetOutput(new LogMCB(&mcbP)); + msgCBCl = mcbP; } // All done diff --git a/src/XrdSsi/XrdSsiLogger.hh b/src/XrdSsi/XrdSsiLogger.hh index 7fb40f16e6c..61ec403d626 100644 --- a/src/XrdSsi/XrdSsiLogger.hh +++ b/src/XrdSsi/XrdSsiLogger.hh @@ -35,6 +35,8 @@ //! The XrdSsiLogger object is used to route messages to the default logfile. //----------------------------------------------------------------------------- +struct iovec; + class XrdSsiLogger { public: @@ -79,6 +81,16 @@ static void Msgf(const char *pfx, const char *fmt, ...); static void Msgv(const char *pfx, const char *fmt, va_list aP); +//----------------------------------------------------------------------------- +//! Insert a formated error message into the log file using a iovec. +//! +//! @param iovP pointer to an iovec that contains the message. +//! that a newline character is always appended to the message. +//! @param iobN the number of elements in the iovec. +//----------------------------------------------------------------------------- + +static void Msgv(struct iovec *iovP, int iovN); + //----------------------------------------------------------------------------- //! Set a message callback function for messages issued via this object. This //! method should be called during static initialization (this means the call diff --git a/src/XrdSsi/XrdSsiSessReal.cc b/src/XrdSsi/XrdSsiSessReal.cc index 644a842a961..1403c578a4e 100644 --- a/src/XrdSsi/XrdSsiSessReal.cc +++ b/src/XrdSsi/XrdSsiSessReal.cc @@ -35,13 +35,15 @@ #include #include -#include "XrdSsi/XrdSsiDebug.hh" #include "XrdSsi/XrdSsiRequest.hh" #include "XrdSsi/XrdSsiRRInfo.hh" #include "XrdSsi/XrdSsiServReal.hh" #include "XrdSsi/XrdSsiSessReal.hh" +#include "XrdSsi/XrdSsiTrace.hh" #include "XrdSys/XrdSysHeaders.hh" +using namespace XrdSsi; + /******************************************************************************/ /* L o c a l D e f i n e s */ /******************************************************************************/ @@ -70,6 +72,7 @@ namespace { std::string dsProperty("DataServer"); + const char *tident = 0; } /******************************************************************************/ @@ -147,7 +150,7 @@ bool XrdSsiSessReal::Open(XrdSsiService::Resource *resP, // Issue the open and if the open was started, return success. // - DBG("Opening " <Init(reqP, tOut); - DBG("Task="<Get(buffP); if (!buffP || !(cdP = buffP->GetBuffer())) - {DBG("Responding with stream id=" <eInfo); tStat = isDone; - DBG("Task Async SetBuff error id=" <Recycle(this); sessP->UnLock(); } else { - DBG("Deleting task."); + DEBUG("Deleting task."); sessP->UnLock(); delete this; } @@ -411,7 +415,7 @@ bool XrdSsiTaskReal::XeqEvent(XrdCl::XRootDStatus *status, mhPend = false; last = tStat == isDone; sessP->UnLock(); - DBG("Calling ProcessResponseData; len="<