Skip to content

Commit

Permalink
Merge pull request opencurve#7 from cw123/fs_mds_metaserver_3
Browse files Browse the repository at this point in the history
curvefs metaserver mds
  • Loading branch information
cw123 authored Jun 17, 2021
2 parents de06a9f + 3549c23 commit 5a8e82d
Show file tree
Hide file tree
Showing 53 changed files with 5,101 additions and 15 deletions.
57 changes: 57 additions & 0 deletions buildfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

cpplint --recursive curvefs
if [ $? -ne 0 ]
then
echo "cpplint failed"
exit
fi

if [ "$1" = "debug" ]
then
DEBUG_FLAG="--compilation_mode=dbg"
fi

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
if [ $? -ne 0 ]
then
echo "build metaserver failed"
exit
fi

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
if [ $? -ne 0 ]
then
echo "build mds failed"
exit
fi

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
if [ $? -ne 0 ]
then
echo "build mds failed"
exit
fi

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
if [ $? -ne 0 ]
then
echo "build mds failed"
exit
fi

if [ "$1" = "test" ]
then
./bazel-bin/curvefs/test/metaserver/metaserver_test
if [ $? -ne 0 ]
then
echo "metaserver_test failed"
exit
fi
./bazel-bin/curvefs/test/mds/mds_test
if [ $? -ne 0 ]
then
echo "mds_test failed"
exit
fi
fi
10 changes: 10 additions & 0 deletions curvefs/conf/mds.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# mds服务端口
#
mds.listen.addr=127.0.0.1:6700

#
# space服务端口
#
space.addr=127.0.0.1:6702
space.rpcTimeoutMs=500
6 changes: 6 additions & 0 deletions curvefs/conf/metaserver.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# metaserver服务端口
#
metaserver.listen.addr=127.0.0.1:6701


2 changes: 1 addition & 1 deletion curvefs/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ cc_proto_library(
proto_library(
name = "space_proto",
srcs = ["space.proto"],
deps = [":curvefs_common_proto"],
deps = [":curvefs_common_proto",":mds_proto"],
)
17 changes: 11 additions & 6 deletions curvefs/proto/mds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ option cc_generic_services = true;
enum FSStatusCode {
OK = 0;
UNKNOWN_ERROR = 1;
NOSPACE = 2;
FS_NOT_FOUND = 3;
FS_EXIST = 2;
NOT_FOUND = 3;
PARAM_ERROR = 4;
MOUNT_POINT_EXIST = 5;
RPC_ERROR = 6;
INIT_SPACE_ERROR = 7;
UNINIT_SPACE_ERROR = 8;
FS_BUSY = 9;
}

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

message mountPoint {
message MountPoint {
required string host = 1;
required string mountDir = 2; // use full path
}
Expand All @@ -46,7 +51,7 @@ message FsInfo {
required uint64 blockSize = 5;
required common.Volume volume = 6;
required uint32 mountNum = 7;
repeated mountPoint mountpoints = 8;
repeated MountPoint mountpoints = 8;
}

message GetFsInfoResponse {
Expand All @@ -67,7 +72,7 @@ message CreateFsResponse {

message MountFsRequest {
required string fsName = 1;
required mountPoint mountpoint = 2;
required MountPoint mountpoint = 2;
}

message MountFsResponse {
Expand All @@ -77,7 +82,7 @@ message MountFsResponse {

message UmountFsRequest {
required string fsName = 1;
required mountPoint mountpoint = 2;
required MountPoint mountpoint = 2;
}

message UmountFsResponse {
Expand Down
8 changes: 7 additions & 1 deletion curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ enum MetaStatusCode {
OK = 0;
UNKNOWN_ERROR = 1;
PARAM_ERROR = 2;
NOT_FOUND = 3;
INODE_EXIST = 4;
DENTRY_EXIST = 5;
SYM_LINK_EMPTY = 6;
}

// dentry interface
Expand Down Expand Up @@ -63,13 +67,15 @@ message CreateDentryResponse {
required MetaStatusCode statusCode = 1;
}

/*
message UpdateDentryRequest {
required Dentry dentry = 1;
}
message UpdateDentryResponse {
required MetaStatusCode statusCode = 1;
}
*/

message DeleteDentryRequest {
required uint32 fsId = 1;
Expand Down Expand Up @@ -170,7 +176,7 @@ service MetaServerService {
rpc GetDentry(GetDentryRequest) returns (GetDentryResponse);
rpc ListDentry(ListDentryRequest) returns (ListDentryResponse);
rpc CreateDentry(CreateDentryRequest) returns (CreateDentryResponse);
rpc UpdateDentry(UpdateDentryRequest) returns (UpdateDentryResponse);
// rpc UpdateDentry(UpdateDentryRequest) returns (UpdateDentryResponse);
rpc DeleteDentry(DeleteDentryRequest) returns (DeleteDentryResponse);

// inode interface
Expand Down
4 changes: 2 additions & 2 deletions curvefs/proto/space.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

syntax="proto2";
import "curvefs/proto/common.proto";
import "curvefs/proto/mds.proto";
package curvefs.space;
option cc_generic_services = true;

Expand Down Expand Up @@ -44,8 +45,7 @@ message AllocateHint {
}

message InitSpaceRequest {
required uint32 fsId = 1;
required common.Volume volumeInfo = 2;
required mds.FsInfo fsInfo = 1;
}

message InitSpaceResponse {
Expand Down
9 changes: 4 additions & 5 deletions curvefs/src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ static const struct fuse_lowlevel_ops curve_ll_oper = {
.setattr = curve_ll_setattr,
};

int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct fuse_session *se;
struct fuse_cmdline_opts opts;
Expand All @@ -64,7 +63,7 @@ int main(int argc, char *argv[])
goto err_out1;
}

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

/* Block until ctrl+c or fusermount -u */
if (opts.singlethread)
if (opts.singlethread) {
ret = fuse_session_loop(se);
else {
} else {
config.clone_fd = opts.clone_fd;
config.max_idle_threads = opts.max_idle_threads;
ret = fuse_session_loop_mt(se, &config);
Expand Down
65 changes: 65 additions & 0 deletions curvefs/src/mds/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Copyright (c) 2021 NetEase Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

COPTS = [
"-DGFLAGS=gflags",
"-DOS_LINUX",
"-DSNAPPY",
"-DHAVE_SSE42",
"-DHAVE_ZLIB",
"-DNDEBUG",
"-fno-omit-frame-pointer",
"-momit-leaf-frame-pointer",
"-msse4.2",
"-pthread",
"-Wsign-compare",
"-Wno-unused-parameter",
"-Wno-unused-variable",
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++11",
]

cc_library(
name="mds",
hdrs=glob(["*.h"]),
srcs=glob(["*.cpp"],
exclude = ["main.cpp"]
),
copts = COPTS,
visibility = ["//visibility:public"],
deps = [
"//external:brpc",
"//curvefs/proto:mds_cc_proto",
"//curvefs/proto:space_cc_proto",
"//src/common/concurrent:curve_concurrent",
"//src/common:curve_common",
],
)

cc_binary(
name = "curvefs_mds",
srcs = glob([
"main.cpp",
]),
copts = COPTS,
visibility = ["//visibility:public"],
deps = [
"//curvefs/src/mds:mds",
],
)

102 changes: 102 additions & 0 deletions curvefs/src/mds/fs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2021 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* @Project: curve
* @Date: 2021-06-04 14:11:16
* @Author: chenwei
*/

#include "curvefs/src/mds/fs.h"
namespace curvefs {
namespace mds {
MdsFsInfo::MdsFsInfo(uint32_t fsId, std::string fsName, uint64_t rootInodeId,
uint64_t capacity, uint64_t blockSize, const common::Volume& volume) {
fsId_ = fsId;
fsName_ = fsName;
rootInodeId_ = rootInodeId;
capacity_ = capacity;
blockSize_ = blockSize;
volume_.CopyFrom(volume);
mountNum_ = 0;
}

void MdsFsInfo::ConvertToProto(FsInfo *file) {
// ReadLockGuard readLockGuard(rwLock_);
file->set_fsid(fsId_);
file->set_fsname(fsName_);
file->set_rootinodeid(rootInodeId_);
file->set_capacity(capacity_);
file->set_blocksize(blockSize_);
file->set_mountnum(mountNum_);
file->mutable_volume()->CopyFrom(volume_);
*file->mutable_mountpoints() = {mountPointList_.begin(),
mountPointList_.end()};
return;
}

std::list<MountPoint> MdsFsInfo::GetMountPointList() {
return mountPointList_;
}

bool MdsFsInfo::MountPointEmpty() {
return mountNum_ == 0;
}

bool MdsFsInfo::MountPointExist(const MountPoint& mountpoint) {
// ReadLockGuard readLockGuard(rwLock_);
for (auto it : mountPointList_) {
if (it.host() == mountpoint.host()
&& it.mountdir() == mountpoint.mountdir()) {
return true;
}
}
return false;
}

void MdsFsInfo::AddMountPoint(const MountPoint& mountpoint) {
// WriteLockGuard writeLockGuard(rwLock_);
mountPointList_.push_back(mountpoint);
mountNum_++;
return;
}

FSStatusCode MdsFsInfo::DeleteMountPoint(const MountPoint& mountpoint) {
// WriteLockGuard writeLockGuard(rwLock_);
for (auto it = mountPointList_.begin(); it != mountPointList_.end(); it++) {
if (it->host() == mountpoint.host()
&& it->mountdir() == mountpoint.mountdir()) {
mountPointList_.erase(it);
mountNum_--;
return FSStatusCode::OK;
}
}
return FSStatusCode::NOT_FOUND;
}

uint32_t MdsFsInfo::GetFsId() const {
return fsId_;
}

std::string MdsFsInfo::GetFsName() const {
return fsName_;
}

Volume MdsFsInfo::GetVolumeInfo() {
return volume_;
}
} // namespace mds
} // namespace curvefs
Loading

0 comments on commit 5a8e82d

Please sign in to comment.