]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: move readdir operations into RGWFileHandle::readdir
authorMatt Benjamin <mbenjamin@redhat.com>
Tue, 22 Dec 2015 21:01:19 +0000 (16:01 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:07:16 +0000 (12:07 -0500)
The motivation here is to localize state updates to the class,
e.g., to hide consistency logic.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index 4dbb365593604176cabf1d829a257009761df8b6..c4aa8b646afaae92a69e1ba1f6b30f8cfcd9b2f9 100644 (file)
@@ -155,6 +155,35 @@ namespace rgw {
     return true;
   } /* RGWFileHandle::reclaim */
 
+  int RGWFileHandle::readdir(rgw_readdir_cb rcb, void *cb_arg, uint64_t *offset,
+                            bool *eof)
+  {
+    int rc = 0;
+    CephContext* cct = fs->get_context();
+    if (is_root()) {
+      RGWListBucketsRequest req(cct, fs->get_user(), this, rcb, cb_arg,
+                               offset);
+      rc = librgw.get_fe()->execute_req(&req);
+      if (! rc) {
+       lock_guard guard(mtx);
+       (void) clock_gettime(CLOCK_MONOTONIC_COARSE, &state.atime);
+       *eof = req.eof();
+      }
+    } else {
+      // XXX finish marker handling
+      rgw_obj_key marker{"", ""};
+      RGWReaddirRequest req(cct, fs->get_user(), this, rcb, cb_arg, offset);
+      rc = librgw.get_fe()->execute_req(&req);
+      if (! rc) {
+       lock_guard guard(mtx);
+       /* XXX update link count (incorrectly) */
+       parent->set_nlink(3 + *offset);
+       *eof = req.eof();
+      }
+    }
+    return rc;
+  } /* RGWFileHandle::readdir */
+
   int RGWFileHandle::write(uint64_t off, size_t len, size_t *bytes_written,
                           void *buffer)
   {
@@ -867,39 +896,13 @@ int rgw_readdir(struct rgw_fs *rgw_fs,
                struct rgw_file_handle *parent_fh, uint64_t *offset,
                rgw_readdir_cb rcb, void *cb_arg, bool *eof)
 {
-  int rc;
-
-  RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
-  CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw);
-
-  /* TODO:
-   * deal with markers (continuation)
-   * deal with authorization
-   * consider non-default tenancy/user and bucket layouts
-   */
   RGWFileHandle* parent = get_rgwfh(parent_fh);
   if (! parent) {
     /* bad parent */
     return -EINVAL;
   }
-
-  if (parent->is_root()) {
-    RGWListBucketsRequest req(cct, fs->get_user(), parent, rcb, cb_arg, offset);
-    rc = librgw.get_fe()->execute_req(&req);
-  } else {
-    // XXX finish marker handling
-    rgw_obj_key marker{"", ""};
-    RGWReaddirRequest req(cct, fs->get_user(), parent, rcb, cb_arg, offset);
-    rc = librgw.get_fe()->execute_req(&req);
-
-    /* XXX update link count (incorrectly) */
-    parent->set_nlink(3 + *offset);
-  }
-
-  /* XXXX request MUST set this */
-  *eof = true; // XXX move into RGGWListBucket(s)Request
-
-  return rc;
+  int rc = parent->readdir(rcb, cb_arg, offset, eof);
+  return -rc;
 }
 
 /*
index d4eb03673ddac2a6a5fed9b73103c28518432ae7..87cbfbf43099ee4e921c4666a7d1c7b4e0601295 100644 (file)
@@ -404,6 +404,7 @@ namespace rgw {
       return EPERM;
     }
 
+    int readdir(rgw_readdir_cb rcb, void *cb_arg, uint64_t *offset, bool *eof);
     int write(uint64_t off, size_t len, size_t *nbytes, void *buffer);
     int write_finish();
     int close();