Skip to content

Commit

Permalink
curvefs/client: add -o mdsaddr=xxxx support
Browse files Browse the repository at this point in the history
1. remove option: user, volume
2. add option: mdsAddr
3. format help message
4. fix coredump issue
  • Loading branch information
h0hmj committed Apr 29, 2022
1 parent d4bfa7e commit 35a1bb3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
10 changes: 7 additions & 3 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int InitGlog(const char *confPath, const char *argv0) {
}

int InitFuseClient(const char *confPath, const char* fsName,
const char *fsType) {
const char *fsType, const char *mdsAddr) {
g_clientOpMetric = new ClientOpMetric();

Configuration conf;
Expand All @@ -154,6 +154,8 @@ int InitFuseClient(const char *confPath, const char* fsName,
LOG(ERROR) << "LoadConfig failed, confPath = " << confPath;
return -1;
}
if (mdsAddr)
conf.SetStringValue("mdsOpt.rpcRetryOpt.addrs", mdsAddr);

conf.PrintConfig();

Expand Down Expand Up @@ -199,8 +201,10 @@ int InitFuseClient(const char *confPath, const char* fsName,
}

void UnInitFuseClient() {
g_ClientInstance->Fini();
g_ClientInstance->UnInit();
if (g_ClientInstance) {
g_ClientInstance->Fini();
g_ClientInstance->UnInit();
}
delete g_ClientInstance;
delete g_fuseClientOption;
delete g_clientOpMetric;
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/curve_fuse_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" {
int InitGlog(const char *confPath, const char *argv0);

int InitFuseClient(const char *confPath, const char *fsName,
const char* fsType);
const char* fsType, const char* mdsAddr);

void UnInitFuseClient();

Expand Down
12 changes: 4 additions & 8 deletions curvefs/src/client/fuse_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ struct MountOption {
const char* mountPoint;
const char* fsName;
const char* fsType;
const char* volume;
const char* user;
const char* conf;
const char* mdsAddr;
};

static const struct fuse_opt mount_opts[] = {
Expand All @@ -49,15 +48,12 @@ static const struct fuse_opt mount_opts[] = {
{ "fstype=%s",
offsetof(struct MountOption, fsType), 0},

{ "volume=%s",
offsetof(struct MountOption, volume), 0},

{ "user=%s",
offsetof(struct MountOption, user), 0},

{ "conf=%s",
offsetof(struct MountOption, conf), 0},

{ "mdsaddr=%s",
offsetof(struct MountOption, mdsAddr), 0},

FUSE_OPT_END
};

Expand Down
37 changes: 27 additions & 10 deletions curvefs/src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,38 @@ static const struct fuse_lowlevel_ops curve_ll_oper = {
.statfs = FuseOpStatFs,
};

void print_option_help(const char* o, const char* msg) {
printf(" -o %-20s%s\n", o, msg);
}

void extra_options_help() {
printf("\nExtra options:\n");
print_option_help("fsname", "[required] name of filesystem to be mounted");
print_option_help(
"fstype", "[required] type of filesystem to be mounted (s3/volume)");
print_option_help("conf", "[required] path of config file");
print_option_help("mdsAddr", "mdsAddr of curvefs cluster");
}

int main(int argc, char *argv[]) {
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct fuse_session *se;
struct fuse_cmdline_opts opts;
struct fuse_loop_config config;
struct MountOption mOpts = { .mountPoint = 0,
.volume = 0 };
struct MountOption mOpts = {0};
int ret = -1;

if (fuse_parse_cmdline(&args, &opts) != 0)
return 1;
if (opts.show_help) {
printf("usage: %s -o volume=xxx conf=xxx [options] <mountpoint>\n\n", argv[0]); // NOLINT
printf(
"usage: %s -o conf=/etc/curvefs/client.conf -o fsname=testfs \\\n"
" -o fstype=s3 [-o mdsaddr=1.1.1.1] [OPTIONS] <mountpoint>\n",
argv[0]);
printf("Fuse Options:\n");
fuse_cmdline_help();
fuse_lowlevel_help();
extra_options_help();
ret = 0;
goto err_out1;
} else if (opts.show_version) {
Expand All @@ -79,8 +96,7 @@ int main(int argc, char *argv[]) {
}

if (opts.mountpoint == NULL) {
printf("usage: %s -o volume=xxx conf=xxx [options] <mountpoint>\n\n", argv[0]); // NOLINT
printf(" %s --help\n", argv[0]);
printf("required option is missing: mountpoint\n");
ret = 1;
goto err_out1;
}
Expand All @@ -90,20 +106,21 @@ int main(int argc, char *argv[]) {

mOpts.mountPoint = opts.mountpoint;

if (mOpts.conf == NULL) {
printf("usage: %s -o volume=xxx conf=xxx [options] <mountpoint>\n\n", argv[0]); // NOLINT
printf(" %s --help\n", argv[0]);
if (mOpts.conf == NULL || mOpts.fsName == NULL || mOpts.fsType == NULL) {
printf(
"one of required options is missing. conf, fsname, fstype are "
"required.\n");
ret = 1;
goto err_out1;
}

printf("Mount %s on volume %s ... \n", mOpts.mountPoint, mOpts.volume);
printf("Begin to mount fs %s to %s\n", mOpts.fsName, mOpts.mountPoint);

if (InitGlog(mOpts.conf, argv[0]) < 0) {
printf("Init glog failed, confpath = %s\n", mOpts.conf);
}

ret = InitFuseClient(mOpts.conf, mOpts.fsName, mOpts.fsType);
ret = InitFuseClient(mOpts.conf, mOpts.fsName, mOpts.fsType, mOpts.mdsAddr);
if (ret < 0) {
printf("init fuse client fail, conf =%s\n", mOpts.conf);
goto err_out2;
Expand Down
11 changes: 2 additions & 9 deletions curvefs/test/client/test_fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,10 @@ TEST_F(TestFuseVolumeClient, FuseOpInit_when_fs_exist) {
MountOption mOpts;
memset(&mOpts, 0, sizeof(mOpts));
mOpts.mountPoint = "host1:/test";
mOpts.volume = "xxx";
mOpts.fsName = "xxx";
mOpts.user = "test";
mOpts.fsType = "curve";

std::string volName = mOpts.volume;
std::string user = mOpts.user;
std::string fsName = mOpts.volume;
std::string fsName = mOpts.fsName;

FsInfo fsInfoExp;
fsInfoExp.set_fsid(200);
Expand All @@ -194,11 +190,10 @@ TEST_F(TestFuseVolumeClient, FuseOpDestroy) {
MountOption mOpts;
memset(&mOpts, 0, sizeof(mOpts));
mOpts.mountPoint = "host1:/test";
mOpts.volume = "xxx";
mOpts.fsName = "xxx";
mOpts.fsType = "curve";

std::string fsName = mOpts.volume;
std::string fsName = mOpts.fsName;

EXPECT_CALL(*mdsClient_, UmountFs(fsName, _))
.WillOnce(Return(FSStatusCode::OK));
Expand Down Expand Up @@ -1561,7 +1556,6 @@ TEST_F(TestFuseS3Client, FuseOpInit_when_fs_exist) {
memset(&mOpts, 0, sizeof(mOpts));
mOpts.fsName = "s3fs";
mOpts.mountPoint = "host1:/test";
mOpts.user = "test";
mOpts.fsType = "s3";

std::string fsName = mOpts.fsName;
Expand All @@ -1587,7 +1581,6 @@ TEST_F(TestFuseS3Client, FuseOpDestroy) {
memset(&mOpts, 0, sizeof(mOpts));
mOpts.fsName = "s3fs";
mOpts.mountPoint = "host1:/test";
mOpts.user = "test";
mOpts.fsType = "s3";

std::string fsName = mOpts.fsName;
Expand Down

0 comments on commit 35a1bb3

Please sign in to comment.