From f1da417cea8c71c3319b2b6f81af40765e3caecd Mon Sep 17 00:00:00 2001 From: Xavier Deguillard Date: Fri, 14 Aug 2020 16:00:04 -0700 Subject: [PATCH] win: use the strace logger Summary: On Linux, all the notifications are sent to the strace logger, let's do the same on Windows. Whenever possible, I've tried to use the name of the Linux syscalls that correspond to the notification. Reviewed By: chadaustin Differential Revision: D23105536 fbshipit-source-id: 31c6e545cdec93b0f751682e34c34b894b2890c4 --- eden/fs/inodes/EdenMount.h | 2 +- eden/fs/win/mount/EdenDispatcher.cpp | 66 ++++++++++++++++++++-------- eden/fs/win/utils/Guid.h | 28 ++++++++++++ eden/fs/win/utils/test/GuidTest.cpp | 11 +++++ 4 files changed, 88 insertions(+), 19 deletions(-) diff --git a/eden/fs/inodes/EdenMount.h b/eden/fs/inodes/EdenMount.h index 9def5b1cde..b5e152013c 100644 --- a/eden/fs/inodes/EdenMount.h +++ b/eden/fs/inodes/EdenMount.h @@ -539,7 +539,7 @@ class EdenMount { */ EdenStats* getStats() const; - folly::Logger& getStraceLogger() { + const folly::Logger& getStraceLogger() const { return straceLogger_; } diff --git a/eden/fs/win/mount/EdenDispatcher.cpp b/eden/fs/win/mount/EdenDispatcher.cpp index 0ec946e57d..21e72d633d 100644 --- a/eden/fs/win/mount/EdenDispatcher.cpp +++ b/eden/fs/win/mount/EdenDispatcher.cpp @@ -22,6 +22,7 @@ #include "eden/fs/store/ObjectFetchContext.h" #include "eden/fs/utils/SystemError.h" #include "eden/fs/win/mount/EdenDispatcher.h" +#include "eden/fs/win/utils/Guid.h" #include "eden/fs/win/utils/StringConv.h" #include "eden/fs/win/utils/WinError.h" @@ -82,14 +83,10 @@ HRESULT EdenDispatcher::startEnumeration( const GUID& enumerationId) noexcept { try { auto relPath = RelativePath(callbackData.FilePathName); + auto guid = Guid(enumerationId); - XLOGF( - DBG6, - "startEnumeration mount ({}) path ({}) process ({})", - getMount().getPath(), - relPath, - wideToMultibyteString( - callbackData.TriggeringProcessImageFileName)); + FB_LOGF( + mount_.getStraceLogger(), DBG7, "opendir({}, guid={})", relPath, guid); auto list = getMount() .getInode(relPath) @@ -100,7 +97,7 @@ HRESULT EdenDispatcher::startEnumeration( .get(); auto [iterator, inserted] = enumSessions_.wlock()->emplace( - enumerationId, make_unique(enumerationId, std::move(list))); + enumerationId, make_unique(guid, std::move(list))); DCHECK(inserted); return S_OK; } catch (const std::exception& ex) { @@ -110,6 +107,9 @@ HRESULT EdenDispatcher::startEnumeration( HRESULT EdenDispatcher::endEnumeration(const GUID& enumerationId) noexcept { try { + FB_LOGF( + mount_.getStraceLogger(), DBG7, "releasedir({})", Guid(enumerationId)); + auto erasedCount = enumSessions_.wlock()->erase(enumerationId); DCHECK(erasedCount == 1); return S_OK; @@ -124,11 +124,21 @@ HRESULT EdenDispatcher::getEnumerationData( PCWSTR searchExpression, PRJ_DIR_ENTRY_BUFFER_HANDLE bufferHandle) noexcept { try { + auto guid = Guid(enumerationId); + FB_LOGF( + mount_.getStraceLogger(), + DBG7, + "readdir({}, searchExpression={})", + guid, + searchExpression == nullptr + ? "" + : wideToMultibyteString(searchExpression)); + // // Error if we don't have the session. // auto lockedSessions = enumSessions_.rlock(); - auto sessionIterator = lockedSessions->find(enumerationId); + auto sessionIterator = lockedSessions->find(guid); if (sessionIterator == lockedSessions->end()) { XLOG(DBG5) << "Enum instance not found: " << RelativePath(callbackData.FilePathName); @@ -186,6 +196,7 @@ HRESULT EdenDispatcher::getFileInfo(const PRJ_CALLBACK_DATA& callbackData) noexcept { try { auto relPath = RelativePath(callbackData.FilePathName); + FB_LOGF(mount_.getStraceLogger(), DBG7, "lookup({})", relPath); struct InodeMetadata { // To ensure that the OS has a record of the canonical file name, and not @@ -267,6 +278,7 @@ HRESULT EdenDispatcher::queryFileName(const PRJ_CALLBACK_DATA& callbackData) noexcept { try { auto relPath = RelativePath(callbackData.FilePathName); + FB_LOGF(mount_.getStraceLogger(), DBG7, "access({})", relPath); return getMount() .getInode(relPath) @@ -368,6 +380,13 @@ EdenDispatcher::getFileData( uint32_t length) noexcept { try { auto relPath = RelativePath(callbackData.FilePathName); + FB_LOGF( + mount_.getStraceLogger(), + DBG7, + "read({}, off={}, len={})", + relPath, + byteOffset, + length); auto content = getMount() @@ -587,7 +606,12 @@ folly::Future newFileCreated( PCWSTR destPath, bool isDirectory) { auto relPath = RelativePath(path); - XLOG(DBG6) << "NEW_FILE_CREATED path=" << relPath; + FB_LOGF( + mount.getStraceLogger(), + DBG7, + "{}({})", + isDirectory ? "mkdir" : "mknod", + relPath); return createFile(mount, relPath, isDirectory); } @@ -597,7 +621,7 @@ folly::Future fileOverwritten( PCWSTR destPath, bool isDirectory) { auto relPath = RelativePath(path); - XLOG(DBG6) << "FILE_OVERWRITTEN path=" << relPath; + FB_LOGF(mount.getStraceLogger(), DBG7, "overwrite({})", relPath); return materializeFile(mount, relPath); } @@ -607,7 +631,7 @@ folly::Future fileHandleClosedFileModified( PCWSTR destPath, bool isDirectory) { auto relPath = RelativePath(path); - XLOG(DBG6) << "FILE_HANDLE_CLOSED_FILE_MODIFIED path=" << relPath; + FB_LOGF(mount.getStraceLogger(), DBG7, "modified({})", relPath); return materializeFile(mount, relPath); } @@ -619,7 +643,7 @@ folly::Future fileRenamed( auto oldPath = RelativePath(path); auto newPath = RelativePath(destPath); - XLOG(DBG6) << "FILE_RENAMED oldPath=" << oldPath << " newPath=" << newPath; + FB_LOGF(mount.getStraceLogger(), DBG7, "rename({} -> {})", oldPath, newPath); // When files are moved in and out of the repo, the rename paths are // empty, handle these like creation/removal of files. @@ -637,9 +661,10 @@ folly::Future preRename( PCWSTR path, PCWSTR destPath, bool isDirectory) { - XLOGF( - DBG6, - "PRE_RENAME oldPath={} newPath={}", + FB_LOGF( + mount.getStraceLogger(), + DBG7, + "prerename({} -> {})", RelativePath(path), RelativePath(destPath)); return folly::unit; @@ -651,7 +676,12 @@ folly::Future fileHandleClosedFileDeleted( PCWSTR destPath, bool isDirectory) { auto oldPath = RelativePath(path); - XLOG(DBG6) << "FILE_HANDLE_CLOSED_FILE_MODIFIED path=" << oldPath; + FB_LOGF( + mount.getStraceLogger(), + DBG7, + "{}({})", + isDirectory ? "rmdir" : "unlink", + oldPath); return removeFile(mount, oldPath, isDirectory); } @@ -661,7 +691,7 @@ folly::Future preSetHardlink( PCWSTR destPath, bool isDirectory) { auto relPath = RelativePath(path); - XLOG(DBG6) << "PRE_SET_HARDLINK path=" << relPath; + FB_LOGF(mount.getStraceLogger(), DBG7, "link({})", relPath); return folly::makeFuture(makeHResultErrorExplicit( HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), sformat("Hardlinks are not supported: {}", relPath))); diff --git a/eden/fs/win/utils/Guid.h b/eden/fs/win/utils/Guid.h index b4bd80ef83..918c8b45a8 100644 --- a/eden/fs/win/utils/Guid.h +++ b/eden/fs/win/utils/Guid.h @@ -9,6 +9,7 @@ #include "folly/portability/Windows.h" #include +#include #include "eden/fs/win/utils/WinError.h" namespace facebook { @@ -56,6 +57,23 @@ class Guid { return !(*this == other); } + std::string toString() const noexcept { + return fmt::format( + FMT_STRING( + "{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}"), + guid_.Data1, + guid_.Data2, + guid_.Data3, + guid_.Data4[0], + guid_.Data4[1], + guid_.Data4[2], + guid_.Data4[3], + guid_.Data4[4], + guid_.Data4[5], + guid_.Data4[6], + guid_.Data4[7]); + } + private: GUID guid_; }; @@ -68,3 +86,13 @@ struct CompareGuid { } // namespace eden } // namespace facebook + +namespace fmt { +template <> +struct formatter : formatter { + auto format(const facebook::eden::Guid& guid, format_context& ctx) { + auto s = guid.toString(); + return formatter::format(s, ctx); + } +}; +} // namespace fmt diff --git a/eden/fs/win/utils/test/GuidTest.cpp b/eden/fs/win/utils/test/GuidTest.cpp index 6afa17c5e6..cf18c5e745 100644 --- a/eden/fs/win/utils/test/GuidTest.cpp +++ b/eden/fs/win/utils/test/GuidTest.cpp @@ -6,6 +6,7 @@ */ #include "eden/fs/win/utils/Guid.h" +#include #include #include #include "gtest/gtest.h" @@ -77,3 +78,13 @@ TEST(GuidTest, pointerGuids) { EXPECT_EQ(guid1, guid2); EXPECT_EQ(guid1, guid3); } + +TEST(GuidTest, formatGuid) { + static const GUID testGuid = {0x811305da, + 0xf51e, + 0x4e2d, + {0x92, 0x1, 0xd, 0x12, 0xa1, 0xe7, 0xf8, 0xd5}}; + Guid guid1{testGuid}; + auto s = fmt::format(FMT_STRING("{}"), guid1); + EXPECT_EQ(s, "{811305DA-F51E-4E2D-9201-0D12A1E7F8D5}"); +}