-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathextent_server.cc
89 lines (66 loc) · 1.82 KB
/
extent_server.cc
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
// the extent server implementation
#include "extent_server.h"
#include <fcntl.h>
#include <sstream>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
extent_server::extent_server()
{
pthread_mutex_init(&m, NULL);
// FUSE assumes that the inum for the root directory is 1.
int r;
put(1, "", r);
}
int extent_server::put(extent_protocol::extentid_t id, std::string buf, int &)
{
printf("put request id=%lld, size=%ld\n", id, buf.size());
ScopedLock ml(&m);
extent_t ext;
unsigned int t = time_since_epoch();
ext.attr.size = buf.size();
ext.attr.atime = t;
ext.attr.mtime = t;
ext.attr.ctime = t;
ext.ext = std::move(buf);
exts[id] = std::move(ext);
return extent_protocol::OK;
}
int extent_server::get(extent_protocol::extentid_t id, std::string &buf)
{
printf("get request id=%lld\n", id);
ScopedLock ml(&m);
std::map<extent_protocol::extentid_t, extent_t>::iterator it;
it = exts.find(id);
if (it == exts.end()) {
return extent_protocol::IOERR;
}
it->second.attr.atime = time_since_epoch();
buf = it->second.ext;
return extent_protocol::OK;
}
int extent_server::getattr(extent_protocol::extentid_t id, extent_protocol::attr &a)
{
printf("getattr request id=%lld\n", id);
ScopedLock ml(&m);
std::map<extent_protocol::extentid_t, extent_t>::iterator it;
it = exts.find(id);
if (it == exts.end()) {
return extent_protocol::IOERR;
}
a = it->second.attr;
return extent_protocol::OK;
}
int extent_server::remove(extent_protocol::extentid_t id, int &)
{
printf("remove request id=%lld\n", id);
ScopedLock ml(&m);
std::map<extent_protocol::extentid_t, extent_t>::iterator it;
it = exts.find(id);
if (it == exts.end()) { // Silently OK if not found.
return extent_protocol::OK;
}
exts.erase(it);
return extent_protocol::OK;
}