2016-05-12 23:43:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2016-12-01 02:48:04 +03:00
|
|
|
#include "FileHandle.h"
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2016-09-19 22:48:11 +03:00
|
|
|
#include "EdenMount.h"
|
2016-05-17 00:48:25 +03:00
|
|
|
#include "FileData.h"
|
2016-12-01 02:48:04 +03:00
|
|
|
#include "FileInode.h"
|
2016-05-12 23:43:17 +03:00
|
|
|
#include "eden/fs/store/LocalStore.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
FileHandle::FileHandle(
|
|
|
|
std::shared_ptr<FileInode> inode,
|
2016-05-17 00:48:29 +03:00
|
|
|
std::shared_ptr<FileData> data,
|
|
|
|
int flags)
|
2016-12-01 02:48:04 +03:00
|
|
|
: inode_(std::move(inode)), data_(std::move(data)), openFlags_(flags) {}
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
FileHandle::~FileHandle() {
|
2016-05-17 00:48:25 +03:00
|
|
|
// Must reset the data point prior to calling fileHandleDidClose,
|
|
|
|
// otherwise it will see a use count that is too high and won't
|
|
|
|
// reclaim resources soon enough.
|
|
|
|
data_.reset();
|
2016-05-12 23:43:17 +03:00
|
|
|
inode_->fileHandleDidClose();
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<fusell::Dispatcher::Attr> FileHandle::getattr() {
|
2016-05-12 23:43:17 +03:00
|
|
|
return inode_->getattr();
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<fusell::Dispatcher::Attr> FileHandle::setattr(
|
2016-05-12 23:43:17 +03:00
|
|
|
const struct stat& attr,
|
|
|
|
int to_set) {
|
|
|
|
return inode_->setattr(attr, to_set);
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
bool FileHandle::preserveCache() const {
|
2016-05-12 23:43:17 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
bool FileHandle::isSeekable() const {
|
2016-05-12 23:43:17 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<fusell::BufVec> FileHandle::read(size_t size, off_t off) {
|
2016-05-17 00:48:25 +03:00
|
|
|
return data_->read(size, off);
|
2016-05-12 23:43:17 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<size_t> FileHandle::write(fusell::BufVec&& buf, off_t off) {
|
2016-09-19 22:48:11 +03:00
|
|
|
SCOPE_SUCCESS {
|
|
|
|
auto myname = inode_->parentInode_->getNameMgr()->resolvePathToNode(
|
|
|
|
inode_->getNodeId());
|
|
|
|
inode_->parentInode_->getMount()->getJournal().wlock()->addDelta(
|
|
|
|
std::make_unique<JournalDelta>(JournalDelta{myname}));
|
|
|
|
};
|
2016-05-17 00:48:30 +03:00
|
|
|
return data_->write(std::move(buf), off);
|
2016-05-12 23:43:17 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<size_t> FileHandle::write(folly::StringPiece str, off_t off) {
|
2016-09-19 22:48:11 +03:00
|
|
|
SCOPE_SUCCESS {
|
|
|
|
auto myname = inode_->parentInode_->getNameMgr()->resolvePathToNode(
|
|
|
|
inode_->getNodeId());
|
|
|
|
inode_->parentInode_->getMount()->getJournal().wlock()->addDelta(
|
|
|
|
std::make_unique<JournalDelta>(JournalDelta{myname}));
|
|
|
|
};
|
2016-05-17 00:48:30 +03:00
|
|
|
return data_->write(str, off);
|
2016-05-12 23:43:17 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<folly::Unit> FileHandle::flush(uint64_t lock_owner) {
|
2016-05-17 00:48:30 +03:00
|
|
|
data_->flush(lock_owner);
|
2016-05-12 23:43:17 +03:00
|
|
|
return folly::Unit{};
|
|
|
|
}
|
|
|
|
|
2016-12-01 02:48:04 +03:00
|
|
|
folly::Future<folly::Unit> FileHandle::fsync(bool datasync) {
|
2016-05-17 00:48:30 +03:00
|
|
|
data_->fsync(datasync);
|
2016-05-12 23:43:17 +03:00
|
|
|
return folly::Unit{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|