]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
uclient: fix _getdents and add some documentation.
authorGreg Farnum <gregory.farnum@dreamhost.com>
Fri, 28 Oct 2011 00:24:49 +0000 (17:24 -0700)
committerGreg Farnum <gregory.farnum@dreamhost.com>
Fri, 28 Oct 2011 00:24:49 +0000 (17:24 -0700)
If readdir_r_cb returns 0, that means SUCCESS, regardless of how
many entries it actually wrote.
If it returns <0, then either:
a) our callback failed to fit some data (returning -1), which is fine
unless we took no entries (so return gr.pos or -ERANGE, depending), or
b) something else failed, so return that error code.
If it returns 0, we succeeded, so return the amount of used buffer.

Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h

index e56e2f29e26346a0c6fa1dfe32b34e0b3033eac4..9a21afcac7de7aa05bfd37417edcd1e6e0718949 100644 (file)
@@ -4680,12 +4680,17 @@ int Client::_getdents(dir_result_t *dir, char *buf, int buflen, bool fullent)
   gr.pos = 0;
 
   int r = readdir_r_cb(dir, _readdir_getdent_cb, (void *)&gr);
-  if (r < 0) 
-    return r;
-
-  if (gr.pos == 0)
-    return -ERANGE;
 
+  if (r < 0) { // some error
+    if (r == -1) { // buffer ran out of space
+      if (gr.pos) { // but we got some entries already!
+        return gr.pos;
+      } // or we need a larger buffer
+      return -ERANGE;
+    } else { // actual error, return it
+      return r;
+    }
+  }
   return gr.pos;
 }
 
index b8909c945f931dfa43ef0c8cc6d2a2814e245604..5ee7415f4fdba6f6cae2b0be34a09fa0844fc0a5 100644 (file)
@@ -535,6 +535,11 @@ public:
 
   int getdir(const char *relpath, list<string>& names);  // get the whole dir at once.
 
+  /**
+   * Returns the length of the buffer that got filled in, or -errno.
+   * If it returns -ERANGE you just need to increase the size of the
+   * buffer and try again.
+   */
   int _getdents(dir_result_t *dirp, char *buf, int buflen, bool ful);  // get a bunch of dentries at once
   int getdents(dir_result_t *dirp, char *buf, int buflen) {
     return _getdents(dirp, buf, buflen, true);
index f8dbe7986fbe7fd31c0c6b506c38532d01029eeb..31974bee7646776d9072bc057dc1f7dfab4e74af 100644 (file)
@@ -82,6 +82,10 @@ int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp,
 int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de,
                       struct stat *st, int *stmask);
 int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
+/**
+ * This returns the used buffer space on success, -ERANGE if the buffer
+ * is not large enough to hold a name, or -errno on other issues.
+ */
 int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, char *name, int buflen);
 void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);
 loff_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp);