diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 48474c9fecc..8fe95b964a6 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -2043,10 +2043,21 @@ int rgw_mount2(librgw_t rgw, const char *uid, const char *acc_key, { int rc = 0; - /* stash access data for "mount" */ - RGWLibFS* new_fs = new RGWLibFS(static_cast<CephContext*>(rgw), uid, acc_key, - sec_key, root); - ceph_assert(new_fs); + /* if the config has no value for path/root, choose "/" */ + RGWLibFS* new_fs{nullptr}; + if(root && + (!strcmp(root, ""))) { + /* stash access data for "mount" */ + new_fs = new RGWLibFS( + static_cast<CephContext*>(rgw), uid, acc_key, sec_key, "/"); + } + else { + /* stash access data for "mount" */ + new_fs = new RGWLibFS( + static_cast<CephContext*>(rgw), uid, acc_key, sec_key, root); + } + + ceph_assert(new_fs); /* should we be using ceph_assert? */ const DoutPrefix dp(rgwlib.get_store()->ctx(), dout_subsys, "rgw mount2: "); rc = new_fs->authorize(&dp, rgwlib.get_store()); diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index b5ab94986dc..6e909f3ee17 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -371,6 +371,10 @@ namespace rgw { fh.fh_private = this; } + const std::string& get_name() const { + return name; + } + const fh_key& get_key() const { return fhk; } @@ -1291,6 +1295,8 @@ namespace rgw { struct rgw_fs* get_fs() { return &fs; } + RGWFileHandle& get_fh() { return root_fh; } + uint64_t get_fsid() { return root_fh.state.dev; } RGWUserInfo* get_user() { return &user->get_info(); } diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc index c1e9c35c58b..3adcc2d3ec6 100644 --- a/src/test/librgw_file_nfsns.cc +++ b/src/test/librgw_file_nfsns.cc @@ -189,6 +189,21 @@ TEST(LibRGW, INIT) { ASSERT_NE(rgw_h, nullptr); } +TEST(LibRGW, MOUNT_NOROOT) { + /* do a mount at root="" and verify that it's root is "/" */ + struct rgw_fs *fs = nullptr; + int ret = rgw_mount2(rgw_h, userid.c_str(), access_key.c_str(), + secret_key.c_str(), "", &fs, RGW_MOUNT_FLAG_NONE); + ASSERT_EQ(ret, 0); + ASSERT_NE(fs, nullptr); + + auto& root_fh = static_cast<RGWLibFS*>(fs->fs_private)->get_fh(); + ASSERT_EQ(root_fh.get_name(), "/"); + + ret = rgw_umount(fs, RGW_UMOUNT_FLAG_NONE); + ASSERT_EQ(ret, 0); +} + TEST(LibRGW, MOUNT) { int ret = rgw_mount2(rgw_h, userid.c_str(), access_key.c_str(), secret_key.c_str(), "/", &fs, RGW_MOUNT_FLAG_NONE);