| 266 | } |
| 267 | |
| 268 | static int cls_2pc_queue_commit(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { |
| 269 | cls_2pc_queue_commit_op commit_op; |
| 270 | try { |
| 271 | auto in_iter = in->cbegin(); |
| 272 | decode(commit_op, in_iter); |
| 273 | } catch (ceph::buffer::error& err) { |
| 274 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: failed to decode entry: %s", err.what()); |
| 275 | return -EINVAL; |
| 276 | } |
| 277 | |
| 278 | // get head |
| 279 | cls_queue_head head; |
| 280 | int ret = queue_read_head(hctx, head); |
| 281 | if (ret < 0) { |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | cls_2pc_urgent_data urgent_data; |
| 286 | try { |
| 287 | auto in_iter = head.bl_urgent_data.cbegin(); |
| 288 | decode(urgent_data, in_iter); |
| 289 | } catch (ceph::buffer::error& err) { |
| 290 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: failed to decode entry: %s", err.what()); |
| 291 | return -EINVAL; |
| 292 | } |
| 293 | |
| 294 | auto it = urgent_data.reservations.find(commit_op.id); |
| 295 | cls_2pc_reservations xattr_reservations; |
| 296 | bufferlist bl_xattrs; |
| 297 | if (it == urgent_data.reservations.end()) { |
| 298 | if (!urgent_data.has_xattrs) { |
| 299 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: reservation does not exist: %u", commit_op.id); |
| 300 | return -ENOENT; |
| 301 | } |
| 302 | // try to look for the reservation in xattrs |
| 303 | auto ret = cls_cxx_getxattr(hctx, CLS_QUEUE_URGENT_DATA_XATTR_NAME, &bl_xattrs); |
| 304 | if (ret < 0) { |
| 305 | if (ret == -ENOENT || ret == -ENODATA) { |
| 306 | // no xattrs, reservation does not exists |
| 307 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: reservation does not exist: %u", commit_op.id); |
| 308 | return -ENOENT; |
| 309 | } |
| 310 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: failed to read xattrs with: %d", ret); |
| 311 | return ret; |
| 312 | } |
| 313 | auto iter = bl_xattrs.cbegin(); |
| 314 | try { |
| 315 | decode(xattr_reservations, iter); |
| 316 | } catch (ceph::buffer::error& err) { |
| 317 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: failed to decode xattrs urgent data map"); |
| 318 | return -EINVAL; |
| 319 | } //end - catch |
| 320 | it = xattr_reservations.find(commit_op.id); |
| 321 | if (it == urgent_data.reservations.end()) { |
| 322 | CLS_LOG(1, "ERROR: cls_2pc_queue_commit: reservation does not exist: %u", commit_op.id); |
| 323 | return -ENOENT; |
| 324 | } |
| 325 | } |