mirror of
https://github.com/ceph/ceph
synced 2025-02-22 18:47:18 +00:00
rbd: verify the specified namespace before set
Signed-off-by: songweibin <song.weibin@zte.com.cn>
This commit is contained in:
parent
aebd6ed964
commit
a2c9a622e6
@ -665,6 +665,21 @@ int init_io_ctx(librados::Rados &rados, const std::string &pool_name,
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!namespace_name.empty()) {
|
||||
librbd::RBD rbd;
|
||||
bool exists = false;
|
||||
r = rbd.namespace_exists(*io_ctx, namespace_name.c_str(), &exists);
|
||||
if (r < 0) {
|
||||
std::cerr << "rbd: error asserting namespace: "
|
||||
<< cpp_strerror(r) << std::endl;
|
||||
return r;
|
||||
}
|
||||
if (!exists) {
|
||||
std::cerr << "rbd: namespace '" << namespace_name << "' does not exist."
|
||||
<< std::endl;
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
io_ctx->set_namespace(namespace_name);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user