def eprint(*args, **kwargs):
"""print something to stderr"""
print(*args, file=sys.stderr, **kwargs)
+ sys.stderr.flush()
class LpccService:
"""
return result
+ def purge_scan(self):
+ """
+ trigger purge scan for a PCC device
+ """
+ eprint("Trigger purge scan...")
+ self._dump_config()
+
+ result = {}
+ result['mount'] = self.lpcc_mount
+ result['cache'] = self.lpcc_cache
+
+ pidfile = '/var/run/lpcc_purge-%d.pid' % self.lpcc_roid
+ with open(pidfile) as f:
+ pid = f.read().replace('\n', '')
+ eprint("send SIGUSR2 to pid %s..." % pid)
+
+ cmdline = ['pkill', '--signal', 'USR2', '--pidfile', pidfile, '--', 'lpcc_purge']
+ subprocess.call(cmdline)
+
+ eprint("Done")
+ eprint()
+ return result
+
def is_running(self):
"""
Check the status of PCC, return True if PCC is started, or False
+ result.get('pcc_hit_bytes', 0) \
- result.get('pcc_attach_bytes', 0)
real_hit_bytes = result.get('pcc_hit_bytes', 0)
- result['pcc_real_hit_bytes'] = real_hit_bytes;
- result['total_read_bytes'] = total_read_bytes;
+ result['pcc_real_hit_bytes'] = real_hit_bytes
+ result['total_read_bytes'] = total_read_bytes
result.pop('read_bytes', None)
result.pop('pcc_hit_bytes', None)
result.pop('pcc_attach_bytes', None)
response['status_list'] = self._group_status_list(status_list)
return response
+ def _purge_scan_pcc(self, request):
+ response = {}
+ response['trigger'] = []
+ mount = request.get('mount')
+ cache = request.get('cache')
+
+ for lpcc_config in self.config_obj:
+ if mount is not None and mount != lpcc_config['mount']:
+ continue
+ if cache is not None and cache != lpcc_config['cache']:
+ continue
+
+ lpcc_service = LpccService(lpcc_config)
+ if not lpcc_service.is_stopped():
+ resp = lpcc_service.purge_scan()
+ response['trigger'].append(resp)
+
+ response['retcode'] = 0
+ return response
+
def _process_cmd(self, request):
response = {}
response = self._stop_pcc(request)
elif request['action'] == 'status' or request['action'] == 'status-all':
response = self._status_pcc(request)
+ elif request['action'] == 'purge-scan':
+ response = self._purge_scan_pcc(request)
else:
response['retcode'] = -1
+ response['error_msg'] = "no such command"
response['request'] = request
return response
status_parser.add_argument('cache', nargs='?', help=\
'the cache dir of LPCC')
+ purge_scan_parser = subparsers.add_parser('purge-scan', help=\
+ 'trigger purge scanning of LPCC cache device')
+ purge_scan_parser.add_argument('mount', nargs='?', help=\
+ 'the mount point of lustre file system')
+ purge_scan_parser.add_argument('cache', nargs='?', help=\
+ 'the cache dir of LPCC')
+
subparsers.add_parser('start-all', help='start all LPCCs')
subparsers.add_parser('stop-all', help='stop all LPCCs')
subparsers.add_parser('status-all', help='get the status of all LPCCs')
print(json.dumps(response['status_list'], indent=4))
return response['retcode']
+ if args.action == 'purge-scan':
+ request = {}
+ request['action'] = args.action
+ request['mount'] = args.mount
+ request['cache'] = args.cache
+
+ response = LpccCli().run_cmd(request)
+
+ print(response)
+ return response['retcode']
+
eprint("Type 'lpcc -h' for more information.")
return 1
--- /dev/null
+.\" -*- nroff -*-
+.\" Copyright (c) 2023, DDN and/or its affiliates. All rights reserved.
+.\" This file may be copied under the terms of the GNU Public License, v2.
+.\"
+.TH lpcc-purge-scan 8 "2023 Nov 9" Lustre "configuration utilities"
+
+.SH NAME
+lpcc-purge-scan - lpcc purge-scan sub command
+
+.SH SYNOPSIS
+.RI "\fBlpcc purge-scan" " " [ MOUNT_POINT " [" CACHE_DIR ]]
+.PP
+
+.SH DESCRIPTION
+Trigger force scanning of a specific LPCC
+if both \fIMOUNT_POINT\fR and \fICACHE_DIR\fR are specified.
+.PP
+Trigger force scanning of all LPCCs based on a specific Lustre file system
+if only \fIMOUNT_POINT\fR are specified.
+.PP
+Trigger force scanning of all LPCCs in config file
+if neither \fIMOUNT_POINT\fR nor \fICACHE_DIR\fR is specified.
+.PP
+To know whether the scanning ends, run \fBlpcc status\fR and check the value of
+field \fBend_time_secs\fR. \fB0\fR means the scanning is still running.
+
+.PP
+.SH "SEE ALSO"
+.BR lpcc(8)
+.BR lpcc-start(8)
+.BR lpcc-stop(8)
+.BR lpcc-status(8)