]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix error handling for GET with ?torrent 21576/head
authorCasey Bodley <cbodley@redhat.com>
Fri, 20 Apr 2018 20:12:18 +0000 (16:12 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 20 Apr 2018 20:18:17 +0000 (16:18 -0400)
GET requests with ?torrent should never be treated as a normal GET
request. if rgw_torrent_flag wasn't true when the object was uploaded,
we'll detect the lack of torrent data when reading from omap

conversely, if rgw_torrent_flag was true during upload but disabled
afterwards, we can still return the torrent data

Fixes: http://tracker.ceph.com/issues/23506
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/common/options.cc
src/rgw/rgw_op.cc
src/rgw/rgw_rest.cc
src/rgw/rgw_torrent.cc

index 8153d889673716133ac9d0c9e26f8505a0d001ff..9b60b6f715d8095edcd733e088dd9430f05ed375 100644 (file)
@@ -6054,7 +6054,9 @@ std::vector<Option> get_rgw_options() {
 
     Option("rgw_torrent_flag", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
     .set_default(false)
-    .set_description("Produce torrent function flag"),
+    .set_description("When true, uploaded objects will calculate and store "
+                     "a SHA256 hash of object data so the object can be "
+                     "retrieved as a torrent file"),
 
     Option("rgw_torrent_tracker", Option::TYPE_STR, Option::LEVEL_ADVANCED)
     .set_default("")
index 4537680af1af6eb7df22df53dba38f5740b333de..3b77eff5265da5987b5163fa909825ee46f8e9ee 100644 (file)
@@ -1763,7 +1763,9 @@ void RGWGetObj::execute()
   {
     attr_iter = attrs.find(RGW_ATTR_CRYPT_MODE);
     if (attr_iter != attrs.end() && attr_iter->second.to_str() == "SSE-C-AES256") {
-      op_ret = -ERR_INVALID_REQUEST;
+      ldout(s->cct, 0) << "ERROR: torrents are not supported for objects "
+          "encrypted with SSE-C" << dendl;
+      op_ret = -EINVAL;
       goto done_err;
     }
     torrent.init(s, store);
index 6f63517c4a5f9152ef5a000a37c7baf7dc2fe0d0..302c834565c8bd23ef4024b9e7bb335fe8bad9ad 100644 (file)
@@ -812,20 +812,9 @@ int RGWGetObj_ObjStore::get_params()
     get_data &= (!rgwx_stat);
   }
 
-  /* start gettorrent */
-  bool is_torrent = s->info.args.exists(GET_TORRENT);
-  bool torrent_flag = s->cct->_conf->rgw_torrent_flag;
-  if (torrent_flag && is_torrent)
-  {
-    int ret = 0;
-    ret = torrent.get_params();
-    if (ret < 0)
-    {
-      return ret;
-    }
+  if (s->info.args.exists(GET_TORRENT)) {
+    return torrent.get_params();
   }
-  /* end gettorrent */
-
   return 0;
 }
 
index 1ba9595b1e0298e9d8037e04542d1e79efd98ca3..42ae400f5a953347b48a07ca8a3a1dff039254f6 100644 (file)
@@ -58,27 +58,21 @@ int seed::get_torrent_file(RGWRados::Object::Read &read_op,
   }
 
   string oid, key;
-  map<string, bufferlist> m;
-  set<string> obj_key;
   get_obj_bucket_and_oid_loc(obj, oid, key);
-  ldout(s->cct, 0) << "NOTICE: head obj oid= " << oid << dendl;
+  ldout(s->cct, 20) << "NOTICE: head obj oid= " << oid << dendl;
 
-  obj_key.insert(RGW_OBJ_TORRENT);
-  const int op_ret = read_op.state.io_ctx.omap_get_vals_by_keys(oid, obj_key, &m);
-  if (op_ret < 0)
-  {
-    ldout(s->cct, 0) << "ERROR: failed to omap_get_vals_by_keys op_ret = "
-                     << op_ret << dendl;
-    return op_ret;
+  const set<string> obj_key{RGW_OBJ_TORRENT};
+  map<string, bufferlist> m;
+  const int r = read_op.state.io_ctx.omap_get_vals_by_keys(oid, obj_key, &m);
+  if (r < 0) {
+    ldout(s->cct, 0) << "ERROR: omap_get_vals_by_keys failed: " << r << dendl;
+    return r;
   }
-
-  map<string, bufferlist>::iterator iter;
-  for (iter = m.begin(); iter != m.end(); ++iter)
-  {
-    bufferlist bl_tmp = iter->second;
-    char *pbuff = bl_tmp.c_str();
-    bl.append(pbuff, bl_tmp.length());
+  if (m.size() != 1) {
+    ldout(s->cct, 0) << "ERROR: omap key " RGW_OBJ_TORRENT " not found" << dendl;
+    return -EINVAL;
   }
+  bl.append(std::move(m.begin()->second));
   dencode.bencode_end(bl);
 
   bl_data = bl;