]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph.in: try harder if asok path does not exist 38599/head
authorKefu Chai <kchai@redhat.com>
Tue, 15 Dec 2020 15:11:47 +0000 (23:11 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 17 Dec 2020 00:54:44 +0000 (08:54 +0800)
when handling "ceph daemon <name> ...", we need to figure out the asok
path, if the "<name>" option is not a path but a "name" as it claims to
be. but if the "admin_socket" option includes substitution/meta variable of
"$pid", it will be expanded using its own pid, instead of the process
with the specified "name". but "ceph" cli does not offer a dedicated
option for overriding the pid for ceph-conf which is used "ceph" cli to
retrieve the "admin_socket" option with specified "name".

in this change, "<name>" option is interpreted as "${name}.${pid}" if
the returned admin_socket path does not point to a valid UNIX domain
socket file. and "ceph" cli will try harder by passing "--pid ${pid}"
and "--name ${name}" instead of "--name ${name}.${pid}" to ceph-conf.

Fixes: https://tracker.ceph.com/issues/47977
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/ceph.in

index 2ee2f3d6c2ef25d6e118a09bff8f672026b3fe5c..1714ae931bbbd23525a7c34ac99cf12f0ed69501 100755 (executable)
@@ -20,11 +20,11 @@ Foundation.  See file COPYING.
 """
 
 from time import sleep
-import codecs
 import grp
 import os
 import pwd
 import shutil
+import stat
 import sys
 import time
 import platform
@@ -495,7 +495,7 @@ def format_help(cmddict, partial=None):
     return fullusage
 
 
-def ceph_conf(parsed_args, field, name):
+def ceph_conf(parsed_args, field, name, pid=None):
     cmd = 'ceph-conf'
     bindir = os.path.dirname(__file__)
     if shutil.which(cmd):
@@ -507,6 +507,8 @@ def ceph_conf(parsed_args, field, name):
 
     if name:
         args.extend(['--name', name])
+    if pid:
+        args.extend(['--pid', pid])
 
     # add any args in GLOBAL_ARGS
     for key, val in GLOBAL_ARGS.items():
@@ -526,6 +528,7 @@ def ceph_conf(parsed_args, field, name):
         raise RuntimeError('unable to get conf option %s for %s: %s' % (field, name, errdata))
     return outdata.rstrip()
 
+
 PROMPT = 'ceph> '
 
 if sys.stdin.isatty():
@@ -731,7 +734,20 @@ def ping_monitor(cluster_handle, name, timeout):
 
 
 def get_admin_socket(parsed_args, name):
-    return ceph_conf(parsed_args, 'admin_socket', name)
+    path = ceph_conf(parsed_args, 'admin_socket', name)
+    try:
+        if stat.S_ISSOCK(os.stat(path).st_mode):
+            return path
+    except OSError:
+        pass
+    # try harder, probably the "name" option is in the form of
+    # "${name}.${pid}"?
+    parts = name.rsplit('.', 1)
+    if len(parts) > 1 and parts[-1].isnumeric():
+        name, pid = parts
+        return ceph_conf(parsed_args, 'admin_socket', name, pid)
+    else:
+        return path
 
 
 def maybe_daemon_command(parsed_args, childargs):