diff options
author | Yehuda Sadeh <yehuda@hq.newdream.net> | 2010-06-29 15:15:00 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@hq.newdream.net> | 2010-06-29 16:00:05 -0700 |
commit | 96b1db80d0466c405fc1dc44680169f955c82c83 (patch) | |
tree | 035611881b8ef683bdc0b65cad72acb35a51a00f /src/cls_rbd.cc | |
parent | c9930900e6b03eae2bb6cdbfe12bf80e39e0085a (diff) | |
download | ceph-96b1db80d0466c405fc1dc44680169f955c82c83.tar.gz |
rbdtool: init rbd block id, later will be used for rename
Diffstat (limited to 'src/cls_rbd.cc')
-rw-r--r-- | src/cls_rbd.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/cls_rbd.cc b/src/cls_rbd.cc index d4cae65d2e6..a216097e3f3 100644 --- a/src/cls_rbd.cc +++ b/src/cls_rbd.cc @@ -18,6 +18,7 @@ cls_handle_t h_class; cls_method_handle_t h_snapshots_list; cls_method_handle_t h_snapshot_add; cls_method_handle_t h_snapshot_revert; +cls_method_handle_t h_assign_bid; static int snap_read_header(cls_method_context_t hctx, bufferlist& bl) { @@ -236,6 +237,47 @@ int snapshot_revert(cls_method_context_t hctx, bufferlist *in, bufferlist *out) return out->length(); } +/* assign block id. This method should be called on the rbd_info object */ +int rbd_assign_bid(cls_method_context_t hctx, bufferlist *in, bufferlist *out) +{ + struct rbd_info info; + int rc; + bufferlist bl; + + rc = cls_cxx_read(hctx, 0, sizeof(info), &bl); + if (rc < 0 && rc != -EEXIST) + return rc; + + if (rc && rc < (int)sizeof(info)) { + CLS_LOG("bad rbd_info object, read %d bytes, expected %d", rc, sizeof(info)); + return -EIO; + } + + uint64_t max_id; + if (rc) { + memcpy(&info, bl.c_str(), sizeof(info)); + max_id = info.max_id + 1; + info.max_id = max_id; + } else { + memset(&info, 0, sizeof(info)); + max_id = 0; + } + + bufferlist newbl; + bufferptr bp(sizeof(info)); + memcpy(bp.c_str(), &info, sizeof(info)); + newbl.push_back(bp); + rc = cls_cxx_write_full(hctx, &newbl); + if (rc < 0) { + CLS_LOG("error writing rbd_info, got rc=%d", rc); + return rc; + } + + ::encode(max_id, *out); + + return out->length(); +} + void __cls_init() { CLS_LOG("Loaded rbd class!"); @@ -245,6 +287,9 @@ void __cls_init() cls_register_cxx_method(h_class, "snap_add", CLS_METHOD_RD | CLS_METHOD_WR, snapshot_add, &h_snapshot_add); cls_register_cxx_method(h_class, "snap_revert", CLS_METHOD_RD | CLS_METHOD_WR, snapshot_revert, &h_snapshot_revert); + /* assign a unique block id for rbd blocks */ + cls_register_cxx_method(h_class, "assign_bid", CLS_METHOD_RD | CLS_METHOD_WR, rbd_assign_bid, &h_assign_bid); + return; } |