]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-bluestore-tool: prime-osd-dir: update symlinks instead of bailing
authorSage Weil <sage@redhat.com>
Thu, 26 Oct 2017 18:51:40 +0000 (13:51 -0500)
committerSage Weil <sage@redhat.com>
Thu, 26 Oct 2017 18:51:40 +0000 (13:51 -0500)
If the symlink points to the right location, do nothing.  If it doesn't,
replace it.  If it's not a symlink, bail with EEXIST.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/bluestore_tool.cc

index 728ad4f60a3a59301037e5d96c6fdf8d9480035b..ae259f6a49c7a3742958b86f116e246be331389b 100644 (file)
@@ -336,6 +336,25 @@ int main(int argc, char **argv)
       if (k.find("path_") == 0) {
        p = path + "/" + k.substr(5);
        int r = ::symlink(v.c_str(), p.c_str());
+       if (r < 0 && errno == EEXIST) {
+         struct stat st;
+         r = ::stat(p.c_str(), &st);
+         if (r == 0 && S_ISLNK(st.st_mode)) {
+           char target[PATH_MAX];
+           r = ::readlink(p.c_str(), target, sizeof(target));
+           if (r > 0) {
+             if (v == target) {
+               r = 0;  // already matches our target
+             } else {
+               ::unlink(p.c_str());
+               r = ::symlink(v.c_str(), p.c_str());
+             }
+           } else {
+             cerr << "error reading existing link at " << p << ": " << cpp_strerror(errno)
+                  << std::endl;
+           }
+         }
+       }
        if (r < 0) {
          cerr << "error symlinking " << p << ": " << cpp_strerror(errno)
               << std::endl;