From: Matt Benjamin Date: Tue, 12 Jan 2016 01:57:14 +0000 (-0500) Subject: librgw: rgw_getattr refactor, RGWLibFS::stat_leaf (object) X-Git-Tag: v10.1.0~382^2~39 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=441bff73c282af4c7fbeb21fdfdd6ef35bdfbd08;p=ceph-ci.git librgw: rgw_getattr refactor, RGWLibFS::stat_leaf (object) 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 --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 6a11e22ef0d..60d1afbcbc0 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -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(rgw_fs->fs_private); RGWFileHandle* rgw_fh = get_rgwfh(fh); - return -(rgw_fh->stat(st)); + + return -(fs->getattr(rgw_fh, st)); } /* diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index bacd9463ef4..aac73446085 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -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& 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 ? */ diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc index ff4ddbddc4f..b24f1435cf9 100644 --- a/src/test/librgw_file_nfsns.cc +++ b/src/test/librgw_file_nfsns.cc @@ -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);