Skip to content

Commit

Permalink
Add methods for privHelper client to interact with fam
Browse files Browse the repository at this point in the history
Summary:
## This Diff
Defined two methods: startFam and stopFam for privHelper client. These methods will be called directly by serviceHandler upon receiving the Thrift requests.

## Context
File Access Monitor(FAM) is a tool to monitor file system access, aiming to find out EdenFS crawlers. The tool will be implemented after the toolchain is ready. Before that, we are going to use [this third-party binary](https://github.com/objective-see/FileMonitor).
This diff stack focuses on integrating the binary into Eden package and spawn a process from privHelper because of the required privileged permission.

Reviewed By: jdelliot

Differential Revision: D69340304

fbshipit-source-id: 815423a1d38ea9af6bcd74d481e60f6299a5baf8
  • Loading branch information
lXXXw authored and facebook-github-bot committed Feb 13, 2025
1 parent 5f2d76b commit d55f8e4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
19 changes: 19 additions & 0 deletions eden/fs/privhelper/PrivHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ class PrivHelper {
*/
FOLLY_NODISCARD virtual folly::Future<pid_t> getServerPid() = 0;

/**
* Start File Access Monitor(FAM).
*
* @param paths A list of paths to be monitored by FAM.
* @param outputPath The path to the output file.
* @return pid of the started FAM process
*/
FOLLY_NODISCARD virtual folly::Future<pid_t> startFam(
const std::vector<std::string>& paths,
const std::string& tmpOutputPath,
const std::string& specifiedOutputPath,
const bool shouldUpload) = 0;

/**
* Stop File Access Monitor(FAM).
*/
FOLLY_NODISCARD virtual folly::Future<StopFileAccessMonitorResponse>
stopFam() = 0;

/**
* setLogFileBlocking() is a wrapper around setLogFile() that blocks until
* the call has completed.
Expand Down
49 changes: 49 additions & 0 deletions eden/fs/privhelper/PrivHelperImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ class PrivHelperClientImpl : public PrivHelper,
std::chrono::nanoseconds duration) override;
Future<folly::Unit> setUseEdenFs(bool useEdenFs) override;
Future<pid_t> getServerPid() override;
Future<pid_t> startFam(
const std::vector<std::string>& paths,
const std::string& tmpOutputPath,
const std::string& specifiedOutputPath,
const bool shouldUpload) override;
Future<StopFileAccessMonitorResponse> stopFam() override;
int stop() override;
int getRawClientFd() const override {
auto state = state_.rlock();
Expand Down Expand Up @@ -588,6 +594,37 @@ Future<pid_t> PrivHelperClientImpl::getServerPid() {
});
}

Future<pid_t> PrivHelperClientImpl::startFam(
const std::vector<std::string>& paths,
const std::string& tmpOutputPath,
const std::string& specifiedOutputPath,
const bool shouldUpload) {
auto xid = getNextXid();
auto request = PrivHelperConn::serializeStartFamRequest(
xid, paths, tmpOutputPath, specifiedOutputPath, shouldUpload);

return sendAndRecv(xid, std::move(request))
.thenValue([](UnixSocket::Message&& response) {
return PrivHelperConn::parseStartFamResponse(response);
});
}

Future<StopFileAccessMonitorResponse> PrivHelperClientImpl::stopFam() {
auto xid = getNextXid();
auto request = PrivHelperConn::serializeStopFamRequest(xid);

return sendAndRecv(xid, std::move(request))
.thenValue([&](UnixSocket::Message&& response) {
StopFileAccessMonitorResponse stopResponse{};
PrivHelperConn::parseStopFamResponse(
response,
stopResponse.tmpOutputPath,
stopResponse.specifiedOutputPath,
stopResponse.shouldUpload);
return stopResponse;
});
}

int PrivHelperClientImpl::stop() {
const auto result = cleanup();
if (result.hasError()) {
Expand Down Expand Up @@ -880,6 +917,18 @@ class StubPrivHelper final : public PrivHelper {
return -1;
}

folly::Future<pid_t> startFam(
const std::vector<std::string>& paths,
const std::string& tmpOutputPath,
const std::string& specifiedOutputPath,
const bool shouldUpload) override {
NOT_IMPLEMENTED();
}

folly::Future<StopFileAccessMonitorResponse> stopFam() override {
NOT_IMPLEMENTED();
}

int stop() override {
return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions eden/fs/testharness/FakePrivHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,18 @@ folly::Future<pid_t> FakePrivHelper::getServerPid() {
return -1;
}

folly::Future<pid_t> FakePrivHelper::startFam(
const std::vector<std::string>& /* paths */,
const std::string& /* tmpOutputPath */,
const std::string& /* specifiedOutputPath */,
const bool /* shouldUpload */) {
return makeFuture<pid_t>(
runtime_error("FakePrivHelper::startFam() not implemented"));
}

folly::Future<StopFileAccessMonitorResponse> FakePrivHelper::stopFam() {
return makeFuture<StopFileAccessMonitorResponse>(
runtime_error("FakePrivHelper::stopFam() not implemented"));
}

} // namespace facebook::eden
6 changes: 6 additions & 0 deletions eden/fs/testharness/FakePrivHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class FakePrivHelper final : public PrivHelper {
std::chrono::nanoseconds duration) override;
folly::Future<folly::Unit> setUseEdenFs(bool useEdenFs) override;
folly::Future<pid_t> getServerPid() override;
folly::Future<pid_t> startFam(
const std::vector<std::string>& paths,
const std::string& tmpOutputPath,
const std::string& specifiedOutputPath,
const bool shouldUpload) override;
folly::Future<StopFileAccessMonitorResponse> stopFam() override;
int stop() override;
int getRawClientFd() const override {
return -1;
Expand Down

0 comments on commit d55f8e4

Please sign in to comment.