mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
28f7b4a0b0
Summary: This commit causes a desktop notification to be shown if we generate EIO or ETIMEDOUT responses via fuse; the prompt is intended to make it obvious to the user that they need to connect to the VPN. The commit by itself doesn't show a notification, it allows configuring a command that can be run to do something to show a notification. The test plan includes one such configuration for our corp environment. * It doesn't trigger for thrift-originated downloads (eg: prefetch), only for VFS operations through FUSE. * Ideally we'd know exactly when we have a network related error in the store code and use that to trigger the notification. However, we have a rather convoluted set of importers and fallbacks today, one of which is interpreting a generic response returned from a pipe, so it is not especially clear exactly where we should locate the logic Reviewed By: chadaustin Differential Revision: D17513364 fbshipit-source-id: 45134f3672679cb5580cb0c1bc12a0d6e38525ca
152 lines
4.4 KiB
C++
152 lines
4.4 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/telemetry/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};
|
|
|
|
struct EdenTopStats {
|
|
public:
|
|
bool didImportFromBackingStore() const {
|
|
return didImportFromBackingStore_.load(std::memory_order_relaxed);
|
|
}
|
|
void setDidImportFromBackingStore() {
|
|
didImportFromBackingStore_.store(true, std::memory_order_relaxed);
|
|
}
|
|
std::chrono::nanoseconds fuseDuration{0};
|
|
|
|
private:
|
|
std::atomic<bool> didImportFromBackingStore_{false};
|
|
} edenTopStats_;
|
|
|
|
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;
|
|
|
|
EdenTopStats& getEdenTopStats();
|
|
|
|
// 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,
|
|
Notifications* FOLLY_NULLABLE notifications) {
|
|
return std::move(fut)
|
|
.thenError(
|
|
folly::tag_t<folly::FutureTimeout>{},
|
|
[notifications](auto&& err) {
|
|
timeoutErrorHandler(err, notifications);
|
|
})
|
|
.thenError(
|
|
folly::tag_t<std::system_error>{},
|
|
[notifications](auto&& err) {
|
|
systemErrorHandler(err, notifications);
|
|
})
|
|
.thenError(
|
|
folly::tag_t<std::exception>{},
|
|
[notifications](auto&& err) {
|
|
genericErrorHandler(err, notifications);
|
|
})
|
|
.ensure([] { RequestData::get().finishRequest(); });
|
|
}
|
|
|
|
static void systemErrorHandler(
|
|
const std::system_error& err,
|
|
Notifications* FOLLY_NULLABLE notifications);
|
|
static void genericErrorHandler(
|
|
const std::exception& err,
|
|
Notifications* FOLLY_NULLABLE notifications);
|
|
static void timeoutErrorHandler(
|
|
const folly::FutureTimeout& err,
|
|
Notifications* FOLLY_NULLABLE notifications);
|
|
|
|
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
|