From c826b0338302d3728523ed88e9bde1550ad1525a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 15 Dec 2020 23:11:47 +0800 Subject: [PATCH] ceph.in: try harder if asok path does not exist when handling "ceph daemon ...", we need to figure out the asok path, if the "" 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, "" 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 --- src/ceph.in | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index 2ee2f3d6c2ef..1714ae931bbb 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -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): -- 2.47.3