diff options
author | Yehuda Sadeh <yehuda@hq.newdream.net> | 2011-09-20 11:56:46 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@hq.newdream.net> | 2011-09-20 11:56:46 -0700 |
commit | 73bc7713ad7b2ea85e5868c2132362b28d6a164e (patch) | |
tree | ece23bb59effa884b4cb6ef729ed1148ceb81902 /src/cls_rgw.cc | |
parent | 741990ccfbf7d46335ecf34875e90118d46100cc (diff) | |
download | ceph-73bc7713ad7b2ea85e5868c2132362b28d6a164e.tar.gz |
rgw: make cls_rgw compile
Diffstat (limited to 'src/cls_rgw.cc')
-rw-r--r-- | src/cls_rgw.cc | 88 |
1 files changed, 66 insertions, 22 deletions
diff --git a/src/cls_rgw.cc b/src/cls_rgw.cc index f89b702fde2..616d6d7db3d 100644 --- a/src/cls_rgw.cc +++ b/src/cls_rgw.cc @@ -2,11 +2,13 @@ #include <iostream> + #include <string.h> #include <stdlib.h> #include <errno.h> #include "include/types.h" +#include "include/utime.h" #include "objclass/objclass.h" CLS_VER(1,0) @@ -14,26 +16,68 @@ CLS_NAME(rgw) cls_handle_t h_class; cls_method_handle_t h_rgw_bucket_list; -cls_method_handle_t h_rgw_bucket_add; -cls_method_handle_t h_rgw_bucket_del; -cls_method_handle_t h_rgw_bucket_info; +cls_method_handle_t h_rgw_bucket_modify; struct rgw_bucket_dir_entry { - uint64_t epoch; - string name; + std::string name; uint64_t size; utime_t mtime; + uint64_t epoch; + + void encode(bufferlist &bl) const { + __u8 struct_v = 1; + ::encode(struct_v, bl); + ::encode(name, bl); + ::encode(mtime, bl); + ::encode(epoch, bl); + } + void decode(bufferlist::iterator &bl) { + __u8 struct_v; + ::decode(struct_v, bl); + ::decode(name, bl); + ::decode(mtime, bl); + ::decode(epoch, bl); + } }; +WRITE_CLASS_ENCODER(rgw_bucket_dir_entry) struct rgw_bucket_dir_header { uint64_t total_size; uint64_t num_entries; + + void encode(bufferlist &bl) const { + __u8 struct_v = 1; + ::encode(struct_v, bl); + ::encode(total_size, bl); + ::encode(num_entries, bl); + } + void decode(bufferlist::iterator &bl) { + __u8 struct_v; + ::decode(struct_v, bl); + ::decode(total_size, bl); + ::decode(num_entries, bl); + } }; +WRITE_CLASS_ENCODER(rgw_bucket_dir_header) struct rgw_bucket_dir { struct rgw_bucket_dir_header header; - map<string, struct rgw_bucket_dir_entry> m; + std::map<string, struct rgw_bucket_dir_entry> m; + + void encode(bufferlist &bl) const { + __u8 struct_v = 1; + ::encode(struct_v, bl); + ::encode(header, bl); + ::encode(m, bl); + } + void decode(bufferlist::iterator &bl) { + __u8 struct_v; + ::decode(struct_v, bl); + ::decode(header, bl); + ::decode(m, bl); + } }; +WRITE_CLASS_ENCODER(rgw_bucket_dir) enum modify_op { CLS_RGW_OP_ADD = 0, @@ -45,7 +89,7 @@ static int read_bucket_dir(cls_method_context_t hctx, struct rgw_bucket_dir& dir bufferlist bl; bufferlist::iterator iter; - rc = cls_cxx_read(hctx, 0, (uint64_t)-1, &bl); + int rc = cls_cxx_read(hctx, 0, 0, &bl); if (rc < 0) return rc; @@ -73,8 +117,8 @@ static int write_bucket_dir(cls_method_context_t hctx, struct rgw_bucket_dir& di int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { bufferlist bl; - struct rbd_bucket_dir dir; - int rc = read_bucket_dir(hctx, header); + struct rgw_bucket_dir dir; + int rc = read_bucket_dir(hctx, dir); if (rc < 0) return rc; @@ -90,13 +134,13 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out) return -EINVAL; } - struct rbd_bucket_dir new_dir; + struct rgw_bucket_dir new_dir; new_dir.header = dir.header; - map<string, struct rgw_bucket_dir_entry>& m = new_dir.m; - map<string, struct rgw_bucket_dir_entry>::iterator miter; + std::map<string, struct rgw_bucket_dir_entry>& m = new_dir.m; + std::map<string, struct rgw_bucket_dir_entry>::iterator miter; uint32_t i; for (i = 0, miter = dir.m.begin(); i !=num_entries && miter != dir.m.end(); ++i, ++miter) { - m.insert(miter); + m[miter->first] = miter->second; } ::encode(new_dir, *out); @@ -106,14 +150,14 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out) int rgw_bucket_modify(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { bufferlist bl; - struct rbd_bucket_dir dir; + struct rgw_bucket_dir dir; int rc = read_bucket_dir(hctx, dir); if (rc < 0) return rc; uint8_t op; uint64_t epoch; - struct rbd_bucket_dir_entry entry; + struct rgw_bucket_dir_entry entry; bufferlist::iterator iter = in->begin(); try { @@ -126,7 +170,7 @@ int rgw_bucket_modify(cls_method_context_t hctx, bufferlist *in, bufferlist *out } CLS_LOG("rgw_bucket_modify(): request: op=%d name=%s epoch=%lld\n", op, entry.name.c_str(), epoch); - map<string, struct rgw_bucket_dir_entry>::iterator miter = dir.m.find(entry.name); + std::map<string, struct rgw_bucket_dir_entry>::iterator miter = dir.m.find(entry.name); if (miter != dir.m.end()) { CLS_LOG("rgw_bucket_modify(): existing entry: epoch=%lld\n", entry.epoch); @@ -137,14 +181,14 @@ int rgw_bucket_modify(cls_method_context_t hctx, bufferlist *in, bufferlist *out } switch (op) { - case RGW_OP_DEL: + case CLS_RGW_OP_DEL: if (miter != dir.m.end()) - dir.erase(miter); + dir.m.erase(miter); else return -ENOENT; break; - case RGW_OP_ADD: - dir[entry.name] = entry; + case CLS_RGW_OP_ADD: + dir.m[entry.name] = entry; break; } @@ -158,8 +202,8 @@ void __cls_init() CLS_LOG("Loaded rgw class!"); cls_register("rgw", &h_class); - cls_register_cxx_method(h_class, "rgw_bucket_list", CLS_METHOD_RD | CLS_METHOD_PUBLIC, snapshots_list, &h_snapshots_list); - cls_register_cxx_method(h_class, "rgw_bucket_modify", CLS_METHOD_RD | CLS_METHOD_WR | CLS_METHOD_PUBLIC, snapshot_add, &h_snapshot_add); + cls_register_cxx_method(h_class, "rgw_bucket_list", CLS_METHOD_RD | CLS_METHOD_PUBLIC, rgw_bucket_list, &h_rgw_bucket_list); + cls_register_cxx_method(h_class, "rgw_bucket_modify", CLS_METHOD_RD | CLS_METHOD_WR | CLS_METHOD_PUBLIC, rgw_bucket_modify, &h_rgw_bucket_modify); return; } |