mirror of
https://github.com/facebook/sapling.git
synced 2024-10-04 22:07:44 +03:00
Misc cleanup of cpp files in eden/fs/fuse/
Summary: Misc cleanup (mainly constification). Reviewed By: simpkins Differential Revision: D6720987 fbshipit-source-id: c9c719fce93d413857c48c61e0c920319e865209
This commit is contained in:
parent
0eb330520f
commit
ea2994c045
@ -21,14 +21,14 @@ DirList::DirList(size_t maxSize)
|
||||
: buf_(new char[maxSize]), end_(buf_.get() + maxSize), cur_(buf_.get()) {}
|
||||
|
||||
bool DirList::add(StringPiece name, ino_t inode, dtype_t type, off_t off) {
|
||||
size_t avail = end_ - cur_;
|
||||
auto entLength = FUSE_NAME_OFFSET + name.size();
|
||||
auto fullSize = FUSE_DIRENT_ALIGN(entLength);
|
||||
const size_t avail = end_ - cur_;
|
||||
const auto entLength = FUSE_NAME_OFFSET + name.size();
|
||||
const auto fullSize = FUSE_DIRENT_ALIGN(entLength);
|
||||
if (fullSize > avail) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fuse_dirent* dirent = reinterpret_cast<fuse_dirent*>(cur_);
|
||||
fuse_dirent* const dirent = reinterpret_cast<fuse_dirent*>(cur_);
|
||||
dirent->ino = inode;
|
||||
dirent->off = off;
|
||||
dirent->namelen = name.size();
|
||||
|
@ -27,8 +27,8 @@ namespace fusell {
|
||||
|
||||
std::shared_ptr<FileHandleBase> FileHandleMap::getGenericFileHandle(
|
||||
uint64_t fh) {
|
||||
auto handles = handles_.rlock();
|
||||
auto iter = handles->find(fh);
|
||||
const auto handles = handles_.rlock();
|
||||
const auto iter = handles->find(fh);
|
||||
if (iter == handles->end()) {
|
||||
folly::throwSystemErrorExplicit(
|
||||
EBADF, "file number ", fh, " is not tracked by this FileHandleMap");
|
||||
@ -37,8 +37,8 @@ std::shared_ptr<FileHandleBase> FileHandleMap::getGenericFileHandle(
|
||||
}
|
||||
|
||||
std::shared_ptr<FileHandle> FileHandleMap::getFileHandle(uint64_t fh) {
|
||||
auto handle = getGenericFileHandle(fh);
|
||||
auto result = std::dynamic_pointer_cast<FileHandle>(handle);
|
||||
const auto handle = getGenericFileHandle(fh);
|
||||
const auto result = std::dynamic_pointer_cast<FileHandle>(handle);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@ -47,8 +47,8 @@ std::shared_ptr<FileHandle> FileHandleMap::getFileHandle(uint64_t fh) {
|
||||
}
|
||||
|
||||
std::shared_ptr<DirHandle> FileHandleMap::getDirHandle(uint64_t fh) {
|
||||
auto handle = getGenericFileHandle(fh);
|
||||
auto result = std::dynamic_pointer_cast<DirHandle>(handle);
|
||||
const auto handle = getGenericFileHandle(fh);
|
||||
const auto result = std::dynamic_pointer_cast<DirHandle>(handle);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@ -59,10 +59,9 @@ std::shared_ptr<DirHandle> FileHandleMap::getDirHandle(uint64_t fh) {
|
||||
void FileHandleMap::recordHandle(
|
||||
std::shared_ptr<FileHandleBase> fh,
|
||||
uint64_t number) {
|
||||
auto handles = handles_.wlock();
|
||||
const auto handles = handles_.wlock();
|
||||
|
||||
auto it = handles->find(number);
|
||||
if (it != handles->end()) {
|
||||
if (handles->find(number) != handles->end()) {
|
||||
folly::throwSystemErrorExplicit(
|
||||
EEXIST, "file number ", number, " is already present in the map!?");
|
||||
}
|
||||
@ -113,9 +112,9 @@ uint64_t FileHandleMap::recordHandle(std::shared_ptr<FileHandleBase> fh) {
|
||||
|
||||
std::shared_ptr<FileHandleBase> FileHandleMap::forgetGenericHandle(
|
||||
uint64_t fh) {
|
||||
auto handles = handles_.wlock();
|
||||
const auto handles = handles_.wlock();
|
||||
|
||||
auto iter = handles->find(fh);
|
||||
const auto iter = handles->find(fh);
|
||||
if (iter == handles->end()) {
|
||||
folly::throwSystemErrorExplicit(EBADF);
|
||||
}
|
||||
@ -127,8 +126,8 @@ std::shared_ptr<FileHandleBase> FileHandleMap::forgetGenericHandle(
|
||||
SerializedFileHandleMap FileHandleMap::serializeMap() {
|
||||
SerializedFileHandleMap result;
|
||||
|
||||
auto handles = handles_.wlock();
|
||||
for (auto& it : *handles) {
|
||||
const auto handles = handles_.wlock();
|
||||
for (const auto& it : *handles) {
|
||||
FileHandleMapEntry entry;
|
||||
|
||||
entry.handleId = (int64_t)it.first;
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <folly/io/async/Request.h>
|
||||
#include <folly/system/ThreadName.h>
|
||||
#include <signal.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include "eden/fs/fuse/DirHandle.h"
|
||||
#include "eden/fs/fuse/Dispatcher.h"
|
||||
#include "eden/fs/fuse/FileHandle.h"
|
||||
@ -184,7 +183,7 @@ static std::string flagsToLabel(
|
||||
const std::unordered_map<int32_t, const char*>& labels,
|
||||
uint32_t flags) {
|
||||
std::vector<const char*> bits;
|
||||
for (auto& it : labels) {
|
||||
for (const auto& it : labels) {
|
||||
if (it.first == 0) {
|
||||
// Sometimes a define evaluates to zero; it's not useful so skip it
|
||||
continue;
|
||||
@ -238,8 +237,12 @@ void FuseChannel::replyError(const fuse_in_header& request, int errorCode) {
|
||||
err.error = -errorCode;
|
||||
err.unique = request.unique;
|
||||
auto res = write(fuseDevice_.fd(), &err, sizeof(err));
|
||||
if (res < 0) {
|
||||
throwSystemErrorExplicit(errno, "replyError: error writing to fuse device");
|
||||
if (res != sizeof(err)) {
|
||||
if (res < 0) {
|
||||
throwSystemError("replyError: error writing to fuse device");
|
||||
} else {
|
||||
throw std::runtime_error("unexpected short write to FUSE device");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,14 +277,14 @@ void FuseChannel::sendReply(
|
||||
void FuseChannel::sendRawReply(const iovec iov[], size_t count) const {
|
||||
// Ensure that the length is set correctly
|
||||
DCHECK_EQ(iov[0].iov_len, sizeof(fuse_out_header));
|
||||
auto header = reinterpret_cast<fuse_out_header*>(iov[0].iov_base);
|
||||
const auto header = reinterpret_cast<fuse_out_header*>(iov[0].iov_base);
|
||||
header->len = 0;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
header->len += iov[i].iov_len;
|
||||
}
|
||||
|
||||
auto res = writev(fuseDevice_.fd(), iov, count);
|
||||
int err = errno;
|
||||
const auto res = writev(fuseDevice_.fd(), iov, count);
|
||||
const int err = errno;
|
||||
XLOG(DBG7) << "sendRawReply: unique=" << header->unique
|
||||
<< " header->len=" << header->len << " wrote=" << res;
|
||||
|
||||
@ -468,7 +471,7 @@ void FuseChannel::fuseWorkerThread(size_t threadNumber) {
|
||||
// the promise callbacks while we hold a lock.
|
||||
bool complete = false;
|
||||
{
|
||||
auto requests = requests_.wlock();
|
||||
const auto requests = requests_.wlock();
|
||||
// there may be outstanding requests even though we have
|
||||
// now shut down all of the fuse device processing threads.
|
||||
// If there are none outstanding then we can consider the
|
||||
@ -523,7 +526,7 @@ void FuseChannel::processSession() {
|
||||
break;
|
||||
}
|
||||
|
||||
auto arg_size = static_cast<size_t>(res);
|
||||
const auto arg_size = static_cast<size_t>(res);
|
||||
|
||||
if (arg_size < sizeof(struct fuse_in_header)) {
|
||||
XLOG(ERR) << "read truncated message from kernel fuse device: len="
|
||||
@ -542,7 +545,7 @@ void FuseChannel::processSession() {
|
||||
|
||||
switch (header->opcode) {
|
||||
case FUSE_INIT: {
|
||||
auto in = reinterpret_cast<const fuse_init_in*>(arg);
|
||||
const auto in = reinterpret_cast<const fuse_init_in*>(arg);
|
||||
|
||||
memset(&connInfo_, 0, sizeof(connInfo_));
|
||||
connInfo_.major = FUSE_KERNEL_VERSION;
|
||||
@ -597,15 +600,15 @@ void FuseChannel::processSession() {
|
||||
case FUSE_INTERRUPT: {
|
||||
// no reply is required
|
||||
XLOG(DBG7) << "FUSE_INTERRUPT";
|
||||
auto in = reinterpret_cast<const fuse_interrupt_in*>(arg);
|
||||
const auto in = reinterpret_cast<const fuse_interrupt_in*>(arg);
|
||||
|
||||
// Look up the fuse request; if we find it and the context
|
||||
// is still alive, ctx will be set to it
|
||||
std::shared_ptr<folly::RequestContext> ctx;
|
||||
|
||||
{
|
||||
auto requests = requests_.wlock();
|
||||
auto requestIter = requests->find(in->unique);
|
||||
const auto requests = requests_.wlock();
|
||||
const auto requestIter = requests->find(in->unique);
|
||||
if (requestIter != requests->end()) {
|
||||
ctx = requestIter->second.lock();
|
||||
}
|
||||
@ -615,7 +618,7 @@ void FuseChannel::processSession() {
|
||||
// context so that we can test whether the request is definitely a fuse
|
||||
// request; if so, interrupt it.
|
||||
if (ctx) {
|
||||
RequestContextScopeGuard guard(ctx);
|
||||
const RequestContextScopeGuard guard(ctx);
|
||||
if (RequestData::isFuseRequest()) {
|
||||
RequestData::get().interrupt();
|
||||
}
|
||||
@ -643,7 +646,7 @@ void FuseChannel::processSession() {
|
||||
break;
|
||||
|
||||
default: {
|
||||
auto handlerIter = handlerMap.find(header->opcode);
|
||||
const auto handlerIter = handlerMap.find(header->opcode);
|
||||
if (handlerIter != handlerMap.end()) {
|
||||
// Start a new request and associate it with the current thread.
|
||||
// It will be disassociated when we leave this scope, but will
|
||||
@ -659,7 +662,7 @@ void FuseChannel::processSession() {
|
||||
RequestContext::saveContext()));
|
||||
|
||||
auto& request = RequestData::create(this, *header, dispatcher_);
|
||||
auto& entry = handlerIter->second;
|
||||
const auto& entry = handlerIter->second;
|
||||
|
||||
request.setRequestFuture(
|
||||
request.startRequest(dispatcher_->getStats(), entry.histogram)
|
||||
@ -670,7 +673,7 @@ void FuseChannel::processSession() {
|
||||
}
|
||||
|
||||
unhandledOpcodes_.withULockPtr([&](auto ulock) {
|
||||
auto opcode = header->opcode;
|
||||
const auto opcode = header->opcode;
|
||||
if (ulock->find(opcode) == ulock->end()) {
|
||||
XLOG(ERR) << "unhandled fuse opcode " << opcode << "("
|
||||
<< fuseOpcodeName(opcode) << ")";
|
||||
@ -699,8 +702,8 @@ void FuseChannel::finishRequest(const fuse_in_header& header) {
|
||||
// while we hold a lock.
|
||||
bool complete = false;
|
||||
{
|
||||
auto requests = requests_.wlock();
|
||||
bool erased = requests->erase(header.unique) > 0;
|
||||
const auto requests = requests_.wlock();
|
||||
const bool erased = requests->erase(header.unique) > 0;
|
||||
|
||||
// We only want to fulfil on the transition, so we take
|
||||
// care to gate this on whether we actually erased and
|
||||
@ -715,7 +718,7 @@ void FuseChannel::finishRequest(const fuse_in_header& header) {
|
||||
folly::Future<folly::Unit> FuseChannel::fuseRead(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto read = reinterpret_cast<const fuse_read_in*>(arg);
|
||||
const auto read = reinterpret_cast<const fuse_read_in*>(arg);
|
||||
|
||||
XLOG(DBG7) << "FUSE_READ";
|
||||
|
||||
@ -729,14 +732,14 @@ folly::Future<folly::Unit> FuseChannel::fuseRead(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseWrite(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto write = reinterpret_cast<const fuse_write_in*>(arg);
|
||||
const auto write = reinterpret_cast<const fuse_write_in*>(arg);
|
||||
auto bufPtr = reinterpret_cast<const char*>(write + 1);
|
||||
if (connInfo_.minor < 9) {
|
||||
bufPtr = reinterpret_cast<const char*>(arg) + FUSE_COMPAT_WRITE_IN_SIZE;
|
||||
}
|
||||
XLOG(DBG7) << "FUSE_WRITE " << write->size << " @" << write->offset;
|
||||
|
||||
auto fh = dispatcher_->getFileHandle(write->fh);
|
||||
const auto fh = dispatcher_->getFileHandle(write->fh);
|
||||
|
||||
return fh->write(folly::StringPiece(bufPtr, write->size), write->offset)
|
||||
.then([](size_t wrote) {
|
||||
@ -751,7 +754,7 @@ folly::Future<folly::Unit> FuseChannel::fuseLookup(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
PathComponentPiece name{reinterpret_cast<const char*>(arg)};
|
||||
auto parent = header->nodeid;
|
||||
const auto parent = header->nodeid;
|
||||
|
||||
XLOG(DBG7) << "FUSE_LOOKUP";
|
||||
|
||||
@ -777,7 +780,7 @@ folly::Future<folly::Unit> FuseChannel::fuseGetAttr(
|
||||
|
||||
// If we're new enough, check to see if a file handle was provided
|
||||
if (connInfo_.minor >= 9) {
|
||||
auto getattr = reinterpret_cast<const fuse_getattr_in*>(arg);
|
||||
const auto getattr = reinterpret_cast<const fuse_getattr_in*>(arg);
|
||||
if (getattr->getattr_flags & FUSE_GETATTR_FH) {
|
||||
return dispatcher_->getGenericFileHandle(getattr->fh)
|
||||
->getattr()
|
||||
@ -796,7 +799,7 @@ folly::Future<folly::Unit> FuseChannel::fuseGetAttr(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseSetAttr(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto setattr = reinterpret_cast<const fuse_setattr_in*>(arg);
|
||||
const auto setattr = reinterpret_cast<const fuse_setattr_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_SETATTR";
|
||||
if (setattr->valid & FATTR_FH) {
|
||||
return dispatcher_->getGenericFileHandle(setattr->fh)
|
||||
@ -824,10 +827,10 @@ folly::Future<folly::Unit> FuseChannel::fuseReadLink(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseSymlink(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
const auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
XLOG(DBG7) << "FUSE_SYMLINK";
|
||||
PathComponentPiece name{nameStr};
|
||||
StringPiece link{nameStr + name.stringPiece().size() + 1};
|
||||
const PathComponentPiece name{nameStr};
|
||||
const StringPiece link{nameStr + name.stringPiece().size() + 1};
|
||||
|
||||
return dispatcher_->symlink(header->nodeid, name, link)
|
||||
.then([](fuse_entry_out param) { RequestData::get().sendReply(param); });
|
||||
@ -836,7 +839,7 @@ folly::Future<folly::Unit> FuseChannel::fuseSymlink(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseMknod(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto nod = reinterpret_cast<const fuse_mknod_in*>(arg);
|
||||
const auto nod = reinterpret_cast<const fuse_mknod_in*>(arg);
|
||||
auto nameStr = reinterpret_cast<const char*>(nod + 1);
|
||||
|
||||
if (connInfo_.minor >= 12) {
|
||||
@ -846,7 +849,7 @@ folly::Future<folly::Unit> FuseChannel::fuseMknod(
|
||||
nameStr = reinterpret_cast<const char*>(arg) + FUSE_COMPAT_MKNOD_IN_SIZE;
|
||||
}
|
||||
|
||||
PathComponentPiece name{nameStr};
|
||||
const PathComponentPiece name{nameStr};
|
||||
XLOG(DBG7) << "FUSE_MKNOD " << name;
|
||||
|
||||
return dispatcher_->mknod(header->nodeid, name, nod->mode, nod->rdev)
|
||||
@ -856,9 +859,9 @@ folly::Future<folly::Unit> FuseChannel::fuseMknod(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseMkdir(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto dir = reinterpret_cast<const fuse_mkdir_in*>(arg);
|
||||
auto nameStr = reinterpret_cast<const char*>(dir + 1);
|
||||
PathComponentPiece name{nameStr};
|
||||
const auto dir = reinterpret_cast<const fuse_mkdir_in*>(arg);
|
||||
const auto nameStr = reinterpret_cast<const char*>(dir + 1);
|
||||
const PathComponentPiece name{nameStr};
|
||||
|
||||
XLOG(DBG7) << "FUSE_MKDIR " << name;
|
||||
|
||||
@ -871,8 +874,8 @@ folly::Future<folly::Unit> FuseChannel::fuseMkdir(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseUnlink(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
PathComponentPiece name{nameStr};
|
||||
const auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
const PathComponentPiece name{nameStr};
|
||||
|
||||
XLOG(DBG7) << "FUSE_UNLINK " << name;
|
||||
|
||||
@ -884,8 +887,8 @@ folly::Future<folly::Unit> FuseChannel::fuseUnlink(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseRmdir(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
PathComponentPiece name{nameStr};
|
||||
const auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
const PathComponentPiece name{nameStr};
|
||||
|
||||
XLOG(DBG7) << "FUSE_RMDIR " << name;
|
||||
|
||||
@ -897,10 +900,11 @@ folly::Future<folly::Unit> FuseChannel::fuseRmdir(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseRename(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto rename = reinterpret_cast<const fuse_rename_in*>(arg);
|
||||
auto oldNameStr = reinterpret_cast<const char*>(rename + 1);
|
||||
PathComponentPiece oldName{oldNameStr};
|
||||
PathComponentPiece newName{oldNameStr + oldName.stringPiece().size() + 1};
|
||||
const auto rename = reinterpret_cast<const fuse_rename_in*>(arg);
|
||||
const auto oldNameStr = reinterpret_cast<const char*>(rename + 1);
|
||||
const PathComponentPiece oldName{oldNameStr};
|
||||
const PathComponentPiece newName{oldNameStr + oldName.stringPiece().size() +
|
||||
1};
|
||||
|
||||
XLOG(DBG7) << "FUSE_RENAME " << oldName << " -> " << newName;
|
||||
return dispatcher_->rename(header->nodeid, oldName, rename->newdir, newName)
|
||||
@ -910,9 +914,9 @@ folly::Future<folly::Unit> FuseChannel::fuseRename(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseLink(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto link = reinterpret_cast<const fuse_link_in*>(arg);
|
||||
auto nameStr = reinterpret_cast<const char*>(link + 1);
|
||||
PathComponentPiece newName{nameStr};
|
||||
const auto link = reinterpret_cast<const fuse_link_in*>(arg);
|
||||
const auto nameStr = reinterpret_cast<const char*>(link + 1);
|
||||
const PathComponentPiece newName{nameStr};
|
||||
|
||||
XLOG(DBG7) << "FUSE_LINK " << newName;
|
||||
|
||||
@ -923,7 +927,7 @@ folly::Future<folly::Unit> FuseChannel::fuseLink(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseOpen(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto open = reinterpret_cast<const fuse_open_in*>(arg);
|
||||
const auto open = reinterpret_cast<const fuse_open_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_OPEN";
|
||||
return dispatcher_->open(header->nodeid, open->flags)
|
||||
.then([this](std::shared_ptr<FileHandle> fh) {
|
||||
@ -968,7 +972,7 @@ folly::Future<folly::Unit> FuseChannel::fuseStatFs(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseRelease(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto release = reinterpret_cast<const fuse_release_in*>(arg);
|
||||
const auto release = reinterpret_cast<const fuse_release_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_RELEASE";
|
||||
dispatcher_->getFileHandles().forgetGenericHandle(release->fh);
|
||||
RequestData::get().replyError(0);
|
||||
@ -979,9 +983,9 @@ folly::Future<folly::Unit> FuseChannel::fuseFsync(
|
||||
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto fsync = reinterpret_cast<const fuse_fsync_in*>(arg);
|
||||
const auto fsync = reinterpret_cast<const fuse_fsync_in*>(arg);
|
||||
// There's no symbolic constant for this :-/
|
||||
bool datasync = fsync->fsync_flags & 1;
|
||||
const bool datasync = fsync->fsync_flags & 1;
|
||||
|
||||
XLOG(DBG7) << "FUSE_FSYNC";
|
||||
|
||||
@ -992,11 +996,11 @@ folly::Future<folly::Unit> FuseChannel::fuseFsync(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseSetXAttr(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto setxattr = reinterpret_cast<const fuse_setxattr_in*>(arg);
|
||||
auto nameStr = reinterpret_cast<const char*>(setxattr + 1);
|
||||
StringPiece attrName{nameStr};
|
||||
auto bufPtr = nameStr + attrName.size() + 1;
|
||||
StringPiece value(bufPtr, setxattr->size);
|
||||
const auto setxattr = reinterpret_cast<const fuse_setxattr_in*>(arg);
|
||||
const auto nameStr = reinterpret_cast<const char*>(setxattr + 1);
|
||||
const StringPiece attrName{nameStr};
|
||||
const auto bufPtr = nameStr + attrName.size() + 1;
|
||||
const StringPiece value(bufPtr, setxattr->size);
|
||||
|
||||
XLOG(DBG7) << "FUSE_SETXATTR";
|
||||
|
||||
@ -1007,9 +1011,9 @@ folly::Future<folly::Unit> FuseChannel::fuseSetXAttr(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseGetXAttr(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto getxattr = reinterpret_cast<const fuse_getxattr_in*>(arg);
|
||||
auto nameStr = reinterpret_cast<const char*>(getxattr + 1);
|
||||
StringPiece attrName{nameStr};
|
||||
const auto getxattr = reinterpret_cast<const fuse_getxattr_in*>(arg);
|
||||
const auto nameStr = reinterpret_cast<const char*>(getxattr + 1);
|
||||
const StringPiece attrName{nameStr};
|
||||
XLOG(DBG7) << "FUSE_GETXATTR";
|
||||
return dispatcher_->getxattr(header->nodeid, attrName)
|
||||
.then([size = getxattr->size](std::string attr) {
|
||||
@ -1030,7 +1034,7 @@ folly::Future<folly::Unit> FuseChannel::fuseGetXAttr(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseListXAttr(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto listattr = reinterpret_cast<const fuse_getxattr_in*>(arg);
|
||||
const auto listattr = reinterpret_cast<const fuse_getxattr_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_LISTXATTR";
|
||||
return dispatcher_->listxattr(header->nodeid)
|
||||
.then([size = listattr->size](std::vector<std::string> attrs) {
|
||||
@ -1039,7 +1043,7 @@ folly::Future<folly::Unit> FuseChannel::fuseListXAttr(
|
||||
// Initialize count to include the \0 for each
|
||||
// entry.
|
||||
size_t count = attrs.size();
|
||||
for (auto& attr : attrs) {
|
||||
for (const auto& attr : attrs) {
|
||||
count += attr.size();
|
||||
}
|
||||
|
||||
@ -1066,8 +1070,8 @@ folly::Future<folly::Unit> FuseChannel::fuseListXAttr(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseRemoveXAttr(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
StringPiece attrName{nameStr};
|
||||
const auto nameStr = reinterpret_cast<const char*>(arg);
|
||||
const StringPiece attrName{nameStr};
|
||||
XLOG(DBG7) << "FUSE_REMOVEXATTR";
|
||||
return dispatcher_->removexattr(header->nodeid, attrName).then([]() {
|
||||
RequestData::get().replyError(0);
|
||||
@ -1077,9 +1081,9 @@ folly::Future<folly::Unit> FuseChannel::fuseRemoveXAttr(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseFlush(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto flush = reinterpret_cast<const fuse_flush_in*>(arg);
|
||||
const auto flush = reinterpret_cast<const fuse_flush_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_FLUSH";
|
||||
auto fh = dispatcher_->getFileHandle(flush->fh);
|
||||
const auto fh = dispatcher_->getFileHandle(flush->fh);
|
||||
|
||||
return fh->flush(flush->lock_owner).then([]() {
|
||||
RequestData::get().replyError(0);
|
||||
@ -1089,7 +1093,7 @@ folly::Future<folly::Unit> FuseChannel::fuseFlush(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseOpenDir(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto open = reinterpret_cast<const fuse_open_in*>(arg);
|
||||
const auto open = reinterpret_cast<const fuse_open_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_OPENDIR";
|
||||
return dispatcher_->opendir(header->nodeid, open->flags)
|
||||
.then([this](std::shared_ptr<DirHandle> dh) {
|
||||
@ -1115,10 +1119,10 @@ folly::Future<folly::Unit> FuseChannel::fuseReadDir(
|
||||
const uint8_t* arg) {
|
||||
auto read = reinterpret_cast<const fuse_read_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_READDIR";
|
||||
auto dh = dispatcher_->getDirHandle(read->fh);
|
||||
const auto dh = dispatcher_->getDirHandle(read->fh);
|
||||
return dh->readdir(DirList(read->size), read->offset)
|
||||
.then([](DirList&& list) {
|
||||
auto buf = list.getBuf();
|
||||
const auto buf = list.getBuf();
|
||||
RequestData::get().sendReply(StringPiece(buf));
|
||||
});
|
||||
}
|
||||
@ -1126,7 +1130,7 @@ folly::Future<folly::Unit> FuseChannel::fuseReadDir(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseReleaseDir(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto release = reinterpret_cast<const fuse_release_in*>(arg);
|
||||
const auto release = reinterpret_cast<const fuse_release_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_RELEASEDIR";
|
||||
dispatcher_->getFileHandles().forgetGenericHandle(release->fh);
|
||||
RequestData::get().replyError(0);
|
||||
@ -1136,9 +1140,9 @@ folly::Future<folly::Unit> FuseChannel::fuseReleaseDir(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseFsyncDir(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto fsync = reinterpret_cast<const fuse_fsync_in*>(arg);
|
||||
const auto fsync = reinterpret_cast<const fuse_fsync_in*>(arg);
|
||||
// There's no symbolic constant for this :-/
|
||||
bool datasync = fsync->fsync_flags & 1;
|
||||
const bool datasync = fsync->fsync_flags & 1;
|
||||
|
||||
XLOG(DBG7) << "FUSE_FSYNCDIR";
|
||||
|
||||
@ -1150,7 +1154,7 @@ folly::Future<folly::Unit> FuseChannel::fuseFsyncDir(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseAccess(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto access = reinterpret_cast<const fuse_access_in*>(arg);
|
||||
const auto access = reinterpret_cast<const fuse_access_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_ACCESS";
|
||||
return dispatcher_->access(header->nodeid, access->mask).then([]() {
|
||||
RequestData::get().replyError(0);
|
||||
@ -1160,8 +1164,8 @@ folly::Future<folly::Unit> FuseChannel::fuseAccess(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseCreate(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto create = reinterpret_cast<const fuse_create_in*>(arg);
|
||||
PathComponentPiece name{reinterpret_cast<const char*>(create + 1)};
|
||||
const auto create = reinterpret_cast<const fuse_create_in*>(arg);
|
||||
const PathComponentPiece name{reinterpret_cast<const char*>(create + 1)};
|
||||
XLOG(DBG7) << "FUSE_CREATE " << name;
|
||||
return dispatcher_->create(header->nodeid, name, create->mode, create->flags)
|
||||
.then([this](Dispatcher::Create info) {
|
||||
@ -1182,6 +1186,8 @@ folly::Future<folly::Unit> FuseChannel::fuseCreate(
|
||||
XLOG(DBG7) << "CREATE fh=" << out.fh << " flags=" << out.open_flags;
|
||||
|
||||
folly::fbvector<iovec> vec;
|
||||
|
||||
// 3 to avoid realloc when sendRepy prepends a header to the iovec
|
||||
vec.reserve(3);
|
||||
|
||||
vec.push_back(make_iovec(info.entry));
|
||||
@ -1200,7 +1206,7 @@ folly::Future<folly::Unit> FuseChannel::fuseCreate(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseBmap(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto bmap = reinterpret_cast<const fuse_bmap_in*>(arg);
|
||||
const auto bmap = reinterpret_cast<const fuse_bmap_in*>(arg);
|
||||
XLOG(DBG7) << "FUSE_BMAP";
|
||||
return dispatcher_->bmap(header->nodeid, bmap->blocksize, bmap->block)
|
||||
.then([](uint64_t resultIdx) {
|
||||
@ -1213,9 +1219,9 @@ folly::Future<folly::Unit> FuseChannel::fuseBmap(
|
||||
folly::Future<folly::Unit> FuseChannel::fuseBatchForget(
|
||||
const fuse_in_header* header,
|
||||
const uint8_t* arg) {
|
||||
auto forgets = reinterpret_cast<const fuse_batch_forget_in*>(arg);
|
||||
const auto forgets = reinterpret_cast<const fuse_batch_forget_in*>(arg);
|
||||
auto item = reinterpret_cast<const fuse_forget_one*>(forgets + 1);
|
||||
auto end = item + forgets->count;
|
||||
const auto end = item + forgets->count;
|
||||
XLOG(DBG7) << "FUSE_BATCH_FORGET";
|
||||
|
||||
while (item != end) {
|
||||
|
@ -48,7 +48,7 @@ bool RequestData::isFuseRequest() {
|
||||
}
|
||||
|
||||
RequestData& RequestData::get() {
|
||||
auto data = folly::RequestContext::get()->getContextData(kKey);
|
||||
const auto data = folly::RequestContext::get()->getContextData(kKey);
|
||||
if (UNLIKELY(!data)) {
|
||||
XLOG(FATAL) << "boom for missing RequestData";
|
||||
throw std::runtime_error("no fuse request data set in this context!");
|
||||
@ -77,9 +77,9 @@ Future<folly::Unit> RequestData::startRequest(
|
||||
}
|
||||
|
||||
void RequestData::finishRequest() {
|
||||
auto now = steady_clock::now();
|
||||
auto now_since_epoch = duration_cast<seconds>(now.time_since_epoch());
|
||||
auto diff = duration_cast<microseconds>(now - startTime_);
|
||||
const auto now = steady_clock::now();
|
||||
const auto now_since_epoch = duration_cast<seconds>(now.time_since_epoch());
|
||||
const auto diff = duration_cast<microseconds>(now - startTime_);
|
||||
stats_->get()->recordLatency(latencyHistogram_, diff, now_since_epoch);
|
||||
latencyHistogram_ = nullptr;
|
||||
stats_ = nullptr;
|
||||
|
@ -89,9 +89,9 @@ class PrivHelper {
|
||||
// We only support a single operation at a time for now.
|
||||
// (The privhelper process only has a single thread anyway, and we don't
|
||||
// currently support processing out-of-order responses.)
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
const std::lock_guard<std::mutex> guard(mutex_);
|
||||
|
||||
auto requestXid = nextXid_;
|
||||
const auto requestXid = nextXid_;
|
||||
++nextXid_;
|
||||
msg->xid = requestXid;
|
||||
|
||||
@ -153,7 +153,7 @@ void startPrivHelper(PrivHelperServer* server, const UserInfo& userInfo) {
|
||||
PrivHelperConn serverConn;
|
||||
PrivHelperConn::createConnPair(clientConn, serverConn);
|
||||
|
||||
auto pid = fork();
|
||||
const auto pid = fork();
|
||||
checkUnixError(pid, "failed to fork mount helper");
|
||||
if (pid > 0) {
|
||||
// Parent
|
||||
@ -183,7 +183,7 @@ int stopPrivHelper() {
|
||||
throw std::runtime_error(
|
||||
"attempted to stop the privhelper process when it was not running");
|
||||
}
|
||||
auto result = gPrivHelper->cleanup();
|
||||
const auto result = gPrivHelper->cleanup();
|
||||
gPrivHelper.reset();
|
||||
if (result.hasError()) {
|
||||
folly::throwSystemErrorExplicit(
|
||||
|
@ -77,7 +77,7 @@ void serializeString(Appender& a, StringPiece str) {
|
||||
}
|
||||
|
||||
std::string deserializeString(Cursor& cursor) {
|
||||
auto length = cursor.readBE<uint32_t>();
|
||||
const auto length = cursor.readBE<uint32_t>();
|
||||
return cursor.readFixedString(length);
|
||||
}
|
||||
|
||||
@ -111,16 +111,18 @@ void PrivHelperConn::createConnPair(
|
||||
PrivHelperConn& client,
|
||||
PrivHelperConn& server) {
|
||||
std::array<int, 2> sockpair;
|
||||
int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair.data());
|
||||
checkUnixError(rc, "failed to create socket pair for privhelper");
|
||||
checkUnixError(
|
||||
socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair.data()),
|
||||
"failed to create socket pair for privhelper");
|
||||
SCOPE_FAIL {
|
||||
folly::closeNoInt(sockpair[0]);
|
||||
folly::closeNoInt(sockpair[1]);
|
||||
};
|
||||
|
||||
auto setupSock = [](int sock) {
|
||||
int retcode = fcntl(sock, F_SETFD, FD_CLOEXEC);
|
||||
checkUnixError(retcode, "failed to set privhelper socket as close-on-exec");
|
||||
checkUnixError(
|
||||
fcntl(sock, F_SETFD, FD_CLOEXEC),
|
||||
"failed to set privhelper socket as close-on-exec");
|
||||
|
||||
// Make sure the socket buffer is big enough to support our maximum message
|
||||
// size.
|
||||
@ -129,10 +131,10 @@ void PrivHelperConn::createConnPair(
|
||||
// However, we have to create the socket as SOCK_STREAM rather than
|
||||
// SOCK_DGRAM in order to be able to tell when the remote endpoint
|
||||
// closes the connection.
|
||||
int bufSize = MAX_MSG_LENGTH * 2;
|
||||
retcode =
|
||||
setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &bufSize, sizeof(bufSize));
|
||||
checkUnixError(retcode, "failed to set privhelper socket send buffer size");
|
||||
const int bufSize = MAX_MSG_LENGTH * 2;
|
||||
checkUnixError(
|
||||
setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &bufSize, sizeof(bufSize)),
|
||||
"failed to set privhelper socket send buffer size");
|
||||
};
|
||||
|
||||
setupSock(sockpair[0]);
|
||||
@ -143,8 +145,9 @@ void PrivHelperConn::createConnPair(
|
||||
struct timeval tv;
|
||||
tv.tv_sec = FLAGS_privhelperTimeoutSeconds;
|
||||
tv.tv_usec = 0;
|
||||
rc = setsockopt(sockpair[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
checkUnixError(rc, "failed to set receive timeout on mount helper socket");
|
||||
checkUnixError(
|
||||
setsockopt(sockpair[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)),
|
||||
"failed to set receive timeout on mount helper socket");
|
||||
|
||||
client = PrivHelperConn{sockpair[0]};
|
||||
server = PrivHelperConn{sockpair[1]};
|
||||
@ -164,7 +167,7 @@ void PrivHelperConn::sendMsg(const Message* msg, int fd) {
|
||||
CHECK_LE(msg->dataSize, MAX_MSG_LENGTH);
|
||||
|
||||
// Prepare the message iovec
|
||||
auto msgSize = msg->getFullLength();
|
||||
const auto msgSize = msg->getFullLength();
|
||||
std::array<struct iovec, 1> vec;
|
||||
vec[0].iov_base = const_cast<Message*>(msg);
|
||||
vec[0].iov_len = msgSize;
|
||||
@ -192,7 +195,7 @@ void PrivHelperConn::sendMsg(const Message* msg, int fd) {
|
||||
|
||||
// Finally send the message
|
||||
while (true) {
|
||||
auto bytesSent = sendmsg(socket_, &mh, MSG_NOSIGNAL);
|
||||
const auto bytesSent = sendmsg(socket_, &mh, MSG_NOSIGNAL);
|
||||
if (bytesSent >= 0) {
|
||||
// Assert that we sent a full message.
|
||||
//
|
||||
@ -285,13 +288,15 @@ void PrivHelperConn::recvMsg(Message* msg, folly::File* f) {
|
||||
void PrivHelperConn::serializeMountRequest(
|
||||
Message* msg,
|
||||
StringPiece mountPoint) {
|
||||
auto serializeBody = [&](Appender& a) { serializeString(a, mountPoint); };
|
||||
const auto serializeBody = [mountPoint](Appender& a) {
|
||||
serializeString(a, mountPoint);
|
||||
};
|
||||
serializeMessage(msg, REQ_MOUNT_FUSE, serializeBody);
|
||||
}
|
||||
|
||||
void PrivHelperConn::parseMountRequest(Message* msg, string& mountPoint) {
|
||||
CHECK_EQ(msg->msgType, REQ_MOUNT_FUSE);
|
||||
auto parseBody = [&](Cursor& cursor) {
|
||||
const auto parseBody = [&mountPoint](Cursor& cursor) {
|
||||
mountPoint = deserializeString(cursor);
|
||||
};
|
||||
deserializeMessage(msg, parseBody);
|
||||
@ -300,13 +305,15 @@ void PrivHelperConn::parseMountRequest(Message* msg, string& mountPoint) {
|
||||
void PrivHelperConn::serializeUnmountRequest(
|
||||
Message* msg,
|
||||
StringPiece mountPoint) {
|
||||
auto serializeBody = [&](Appender& a) { serializeString(a, mountPoint); };
|
||||
const auto serializeBody = [mountPoint](Appender& a) {
|
||||
serializeString(a, mountPoint);
|
||||
};
|
||||
serializeMessage(msg, REQ_UNMOUNT_FUSE, serializeBody);
|
||||
}
|
||||
|
||||
void PrivHelperConn::parseUnmountRequest(Message* msg, string& mountPoint) {
|
||||
CHECK_EQ(msg->msgType, REQ_UNMOUNT_FUSE);
|
||||
auto parseBody = [&](Cursor& cursor) {
|
||||
const auto parseBody = [&mountPoint](Cursor& cursor) {
|
||||
mountPoint = deserializeString(cursor);
|
||||
};
|
||||
deserializeMessage(msg, parseBody);
|
||||
@ -315,7 +322,9 @@ void PrivHelperConn::parseUnmountRequest(Message* msg, string& mountPoint) {
|
||||
void PrivHelperConn::serializeTakeoverShutdownRequest(
|
||||
Message* msg,
|
||||
StringPiece mountPoint) {
|
||||
auto serializeBody = [&](Appender& a) { serializeString(a, mountPoint); };
|
||||
const auto serializeBody = [mountPoint](Appender& a) {
|
||||
serializeString(a, mountPoint);
|
||||
};
|
||||
serializeMessage(msg, REQ_TAKEOVER_SHUTDOWN, serializeBody);
|
||||
}
|
||||
|
||||
@ -323,7 +332,7 @@ void PrivHelperConn::parseTakeoverShutdownRequest(
|
||||
Message* msg,
|
||||
string& mountPoint) {
|
||||
CHECK_EQ(msg->msgType, REQ_TAKEOVER_SHUTDOWN);
|
||||
auto parseBody = [&](Cursor& cursor) {
|
||||
const auto parseBody = [&mountPoint](Cursor& cursor) {
|
||||
mountPoint = deserializeString(cursor);
|
||||
};
|
||||
deserializeMessage(msg, parseBody);
|
||||
@ -333,7 +342,7 @@ void PrivHelperConn::serializeTakeoverStartupRequest(
|
||||
Message* msg,
|
||||
folly::StringPiece mountPoint,
|
||||
const std::vector<std::string>& bindMounts) {
|
||||
auto serializeBody = [&](Appender& a) {
|
||||
const auto serializeBody = [mountPoint, &bindMounts](Appender& a) {
|
||||
serializeString(a, mountPoint);
|
||||
a.writeBE<uint32_t>(bindMounts.size());
|
||||
for (const auto& path : bindMounts) {
|
||||
@ -348,7 +357,7 @@ void PrivHelperConn::parseTakeoverStartupRequest(
|
||||
std::string& mountPoint,
|
||||
std::vector<std::string>& bindMounts) {
|
||||
CHECK_EQ(msg->msgType, REQ_TAKEOVER_STARTUP);
|
||||
auto parseBody = [&](Cursor& cursor) {
|
||||
const auto parseBody = [&mountPoint, &bindMounts](Cursor& cursor) {
|
||||
mountPoint = deserializeString(cursor);
|
||||
auto n = cursor.readBE<uint32_t>();
|
||||
while (n-- != 0) {
|
||||
@ -376,7 +385,7 @@ void PrivHelperConn::serializeBindMountRequest(
|
||||
Message* msg,
|
||||
folly::StringPiece clientPath,
|
||||
folly::StringPiece mountPath) {
|
||||
auto serializeBody = [&](Appender& a) {
|
||||
const auto serializeBody = [clientPath, mountPath](Appender& a) {
|
||||
serializeString(a, mountPath);
|
||||
serializeString(a, clientPath);
|
||||
};
|
||||
@ -388,7 +397,7 @@ void PrivHelperConn::parseBindMountRequest(
|
||||
std::string& clientPath,
|
||||
std::string& mountPath) {
|
||||
CHECK_EQ(msg->msgType, REQ_MOUNT_BIND);
|
||||
auto parseBody = [&](Cursor& cursor) {
|
||||
const auto parseBody = [&clientPath, &mountPath](Cursor& cursor) {
|
||||
mountPath = deserializeString(cursor);
|
||||
clientPath = deserializeString(cursor);
|
||||
};
|
||||
@ -404,7 +413,7 @@ void PrivHelperConn::serializeErrorResponse(
|
||||
errnum = sysEx->code().value();
|
||||
}
|
||||
|
||||
auto exceptionType = folly::demangle(typeid(ex));
|
||||
const auto exceptionType = folly::demangle(typeid(ex));
|
||||
serializeErrorResponse(msg, ex.what(), errnum, exceptionType);
|
||||
}
|
||||
|
||||
@ -441,11 +450,11 @@ void PrivHelperConn::rethrowErrorResponse(const Message* msg) {
|
||||
IOBuf buf{IOBuf::WRAP_BUFFER, msg->data, msg->dataSize};
|
||||
Cursor c{&buf};
|
||||
|
||||
int errnum = c.readBE<uint32_t>();
|
||||
const int errnum = c.readBE<uint32_t>();
|
||||
auto size = c.readBE<uint32_t>();
|
||||
auto errmsg = c.readFixedString(size);
|
||||
const auto errmsg = c.readFixedString(size);
|
||||
size = c.readBE<uint32_t>();
|
||||
auto errtype = c.readFixedString(size);
|
||||
const auto errtype = c.readFixedString(size);
|
||||
|
||||
if (errnum != 0) {
|
||||
// If we have an errnum, rethrow the error as a std::system_error
|
||||
|
@ -83,7 +83,7 @@ folly::File PrivHelperServer::fuseMount(const char* mountPath) {
|
||||
// We manually call open() here rather than using the folly::File()
|
||||
// constructor just so we can emit a slightly more helpful message on error.
|
||||
const char* devName = "/dev/fuse";
|
||||
int fd = folly::openNoInt(devName, O_RDWR | O_CLOEXEC);
|
||||
const int fd = folly::openNoInt(devName, O_RDWR | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
if (errno == ENODEV || errno == ENOENT) {
|
||||
throwSystemError(
|
||||
@ -100,7 +100,7 @@ folly::File PrivHelperServer::fuseMount(const char* mountPath) {
|
||||
// We currently don't allow these to be customized by the unprivileged
|
||||
// requester. We could add this functionality in the future if we have a
|
||||
// need for it, but we would need to validate their changes are safe.
|
||||
int rootMode = S_IFDIR;
|
||||
const int rootMode = S_IFDIR;
|
||||
auto mountOpts = folly::sformat(
|
||||
"allow_other,default_permissions,"
|
||||
"rootmode={:o},user_id={},group_id={},fd={}",
|
||||
@ -113,8 +113,7 @@ folly::File PrivHelperServer::fuseMount(const char* mountPath) {
|
||||
// We do not use MS_NODEV. MS_NODEV prevents mount points from being created
|
||||
// inside our filesystem. We currently use bind mounts to point the buck-out
|
||||
// directory to an alternate location outside of eden.
|
||||
int mountFlags = MS_NOSUID;
|
||||
|
||||
const int mountFlags = MS_NOSUID;
|
||||
const char* type = "fuse";
|
||||
int rc = mount("edenfs", mountPath, type, mountFlags, mountOpts.c_str());
|
||||
checkUnixError(rc, "failed to mount");
|
||||
@ -124,8 +123,8 @@ folly::File PrivHelperServer::fuseMount(const char* mountPath) {
|
||||
void PrivHelperServer::bindMount(
|
||||
const char* clientPath,
|
||||
const char* mountPath) {
|
||||
int rc = mount(
|
||||
clientPath, mountPath, /* type */ nullptr, MS_BIND, /* data */ nullptr);
|
||||
const int rc =
|
||||
mount(clientPath, mountPath, /*type*/ nullptr, MS_BIND, /*data*/ nullptr);
|
||||
checkUnixError(rc, "failed to mount");
|
||||
}
|
||||
|
||||
@ -152,10 +151,10 @@ void PrivHelperServer::fuseUnmount(const char* mountPath) {
|
||||
// However for now we always do forced unmount. This helps ensure that
|
||||
// edenfs does not get stuck waiting on unmounts to complete when shutting
|
||||
// down.
|
||||
int umountFlags = UMOUNT_NOFOLLOW | MNT_FORCE | MNT_DETACH;
|
||||
auto rc = umount2(mountPath, umountFlags);
|
||||
const int umountFlags = UMOUNT_NOFOLLOW | MNT_FORCE | MNT_DETACH;
|
||||
const auto rc = umount2(mountPath, umountFlags);
|
||||
if (rc != 0) {
|
||||
int errnum = errno;
|
||||
const int errnum = errno;
|
||||
// EINVAL simply means the path is no longer mounted.
|
||||
// This can happen if it was already manually unmounted by a
|
||||
// separate process.
|
||||
@ -214,16 +213,15 @@ void PrivHelperServer::processUnmountMsg(PrivHelperConn::Message* msg) {
|
||||
conn_.parseUnmountRequest(msg, mountPath);
|
||||
|
||||
try {
|
||||
auto it = mountPoints_.find(mountPath);
|
||||
const auto it = mountPoints_.find(mountPath);
|
||||
if (it == mountPoints_.end()) {
|
||||
throw std::domain_error(
|
||||
folly::to<string>("No FUSE mount found for ", mountPath));
|
||||
}
|
||||
|
||||
auto range = bindMountPoints_.equal_range(mountPath);
|
||||
const auto range = bindMountPoints_.equal_range(mountPath);
|
||||
for (auto it = range.first; it != range.second; ++it) {
|
||||
auto bindMount = it->second;
|
||||
bindUnmount(bindMount.c_str());
|
||||
bindUnmount(it->second.c_str());
|
||||
}
|
||||
bindMountPoints_.erase(range.first, range.second);
|
||||
|
||||
@ -247,13 +245,13 @@ void PrivHelperServer::processTakeoverShutdownMsg(
|
||||
conn_.parseTakeoverShutdownRequest(msg, mountPath);
|
||||
|
||||
try {
|
||||
auto it = mountPoints_.find(mountPath);
|
||||
const auto it = mountPoints_.find(mountPath);
|
||||
if (it == mountPoints_.end()) {
|
||||
throw std::domain_error(
|
||||
folly::to<string>("No FUSE mount found for ", mountPath));
|
||||
}
|
||||
|
||||
auto range = bindMountPoints_.equal_range(mountPath);
|
||||
const auto range = bindMountPoints_.equal_range(mountPath);
|
||||
bindMountPoints_.erase(range.first, range.second);
|
||||
|
||||
mountPoints_.erase(mountPath);
|
||||
@ -306,7 +304,7 @@ void PrivHelperServer::processBindMountMsg(PrivHelperConn::Message* msg) {
|
||||
void PrivHelperServer::messageLoop() {
|
||||
PrivHelperConn::Message msg;
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
conn_.recvMsg(&msg, nullptr);
|
||||
|
||||
switch (msg.msgType) {
|
||||
@ -347,12 +345,10 @@ void PrivHelperServer::cleanupMountPoints() {
|
||||
// exited: these are inside an eden mount, and so accessing the parent
|
||||
// directory will fail with ENOTCONN the eden has already closed the fuse
|
||||
// connection.
|
||||
auto range = bindMountPoints_.equal_range(mountPoint);
|
||||
const auto range = bindMountPoints_.equal_range(mountPoint);
|
||||
for (auto it = range.first; it != range.second; ++it) {
|
||||
auto bindMount = it->second;
|
||||
auto path = bindMount.c_str();
|
||||
bindUnmount(bindMount.c_str());
|
||||
numBindMountsRemoved++;
|
||||
bindUnmount(it->second.c_str());
|
||||
++numBindMountsRemoved;
|
||||
}
|
||||
|
||||
fuseUnmount(mountPoint.c_str());
|
||||
@ -368,8 +364,7 @@ namespace {
|
||||
/// Get the file system ID, or an errno value on error
|
||||
folly::Expected<unsigned long, int> getFSID(const char* path) {
|
||||
struct statvfs data;
|
||||
int rc = statvfs(path, &data);
|
||||
if (rc != 0) {
|
||||
if (statvfs(path, &data) != 0) {
|
||||
return folly::makeUnexpected(errno);
|
||||
}
|
||||
return folly::makeExpected<int>(data.f_fsid);
|
||||
@ -379,7 +374,7 @@ folly::Expected<unsigned long, int> getFSID(const char* path) {
|
||||
void PrivHelperServer::bindUnmount(const char* mountPath) {
|
||||
// Check the current filesystem information for this path,
|
||||
// so we can confirm that it has been unmounted afterwards.
|
||||
auto origFSID = getFSID(mountPath);
|
||||
const auto origFSID = getFSID(mountPath);
|
||||
|
||||
fuseUnmount(mountPath);
|
||||
|
||||
@ -389,9 +384,9 @@ void PrivHelperServer::bindUnmount(const char* mountPath) {
|
||||
//
|
||||
// Give up after 2 seconds even if the unmount does not appear complete.
|
||||
constexpr auto timeout = std::chrono::seconds(2);
|
||||
auto endTime = std::chrono::steady_clock::now() + timeout;
|
||||
const auto endTime = std::chrono::steady_clock::now() + timeout;
|
||||
while (true) {
|
||||
auto fsid = getFSID(mountPath);
|
||||
const auto fsid = getFSID(mountPath);
|
||||
if (!fsid.hasValue()) {
|
||||
// Assume the file system is unmounted if the statvfs() call failed.
|
||||
break;
|
||||
@ -401,8 +396,7 @@ void PrivHelperServer::bindUnmount(const char* mountPath) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (now > endTime) {
|
||||
if (std::chrono::steady_clock::now() > endTime) {
|
||||
XLOG(WARNING) << "error unmounting " << mountPath
|
||||
<< ": mount did not go away after successful unmount call";
|
||||
break;
|
||||
@ -419,13 +413,11 @@ void PrivHelperServer::run() {
|
||||
// to this signal. We don't want to exit immediately--we want to wait until
|
||||
// the parent exits and then umount all outstanding mount points before we
|
||||
// exit.)
|
||||
auto sigret = signal(SIGINT, SIG_IGN);
|
||||
if (sigret == SIG_ERR) {
|
||||
if (signal(SIGINT, SIG_IGN) == SIG_ERR) {
|
||||
XLOG(FATAL) << "error setting SIGINT handler in privhelper process"
|
||||
<< folly::errnoStr(errno);
|
||||
}
|
||||
sigret = signal(SIGTERM, SIG_IGN);
|
||||
if (sigret == SIG_ERR) {
|
||||
if (signal(SIGTERM, SIG_IGN) == SIG_ERR) {
|
||||
XLOG(FATAL) << "error setting SIGTERM handler in privhelper process"
|
||||
<< folly::errnoStr(errno);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ UserInfo::PasswdEntry UserInfo::getPasswdUid(uid_t uid) {
|
||||
|
||||
struct passwd* result;
|
||||
while (true) {
|
||||
auto errnum =
|
||||
const auto errnum =
|
||||
getpwuid_r(uid, &pwd.pwd, pwd.buf.data(), pwd.buf.size(), &result);
|
||||
if (errnum == 0) {
|
||||
break;
|
||||
@ -69,7 +69,7 @@ UserInfo::PasswdEntry UserInfo::getPasswdUid(uid_t uid) {
|
||||
bool UserInfo::initFromSudo() {
|
||||
// If SUDO_UID is not set, return false indicating we could not
|
||||
// find sudo-based identity information.
|
||||
auto sudoUid = getenv("SUDO_UID");
|
||||
const auto sudoUid = getenv("SUDO_UID");
|
||||
if (sudoUid == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@ -78,11 +78,11 @@ bool UserInfo::initFromSudo() {
|
||||
// parse them below. We want to fail hard if we have SUDO_UID but we can't
|
||||
// use it for some reason. We don't want to fall back to running as root in
|
||||
// this case.
|
||||
auto sudoGid = getenv("SUDO_GID");
|
||||
const auto sudoGid = getenv("SUDO_GID");
|
||||
if (sudoGid == nullptr) {
|
||||
throw std::runtime_error("SUDO_UID set without SUDO_GID");
|
||||
}
|
||||
auto sudoUser = getenv("SUDO_USER");
|
||||
const auto sudoUser = getenv("SUDO_USER");
|
||||
if (sudoUser == nullptr) {
|
||||
throw std::runtime_error("SUDO_UID set without SUDO_USER");
|
||||
}
|
||||
@ -129,7 +129,7 @@ void UserInfo::initHomedir(PasswdEntry* pwd) {
|
||||
// generally be run before we have dropped privileges, and we do not want to
|
||||
// try traversing symlinks that the user may not actually have permissions to
|
||||
// resolve.
|
||||
auto homeEnv = getenv("HOME");
|
||||
const auto homeEnv = getenv("HOME");
|
||||
if (homeEnv != nullptr) {
|
||||
homeDirectory_ = canonicalPath(homeEnv);
|
||||
return;
|
||||
@ -154,7 +154,7 @@ UserInfo UserInfo::lookup() {
|
||||
UserInfo info;
|
||||
// First check the real UID. If it is non-root, use that.
|
||||
// This happens if our binary is setuid root and invoked by a non-root user.
|
||||
auto uid = getuid();
|
||||
const auto uid = getuid();
|
||||
if (uid != 0) {
|
||||
info.initFromNonRoot(uid);
|
||||
return info;
|
||||
|
@ -14,7 +14,7 @@
|
||||
TEST(BufVecTest, BufVec) {
|
||||
auto root = folly::IOBuf::wrapBuffer("hello", 5);
|
||||
root->appendChain(folly::IOBuf::wrapBuffer("world", 5));
|
||||
auto bufVec = facebook::eden::fusell::BufVec{std::move(root)};
|
||||
const auto bufVec = facebook::eden::fusell::BufVec{std::move(root)};
|
||||
EXPECT_EQ(10u, bufVec.size());
|
||||
EXPECT_EQ(10u, bufVec.copyData().size());
|
||||
EXPECT_EQ("helloworld", bufVec.copyData());
|
||||
|
@ -73,6 +73,7 @@ DEFINE_int64(
|
||||
"Minimum age of the inodes to be unloaded");
|
||||
|
||||
using apache::thrift::ThriftServer;
|
||||
using facebook::eden::fusell::FuseChannelData;
|
||||
using folly::File;
|
||||
using folly::Future;
|
||||
using folly::Optional;
|
||||
@ -83,7 +84,6 @@ using std::make_shared;
|
||||
using std::shared_ptr;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
using facebook::eden::fusell::FuseChannelData;
|
||||
|
||||
namespace {
|
||||
using namespace facebook::eden;
|
||||
@ -150,7 +150,7 @@ EdenServer::~EdenServer() {}
|
||||
folly::Future<Optional<TakeoverData>> EdenServer::unmountAll(bool doTakeover) {
|
||||
std::vector<Future<Optional<TakeoverData::MountInfo>>> futures;
|
||||
{
|
||||
auto mountPoints = mountPoints_.wlock();
|
||||
const auto mountPoints = mountPoints_.wlock();
|
||||
for (auto& entry : *mountPoints) {
|
||||
const auto& mountPath = entry.first;
|
||||
auto& info = entry.second;
|
||||
@ -217,7 +217,7 @@ void EdenServer::scheduleFlushStats() {
|
||||
void EdenServer::unloadInodes() {
|
||||
std::vector<TreeInodePtr> roots;
|
||||
{
|
||||
auto mountPoints = mountPoints_.wlock();
|
||||
const auto mountPoints = mountPoints_.wlock();
|
||||
for (auto& entry : *mountPoints) {
|
||||
roots.emplace_back(entry.second.edenMount->getRootInode());
|
||||
}
|
||||
@ -284,7 +284,7 @@ void EdenServer::prepare() {
|
||||
// If we are gracefully taking over from an existing edenfs process,
|
||||
// receive its lock, thrift socket, and mount points now.
|
||||
// This will shut down the old process.
|
||||
auto takeoverPath = edenDir_ + PathComponentPiece{"takeover"};
|
||||
const auto takeoverPath = edenDir_ + PathComponentPiece{"takeover"};
|
||||
TakeoverData takeoverData;
|
||||
if (doingTakeover) {
|
||||
takeoverData = takeoverMounts(takeoverPath);
|
||||
@ -298,7 +298,7 @@ void EdenServer::prepare() {
|
||||
}
|
||||
|
||||
XLOG(DBG2) << "opening local RocksDB store";
|
||||
auto rocksPath = edenDir_ + RelativePathPiece{kRocksDBPath};
|
||||
const auto rocksPath = edenDir_ + RelativePathPiece{kRocksDBPath};
|
||||
localStore_ = make_shared<LocalStore>(rocksPath);
|
||||
XLOG(DBG2) << "done opening local RocksDB store";
|
||||
|
||||
@ -311,7 +311,7 @@ void EdenServer::prepare() {
|
||||
// if doingTakeover is true, use the mounts received in TakeoverData
|
||||
if (doingTakeover) {
|
||||
for (auto& info : takeoverData.mountPoints) {
|
||||
auto stateDirectory = info.stateDirectory;
|
||||
const auto stateDirectory = info.stateDirectory;
|
||||
try {
|
||||
auto initialConfig = ClientConfig::loadFromClientDirectory(
|
||||
AbsolutePathPiece{info.mountPath},
|
||||
@ -330,7 +330,7 @@ void EdenServer::prepare() {
|
||||
XLOG(ERR) << "Could not parse config.json file: " << ex.what()
|
||||
<< " Skipping remount step.";
|
||||
}
|
||||
for (auto& client : dirs.items()) {
|
||||
for (const auto& client : dirs.items()) {
|
||||
MountInfo mountInfo;
|
||||
mountInfo.mountPoint = client.first.c_str();
|
||||
auto edenClientPath = edenDir_ + PathComponent("clients") +
|
||||
@ -357,7 +357,7 @@ void EdenServer::run() {
|
||||
prepare();
|
||||
|
||||
// Start listening for graceful takeover requests
|
||||
auto takeoverPath = edenDir_ + PathComponentPiece{kTakeoverSocketName};
|
||||
const auto takeoverPath = edenDir_ + PathComponentPiece{kTakeoverSocketName};
|
||||
takeoverServer_.reset(
|
||||
new TakeoverServer(getMainEventBase(), takeoverPath, this));
|
||||
takeoverServer_->start();
|
||||
@ -433,7 +433,7 @@ Future<Unit> EdenServer::performNormalShutdown() {
|
||||
void EdenServer::shutdownPrivhelper() {
|
||||
// Explicitly stop the privhelper process so we can verify that it
|
||||
// exits normally.
|
||||
auto privhelperExitCode = fusell::stopPrivHelper();
|
||||
const auto privhelperExitCode = fusell::stopPrivHelper();
|
||||
if (privhelperExitCode != 0) {
|
||||
if (privhelperExitCode > 0) {
|
||||
XLOG(ERR) << "privhelper process exited with unexpected code "
|
||||
@ -448,8 +448,8 @@ void EdenServer::shutdownPrivhelper() {
|
||||
void EdenServer::addToMountPoints(std::shared_ptr<EdenMount> edenMount) {
|
||||
auto mountPath = edenMount->getPath().stringPiece();
|
||||
{
|
||||
auto mountPoints = mountPoints_.wlock();
|
||||
auto ret = mountPoints->emplace(mountPath, EdenMountInfo(edenMount));
|
||||
const auto mountPoints = mountPoints_.wlock();
|
||||
const auto ret = mountPoints->emplace(mountPath, EdenMountInfo(edenMount));
|
||||
if (!ret.second) {
|
||||
// This mount point already exists.
|
||||
throw EdenError(folly::to<string>(
|
||||
@ -543,11 +543,11 @@ folly::Future<folly::Unit> EdenServer::performTakeoverFuseStart(
|
||||
folly::Future<std::shared_ptr<EdenMount>> EdenServer::mount(
|
||||
std::unique_ptr<ClientConfig> initialConfig,
|
||||
Optional<TakeoverData::MountInfo>&& optionalTakeover) {
|
||||
auto repoType = initialConfig->getRepoType();
|
||||
auto backingStore = getBackingStore(repoType, initialConfig->getRepoSource());
|
||||
auto backingStore = getBackingStore(
|
||||
initialConfig->getRepoType(), initialConfig->getRepoSource());
|
||||
auto objectStore =
|
||||
std::make_unique<ObjectStore>(getLocalStore(), backingStore);
|
||||
bool doTakeover = optionalTakeover.hasValue();
|
||||
const bool doTakeover = optionalTakeover.hasValue();
|
||||
|
||||
auto edenMount = EdenMount::create(
|
||||
std::move(initialConfig),
|
||||
@ -619,8 +619,8 @@ Future<Unit> EdenServer::unmount(StringPiece mountPath) {
|
||||
try {
|
||||
auto future = Future<Unit>::makeEmpty();
|
||||
{
|
||||
auto mountPoints = mountPoints_.wlock();
|
||||
auto it = mountPoints->find(mountPath);
|
||||
const auto mountPoints = mountPoints_.wlock();
|
||||
const auto it = mountPoints->find(mountPath);
|
||||
if (it == mountPoints->end()) {
|
||||
return makeFuture<Unit>(
|
||||
std::out_of_range("no such mount point " + mountPath.str()));
|
||||
@ -641,7 +641,7 @@ Future<Unit> EdenServer::unmount(StringPiece mountPath) {
|
||||
void EdenServer::mountFinished(
|
||||
EdenMount* edenMount,
|
||||
folly::Optional<TakeoverData::MountInfo> takeover) {
|
||||
auto mountPath = edenMount->getPath().stringPiece();
|
||||
const auto mountPath = edenMount->getPath().stringPiece();
|
||||
XLOG(INFO) << "mount point \"" << mountPath << "\" stopped";
|
||||
unregisterStats(edenMount);
|
||||
|
||||
@ -649,15 +649,15 @@ void EdenServer::mountFinished(
|
||||
folly::SharedPromise<Unit> unmountPromise;
|
||||
folly::Optional<folly::Promise<TakeoverData::MountInfo>> takeoverPromise;
|
||||
{
|
||||
auto mountPoints = mountPoints_.wlock();
|
||||
auto it = mountPoints->find(mountPath);
|
||||
const auto mountPoints = mountPoints_.wlock();
|
||||
const auto it = mountPoints->find(mountPath);
|
||||
CHECK(it != mountPoints->end());
|
||||
unmountPromise = std::move(it->second.unmountPromise);
|
||||
takeoverPromise = std::move(it->second.takeoverPromise);
|
||||
mountPoints->erase(it);
|
||||
}
|
||||
|
||||
bool doTakeover = takeoverPromise.hasValue();
|
||||
const bool doTakeover = takeoverPromise.hasValue();
|
||||
|
||||
// Shutdown the EdenMount, and fulfill the unmount promise
|
||||
// when the shutdown completes
|
||||
@ -683,7 +683,7 @@ void EdenServer::mountFinished(
|
||||
EdenServer::MountList EdenServer::getMountPoints() const {
|
||||
MountList results;
|
||||
{
|
||||
auto mountPoints = mountPoints_.rlock();
|
||||
const auto mountPoints = mountPoints_.rlock();
|
||||
for (const auto& entry : *mountPoints) {
|
||||
results.emplace_back(entry.second.edenMount);
|
||||
}
|
||||
@ -692,7 +692,7 @@ EdenServer::MountList EdenServer::getMountPoints() const {
|
||||
}
|
||||
|
||||
shared_ptr<EdenMount> EdenServer::getMount(StringPiece mountPath) const {
|
||||
auto mount = getMountOrNull(mountPath);
|
||||
const auto mount = getMountOrNull(mountPath);
|
||||
if (!mount) {
|
||||
throw EdenError(folly::to<string>(
|
||||
"mount point \"", mountPath, "\" is not known to this eden instance"));
|
||||
@ -701,8 +701,8 @@ shared_ptr<EdenMount> EdenServer::getMount(StringPiece mountPath) const {
|
||||
}
|
||||
|
||||
shared_ptr<EdenMount> EdenServer::getMountOrNull(StringPiece mountPath) const {
|
||||
auto mountPoints = mountPoints_.rlock();
|
||||
auto it = mountPoints->find(mountPath);
|
||||
const auto mountPoints = mountPoints_.rlock();
|
||||
const auto it = mountPoints->find(mountPath);
|
||||
if (it == mountPoints->end()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -714,12 +714,12 @@ shared_ptr<BackingStore> EdenServer::getBackingStore(
|
||||
StringPiece name) {
|
||||
BackingStoreKey key{type.str(), name.str()};
|
||||
SYNCHRONIZED(lockedStores, backingStores_) {
|
||||
auto it = lockedStores.find(key);
|
||||
const auto it = lockedStores.find(key);
|
||||
if (it != lockedStores.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
auto store = createBackingStore(type, name);
|
||||
const auto store = createBackingStore(type, name);
|
||||
lockedStores.emplace(key, store);
|
||||
return store;
|
||||
}
|
||||
@ -736,11 +736,11 @@ shared_ptr<BackingStore> EdenServer::createBackingStore(
|
||||
if (type == "null") {
|
||||
return make_shared<EmptyBackingStore>();
|
||||
} else if (type == "hg") {
|
||||
auto repoPath = realpath(name);
|
||||
const auto repoPath = realpath(name);
|
||||
return make_shared<HgBackingStore>(
|
||||
repoPath, localStore_.get(), threadPool_.get());
|
||||
} else if (type == "git") {
|
||||
auto repoPath = realpath(name);
|
||||
const auto repoPath = realpath(name);
|
||||
return make_shared<GitBackingStore>(repoPath, localStore_.get());
|
||||
} else {
|
||||
throw std::domain_error(
|
||||
@ -749,8 +749,6 @@ shared_ptr<BackingStore> EdenServer::createBackingStore(
|
||||
}
|
||||
|
||||
void EdenServer::createThriftServer() {
|
||||
auto address = getThriftAddress(FLAGS_thrift_address, edenDir_);
|
||||
|
||||
server_ = make_shared<ThriftServer>();
|
||||
server_->setMaxRequests(FLAGS_thrift_max_requests);
|
||||
server_->setNumIOWorkerThreads(FLAGS_thrift_num_workers);
|
||||
@ -759,14 +757,14 @@ void EdenServer::createThriftServer() {
|
||||
|
||||
handler_ = make_shared<EdenServiceHandler>(this);
|
||||
server_->setInterface(handler_);
|
||||
server_->setAddress(address);
|
||||
server_->setAddress(getThriftAddress(FLAGS_thrift_address, edenDir_));
|
||||
|
||||
serverEventHandler_ = make_shared<ThriftServerEventHandler>(this);
|
||||
server_->setServerEventHandler(serverEventHandler_);
|
||||
}
|
||||
|
||||
bool EdenServer::acquireEdenLock() {
|
||||
auto lockPath = edenDir_ + PathComponentPiece{kLockFileName};
|
||||
const auto lockPath = edenDir_ + PathComponentPiece{kLockFileName};
|
||||
lockFile_ = folly::File(lockPath.value(), O_WRONLY | O_CREAT);
|
||||
if (!lockFile_.try_lock()) {
|
||||
lockFile_.close();
|
||||
@ -774,9 +772,9 @@ bool EdenServer::acquireEdenLock() {
|
||||
}
|
||||
|
||||
// Write the PID (with a newline) to the lockfile.
|
||||
int fd = lockFile_.fd();
|
||||
const int fd = lockFile_.fd();
|
||||
folly::ftruncateNoInt(fd, /* len */ 0);
|
||||
auto pidContents = folly::to<std::string>(getpid(), "\n");
|
||||
const auto pidContents = folly::to<std::string>(getpid(), "\n");
|
||||
folly::writeNoInt(fd, pidContents.data(), pidContents.size());
|
||||
|
||||
return true;
|
||||
@ -799,7 +797,7 @@ void EdenServer::prepareThriftAddress() {
|
||||
if (addr.getFamily() != AF_UNIX) {
|
||||
return;
|
||||
}
|
||||
int rc = unlink(addr.getPath().c_str());
|
||||
const int rc = unlink(addr.getPath().c_str());
|
||||
if (rc != 0 && errno != ENOENT) {
|
||||
// This might happen if we don't have permission to remove the file.
|
||||
folly::throwSystemError(
|
||||
@ -840,7 +838,7 @@ folly::Future<TakeoverData> EdenServer::startTakeoverShutdown() {
|
||||
// the server. The easiest way to avoid completely closing the server
|
||||
// socket for now is simply by duplicating the socket to a new fd.
|
||||
// We will transfer this duplicated FD to the new edenfs process.
|
||||
int takeoverThriftSocket = dup(server_->getListenSocket());
|
||||
const int takeoverThriftSocket = dup(server_->getListenSocket());
|
||||
folly::checkUnixError(
|
||||
takeoverThriftSocket,
|
||||
"error duplicating thrift server socket during graceful takeover");
|
||||
@ -860,7 +858,7 @@ void EdenServer::shutdownSubscribers() const {
|
||||
// those down now, otherwise they will block the server_->stop() call
|
||||
// below
|
||||
XLOG(DBG1) << "cancel all subscribers prior to stopping thrift";
|
||||
auto mountPoints = mountPoints_.wlock();
|
||||
const auto mountPoints = mountPoints_.wlock();
|
||||
for (auto& entry : *mountPoints) {
|
||||
auto& info = entry.second;
|
||||
info.edenMount->getJournal().cancelAllSubscribers();
|
||||
@ -888,19 +886,18 @@ folly::SocketAddress getThriftAddress(
|
||||
// If the argument is empty, default to a Unix socket placed next
|
||||
// to the mount point
|
||||
if (argument.empty()) {
|
||||
auto socketPath = edenDir + PathComponentPiece{kThriftSocketName};
|
||||
addr.setFromPath(socketPath.stringPiece());
|
||||
addr.setFromPath(
|
||||
(edenDir + PathComponentPiece{kThriftSocketName}).stringPiece());
|
||||
return addr;
|
||||
}
|
||||
|
||||
// Check to see if the argument looks like a port number
|
||||
uint16_t port;
|
||||
bool validPort{false};
|
||||
bool validPort{true};
|
||||
try {
|
||||
port = folly::to<uint16_t>(argument);
|
||||
validPort = true;
|
||||
} catch (const std::range_error& ex) {
|
||||
// validPort = false
|
||||
validPort = false;
|
||||
}
|
||||
if (validPort) {
|
||||
addr.setFromLocalPort(port);
|
||||
|
@ -71,6 +71,7 @@ class EdenServer : private TakeoverHandler {
|
||||
AbsolutePathPiece edenDir,
|
||||
AbsolutePathPiece etcEdenDir,
|
||||
AbsolutePathPiece configPath);
|
||||
|
||||
virtual ~EdenServer();
|
||||
|
||||
/**
|
||||
|
@ -34,6 +34,9 @@ class EdenServiceHandler : virtual public StreamingEdenServiceSvIf,
|
||||
public:
|
||||
explicit EdenServiceHandler(EdenServer* server);
|
||||
|
||||
EdenServiceHandler(EdenServiceHandler const&) = delete;
|
||||
EdenServiceHandler& operator=(EdenServiceHandler const&) = delete;
|
||||
|
||||
facebook::fb303::cpp2::fb_status getStatus() override;
|
||||
|
||||
void mount(std::unique_ptr<MountInfo> info) override;
|
||||
@ -152,10 +155,6 @@ class EdenServiceHandler : virtual public StreamingEdenServiceSvIf,
|
||||
void shutdown() override;
|
||||
|
||||
private:
|
||||
// Forbidden copy constructor and assignment operator
|
||||
EdenServiceHandler(EdenServiceHandler const&) = delete;
|
||||
EdenServiceHandler& operator=(EdenServiceHandler const&) = delete;
|
||||
|
||||
folly::Future<Hash> getSHA1ForPath(
|
||||
folly::StringPiece mountPoint,
|
||||
folly::StringPiece path);
|
||||
|
@ -85,20 +85,17 @@ int main(int argc, char** argv) {
|
||||
return EX_USAGE;
|
||||
}
|
||||
// We require edenDir to already exist, so use realpath() to resolve it.
|
||||
auto edenDir = facebook::eden::realpath(FLAGS_edenDir);
|
||||
const auto edenDir = facebook::eden::realpath(FLAGS_edenDir);
|
||||
|
||||
// It's okay if the etcEdenDir and configPath don't exist, so use
|
||||
// normalizeBestEffort() to try resolving symlinks in these paths but don't
|
||||
// fail if they don't exist.
|
||||
auto etcEdenDir = normalizeBestEffort(FLAGS_etcEdenDir);
|
||||
const auto etcEdenDir = normalizeBestEffort(FLAGS_etcEdenDir);
|
||||
|
||||
AbsolutePath configPath;
|
||||
std::string configPathStr = FLAGS_configPath;
|
||||
if (configPathStr.empty()) {
|
||||
configPath = identity.getHomeDirectory() + PathComponentPiece{".edenrc"};
|
||||
} else {
|
||||
configPath = normalizeBestEffort(configPathStr);
|
||||
}
|
||||
const std::string configPathStr = FLAGS_configPath;
|
||||
const AbsolutePath configPath = configPathStr.empty()
|
||||
? identity.getHomeDirectory() + PathComponentPiece{".edenrc"}
|
||||
: normalizeBestEffort(configPathStr);
|
||||
|
||||
EdenServer server(edenDir, etcEdenDir, configPath);
|
||||
server.run();
|
||||
|
Loading…
Reference in New Issue
Block a user