get_index_by_object(entry.object, entry.op_id, index);
}
+static int get_existing_entry(cls_method_context_t hctx, const string& client_id,
+ const string& op_id, const string& object,
+ cls_statelog_entry& entry)
+{
+ if ((object.empty() && client_id.empty()) || op_id.empty()) {
+ return -EINVAL;
+ }
+
+ string obj_index;
+ if (!object.empty()) {
+ get_index_by_object(object, op_id, obj_index);
+ } else {
+ get_index_by_client(client_id, op_id, obj_index);
+ }
+
+ bufferlist bl;
+ int rc = cls_cxx_map_get_val(hctx, obj_index, &bl);
+ if (rc < 0) {
+ CLS_LOG(0, "could not find entry %s", obj_index.c_str());
+ return rc;
+ }
+ try {
+ bufferlist::iterator iter = bl.begin();
+ ::decode(entry, iter);
+ } catch (buffer::error& err) {
+ CLS_LOG(0, "ERROR: failed to decode entry %s", obj_index.c_str());
+ return -EIO;
+ }
+
+ if ((!object.empty() && entry.object != object) ||
+ (!client_id.empty() && entry.client_id != client_id)){
+ /* ouch, we were passed inconsistent client_id / object */
+ CLS_LOG(0, "data mismatch: object=%s client_id=%s entry: object=%s client_id=%s",
+ object.c_str(), client_id.c_str(), entry.object.c_str(), entry.client_id.c_str());
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int cls_statelog_add(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
{
bufferlist::iterator in_iter = in->begin();
return -EINVAL;
}
- if (op.object.empty() || op.op_id.empty()) {
- CLS_LOG(0, "object name or op id not specified");
- return -EINVAL;
- }
+ cls_statelog_entry entry;
+
+ int rc = get_existing_entry(hctx, op.client_id, op.op_id, op.object, entry);
+ if (rc < 0)
+ return rc;
string obj_index;
- get_index_by_object(op.object, op.op_id, obj_index);
+ get_index_by_object(entry.object, entry.op_id, obj_index);
- bufferlist bl;
- int rc = cls_cxx_map_get_val(hctx, obj_index, &bl);
+ rc = cls_cxx_map_remove_key(hctx, obj_index);
if (rc < 0) {
- CLS_LOG(0, "could not find entry %s", obj_index.c_str());
+ CLS_LOG(0, "ERROR: failed to remove key");
return rc;
}
- cls_statelog_entry entry;
-
- try {
- bufferlist::iterator iter = bl.begin();
- ::decode(entry, iter);
- } catch (buffer::error& err) {
- CLS_LOG(0, "ERROR: failed to decode entry %s", obj_index.c_str());
- return -EIO;
- }
-
string client_index;
get_index_by_client(entry.client_id, entry.op_id, client_index);
- rc = cls_cxx_map_remove_key(hctx, obj_index);
- if (rc < 0) {
- CLS_LOG(0, "ERROR: failed to remove key");
- return rc;
- }
rc = cls_cxx_map_remove_key(hctx, client_index);
if (rc < 0) {
CLS_LOG(0, "ERROR: failed to remove key");
cls_statelog_entry entry;
- try {
- bufferlist::iterator iter = bl.begin();
- ::decode(entry, iter);
- } catch (buffer::error& err) {
- CLS_LOG(0, "ERROR: failed to decode entry %s", obj_index.c_str());
- return -EIO;
- }
+ rc = get_existing_entry(hctx, op.client_id, op.op_id, op.object, entry);
+ if (rc < 0)
+ return rc;
if (entry.state != op.state)
return -ECANCELED;
* -ENODATA when done, so caller needs to repeat sending request until that.
*/
struct cls_statelog_remove_op {
- string object;
+ string client_id;
string op_id;
+ string object;
cls_statelog_remove_op() {}
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
- ::encode(object, bl);
+ ::encode(client_id, bl);
::encode(op_id, bl);
+ ::encode(object, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
- ::decode(object, bl);
+ ::decode(client_id, bl);
::decode(op_id, bl);
+ ::decode(object, bl);
DECODE_FINISH(bl);
}
};
WRITE_CLASS_ENCODER(cls_statelog_remove_op)
struct cls_statelog_check_state_op {
- string object;
+ string client_id;
string op_id;
+ string object;
uint32_t state;
cls_statelog_check_state_op() {}
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
- ::encode(object, bl);
+ ::encode(client_id, bl);
::encode(op_id, bl);
+ ::encode(object, bl);
::encode(state, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::iterator& bl) {
DECODE_START(1, bl);
- ::decode(object, bl);
+ ::decode(client_id, bl);
::decode(op_id, bl);
+ ::decode(object, bl);
::decode(state, bl);
DECODE_FINISH(bl);
}