#include #include #include #include #include #include "TruncFileMsgEx.h" #include FileIDLock TruncFileMsgEx::lock(EntryLockStore& store) { return {&store, getEntryInfo()->getEntryID(), true}; } bool TruncFileMsgEx::processIncoming(ResponseContext& ctx) { return BaseType::processIncoming(ctx); } std::unique_ptr TruncFileMsgEx::executeLocally(ResponseContext& ctx, bool isSecondary) { App* app = Program::getApp(); // update operation counters updateNodeOp(ctx, MetaOpCounter_TRUNCATE); MetaStore* metaStore = Program::getApp()->getMetaStore(); if (!isSecondary) { FhgfsOpsErr truncRes = MsgHelperTrunc::truncFile(getEntryInfo(), getFilesize(), isMsgHeaderFeatureFlagSet(TRUNCFILEMSG_FLAG_USE_QUOTA), getMsgHeaderUserID(), dynAttribs); if (truncRes == FhgfsOpsErr_SUCCESS && (shouldFixTimestamps() || getFileEvent())) { auto [inode, referenceRes] = metaStore->referenceFile(getEntryInfo()); unsigned numHardlinks = 0; if (likely(inode)) { if (shouldFixTimestamps()) fixInodeTimestamp(*inode, mirroredTimestamps, nullptr); numHardlinks = inode->getNumHardlinks(); metaStore->releaseFile(getEntryInfo()->getParentEntryID(), inode); } if (app->getFileEventLogger() && getFileEvent()) { EventContext eventCtx = makeEventContext( getEntryInfo(), getEntryInfo()->getParentEntryID(), getMsgHeaderUserID(), "", numHardlinks, isSecondary ); logEvent(app->getFileEventLogger(), *getFileEvent(), eventCtx); } } return boost::make_unique(truncRes); } auto [inode, referenceRes] = metaStore->referenceFile(getEntryInfo()); if(!inode) return boost::make_unique(referenceRes); inode->setDynAttribs(dynAttribs); if (shouldFixTimestamps()) fixInodeTimestamp(*inode, mirroredTimestamps, nullptr); inode->updateInodeOnDisk(getEntryInfo()); metaStore->releaseFile(getEntryInfo()->getParentEntryID(), inode); return boost::make_unique(FhgfsOpsErr_SUCCESS); } void TruncFileMsgEx::forwardToSecondary(ResponseContext& ctx) { sendToSecondary(ctx, *this, NETMSGTYPE_TruncFileResp); }