All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Adding ceph_readdir to libceph
@ 2011-05-19 20:22 Brian Chrisman
  2011-05-19 20:22 ` [PATCH 1/2] add ceph_readdir() " Brian Chrisman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Brian Chrisman @ 2011-05-19 20:22 UTC (permalink / raw)
  To: ceph-devel; +Cc: Brian Chrisman

Some applications (Samba-VFS layer included) expect readdir() rather than readdir_r().
Expanded Client & libceph to include readdir.
Expanded testceph to cover additional basic functionality.

Brian Chrisman (2):
  add ceph_readdir() to libceph
  expanding testceph to test open/readdir/telldir

 src/client/Client.cc       |   35 ++++++++++++++++-
 src/client/Client.h        |    1 +
 src/client/testceph.cc     |   88 ++++++++++++++++++++++++++++++++++---------
 src/include/ceph/libceph.h |    1 +
 src/libceph.cc             |    5 ++
 5 files changed, 109 insertions(+), 21 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] add ceph_readdir() to libceph
  2011-05-19 20:22 [PATCH 0/2] Adding ceph_readdir to libceph Brian Chrisman
@ 2011-05-19 20:22 ` Brian Chrisman
  2011-05-19 20:22 ` [PATCH 2/2] expanding testceph to test open/readdir/telldir Brian Chrisman
  2011-05-19 22:05 ` [PATCH 0/2] Adding ceph_readdir to libceph Sage Weil
  2 siblings, 0 replies; 4+ messages in thread
From: Brian Chrisman @ 2011-05-19 20:22 UTC (permalink / raw)
  To: ceph-devel; +Cc: Brian Chrisman


Signed-off-by: Brian Chrisman <brchrisman@gmail.com>
---
 src/client/Client.cc       |   35 +++++++++++++++++++++++++++++++++--
 src/client/Client.h        |    1 +
 src/include/ceph/libceph.h |    1 +
 src/libceph.cc             |    5 +++++
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/src/client/Client.cc b/src/client/Client.cc
index e4b400c..0284c03 100644
--- a/src/client/Client.cc
+++ b/src/client/Client.cc
@@ -4298,8 +4298,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);
@@ -4337,6 +4335,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;
diff --git a/src/client/Client.h b/src/client/Client.h
index b36621d..e10979d 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -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);
 
diff --git a/src/include/ceph/libceph.h b/src/include/ceph/libceph.h
index f9fc29e..bf28402 100644
--- a/src/include/ceph/libceph.h
+++ b/src/include/ceph/libceph.h
@@ -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);
diff --git a/src/libceph.cc b/src/libceph.cc
index 6388bde..54993ac 100644
--- a/src/libceph.cc
+++ b/src/libceph.cc
@@ -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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] expanding testceph to test open/readdir/telldir
  2011-05-19 20:22 [PATCH 0/2] Adding ceph_readdir to libceph Brian Chrisman
  2011-05-19 20:22 ` [PATCH 1/2] add ceph_readdir() " Brian Chrisman
@ 2011-05-19 20:22 ` Brian Chrisman
  2011-05-19 22:05 ` [PATCH 0/2] Adding ceph_readdir to libceph Sage Weil
  2 siblings, 0 replies; 4+ messages in thread
From: Brian Chrisman @ 2011-05-19 20:22 UTC (permalink / raw)
  To: ceph-devel; +Cc: Brian Chrisman


Signed-off-by: Brian Chrisman <brchrisman@gmail.com>
---
 src/client/testceph.cc |   88 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 69 insertions(+), 19 deletions(-)

diff --git a/src/client/testceph.cc b/src/client/testceph.cc
index c24cc03..413da10 100644
--- a/src/client/testceph.cc
+++ b/src/client/testceph.cc
@@ -30,6 +30,7 @@ int main(int argc, const char **argv)
 {
   struct ceph_mount_info *cmount;
     cout << "calling ceph_create..." << std::endl;
+  int my_fd;
   int ret = ceph_create(&cmount, NULL);
   if (ret) {
     cerr << "ceph_create failed with error: " << ret << std::endl;
@@ -67,7 +68,12 @@ int main(int argc, const char **argv)
   } else {
     cout << "ceph_opendir: success" << std::endl;
   }
-
+  //ret = ceph_closedir(cmount, foo_dir);
+  //if (ret == 0) {
+  //  cerr << "ceph_closedir success" << std::endl;
+  //} else {
+  //  cerr << "ceph_closedir error: " << cpp_strerror(ret) << std::endl;
+  //}
   ret = ceph_mkdir(cmount, "foo",  0777);
   if (ret) {
     cerr << "ceph_mkdir error: " << cpp_strerror(ret) << std::endl;
@@ -129,7 +135,7 @@ int main(int argc, const char **argv)
   } else {
     cout << "ceph_rmdir: success" << std::endl;
   }
-  ret = ceph_open(cmount, "barfile", O_CREAT, 0666);
+  my_fd = ret = ceph_open(cmount, "barfile", O_CREAT, 0666);
   if (ret < 0) {
     cerr << "ceph_open O_CREAT error: " << cpp_strerror(ret) << std::endl;
     return 1;
@@ -175,6 +181,15 @@ int main(int argc, const char **argv)
   if (strncmp((char *) aybabtu, aybabtu_reference,7)) {
     cerr << "ceph_getxattr error: no match (" << aybabtu << ") should be (" << aybabtu_reference << cpp_strerror(ret) << std::endl;
   }
+  ret = ceph_close(cmount,my_fd);
+  if (ret < 0) {
+    cerr << "ceph_close error: " << cpp_strerror(ret) << std::endl;
+    return 1;
+  } else {
+    cout << "ceph_close: success" << std::endl;
+  }
+
+
   cout << "Attempting lstat on '/.'" << std::endl;
   ret = ceph_lstat(cmount, "/.", &stbuf);
   if (ret) {
@@ -191,40 +206,75 @@ int main(int argc, const char **argv)
   } else {
     cout << "ceph_lstat: success" << std::endl;
   }
-  cout << "Attempting readdir_r" << std::endl;
-  ret = ceph_mkdir(cmount, "readdir_r_test",  0777);
+  cout << "Setting up readdir test" << std::endl;
+  ret = ceph_mkdir(cmount, "readdir_test",  0777);
   if (ret) {
     cerr << "ceph_mkdir error: " << cpp_strerror(ret) << std::endl;
     return 1;
   } else {
     cout << "ceph_mkdir: success" << std::endl;
   }
-  struct ceph_dir_result *readdir_r_test_dir;
-  ret = ceph_opendir(cmount, "readdir_r_test", &readdir_r_test_dir);
-  if (ret != 0) {
-    cerr << "ceph_opendir error: unexpected result from trying to open readdir_r_test: "
-	 << cpp_strerror(ret) << std::endl;
+  my_fd = ret = ceph_open(cmount, "readdir_test/opened_file_1", O_CREAT, 0666);
+  if (ret < 0) {
+    cerr << "ceph_open O_CREAT error: " << cpp_strerror(ret) << std::endl;
     return 1;
   } else {
-    cout << "ceph_opendir: success" << std::endl;
+    cout << "ceph_open: success" << std::endl;
   }
-  ret = ceph_open(cmount, "readdir_r_test/opened_file", O_CREAT, 0666);
+  ret = ceph_close(cmount, my_fd);
   if (ret < 0) {
-    cerr << "ceph_open O_CREAT error: " << cpp_strerror(ret) << std::endl;
+    cerr << "ceph_close error: " << cpp_strerror(ret) << std::endl;
     return 1;
   } else {
-    cout << "ceph_open: success" << std::endl;
+    cout << "ceph_close: success" << std::endl;
   }
 
-  struct dirent * result;
-  result = (struct dirent *) malloc(sizeof(struct dirent));
-  ret = ceph_readdir_r(cmount, readdir_r_test_dir, result);
+  struct ceph_dir_result *readdir_test_dir;
+  ret = ceph_opendir(cmount, "readdir_test", &readdir_test_dir);
   if (ret != 0) {
-    cerr << "ceph_readdir_r: fail, returned: " << ret << std::endl;
-  } else {
-    cerr << "ceph_readdir_r: success: " << *result->d_name << std::endl;
+    cerr << "ceph_opendir error: unexpected result from trying to open readdir_test: "
+	 << cpp_strerror(ret) << std::endl;
     return 1;
+  } else {
+    cout << "ceph_opendir: success" << std::endl;
   }
+  cout << "Attempting readdir on opened directory..." << std::endl;
+  struct dirent * result;
+  //result = (struct dirent *) malloc(sizeof(struct dirent));
+  result = ceph_readdir(cmount, readdir_test_dir);
+  if (result == (dirent *) NULL) {
+    cout << "ceph_readdir: failed to read any entries" << std::endl;
+  }
+  loff_t telldir_result;
+  while ( result != (dirent *) NULL) {
+    cout << "ceph_readdir: dirent->d_name: (" << result->d_name << ")" << std::endl;
+    cout << "ceph_telldir: starting" << std::endl;
+    telldir_result = ceph_telldir(cmount, readdir_test_dir);
+    if (telldir_result > -1) {
+      cout << "ceph_telldir: offset: from return code:" << telldir_result << std::endl;
+    } else {
+      cout << "ceph_telldir: failed" << std::endl;
+    }
+    cout << "ceph_readdir: lookup success: trying for another..." << std::endl;
+    result = ceph_readdir(cmount, readdir_test_dir);
+  }
+  cout << "ceph_readdir: finished" << std::endl;
+
+  // tell us that we're at the end of the directory:
+  cout << "ceph_telldir: starting" << std::endl;
+  telldir_result = ceph_telldir(cmount, readdir_test_dir);
+  if (telldir_result > -1) {
+    cout << "ceph_telldir: offset: from return code:" << telldir_result << std::endl;
+  } else {
+    cout << "ceph_telldir: failed" << std::endl;
+  }
+
+  //ret = ceph_closedir(cmount,readdir_test_dir);
+  //if (ret == 0) {
+  //  cerr << "ceph_closedir success" << std::endl;
+  //} else {
+  //  cerr << "ceph_closedir error: " << cpp_strerror(ret) << std::endl;
+  //}
   
   ceph_shutdown(cmount);
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Adding ceph_readdir to libceph
  2011-05-19 20:22 [PATCH 0/2] Adding ceph_readdir to libceph Brian Chrisman
  2011-05-19 20:22 ` [PATCH 1/2] add ceph_readdir() " Brian Chrisman
  2011-05-19 20:22 ` [PATCH 2/2] expanding testceph to test open/readdir/telldir Brian Chrisman
@ 2011-05-19 22:05 ` Sage Weil
  2 siblings, 0 replies; 4+ messages in thread
From: Sage Weil @ 2011-05-19 22:05 UTC (permalink / raw)
  To: Brian Chrisman; +Cc: ceph-devel

On Thu, 19 May 2011, Brian Chrisman wrote:
> Some applications (Samba-VFS layer included) expect readdir() rather than readdir_r().
> Expanded Client & libceph to include readdir.
> Expanded testceph to cover additional basic functionality.
> 
> Brian Chrisman (2):
>   add ceph_readdir() to libceph
>   expanding testceph to test open/readdir/telldir

Applied, thanks!
sage



> 
>  src/client/Client.cc       |   35 ++++++++++++++++-
>  src/client/Client.h        |    1 +
>  src/client/testceph.cc     |   88 ++++++++++++++++++++++++++++++++++---------
>  src/include/ceph/libceph.h |    1 +
>  src/libceph.cc             |    5 ++
>  5 files changed, 109 insertions(+), 21 deletions(-)
> 
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-19 22:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-19 20:22 [PATCH 0/2] Adding ceph_readdir to libceph Brian Chrisman
2011-05-19 20:22 ` [PATCH 1/2] add ceph_readdir() " Brian Chrisman
2011-05-19 20:22 ` [PATCH 2/2] expanding testceph to test open/readdir/telldir Brian Chrisman
2011-05-19 22:05 ` [PATCH 0/2] Adding ceph_readdir to libceph Sage Weil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.