]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librgw: rgw_getattr refactor, RGWLibFS::stat_leaf (object)
authorMatt Benjamin <mbenjamin@redhat.com>
Tue, 12 Jan 2016 01:57:14 +0000 (20:57 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:07:55 +0000 (12:07 -0500)
Rewrite rgw_getattr to just dispatch into RGWLibFS::getattr, where
we can better use RGWFileHandle and RGWLibFS internals.

Initially, this change intended to dispatch a new RGWStatObjRequest
in the file case, but during implementation, discovered that in
(apparently) all file cases, it has already been done--but the path
had stopped working with the naming change.

Current GETATTR_DIRS1 unit test, when repeated so relying on lookup
(rather than saving size after rgw_write/rgw_close), passes.

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

index 6a11e22ef0d27ec2e12e695ecb391f401a13b15d..60d1afbcbc0189775a1bcac66fbf24460d02e657 100644 (file)
@@ -88,8 +88,12 @@ namespace rgw {
       switch (ix) {
       case 0:
       {
+       std::string obj_name{parent->relative_object_name()};
+       if (obj_name.back() != '/')
+         obj_name += "/";
+       obj_name += path;
        RGWStatObjRequest req(cct, get_user(),
-                             parent->bucket_name(), object_name,
+                             parent->bucket_name(), obj_name,
                              RGWStatObjRequest::FLAG_NONE);
        int rc = rgwlib.get_fe()->execute_req(&req);
        if ((rc == 0) &&
@@ -97,6 +101,7 @@ namespace rgw {
          fhr = lookup_fh(parent, path, RGWFileHandle::FLAG_NONE);
          if (get<0>(fhr)) {
            RGWFileHandle* rgw_fh = get<0>(fhr);
+           rgw_fh->set_size(req.get_size());
            rgw_fh->set_mtime({req.get_mtime(), 0});
          }
          goto done;
@@ -137,6 +142,19 @@ namespace rgw {
     return fhr;
   } /* RGWLibFS::stat_leaf */
 
+  int RGWLibFS::getattr(RGWFileHandle* rgw_fh, struct stat* st)
+  {
+    switch(rgw_fh->fh.fh_type) {
+    case RGW_FS_TYPE_FILE:
+      break;
+    case RGW_FS_TYPE_DIRECTORY:
+    default:
+      break;
+    };
+
+    return rgw_fh->stat(st);;
+  } /* RGWLibFS::getattr */
+
   void RGWLibFS::close()
   {
     state.flags |= FLAG_CLOSED;
@@ -955,8 +973,10 @@ 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)
 {
+  RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
-  return -(rgw_fh->stat(st));
+
+  return -(fs->getattr(rgw_fh, st));
 }
 
 /*
index bacd9463ef436ba2a6f57808e1b764bd6357d4c1..aac73446085ca9a5062747551c6287390332ea69 100644 (file)
@@ -724,6 +724,8 @@ namespace rgw {
       return fh;
     }
 
+    int getattr(RGWFileHandle* rgw_fh, struct stat* st);
+
     LookupFHResult stat_bucket(RGWFileHandle* parent,
                               const char *path, uint32_t flags);
 
@@ -1374,7 +1376,7 @@ public:
     return 0;
   }
 
-}; /* RGWGetObjRequest */
+}; /* RGWReadRequest */
 
 /*
   delete object
@@ -1466,7 +1468,7 @@ public:
   }
 
   /* attributes */
-  uint64_t size() { return _size; }
+  uint64_t get_size() { return _size; }
   time_t ctime() { return mod_time; } // XXX
   time_t mtime() { return mod_time; }
   map<string, bufferlist>& get_attrs() { return attrs; }
@@ -1491,10 +1493,9 @@ public:
     s->op = OP_GET;
 
     /* XXX derp derp derp */
-    std::string uri = make_uri(bucket_name, obj_name);
-    s->relative_uri = uri;
-    s->info.request_uri = uri; // XXX
-    s->info.effective_uri = uri;
+    s->relative_uri = make_uri(bucket_name, obj_name);
+    s->info.request_uri = s->relative_uri; // XXX
+    s->info.effective_uri = s->relative_uri;
     s->info.request_params = "";
     s->info.domain = ""; /* XXX ? */
 
index ff4ddbddc4f052c90ea63bb983c3d173f0538836..b24f1435cf95f5eceb52ab054cbb635e9030f851 100644 (file)
@@ -439,6 +439,7 @@ TEST(LibRGW, READ_DIRS1)
            (sobj.rgw_fh->object_name().find("sfile_1")
             != std::string::npos)) {
          ASSERT_TRUE(sobj.rgw_fh->is_file());
+         ASSERT_EQ(sobj.rgw_fh->get_size(), 16UL);
          // do it
          memset(buf, 0, 256);
          rc = rgw_read(fs, sobj.fh, 0, 256, &nread, buf, RGW_READ_FLAG_NONE);