| 375 | } |
| 376 | |
| 377 | static int cls_2pc_queue_abort(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { |
| 378 | cls_2pc_queue_abort_op abort_op; |
| 379 | try { |
| 380 | auto in_iter = in->cbegin(); |
| 381 | decode(abort_op, in_iter); |
| 382 | } catch (ceph::buffer::error& err) { |
| 383 | CLS_LOG(1, "ERROR: cls_2pc_queue_abort: failed to decode entry: %s", err.what()); |
| 384 | return -EINVAL; |
| 385 | } |
| 386 | |
| 387 | // get head |
| 388 | cls_queue_head head; |
| 389 | int ret = queue_read_head(hctx, head); |
| 390 | if (ret < 0) { |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | cls_2pc_urgent_data urgent_data; |
| 395 | try { |
| 396 | auto in_iter = head.bl_urgent_data.cbegin(); |
| 397 | decode(urgent_data, in_iter); |
| 398 | } catch (ceph::buffer::error& err) { |
| 399 | CLS_LOG(1, "ERROR: cls_2pc_queue_abort: failed to decode entry: %s", err.what()); |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | |
| 403 | auto it = urgent_data.reservations.find(abort_op.id); |
| 404 | uint64_t reservation_size; |
| 405 | if (it == urgent_data.reservations.end()) { |
| 406 | if (!urgent_data.has_xattrs) { |
| 407 | CLS_LOG(20, "INFO: cls_2pc_queue_abort: reservation does not exist: %u", abort_op.id); |
| 408 | return 0; |
| 409 | } |
| 410 | // try to look for the reservation in xattrs |
| 411 | bufferlist bl_xattrs; |
| 412 | auto ret = cls_cxx_getxattr(hctx, CLS_QUEUE_URGENT_DATA_XATTR_NAME, &bl_xattrs); |
| 413 | if (ret < 0) { |
| 414 | if (ret == -ENOENT || ret == -ENODATA) { |
| 415 | // no xattrs, reservation does not exists |
| 416 | CLS_LOG(20, "INFO: cls_2pc_queue_abort: reservation does not exist: %u", abort_op.id); |
| 417 | return 0; |
| 418 | } |
| 419 | CLS_LOG(1, "ERROR: cls_2pc_queue_abort: failed to read xattrs with: %d", ret); |
| 420 | return ret; |
| 421 | } |
| 422 | auto iter = bl_xattrs.cbegin(); |
| 423 | cls_2pc_reservations xattr_reservations; |
| 424 | try { |
| 425 | decode(xattr_reservations, iter); |
| 426 | } catch (ceph::buffer::error& err) { |
| 427 | CLS_LOG(1, "ERROR: cls_2pc_queue_abort: failed to decode xattrs urgent data map"); |
| 428 | return -EINVAL; |
| 429 | } //end - catch |
| 430 | it = xattr_reservations.find(abort_op.id); |
| 431 | if (it == xattr_reservations.end()) { |
| 432 | CLS_LOG(20, "INFO: cls_2pc_queue_abort: reservation does not exist: %u", abort_op.id); |
| 433 | return 0; |
| 434 | } |