Whamcloud - gitweb
EX-8570 lipe: add lpcc sub command to trigger purge scan
authorLei Feng <flei@whamcloud.com>
Wed, 8 Nov 2023 08:01:05 +0000 (16:01 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 9 Nov 2023 09:26:27 +0000 (09:26 +0000)
Add a sub command 'lpcc purge-scan' to trigger purge
scanning by sending SIGUSR2 to matching lpcc_purge
process.

Signed-off-by: Lei Feng <flei@whamcloud.com>
Test-Parameters: trivial
Change-Id: I976621fe787daa15b8206eed97efdebe75cd7425
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53036
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/lipe.spec.in
lipe/lpcc
lipe/man/lpcc-purge-scan.8 [new file with mode: 0644]
lipe/man/lpcc-start.8
lipe/man/lpcc-status.8
lipe/man/lpcc-stop.8
lipe/man/lpcc.8

index 9f2074a..353ba30 100644 (file)
@@ -275,6 +275,7 @@ install -m 0644 man/lpcc.8 $RPM_BUILD_ROOT%{_mandir}/man8/
 install -m 0644 man/lpcc-start.8 $RPM_BUILD_ROOT%{_mandir}/man8/
 install -m 0644 man/lpcc-stop.8 $RPM_BUILD_ROOT%{_mandir}/man8/
 install -m 0644 man/lpcc-status.8 $RPM_BUILD_ROOT%{_mandir}/man8/
+install -m 0644 man/lpcc-purge-scan.8 $RPM_BUILD_ROOT%{_mandir}/man8/
 install -m 0644 man/lpcc.conf.5 $RPM_BUILD_ROOT%{_mandir}/man5/
 %if %{with server}
 install -m 0644 man/lipe_find.1 $RPM_BUILD_ROOT%{_mandir}/man1/
@@ -304,6 +305,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man8/lpcc-start.8*
 %{_mandir}/man8/lpcc-stop.8*
 %{_mandir}/man8/lpcc-status.8*
+%{_mandir}/man8/lpcc-purge-scan.8*
 %{_mandir}/man5/lpcc.conf.5*
 
 %if %{with server}
index eaaa42c..a20bbd8 100755 (executable)
--- a/lipe/lpcc
+++ b/lipe/lpcc
@@ -27,6 +27,7 @@ LISTEN_SOCK = None
 def eprint(*args, **kwargs):
     """print something to stderr"""
     print(*args, file=sys.stderr, **kwargs)
+    sys.stderr.flush()
 
 class LpccService:
     """
@@ -267,6 +268,29 @@ 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
@@ -440,8 +464,8 @@ class LpccMonitor:
                            + 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)
@@ -493,6 +517,26 @@ class LpccMonitor:
         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 = {}
 
@@ -502,8 +546,11 @@ class LpccMonitor:
             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
@@ -642,6 +689,13 @@ def main():
     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')
@@ -704,6 +758,17 @@ def main():
         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
 
diff --git a/lipe/man/lpcc-purge-scan.8 b/lipe/man/lpcc-purge-scan.8
new file mode 100644 (file)
index 0000000..8a06782
--- /dev/null
@@ -0,0 +1,32 @@
+.\" -*- 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)
index 661b3e3..1b922ed 100644 (file)
@@ -8,19 +8,20 @@
 lpcc-start - lpcc start sub command
 
 .SH SYNOPSIS
-.BI "lpcc start MOUNT_POINT [CACHE_DIR]"
+.RI "\fBlpcc start"  " MOUNT_POINT" " [" CACHE_DIR ]
 .PP
 .BI "lpcc start-all"
 .PP
 
 .SH DESCRIPTION
-Start a specific LPCC if both \fBMOUNT_POINT\fR and \fBCAHCE_DIR\fR
+Start a specific LPCC if both \fIMOUNT_POINT\fR and \fICACHE_DIR\fR
 are specified.
 Start all LPCCs based on a specific Lustre file system if only
-\fBMOUNT_POINT\fR are specified.
+\fIMOUNT_POINT\fR are specified.
 \fBstart_all\fR sub command starts all LPCCs in config file.
 .PP
 .SH "SEE ALSO"
 .BR lpcc(8)
 .BR lpcc-stop(8)
 .BR lpcc-status(8)
+.BR lpcc-purge-scan(8)
index 1d2e3e4..5ba0f85 100644 (file)
@@ -8,20 +8,21 @@
 lpcc-status - lpcc status sub command
 
 .SH SYNOPSIS
-.BI "lpcc status [MOUNT_POINT [CACHE_DIR]]"
+.RI "\fBlpcc status" " " [ MOUNT_POINT " [" CACHE_DIR ]]
 .PP
 
 .SH DESCRIPTION
 Get the status of a specific LPCC
-if both \fBMOUNT_POINT\fR and \fBCAHCE_DIR\fR are specified.
+if both \fIMOUNT_POINT\fR and \fICACHE_DIR\fR are specified.
 .PP
 Get the status of all LPCCs based on a specific Lustre file system
-if only \fBMOUNT_POINT\fR are specified.
+if only \fIMOUNT_POINT\fR are specified.
 .PP
 Get the status of all LPCCs in config file
-if neither \fBMOUNT_POINT\fR nor \fBCACHE_DIR\fR is specified.
+if neither \fIMOUNT_POINT\fR nor \fICACHE_DIR\fR is specified.
 .PP
 .SH "SEE ALSO"
 .BR lpcc(8)
 .BR lpcc-start(8)
 .BR lpcc-stop(8)
+.BR lpcc-purge-scan(8)
index cb26524..91d772e 100644 (file)
@@ -8,16 +8,16 @@
 lpcc-stop - lpcc stop sub command
 
 .SH SYNOPSIS
-.BI "lpcc stop MOUNT_POINT [CACHE_DIR] [OPTIONS]"
+.RI "\fBlpcc stop " MOUNT_POINT " [" CACHE_DIR "] [" OPTIONS ]
 .PP
 .BI "lpcc stop-all"
 .PP
 
 .SH DESCRIPTION
-Stop a specific LPCC if both \fBMOUNT_POINT\fR and \fBCAHCE_DIR\fR
+Stop a specific LPCC if both \fIMOUNT_POINT\fR and \fICACHE_DIR\fR
 are specified.
 Stop all LPCCs based on a specific Lustre file system if only
-\fBMOUNT_POINT\fR are specified.
+\fIMOUNT_POINT\fR are specified.
 \fBstop_all\fR sub command stops all LPCCs in config file.
 .PP
 .SH OPTIONS
@@ -32,3 +32,4 @@ file system is mounted again.
 .BR lpcc(8)
 .BR lpcc-start(8)
 .BR lpcc-status(8)
+.BR lpcc-purge-scan(8)
index c32f609..9d20e87 100644 (file)
@@ -8,9 +8,9 @@
 lpcc - Management tool for Lustre Persistent Client Cache (LPCC)
 
 .SH SYNOPSIS
-.BI "lpcc -h|--help"
+.BR lpcc " [" -h|--help ]
 .PP
-.BI "lpcc SUBCMD ARGS"
+.BI lpcc " SUBCMD ARGS"
 .PP
 
 .SH DESCRIPTION
@@ -49,8 +49,8 @@ based on that file system and starts it. If a lustre file system is unmounted,
 it before doing the real umounting.
 .PP
 While the monitor daemon is running, user can manually start/stop one specific
-LPCC by \fImount_point\fR and \fIcache_dir\fR, or all LPCCs based on a
-specific \fImount_point\fR.
+LPCC by \fIMOUNT_POINT\fR and \fICACHE_DIR\fR, or all LPCCs based on a
+specific \fIMOUNT_POINT\fR.
 .PP
 All these LPCCs will be stopped when the monitor daemon stops.
 .SH "SEE ALSO"
@@ -58,4 +58,5 @@ All these LPCCs will be stopped when the monitor daemon stops.
 .BR lpcc-start(8)
 .BR lpcc-stop(8)
 .BR lpcc-status(8)
+.BR lpcc-purge-scan(8)
 .BR lctl-pcc(8)