mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
aa5e6c7295
Summary: Update the copyright & license headers in C++ files to reflect the relicensing to GPLv2 Reviewed By: wez Differential Revision: D15487078 fbshipit-source-id: 19f24c933a64ecad0d3a692d0f8d2a38b4194b1d
111 lines
3.2 KiB
C++
111 lines
3.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
#pragma once
|
|
#include <folly/futures/Future.h>
|
|
#include <folly/io/async/Request.h>
|
|
#include <atomic>
|
|
#include <utility>
|
|
#include "eden/fs/fuse/FuseChannel.h"
|
|
#include "eden/fs/fuse/FuseTypes.h"
|
|
#include "eden/fs/tracing/EdenStats.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
class Dispatcher;
|
|
|
|
class RequestData : public folly::RequestData {
|
|
FuseChannel* channel_;
|
|
fuse_in_header fuseHeader_;
|
|
// Needed to track stats
|
|
std::chrono::time_point<std::chrono::steady_clock> startTime_;
|
|
FuseThreadStats::HistogramPtr latencyHistogram_{nullptr};
|
|
EdenStats* stats_{nullptr};
|
|
Dispatcher* dispatcher_{nullptr};
|
|
|
|
fuse_in_header stealReq();
|
|
|
|
public:
|
|
static const std::string kKey;
|
|
RequestData(const RequestData&) = delete;
|
|
RequestData& operator=(const RequestData&) = delete;
|
|
RequestData(RequestData&&) = delete;
|
|
RequestData& operator=(RequestData&&) = delete;
|
|
explicit RequestData(
|
|
FuseChannel* channel,
|
|
const fuse_in_header& fuseHeader,
|
|
Dispatcher* dispatcher);
|
|
static RequestData& get();
|
|
static RequestData& create(
|
|
FuseChannel* channel,
|
|
const fuse_in_header& fuseHeader,
|
|
Dispatcher* dispatcher);
|
|
|
|
bool hasCallback() override {
|
|
return false;
|
|
}
|
|
|
|
// Returns true if the current context is being called from inside
|
|
// a FUSE request, false otherwise.
|
|
static bool isFuseRequest();
|
|
|
|
void startRequest(EdenStats* stats, FuseThreadStats::HistogramPtr histogram);
|
|
void finishRequest();
|
|
|
|
// Returns the associated dispatcher instance
|
|
Dispatcher* getDispatcher() const;
|
|
|
|
// Returns the underlying fuse request, throwing an error if it has
|
|
// already been released
|
|
const fuse_in_header& getReq() const;
|
|
|
|
// Returns the underlying fuse request. Unlike getReq this function doesn't
|
|
// throw. The caller is responsible to verify that the fuse_in_header is valid
|
|
// by checking if (fuseHeader.opcode != 0)
|
|
const fuse_in_header& examineReq() const;
|
|
|
|
/** Append error handling clauses to a future chain
|
|
* These clauses result in reporting a fuse request error back to the
|
|
* kernel. */
|
|
template <typename T>
|
|
folly::Future<folly::Unit> catchErrors(folly::Future<T>&& fut) {
|
|
return std::move(fut)
|
|
.thenError(folly::tag_t<std::system_error>{}, systemErrorHandler)
|
|
.thenError(folly::tag_t<std::exception>{}, genericErrorHandler)
|
|
.ensure([] { RequestData::get().finishRequest(); });
|
|
}
|
|
|
|
static void systemErrorHandler(const std::system_error& err);
|
|
static void genericErrorHandler(const std::exception& err);
|
|
|
|
template <typename T>
|
|
void sendReply(const T& payload) {
|
|
channel_->sendReply(stealReq(), payload);
|
|
}
|
|
|
|
void sendReply(folly::ByteRange bytes) {
|
|
channel_->sendReply(stealReq(), bytes);
|
|
}
|
|
|
|
void sendReply(folly::fbvector<iovec>&& vec) {
|
|
channel_->sendReply(stealReq(), std::move(vec));
|
|
}
|
|
|
|
void sendReply(folly::StringPiece piece) {
|
|
channel_->sendReply(stealReq(), folly::ByteRange(piece));
|
|
}
|
|
|
|
// Reply with a negative errno value or 0 for success
|
|
void replyError(int err);
|
|
|
|
// Don't send a reply, just release req_
|
|
void replyNone();
|
|
};
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|