| 14 | |
| 15 | @contextlib.contextmanager |
| 16 | def task(ctx, config): |
| 17 | log.info('Setting up nvme_loop on scratch devices...') |
| 18 | host = 'hostnqn' |
| 19 | port = '1' |
| 20 | devs_by_remote = {} |
| 21 | old_scratch_by_remote = {} |
| 22 | for remote, roles in ctx.cluster.remotes.items(): |
| 23 | if remote.is_container: |
| 24 | continue |
| 25 | devs = teuthology.get_scratch_devices(remote) |
| 26 | devs_by_remote[remote] = devs |
| 27 | base = '/sys/kernel/config/nvmet' |
| 28 | remote.run( |
| 29 | args=[ |
| 30 | 'grep', '^nvme_loop', '/proc/modules', run.Raw('||'), |
| 31 | 'sudo', 'modprobe', 'nvme_loop', |
| 32 | run.Raw('&&'), |
| 33 | 'sudo', 'mkdir', '-p', f'{base}/hosts/{host}', |
| 34 | run.Raw('&&'), |
| 35 | 'sudo', 'mkdir', '-p', f'{base}/ports/{port}', |
| 36 | run.Raw('&&'), |
| 37 | 'echo', 'loop', run.Raw('|'), |
| 38 | 'sudo', 'tee', f'{base}/ports/{port}/addr_trtype', |
| 39 | ] |
| 40 | ) |
| 41 | provide_hostname = True |
| 42 | for dev in devs: |
| 43 | short = dev.split('/')[-1] |
| 44 | log.info(f'Connecting nvme_loop {remote.shortname}:{dev}...') |
| 45 | nvme_connect_args=[ |
| 46 | 'sudo', 'mkdir', '-p', f'{base}/subsystems/{short}', |
| 47 | run.Raw('&&'), |
| 48 | 'echo', '1', run.Raw('|'), |
| 49 | 'sudo', 'tee', f'{base}/subsystems/{short}/attr_allow_any_host', |
| 50 | run.Raw('&&'), |
| 51 | 'sudo', 'mkdir', '-p', f'{base}/subsystems/{short}/namespaces/1', |
| 52 | run.Raw('&&'), |
| 53 | 'echo', '-n', dev, run.Raw('|'), |
| 54 | 'sudo', 'tee', f'{base}/subsystems/{short}/namespaces/1/device_path', |
| 55 | run.Raw('&&'), |
| 56 | 'echo', '1', run.Raw('|'), |
| 57 | 'sudo', 'tee', f'{base}/subsystems/{short}/namespaces/1/enable', |
| 58 | run.Raw('&&'), |
| 59 | 'sudo', 'ln', '-s', f'{base}/subsystems/{short}', |
| 60 | f'{base}/ports/{port}/subsystems/{short}', |
| 61 | run.Raw('&&'), |
| 62 | 'sudo', 'nvme', 'connect', '-t', 'loop', '-n', short |
| 63 | ] |
| 64 | if provide_hostname: |
| 65 | nvme_connect_args.extend(['-q', host]) |
| 66 | try: |
| 67 | remote.run(args=nvme_connect_args) |
| 68 | except Exception: |
| 69 | if provide_hostname: |
| 70 | provide_hostname = False |
| 71 | remote.run(args=['sudo', 'nvme', 'connect', '-t', 'loop', '-n', short]) |
| 72 | else: |
| 73 | raise |