]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: add rgw_getattr tests
authorMatt Benjamin <mbenjamin@redhat.com>
Mon, 11 Jan 2016 21:50:01 +0000 (16:50 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:07:53 +0000 (12:07 -0500)
Re-implement rgw_getattr to just dispatch into RGWFileHandle::stat,
we expect all objects to stat correctly for their type.

The size of file objects is currently reporting as 0, where we expect
a small, positive size (reviewing).

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

index a0c0414e33a3646701e6e0d87b4f6f79c7be2d9f..9d38e644ca35facf89b93c3a50fce0bb368e82b1 100644 (file)
@@ -955,46 +955,8 @@ int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
 int rgw_getattr(struct rgw_fs *rgw_fs,
                struct rgw_file_handle *fh, struct stat *st, uint32_t flags)
 {
-  CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw);
-  RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
-
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
-
-  if (rgw_fh->is_root() ||
-      rgw_fh->is_bucket()) {
-    /* XXX nothing */
-  } else {
-    /* object */
-
-    /* an object being created isn't expected to exist (if it does,
-     * we'll detect the conflict later */
-    if (rgw_fh->creating())
-      goto done;
-
-    const std::string& bname = rgw_fh->bucket_name();
-    const std::string& oname = rgw_fh->object_name();
-
-    RGWStatObjRequest req(cct, fs->get_user(), bname, oname,
-                         RGWStatObjRequest::FLAG_NONE);
-
-    int rc = rgwlib.get_fe()->execute_req(&req);
-    if ((rc != 0) ||
-       (req.get_ret() != 0)) {
-      /* XXX EINVAL is likely illegal protocol return--if the object
-       * should but doesn't exist, it should probably be ENOENT */
-      return -EINVAL;
-    }
-
-    /* fill in stat data */
-    rgw_fh->set_size(req.size());
-    rgw_fh->set_ctime({req.ctime(), 0});
-    rgw_fh->set_mtime({req.mtime(), 0});
-    rgw_fh->set_atime({req.mtime(), 0});
-  }
-
-done:
-  (void) rgw_fh->stat(st);
-  return 0;
+  return -(rgw_fh->stat(st));
 }
 
 /*
index f9a6f24d07ba86d44d4cacb4235ce25f4790ad29..88ec5c60d705b3f599e41a0687f64044c702ea1d 100644 (file)
@@ -95,6 +95,40 @@ namespace {
 
   dirs1_vec dirs_vec;
 
+  struct obj_rec_st
+  {
+    const obj_rec& obj;
+    const struct stat& st;
+
+    obj_rec_st(const obj_rec& _obj, const struct stat& _st)
+      : obj(_obj), st(_st) {}
+  };
+
+  ostream& operator<<(ostream& os, const obj_rec_st& rec)
+  {
+    RGWFileHandle* rgw_fh = rec.obj.rgw_fh;
+    if (rgw_fh) {
+      const char* type = rgw_fh->is_dir() ? "DIR " : "FILE ";
+      os << rgw_fh->full_object_name()
+        << " (" << rgw_fh->object_name() << "): "
+        << type;
+      const struct stat& st = rec.st;
+      switch(uint8_t(rgw_fh->is_dir())) {
+      case 1:
+       os << " mode: " << st.st_mode;
+       os << " nlinks: " << st.st_nlink;
+       break;
+      case 0:
+      default:
+       os << " mode: " << st.st_mode;
+       os << " size: " << st.st_size;
+       // xxx
+       break;
+      }
+    }
+    return os;
+  }
+
   bool do_hier1 = false;
   bool do_dirs1 = false;
   bool do_marker1 = false;
@@ -304,19 +338,25 @@ TEST(LibRGW, SETUP_DIRS1) {
 TEST(LibRGW, RGW_CREATE_DIRS1) {
   /* verify rgw_create (create [empty] file objects the easy way) */
   if (do_dirs1) {
-    int rc;
-    struct stat st;
-    for (auto& dirs_rec : dirs_vec) {
-      /* create 1 more file in each sdir */
-      obj_rec& dir = get<0>(dirs_rec);
-      std::string sfname{"sfile_" + to_string(n_dirs1_objs)};
-      obj_rec sf{sfname, nullptr, dir.fh, nullptr};
-      rc = rgw_create(fs, sf.parent_fh, sf.name.c_str(), 644, &st, &sf.fh,
-                     RGW_CREATE_FLAG_NONE);
-      ASSERT_EQ(rc, 0);
-      sf.sync();
+    if (do_create) {
+      int rc;
+      struct stat st;
+      for (auto& dirs_rec : dirs_vec) {
+       /* create 1 more file in each sdir */
+       obj_rec& dir = get<0>(dirs_rec);
+       std::string sfname{"sfile_" + to_string(n_dirs1_objs)};
+       obj_rec sf{sfname, nullptr, dir.fh, nullptr};
+       (void) rgw_lookup(fs, sf.parent_fh, sf.name.c_str(), &sf.fh,
+                         RGW_LOOKUP_FLAG_NONE);
+       if (! sf.fh) {
+         rc = rgw_create(fs, sf.parent_fh, sf.name.c_str(), 644, &st, &sf.fh,
+                         RGW_CREATE_FLAG_NONE);
+         ASSERT_EQ(rc, 0);
+       }
+       sf.sync();
+      }
+      n_dirs1_objs++;
     }
-    n_dirs1_objs++;
   }
 }
 
@@ -346,7 +386,37 @@ TEST(LibRGW, BAD_DELETES_DIRS1) {
 
 TEST(LibRGW, GETATTR_DIRS1)
 {
-
+  if (do_dirs1) {
+    int rc;
+    struct stat st;
+    for (auto& dirs_rec : dirs_vec) {
+      obj_rec& dir = get<0>(dirs_rec);
+      if (verbose) {
+       std::cout << "scanning objects in "
+                 << dir.rgw_fh->full_object_name()
+                 << std::endl;
+      }
+      for (auto& sobj : get<1>(dirs_rec)) {
+       rc = rgw_getattr(fs, sobj.fh, &st, RGW_GETATTR_FLAG_NONE);
+       ASSERT_EQ(rc, 0);
+       /* validate, pretty-print */
+       if (sobj.rgw_fh->object_name().find("sfile") != std::string::npos) {
+         ASSERT_TRUE(sobj.rgw_fh->is_file());
+         ASSERT_TRUE(S_ISREG(st.st_mode));
+       }
+       if (sobj.rgw_fh->object_name().find("sdir") != std::string::npos) {
+         ASSERT_TRUE(sobj.rgw_fh->is_dir());
+         ASSERT_TRUE(S_ISDIR(st.st_mode));
+       }
+       if (verbose) {
+         obj_rec_st rec_st{sobj, st};
+         std::cout << "\t"
+                   << rec_st
+                   << std::endl;
+       }
+      }
+    }
+  }
 }
 
 TEST(LibRGW, RELEASE_DIRS1) {