sapling/eden/fs/inodes/Overlay.h
Adam Simpkins fed342da30 store overlay files using inode numbers instead of paths
Summary:
Refactor the Overlay code to store data using inode numbers rather than the
affected file's path in the repository.  This simplifies the TreeInode code a
bit, as we no longer have to rename overlay files to stay in sync with the file
paths.  This also eliminates some crashes when trying to update overlay files
for inodes that have been unlinked (and hence no longer have a path).  This
also includes a few fixes to avoid writing journal entries for unlinked files
too.  Additionally this contains a few fixes to how mode bits are stored in the
overlay, and fixes a bug where create() was ignoring the mode argument.

Reviewed By: wez

Differential Revision: D4517578

fbshipit-source-id: c1e31497dcf62c322b0deff72b0a02675b0509ab
2017-02-10 14:17:52 -08:00

82 lines
2.4 KiB
C++

/*
* Copyright (c) 2016-present, 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.
*
*/
#pragma once
#include <folly/Optional.h>
#include <folly/Range.h>
#include "TreeInode.h"
#include "eden/utils/DirType.h"
#include "eden/utils/PathFuncs.h"
#include "eden/utils/PathMap.h"
namespace facebook {
namespace eden {
namespace overlay {
class OverlayDir;
}
/** Manages the write overlay storage area.
*
* The overlay is where we store files that are not yet part of a snapshot.
*
* The contents of this storage layer are overlaid on top of the object store
* snapshot that is active in a given mount point.
*
* There is one overlay area associated with each eden client instance.
*
* We use the Overlay to manage mutating the structure of the checkout;
* each time we create or delete a directory entry, we do so through
* the overlay class.
*
* The Overlay class keeps track of the mutated tree; if we mutate some
* file "foo/bar/baz" then the Overlay records metadata about the list
* of files in the root, the list of files in "foo", the list of files in
* "foo/bar" and finally materializes "foo/bar/baz".
*/
class Overlay {
public:
explicit Overlay(AbsolutePathPiece localDir);
/** Returns the path to the root of the Overlay storage area */
const AbsolutePath& getLocalDir() const;
void saveOverlayDir(fuse_ino_t inodeNumber, const TreeInode::Dir* dir);
folly::Optional<TreeInode::Dir> loadOverlayDir(fuse_ino_t inodeNumber) const;
void removeOverlayData(fuse_ino_t inodeNumber) const;
/**
* Get the path to the overlay file for the given inode
*/
AbsolutePath getFilePath(fuse_ino_t inodeNumber) const;
/**
* Get the maximum inode number stored in the overlay.
*
* This is called when opening a mount point, to make sure that new inodes
* handed out from this point forwards are always greater than any inodes
* already tracked in the overlay.
*/
fuse_ino_t getMaxRecordedInode();
private:
void initOverlay();
bool isOldFormatOverlay() const;
void readExistingOverlay(int infoFD);
void initNewOverlay();
folly::Optional<overlay::OverlayDir> deserializeOverlayDir(
fuse_ino_t inodeNumber) const;
/** path to ".eden/CLIENT/local" */
AbsolutePath localDir_;
};
}
}