]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/filestore: use readdir() as readdir_r() is deprecated
authorKefu Chai <kchai@redhat.com>
Mon, 7 Nov 2016 05:59:45 +0000 (13:59 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 7 Nov 2016 06:19:44 +0000 (14:19 +0800)
see https://lwn.net/Articles/696469/, readdir_r() is deprecated by
glibc since 2.24. so let's use readdir() instead.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/os/filestore/BtrfsFileStoreBackend.cc
src/os/filestore/FileStore.cc
src/os/filestore/LFNIndex.cc

index 97421c5be19b3115c8b6bc616a2686fff29ee0e8..0d52f1121abf9d887af411776b4b32facc76a095 100644 (file)
@@ -320,12 +320,8 @@ int BtrfsFileStoreBackend::list_checkpoints(list<string>& ls)
 
   list<string> snaps;
   char path[PATH_MAX];
-  char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1];
   struct dirent *de;
-  while (::readdir_r(dir, (struct dirent *)&buf, &de) == 0) {
-    if (!de)
-      break;
-
+  while ((de = ::readdir(dir))) {
     snprintf(path, sizeof(path), "%s/%s", get_basedir_path().c_str(), de->d_name);
 
     struct stat st;
index 27e6197e9afd3d2d382d290cf86550324bd6b197..7ff064acf5d55fbe32187dd362bb34f016819ae4 100644 (file)
@@ -4633,11 +4633,8 @@ int FileStore::list_collections(vector<coll_t>& ls, bool include_temp)
     return r;
   }
 
-  char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1];
-  struct dirent *de;
-  while ((r = ::readdir_r(dir, (struct dirent *)&buf, &de)) == 0) {
-    if (!de)
-      break;
+  struct dirent *de = nullptr;
+  while ((de = ::readdir(dir))) {
     if (de->d_type == DT_UNKNOWN) {
       // d_type not supported (non-ext[234], btrfs), must stat
       struct stat sb;
@@ -4675,7 +4672,7 @@ int FileStore::list_collections(vector<coll_t>& ls, bool include_temp)
   }
 
   if (r > 0) {
-    derr << "trying readdir_r " << fn << ": " << cpp_strerror(r) << dendl;
+    derr << "trying readdir " << fn << ": " << cpp_strerror(r) << dendl;
     r = -r;
   }
 
index f56c1f3c02376eed87ac5abcade89a705673bc7d..9ac0457d6109c88728055f97305d8e95af67ddec 100644 (file)
@@ -406,8 +406,6 @@ int LFNIndex::list_objects(const vector<string> &to_list, int max_objs,
 {
   string to_list_path = get_full_path_subdir(to_list);
   DIR *dir = ::opendir(to_list_path.c_str());
-  char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1];
-  int r;
   if (!dir) {
     return -errno;
   }
@@ -416,14 +414,12 @@ int LFNIndex::list_objects(const vector<string> &to_list, int max_objs,
     seekdir(dir, *handle);
   }
 
-  struct dirent *de;
+  struct dirent *de = nullptr;
+  int r = 0;
   int listed = 0;
-  bool end = false;
-  while (!::readdir_r(dir, reinterpret_cast<struct dirent*>(buf), &de)) {
-    if (!de) {
-      end = true;
-      break;
-    }
+  bool end = true;
+  while ((de = ::readdir(dir))) {
+    end = false;
     if (max_objs > 0 && listed >= max_objs) {
       break;
     }
@@ -466,15 +462,11 @@ int LFNIndex::list_subdirs(const vector<string> &to_list,
 {
   string to_list_path = get_full_path_subdir(to_list);
   DIR *dir = ::opendir(to_list_path.c_str());
-  char buf[offsetof(struct dirent, d_name) + PATH_MAX + 1];
   if (!dir)
     return -errno;
 
-  struct dirent *de;
-  while (!::readdir_r(dir, reinterpret_cast<struct dirent*>(buf), &de)) {
-    if (!de) {
-      break;
-    }
+  struct dirent *de = nullptr;
+  while ((de = ::readdir(dir))) {
     string short_name(de->d_name);
     string demangled_name;
     if (lfn_is_subdir(short_name, &demangled_name)) {