From 8878630c20163dc9b716e2fdc35cae23b8aec6d1 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Tue, 14 Jun 2022 15:30:49 +0800
Subject: [PATCH 21/30] set the name of each container and image operation
 thread

Signed-off-by: wujing <wujing50@huawei.com>
---
 .../connect/grpc/grpc_containers_service.cc   | 54 +++++++++++++++++++
 .../entry/connect/grpc/grpc_images_service.cc | 16 ++++++
 2 files changed, 70 insertions(+)

diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.cc b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
index f3066af4..62aeb05a 100644
--- a/src/daemon/entry/connect/grpc/grpc_containers_service.cc
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
@@ -153,6 +153,8 @@ Status ContainerServiceImpl::Version(ServerContext *context, const VersionReques
     container_version_request *container_req = nullptr;
     container_version_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "VersionOp");
+
     auto status = GrpcServerTlsAuth::auth(context, "docker_version");
     if (!status.ok()) {
         return status;
@@ -185,6 +187,8 @@ Status ContainerServiceImpl::Info(ServerContext *context, const InfoRequest *req
     host_info_request *container_req = nullptr;
     host_info_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "InfoOp");
+
     auto status = GrpcServerTlsAuth::auth(context, "docker_info");
     if (!status.ok()) {
         return status;
@@ -217,6 +221,8 @@ Status ContainerServiceImpl::Create(ServerContext *context, const CreateRequest
     container_create_response *container_res = nullptr;
     container_create_request *container_req = nullptr;
 
+    prctl(PR_SET_NAME, "ContCreate");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_create");
     if (!status.ok()) {
         return status;
@@ -249,6 +255,8 @@ Status ContainerServiceImpl::Start(ServerContext *context, const StartRequest *r
     container_start_request *req = nullptr;
     container_start_response *res = nullptr;
 
+    prctl(PR_SET_NAME, "ContStart");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_start");
     if (!status.ok()) {
         return status;
@@ -327,6 +335,8 @@ Status ContainerServiceImpl::RemoteStart(ServerContext *context,
     container_start_response *container_res = nullptr;
     sem_t sem;
 
+    prctl(PR_SET_NAME, "ContRStart");
+
     cb = get_service_executor();
     if (cb == nullptr || cb->container.start == nullptr) {
         return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
@@ -402,6 +412,8 @@ Status ContainerServiceImpl::Top(ServerContext *context, const TopRequest *reque
     container_top_request *req = nullptr;
     container_top_response *res = nullptr;
 
+    prctl(PR_SET_NAME, "ContTop");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_top");
     if (!status.ok()) {
         return status;
@@ -434,6 +446,8 @@ Status ContainerServiceImpl::Stop(ServerContext *context, const StopRequest *req
     container_stop_request *container_req = nullptr;
     container_stop_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContStop");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_stop");
     if (!status.ok()) {
         return status;
@@ -466,6 +480,8 @@ Status ContainerServiceImpl::Restart(ServerContext *context, const RestartReques
     container_restart_request *container_req = nullptr;
     container_restart_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContRestart");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_restart");
     if (!status.ok()) {
         return status;
@@ -498,6 +514,8 @@ Status ContainerServiceImpl::Kill(ServerContext *context, const KillRequest *req
     container_kill_request *container_req = nullptr;
     container_kill_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContKill");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_kill");
     if (!status.ok()) {
         return status;
@@ -530,6 +548,8 @@ Status ContainerServiceImpl::Delete(ServerContext *context, const DeleteRequest
     container_delete_request *container_req = nullptr;
     container_delete_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContDelete");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_delete");
     if (!status.ok()) {
         return status;
@@ -562,6 +582,8 @@ Status ContainerServiceImpl::Exec(ServerContext *context, const ExecRequest *req
     container_exec_request *container_req = nullptr;
     container_exec_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContExec");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_exec_create");
     if (!status.ok()) {
         return status;
@@ -665,6 +687,8 @@ Status ContainerServiceImpl::RemoteExec(ServerContext *context,
     container_exec_request *container_req = nullptr;
     container_exec_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContRExec");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_exec_create");
     if (!status.ok()) {
         return status;
@@ -739,6 +763,8 @@ Status ContainerServiceImpl::Inspect(ServerContext *context, const InspectContai
     container_inspect_request *container_req = nullptr;
     container_inspect_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContInspect");
+
     Status status = GrpcServerTlsAuth::auth(context, "container_inspect");
     if (!status.ok()) {
         return status;
@@ -772,6 +798,8 @@ Status ContainerServiceImpl::List(ServerContext *context, const ListRequest *req
     container_list_request *container_req = nullptr;
     container_list_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContList");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_list");
     if (!status.ok()) {
         return status;
@@ -884,6 +912,8 @@ Status ContainerServiceImpl::Attach(ServerContext *context, ServerReaderWriter<A
     sem_t sem_stderr;
     int pipefd[2] = { -1, -1 };
 
+    prctl(PR_SET_NAME, "ContAttach");
+
     auto status = AttachInit(context, &cb, &container_req, &container_res, &sem_stderr, pipefd);
     if (!status.ok()) {
         return status;
@@ -944,6 +974,8 @@ Status ContainerServiceImpl::Pause(ServerContext *context, const PauseRequest *r
     container_pause_request *container_req = nullptr;
     container_pause_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContPause");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_pause");
     if (!status.ok()) {
         return status;
@@ -976,6 +1008,8 @@ Status ContainerServiceImpl::Resume(ServerContext *context, const ResumeRequest
     container_resume_request *container_req = nullptr;
     container_resume_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContResume");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_unpause");
     if (!status.ok()) {
         return status;
@@ -1008,6 +1042,8 @@ Status ContainerServiceImpl::Export(ServerContext *context, const ExportRequest
     container_export_request *container_req = nullptr;
     container_export_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContExport");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_export");
     if (!status.ok()) {
         return status;
@@ -1040,6 +1076,8 @@ Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest
     struct isulad_container_rename_request *isuladreq = nullptr;
     struct isulad_container_rename_response *isuladres = nullptr;
 
+    prctl(PR_SET_NAME, "ContRename");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_rename");
     if (!status.ok()) {
         return status;
@@ -1073,6 +1111,8 @@ Status ContainerServiceImpl::Resize(ServerContext *context, const ResizeRequest
     struct isulad_container_resize_request *isuladreq = nullptr;
     struct isulad_container_resize_response *isuladres = nullptr;
 
+    prctl(PR_SET_NAME, "ContResize");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_resize");
     if (!status.ok()) {
         return status;
@@ -1106,6 +1146,8 @@ Status ContainerServiceImpl::Update(ServerContext *context, const UpdateRequest
     container_update_request *container_req = nullptr;
     container_update_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContUpdate");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_update");
     if (!status.ok()) {
         return status;
@@ -1138,6 +1180,8 @@ Status ContainerServiceImpl::Stats(ServerContext *context, const StatsRequest *r
     container_stats_request *container_req = nullptr;
     container_stats_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContStats");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_stats");
     if (!status.ok()) {
         return status;
@@ -1170,6 +1214,8 @@ Status ContainerServiceImpl::Wait(ServerContext *context, const WaitRequest *req
     container_wait_request *container_req = nullptr;
     container_wait_response *container_res = nullptr;
 
+    prctl(PR_SET_NAME, "ContWait");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_wait");
     if (!status.ok()) {
         return status;
@@ -1202,6 +1248,8 @@ Status ContainerServiceImpl::Events(ServerContext *context, const EventsRequest
     isulad_events_request *isuladreq = nullptr;
     stream_func_wrapper stream = { 0 };
 
+    prctl(PR_SET_NAME, "ContEvents");
+
     auto status = GrpcServerTlsAuth::auth(context, "docker_events");
     if (!status.ok()) {
         return status;
@@ -1238,6 +1286,8 @@ Status ContainerServiceImpl::CopyFromContainer(ServerContext *context, const Cop
     service_executor_t *cb = nullptr;
     isulad_copy_from_container_request *isuladreq = nullptr;
 
+    prctl(PR_SET_NAME, "ContCopyFrom");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_archive");
     if (!status.ok()) {
         return status;
@@ -1280,6 +1330,8 @@ ContainerServiceImpl::CopyToContainer(ServerContext *context,
     service_executor_t *cb = nullptr;
     container_copy_to_request *isuladreq = nullptr;
 
+    prctl(PR_SET_NAME, "ContCopyTo");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_archive");
     if (!status.ok()) {
         return status;
@@ -1387,6 +1439,8 @@ Status ContainerServiceImpl::Logs(ServerContext *context, const LogsRequest *req
     struct isulad_logs_response *isulad_response = nullptr;
     stream_func_wrapper stream = { 0 };
 
+    prctl(PR_SET_NAME, "ContLogs");
+
     auto status = GrpcServerTlsAuth::auth(context, "container_logs");
     if (!status.ok()) {
         return status;
diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.cc b/src/daemon/entry/connect/grpc/grpc_images_service.cc
index dff07b39..79c4fb7c 100644
--- a/src/daemon/entry/connect/grpc/grpc_images_service.cc
+++ b/src/daemon/entry/connect/grpc/grpc_images_service.cc
@@ -248,6 +248,8 @@ void ImagesServiceImpl::inspect_response_to_grpc(const image_inspect_response *r
 
 Status ImagesServiceImpl::List(ServerContext *context, const ListImagesRequest *request, ListImagesResponse *reply)
 {
+    prctl(PR_SET_NAME, "ImageList");
+
     auto status = GrpcServerTlsAuth::auth(context, "image_list");
     if (!status.ok()) {
         return status;
@@ -277,6 +279,8 @@ Status ImagesServiceImpl::List(ServerContext *context, const ListImagesRequest *
 
 Status ImagesServiceImpl::Delete(ServerContext *context, const DeleteImageRequest *request, DeleteImageResponse *reply)
 {
+    prctl(PR_SET_NAME, "ImageDelete");
+
     auto status = GrpcServerTlsAuth::auth(context, "image_delete");
     if (!status.ok()) {
         return status;
@@ -306,6 +310,8 @@ Status ImagesServiceImpl::Delete(ServerContext *context, const DeleteImageReques
 
 Status ImagesServiceImpl::Tag(ServerContext *context, const TagImageRequest *request, TagImageResponse *reply)
 {
+    prctl(PR_SET_NAME, "ImageTag");
+
     auto status = GrpcServerTlsAuth::auth(context, "image_tag");
     if (!status.ok()) {
         return status;
@@ -351,6 +357,8 @@ void ImagesServiceImpl::import_response_to_grpc(const image_import_response *res
 
 Status ImagesServiceImpl::Import(ServerContext *context, const ImportRequest *request, ImportResponse *reply)
 {
+    prctl(PR_SET_NAME, "ImageImport");
+
     auto status = GrpcServerTlsAuth::auth(context, "image_import");
     if (!status.ok()) {
         return status;
@@ -380,6 +388,8 @@ Status ImagesServiceImpl::Import(ServerContext *context, const ImportRequest *re
 
 Status ImagesServiceImpl::Load(ServerContext *context, const LoadImageRequest *request, LoadImageResponse *reply)
 {
+    prctl(PR_SET_NAME, "ImageLoad");
+
     auto status = GrpcServerTlsAuth::auth(context, "image_load");
     if (!status.ok()) {
         return status;
@@ -415,6 +425,8 @@ Status ImagesServiceImpl::Inspect(ServerContext *context, const InspectImageRequ
     image_inspect_request *image_req = nullptr;
     image_inspect_response *image_res = nullptr;
 
+    prctl(PR_SET_NAME, "ImageInspect");
+
     Status status = GrpcServerTlsAuth::auth(context, "image_inspect");
     if (!status.ok()) {
         return status;
@@ -487,6 +499,8 @@ int ImagesServiceImpl::image_logout_request_from_grpc(const LogoutRequest *grequ
 
 Status ImagesServiceImpl::Login(ServerContext *context, const LoginRequest *request, LoginResponse *reply)
 {
+    prctl(PR_SET_NAME, "RegistryLogin");
+
     auto status = GrpcServerTlsAuth::auth(context, "login");
     if (!status.ok()) {
         return status;
@@ -516,6 +530,8 @@ Status ImagesServiceImpl::Login(ServerContext *context, const LoginRequest *requ
 
 Status ImagesServiceImpl::Logout(ServerContext *context, const LogoutRequest *request, LogoutResponse *reply)
 {
+    prctl(PR_SET_NAME, "RegistryLogout");
+
     auto status = GrpcServerTlsAuth::auth(context, "logout");
     if (!status.ok()) {
         return status;
-- 
2.32.1 (Apple Git-133)

