Skip to content

Commit

Permalink
rados: implement rm --force option to force remove when full.
Browse files Browse the repository at this point in the history
    librados extend remove interface, add flags parameter, and use
    this extended interface to implement force remove when cluster
    full.

Signed-off-by: Xiaowei Chen <chen.xiaowei@h3c.com>
  • Loading branch information
Xiaowei Chen committed Nov 7, 2015
1 parent 116bc83 commit b6ac5da
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/include/rados/librados.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ namespace librados
size_t len);
int read(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
int remove(const std::string& oid);
int remove(const std::string& oid, int flags);
int trunc(const std::string& oid, uint64_t size);
int mapext(const std::string& o, uint64_t off, size_t len, std::map<uint64_t,uint64_t>& m);
int sparse_read(const std::string& o, std::map<uint64_t,uint64_t>& m, bufferlist& bl, size_t len, uint64_t off);
Expand Down
8 changes: 8 additions & 0 deletions src/librados/IoCtxImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,14 @@ int librados::IoCtxImpl::remove(const object_t& oid)
return operate(oid, &op, NULL);
}

int librados::IoCtxImpl::remove(const object_t& oid, int flags)
{
::ObjectOperation op;
prepare_assert_ops(&op);
op.remove();
return operate(oid, &op, NULL, flags);
}

int librados::IoCtxImpl::trunc(const object_t& oid, uint64_t size)
{
::ObjectOperation op;
Expand Down
1 change: 1 addition & 0 deletions src/librados/IoCtxImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct librados::IoCtxImpl {
int sparse_read(const object_t& oid, std::map<uint64_t,uint64_t>& m,
bufferlist& bl, size_t len, uint64_t off);
int remove(const object_t& oid);
int remove(const object_t& oid, int flags);
int stat(const object_t& oid, uint64_t *psize, time_t *pmtime);
int trunc(const object_t& oid, uint64_t size);

Expand Down
6 changes: 6 additions & 0 deletions src/librados/librados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,12 @@ int librados::IoCtx::remove(const std::string& oid)
return io_ctx_impl->remove(obj);
}

int librados::IoCtx::remove(const std::string& oid, int flags)
{
object_t obj(oid);
return io_ctx_impl->remove(obj, flags);
}

int librados::IoCtx::trunc(const std::string& oid, uint64_t size)
{
object_t obj(oid);
Expand Down
17 changes: 14 additions & 3 deletions src/tools/rados/rados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void usage(ostream& out)
" put <obj-name> [infile] write object\n"
" truncate <obj-name> length truncate object\n"
" create <obj-name> create object\n"
" rm <obj-name> ... remove object(s)\n"
" rm <obj-name> ...[--force-full] [force no matter full or not]remove object(s)\n"
" cp <obj-name> [target-obj] copy object\n"
" clonedata <src-obj> <dst-obj> clone object data\n"
" listxattr <obj-name>\n"
Expand Down Expand Up @@ -1205,7 +1205,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,

std::string run_name;
std::string prefix;

std::string forcefull("");
Formatter *formatter = NULL;
bool pretty_format = false;
const char *output = NULL;
Expand Down Expand Up @@ -1248,6 +1248,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
if (i != opts.end()) {
run_name = i->second;
}

i = opts.find("force-full");
if (i != opts.end()) {
forcefull = i->second;
}
i = opts.find("prefix");
if (i != opts.end()) {
prefix = i->second;
Expand Down Expand Up @@ -2101,7 +2106,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
if (use_striper) {
ret = striper.remove(oid);
} else {
ret = io_ctx.remove(oid);
if ( forcefull == "true" ){
ret = io_ctx.remove(oid, CEPH_OSD_FLAG_FULL_FORCE);
} else {
ret = io_ctx.remove(oid);
}
}
if (ret < 0) {
string name = (nspace.size() ? nspace + "/" : "" ) + oid;
Expand Down Expand Up @@ -2869,6 +2878,8 @@ int main(int argc, const char **argv)
exit(0);
} else if (ceph_argparse_flag(args, i, "-f", "--force", (char*)NULL)) {
opts["force"] = "true";
} else if (ceph_argparse_flag(args, i, "--force-full", (char*)NULL)) {
opts["force-full"] = "true";
} else if (ceph_argparse_flag(args, i, "-d", "--delete-after", (char*)NULL)) {
opts["delete-after"] = "true";
} else if (ceph_argparse_flag(args, i, "-C", "--create", "--create-pool",
Expand Down

0 comments on commit b6ac5da

Please sign in to comment.