using std::list;
using std::map;
using std::make_pair;
-using std::ostream;
-using std::ostringstream;
using std::pair;
using std::set;
using std::string;
-using std::stringstream;
using std::to_string;
using std::vector;
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
string flag_name;
cmd_getval(cmdmap, "flag_name", flag_name);
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream& ss) override
+ std::ostream& ss) override
{
if (!mon->osdmon()->is_writeable()) {
// not allowed to write yet, so retry when we can
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
ceph_assert(m_paxos->is_plugged());
return -EINVAL;
}
+ bool allow_overlay = false;
+ cmd_getval(cmdmap, "allow_dangerous_metadata_overlay", allow_overlay);
+
for (auto& fs : fsmap.get_filesystems()) {
const std::vector<int64_t> &data_pools = fs->mds_map.get_data_pools();
-
- bool sure = false;
- cmd_getval(cmdmap,
- "allow_dangerous_metadata_overlay", sure);
-
if ((std::find(data_pools.begin(), data_pools.end(), data) != data_pools.end()
|| fs->mds_map.get_metadata_pool() == metadata)
- && !sure) {
+ && !allow_overlay) {
ss << "Filesystem '" << fs_name
<< "' is already using one of the specified RADOS pools. This should ONLY be done in emergencies and after careful reading of the documentation. Pass --allow-dangerous-metadata-overlay to permit this.";
- return -EEXIST;
+ return -EINVAL;
+ }
+ }
+
+ int64_t fscid = FS_CLUSTER_ID_NONE;
+ if (cmd_getval(cmdmap, "fscid", fscid)) {
+ if (!force) {
+ ss << "Pass --force to create a file system with a specific ID";
+ return -EINVAL;
+ }
+ if (fsmap.filesystem_exists(fscid)) {
+ ss << "filesystem already exists with id '" << fscid << "'";
+ return -EINVAL;
}
}
pg_pool_t const *metadata_pool = mon->osdmon()->osdmap.get_pg_pool(metadata);
ceph_assert(metadata_pool != NULL); // Checked it existed above
- int r = _check_pool(mon->osdmon()->osdmap, data, POOL_DATA_DEFAULT, force, &ss);
+ int r = _check_pool(mon->osdmon()->osdmap, data, POOL_DATA_DEFAULT, force, &ss, allow_overlay);
if (r < 0) {
return r;
}
- r = _check_pool(mon->osdmon()->osdmap, metadata, POOL_METADATA, force, &ss);
+ r = _check_pool(mon->osdmon()->osdmap, metadata, POOL_METADATA, force, &ss, allow_overlay);
if (r < 0) {
return r;
}
static_cast<double>(4.0));
mon->osdmon()->propose_pending();
+ bool recover = false;
+ cmd_getval(cmdmap, "recover", recover);
+
// All checks passed, go ahead and create.
auto&& fs = fsmap.create_filesystem(fs_name, metadata, data,
- mon->get_quorum_con_features());
+ mon->get_quorum_con_features(), fscid, recover);
ss << "new fs with metadata pool " << metadata << " and data pool " << data;
+ if (recover) {
+ return 0;
+ }
+
// assign a standby to rank 0 to avoid health warnings
auto info = fsmap.find_replacement_for({fs->fscid, 0});
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
std::string fs_name;
if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
{
fs->mds_map.set_inline_data_enabled(true);
});
-
- // Update `compat`
- CompatSet c = fsmap.get_compat();
- c.incompat.insert(MDS_FEATURE_INCOMPAT_INLINE);
- fsmap.update_compat(c);
} else {
ss << "inline data disabled";
fsmap.modify_filesystem(
fs->mds_map.set_balancer(val);
});
return true;
+ } else if (var == "bal_rank_mask") {
+ if (val.empty()) {
+ ss << "bal_rank_mask may not be empty";
+ return -EINVAL;
+ }
+
+ if (fs->mds_map.check_special_bal_rank_mask(val, MDSMap::BAL_RANK_MASK_TYPE_ANY) == false) {
+ std::string bin_string;
+ int r = fs->mds_map.hex2bin(val, bin_string, MAX_MDS, ss);
+ if (r != 0) {
+ return r;
+ }
+ }
+ ss << "setting the metadata balancer rank mask to " << val;
+
+ fsmap.modify_filesystem(
+ fs->fscid,
+ [val](std::shared_ptr<Filesystem> fs)
+ {
+ fs->mds_map.set_bal_rank_mask(val);
+ });
+ return true;
} else if (var == "max_file_size") {
if (interr.length()) {
ss << var << " requires an integer value";
fs->mds_map.set_min_compat_client(vno);
};
fsmap.modify_filesystem(fs->fscid, std::move(f));
+ } else if (var == "refuse_client_session") {
+ bool refuse_session = false;
+ int r = parse_bool(val, &refuse_session, ss);
+ if (r != 0) {
+ return r;
+ }
+
+ if (refuse_session) {
+ if (!(fs->mds_map.test_flag(CEPH_MDSMAP_REFUSE_CLIENT_SESSION))) {
+ fsmap.modify_filesystem(
+ fs->fscid,
+ [](std::shared_ptr<Filesystem> fs)
+ {
+ fs->mds_map.set_flag(CEPH_MDSMAP_REFUSE_CLIENT_SESSION);
+ });
+ ss << "client(s) blocked from establishing new session(s)";
+ } else {
+ ss << "client(s) already blocked from establishing new session(s)";
+ }
+ } else {
+ if (fs->mds_map.test_flag(CEPH_MDSMAP_REFUSE_CLIENT_SESSION)) {
+ fsmap.modify_filesystem(
+ fs->fscid,
+ [](std::shared_ptr<Filesystem> fs)
+ {
+ fs->mds_map.clear_flag(CEPH_MDSMAP_REFUSE_CLIENT_SESSION);
+ });
+ ss << "client(s) allowed to establish new session(s)";
+ } else {
+ ss << "client(s) already allowed to establish new session(s)";
+ }
+ }
} else {
ss << "unknown variable " << var;
return -EINVAL;
}
};
+class CompatSetHandler : public FileSystemCommandHandler
+{
+ public:
+ CompatSetHandler()
+ : FileSystemCommandHandler("fs compat")
+ {
+ }
+
+ int handle(
+ Monitor *mon,
+ FSMap &fsmap,
+ MonOpRequestRef op,
+ const cmdmap_t& cmdmap,
+ std::ostream &ss) override
+ {
+ static const std::set<std::string> subops = {"rm_incompat", "rm_compat", "add_incompat", "add_compat"};
+
+ std::string fs_name;
+ if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
+ ss << "Missing filesystem name";
+ return -EINVAL;
+ }
+ auto fs = fsmap.get_filesystem(fs_name);
+ if (fs == nullptr) {
+ ss << "Not found: '" << fs_name << "'";
+ return -ENOENT;
+ }
+
+ string subop;
+ if (!cmd_getval(cmdmap, "subop", subop) || subops.count(subop) == 0) {
+ ss << "subop `" << subop << "' not recognized. Must be one of: " << subops;
+ return -EINVAL;
+ }
+
+ int64_t feature;
+ if (!cmd_getval(cmdmap, "feature", feature) || feature <= 0) {
+ ss << "Invalid feature";
+ return -EINVAL;
+ }
+
+ if (fs->mds_map.get_num_up_mds() > 0) {
+ ss << "file system must be failed or down; use `ceph fs fail` to bring down";
+ return -EBUSY;
+ }
+
+ CompatSet cs = fs->mds_map.compat;
+ if (subop == "rm_compat") {
+ if (cs.compat.contains(feature)) {
+ ss << "removed compat feature " << feature;
+ cs.compat.remove(feature);
+ } else {
+ ss << "already removed compat feature " << feature;
+ }
+ } else if (subop == "rm_incompat") {
+ if (cs.incompat.contains(feature)) {
+ ss << "removed incompat feature " << feature;
+ cs.incompat.remove(feature);
+ } else {
+ ss << "already removed incompat feature " << feature;
+ }
+ } else if (subop == "add_compat" || subop == "add_incompat") {
+ string feature_str;
+ if (!cmd_getval(cmdmap, "feature_str", feature_str) || feature_str.empty()) {
+ ss << "adding a feature requires a feature string";
+ return -EINVAL;
+ }
+ auto f = CompatSet::Feature(feature, feature_str);
+ if (subop == "add_compat") {
+ if (cs.compat.contains(feature)) {
+ auto name = cs.compat.get_name(feature);
+ if (name == feature_str) {
+ ss << "feature already exists";
+ } else {
+ ss << "feature with differing name `" << name << "' exists";
+ return -EEXIST;
+ }
+ } else {
+ cs.compat.insert(f);
+ ss << "added compat feature " << f;
+ }
+ } else if (subop == "add_incompat") {
+ if (cs.incompat.contains(feature)) {
+ auto name = cs.incompat.get_name(feature);
+ if (name == feature_str) {
+ ss << "feature already exists";
+ } else {
+ ss << "feature with differing name `" << name << "' exists";
+ return -EEXIST;
+ }
+ } else {
+ cs.incompat.insert(f);
+ ss << "added incompat feature " << f;
+ }
+ } else ceph_assert(0);
+ } else ceph_assert(0);
+
+ auto modifyf = [cs = std::move(cs)](auto&& fs) {
+ fs->mds_map.compat = cs;
+ };
+
+ fsmap.modify_filesystem(fs->fscid, std::move(modifyf));
+ return 0;
+ }
+};
+
class RequiredClientFeaturesHandler : public FileSystemCommandHandler
{
public:
FSMap &fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
std::string fs_name;
if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
ceph_assert(m_paxos->is_plugged());
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
std::string fs_name;
cmd_getval(cmdmap, "fs_name", fs_name);
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
/* We may need to blocklist ranks. */
if (!mon->osdmon()->is_writeable()) {
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
string fs_name;
cmd_getval(cmdmap, "fs_name", fs_name);
}
};
+class RenameFilesystemHandler : public FileSystemCommandHandler
+{
+ public:
+ explicit RenameFilesystemHandler(Paxos *paxos)
+ : FileSystemCommandHandler("fs rename"), m_paxos(paxos)
+ {
+ }
+
+ bool batched_propose() override {
+ return true;
+ }
+
+ int handle(
+ Monitor *mon,
+ FSMap& fsmap,
+ MonOpRequestRef op,
+ const cmdmap_t& cmdmap,
+ std::ostream &ss) override
+ {
+ ceph_assert(m_paxos->is_plugged());
+
+ string fs_name;
+ cmd_getval(cmdmap, "fs_name", fs_name);
+ auto fs = fsmap.get_filesystem(fs_name);
+
+ string new_fs_name;
+ cmd_getval(cmdmap, "new_fs_name", new_fs_name);
+ auto new_fs = fsmap.get_filesystem(new_fs_name);
+
+ if (fs == nullptr) {
+ if (new_fs) {
+ // make 'fs rename' idempotent
+ ss << "File system may already have been renamed. Desired file system '"
+ << new_fs_name << "' exists.";
+ return 0;
+ } else {
+ ss << "File system '" << fs_name << "' does not exist";
+ return -ENOENT;
+ }
+ }
+
+ if (new_fs) {
+ ss << "Desired file system name '" << new_fs_name << "' already in use";
+ return -EINVAL;
+ }
+
+ if (fs->mirror_info.mirrored) {
+ ss << "Mirroring is enabled on file system '"<< fs_name << "'. Disable mirroring on the "
+ "file system after ensuring it's OK to do so, and then retry to rename.";
+ return -EPERM;
+ }
+
+ // Check for confirmation flag
+ bool sure = false;
+ cmd_getval(cmdmap, "yes_i_really_mean_it", sure);
+ if (!sure) {
+ ss << "this is a potentially disruptive operation, clients' cephx credentials need reauthorized "
+ "to access the file system and its pools with the new name. "
+ "Add --yes-i-really-mean-it if you are sure you wish to continue.";
+ return -EPERM;
+ }
+
+ if (!mon->osdmon()->is_writeable()) {
+ // not allowed to write yet, so retry when we can
+ mon->osdmon()->wait_for_writeable(op, new PaxosService::C_RetryMessage(mon->mdsmon(), op));
+ return -EAGAIN;
+ }
+ for (const auto p : fs->mds_map.get_data_pools()) {
+ mon->osdmon()->do_application_enable(p,
+ pg_pool_t::APPLICATION_NAME_CEPHFS,
+ "data", new_fs_name, true);
+ }
+
+ mon->osdmon()->do_application_enable(fs->mds_map.get_metadata_pool(),
+ pg_pool_t::APPLICATION_NAME_CEPHFS,
+ "metadata", new_fs_name, true);
+ mon->osdmon()->propose_pending();
+
+ auto f = [new_fs_name](auto fs) {
+ fs->mds_map.set_fs_name(new_fs_name);
+ };
+ fsmap.modify_filesystem(fs->fscid, std::move(f));
+
+ ss << "File system is renamed. cephx credentials authorized to "
+ "old file system name need to be reauthorized to new file "
+ "system name.";
+
+ return 0;
+ }
+
+private:
+ Paxos *m_paxos;
+};
+
class RemoveDataPoolHandler : public FileSystemCommandHandler
{
public:
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
string poolname;
cmd_getval(cmdmap, "pool", poolname);
FSMap& fsmap,
MonOpRequestRef op,
const cmdmap_t& cmdmap,
- std::stringstream &ss) override
+ std::ostream &ss) override
{
return T::handle(mon, fsmap, op, cmdmap, ss);
}
int handle(Monitor *mon,
FSMap &fsmap, MonOpRequestRef op,
- const cmdmap_t& cmdmap, std::stringstream &ss) override {
+ const cmdmap_t& cmdmap, std::ostream &ss) override {
std::string fs_name;
if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
ss << "Missing filesystem name";
int handle(Monitor *mon,
FSMap &fsmap, MonOpRequestRef op,
- const cmdmap_t& cmdmap, std::stringstream &ss) override {
+ const cmdmap_t& cmdmap, std::ostream &ss) override {
std::string fs_name;
if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
ss << "Missing filesystem name";
}
bool peer_add(FSMap &fsmap, Filesystem::const_ref &&fs,
- const cmdmap_t &cmdmap, std::stringstream &ss) {
+ const cmdmap_t &cmdmap, std::ostream &ss) {
string peer_uuid;
string remote_spec;
string remote_fs_name;
int handle(Monitor *mon,
FSMap &fsmap, MonOpRequestRef op,
- const cmdmap_t& cmdmap, std::stringstream &ss) override {
+ const cmdmap_t& cmdmap, std::ostream &ss) override {
std::string fs_name;
if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
ss << "Missing filesystem name";
{}
bool peer_remove(FSMap &fsmap, Filesystem::const_ref &&fs,
- const cmdmap_t &cmdmap, std::stringstream &ss) {
+ const cmdmap_t &cmdmap, std::ostream &ss) {
string peer_uuid;
cmd_getval(cmdmap, "uuid", peer_uuid);
int handle(Monitor *mon,
FSMap &fsmap, MonOpRequestRef op,
- const cmdmap_t& cmdmap, std::stringstream &ss) override {
+ const cmdmap_t& cmdmap, std::ostream &ss) override {
std::string fs_name;
if (!cmd_getval(cmdmap, "fs_name", fs_name) || fs_name.empty()) {
ss << "Missing filesystem name";
handlers.push_back(std::make_shared<SetHandler>());
handlers.push_back(std::make_shared<FailHandler>());
handlers.push_back(std::make_shared<FlagSetHandler>());
+ handlers.push_back(std::make_shared<CompatSetHandler>());
handlers.push_back(std::make_shared<RequiredClientFeaturesHandler>());
handlers.push_back(std::make_shared<AddDataPoolHandler>(paxos));
handlers.push_back(std::make_shared<RemoveDataPoolHandler>());
handlers.push_back(std::make_shared<FsNewHandler>(paxos));
handlers.push_back(std::make_shared<RemoveFilesystemHandler>());
handlers.push_back(std::make_shared<ResetFilesystemHandler>());
+ handlers.push_back(std::make_shared<RenameFilesystemHandler>(paxos));
handlers.push_back(std::make_shared<SetDefaultHandler>());
handlers.push_back(std::make_shared<AliasHandler<SetDefaultHandler> >(
const int64_t pool_id,
int type,
bool force,
- std::stringstream *ss) const
+ std::ostream *ss,
+ bool allow_overlay) const
{
ceph_assert(ss != NULL);
return -ENOENT;
}
+ if (pool->has_snaps()) {
+ *ss << "pool(" << pool_id <<") already has mon-managed snaps; "
+ "can't attach pool to fs";
+ return -EOPNOTSUPP;
+ }
+
const string& pool_name = osd_map.get_pool_name(pool_id);
+ auto app_map = pool->application_metadata;
+
+ if (!allow_overlay && !force && !app_map.empty()) {
+ auto app = app_map.find(pg_pool_t::APPLICATION_NAME_CEPHFS);
+ if (app != app_map.end()) {
+ auto& [app_name, app_metadata] = *app;
+ auto itr = app_metadata.find("data");
+ if (itr == app_metadata.end()) {
+ itr = app_metadata.find("metadata");
+ }
+ if (itr != app_metadata.end()) {
+ auto& [type, filesystem] = *itr;
+ *ss << "RADOS pool '" << pool_name << "' is already used by filesystem '"
+ << filesystem << "' as a '" << type << "' pool for application '"
+ << app_name << "'";
+ return -EINVAL;
+ }
+ } else {
+ *ss << "RADOS pool '" << pool_name
+ << "' has another non-CephFS application enabled.";
+ return -EINVAL;
+ }
+ }
if (pool->is_erasure()) {
if (type == POOL_METADATA) {
return -EINVAL;
}
+ if (type != POOL_METADATA && pool->pg_autoscale_mode == pg_pool_t::pg_autoscale_mode_t::ON && !pool->has_flag(pg_pool_t::FLAG_BULK)) {
+ // TODO: consider issuing an info event in this case
+ *ss << " Pool '" << pool_name << "' (id '" << pool_id
+ << "') has pg autoscale mode 'on' but is not marked as bulk." << std::endl
+ << " Consider setting the flag by running" << std::endl
+ << " # ceph osd pool set " << pool_name << " bulk true" << std::endl;
+ }
+
// Nothing special about this pool, so it is permissible
return 0;
}
int FileSystemCommandHandler::is_op_allowed(
const MonOpRequestRef& op, const FSMap& fsmap, const cmdmap_t& cmdmap,
- std::stringstream &ss) const
+ std::ostream &ss) const
{
string fs_name;
cmd_getval(cmdmap, "fs_name", fs_name);
auto fs = fsmap_copy.get_filesystem(fs_name);
if (fs == nullptr) {
- /* let "fs rm" handle idempotent case where file system does not exist */
- if (!(get_prefix() == "fs rm" && fsmap.get_filesystem(fs_name) == nullptr)) {
+ auto prefix = get_prefix();
+ /* let "fs rm" and "fs rename" handle idempotent cases where file systems do not exist */
+ if (!(prefix == "fs rm" || prefix == "fs rename") && fsmap.get_filesystem(fs_name) == nullptr) {
ss << "Filesystem not found: '" << fs_name << "'";
return -ENOENT;
}