Skip to content

Commit 5a8e82d

Browse files
authored
Merge pull request opencurve#7 from cw123/fs_mds_metaserver_3
curvefs metaserver mds
2 parents de06a9f + 3549c23 commit 5a8e82d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5101
-15
lines changed

buildfs.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
3+
cpplint --recursive curvefs
4+
if [ $? -ne 0 ]
5+
then
6+
echo "cpplint failed"
7+
exit
8+
fi
9+
10+
if [ "$1" = "debug" ]
11+
then
12+
DEBUG_FLAG="--compilation_mode=dbg"
13+
fi
14+
15+
bazel build curvefs/src/metaserver:curvefs_metaserver --copt -DHAVE_ZLIB=1 ${DEBUG_FLAG} -s --define=with_glog=true --define=libunwind=true --copt -DGFLAGS_NS=google --copt -Wno-error=format-security --copt -DUSE_BTHREAD_MUTEX --copt -DCURVEVERSION=${curve_version} --linkopt -L/usr/local/lib
16+
if [ $? -ne 0 ]
17+
then
18+
echo "build metaserver failed"
19+
exit
20+
fi
21+
22+
bazel build curvefs/src/mds:curvefs_mds --copt -DHAVE_ZLIB=1 ${DEBUG_FLAG} -s --define=with_glog=true --define=libunwind=true --copt -DGFLAGS_NS=google --copt -Wno-error=format-security --copt -DUSE_BTHREAD_MUTEX --copt -DCURVEVERSION=${curve_version} --linkopt -L/usr/local/lib
23+
if [ $? -ne 0 ]
24+
then
25+
echo "build mds failed"
26+
exit
27+
fi
28+
29+
bazel build curvefs/test/metaserver:metaserver_test --copt -DHAVE_ZLIB=1 ${DEBUG_FLAG} -s --define=with_glog=true --define=libunwind=true --copt -DGFLAGS_NS=google --copt -Wno-error=format-security --copt -DUSE_BTHREAD_MUTEX --copt -DCURVEVERSION=${curve_version} --linkopt -L/usr/local/lib
30+
if [ $? -ne 0 ]
31+
then
32+
echo "build mds failed"
33+
exit
34+
fi
35+
36+
bazel build curvefs/test/mds:mds_test --copt -DHAVE_ZLIB=1 ${DEBUG_FLAG} -s --define=with_glog=true --define=libunwind=true --copt -DGFLAGS_NS=google --copt -Wno-error=format-security --copt -DUSE_BTHREAD_MUTEX --copt -DCURVEVERSION=${curve_version} --linkopt -L/usr/local/lib
37+
if [ $? -ne 0 ]
38+
then
39+
echo "build mds failed"
40+
exit
41+
fi
42+
43+
if [ "$1" = "test" ]
44+
then
45+
./bazel-bin/curvefs/test/metaserver/metaserver_test
46+
if [ $? -ne 0 ]
47+
then
48+
echo "metaserver_test failed"
49+
exit
50+
fi
51+
./bazel-bin/curvefs/test/mds/mds_test
52+
if [ $? -ne 0 ]
53+
then
54+
echo "mds_test failed"
55+
exit
56+
fi
57+
fi

curvefs/conf/mds.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# mds服务端口
3+
#
4+
mds.listen.addr=127.0.0.1:6700
5+
6+
#
7+
# space服务端口
8+
#
9+
space.addr=127.0.0.1:6702
10+
space.rpcTimeoutMs=500

curvefs/conf/metaserver.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# metaserver服务端口
3+
#
4+
metaserver.listen.addr=127.0.0.1:6701
5+
6+

curvefs/proto/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ cc_proto_library(
5757
proto_library(
5858
name = "space_proto",
5959
srcs = ["space.proto"],
60-
deps = [":curvefs_common_proto"],
60+
deps = [":curvefs_common_proto",":mds_proto"],
6161
)

curvefs/proto/mds.proto

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ option cc_generic_services = true;
2222
enum FSStatusCode {
2323
OK = 0;
2424
UNKNOWN_ERROR = 1;
25-
NOSPACE = 2;
26-
FS_NOT_FOUND = 3;
25+
FS_EXIST = 2;
26+
NOT_FOUND = 3;
2727
PARAM_ERROR = 4;
28+
MOUNT_POINT_EXIST = 5;
29+
RPC_ERROR = 6;
30+
INIT_SPACE_ERROR = 7;
31+
UNINIT_SPACE_ERROR = 8;
32+
FS_BUSY = 9;
2833
}
2934

3035
// fs interface
@@ -33,7 +38,7 @@ message GetFsInfoRequest {
3338
optional string fsName = 2; // Globally unique, no duplicates allowed
3439
}
3540

36-
message mountPoint {
41+
message MountPoint {
3742
required string host = 1;
3843
required string mountDir = 2; // use full path
3944
}
@@ -46,7 +51,7 @@ message FsInfo {
4651
required uint64 blockSize = 5;
4752
required common.Volume volume = 6;
4853
required uint32 mountNum = 7;
49-
repeated mountPoint mountpoints = 8;
54+
repeated MountPoint mountpoints = 8;
5055
}
5156

5257
message GetFsInfoResponse {
@@ -67,7 +72,7 @@ message CreateFsResponse {
6772

6873
message MountFsRequest {
6974
required string fsName = 1;
70-
required mountPoint mountpoint = 2;
75+
required MountPoint mountpoint = 2;
7176
}
7277

7378
message MountFsResponse {
@@ -77,7 +82,7 @@ message MountFsResponse {
7782

7883
message UmountFsRequest {
7984
required string fsName = 1;
80-
required mountPoint mountpoint = 2;
85+
required MountPoint mountpoint = 2;
8186
}
8287

8388
message UmountFsResponse {

curvefs/proto/metaserver.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ enum MetaStatusCode {
2222
OK = 0;
2323
UNKNOWN_ERROR = 1;
2424
PARAM_ERROR = 2;
25+
NOT_FOUND = 3;
26+
INODE_EXIST = 4;
27+
DENTRY_EXIST = 5;
28+
SYM_LINK_EMPTY = 6;
2529
}
2630

2731
// dentry interface
@@ -63,13 +67,15 @@ message CreateDentryResponse {
6367
required MetaStatusCode statusCode = 1;
6468
}
6569

70+
/*
6671
message UpdateDentryRequest {
6772
required Dentry dentry = 1;
6873
}
6974
7075
message UpdateDentryResponse {
7176
required MetaStatusCode statusCode = 1;
7277
}
78+
*/
7379

7480
message DeleteDentryRequest {
7581
required uint32 fsId = 1;
@@ -170,7 +176,7 @@ service MetaServerService {
170176
rpc GetDentry(GetDentryRequest) returns (GetDentryResponse);
171177
rpc ListDentry(ListDentryRequest) returns (ListDentryResponse);
172178
rpc CreateDentry(CreateDentryRequest) returns (CreateDentryResponse);
173-
rpc UpdateDentry(UpdateDentryRequest) returns (UpdateDentryResponse);
179+
// rpc UpdateDentry(UpdateDentryRequest) returns (UpdateDentryResponse);
174180
rpc DeleteDentry(DeleteDentryRequest) returns (DeleteDentryResponse);
175181

176182
// inode interface

curvefs/proto/space.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
syntax="proto2";
1818
import "curvefs/proto/common.proto";
19+
import "curvefs/proto/mds.proto";
1920
package curvefs.space;
2021
option cc_generic_services = true;
2122

@@ -44,8 +45,7 @@ message AllocateHint {
4445
}
4546

4647
message InitSpaceRequest {
47-
required uint32 fsId = 1;
48-
required common.Volume volumeInfo = 2;
48+
required mds.FsInfo fsInfo = 1;
4949
}
5050

5151
message InitSpaceResponse {

curvefs/src/client/main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ static const struct fuse_lowlevel_ops curve_ll_oper = {
4141
.setattr = curve_ll_setattr,
4242
};
4343

44-
int main(int argc, char *argv[])
45-
{
44+
int main(int argc, char *argv[]) {
4645
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
4746
struct fuse_session *se;
4847
struct fuse_cmdline_opts opts;
@@ -64,7 +63,7 @@ int main(int argc, char *argv[])
6463
goto err_out1;
6564
}
6665

67-
if(opts.mountpoint == NULL) {
66+
if (opts.mountpoint == NULL) {
6867
printf("usage: %s [options] <mountpoint>\n", argv[0]);
6968
printf(" %s --help\n", argv[0]);
7069
ret = 1;
@@ -91,9 +90,9 @@ int main(int argc, char *argv[])
9190
fuse_daemonize(opts.foreground);
9291

9392
/* Block until ctrl+c or fusermount -u */
94-
if (opts.singlethread)
93+
if (opts.singlethread) {
9594
ret = fuse_session_loop(se);
96-
else {
95+
} else {
9796
config.clone_fd = opts.clone_fd;
9897
config.max_idle_threads = opts.max_idle_threads;
9998
ret = fuse_session_loop_mt(se, &config);

curvefs/src/mds/BUILD

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Copyright (c) 2021 NetEase Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
COPTS = [
18+
"-DGFLAGS=gflags",
19+
"-DOS_LINUX",
20+
"-DSNAPPY",
21+
"-DHAVE_SSE42",
22+
"-DHAVE_ZLIB",
23+
"-DNDEBUG",
24+
"-fno-omit-frame-pointer",
25+
"-momit-leaf-frame-pointer",
26+
"-msse4.2",
27+
"-pthread",
28+
"-Wsign-compare",
29+
"-Wno-unused-parameter",
30+
"-Wno-unused-variable",
31+
"-Woverloaded-virtual",
32+
"-Wnon-virtual-dtor",
33+
"-Wno-missing-field-initializers",
34+
"-std=c++11",
35+
]
36+
37+
cc_library(
38+
name="mds",
39+
hdrs=glob(["*.h"]),
40+
srcs=glob(["*.cpp"],
41+
exclude = ["main.cpp"]
42+
),
43+
copts = COPTS,
44+
visibility = ["//visibility:public"],
45+
deps = [
46+
"//external:brpc",
47+
"//curvefs/proto:mds_cc_proto",
48+
"//curvefs/proto:space_cc_proto",
49+
"//src/common/concurrent:curve_concurrent",
50+
"//src/common:curve_common",
51+
],
52+
)
53+
54+
cc_binary(
55+
name = "curvefs_mds",
56+
srcs = glob([
57+
"main.cpp",
58+
]),
59+
copts = COPTS,
60+
visibility = ["//visibility:public"],
61+
deps = [
62+
"//curvefs/src/mds:mds",
63+
],
64+
)
65+

curvefs/src/mds/fs.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2021 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* @Project: curve
19+
* @Date: 2021-06-04 14:11:16
20+
* @Author: chenwei
21+
*/
22+
23+
#include "curvefs/src/mds/fs.h"
24+
namespace curvefs {
25+
namespace mds {
26+
MdsFsInfo::MdsFsInfo(uint32_t fsId, std::string fsName, uint64_t rootInodeId,
27+
uint64_t capacity, uint64_t blockSize, const common::Volume& volume) {
28+
fsId_ = fsId;
29+
fsName_ = fsName;
30+
rootInodeId_ = rootInodeId;
31+
capacity_ = capacity;
32+
blockSize_ = blockSize;
33+
volume_.CopyFrom(volume);
34+
mountNum_ = 0;
35+
}
36+
37+
void MdsFsInfo::ConvertToProto(FsInfo *file) {
38+
// ReadLockGuard readLockGuard(rwLock_);
39+
file->set_fsid(fsId_);
40+
file->set_fsname(fsName_);
41+
file->set_rootinodeid(rootInodeId_);
42+
file->set_capacity(capacity_);
43+
file->set_blocksize(blockSize_);
44+
file->set_mountnum(mountNum_);
45+
file->mutable_volume()->CopyFrom(volume_);
46+
*file->mutable_mountpoints() = {mountPointList_.begin(),
47+
mountPointList_.end()};
48+
return;
49+
}
50+
51+
std::list<MountPoint> MdsFsInfo::GetMountPointList() {
52+
return mountPointList_;
53+
}
54+
55+
bool MdsFsInfo::MountPointEmpty() {
56+
return mountNum_ == 0;
57+
}
58+
59+
bool MdsFsInfo::MountPointExist(const MountPoint& mountpoint) {
60+
// ReadLockGuard readLockGuard(rwLock_);
61+
for (auto it : mountPointList_) {
62+
if (it.host() == mountpoint.host()
63+
&& it.mountdir() == mountpoint.mountdir()) {
64+
return true;
65+
}
66+
}
67+
return false;
68+
}
69+
70+
void MdsFsInfo::AddMountPoint(const MountPoint& mountpoint) {
71+
// WriteLockGuard writeLockGuard(rwLock_);
72+
mountPointList_.push_back(mountpoint);
73+
mountNum_++;
74+
return;
75+
}
76+
77+
FSStatusCode MdsFsInfo::DeleteMountPoint(const MountPoint& mountpoint) {
78+
// WriteLockGuard writeLockGuard(rwLock_);
79+
for (auto it = mountPointList_.begin(); it != mountPointList_.end(); it++) {
80+
if (it->host() == mountpoint.host()
81+
&& it->mountdir() == mountpoint.mountdir()) {
82+
mountPointList_.erase(it);
83+
mountNum_--;
84+
return FSStatusCode::OK;
85+
}
86+
}
87+
return FSStatusCode::NOT_FOUND;
88+
}
89+
90+
uint32_t MdsFsInfo::GetFsId() const {
91+
return fsId_;
92+
}
93+
94+
std::string MdsFsInfo::GetFsName() const {
95+
return fsName_;
96+
}
97+
98+
Volume MdsFsInfo::GetVolumeInfo() {
99+
return volume_;
100+
}
101+
} // namespace mds
102+
} // namespace curvefs

0 commit comments

Comments
 (0)