]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: obj listing doesn't stat object
authorYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 22 Sep 2011 00:27:47 +0000 (17:27 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 22 Sep 2011 00:27:47 +0000 (17:27 -0700)
src/cls_rgw.cc
src/rgw/rgw_cls_api.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 83cfe390437f6f3a643cfd3a4efd063260a560ac..39125a56caa1a66730d25915422f89adbc546e9f 100644 (file)
@@ -88,6 +88,9 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
   for (i = 0; i != op.num_entries && miter != dir.m.end(); ++i, ++miter) {
     m[miter->first] = miter->second;
   }
+
+  ret.is_truncated = (miter != dir.m.end());
+
   ::encode(ret, *out);
 
   return 0;
index 4c53da338ed8cefb9fa44bf6d56275ab68b4bd03..ce89361d0dda734450837bcdd81d5756850ed3a7 100644 (file)
@@ -142,16 +142,19 @@ WRITE_CLASS_ENCODER(rgw_cls_list_op)
 struct rgw_cls_list_ret
 {
   rgw_bucket_dir dir;
+  bool is_truncated;
 
   void encode(bufferlist &bl) const {
     __u8 struct_v = 1;
     ::encode(struct_v, bl);
     ::encode(dir, bl);
+    ::encode(is_truncated, bl);
   }
   void decode(bufferlist::iterator &bl) {
     __u8 struct_v;
     ::decode(struct_v, bl);
     ::decode(dir, bl);
+    ::decode(is_truncated, bl);
   }
 };
 WRITE_CLASS_ENCODER(rgw_cls_list_ret)
index b1c818f8e488bdb39592b3731c525223308232ff..d16f08ad57c18adeed98678995688179daa55fdb 100644 (file)
@@ -247,40 +247,14 @@ int RGWRados::list_objects(string& id, rgw_bucket& bucket, int max, string& pref
     bucket_marker.append("_");
   }
 
-  std::map<string, string> dir_map;
-#if 0
-  {
-    librados::ObjectIterator i_end = io_ctx.objects_end();
-    for (librados::ObjectIterator i = io_ctx.objects_begin(); i != i_end; ++i) {
-        string obj = *i;
-        string key = obj;
-
-        if (bucket_marker.size()) {
-          if (obj.compare(0, bucket_marker.size(), bucket_marker) != 0)
-            continue;
-
-          obj = obj.substr(bucket_marker.size());
-          key = obj;
-        }
-
-        if (!rgw_obj::translate_raw_obj(obj, ns))
-          continue;
-
-        if (filter && !filter->filter(obj, key))
-          continue;
-
-       if (prefix.empty() ||
-           ((obj).compare(0, prefix.size(), prefix) == 0)) {
-         dir_map[obj] = key;
-       }
-    }
-  }
-#endif
+  std::map<string, RGWObjEnt> dir_map;
   std::map<string, RGWObjEnt> ent_map;
-  r = cls_bucket_list(bucket, marker, max, ent_map);
+  r = cls_bucket_list(bucket, marker, max, ent_map, is_truncated);
   if (r < 0)
     return r;
 
+  result.clear();
+
   std::map<string, RGWObjEnt>::iterator eiter;
   for (eiter = ent_map.begin(); eiter != ent_map.end(); ++eiter) {
     string obj = eiter->first;
@@ -293,89 +267,9 @@ int RGWRados::list_objects(string& id, rgw_bucket& bucket, int max, string& pref
       continue;
 
     if (prefix.empty() || ((obj).compare(0, prefix.size(), prefix) == 0)) {
-      dir_map[obj] = key;
-    }
-  }
-
-  std::map<string, string>::iterator p;
-  if (!marker.empty())
-    p = dir_map.upper_bound(marker);
-  else
-    p = dir_map.begin();
-
-  if (max < 0) {
-    max = dir_map.size();
-  }
-
-  result.clear();
-  int i;
-  for (i=0; i<max && p != dir_map.end(); i++, ++p) {
-    RGWObjEnt obj;
-    string name = p->first;
-    string key = p->second;
-    obj.name = name;
-
-    if (!delim.empty()) {
-      int delim_pos = name.find(delim, prefix.size());
-
-      if (delim_pos >= 0) {
-        common_prefixes[name.substr(0, delim_pos + 1)] = true;
-        continue;
-      }
+      result.push_back(eiter->second);
     }
-    string oid = name;
-    if (!ns.empty()) {
-      oid = "_";
-      oid.append(ns);
-      oid.append("_");
-      oid.append(name);
-    }
-
-    string new_oid;
-    prepend_bucket_marker(bucket, oid, new_oid);
-
-    uint64_t s;
-    io_ctx.locator_set_key(key);
-
-    if (io_ctx.stat(new_oid, &s, &obj.mtime) < 0)
-      continue;
-    obj.size = s;
-
-    obj.etag[0] = '\0';
-    map<string, bufferlist> attrset;
-    if (io_ctx.getxattrs(oid, attrset) >= 0) {
-      map<string, bufferlist>::iterator iter = attrset.find(RGW_ATTR_ETAG);
-      if (iter != attrset.end()) {
-        bufferlist& bl = iter->second;
-        obj.etag = bl.c_str();
-      }
-      iter = attrset.find(RGW_ATTR_ACL);
-      if (iter != attrset.end()) {
-        bufferlist& bl = iter->second;
-        bufferlist::iterator i = bl.begin();
-        RGWAccessControlPolicy policy;
-        try {
-          policy.decode_owner(i);
-        } catch (buffer::error& err) {
-          RGW_LOG(0) << "ERROR: could not decode policy for oid=" << oid << ", caught buffer::error" << dendl;
-          continue;
-        }
-        ACLOwner& owner = policy.get_owner();
-        obj.owner = owner.get_id();
-        obj.owner_display_name = owner.get_display_name();
-      }
-    }
-    bufferlist bl;
-    if (get_content_type) {
-      obj.content_type = "";
-      if (io_ctx.getxattr(oid, RGW_ATTR_CONTENT_TYPE, bl) >= 0) {
-        obj.content_type = bl.c_str();
-      }
-    }
-    result.push_back(obj);
   }
-  if (is_truncated)
-    *is_truncated = (p != dir_map.end());
 
   return 0;
 }
@@ -1920,7 +1814,7 @@ int RGWRados::cls_obj_del(rgw_bucket& bucket, uint64_t epoch, string& name)
   return cls_obj_op(bucket, CLS_RGW_OP_DEL, epoch, ent, 0);
 }
 
-int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, map<string, RGWObjEnt>& m)
+int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, map<string, RGWObjEnt>& m, bool *is_truncated)
 {
   librados::IoCtx io_ctx;
   int r = open_bucket_ctx(bucket, io_ctx);
@@ -1953,6 +1847,9 @@ int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, ma
     return -EIO;
   }
 
+  if (is_truncated)
+    *is_truncated = ret.is_truncated;
+
   struct rgw_bucket_dir& dir = ret.dir;
   map<string, struct rgw_bucket_dir_entry>::iterator miter;
   for (miter = dir.m.begin(); miter != dir.m.end(); ++miter) {
index 4f37ff316f2e70cbdb04c33c1e314d86224cc2e5..b0578a9c98d3575f8b85f676b12661ffdfa0d361 100644 (file)
@@ -284,7 +284,7 @@ public:
                  RGWObjEnt& ent, uint8_t category);
   int cls_obj_add(rgw_bucket& bucket, uint64_t epoch, RGWObjEnt& ent, uint8_t category);
   int cls_obj_del(rgw_bucket& bucket, uint64_t epoch, string& name);
-  int cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, map<string, RGWObjEnt>& m);
+  int cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, map<string, RGWObjEnt>& m, bool *is_truncated);
 };
 
 #endif