]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
add ceph_readdir() to libceph
authorBrian Chrisman <brchrisman@gmail.com>
Thu, 19 May 2011 20:22:32 +0000 (13:22 -0700)
committerSage Weil <sage@newdream.net>
Thu, 19 May 2011 22:24:58 +0000 (15:24 -0700)
Signed-off-by: Brian Chrisman <brchrisman@gmail.com>
Signed-off-by: Sage Weil <sage@newdream.net>
src/client/Client.cc
src/client/Client.h
src/include/ceph/libceph.h
src/libceph.cc

index bf8f6f2e7a916501002b40f91c2417b2c7828307..189989f17fe6ba6e5ce70deb4cb402989c8b0e81 100644 (file)
@@ -4295,8 +4295,6 @@ int Client::readdir_r_cb(dir_result_t *d, add_dirent_cb_t cb, void *p)
 }
 
 
-
-
 int Client::readdir_r(dir_result_t *d, struct dirent *de)
 {  
   return readdirplus_r(d, de, 0, 0);
@@ -4334,6 +4332,39 @@ static int _readdir_single_dirent_cb(void *p, struct dirent *de, struct stat *st
   return 0;  
 }
 
+struct dirent * Client::readdir(dir_result_t *d)
+{
+  int ret;
+  static int stmask;
+  static struct dirent de;
+  static struct stat st;
+  single_readdir sr;
+  sr.de = &de;
+  sr.st = &st;
+  sr.stmask = &stmask;
+  sr.full = false;
+
+  /*
+   * Return mechanisms are non-obvious (callback appears intended for multi-read mechanism like cfuse)
+   * readdir_r_cb=0 end of directory reached on prior call
+   * readdir_r_cb=0 entry filled and offset now at end of the directory
+   * readdir_r_cb=-1 entry is filled successfully, not end of dir
+   * readdir_r_cb=-(other) on error
+   * callback leaves sr.full=false when 'offset is at end of directory'
+   * callback may leave sr.full=false on error
+   * callback sets sr.full=true on 'successfully read dirent'
+   */
+  ret = readdir_r_cb(d, _readdir_single_dirent_cb, (void *)&sr);
+  if (ret < -1) {
+    errno = -ret;
+    return (dirent *) NULL;
+  }
+  if (sr.full) {
+    return &de;
+  }
+  return (dirent *) NULL;
+}
+
 int Client::readdirplus_r(dir_result_t *d, struct dirent *de, struct stat *st, int *stmask)
 {  
   single_readdir sr;
index b73af286571b41aa1bd3373ef5c33cc6e2cc5ddd..ec71b2025b74ca7297dbb44a9124e762a12b0bc6 100644 (file)
@@ -1204,6 +1204,7 @@ public:
 
   int readdir_r_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p);
 
+  struct dirent * readdir(dir_result_t *d);
   int readdir_r(dir_result_t *dirp, struct dirent *de);
   int readdirplus_r(dir_result_t *dirp, struct dirent *de, struct stat *st, int *stmask);
 
index f9fc29ea1b5cae07deefc2e8289a494bf3fc66ae..bf28402fee483bc7ff290e0118e0afea283e5788 100644 (file)
@@ -76,6 +76,7 @@ int ceph_chdir(struct ceph_mount_info *cmount, const char *s);
 
 int ceph_opendir(struct ceph_mount_info *cmount, const char *name, struct ceph_dir_result **dirpp);
 int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
+struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
 int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de);
 int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de,
                       struct stat *st, int *stmask);
index 6388bde1f2636aad700dc411ec2bb553b9634623..54993ac124df4872b5aef0dd479e3c9d35599893 100644 (file)
@@ -319,6 +319,11 @@ extern "C" int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_res
   return cmount->get_client()->closedir((dir_result_t*)dirp);
 }
 
+extern "C" struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp)
+{
+  return cmount->get_client()->readdir((dir_result_t*)dirp);
+}
+
 extern "C" int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de)
 {
   return cmount->get_client()->readdir_r((dir_result_t*)dirp, de);