| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
#ifndef CVMFS_FUSE_EVICT_H_ |
| 6 |
|
|
#define CVMFS_FUSE_EVICT_H_ |
| 7 |
|
|
|
| 8 |
|
|
#include <pthread.h> |
| 9 |
|
|
#include <stdint.h> |
| 10 |
|
|
|
| 11 |
|
|
#include "bigvector.h" |
| 12 |
|
|
#include "duplex_fuse.h" |
| 13 |
|
|
#include "duplex_testing.h" |
| 14 |
|
|
#include "shortstring.h" |
| 15 |
|
|
#include "util/atomic.h" |
| 16 |
|
|
#include "util/concurrency.h" |
| 17 |
|
|
#include "util/single_copy.h" |
| 18 |
|
|
|
| 19 |
|
|
namespace glue { |
| 20 |
|
|
class InodeTracker; |
| 21 |
|
|
class DentryTracker; |
| 22 |
|
|
} // namespace glue |
| 23 |
|
|
|
| 24 |
|
|
class MountPoint; |
| 25 |
|
|
|
| 26 |
|
|
/** |
| 27 |
|
|
* This class can poke all known dentries out of the kernel caches. This allows |
| 28 |
|
|
* for faster remount/reload of the fuse module because caches don't need to |
| 29 |
|
|
* drain out by timeout. If the fuse library doesn't provide |
| 30 |
|
|
* fuse_lowlevel_notify_inval_entry, it falls back to waiting for drainout. |
| 31 |
|
|
* |
| 32 |
|
|
* Evicting entries from the cache must be done from a separate thread to |
| 33 |
|
|
* avoid a deadlock in the fuse callbacks (see Fuse documentation). |
| 34 |
|
|
*/ |
| 35 |
|
|
class FuseInvalidator : SingleCopy { |
| 36 |
|
|
friend class T_FuseInvalidator; // for T_FuseInvalidator.SetUp() |
| 37 |
|
|
FRIEND_TEST(T_FuseInvalidator, StartStop); |
| 38 |
|
|
FRIEND_TEST(T_FuseInvalidator, InvalidateTimeout); |
| 39 |
|
|
FRIEND_TEST(T_FuseInvalidator, InvalidateOps); |
| 40 |
|
|
|
| 41 |
|
|
public: |
| 42 |
|
|
static bool HasFuseNotifyInval(); |
| 43 |
|
|
|
| 44 |
|
|
/** |
| 45 |
|
|
* Used to track the progress of an "invalidation" request. The invalidator |
| 46 |
|
|
* will evict cache entries for a duration given by the timeout. For very |
| 47 |
|
|
* large caches, active eviction can take longer than the timeout. |
| 48 |
|
|
* |
| 49 |
|
|
* The caller needs to keep Handle active until IsDone() is true; |
| 50 |
|
|
*/ |
| 51 |
|
|
class Handle : SingleCopy { |
| 52 |
|
|
friend class FuseInvalidator; |
| 53 |
|
|
|
| 54 |
|
|
public: |
| 55 |
|
|
explicit Handle(unsigned timeout_s); |
| 56 |
|
|
~Handle(); |
| 57 |
|
189 |
bool IsDone() const { return atomic_read32(status_) == 1; } |
| 58 |
|
9 |
void Reset() { atomic_write32(status_, 0); } |
| 59 |
|
|
void WaitFor(); |
| 60 |
|
|
|
| 61 |
|
|
private: |
| 62 |
|
45 |
void SetDone() { atomic_cas32(status_, 0, 1); } |
| 63 |
|
|
|
| 64 |
|
|
unsigned timeout_s_; |
| 65 |
|
|
atomic_int32 *status_; |
| 66 |
|
|
}; |
| 67 |
|
|
|
| 68 |
|
|
struct Command { |
| 69 |
|
162 |
virtual ~Command() { } |
| 70 |
|
|
}; |
| 71 |
|
|
struct QuitCommand : public Command { }; |
| 72 |
|
|
struct InvalInodesCommand : public Command { |
| 73 |
|
|
Handle *handle; |
| 74 |
|
|
}; |
| 75 |
|
|
struct InvalDentryCommand : public Command { |
| 76 |
|
|
uint64_t parent_ino; |
| 77 |
|
|
NameString name; |
| 78 |
|
|
}; |
| 79 |
|
|
|
| 80 |
|
|
FuseInvalidator(MountPoint *mountpoint, |
| 81 |
|
|
void **fuse_channel_or_session, |
| 82 |
|
|
bool fuse_notify_invalidation); |
| 83 |
|
|
~FuseInvalidator(); |
| 84 |
|
|
void Spawn(); |
| 85 |
|
|
void InvalidateInodes(Handle *handle); |
| 86 |
|
|
|
| 87 |
|
|
void InvalidateDentry(uint64_t parent_ino, const NameString &name); |
| 88 |
|
|
|
| 89 |
|
|
private: |
| 90 |
|
|
/** |
| 91 |
|
|
* CONSTRUCTOR ONLY FOR UNITTESTS - mountpoint will illegally be null |
| 92 |
|
|
* ( we do not want to construct a full mountpoint in the unittest ) |
| 93 |
|
|
*/ |
| 94 |
|
|
FuseInvalidator(glue::InodeTracker *inode_tracker, |
| 95 |
|
|
glue::DentryTracker *dentry_tracker, |
| 96 |
|
|
void **fuse_channel_or_session, |
| 97 |
|
|
bool fuse_notify_invalidation); |
| 98 |
|
|
/** |
| 99 |
|
|
* Add one second to the caller-provided timeout to be on the safe side. |
| 100 |
|
|
*/ |
| 101 |
|
|
static const unsigned kTimeoutSafetyMarginSec; // = 1; |
| 102 |
|
|
/** |
| 103 |
|
|
* If caches are drained out by timeout, set a polling interval. |
| 104 |
|
|
*/ |
| 105 |
|
|
static const unsigned kCheckTimeoutFreqMs; // = 100; |
| 106 |
|
|
/** |
| 107 |
|
|
* If caches are actively drained out, check every so many operations if the |
| 108 |
|
|
* caches are anyway drained out by timeout. |
| 109 |
|
|
*/ |
| 110 |
|
|
static const unsigned kCheckTimeoutFreqOps; // = 256 |
| 111 |
|
|
|
| 112 |
|
|
static void *MainInvalidator(void *data); |
| 113 |
|
|
|
| 114 |
|
|
MountPoint *mount_point_; |
| 115 |
|
|
|
| 116 |
|
|
glue::InodeTracker *inode_tracker_; |
| 117 |
|
|
glue::DentryTracker *dentry_tracker_; |
| 118 |
|
|
/** |
| 119 |
|
|
* libfuse2 uses struct fuse_chan, libfuse3 uses struct fuse_session |
| 120 |
|
|
*/ |
| 121 |
|
|
void **fuse_channel_or_session_; |
| 122 |
|
|
bool spawned_; |
| 123 |
|
|
Channel<Command> channel_; |
| 124 |
|
|
pthread_t thread_invalidator_; |
| 125 |
|
|
/** |
| 126 |
|
|
* An invalidation run can take some time. Allow for early cancellation if |
| 127 |
|
|
* thread should be shut down. |
| 128 |
|
|
*/ |
| 129 |
|
|
atomic_int32 terminated_; |
| 130 |
|
|
BigVector<uint64_t> evict_list_; |
| 131 |
|
|
|
| 132 |
|
|
static bool g_fuse_notify_invalidation_; |
| 133 |
|
|
}; // class FuseInvalidator |
| 134 |
|
|
|
| 135 |
|
|
#endif // CVMFS_FUSE_EVICT_H_ |
| 136 |
|
|
|