Skip to content

Commit

Permalink
curvefs client : implement symlink, readlink, link, unlink, rmdir, tr…
Browse files Browse the repository at this point in the history
…uncate
  • Loading branch information
xu-chaojie authored and ilixiaocui committed Sep 13, 2021
1 parent 158552d commit 9fd79ee
Show file tree
Hide file tree
Showing 47 changed files with 1,221 additions and 2,833 deletions.
1 change: 1 addition & 0 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ message UpdateInodeRequest {
optional uint32 mode = 12;
optional VolumeExtentList volumeExtentList = 13; // TYPE_FILE only
optional S3ChunkInfoList s3ChunkInfoList = 14; // TYPE_S3 only
optional uint32 nlink = 15;
}

message UpdateInodeResponse {
Expand Down
2 changes: 2 additions & 0 deletions curvefs/src/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cc_binary(
"//src/common:curve_common",
"//src/client:curve_client",
"//src/common:curve_s3_adapter",
"//curvefs/src/client/rpcclient:rpcclient",
],
linkopts = ["-lfuse3",
"-lpthread",
Expand Down Expand Up @@ -70,6 +71,7 @@ cc_library(
"//src/common:curve_common",
"//src/client:curve_client",
"//src/common:curve_s3_adapter",
"//curvefs/src/client/rpcclient:rpcclient",
],
linkopts = ["-lfuse3",
"-lpthread",
Expand Down
228 changes: 0 additions & 228 deletions curvefs/src/client/base_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,234 +24,6 @@
namespace curvefs {
namespace client {

using curvefs::metaserver::VolumeExtentList;

void MetaServerBaseClient::GetDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name,
GetDentryResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
GetDentryRequest request;
// TODO(@许超杰): delete it
request.set_fsid(fsId);
request.set_parentinodeid(inodeid);
request.set_name(name);
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_txid(1);

curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.GetDentry(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::ListDentry(uint32_t fsId, uint64_t inodeid,
const std::string &last, uint32_t count,
ListDentryResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
ListDentryRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_txid(1);
request.set_fsid(fsId);
request.set_dirinodeid(inodeid);
request.set_last(last);
request.set_count(count);


curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.ListDentry(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::CreateDentry(const Dentry &dentry,
CreateDentryResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
CreateDentryRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
Dentry *d = new Dentry;
d->set_fsid(dentry.fsid());
d->set_inodeid(dentry.inodeid());
d->set_parentinodeid(dentry.parentinodeid());
d->set_name(dentry.name());
// TODO(@许超杰) delete it
d->set_txid(100);
request.set_allocated_dentry(d);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.CreateDentry(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::DeleteDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name,
DeleteDentryResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
DeleteDentryRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_txid(1);
request.set_fsid(fsId);
request.set_parentinodeid(inodeid);
request.set_name(name);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.DeleteDentry(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::GetInode(uint32_t fsId, uint64_t inodeid,
GetInodeResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
GetInodeRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_fsid(fsId);
request.set_inodeid(inodeid);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.GetInode(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::UpdateInode(const Inode &inode,
UpdateInodeResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
UpdateInodeRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_inodeid(inode.inodeid());
request.set_fsid(inode.fsid());
request.set_length(inode.length());
request.set_ctime(inode.ctime());
request.set_mtime(inode.mtime());
request.set_atime(inode.atime());
request.set_uid(inode.uid());
request.set_gid(inode.gid());
request.set_mode(inode.mode());
if (inode.has_volumeextentlist()) {
VolumeExtentList *vlist = new VolumeExtentList;
vlist->CopyFrom(inode.volumeextentlist());
request.set_allocated_volumeextentlist(vlist);
}
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.UpdateInode(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::CreateInode(const InodeParam &param,
CreateInodeResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
CreateInodeRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_fsid(param.fsId);
request.set_length(param.length);
request.set_uid(param.uid);
request.set_gid(param.gid);
request.set_mode(param.mode);
request.set_type(param.type);
request.set_symlink(param.symlink);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.CreateInode(cntl, &request, response, nullptr);
}

void MetaServerBaseClient::DeleteInode(uint32_t fsId, uint64_t inodeid,
DeleteInodeResponse *response,
brpc::Controller *cntl,
brpc::Channel *channel) {
DeleteInodeRequest request;
request.set_copysetid(1);
request.set_poolid(1);
request.set_partitionid(1);
request.set_fsid(fsId);
request.set_inodeid(inodeid);
curvefs::metaserver::MetaServerService_Stub stub(channel);
stub.DeleteInode(cntl, &request, response, nullptr);
}


void MDSBaseClient::CreateFs(const std::string &fsName, uint64_t blockSize,
const Volume &volume, CreateFsResponse *response,
brpc::Controller *cntl, brpc::Channel *channel) {
CreateFsRequest request;
request.set_fsname(fsName);
request.set_blocksize(blockSize);
request.set_fstype(::curvefs::common::FSType::TYPE_VOLUME);
Volume *vol = new Volume;
vol->CopyFrom(volume);
request.mutable_fsdetail()->set_allocated_volume(vol);
curvefs::mds::MdsService_Stub stub(channel);
stub.CreateFs(cntl, &request, response, nullptr);
}

void MDSBaseClient::CreateFsS3(const std::string &fsName, uint64_t blockSize,
const S3Info &s3Info, CreateFsResponse *response,
brpc::Controller *cntl, brpc::Channel *channel) {
CreateFsRequest request;
request.set_fsname(fsName);
request.set_blocksize(blockSize);
request.set_fstype(FSType::TYPE_S3);
S3Info *info = new S3Info;
info->CopyFrom(s3Info);
request.mutable_fsdetail()->set_allocated_s3info(info);
curvefs::mds::MdsService_Stub stub(channel);
stub.CreateFs(cntl, &request, response, nullptr);
}

void MDSBaseClient::DeleteFs(const std::string &fsName,
DeleteFsResponse *response, brpc::Controller *cntl,
brpc::Channel *channel) {
DeleteFsRequest request;
request.set_fsname(fsName);
curvefs::mds::MdsService_Stub stub(channel);
stub.DeleteFs(cntl, &request, response, nullptr);
}

void MDSBaseClient::MountFs(const std::string &fsName,
const std::string &mountPt,
MountFsResponse *response, brpc::Controller *cntl,
brpc::Channel *channel) {
MountFsRequest request;
request.set_fsname(fsName);
request.set_mountpoint(mountPt);
curvefs::mds::MdsService_Stub stub(channel);
stub.MountFs(cntl, &request, response, nullptr);
}

void MDSBaseClient::UmountFs(const std::string &fsName,
const std::string &mountPt,
UmountFsResponse *response, brpc::Controller *cntl,
brpc::Channel *channel) {
UmountFsRequest request;
request.set_fsname(fsName);
request.set_mountpoint(mountPt);
curvefs::mds::MdsService_Stub stub(channel);
stub.UmountFs(cntl, &request, response, nullptr);
}

void MDSBaseClient::GetFsInfo(const std::string &fsName,
GetFsInfoResponse *response,
brpc::Controller *cntl, brpc::Channel *channel) {
GetFsInfoRequest request;
request.set_fsname(fsName);
curvefs::mds::MdsService_Stub stub(channel);
stub.GetFsInfo(cntl, &request, response, nullptr);
}

void MDSBaseClient::GetFsInfo(uint32_t fsId, GetFsInfoResponse *response,
brpc::Controller *cntl, brpc::Channel *channel) {
GetFsInfoRequest request;
request.set_fsid(fsId);
curvefs::mds::MdsService_Stub stub(channel);
stub.GetFsInfo(cntl, &request, response, nullptr);
}

void SpaceBaseClient::AllocExtents(uint32_t fsId,
const ExtentAllocInfo &toAllocExtent,
curvefs::space::AllocateType type,
Expand Down
119 changes: 2 additions & 117 deletions curvefs/src/client/base_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,133 +31,18 @@
#include "curvefs/proto/mds.pb.h"
#include "curvefs/proto/metaserver.pb.h"
#include "curvefs/proto/space.pb.h"
#include "curvefs/src/client/extent.h"
#include "curvefs/src/client/common/extent.h"

namespace curvefs {
namespace client {

using curvefs::metaserver::CreateDentryRequest;
using curvefs::metaserver::CreateDentryResponse;
using curvefs::metaserver::CreateInodeRequest;
using curvefs::metaserver::CreateInodeResponse;
using curvefs::metaserver::DeleteDentryRequest;
using curvefs::metaserver::DeleteDentryResponse;
using curvefs::metaserver::DeleteInodeRequest;
using curvefs::metaserver::DeleteInodeResponse;
using curvefs::metaserver::Dentry;
using ::curvefs::metaserver::FsFileType;
using curvefs::metaserver::GetDentryRequest;
using curvefs::metaserver::GetDentryResponse;
using curvefs::metaserver::GetInodeRequest;
using curvefs::metaserver::GetInodeResponse;
using curvefs::metaserver::Inode;
using curvefs::metaserver::ListDentryRequest;
using curvefs::metaserver::ListDentryResponse;
using curvefs::metaserver::UpdateInodeRequest;
using curvefs::metaserver::UpdateInodeResponse;

using curvefs::common::Volume;
using curvefs::common::S3Info;
using curvefs::common::FSType;
using curvefs::mds::CreateFsRequest;
using curvefs::mds::CreateFsResponse;
using curvefs::mds::DeleteFsRequest;
using curvefs::mds::DeleteFsResponse;
using curvefs::mds::FsInfo;
using curvefs::mds::FsStatus;
using curvefs::mds::GetFsInfoRequest;
using curvefs::mds::GetFsInfoResponse;
using curvefs::mds::MountFsRequest;
using curvefs::mds::MountFsResponse;
using curvefs::mds::UmountFsRequest;
using curvefs::mds::UmountFsResponse;

using curvefs::space::AllocateSpaceRequest;
using curvefs::space::AllocateSpaceResponse;
using curvefs::space::DeallocateSpaceRequest;
using curvefs::space::DeallocateSpaceResponse;
using curvefs::space::Extent;


struct InodeParam {
uint64_t fsId;
uint64_t length;
uint32_t uid;
uint32_t gid;
uint32_t mode;
FsFileType type;
std::string symlink;
};


class MetaServerBaseClient {
public:
MetaServerBaseClient() {}

virtual ~MetaServerBaseClient() {}

virtual void GetDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name, GetDentryResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void ListDentry(uint32_t fsId, uint64_t inodeid,
const std::string &last, uint32_t count,
ListDentryResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void CreateDentry(const Dentry &dentry,
CreateDentryResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void DeleteDentry(uint32_t fsId, uint64_t inodeid,
const std::string &name,
DeleteDentryResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void GetInode(uint32_t fsId, uint64_t inodeid,
GetInodeResponse *response, brpc::Controller *cntl,
brpc::Channel *channel);

virtual void UpdateInode(const Inode &inode, UpdateInodeResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void CreateInode(const InodeParam &param,
CreateInodeResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void DeleteInode(uint32_t fsId, uint64_t inodeid,
DeleteInodeResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);
};

class MDSBaseClient {
public:
virtual void CreateFs(const std::string &fsName, uint64_t blockSize,
const Volume &volume, CreateFsResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void CreateFsS3(const std::string &fsName, uint64_t blockSize,
const S3Info &s3Info, CreateFsResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void DeleteFs(const std::string &fsName, DeleteFsResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);

virtual void MountFs(const std::string &fsName, const std::string &mountPt,
MountFsResponse *response, brpc::Controller *cntl,
brpc::Channel *channel);

virtual void UmountFs(const std::string &fsName, const std::string &mountPt,
UmountFsResponse *response, brpc::Controller *cntl,
brpc::Channel *channel);

virtual void GetFsInfo(const std::string &fsName,
GetFsInfoResponse *response, brpc::Controller *cntl,
brpc::Channel *channel);

virtual void GetFsInfo(uint32_t fsId, GetFsInfoResponse *response,
brpc::Controller *cntl, brpc::Channel *channel);
};
using common::ExtentAllocInfo;

class SpaceBaseClient {
public:
Expand Down
Loading

0 comments on commit 9fd79ee

Please sign in to comment.