Skip to content

Commit

Permalink
curvefs/tool: add create-fs
Browse files Browse the repository at this point in the history
1. curvefs_tool add create-fs command whitch send create-fs rpc to mds/topology
2. rename buildtopo directory
  • Loading branch information
Cyber-SiKu authored and wu-hanqing committed Dec 28, 2021
1 parent df55c9a commit 81ef9ff
Show file tree
Hide file tree
Showing 14 changed files with 409 additions and 32 deletions.
16 changes: 16 additions & 0 deletions curvefs/conf/tools.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,19 @@ topoFilePath=curvefs/test/tools/topo_example.json # __CURVEADM_TEMPLATE__ /usr/
metaserverAddr=127.0.0.1:6701 # __CURVEADM_TEMPLATE__ ${cluster_metaserver_addr} __CURVEADM_TEMPLATE__ __ANSIBLE_TEMPLATE__ {{ groups.metaserver | join_peer(hostvars, "metaserver_listen_port") }} __ANSIBLE_TEMPLATE__
# etcd
etcdAddr=127.0.0.1:12379 # __CURVEADM_TEMPLATE__ ${cluster_etcd_addr} __CURVEADM_TEMPLATE__ __ANSIBLE_TEMPLATE__ {{ groups.etcd | join_peer(hostvars, "etcd_listen_client_port") }} __ANSIBLE_TEMPLATE__
# fs
blockSize=1048576
fsType=s3
# volume
volumeSize=1048576
volumeBlockSize=4096
volumeName=volume
volumeUser=user
volumePassword=password
# s3
s3.ak=ak
s3.sk=sk
s3.endpoint=endpoint
s3.bucket_Name=bucket
s3.blocksize=1048576
s3.chunksize=4194304
2 changes: 1 addition & 1 deletion curvefs/devops/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
- name: create topology
shell: >
{{ project_root_dest }}/sbin/curvefs_tool
build-topology
create-topology
-confPath={{ project_root_dest }}/conf/tools.conf
tags: [topo]
4 changes: 2 additions & 2 deletions curvefs/src/tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cc_library(
name = "curvefs_tools_lib",
srcs = glob([
"*.cpp",
"buildtopo/*.cpp",
"create/*.cpp",
"version/*.cpp",
"usage/*.cpp",
"status/*.cpp",
Expand All @@ -45,7 +45,7 @@ cc_library(
]),
hdrs = glob([
"*.h",
"buildtopo/*.h",
"create/*.h",
"version/*.h",
"usage/*.h",
"status/*.h",
Expand Down
32 changes: 27 additions & 5 deletions curvefs/src/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ and can be specified by "-confPath=".
* [version](#version)
* [status](#status)
* [list](#list)
* [build](#build)
* [create](#create)
* [umount](#umount)
* [usage](#usage)
* [delete](#delete)
Expand Down Expand Up @@ -298,26 +298,48 @@ metaserverId:3, hostname:pubbeta2-curve20.dg.163.org, hostIp:192.168.1.1, port:2
---
## build
## create
### **build-topology**
### **create-topology**
build cluster topology
Usage:
```shell
curvefs_tool build-topology
curvefs_tool create-topology
```
Output:
**if success, there is no output.**
```shell
```
***if success, there is no output.**
### **create-fs**
Usage:
```shell
curvefs_tool create-fs
```
Output:
```shell
create fs success.
the create fs info is:
fsId: 3 fsName: "/test" status: INITED rootInodeId: 1 capacity: 18446744073709551615 blockSize: 1048576 mountNum: 0 fsType: TYPE_S3 detail { s3Info { ak: "ak" sk: "sk" endpoint: "endpoint" bucketname: "bucket" blockSize: 1048576 chunkSize: 4194304 } }
```
***If all the parameters of fs are the same as the existing ones, success will still be returned.**
***Some parameters of create-fs such as s3_sk, s3_ak are named s3.sk, sk.ak in the configuration file (tool.conf).**
***Please pay attention.**
[TOC](#table-of-contents)
---
Expand Down
160 changes: 160 additions & 0 deletions curvefs/src/tools/create/curvefs_create_fs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* 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
* Created Date: 2021-12-23
* Author: chengyi01
*/

#include "curvefs/src/tools/create/curvefs_create_fs.h"

#include "curvefs/proto/common.pb.h"
#include "curvefs/src/tools/curvefs_tool_define.h"
#include "src/common/string_util.h"

DECLARE_string(fsName);
DECLARE_string(confPath);
DECLARE_string(mdsAddr);
DECLARE_uint64(blockSize);
DECLARE_string(fsType);
DECLARE_uint64(volumeSize);
DECLARE_uint64(volumeBlockSize);
DECLARE_string(volumeName);
DECLARE_string(volumeUser);
DECLARE_string(volumePassword);
DECLARE_string(s3_ak);
DECLARE_string(s3_sk);
DECLARE_string(s3_endpoint);
DECLARE_string(s3_bucket_name);
DECLARE_uint64(s3_blocksize);
DECLARE_uint64(s3_chunksize);

namespace curvefs {
namespace tools {
namespace create {

void CreateFsTool::PrintHelp() {
CurvefsToolRpc::PrintHelp();
std::cout << " -fsName=" << FLAGS_fsName
<< "[-blockSize=" << FLAGS_blockSize
<< "] [-fsType=volume -volumeSize=" << FLAGS_volumeSize
<< " -volumeBlockSize=" << FLAGS_volumeBlockSize
<< " -volumeName=" << FLAGS_volumeName
<< " -volumeUser=" << FLAGS_volumeUser
<< " -volumePassword=" << FLAGS_volumePassword
<< "]|[-fsType=s3 -s3_ak=" << FLAGS_s3_ak
<< " -s3_sk=" << FLAGS_s3_sk
<< " -s3_endpoint=" << FLAGS_s3_endpoint
<< " -s3_bucket_name=" << FLAGS_s3_bucket_name
<< " -s3_blocksize=" << FLAGS_s3_blocksize
<< " -s3_chunkSize=" << FLAGS_s3_chunksize
<< "] [-mdsAddr=" << FLAGS_mdsAddr << "]" << std::endl;
}

void CreateFsTool::AddUpdateFlags() {
AddUpdateFlagsFunc(curvefs::tools::SetMdsAddr);
AddUpdateFlagsFunc(curvefs::tools::SetBlockSize);
AddUpdateFlagsFunc(curvefs::tools::SetFsType);
AddUpdateFlagsFunc(curvefs::tools::SetVolumeSize);
AddUpdateFlagsFunc(curvefs::tools::SetVolumeBlockSize);
AddUpdateFlagsFunc(curvefs::tools::SetVolumeName);
AddUpdateFlagsFunc(curvefs::tools::SetVolumeUser);
AddUpdateFlagsFunc(curvefs::tools::SetVolumePassword);
AddUpdateFlagsFunc(curvefs::tools::SetS3_sk);
AddUpdateFlagsFunc(curvefs::tools::SetS3_sk);
AddUpdateFlagsFunc(curvefs::tools::SetS3_endpoint);
AddUpdateFlagsFunc(curvefs::tools::SetS3_bucket_name);
AddUpdateFlagsFunc(curvefs::tools::SetS3_blocksize);
AddUpdateFlagsFunc(curvefs::tools::SetS3_chunksize);
}

int CreateFsTool::Init() {
google::CommandLineFlagInfo info;
if (CheckFsNameDefault(&info)) {
std::cerr << "no -fsName=***, please check it!" << std::endl;
return -1;
}
int ret = CurvefsToolRpc::Init();

curve::common::SplitString(FLAGS_mdsAddr, ",", &hostsAddr_);
service_stub_func_ =
std::bind(&mds::MdsService_Stub::CreateFs, service_stub_.get(),
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, nullptr);

mds::CreateFsRequest request;
request.set_fsname(FLAGS_fsName);
request.set_blocksize(FLAGS_blockSize);
if (FLAGS_fsType == "s3") {
// s3
request.set_fstype(common::FSType::TYPE_S3);
auto s3 = new common::S3Info();
s3->set_ak(FLAGS_s3_ak);
s3->set_sk(FLAGS_s3_sk);
s3->set_endpoint(FLAGS_s3_endpoint);
s3->set_bucketname(FLAGS_s3_bucket_name);
s3->set_blocksize(FLAGS_s3_blocksize);
s3->set_chunksize(FLAGS_s3_chunksize);
request.mutable_fsdetail()->set_allocated_s3info(s3);
} else if (FLAGS_fsType == "volume") {
// volume
request.set_fstype(common::FSType::TYPE_S3);
auto volume = new common::Volume();
volume->set_volumesize(FLAGS_volumeSize);
volume->set_blocksize(FLAGS_volumeBlockSize);
volume->set_volumename(FLAGS_volumeName);
volume->set_user(FLAGS_volumeUser);
volume->set_password(FLAGS_volumePassword);
request.mutable_fsdetail()->set_allocated_volume(volume);
} else {
std::cerr << "-fsType should be s3 or volume." << std::endl;
ret = -1;
}

AddRequest(request);
return ret;
}

bool CreateFsTool::AfterSendRequestToHost(const std::string& host) {
bool ret = true;
if (controller_->Failed()) {
errorOutput_ << "send create fs request to mds: " << host
<< " failed, errorcode= " << controller_->ErrorCode()
<< ", error text: " << controller_->ErrorText()
<< std::endl;
ret = false;
} else if (response_->statuscode() == mds::FSStatusCode::OK) {
// create success
std::cout << "create fs success." << std::endl;
if (response_->has_fsinfo()) {
auto const& fsInfo = response_->fsinfo();
std::cout << "the create fs info is:\n"
<< fsInfo.ShortDebugString() << std::endl;
}
} else {
// create fail
std::cerr << "create fs failed, errorcode= " << response_->statuscode()
<< ", error name: "
<< mds::FSStatusCode_Name(response_->statuscode())
<< std::endl;
ret = false;
}
return ret;
}

} // namespace create
} // namespace tools
} // namespace curvefs
57 changes: 57 additions & 0 deletions curvefs/src/tools/create/curvefs_create_fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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
* Created Date: 2021-12-23
* Author: chengyi01
*/

#ifndef CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_FS_H_
#define CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_FS_H_

#include <string>

#include "curvefs/proto/mds.pb.h"
#include "curvefs/src/tools/curvefs_tool.h"
#include "curvefs/src/tools/curvefs_tool_define.h"

namespace curvefs {
namespace tools {
namespace create {

class CreateFsTool : public CurvefsToolRpc<curvefs::mds::CreateFsRequest,
curvefs::mds::CreateFsResponse,
curvefs::mds::MdsService_Stub> {
public:
explicit CreateFsTool(const std::string& cmd = kCreateFsCmd,
bool show = true)
: CurvefsToolRpc(cmd) {
show_ = show;
}
void PrintHelp() override;

int Init() override;

protected:
void AddUpdateFlags() override;
bool AfterSendRequestToHost(const std::string& host) override;
};

} // namespace create
} // namespace tools
} // namespace curvefs

#endif // CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_FS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// TODO(chengyi): add out put when build sucess

#include "curvefs/src/tools/buildtopo/curvefs_build_topology_tool.h"
#include "curvefs/src/tools/create/curvefs_create_topology_tool.h"

DECLARE_string(mds_addr);
DECLARE_string(cluster_map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* Author: chengyi01
*/

#ifndef CURVEFS_SRC_TOOLS_BUILDTOPO_CURVEFS_BUILD_TOPOLOGY_TOOL_H_
#define CURVEFS_SRC_TOOLS_BUILDTOPO_CURVEFS_BUILD_TOPOLOGY_TOOL_H_
#ifndef CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_TOPOLOGY_TOOL_H_
#define CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_TOPOLOGY_TOOL_H_

#include <brpc/channel.h>
#include <brpc/server.h>
Expand Down Expand Up @@ -75,7 +75,7 @@ class CurvefsBuildTopologyTool : public curvefs::tools::CurvefsTool {
public:
CurvefsBuildTopologyTool()
: curvefs::tools::CurvefsTool(
std::string(curvefs::tools::kBuildTopologyCmd),
std::string(curvefs::tools::kCreateTopologyCmd),
std::string(curvefs::tools::kProgrameName)) {}
~CurvefsBuildTopologyTool() {}

Expand Down Expand Up @@ -160,4 +160,4 @@ class CurvefsBuildTopologyTool : public curvefs::tools::CurvefsTool {
} // namespace mds
} // namespace curvefs

#endif // CURVEFS_SRC_TOOLS_BUILDTOPO_CURVEFS_BUILD_TOPOLOGY_TOOL_H_
#endif // CURVEFS_SRC_TOOLS_CREATE_CURVEFS_CREATE_TOPOLOGY_TOOL_H_
Loading

0 comments on commit 81ef9ff

Please sign in to comment.