Skip to content

Commit

Permalink
Merge pull request #6202 from cxwshawn/wip-ful-fix
Browse files Browse the repository at this point in the history
rados: implement rm --force option to force remove when full

Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
liewegas committed Dec 17, 2015
2 parents 03f9c6f + 54a6ba8 commit 4060d21
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 10 deletions.
15 changes: 15 additions & 0 deletions qa/workunits/rados/test_rados_tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,24 @@ test_xattr() {
rm $V1 $V2
cleanup
}
test_rmobj() {
p=`uuidgen`
ceph osd pool create $p 1
ceph osd pool set-quota $p max_objects 1
V1=`mktemp fooattrXXXXXXX`
rados put $OBJ $V1 -p $p
while ! ceph osd dump | grep 'full max_objects'
do
sleep 2
done
rados -p $p rm $OBJ --force-full
rados rmpool $p $p --yes-i-really-really-mean-it
rm $V1
}

test_xattr
test_omap
test_rmobj

echo "SUCCESS!"
exit 0
1 change: 1 addition & 0 deletions src/include/rados/librados.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,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
2 changes: 1 addition & 1 deletion src/include/radosstriper/libradosstriper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace libradosstriper
* during deletion (same EBUSY return code)
*/
int remove(const std::string& soid);

int remove(const std::string& soid, int flags);
/**
* Resizes a striped object
* the truncation can not happen if any I/O is ongoing (it
Expand Down
8 changes: 8 additions & 0 deletions src/librados/IoCtxImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,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 @@ -1169,6 +1169,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
13 changes: 9 additions & 4 deletions src/libradosstriper/RadosStriperImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ int libradosstriper::RadosStriperImpl::stat(const std::string& soid, uint64_t *p
return 0;
}

int libradosstriper::RadosStriperImpl::remove(const std::string& soid)
int libradosstriper::RadosStriperImpl::remove(const std::string& soid, int flags)
{
std::string firstObjOid = getObjectId(soid, 0);
try {
Expand Down Expand Up @@ -591,11 +591,15 @@ int libradosstriper::RadosStriperImpl::remove(const std::string& soid)
// delete rados objects in reverse order
int rcr = 0;
for (int i = nb_objects-1; i >= 0; i--) {
rcr = m_ioCtx.remove(getObjectId(soid, i));
if (flags == 0) {
rcr = m_ioCtx.remove(getObjectId(soid, i));
} else {
rcr = m_ioCtx.remove(getObjectId(soid, i), flags);
}
if (rcr < 0 and -ENOENT != rcr) {
lderr(cct()) << "RadosStriperImpl::remove : deletion incomplete for " << soid
<< ", as " << getObjectId(soid, i) << " could not be deleted (rc=" << rc << ")"
<< dendl;
<< ", as " << getObjectId(soid, i) << " could not be deleted (rc=" << rc << ")"
<< dendl;
break;
}
}
Expand All @@ -605,6 +609,7 @@ int libradosstriper::RadosStriperImpl::remove(const std::string& soid)
// errror caught when trying to take the exclusive lock
return e.m_code;
}

}

int libradosstriper::RadosStriperImpl::trunc(const std::string& soid, uint64_t size)
Expand Down
2 changes: 1 addition & 1 deletion src/libradosstriper/RadosStriperImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct libradosstriper::RadosStriperImpl {

// stat, deletion and truncation
int stat(const std::string& soid, uint64_t *psize, time_t *pmtime);
int remove(const std::string& soid);
int remove(const std::string& soid, int flags=0);
int trunc(const std::string& soid, uint64_t size);

// reference counting
Expand Down
4 changes: 4 additions & 0 deletions src/libradosstriper/libradosstriper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ int libradosstriper::RadosStriper::remove(const std::string& soid)
{
return rados_striper_impl->remove(soid);
}
int libradosstriper::RadosStriper::remove(const std::string& soid, int flags)
{
return rados_striper_impl->remove(soid, flags);
}

int libradosstriper::RadosStriper::trunc(const std::string& soid, uint64_t size)
{
Expand Down
23 changes: 19 additions & 4 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 @@ -1239,7 +1239,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,

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

bool forcefull = false;
Formatter *formatter = NULL;
bool pretty_format = false;
const char *output = NULL;
Expand Down Expand Up @@ -1282,6 +1282,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 = true;
}
i = opts.find("prefix");
if (i != opts.end()) {
prefix = i->second;
Expand Down Expand Up @@ -2161,9 +2166,17 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
for (; iter != nargs.end(); ++iter) {
const string & oid = *iter;
if (use_striper) {
ret = striper.remove(oid);
if (forcefull) {
ret = striper.remove(oid, CEPH_OSD_FLAG_FULL_FORCE);
} else {
ret = striper.remove(oid);
}
} else {
ret = io_ctx.remove(oid);
if (forcefull) {
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 @@ -2946,6 +2959,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 4060d21

Please sign in to comment.