]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_file: refuse ops on deleted targets
authorMatt Benjamin <mbenjamin@redhat.com>
Wed, 3 Aug 2016 17:53:15 +0000 (13:53 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Wed, 5 Oct 2016 17:14:53 +0000 (13:14 -0400)
Detect these illegal cases, as they are indicate various incorrect
behaviors/bugs.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
(cherry picked from commit 34224ecd8360e03603a1a5dd1c1c9f0a31f1c1d5)

src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index 66e98a56fe1274bd842780ce3252c3065eb9b086..525062cdb12a97c5b3a8271ec84b6c9f14f37326 100644 (file)
@@ -196,6 +196,9 @@ namespace rgw {
     if (! rgw_fh->is_file())
       return -EINVAL;
 
+    if (rgw_fh->deleted())
+      return -ESTALE;
+
     RGWReadRequest req(get_context(), get_user(), rgw_fh, offset, length,
                       buffer);
 
@@ -286,6 +289,15 @@ namespace rgw {
     LookupFHResult fhr = lookup_fh(src_fh, _src_name, RGWFileHandle::FLAG_LOCK);
     RGWFileHandle* rgw_fh = get<0>(fhr);
 
+    /* should not happen */
+    if (! rgw_fh) {
+      ldout(get_context(), 0) << __func__
+                      << " BUG no such src renaming path="
+                      << rgw_fh->full_object_name()
+                      << dendl;
+      goto out;
+    }
+
     for (int ix : {0, 1}) {
       switch (ix) {
       case 0:
@@ -468,8 +480,11 @@ namespace rgw {
   {
     switch(rgw_fh->fh.fh_type) {
     case RGW_FS_TYPE_FILE:
-      break;
-    case RGW_FS_TYPE_DIRECTORY:
+    {
+      if (rgw_fh->deleted())
+       return -ESTALE;
+    }
+    break;
     default:
       break;
     };
@@ -482,6 +497,18 @@ namespace rgw {
   {
     int rc, rc2;
     buffer::list ux_key, ux_attrs;
+
+    switch(rgw_fh->fh.fh_type) {
+    case RGW_FS_TYPE_FILE:
+    {
+      if (rgw_fh->deleted())
+       return -ESTALE;
+    }
+    break;
+    default:
+      break;
+    };
+
     string obj_name{rgw_fh->relative_object_name()};
 
     RGWSetAttrsRequest req(cct, get_user(), rgw_fh->bucket_name(), obj_name);
@@ -663,6 +690,20 @@ namespace rgw {
     if (! f)
       return -EISDIR;
 
+    if (deleted()) {
+      lsubdout(fs->get_context(), rgw, 5)
+       << __func__
+       << " write attempted on deleted object "
+       << this->object_name()
+       << dendl;
+      /* zap write transaction, if any */
+      if (f->write_req) {
+       delete f->write_req;
+       f->write_req = nullptr;
+      }
+      return -ESTALE;
+    }
+
     if (! f->write_req) {
       /* guard--we do not support (e.g., COW-backed) partial writes */
       if (off != 0) {
@@ -1373,6 +1414,9 @@ int rgw_readv(struct rgw_fs *rgw_fs,
 int rgw_writev(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
              rgw_uio *uio, uint32_t flags)
 {
+
+  return -ENOTSUP;
+
   CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw);
   RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
index 06a0fd99c5ee9bc59b6bf594703e129dd2f571bf..bda495986d4e9483e91f7117cc844ec6024551e5 100644 (file)
@@ -488,6 +488,7 @@ namespace rgw {
     bool is_file() const { return (fh.fh_type == RGW_FS_TYPE_FILE); }
     bool is_dir() const { return (fh.fh_type == RGW_FS_TYPE_DIRECTORY); }
     bool creating() const { return flags & FLAG_CREATING; }
+    bool deleted() const { return flags & FLAG_DELETED; }
 
     uint32_t open(uint32_t gsh_flags) {
       lock_guard guard(mtx);