-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathfs_impl.h
More file actions
591 lines (523 loc) · 16.6 KB
/
Copy pathfs_impl.h
File metadata and controls
591 lines (523 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
#pragma once
#include "public.h"
#include "config.h"
#include "directory_entry_version_cache.h"
#include "directory_handle_cache.h"
#include "fs.h"
#include "handle_ops_queue.h"
#include "node_cache.h"
#include <cloud/filestore/libs/diagnostics/request_stats.h>
#include <cloud/filestore/libs/service/context.h>
#include <cloud/filestore/libs/service/filestore.h>
#include <cloud/filestore/libs/service/request.h>
#include <cloud/filestore/libs/vfs/config.h>
#include <cloud/filestore/libs/vfs/convert.h>
#include <cloud/filestore/libs/vfs/fsync_queue.h>
#include <cloud/filestore/libs/vfs_fuse/write_back_cache/write_back_cache.h>
#include <cloud/storage/core/libs/common/error.h>
#include <cloud/storage/core/libs/common/scheduler.h>
#include <cloud/storage/core/libs/common/timer.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <util/datetime/base.h>
#include <util/generic/hash.h>
#include <util/generic/queue.h>
#include <util/generic/string.h>
#include <util/system/align.h>
#include <util/system/mutex.h>
namespace NCloud::NFileStore::NFuse {
struct TRangeLock
{
ui64 Handle = -1;
ui64 Owner = -1;
i32 Pid = -1;
off_t Offset = 0;
off_t Length = 0;
NProto::ELockType LockType;
};
////////////////////////////////////////////////////////////////////////////////
struct TReleaseRequest
{
TCallContextPtr CallContext;
fuse_req_t Req;
fuse_ino_t Ino;
ui64 Fh;
NCloud::NProto::TError WriteBackCacheError;
};
////////////////////////////////////////////////////////////////////////////////
enum class EWriteBackCacheRequestStrategy
{
// WriteBackCache should not be used, the requests should go directly to the
// session
DoNotUse,
// WriteBackCache should be used, with ReadData/WriteData
UseNonDirect,
// WriteBackCache should be used, with ReadDataDirect/WriteDataDirect only
UseDirect
};
////////////////////////////////////////////////////////////////////////////////
class TFileSystem final
: public IFileSystem
, public std::enable_shared_from_this<TFileSystem>
{
private:
const ILoggingServicePtr Logging;
const IProfileLogPtr ProfileLog;
const ITimerPtr Timer;
const ISchedulerPtr Scheduler;
const IFileStorePtr Session;
const TFileSystemConfigPtr Config;
TLog Log;
IRequestStatsPtr RequestStats;
ICompletionQueuePtr CompletionQueue;
std::unique_ptr<NVFS::IFSyncQueue> FSyncQueue;
TNodeCache NodeCache;
TDirectoryEntryVersionCachePtr DirectoryEntryVersionCache;
std::unique_ptr<TDirectoryHandleCache> DirectoryHandleCache;
TXAttrCache XAttrCache;
TMutex XAttrCacheLock;
THandleOpsQueuePtr HandleOpsQueue;
TMutex HandleOpsQueueLock;
TQueue<TReleaseRequest> DelayedReleaseQueue;
TMutex DelayedReleaseQueueLock;
TWriteBackCache WriteBackCache;
std::atomic<ui64> GlobalCacheVersion = 1;
TProtoMessagePrinter ProtoMessagePrinter;
public:
TFileSystem(
ILoggingServicePtr logging,
IProfileLogPtr profileLog,
ISchedulerPtr scheduler,
ITimerPtr timer,
TFileSystemConfigPtr config,
IFileStorePtr session,
IRequestStatsPtr stats,
TDirectoryHandleModuleStatsPtr directoryHandleStats,
ICompletionQueuePtr queue,
THandleOpsQueuePtr handleOpsQueue,
TDirectoryHandleStoragePtr directoryHandleStorage,
TWriteBackCache writeBackCache);
~TFileSystem();
void Init() override;
void Reset() override;
// filesystem information
void StatFs(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino) override;
// nodes
void Lookup(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name) override;
void Forget(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
unsigned long nlookup) override;
void ForgetMulti(
TCallContextPtr callContext,
fuse_req_t req,
size_t count,
fuse_forget_data* forgets) override;
void MkDir(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name,
mode_t mode) override;
void RmDir(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name) override;
void MkNode(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name,
mode_t mode,
dev_t rdev) override;
void Unlink(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name) override;
void Rename(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name,
fuse_ino_t newparent,
TString newname,
int flags) override;
void SymLink(
TCallContextPtr callContext,
fuse_req_t req,
TString link,
fuse_ino_t parent,
TString name) override;
void Link(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_ino_t newparent,
TString newname) override;
void ReadLink(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino) override;
void Access(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
int mask) override;
// node attributes
void SetAttr(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
struct stat* attr,
int to_set,
fuse_file_info* fi) override;
void GetAttr(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi) override;
// extended node attributes
void SetXAttr(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
TString name,
TString value,
int flags) override;
void GetXAttr(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
TString name,
size_t size) override;
void ListXAttr(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
size_t size) override;
void RemoveXAttr(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
TString name) override;
// directory listing
void OpenDir(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi) override;
void ReadDir(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
size_t size,
off_t offset,
fuse_file_info* fi) override;
void ReleaseDir(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi) override;
// read & write files
void Create(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t parent,
TString name,
mode_t mode,
fuse_file_info* fi) override;
void Open(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi) override;
void Read(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
size_t size,
off_t offset,
fuse_file_info* fi) override;
void Write(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
TStringBuf buffer,
off_t offset,
fuse_file_info* fi) override;
void WriteBuf(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_bufvec* bufv,
off_t offset,
fuse_file_info* fi) override;
void FAllocate(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
int mode,
off_t offset,
off_t length,
fuse_file_info* fi) override;
void Flush(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi) override;
void FSync(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
int datasync,
fuse_file_info* fi) override;
void FSyncDir(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
int datasync,
fuse_file_info* fi) override;
void Release(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi) override;
// locking
void GetLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi,
struct flock* lock) override;
void SetLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi,
struct flock* lock,
bool sleep) override;
void FLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
fuse_file_info* fi,
int op) override;
private:
template <typename T>
static std::shared_ptr<T> StartRequest()
{
return std::make_shared<T>();
}
template <typename T>
static std::shared_ptr<T> StartRequest(ui64 node)
{
auto request = StartRequest<T>();
request->SetNodeId(node);
return request;
}
static std::shared_ptr<NProto::TConfirmCreateHandleRequest>
CreateConfirmCreateHandleRequest(
const NProto::TCreateHandleRequest& createRequest,
ui64 nodeId,
ui64 handle,
ui64 originalRequestId);
void ConfirmCreateHandleAndReplyOpen(
TCallContextPtr callContext,
fuse_req_t req,
const NProto::TCreateHandleRequest& createRequest,
ui64 nodeId,
ui64 handle,
fuse_file_info fi);
void CleanupFailedCreateHandle(
TCallContextPtr callContext,
fuse_req_t req,
ui64 nodeId,
ui64 handle,
NProto::TError confirmError);
template <typename T>
void SetUserNGroup(T& request, const fuse_ctx* ctx)
{
request.SetUid(ctx->uid);
request.SetGid(ctx->gid);
request.SetUmask(ctx->umask);
}
template<typename T>
static bool CheckResponse(
std::shared_ptr<TFileSystem> self,
TCallContext& callContext,
fuse_req_t req,
const T& response
) {
return self && self->CheckResponse(callContext, req, response);
}
template <typename T>
bool CheckResponse(
TCallContext& callContext,
fuse_req_t req,
const T& response)
{
return CheckError(callContext, req, response.GetError());
}
bool CheckError(
TCallContext& callContext,
fuse_req_t req,
const NProto::TError& error);
bool ValidateNodeId(
TCallContext& callContext,
fuse_req_t req,
fuse_ino_t ino);
bool ValidateDirectoryHandle(
TCallContext& callContext,
fuse_req_t req,
fuse_ino_t ino,
uint64_t fh);
EWriteBackCacheRequestStrategy GetWriteBackCacheRequestStrategy(
const fuse_file_info* fi) const;
TDuration GetEntryCacheTimeout(const NProto::TNodeAttr& attrs) const;
void AdjustNodeSize(NProto::TNodeAttr& attrs);
bool UpdateNodeAttrsInCache(
const NProto::TNodeAttr& attrs,
fuse_entry_param& entry,
ui64 version);
void InvalidateNodeInCache(ui64 nodeId);
void InvalidateDirectoryEntryInCache(
fuse_ino_t parent,
const TString& name);
void InvalidateXAttrCache(ui64 ino);
void UpdateXAttrCache(
ui64 ino,
const TString& name,
const TString& value,
ui64 version,
const NProto::TError& error);
void ReplyCreateWithCache(
TCallContext& callContext,
const NCloud::NProto::TError& error,
fuse_req_t req,
ui64 handle,
const NProto::TNodeAttr& attrs,
ui64 version,
bool newNodeCreated);
void ReplyEntryWithCache(
TCallContext& callContext,
const NCloud::NProto::TError& error,
fuse_req_t req,
const NProto::TNodeAttr& attrs,
ui64 version,
bool newNodeCreated);
void ReplyXAttrInt(
TCallContext& callContext,
const NCloud::NProto::TError& error,
fuse_req_t req,
const TString& value,
size_t size);
void ReplyAttrWithCache(
TCallContext& callContext,
const NCloud::NProto::TError& error,
fuse_req_t req,
const NProto::TNodeAttr& attrs,
ui64 version);
void ProcessAsyncCreateHandleResponse(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
const NProto::TCreateHandleRequest& originalRequest,
const NProto::TCreateHandleResponse& asyncResponse);
bool ProcessAsyncRelease(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
ui64 handle,
const NCloud::NProto::TError& writeBackCacheError);
void ReleaseImpl(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
ui64 handle,
bool asyncDestroyHandleEnabled,
const NCloud::NProto::TError& writeBackCacheError);
void CompleteAsyncDestroyHandle(
TCallContext& callContext,
const NProto::TDestroyHandleResponse& response);
void CompleteAsyncCreateHandle(
TCallContext& callContext,
const NProto::TConfirmCreateHandleResponse& response);
void CompleteHandleOpsQueueEntry();
void ProcessDelayedRelease();
void ClearDirectoryCache();
void ScheduleProcessHandleOpsQueue(TDuration delay);
void ProcessHandleOpsQueue();
void DoWrite(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
std::shared_ptr<NProto::TWriteDataRequest> request,
ui64 size,
fuse_file_info* fi);
#define FILESYSTEM_REPLY_IMPL(name, ...) \
template<typename... TArgs> \
int Reply##name( \
TCallContext& callContext, \
const NCloud::NProto::TError& error, \
fuse_req_t req, \
TArgs&&... args) \
{ \
Y_ABORT_UNLESS(RequestStats); \
Y_ABORT_UNLESS(CompletionQueue); \
return CompletionQueue->Complete(req, [&] (fuse_req_t r) { \
return NFuse::Reply##name( \
Log, \
*RequestStats, \
callContext, \
error, \
r, \
std::forward<TArgs>(args)...); \
}); \
} \
FILESYSTEM_REPLY_METHOD(FILESYSTEM_REPLY_IMPL)
#undef FILESYSTEM_REPLY_IMPL
void CancelRequest(TCallContextPtr callContext, fuse_req_t req);
void HandleLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
const TRangeLock& range,
NProto::ELockOrigin origin,
bool sleep);
void AcquireLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
const TRangeLock& range,
bool sleep,
NProto::ELockOrigin origin);
void ScheduleAcquireLock(
TCallContextPtr callContext,
const NCloud::NProto::TError& error,
fuse_req_t req,
fuse_ino_t ino,
const TRangeLock& range,
bool sleep,
NProto::ELockOrigin origin);
void ReleaseLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
const TRangeLock& range,
NProto::ELockOrigin origin);
void TestLock(
TCallContextPtr callContext,
fuse_req_t req,
fuse_ino_t ino,
const TRangeLock& range);
};
} // namespace NCloud::NFileStore::NFuse