New upstream version 8.1.0

This commit is contained in:
geos_one
2025-08-10 01:34:16 +02:00
commit c891bb7105
4398 changed files with 838833 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,436 @@
#ifndef APP_H_
#define APP_H_
#include <app/config/MountConfig.h>
#include <common/toolkit/list/PointerListIter.h>
#include <common/toolkit/list/StrCpyListIter.h>
#include <common/toolkit/list/UInt16ListIter.h>
#include <common/net/sock/NicAddressList.h>
#include <common/threading/AtomicInt.h>
#include <common/threading/Mutex.h>
#include <common/threading/Thread.h>
#include <common/Common.h>
#include <toolkit/BitStore.h>
// program return codes
#define APPCODE_NO_ERROR 0
#define APPCODE_PROGRAM_ERROR 1
#define APPCODE_INVALID_CONFIG 2
#define APPCODE_INITIALIZATION_ERROR 3
#define APPCODE_RUNTIME_ERROR 4
// forward declarations
struct Config;
struct Logger;
struct DatagramListener;
struct InternodeSyncer;
struct AckManager;
struct Flusher;
struct Node;
struct NodeStoreEx;
struct TargetMapper;
struct MirrorBuddyGroupMapper;
struct TargetStateStore;
struct NoAllocBufferStore;
struct AcknowledgmentStore;
struct NetFilter;
struct InodeRefStore;
struct StatFsCache;
struct App;
typedef struct App App;
extern void App_init(App* this, MountConfig* mountConfig);
extern void App_uninit(App* this);
extern int App_run(App* this);
extern void App_stop(App* this);
extern bool __App_initDataObjects(App* this, MountConfig* mountConfig);
extern bool __App_initInodeOperations(App* this);
extern bool __App_initLocalNodeInfo(App* this);
extern bool __App_initComponents(App* this);
extern void __App_startComponents(App* this);
extern void __App_stopComponents(App* this);
extern void __App_joinComponents(App* this);
extern void __App_waitForComponentTermination(App* this, Thread* component);
extern void __App_logInfos(App* this);
extern bool __App_mountServerCheck(App* this);
extern bool App_findAllowedInterfaces(App* this, NicAddressList* nicList);
extern void App_findAllowedRDMAInterfaces(App* this, NicAddressList* nicList, NicAddressList* rdmaNicList);
// external getters & setters
extern const char* App_getVersionStr(void);
extern void App_updateLocalInterfaces(App* app, NicAddressList* nicList);
extern char* App_cloneFsUUID(App* this);
extern void App_updateFsUUID(App* this, const char* fsUUID);
extern void App_cloneLocalNicList(App* this, NicAddressList* nicList);
extern void App_cloneLocalRDMANicList(App* this, NicAddressList* rdmaNicList);
// inliners
static inline struct Logger* App_getLogger(App* this);
static inline struct Config* App_getConfig(App* this);
static inline struct MountConfig* App_getMountConfig(App* this);
static inline struct NetFilter* App_getNetFilter(App* this);
static inline struct NetFilter* App_getTcpOnlyFilter(App* this);
static inline NicAddressList* App_getLocalRDMANicListLocked(App* this);
/**
* Called when access to the nicList is required but doesn't
* want the overhead of a clone operation. This locks the internel nicListMutex.
* App_unlockNicList must later be invoked.
*/
static inline void App_lockNicList(App* this);
/**
* Release the lock on nicListMutex acquired by App_lockNicList.
*/
static inline void App_unlockNicList(App* this);
static inline UInt16List* App_getPreferredStorageTargets(App* this);
static inline UInt16List* App_getPreferredMetaNodes(App* this);
static inline struct Node* App_getLocalNode(App* this);
static inline struct NodeStoreEx* App_getMgmtNodes(App* this);
static inline struct NodeStoreEx* App_getMetaNodes(App* this);
static inline struct NodeStoreEx* App_getStorageNodes(App* this);
static inline struct TargetMapper* App_getTargetMapper(App* this);
static inline struct MirrorBuddyGroupMapper* App_getStorageBuddyGroupMapper(App* this);
static inline struct MirrorBuddyGroupMapper* App_getMetaBuddyGroupMapper(App* this);
static inline struct TargetStateStore* App_getTargetStateStore(App* this);
static inline struct TargetStateStore* App_getMetaStateStore(App* this);
static inline struct NoAllocBufferStore* App_getCacheBufStore(App* this);
static inline struct NoAllocBufferStore* App_getPathBufStore(App* this);
static inline struct NoAllocBufferStore* App_getMsgBufStore(App* this);
static inline struct AcknowledgmentStore* App_getAckStore(App* this);
static inline struct InodeRefStore* App_getInodeRefStore(App* this);
static inline struct StatFsCache* App_getStatFsCache(App* this);
static inline struct DatagramListener* App_getDatagramListener(App* this);
static inline struct InternodeSyncer* App_getInternodeSyncer(App* this);
static inline struct AckManager* App_getAckManager(App* this);
static inline AtomicInt* App_getLockAckAtomicCounter(App* this);
static inline bool App_getConnRetriesEnabled(App* this);
static inline void App_setConnRetriesEnabled(App* this, bool connRetriesEnabled);
static inline bool App_getNetBenchModeEnabled(App* this);
static inline void App_setNetBenchModeEnabled(App* this, bool netBenchModeEnabled);
static inline struct inode_operations* App_getFileInodeOps(App* this);
static inline struct inode_operations* App_getSymlinkInodeOps(App* this);
static inline struct inode_operations* App_getDirInodeOps(App* this);
static inline struct inode_operations* App_getSpecialInodeOps(App* this);
#ifdef BEEGFS_DEBUG
static inline size_t App_getNumRPCs(App* this);
static inline void App_incNumRPCs(App* this);
static inline size_t App_getNumRemoteReads(App* this);
static inline void App_incNumRemoteReads(App* this);
static inline size_t App_getNumRemoteWrites(App* this);
static inline void App_incNumRemoteWrites(App* this);
#endif // BEEGFS_DEBUG
struct App
{
int appResult;
MountConfig* mountConfig;
struct Config* cfg;
struct Logger* logger;
const char* fsUUID;
Mutex fsUUIDMutex;
struct NetFilter* netFilter; // empty filter means "all nets allowed"
struct NetFilter* tcpOnlyFilter; // for IPs which allow only plain TCP (no RDMA etc)
StrCpyList allowedInterfaces; // empty list means "all interfaces accepted"
StrCpyList allowedRDMAInterfaces; // empty list means "all interfaces eligible"
UInt16List preferredMetaNodes; // empty list means "no preferred nodes => use any"
UInt16List preferredStorageTargets; // empty list means "no preferred nodes => use any"
// rdmaNicList contains the addresses of specific RDMA NICs to use for outbound RDMA.
// This is only populated when the configuration specifies a list of interfaces. If this
// list is empty, any RDMA NIC on the client may be used for outbound RDMA.
// allowedRDMAInterfaces contains the interface names used to populate this list.
NicAddressList rdmaNicList;
Mutex nicListMutex;
struct Node* localNode;
struct NodeStoreEx* mgmtNodes;
struct NodeStoreEx* metaNodes;
struct NodeStoreEx* storageNodes;
struct TargetMapper* targetMapper;
struct MirrorBuddyGroupMapper* storageBuddyGroupMapper;
struct MirrorBuddyGroupMapper* metaBuddyGroupMapper;
struct TargetStateStore* targetStateStore; // map storage targets IDs to a state
struct TargetStateStore* metaStateStore; // map mds targets (i.e. nodeIDs) to a state
struct NoAllocBufferStore* cacheBufStore; // for buffered cache mode
struct NoAllocBufferStore* pathBufStore; // for dentry path lookups
struct NoAllocBufferStore* msgBufStore; // for MessagingTk request/response
struct AcknowledgmentStore* ackStore;
struct InodeRefStore* inodeRefStore;
struct StatFsCache* statfsCache;
struct DatagramListener* dgramListener;
struct InternodeSyncer* internodeSyncer;
struct AckManager* ackManager;
struct Flusher* flusher;
AtomicInt lockAckAtomicCounter; // used by remoting to generate unique lockAckIDs
volatile bool connRetriesEnabled; // changed at umount and via procfs
bool netBenchModeEnabled; // changed via procfs to disable server-side disk read/write
// Inode operations. Since the members of the structs depend on runtime config opts, we need
// one copy of each struct per App object.
struct inode_operations* fileInodeOps;
struct inode_operations* symlinkInodeOps;
struct inode_operations* dirInodeOps;
struct inode_operations* specialInodeOps;
#ifdef BEEGFS_DEBUG
Mutex debugCounterMutex; // this is the closed tree, so we don't have atomics here (but doesn't
// matter since this is debug info and not performance critical)
size_t numRPCs;
size_t numRemoteReads;
size_t numRemoteWrites;
#endif // BEEGFS_DEBUG
};
struct Logger* App_getLogger(App* this)
{
return this->logger;
}
struct Config* App_getConfig(App* this)
{
return this->cfg;
}
struct MountConfig* App_getMountConfig(App* this)
{
return this->mountConfig;
}
struct NetFilter* App_getNetFilter(App* this)
{
return this->netFilter;
}
struct NetFilter* App_getTcpOnlyFilter(App* this)
{
return this->tcpOnlyFilter;
}
UInt16List* App_getPreferredMetaNodes(App* this)
{
return &this->preferredMetaNodes;
}
UInt16List* App_getPreferredStorageTargets(App* this)
{
return &this->preferredStorageTargets;
}
void App_lockNicList(App* this)
{
Mutex_lock(&this->nicListMutex); // L O C K
}
void App_unlockNicList(App* this)
{
Mutex_unlock(&this->nicListMutex); // U N L O C K
}
NicAddressList* App_getLocalRDMANicListLocked(App* this)
{
return &this->rdmaNicList;
}
struct Node* App_getLocalNode(App* this)
{
return this->localNode;
}
struct NodeStoreEx* App_getMgmtNodes(App* this)
{
return this->mgmtNodes;
}
struct NodeStoreEx* App_getMetaNodes(App* this)
{
return this->metaNodes;
}
struct NodeStoreEx* App_getStorageNodes(App* this)
{
return this->storageNodes;
}
struct TargetMapper* App_getTargetMapper(App* this)
{
return this->targetMapper;
}
struct MirrorBuddyGroupMapper* App_getStorageBuddyGroupMapper(App* this)
{
return this->storageBuddyGroupMapper;
}
struct MirrorBuddyGroupMapper* App_getMetaBuddyGroupMapper(App* this)
{
return this->metaBuddyGroupMapper;
}
struct TargetStateStore* App_getTargetStateStore(App* this)
{
return this->targetStateStore;
}
struct TargetStateStore* App_getMetaStateStore(App* this)
{
return this->metaStateStore;
}
struct NoAllocBufferStore* App_getCacheBufStore(App* this)
{
return this->cacheBufStore;
}
struct NoAllocBufferStore* App_getPathBufStore(App* this)
{
return this->pathBufStore;
}
struct NoAllocBufferStore* App_getMsgBufStore(App* this)
{
return this->msgBufStore;
}
struct AcknowledgmentStore* App_getAckStore(App* this)
{
return this->ackStore;
}
struct InodeRefStore* App_getInodeRefStore(App* this)
{
return this->inodeRefStore;
}
struct StatFsCache* App_getStatFsCache(App* this)
{
return this->statfsCache;
}
struct DatagramListener* App_getDatagramListener(App* this)
{
return this->dgramListener;
}
struct InternodeSyncer* App_getInternodeSyncer(App* this)
{
return this->internodeSyncer;
}
struct AckManager* App_getAckManager(App* this)
{
return this->ackManager;
}
AtomicInt* App_getLockAckAtomicCounter(App* this)
{
return &this->lockAckAtomicCounter;
}
bool App_getConnRetriesEnabled(App* this)
{
return this->connRetriesEnabled;
}
void App_setConnRetriesEnabled(App* this, bool connRetriesEnabled)
{
this->connRetriesEnabled = connRetriesEnabled;
}
bool App_getNetBenchModeEnabled(App* this)
{
return this->netBenchModeEnabled;
}
void App_setNetBenchModeEnabled(App* this, bool netBenchModeEnabled)
{
this->netBenchModeEnabled = netBenchModeEnabled;
}
struct inode_operations* App_getFileInodeOps(App* this)
{
return this->fileInodeOps;
}
struct inode_operations* App_getSymlinkInodeOps(App* this)
{
return this->symlinkInodeOps;
}
struct inode_operations* App_getDirInodeOps(App* this)
{
return this->dirInodeOps;
}
struct inode_operations* App_getSpecialInodeOps(App* this)
{
return this->specialInodeOps;
}
#ifdef BEEGFS_DEBUG
size_t App_getNumRPCs(App* this)
{
return this->numRPCs;
}
void App_incNumRPCs(App* this)
{
Mutex_lock(&this->debugCounterMutex);
this->numRPCs++;
Mutex_unlock(&this->debugCounterMutex);
}
size_t App_getNumRemoteReads(App* this)
{
return this->numRemoteReads;
}
void App_incNumRemoteReads(App* this)
{
Mutex_lock(&this->debugCounterMutex);
this->numRemoteReads++;
Mutex_unlock(&this->debugCounterMutex);
}
size_t App_getNumRemoteWrites(App* this)
{
return this->numRemoteWrites;
}
void App_incNumRemoteWrites(App* this)
{
Mutex_lock(&this->debugCounterMutex);
this->numRemoteWrites++;
Mutex_unlock(&this->debugCounterMutex);
}
#else // BEEGFS_DEBUG
#define App_incNumRPCs(this)
#define App_incNumRemoteReads(this)
#define App_incNumRemoteWrites(this)
#endif // BEEGFS_DEBUG
#endif /*APP_H_*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,758 @@
#ifndef CONFIG_H_
#define CONFIG_H_
#include <common/Common.h>
#include <common/toolkit/list/StrCpyListIter.h>
#include <common/toolkit/list/UInt16ListIter.h>
#include <common/toolkit/tree/StrCpyMap.h>
#include <common/toolkit/tree/StrCpyMapIter.h>
#include <common/toolkit/StringTk.h>
#include <app/config/MountConfig.h>
struct Config;
typedef struct Config Config;
enum FileCacheType;
typedef enum FileCacheType FileCacheType;
enum InodeIDStyle;
typedef enum InodeIDStyle InodeIDStyle;
enum RDMAKeyType;
typedef enum RDMAKeyType RDMAKeyType;
enum CheckCapabilities;
typedef enum CheckCapabilities CheckCapabilities;
enum EventLogMask
{
EventLogMask_NONE = 0,
EventLogMask_FLUSH = 1,
EventLogMask_TRUNC = 2,
EventLogMask_SETATTR = 4,
EventLogMask_CLOSE = 8,
EventLogMask_LINK_OP = 16,
EventLogMask_OPEN_READ = 32,
EventLogMask_OPEN_WRITE = 64,
EventLogMask_OPEN_READ_WRITE = 128
};
extern __must_check bool Config_init(Config* this, MountConfig* mountConfig);
extern Config* Config_construct(MountConfig* mountConfig);
extern void Config_uninit(Config* this);
extern void Config_destruct(Config* this);
extern bool _Config_initConfig(Config* this, MountConfig* mountConfig);
extern StrCpyMapIter _Config_eraseFromConfigMap(Config* this, StrCpyMapIter* iter);
extern void _Config_loadDefaults(Config* this);
extern bool _Config_applyConfigMap(Config* this);
extern void _Config_configMapRedefine(Config* this, char* keyStr, const char* valueStr);
extern void __Config_addLineToConfigMap(Config* this, char* line);
extern void __Config_loadFromMountConfig(Config* this, MountConfig* mountConfig);
extern bool __Config_loadFromFile(struct Config* this, const char* filename);
extern bool Config_loadStringListFile(const char* filename,
StrCpyList* outList);
extern bool Config_loadUInt16ListFile(struct Config* this, const char* filename,
UInt16List* outList);
extern bool __Config_initImplicitVals(Config* this);
extern void __Config_initConnNumCommRetries(Config* this);
extern void __Config_initTuneFileCacheTypeNum(Config* this);
void __Config_initSysInodeIDStyleNum(Config* this);
bool __Config_initConnAuthHash(Config* this, char* connAuthFile, uint64_t* outConnAuthHash);
void __Config_initConnRDMAKeyTypeNum(Config* this);
// conversion
const char* Config_fileCacheTypeNumToStr(FileCacheType cacheType);
const char* Config_inodeIDStyleNumToStr(InodeIDStyle inodeIDStyle);
const char* Config_eventLogMaskToStr(enum EventLogMask mask);
const char* Config_rdmaKeyTypeNumToStr(RDMAKeyType keyType);
const char* Config_checkCapabilitiesTypeToStr(CheckCapabilities checkCapabilities);
// getters & setters
static inline char* Config_getCfgFile(Config* this);
static inline int Config_getLogLevel(Config* this);
static inline bool Config_getLogClientID(Config* this);
static inline bool Config_getConnUseRDMA(Config* this);
static inline bool Config_getConnTCPFallbackEnabled(Config* this);
static inline int Config_getConnClientPort(Config* this);
static inline int Config_getConnMgmtdPort(Config* this);
static inline int Config_getConnMgmtdGrpcPort(Config* this);
static inline void Config_setConnMgmtdGrpcPort(Config* this, int port);
static inline unsigned Config_getConnMaxInternodeNum(Config* this);
static inline char* Config_getConnInterfacesFile(Config* this);
static inline char* Config_getConnInterfacesList(Config* this);
static inline char* Config_getConnRDMAInterfacesFile(Config* this);
static inline unsigned Config_getConnFallbackExpirationSecs(Config* this);
static inline unsigned Config_getConnNumCommRetries(Config* this);
static inline unsigned Config_getConnCommRetrySecs(Config* this);
static inline bool Config_getConnUnmountRetries(Config* this);
static inline int Config_getConnTCPRcvBufSize(Config* this);
static inline int Config_getConnUDPRcvBufSize(Config* this);
static inline unsigned Config_getConnRDMABufSize(Config* this);
static inline unsigned Config_getConnRDMAFragmentSize(Config* this);
static inline unsigned Config_getConnRDMABufNum(Config* this);
static inline unsigned Config_getConnRDMAMetaBufSize(Config* this);
static inline unsigned Config_getConnRDMAMetaBufNum(Config* this);
static inline unsigned Config_getConnRDMAMetaFragmentSize(Config* this);
static inline char* Config_getConnRDMAKeyType(Config* this);
static inline RDMAKeyType Config_getConnRDMAKeyTypeNum(Config* this);
static inline int Config_getConnRDMATypeOfService(Config* this);
static inline unsigned Config_getRemapConnectionFailureStatus(Config* this);
static inline void Config_setRemapConnectionFailureStatus(Config* this, unsigned status);
static inline char* Config_getConnNetFilterFile(Config* this);
static inline unsigned Config_getConnMaxConcurrentAttempts(Config* this);
static inline char* Config_getConnAuthFile(Config* this);
static inline bool Config_getConnDisableAuthentication(Config* this);
static inline uint64_t Config_getConnAuthHash(Config* this);
static inline char* Config_getConnTcpOnlyFilterFile(Config* this);
static inline char* Config_getTunePreferredMetaFile(Config* this);
static inline char* Config_getTunePreferredStorageFile(Config* this);
static inline char* Config_getTuneFileCacheType(Config* this);
static inline FileCacheType Config_getTuneFileCacheTypeNum(Config* this);
static inline int Config_getTuneFileCacheBufSize(Config* this);
static inline int Config_getTuneFileCacheBufNum(Config* this);
static inline int Config_getTunePathBufSize(Config* this);
static inline int Config_getTunePathBufNum(Config* this);
static inline int Config_getTuneMsgBufSize(Config* this);
static inline int Config_getTuneMsgBufNum(Config* this);
static inline unsigned Config_getTunePageCacheValidityMS(Config* this);
static inline unsigned Config_getTuneDirSubentryCacheValidityMS(Config* this);
static inline unsigned Config_getTuneFileSubentryCacheValidityMS(Config* this);
static inline unsigned Config_getTuneENOENTCacheValidityMS(Config* this);
static inline bool Config_getTuneRemoteFSync(Config* this);
static inline bool Config_getTuneUseGlobalFileLocks(Config* this);
static inline bool Config_getTuneRefreshOnGetAttr(Config* this);
static inline void Config_setTuneRefreshOnGetAttr(Config* this);
static inline unsigned Config_getTuneInodeBlockBits(Config* this);
static inline unsigned Config_getTuneInodeBlockSize(Config* this);
static inline bool Config_getTuneEarlyCloseResponse(Config* this);
static inline bool Config_getTuneUseGlobalAppendLocks(Config* this);
static inline bool Config_getTuneUseBufferedAppend(Config* this);
static inline unsigned Config_getTuneStatFsCacheSecs(Config* this);
static inline bool Config_getTuneCoherentBuffers(Config* this);
static inline char* Config_getSysMgmtdHost(Config* this);
static inline char* Config_getSysInodeIDStyle(Config* this);
static inline InodeIDStyle Config_getSysInodeIDStyleNum(Config* this);
static inline bool Config_getSysCacheInvalidationVersion(Config* this);
static inline bool Config_getSysCreateHardlinksAsSymlinks(Config* this);
static inline unsigned Config_getSysMountSanityCheckMS(Config* this);
static inline bool Config_getSysSyncOnClose(Config* this);
static inline bool Config_getSysSessionCheckOnClose(Config* this);
static inline bool Config_getSysSessionChecksEnabled(Config* this);
static inline unsigned Config_getSysUpdateTargetStatesSecs(Config* this);
static inline unsigned Config_getSysTargetOfflineTimeoutSecs(Config* this);
static inline bool Config_getSysXAttrsEnabled(Config* this);
static inline CheckCapabilities Config_getSysXAttrsCheckCapabilities (Config* this);
static inline bool Config_getSysACLsEnabled(Config* this);
static inline bool Config_getSysXAttrsImplicitlyEnabled(Config* this);
static inline bool Config_getSysBypassFileAccessCheckOnMeta(Config* this);
static inline bool Config_getQuotaEnabled(Config* this);
static inline char* Config_getConnMessagingTimeouts(Config* this);
static inline char* Config_getConnRDMATimeouts(Config* this);
static inline int Config_getConnRDMATimeoutConnect(Config* this);
static inline int Config_getConnRDMATimeoutCompletion(Config* this);
static inline int Config_getConnRDMATimeoutFlowSend(Config* this);
static inline int Config_getConnRDMATimeoutFlowRecv(Config* this);
static inline int Config_getConnRDMATimeoutPoll(Config* this);
enum FileCacheType
{ FILECACHETYPE_None = 0, FILECACHETYPE_Buffered = 1, FILECACHETYPE_Paged = 2,
FILECACHETYPE_Native = 3};
#define INODEIDSTYLE_HASH32HSIEH_STR "hash32"
#define INODEIDSTYLE_HASH64HSIEH_STR "hash64"
#define INODEIDSTYLE_HASH32MD4_STR "md4hash32"
#define INODEIDSTYLE_HASH64MD4_STR "md4hash64"
#define INODEIDSTYLE_DEFAULT INODEIDSTYLE_HASH64MD4_STR
enum InodeIDStyle
{
INODEIDSTYLE_Hash32Hsieh = 0, // hsieh32
INODEIDSTYLE_Hash32MD4, // half-md4
INODEIDSTYLE_Hash64HSieh, // hsieh32
INODEIDSTYLE_Hash64MD4 // half-md4
};
#define INODEIDSTYLE_Default INODEIDSTYLE_Hash64MD4
#define RDMAKEYTYPE_UNSAFE_GLOBAL_STR "global"
#define RDMAKEYTYPE_UNSAFE_DMA_STR "dma"
#define RDMAKEYTYPE_REGISTER_STR "register"
enum RDMAKeyType
{
RDMAKEYTYPE_UnsafeGlobal = 0,
RDMAKEYTYPE_UnsafeDMA,
RDMAKEYTYPE_Register
};
#define CHECKCAPABILITIES_ALWAYS_STR "always"
#define CHECKCAPABILITIES_CACHE_STR "cache"
#define CHECKCAPABILITIES_NEVER_STR "never"
enum CheckCapabilities
{
CHECKCAPABILITIES_Always = 0,
CHECKCAPABILITIES_Cache,
CHECKCAPABILITIES_Never
};
struct Config
{
// configurables
char* cfgFile;
int logLevel;
bool logClientID;
int connPortShift; // shifts all UDP and TCP ports
int connClientPort;
int connMgmtdPort;
int connMgmtdGrpcPort; // pulled from mgmtd and not meant to be configured by the user
bool connUseRDMA;
bool connTCPFallbackEnabled;
unsigned connMaxInternodeNum;
char* connInterfacesFile;
char* connInterfacesList;
char* connRDMAInterfacesFile;
unsigned connFallbackExpirationSecs;
unsigned connNumCommRetries; // auto-computed from connCommRetrySecs
unsigned connCommRetrySecs;
bool connUnmountRetries;
int connTCPRcvBufSize;
int connUDPRcvBufSize;
int connRDMABufSize;
int connRDMAFragmentSize;
int connRDMABufNum;
int connRDMAMetaBufSize;
int connRDMAMetaFragmentSize;
int connRDMAMetaBufNum;
int connRDMATypeOfService;
char* connRDMAKeyType;
RDMAKeyType connRDMAKeyTypeNum;
char* connNetFilterFile; // allowed IP addresses (all IPs allowed, if empty)
unsigned connMaxConcurrentAttempts;
char* connAuthFile;
bool connDisableAuthentication;
uint64_t connAuthHash; // implicitly set based on hash of connAuthFile contents
char* connTcpOnlyFilterFile; // allow only plain TCP (no RDMA etc) to these IPs
char* connMessagingTimeouts;
int connMsgLongTimeout;
int connMsgMediumTimeout;
int connMsgShortTimeout; // connection (response) timeouts in ms
// note: be careful here, because servers not
// responding for >30secs under high load is nothing
// unusual, so never use connMsgShortTimeout for
// IO-related operations.
char* connRDMATimeouts;
int connRDMATimeoutConnect;
int connRDMATimeoutCompletion;
int connRDMATimeoutFlowSend;
int connRDMATimeoutFlowRecv;
int connRDMATimeoutPoll;
char* tunePreferredMetaFile;
char* tunePreferredStorageFile;
char* tuneFileCacheType;
FileCacheType tuneFileCacheTypeNum; // auto-generated based on tuneFileCacheType
int tuneFileCacheBufSize;
int tuneFileCacheBufNum; // 0 means automatic setting
unsigned tunePageCacheValidityMS;
unsigned tuneDirSubentryCacheValidityMS;
unsigned tuneFileSubentryCacheValidityMS;
unsigned tuneENOENTCacheValidityMS;
int tunePathBufSize;
int tunePathBufNum;
int tuneMsgBufSize;
int tuneMsgBufNum; // 0 means automatic setting
bool tuneRemoteFSync;
bool tuneUseGlobalFileLocks; // false means local flock/fcntl locks
bool tuneRefreshOnGetAttr; // false means don't refresh on getattr
unsigned tuneInodeBlockBits; // bitshift for optimal io size seen by stat() (2^n)
unsigned tuneInodeBlockSize; // auto-generated based on tuneInodeBlockBits
bool tuneEarlyCloseResponse; // don't wait for chunk files close result
bool tuneUseGlobalAppendLocks; // false means local append locks
bool tuneUseBufferedAppend; // false disables buffering of append writes
unsigned tuneStatFsCacheSecs; // 0 disables caching of free space info from servers
bool tuneCoherentBuffers; // try to keep buffer cache and page cache coherent
char* sysMgmtdHost;
char* sysInodeIDStyle;
InodeIDStyle sysInodeIDStyleNum; // auto-generated based on sysInodeIDStyle
bool sysCacheInvalidationVersion;
bool sysCreateHardlinksAsSymlinks;
unsigned sysMountSanityCheckMS;
bool sysSyncOnClose;
bool sysSessionCheckOnClose;
bool sysSessionChecksEnabled;
unsigned sysUpdateTargetStatesSecs;
unsigned sysTargetOfflineTimeoutSecs;
bool sysXAttrsEnabled;
CheckCapabilities sysXAttrsCheckCapabilities;
bool sysACLsEnabled;
bool sysXAttrsImplicitlyEnabled; // True when XAttrs have not been enabled in the config file
// but have been enabled by __Config_initImplicitVals
// because ACLs are enabled in the config and XAs are needed
// to store the ACLs.
bool sysBypassFileAccessCheckOnMeta; // bypass file access check on meta server
bool quotaEnabled;
enum EventLogMask eventLogMask;
/* workaround for rename of closed files on nfs */
bool sysRenameEbusyAsXdev;
// internals
StrCpyMap configMap;
// testing
unsigned remapConnectionFailureStatus;
};
char* Config_getCfgFile(Config* this)
{
return this->cfgFile;
}
int Config_getLogLevel(Config* this)
{
return this->logLevel;
}
bool Config_getLogClientID(Config* this)
{
return this->logClientID;
}
int Config_getConnClientPort(Config* this)
{
return this->connClientPort ? (this->connClientPort + this->connPortShift) : 0;
}
int Config_getConnMgmtdPort(Config* this)
{
return this->connMgmtdPort ? (this->connMgmtdPort + this->connPortShift) : 0;
}
int Config_getConnMgmtdGrpcPort(Config* this)
{
// not adding port shift here because connMgmtdGrpcPort is pulled from mgmtd and already shifted
return this->connMgmtdGrpcPort ? this->connMgmtdGrpcPort : 0;
}
void Config_setConnMgmtdGrpcPort(Config* this, int port)
{
this->connMgmtdGrpcPort = port;
}
bool Config_getConnUseRDMA(Config* this)
{
return this->connUseRDMA;
}
bool Config_getConnTCPFallbackEnabled(Config* this)
{
return this->connTCPFallbackEnabled;
}
unsigned Config_getConnMaxInternodeNum(Config* this)
{
return this->connMaxInternodeNum;
}
char* Config_getConnInterfacesFile(Config* this)
{
return this->connInterfacesFile;
}
char* Config_getConnInterfacesList(Config* this)
{
return this->connInterfacesList;
}
char* Config_getConnRDMAInterfacesFile(Config* this)
{
return this->connRDMAInterfacesFile;
}
unsigned Config_getConnFallbackExpirationSecs(Config* this)
{
return this->connFallbackExpirationSecs;
}
unsigned Config_getConnNumCommRetries(Config* this)
{
return this->connNumCommRetries;
}
unsigned Config_getConnCommRetrySecs(Config* this)
{
return this->connCommRetrySecs;
}
bool Config_getConnUnmountRetries(Config* this)
{
return this->connUnmountRetries;
}
int Config_getConnTCPRcvBufSize(Config* this)
{
return this->connTCPRcvBufSize;
}
int Config_getConnUDPRcvBufSize(Config* this)
{
return this->connUDPRcvBufSize;
}
unsigned Config_getConnRDMABufSize(Config* this)
{
return (unsigned) this->connRDMABufSize;
}
unsigned Config_getConnRDMAFragmentSize(Config* this)
{
return (unsigned) this->connRDMAFragmentSize;
}
unsigned Config_getConnRDMABufNum(Config* this)
{
return (unsigned) this->connRDMABufNum;
}
unsigned Config_getConnRDMAMetaBufSize(Config* this)
{
return (unsigned) this->connRDMAMetaBufSize;
}
unsigned Config_getConnRDMAMetaFragmentSize(Config* this)
{
return (unsigned) this->connRDMAMetaFragmentSize;
}
unsigned Config_getConnRDMAMetaBufNum(Config* this)
{
return (unsigned) this->connRDMAMetaBufNum;
}
int Config_getConnRDMATypeOfService(Config* this)
{
return this->connRDMATypeOfService;
}
char* Config_getConnRDMAKeyType(Config* this)
{
return this->connRDMAKeyType;
}
RDMAKeyType Config_getConnRDMAKeyTypeNum(Config* this)
{
return this->connRDMAKeyTypeNum;
}
unsigned Config_getRemapConnectionFailureStatus(Config* this)
{
return this->remapConnectionFailureStatus;
}
void Config_setRemapConnectionFailureStatus(Config* this, unsigned status)
{
this->remapConnectionFailureStatus = status;
}
char* Config_getConnNetFilterFile(Config* this)
{
return this->connNetFilterFile;
}
unsigned Config_getConnMaxConcurrentAttempts(Config* this)
{
return this->connMaxConcurrentAttempts;
}
char* Config_getConnAuthFile(Config* this)
{
return this->connAuthFile;
}
bool Config_getConnDisableAuthentication(Config* this)
{
return this->connDisableAuthentication;
}
uint64_t Config_getConnAuthHash(Config* this)
{
return this->connAuthHash;
}
char* Config_getConnTcpOnlyFilterFile(Config* this)
{
return this->connTcpOnlyFilterFile;
}
char* Config_getTunePreferredMetaFile(Config* this)
{
return this->tunePreferredMetaFile;
}
char* Config_getTunePreferredStorageFile(Config* this)
{
return this->tunePreferredStorageFile;
}
char* Config_getTuneFileCacheType(Config* this)
{
return this->tuneFileCacheType;
}
FileCacheType Config_getTuneFileCacheTypeNum(Config* this)
{
return this->tuneFileCacheTypeNum;
}
int Config_getTuneFileCacheBufSize(Config* this)
{
return this->tuneFileCacheBufSize;
}
int Config_getTuneFileCacheBufNum(Config* this)
{
return this->tuneFileCacheBufNum;
}
int Config_getTunePathBufSize(Config* this)
{
return this->tunePathBufSize;
}
int Config_getTunePathBufNum(Config* this)
{
return this->tunePathBufNum;
}
int Config_getTuneMsgBufSize(Config* this)
{
return this->tuneMsgBufSize;
}
int Config_getTuneMsgBufNum(Config* this)
{
return this->tuneMsgBufNum;
}
unsigned Config_getTunePageCacheValidityMS(Config* this)
{
return this->tunePageCacheValidityMS;
}
unsigned Config_getTuneDirSubentryCacheValidityMS(Config* this)
{
return this->tuneDirSubentryCacheValidityMS;
}
unsigned Config_getTuneFileSubentryCacheValidityMS(Config* this)
{
return this->tuneFileSubentryCacheValidityMS;
}
unsigned Config_getTuneENOENTCacheValidityMS(Config* this)
{
return this->tuneENOENTCacheValidityMS;
}
bool Config_getTuneRemoteFSync(Config* this)
{
return this->tuneRemoteFSync;
}
bool Config_getTuneUseGlobalFileLocks(Config* this)
{
return this->tuneUseGlobalFileLocks;
}
bool Config_getTuneRefreshOnGetAttr(Config* this)
{
return this->tuneRefreshOnGetAttr;
}
bool Config_getTuneCoherentBuffers(Config* this)
{
return this->tuneCoherentBuffers;
}
/**
* Special function to automatically enable TuneRefreshOnGetAttr, e.g. for NFS exports.
*
* Note: We do not use any locks here assuming the right value will propate to all cores rather
* soon.
*/
void Config_setTuneRefreshOnGetAttr(Config* this)
{
this->tuneRefreshOnGetAttr = true;
// do a memory barrier, so that other CPUs get the new value as soon as possible
smp_wmb();
}
unsigned Config_getTuneInodeBlockBits(Config* this)
{
return this->tuneInodeBlockBits;
}
unsigned Config_getTuneInodeBlockSize(Config* this)
{
return this->tuneInodeBlockSize;
}
bool Config_getTuneEarlyCloseResponse(Config* this)
{
return this->tuneEarlyCloseResponse;
}
bool Config_getTuneUseGlobalAppendLocks(Config* this)
{
return this->tuneUseGlobalAppendLocks;
}
bool Config_getTuneUseBufferedAppend(Config* this)
{
return this->tuneUseBufferedAppend;
}
unsigned Config_getTuneStatFsCacheSecs(Config* this)
{
return this->tuneStatFsCacheSecs;
}
char* Config_getSysMgmtdHost(Config* this)
{
return this->sysMgmtdHost;
}
char* Config_getSysInodeIDStyle(Config* this)
{
return this->sysInodeIDStyle;
}
InodeIDStyle Config_getSysInodeIDStyleNum(Config* this)
{
return this->sysInodeIDStyleNum;
}
bool Config_getSysCacheInvalidationVersion(Config* this)
{
return this->sysCacheInvalidationVersion;
}
bool Config_getSysCreateHardlinksAsSymlinks(Config* this)
{
return this->sysCreateHardlinksAsSymlinks;
}
unsigned Config_getSysMountSanityCheckMS(Config* this)
{
return this->sysMountSanityCheckMS;
}
bool Config_getSysSyncOnClose(Config* this)
{
return this->sysSyncOnClose;
}
bool Config_getSysSessionCheckOnClose(Config* this)
{
return this->sysSessionCheckOnClose;
}
bool Config_getSysSessionChecksEnabled(Config* this)
{
return this->sysSessionChecksEnabled;
}
unsigned Config_getSysUpdateTargetStatesSecs(Config* this)
{
return this->sysUpdateTargetStatesSecs;
}
unsigned Config_getSysTargetOfflineTimeoutSecs(Config* this)
{
return this->sysTargetOfflineTimeoutSecs;
}
bool Config_getSysXAttrsEnabled(Config* this)
{
return this->sysXAttrsEnabled;
}
CheckCapabilities Config_getSysXAttrsCheckCapabilities(Config* this)
{
return this->sysXAttrsCheckCapabilities;
}
bool Config_getSysACLsEnabled(Config* this)
{
return this->sysACLsEnabled;
}
bool Config_getSysXAttrsImplicitlyEnabled(Config* this)
{
return this->sysXAttrsImplicitlyEnabled;
}
bool Config_getSysBypassFileAccessCheckOnMeta(Config* this)
{
return this->sysBypassFileAccessCheckOnMeta;
}
bool Config_getQuotaEnabled(Config* this)
{
return this->quotaEnabled;
}
char* Config_getConnMessagingTimeouts(Config* this)
{
return this->connMessagingTimeouts;
}
char* Config_getConnRDMATimeouts(Config* this)
{
return this->connRDMATimeouts;
}
int Config_getConnRDMATimeoutConnect(Config* this)
{
return this->connRDMATimeoutConnect;
}
int Config_getConnRDMATimeoutCompletion(Config* this)
{
return this->connRDMATimeoutCompletion;
}
int Config_getConnRDMATimeoutFlowSend(Config* this)
{
return this->connRDMATimeoutFlowSend;
}
int Config_getConnRDMATimeoutFlowRecv(Config* this)
{
return this->connRDMATimeoutFlowRecv;
}
int Config_getConnRDMATimeoutPoll(Config* this)
{
return this->connRDMATimeoutPoll;
}
#endif /*CONFIG_H_*/

View File

@@ -0,0 +1,238 @@
#include <app/config/MountConfig.h>
#include <common/toolkit/list/StrCpyList.h>
#include <common/toolkit/list/StrCpyListIter.h>
#include <common/Common.h>
#include <linux/parser.h>
enum {
/* Mount options that take string arguments */
Opt_cfgFile,
Opt_logStdFile,
Opt_sysMgmtdHost,
Opt_tunePreferredMetaFile,
Opt_tunePreferredStorageFile,
Opt_connInterfacesList,
Opt_connAuthFile,
Opt_connDisableAuthentication,
/* Mount options that take integer arguments */
Opt_logLevel,
Opt_connPortShift,
Opt_connMgmtdPort,
Opt_sysMountSanityCheckMS,
/* Mount options that take no arguments */
Opt_grpid,
Opt_err
};
static match_table_t fhgfs_mount_option_tokens =
{
/* Mount options that take string arguments */
{ Opt_cfgFile, "cfgFile=%s" },
{ Opt_logStdFile, "logStdFile=%s" },
{ Opt_sysMgmtdHost, "sysMgmtdHost=%s" },
{ Opt_tunePreferredMetaFile, "tunePreferredMetaFile=%s" },
{ Opt_tunePreferredStorageFile, "tunePreferredStorageFile=%s" },
{ Opt_connInterfacesList, "connInterfacesList=%s" },
{ Opt_connAuthFile, "connAuthFile=%s" },
{ Opt_connDisableAuthentication, "connDisableAuthentication=%s" },
/* Mount options that take integer arguments */
{ Opt_logLevel, "logLevel=%d" },
{ Opt_connPortShift, "connPortShift=%d" },
{ Opt_connMgmtdPort, "connMgmtdPort=%u" },
{ Opt_sysMountSanityCheckMS, "sysMountSanityCheckMS=%u" },
{ Opt_grpid, "grpid" },
{ Opt_err, NULL }
};
bool MountConfig_parseFromRawOptions(MountConfig* this, char* mountOptions)
{
char* currentOption;
if(!mountOptions)
{
printk_fhgfs_debug(KERN_INFO, "Mount options = <none>\n");
return true;
}
printk_fhgfs_debug(KERN_INFO, "Mount options = '%s'\n", mountOptions);
while( (currentOption = strsep(&mountOptions, ",") ) != NULL)
{
substring_t args[MAX_OPT_ARGS];
int tokenID;
if(!*currentOption)
continue; // skip empty string
tokenID = match_token(currentOption, fhgfs_mount_option_tokens, args);
switch(tokenID)
{
/* Mount options that take STRING arguments */
case Opt_cfgFile:
{
SAFE_KFREE(this->cfgFile);
this->cfgFile = match_strdup(args);// (string kalloc'ed => needs kfree later)
} break;
case Opt_logStdFile:
{
SAFE_KFREE(this->logStdFile);
this->logStdFile = match_strdup(args); // (string kalloc'ed => needs kfree later)
} break;
case Opt_sysMgmtdHost:
{
SAFE_KFREE(this->sysMgmtdHost);
this->sysMgmtdHost = match_strdup(args); // (string kalloc'ed => needs kfree later)
} break;
case Opt_tunePreferredMetaFile:
{
SAFE_KFREE(this->tunePreferredMetaFile);
this->tunePreferredMetaFile = match_strdup(args); // (string kalloc'ed => needs kfree later)
} break;
case Opt_tunePreferredStorageFile:
{
SAFE_KFREE(this->tunePreferredStorageFile);
this->tunePreferredStorageFile = match_strdup(args); // (string kalloc'ed => needs kfree later)
} break;
case Opt_connInterfacesList:
{
SAFE_KFREE(this->connInterfacesList);
this->connInterfacesList = match_strdup(args);
} break;
case Opt_connAuthFile:
{
SAFE_KFREE(this->connAuthFile);
this->connAuthFile = match_strdup(args);
} break;
case Opt_connDisableAuthentication:
{
SAFE_KFREE(this->connDisableAuthentication);
this->connDisableAuthentication = match_strdup(args);
} break;
/* Mount options that take INTEGER arguments */
case Opt_logLevel:
{
if(match_int(args, &this->logLevel) )
goto err_exit_invalid_option;
this->logLevelDefined = true;
} break;
case Opt_connPortShift:
{
if(match_int(args, &this->connPortShift) )
goto err_exit_invalid_option;
this->connPortShiftDefined = true;
} break;
case Opt_connMgmtdPort:
{
if(match_int(args, &this->connMgmtdPort) )
goto err_exit_invalid_option;
this->connMgmtdPortDefined = true;
} break;
case Opt_sysMountSanityCheckMS:
{
if(match_int(args, &this->sysMountSanityCheckMS) )
goto err_exit_invalid_option;
this->sysMountSanityCheckMSDefined = true;
} break;
case Opt_grpid:
this->grpid = true;
break;
default:
goto err_exit_unknown_option;
}
}
return true;
err_exit_unknown_option:
printk_fhgfs(KERN_WARNING, "Unknown mount option: '%s'\n", currentOption);
return false;
err_exit_invalid_option:
printk_fhgfs(KERN_WARNING, "Invalid mount option: '%s'\n", currentOption);
return false;
}
void MountConfig_showOptions(MountConfig* this, struct seq_file* sf)
{
if (this->cfgFile)
seq_printf(sf, ",cfgFile=%s", this->cfgFile);
if (this->logStdFile)
seq_printf(sf, ",logStdFile=%s", this->logStdFile);
if (this->sysMgmtdHost)
seq_printf(sf, ",sysMgmtdHost=%s", this->sysMgmtdHost);
if (this->tunePreferredMetaFile)
seq_printf(sf, ",tunePreferredMetaFile=%s", this->tunePreferredMetaFile);
if (this->tunePreferredStorageFile)
seq_printf(sf, ",tunePreferredStorageFile=%s", this->tunePreferredStorageFile);
if (this->connInterfacesList)
seq_printf(sf, ",connInterfacesList=%s", this->connInterfacesList);
if (this->connAuthFile)
seq_printf(sf, ",connAuthFile=%s", this->connInterfacesList);
if (this->connDisableAuthentication)
seq_printf(sf, ",connDisableAuthentication=%s", this->connInterfacesList);
if (this->logLevelDefined)
seq_printf(sf, ",logLevel=%d", this->logLevel);
if (this->connPortShiftDefined)
seq_printf(sf, ",connPortShift=%d", this->connPortShift);
if (this->connMgmtdPortDefined)
seq_printf(sf, ",connMgmtdPort=%u", this->connMgmtdPort);
if (this->sysMountSanityCheckMSDefined)
seq_printf(sf, ",sysMountSanityCheckMS=%u", this->sysMountSanityCheckMS);
if (this->grpid)
seq_printf(sf, ",grpid");
}

View File

@@ -0,0 +1,80 @@
#ifndef OPEN_MOUNTCONFIG_H_
#define OPEN_MOUNTCONFIG_H_
#include <common/Common.h>
#include <linux/seq_file.h>
struct MountConfig;
typedef struct MountConfig MountConfig;
static inline void MountConfig_init(MountConfig* this);
static inline MountConfig* MountConfig_construct(void);
static inline void MountConfig_uninit(MountConfig* this);
static inline void MountConfig_destruct(MountConfig* this);
extern bool MountConfig_parseFromRawOptions(MountConfig* this, char* mountOptions);
extern void MountConfig_showOptions(MountConfig* this, struct seq_file* sf);
struct MountConfig
{
char* cfgFile;
char* logStdFile;
char* sysMgmtdHost;
char* tunePreferredMetaFile;
char* tunePreferredStorageFile;
bool logLevelDefined; // true if the value has been specified
bool connPortShiftDefined; // true if the value has been specified
bool connMgmtdPortDefined; // true if the value has been specified
bool sysMountSanityCheckMSDefined; // true if the value has been specified
int logLevel;
unsigned connPortShift;
unsigned connMgmtdPort;
unsigned sysMountSanityCheckMS;
char* connInterfacesList;
char* connAuthFile;
char* connDisableAuthentication;
bool grpid;
};
void MountConfig_init(MountConfig* this)
{
memset(this, 0, sizeof(*this) );
}
struct MountConfig* MountConfig_construct(void)
{
struct MountConfig* this = (MountConfig*)os_kmalloc(sizeof(*this) );
MountConfig_init(this);
return this;
}
void MountConfig_uninit(MountConfig* this)
{
SAFE_KFREE(this->cfgFile);
SAFE_KFREE(this->logStdFile);
SAFE_KFREE(this->sysMgmtdHost);
SAFE_KFREE(this->tunePreferredMetaFile);
SAFE_KFREE(this->tunePreferredStorageFile);
SAFE_KFREE(this->connInterfacesList);
SAFE_KFREE(this->connAuthFile);
SAFE_KFREE(this->connDisableAuthentication);
}
void MountConfig_destruct(MountConfig* this)
{
MountConfig_uninit(this);
kfree(this);
}
#endif /*OPEN_MOUNTCONFIG_H_*/

View File

@@ -0,0 +1,331 @@
#include <common/threading/Thread.h>
#include <common/toolkit/MessagingTk.h>
#include <common/nodes/Node.h>
#include <filesystem/FhgfsOpsSuper.h>
#include <filesystem/FhgfsInode.h>
#include <toolkit/NoAllocBufferStore.h>
#include "Logger.h"
#define LOG_TOPIC_GENERAL_STR "general"
#define LOG_TOPIC_CONN_STR "conn"
#define LOG_TOPIC_COMMKIT_STR "commkit"
#define LOG_TOPIC_UNKNOWN_STR "<unknown>" /* for unknown/invalid log topics */
void Logger_init(Logger* this, App* app, Config* cfg)
{
int i;
this->app = app;
for(i=0; i < LogTopic_LAST; i++)
this->logLevels[i] = Config_getLogLevel(cfg);
this->logFormattedBuf = (char*)os_kmalloc(LOGGER_LOGBUF_SIZE);
this->logContextBuf = (char*)os_kmalloc(LOGGER_LOGBUF_SIZE);
this->clientID = NULL;
Mutex_init(&this->outputMutex);
// Note: The follwing guys exist to avoid deadlocks that would occur when log messages are
// created (by the same thread) while we're already trying to send a log message to the
// helper daemon (e.g. the messages of the NodeConnPool). Such messages will be discarded.
this->currentOutputPID = LOGGER_PID_NOCURRENTOUTPUT;
Mutex_init(&this->multiLockMutex);
}
Logger* Logger_construct(App* app, Config* cfg)
{
Logger* this = (Logger*)os_kmalloc(sizeof(Logger) );
Logger_init(this, app, cfg);
return this;
}
void Logger_uninit(Logger* this)
{
SAFE_KFREE(this->clientID);
SAFE_KFREE(this->logContextBuf);
SAFE_KFREE(this->logFormattedBuf);
Mutex_uninit(&this->multiLockMutex);
Mutex_uninit(&this->outputMutex);
}
void Logger_destruct(Logger* this)
{
Logger_uninit(this);
kfree(this);
}
/**
* Just print a log message with formatting similar to printk().
*
* @param level LogLevel_... value
* @param context the context from which this msg was printed (e.g. the calling function).
* @param msg the log message with formatting, e.g. "%s".
*/
void Logger_logFormatted(Logger* this, LogLevel level, const char* context, const char* msgFormat,
...)
{
// note: cannot be inlined because of variable arg list
va_list ap;
if(level > this->logLevels[LogTopic_GENERAL])
return;
va_start(ap, msgFormat);
__Logger_logTopFormattedGranted(this, LogTopic_GENERAL, level, context, msgFormat, ap);
va_end(ap);
}
void Logger_logTopFormatted(Logger* this, LogTopic logTopic, LogLevel level, const char* context,
const char* msgFormat, ...)
{
// note: cannot be inlined because of variable arg list
va_list ap;
if(level > this->logLevels[logTopic])
return;
va_start(ap, msgFormat);
__Logger_logTopFormattedGranted(this, logTopic, level, context, msgFormat, ap);
va_end(ap);
}
/**
* Log with EntryID
*
* Note: This takes an EntryInfo read-lock. Must be used only if there is no risk of deadlock.
*/
void Logger_logTopFormattedWithEntryID(struct inode* inode, LogTopic logTopic, LogLevel level,
const char* logContext, const char* msgFormat, ...)
{
char* newMsg;
App* app = FhgfsOps_getApp(inode->i_sb);
Logger* log = App_getLogger(app);
FhgfsInode* fhgfsInode = BEEGFS_INODE(inode);
const EntryInfo* entryInfo = FhgfsInode_getEntryInfo(fhgfsInode);
va_list ap;
FhgfsInode_entryInfoReadLock(fhgfsInode); // L O C K entryInfo
va_start(ap, msgFormat);
newMsg = os_kmalloc(LOGGER_LOGBUF_SIZE);
if (newMsg)
snprintf(newMsg, LOGGER_LOGBUF_SIZE, "entryID: %s %s ", EntryInfo_getEntryID(entryInfo),
msgFormat);
else // malloc failed. Likely an out memory situation, we still try to print msgFormat
newMsg = (char*)msgFormat;
Logger_logTopFormattedVA(log, logTopic, level, logContext, newMsg, ap);
va_end(ap);
FhgfsInode_entryInfoReadUnlock(fhgfsInode); // U N L O C K entryInfo
if(newMsg != msgFormat)
kfree(newMsg);
}
/**
* Just print a log message. Similar to Logger_logFormatted(), but take a va_list already
*/
void Logger_logFormattedVA(Logger* this, LogLevel level, const char* context, const char* msgFormat,
va_list ap)
{
if(level > this->logLevels[LogTopic_GENERAL])
return;
__Logger_logTopFormattedGranted(this, LogTopic_GENERAL, level, context, msgFormat, ap);
}
/**
* Just print a log message. Similar to Logger_logTopFormatted(), but take a va_list already
*/
void Logger_logTopFormattedVA(Logger* this, LogTopic logTopic, LogLevel level, const char* context,
const char* msgFormat, va_list ap)
{
if(level > this->logLevels[logTopic])
return;
__Logger_logTopFormattedGranted(this, logTopic, level, context, msgFormat, ap);
}
void Logger_logErrFormatted(Logger* this, const char* context, const char* msgFormat, ...)
{
// note: cannot be inlined because of variable arg list
va_list ap;
va_start(ap, msgFormat);
__Logger_logTopFormattedGranted(this, LogTopic_GENERAL, Log_ERR, context, msgFormat, ap);
va_end(ap);
}
void Logger_logTopErrFormatted(Logger* this, LogTopic logTopic, const char* context,
const char* msgFormat, ...)
{
// note: cannot be inlined because of variable arg list
va_list ap;
va_start(ap, msgFormat);
__Logger_logTopFormattedGranted(this, logTopic, Log_ERR, context, msgFormat, ap);
va_end(ap);
}
/**
* Prints a message to the standard log.
*
* @param level log level (Log_... value)
* @param msg the message
*/
void __Logger_logTopFormattedGranted(Logger* this, LogTopic logTopic, LogLevel level,
const char* context, const char* msgFormat, va_list args)
{
if(__Logger_checkThreadMultiLock(this) )
{
// this thread is already trying to log a message. trying to lock outputMutex would deadlock.
// => discard this message
return;
}
Mutex_lock(&this->outputMutex);
__Logger_setCurrentOutputPID(this, current->pid); // grab currentOutputPID
// evaluate msgFormat
vsnprintf(this->logFormattedBuf, LOGGER_LOGBUF_SIZE, msgFormat, args);
// extend context
if(this->clientID)
snprintf(this->logContextBuf, LOGGER_LOGBUF_SIZE, "%s: %s", this->clientID, context);
else
snprintf(this->logContextBuf, LOGGER_LOGBUF_SIZE, "%s", context);
printk_fhgfs(KERN_INFO, "%s: %s\n", this->logContextBuf, this->logFormattedBuf);
__Logger_setCurrentOutputPID(this, LOGGER_PID_NOCURRENTOUTPUT); // release currentOutputPID
Mutex_unlock(&this->outputMutex);
}
/**
* Note: Call this before locking the outputMutex (because it exists to avoid dead-locking).
*
* @return true if the currentOutputPID is set to the current thread and logging cannot continue;
*/
bool __Logger_checkThreadMultiLock(Logger* this)
{
bool retVal = false;
Mutex_lock(&this->multiLockMutex);
if(this->currentOutputPID == current->pid)
{ // we alread own the outputPID (=> we already own the outputMutex)
retVal = true;
}
Mutex_unlock(&this->multiLockMutex);
return retVal;
}
/**
* Note: Call this only after the thread owns the outputMutex to avoid "stealing".
*/
void __Logger_setCurrentOutputPID(Logger* this, pid_t pid)
{
Mutex_lock(&this->multiLockMutex);
this->currentOutputPID = pid;
Mutex_unlock(&this->multiLockMutex);
}
/**
* Returns a pointer to the static string representation of a log topic (or "<unknown>" for unknown/
* invalid log topic numbers.
*/
const char* Logger_getLogTopicStr(LogTopic logTopic)
{
switch(logTopic)
{
case LogTopic_GENERAL:
return LOG_TOPIC_GENERAL_STR;
case LogTopic_CONN:
return LOG_TOPIC_CONN_STR;
case LogTopic_COMMKIT:
return LOG_TOPIC_COMMKIT_STR;
default:
return LOG_TOPIC_UNKNOWN_STR;
}
}
/**
* Returns the log topic number from a string (not case-sensitive).
*
* @return false if string didn't match any known log topic.
*/
bool Logger_getLogTopicFromStr(const char* logTopicStr, LogTopic* outLogTopic)
{
int i;
for(i=0; i < LogTopic_LAST; i++)
{
const char* currentLogTopicStr = Logger_getLogTopicStr( (LogTopic)i);
if(!strcasecmp(logTopicStr, currentLogTopicStr))
{
*outLogTopic = i;
return true;
}
}
// (note: we carefully set outLogTopic to "general" to not risk leaving it undefined)
*outLogTopic = LogTopic_GENERAL;
return false;
}
/**
* Shortcut to retrieve the level of LogTopic_GENERAL in old code.
* New code should use _getLogTopicLevel() instead.
*/
LogLevel Logger_getLogLevel(Logger* this)
{
return this->logLevels[LogTopic_GENERAL];
}
LogLevel Logger_getLogTopicLevel(Logger* this, LogTopic logTopic)
{
return this->logLevels[logTopic];
}

View File

@@ -0,0 +1,244 @@
#ifndef LOGGER_H_
#define LOGGER_H_
#include <app/config/Config.h>
#include <app/App.h>
#include <common/Common.h>
#include <common/toolkit/StringTk.h>
#include <common/toolkit/Time.h>
#include <common/threading/Mutex.h>
#include <common/Common.h>
#include <common/Common.h>
#define LOGGER_LOGBUF_SIZE 1000 /* max log message length */
#define LOGGER_PID_NOCURRENTOUTPUT 0 /* pid value if outputMutex not locked */
#ifdef LOG_DEBUG_MESSAGES
#define LOG_DEBUG(logger, level, contextStr, msgStr) \
do { Logger_log(logger, level, contextStr, msgStr); } while(0)
#define LOG_DEBUG_TOP(logger, logTopic, level, contextStr, msgStr) \
do { Logger_logTop(logger, logTopic, level, contextStr, msgStr); } while(0)
#define LOG_DEBUG_FORMATTED(logger, level, contextStr, msgStr, ...) \
do { Logger_logFormatted(logger, level, contextStr, msgStr, ## __VA_ARGS__); } while(0)
#define LOG_DEBUG_TOP_FORMATTED(logger, logTopic, level, contextStr, msgStr, ...) \
do { Logger_logTopFormatted(logger, logTopic, level, contextStr, msgStr, ## __VA_ARGS__); } \
while(0)
#else
#define LOG_DEBUG(logger, level, contextStr, msgStr)
#define LOG_DEBUG_TOP(logger, logTopic, level, contextStr, msgStr)
#define LOG_DEBUG_FORMATTED(logger, level, contextStr, msgStr, ...)
#define LOG_DEBUG_TOP_FORMATTED(logger, logTopic, level, contextStr, msgStr, ...)
#endif // LOG_DEBUG_MESSAGES
#define Logger_logFormattedWithEntryID(inode, level, logContext, msgFormat, ...) \
Logger_logTopFormattedWithEntryID(inode, LogTopic_GENERAL, level, logContext, msgFormat, \
##__VA_ARGS__)
// forward declarations...
struct Logger;
typedef struct Logger Logger;
struct Node;
enum LogLevel;
typedef enum LogLevel LogLevel;
enum LogTopic;
typedef enum LogTopic LogTopic;
extern void Logger_init(Logger* this, App* app, Config* cfg);
extern Logger* Logger_construct(App* app, Config* cfg);
extern void Logger_uninit(Logger* this);
extern void Logger_destruct(Logger* this);
__attribute__((format(printf, 4, 5)))
extern void Logger_logFormatted(Logger* this, LogLevel level, const char* context,
const char* msgFormat, ...);
__attribute__((format(printf, 5, 6)))
extern void Logger_logTopFormattedWithEntryID(struct inode* inode, LogTopic logTopic,
LogLevel level, const char* logContext, const char* msgFormat, ...);
__attribute__((format(printf, 5, 6)))
extern void Logger_logTopFormatted(Logger* this, LogTopic logTopic, LogLevel level,
const char* context, const char* msgFormat, ...);
extern void Logger_logFormattedVA(Logger* this, LogLevel level, const char* context,
const char* msgFormat, va_list ap);
extern void Logger_logTopFormattedVA(Logger* this, LogTopic logTopic, LogLevel level,
const char* context, const char* msgFormat, va_list ap);
__attribute__((format(printf, 3, 4)))
extern void Logger_logErrFormatted(Logger* this, const char* context, const char* msgFormat, ...);
__attribute__((format(printf, 4, 5)))
extern void Logger_logTopErrFormatted(Logger* this, LogTopic logTopic, const char* context,
const char* msgFormat, ...);
extern LogLevel Logger_getLogLevel(Logger* this);
extern LogLevel Logger_getLogTopicLevel(Logger* this, LogTopic logTopic);
extern void __Logger_logTopFormattedGranted(Logger* this, LogTopic logTopic, LogLevel level,
const char* context, const char* msgFormat, va_list args);
extern bool __Logger_checkThreadMultiLock(Logger* this);
extern void __Logger_setCurrentOutputPID(Logger* this, pid_t pid);
// static
extern const char* Logger_getLogTopicStr(LogTopic logTopic);
extern bool Logger_getLogTopicFromStr(const char* logTopicStr, LogTopic* logTopic);
// getters & setters
static inline void Logger_setClientID(Logger* this, const char* clientID);
static inline void Logger_setAllLogLevels(Logger* this, LogLevel logLevel);
static inline void Logger_setLogTopicLevel(Logger* this, LogTopic logTopic, LogLevel logLevel);
// inliners
static inline void Logger_log(Logger* this, LogLevel level, const char* context, const char* msg);
static inline void Logger_logTop(Logger* this, LogTopic logTopic, LogLevel level,
const char* context, const char* msg);
static inline void Logger_logErr(Logger* this, const char* context, const char* msg);
static inline void Logger_logTopErr(Logger* this, LogTopic logTopic, const char* context,
const char* msg);
enum LogLevel
{
LOG_NOTHING=-1,
Log_ERR=0, /* system error */
Log_CRITICAL=1, /* something the users should definitely know about */
Log_WARNING=2, /* things that indicate or are related to a problem */
Log_NOTICE=3, /* things that could help finding problems */
Log_DEBUG=4, /* things that are only useful during debugging, often logged with LOG_DEBUG() */
Log_SPAM=5 /* things that are typically too detailed even during normal debugging,
very often with LOG_DEBUG() */
};
/**
* Note: When you add a new log topic, you must also update these places:
* 1) Logger_getLogTopicStr()
* 2) ProcFsHelper_{read/write}_logLevels()
*/
enum LogTopic
{
LogTopic_GENERAL=0, /* everything that is not assigned to a more specific log topic */
LogTopic_CONN, /* connects and disconnects */
LogTopic_COMMKIT, /* CommKitVec */
LogTopic_LAST /* not valid, just exists to define the LogLevelsArray size */
};
typedef signed char LogTopicLevels[LogTopic_LAST]; /* array for per-topic log levels, see LogTopic/
LogLevel. Note: Type is actually type LogLevel, but we use char here because we also allow
"-1" to disable a level. */
/**
* This is the general logger class.
*/
struct Logger
{
// configurables
LogTopicLevels logLevels; // per-topic log levels
// internals
App* app;
Mutex outputMutex;
Mutex multiLockMutex; // to avoid multiple locking of the outputMutex by the same thread
pid_t currentOutputPID; // pid of outputMutex holder (see LOGGER_PID_NOCURRENTOUTPUT)
char* logFormattedBuf; // for logging functions with variable argument list
char* logContextBuf; // for extended context logging
char* clientID; // only set if clientID logging is enabled
};
/**
* Note: Copies the clientID.
*/
void Logger_setClientID(Logger* this, const char* clientID)
{
SAFE_KFREE(this->clientID); // free old clientID
this->clientID = StringTk_strDup(clientID);
}
/**
* Note: This is intended to be used during app destruction to disable logging by setting the levels
* to "-1".
*
* @param logLevel LogLevel_... or "-1" to disable.
*/
void Logger_setAllLogLevels(Logger* this, LogLevel logLevel)
{
int i;
for(i=0; i < LogTopic_LAST; i++)
this->logLevels[i] = logLevel;
}
/**
* @param logLevel LogLevel_... or "-1" to disable.
*/
void Logger_setLogTopicLevel(Logger* this, LogTopic logTopic, LogLevel logLevel)
{
this->logLevels[logTopic] = logLevel;
}
/**
* Log msg for LogTopic_GENERAL.
*
* @param level LogLevel_... value
* @param context the context from which this msg was printed (e.g. the calling function).
* @param msg the log message
*/
void Logger_log(Logger* this, LogLevel level, const char* context, const char* msg)
{
Logger_logFormatted(this, level, context, "%s", msg);
}
/**
* Log msg for a certain log topic.
*
* @param level LogLevel_... value
* @param context the context from which this msg was printed (e.g. the calling function).
* @param msg the log message
*/
void Logger_logTop(Logger* this, LogTopic logTopic, LogLevel level, const char* context,
const char* msg)
{
Logger_logTopFormatted(this, logTopic, level, context, "%s", msg);
}
/**
* Log error msg for LogTopic_GENERAL.
*/
void Logger_logErr(Logger* this, const char* context, const char* msg)
{
Logger_logErrFormatted(this, context, "%s", msg);
}
/**
* Log error msg for a certain log topic.
*/
void Logger_logTopErr(Logger* this, LogTopic logTopic, const char* context, const char* msg)
{
Logger_logTopErrFormatted(this, logTopic, context, "%s", msg);
}
#endif /*LOGGER_H_*/