2014-10-28 17:12:02 +00:00
|
|
|
import json
|
2014-07-02 15:43:16 +00:00
|
|
|
import logging
|
2021-06-29 02:21:44 +00:00
|
|
|
import os
|
2020-11-16 05:33:46 +00:00
|
|
|
import re
|
2020-01-27 06:07:44 +00:00
|
|
|
|
|
|
|
from io import StringIO
|
2014-10-28 17:12:02 +00:00
|
|
|
from textwrap import dedent
|
2020-01-27 06:07:44 +00:00
|
|
|
|
2014-09-15 22:41:34 +00:00
|
|
|
from teuthology.orchestra.run import CommandFailedError
|
2014-07-02 15:43:16 +00:00
|
|
|
from teuthology.orchestra import run
|
2017-02-01 00:25:44 +00:00
|
|
|
from teuthology.contextutil import MaxWhileTries
|
2020-01-27 06:07:44 +00:00
|
|
|
|
2020-03-24 08:33:22 +00:00
|
|
|
from tasks.cephfs.mount import CephFSMount
|
2014-07-02 15:43:16 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2017-02-01 00:25:44 +00:00
|
|
|
UMOUNT_TIMEOUT = 300
|
|
|
|
|
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
class KernelMount(CephFSMount):
|
2020-01-27 06:07:44 +00:00
|
|
|
def __init__(self, ctx, test_dir, client_id, client_remote,
|
|
|
|
client_keyring_path=None, hostfs_mntpt=None,
|
2020-11-09 06:22:11 +00:00
|
|
|
cephfs_name=None, cephfs_mntpt=None, brxnet=None, config={}):
|
2020-01-27 06:07:44 +00:00
|
|
|
super(KernelMount, self).__init__(ctx=ctx, test_dir=test_dir,
|
|
|
|
client_id=client_id, client_remote=client_remote,
|
|
|
|
client_keyring_path=client_keyring_path, hostfs_mntpt=hostfs_mntpt,
|
|
|
|
cephfs_name=cephfs_name, cephfs_mntpt=cephfs_mntpt, brxnet=brxnet)
|
|
|
|
|
2020-10-29 03:04:12 +00:00
|
|
|
self.rbytes = config.get('rbytes', False)
|
2020-11-16 05:33:46 +00:00
|
|
|
self.inst = None
|
|
|
|
self.addr = None
|
2020-10-14 11:21:36 +00:00
|
|
|
self._mount_bin = ['adjust-ulimits', 'ceph-coverage', self.test_dir +\
|
|
|
|
'/archive/coverage', '/bin/mount', '-t', 'ceph']
|
2020-10-29 03:04:12 +00:00
|
|
|
|
2021-02-19 16:03:45 +00:00
|
|
|
def mount(self, mntopts=[], check_status=True, **kwargs):
|
2020-01-27 06:07:44 +00:00
|
|
|
self.update_attrs(**kwargs)
|
|
|
|
self.assert_and_log_minimum_mount_details()
|
2014-09-15 22:41:34 +00:00
|
|
|
|
2020-03-03 13:31:29 +00:00
|
|
|
self.setup_netns()
|
2018-07-12 13:25:53 +00:00
|
|
|
|
2020-01-27 06:07:44 +00:00
|
|
|
if not self.cephfs_mntpt:
|
|
|
|
self.cephfs_mntpt = '/'
|
2014-07-02 15:43:16 +00:00
|
|
|
|
2020-10-14 11:21:36 +00:00
|
|
|
self._create_mntpt()
|
2015-11-09 13:15:21 +00:00
|
|
|
|
2020-03-24 11:34:14 +00:00
|
|
|
retval = self._run_mount_cmd(mntopts, check_status)
|
|
|
|
if retval:
|
|
|
|
return retval
|
2016-11-06 22:01:00 +00:00
|
|
|
|
2020-10-14 11:21:36 +00:00
|
|
|
self._set_filemode_on_mntpt()
|
|
|
|
|
|
|
|
self.mounted = True
|
|
|
|
|
|
|
|
def _run_mount_cmd(self, mntopts, check_status):
|
|
|
|
mount_cmd = self._get_mount_cmd(mntopts)
|
|
|
|
mountcmd_stdout, mountcmd_stderr = StringIO(), StringIO()
|
2020-03-24 11:34:14 +00:00
|
|
|
|
2020-10-14 11:21:36 +00:00
|
|
|
try:
|
|
|
|
self.client_remote.run(args=mount_cmd, timeout=(30*60),
|
|
|
|
stdout=mountcmd_stdout,
|
|
|
|
stderr=mountcmd_stderr, omit_sudo=False)
|
|
|
|
except CommandFailedError as e:
|
|
|
|
log.info('mount command failed')
|
|
|
|
if check_status:
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
return (e, mountcmd_stdout.getvalue(),
|
|
|
|
mountcmd_stderr.getvalue())
|
|
|
|
log.info('mount command passed')
|
2016-11-06 22:01:00 +00:00
|
|
|
|
2020-10-14 11:21:36 +00:00
|
|
|
def _get_mount_cmd(self, mntopts):
|
2020-10-13 08:11:43 +00:00
|
|
|
opts = 'norequire_active_mds'
|
2020-03-24 11:34:14 +00:00
|
|
|
if self.client_id:
|
2020-10-13 08:11:43 +00:00
|
|
|
opts += ',name=' + self.client_id
|
2020-03-24 11:34:14 +00:00
|
|
|
if self.client_keyring_path and self.client_id:
|
|
|
|
opts += ',secret=' + self.get_key_from_keyfile()
|
|
|
|
if self.config_path:
|
|
|
|
opts += ',conf=' + self.config_path
|
|
|
|
if self.cephfs_name:
|
|
|
|
opts += ",mds_namespace=" + self.cephfs_name
|
2020-10-29 03:04:12 +00:00
|
|
|
if self.rbytes:
|
|
|
|
opts += ",rbytes"
|
|
|
|
else:
|
|
|
|
opts += ",norbytes"
|
2020-01-27 06:07:44 +00:00
|
|
|
if mntopts:
|
|
|
|
opts += ',' + ','.join(mntopts)
|
2019-10-28 07:39:44 +00:00
|
|
|
|
2020-10-14 11:21:36 +00:00
|
|
|
mount_cmd = ['sudo'] + self._nsenter_args
|
2020-03-24 11:34:14 +00:00
|
|
|
mount_dev = ':' + self.cephfs_mntpt
|
2020-10-14 11:21:36 +00:00
|
|
|
mount_cmd += self._mount_bin + [mount_dev, self.hostfs_mntpt, '-v',
|
|
|
|
'-o', opts]
|
2014-07-02 15:43:16 +00:00
|
|
|
|
2020-10-14 11:21:36 +00:00
|
|
|
return mount_cmd
|
|
|
|
|
2017-01-09 12:47:37 +00:00
|
|
|
def umount(self, force=False):
|
2020-03-05 01:59:04 +00:00
|
|
|
if not self.is_mounted():
|
2020-05-07 12:33:41 +00:00
|
|
|
self.cleanup()
|
2020-03-05 01:59:04 +00:00
|
|
|
return
|
|
|
|
|
2014-07-02 15:43:16 +00:00
|
|
|
log.debug('Unmounting client client.{id}...'.format(id=self.client_id))
|
2017-01-09 12:47:37 +00:00
|
|
|
|
2017-07-19 07:32:37 +00:00
|
|
|
try:
|
2020-01-27 06:07:44 +00:00
|
|
|
cmd=['sudo', 'umount', self.hostfs_mntpt]
|
2020-06-19 06:21:59 +00:00
|
|
|
if force:
|
|
|
|
cmd.append('-f')
|
|
|
|
self.client_remote.run(args=cmd, timeout=(15*60), omit_sudo=False)
|
2017-07-19 07:32:37 +00:00
|
|
|
except Exception as e:
|
2021-06-15 11:16:00 +00:00
|
|
|
log.debug('Killing processes on client.{id}...'.format(id=self.client_id))
|
2020-06-19 06:21:59 +00:00
|
|
|
self.client_remote.run(
|
|
|
|
args=['sudo', run.Raw('PATH=/usr/sbin:$PATH'), 'lsof',
|
|
|
|
run.Raw(';'), 'ps', 'auxf'],
|
|
|
|
timeout=(15*60), omit_sudo=False)
|
2017-07-19 07:32:37 +00:00
|
|
|
raise e
|
2017-01-09 12:47:37 +00:00
|
|
|
|
2014-09-15 22:41:34 +00:00
|
|
|
self.mounted = False
|
2020-03-03 13:31:29 +00:00
|
|
|
self.cleanup()
|
2014-07-17 20:35:22 +00:00
|
|
|
|
2018-05-11 12:26:43 +00:00
|
|
|
def umount_wait(self, force=False, require_clean=False, timeout=900):
|
2014-09-15 22:41:34 +00:00
|
|
|
"""
|
|
|
|
Unlike the fuse client, the kernel client's umount is immediate
|
|
|
|
"""
|
2016-08-30 12:02:28 +00:00
|
|
|
if not self.is_mounted():
|
2020-05-07 12:33:41 +00:00
|
|
|
self.cleanup()
|
2016-08-30 12:02:28 +00:00
|
|
|
return
|
|
|
|
|
2014-09-15 22:41:34 +00:00
|
|
|
try:
|
2017-01-09 12:47:37 +00:00
|
|
|
self.umount(force)
|
2017-02-01 00:25:44 +00:00
|
|
|
except (CommandFailedError, MaxWhileTries):
|
2014-09-15 22:41:34 +00:00
|
|
|
if not force:
|
|
|
|
raise
|
|
|
|
|
2020-03-03 13:31:29 +00:00
|
|
|
# force delete the netns and umount
|
2021-06-15 11:16:00 +00:00
|
|
|
log.debug('Force/lazy unmounting on client.{id}...'.format(id=self.client_id))
|
2020-06-19 06:21:59 +00:00
|
|
|
self.client_remote.run(args=['sudo', 'umount', '-f', '-l',
|
|
|
|
self.mountpoint],
|
|
|
|
timeout=(15*60), omit_sudo=False)
|
2020-03-03 13:31:29 +00:00
|
|
|
|
|
|
|
self.mounted = False
|
|
|
|
self.cleanup()
|
2014-07-17 20:35:22 +00:00
|
|
|
|
|
|
|
def wait_until_mounted(self):
|
2014-09-15 22:41:34 +00:00
|
|
|
"""
|
|
|
|
Unlike the fuse client, the kernel client is up and running as soon
|
|
|
|
as the initial mount() function returns.
|
|
|
|
"""
|
|
|
|
assert self.mounted
|
2014-07-17 20:35:22 +00:00
|
|
|
|
|
|
|
def teardown(self):
|
|
|
|
super(KernelMount, self).teardown()
|
2014-09-15 22:41:34 +00:00
|
|
|
if self.mounted:
|
|
|
|
self.umount()
|
|
|
|
|
2014-10-28 17:12:02 +00:00
|
|
|
def _find_debug_dir(self):
|
2014-09-15 22:41:34 +00:00
|
|
|
"""
|
2014-10-28 17:12:02 +00:00
|
|
|
Find the debugfs folder for this mount
|
2014-09-15 22:41:34 +00:00
|
|
|
"""
|
2014-10-28 17:12:02 +00:00
|
|
|
pyscript = dedent("""
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import json
|
2014-09-15 22:41:34 +00:00
|
|
|
|
2014-10-28 17:12:02 +00:00
|
|
|
def get_id_to_dir():
|
|
|
|
result = {}
|
|
|
|
for dir in glob.glob("/sys/kernel/debug/ceph/*"):
|
|
|
|
mds_sessions_lines = open(os.path.join(dir, "mds_sessions")).readlines()
|
|
|
|
client_id = mds_sessions_lines[1].split()[1].strip('"')
|
|
|
|
|
|
|
|
result[client_id] = dir
|
|
|
|
return result
|
|
|
|
|
2019-10-07 14:09:05 +00:00
|
|
|
print(json.dumps(get_id_to_dir()))
|
2014-10-28 17:12:02 +00:00
|
|
|
""")
|
|
|
|
|
2019-12-16 01:46:13 +00:00
|
|
|
output = self.client_remote.sh([
|
2019-12-19 03:51:52 +00:00
|
|
|
'sudo', 'python3', '-c', pyscript
|
2019-12-16 01:46:13 +00:00
|
|
|
], timeout=(5*60))
|
|
|
|
client_id_to_dir = json.loads(output)
|
2014-09-15 22:41:34 +00:00
|
|
|
|
2014-10-28 17:12:02 +00:00
|
|
|
try:
|
|
|
|
return client_id_to_dir[self.client_id]
|
|
|
|
except KeyError:
|
|
|
|
log.error("Client id '{0}' debug dir not found (clients seen were: {1})".format(
|
|
|
|
self.client_id, ",".join(client_id_to_dir.keys())
|
|
|
|
))
|
|
|
|
raise
|
|
|
|
|
2020-11-16 02:04:27 +00:00
|
|
|
def read_debug_file(self, filename):
|
|
|
|
"""
|
|
|
|
Read the debug file "filename", return None if the file doesn't exist.
|
|
|
|
"""
|
2014-09-15 22:41:34 +00:00
|
|
|
|
2021-06-29 02:21:44 +00:00
|
|
|
path = os.path.join(self._find_debug_dir(), filename)
|
2014-09-15 22:41:34 +00:00
|
|
|
|
2021-06-29 02:21:44 +00:00
|
|
|
stdout = StringIO()
|
2020-11-16 02:04:27 +00:00
|
|
|
stderr = StringIO()
|
|
|
|
try:
|
2021-06-29 02:21:44 +00:00
|
|
|
self.run_shell_payload(f"sudo dd if={path}", timeout=(5*60),
|
|
|
|
stdout=stdout, stderr=stderr)
|
|
|
|
return stdout.getvalue()
|
2020-11-16 02:04:27 +00:00
|
|
|
except CommandFailedError:
|
|
|
|
if 'no such file or directory' in stderr.getvalue().lower():
|
|
|
|
return None
|
|
|
|
raise
|
2014-10-28 17:12:02 +00:00
|
|
|
|
|
|
|
def get_global_id(self):
|
|
|
|
"""
|
|
|
|
Look up the CephFS client ID for this mount, using debugfs.
|
|
|
|
"""
|
|
|
|
|
|
|
|
assert self.mounted
|
|
|
|
|
2020-11-16 02:04:27 +00:00
|
|
|
mds_sessions = self.read_debug_file("mds_sessions")
|
|
|
|
assert mds_sessions
|
|
|
|
|
2014-10-28 17:12:02 +00:00
|
|
|
lines = mds_sessions.split("\n")
|
|
|
|
return int(lines[0].split()[1])
|
|
|
|
|
2020-11-16 05:33:46 +00:00
|
|
|
@property
|
|
|
|
def _global_addr(self):
|
|
|
|
if self.addr is not None:
|
|
|
|
return self.addr
|
|
|
|
|
|
|
|
# The first line of the "status" file's output will be something
|
|
|
|
# like:
|
|
|
|
# "instance: client.4297 (0)10.72.47.117:0/1148470933"
|
|
|
|
# What we need here is only the string "10.72.47.117:0/1148470933"
|
|
|
|
status = self.read_debug_file("status")
|
|
|
|
if status is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
instance = re.findall(r'instance:.*', status)[0]
|
|
|
|
self.addr = instance.split()[2].split(')')[1]
|
|
|
|
return self.addr;
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _global_inst(self):
|
|
|
|
if self.inst is not None:
|
|
|
|
return self.inst
|
|
|
|
|
|
|
|
client_gid = "client%d" % self.get_global_id()
|
|
|
|
self.inst = " ".join([client_gid, self._global_addr])
|
|
|
|
return self.inst
|
|
|
|
|
|
|
|
def get_global_inst(self):
|
|
|
|
"""
|
|
|
|
Look up the CephFS client instance for this mount
|
|
|
|
"""
|
|
|
|
return self._global_inst
|
|
|
|
|
|
|
|
def get_global_addr(self):
|
|
|
|
"""
|
|
|
|
Look up the CephFS client addr for this mount
|
|
|
|
"""
|
|
|
|
return self._global_addr
|
|
|
|
|
2014-10-28 17:12:02 +00:00
|
|
|
def get_osd_epoch(self):
|
|
|
|
"""
|
|
|
|
Return 2-tuple of osd_epoch, osd_epoch_barrier
|
|
|
|
"""
|
2020-11-16 02:04:27 +00:00
|
|
|
osd_map = self.read_debug_file("osdmap")
|
|
|
|
assert osd_map
|
|
|
|
|
2014-10-28 17:12:02 +00:00
|
|
|
lines = osd_map.split("\n")
|
2017-04-09 17:13:29 +00:00
|
|
|
first_line_tokens = lines[0].split()
|
|
|
|
epoch, barrier = int(first_line_tokens[1]), int(first_line_tokens[3])
|
2014-10-28 17:12:02 +00:00
|
|
|
|
2017-04-09 17:13:29 +00:00
|
|
|
return epoch, barrier
|
2020-11-12 06:18:16 +00:00
|
|
|
|
|
|
|
def get_op_read_count(self):
|
|
|
|
buf = self.read_debug_file("metrics")
|
|
|
|
if buf is None:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return int(re.findall(r'read.*', buf)[0].split()[1])
|