]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: bring back lookup_handle()
authorMatt Benjamin <mbenjamin@redhat.com>
Wed, 4 Nov 2015 21:20:45 +0000 (16:20 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:05:37 +0000 (12:05 -0500)
Now as a member of RGWLibFS, and exposed via rgw_lookup_handle()
for use by library clients.

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

index 29a55200648081c1862b47b16c2bad0ad77711ae..5b41389aa4f861112ca6a7c2dea4f29ab498eef9 100644 (file)
@@ -76,6 +76,25 @@ struct rgw_statvfs {
     uint64_t     f_namemax;  /* maximum filename length */
 };
 
+/*
+  lookup object by name (POSIX style)
+*/
+int rgw_lookup(struct rgw_fs *rgw_fs,
+             struct rgw_file_handle *parent_fh, const char *path,
+             struct rgw_file_handle **fh, uint32_t flags);
+
+/*
+  lookup object by handle (NFS style)
+*/
+int rgw_lookup_handle(struct rgw_fs *rgw_fs, struct rgw_fh_hk fh_hk,
+                     struct rgw_file_handle **fh, uint32_t flags);
+
+/*
+ * release file handle
+ */
+int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
+               uint32_t flags);
+
 /*
  attach rgw namespace
 */
@@ -126,20 +145,7 @@ int rgw_unlink(struct rgw_fs *rgw_fs,
               struct rgw_file_handle *parent_fh, const char* path);
 
 /*
-  lookup a directory or file
-*/
-int rgw_lookup(struct rgw_fs *rgw_fs,
-             struct rgw_file_handle *parent_fh, const char *path,
-             struct rgw_file_handle **fh, uint32_t flags);
-
-/*
- * release file handle
- */
-int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
-               uint32_t flags);
-
-/*
-  read  directory content
+    read  directory content
 */
 typedef bool (*rgw_readdir_cb)(const char *name, void *arg, uint64_t offset);
 
@@ -187,7 +193,7 @@ int rgw_open(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh,
 
 #define RGW_CLOSE_FLAG_NONE 0x0000
 #define RGW_CLOSE_FLAG_RELE 0x0001
-
+  
 int rgw_close(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
              uint32_t flags);
 
@@ -197,7 +203,7 @@ int rgw_close(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
 int rgw_read(struct rgw_fs *rgw_fs,
            struct rgw_file_handle *fh, uint64_t offset,
            size_t length, size_t *bytes_read, void *buffer);
-
+  
 /*
    write data to file
 */
index e3f86e1983e5a3b59fbbdad23d2e6757cba04c2a..9792749dfbbad4f50e21ba47bd787be0b4279bdb 100644 (file)
@@ -172,7 +172,7 @@ int rgw_unlink(struct rgw_fs *rgw_fs, struct rgw_file_handle* parent,
 }
 
 /*
-  lookup a directory or file
+  lookup object by name (POSIX style)
 */
 int rgw_lookup(struct rgw_fs *rgw_fs,
              struct rgw_file_handle *parent_fh, const char* path,
@@ -198,6 +198,26 @@ int rgw_lookup(struct rgw_fs *rgw_fs,
   return 0;
 } /* rgw_lookup */
 
+/*
+  lookup object by handle (NFS style)
+*/
+int rgw_lookup_handle(struct rgw_fs *rgw_fs, struct rgw_fh_hk fh_hk,
+                     struct rgw_file_handle **fh, uint32_t flags)
+{
+  RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
+
+  RGWFileHandle* rgw_fh = fs->lookup_handle(fh_hk);
+  if (! rgw_fh) {
+    /* not found */
+    return ENOENT;
+  }
+
+  struct rgw_file_handle *rfh = rgw_fh->get_fh();
+  *fh = rfh;
+
+  return 0;
+}
+
 /*
  * release file handle
  */
index 8f2aec5f8fb962a814c8b38402394de03d630fef..d1d2d46cb3c439aa3e3fa9afbec5b5fb93b6a030 100644 (file)
@@ -313,6 +313,35 @@ namespace rgw {
       return fh;
     }
 
+    /* find or create an RGWFileHandle */
+    RGWFileHandle* lookup_handle(struct rgw_fh_hk fh_hk) {
+
+      RGWFileHandle::FHCache::Latch lat;
+      fh_key fhk(fh_hk);
+
+      RGWFileHandle* fh =
+       fh_cache.find_latch(fhk.fh_hk.object /* partition selector*/,
+                           fhk /* key */, lat /* serializer */,
+                           RGWFileHandle::FHCache::FLAG_LOCK);
+      /* LATCHED */
+      if (! fh) {
+       lsubdout(get_context(), rgw, 0)
+         << __func__ << " handle lookup failed <"
+         << fhk.fh_hk.bucket << "," << fhk.fh_hk.object << ">"
+         << "(need persistent handles)"
+         << dendl;
+       goto out;
+      }
+      intrusive_ptr_add_ref(fh); /* call path/handle ref */
+    out:
+      lat.lock->unlock(); /* !LATCHED */
+      return fh;
+    }
+
+    CephContext* get_context() {
+      return static_cast<CephContext*>(get_fs()->fs_private);
+    }
+
     struct rgw_fs* get_fs() { return &fs; }
 
     RGWUserInfo* get_user() { return &user; }