17b94a
From 2e6a5e504e66bc95208420e4882e453a53ac9ea2 Mon Sep 17 00:00:00 2001
17b94a
From: schaffung <ssivakum@redhat.com>
17b94a
Date: Mon, 2 Nov 2020 11:18:01 +0530
17b94a
Subject: [PATCH 485/511] cli-rpc: conditional init of global quota rpc (#1578)
17b94a
17b94a
Issue: It is seem that the initialization of rpc to
17b94a
connect with quotad is done in every glusterfs cli command,
17b94a
irrespective of whether the quota feature is enabled or disabled.
17b94a
This seems to be an overkill.
17b94a
17b94a
Code change: The file /var/run/quotad/quotad.pid is present
17b94a
signals that quotad is enabled. Hence we can put a conditional
17b94a
check for seeing when this file exists and if it doesn't we
17b94a
just skip over the initialization of the global quotad rpc.
17b94a
17b94a
This will go on to reduce the extra rpc calls and operations
17b94a
being performed in the kernel space.
17b94a
17b94a
>Fixes: #1577
17b94a
>Change-Id: Icb69d35330f76ce95626f59af75a12726eb620ff
17b94a
>Signed-off-by: srijan-sivakumar <ssivakumar@redhat.com>
17b94a
Upstream Patch : https://github.com/gluster/glusterfs/pull/1578
17b94a
17b94a
BUG: 1885966
17b94a
Change-Id: Icb69d35330f76ce95626f59af75a12726eb620ff
17b94a
Signed-off-by: Srijan Sivakumar <ssivakum@redhat.com>
17b94a
Reviewed-on: https://code.engineering.redhat.com/gerrit/220371
17b94a
Tested-by: RHGS Build Bot <nigelb@redhat.com>
17b94a
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
17b94a
---
17b94a
 cli/src/cli.c | 18 +++++++++++++-----
17b94a
 cli/src/cli.h |  3 +++
17b94a
 2 files changed, 16 insertions(+), 5 deletions(-)
17b94a
17b94a
diff --git a/cli/src/cli.c b/cli/src/cli.c
17b94a
index 99a16a0..a76c5a2 100644
17b94a
--- a/cli/src/cli.c
17b94a
+++ b/cli/src/cli.c
17b94a
@@ -64,8 +64,7 @@
17b94a
 extern int connected;
17b94a
 /* using argp for command line parsing */
17b94a
 
17b94a
-const char *argp_program_version =
17b94a
-    PACKAGE_NAME" "PACKAGE_VERSION;
17b94a
+const char *argp_program_version = PACKAGE_NAME " " PACKAGE_VERSION;
17b94a
 const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
17b94a
 
17b94a
 struct rpc_clnt *global_quotad_rpc;
17b94a
@@ -840,9 +839,18 @@ main(int argc, char *argv[])
17b94a
     if (!global_rpc)
17b94a
         goto out;
17b94a
 
17b94a
-    global_quotad_rpc = cli_quotad_clnt_rpc_init();
17b94a
-    if (!global_quotad_rpc)
17b94a
-        goto out;
17b94a
+    /*
17b94a
+     * Now, one doesn't need to initialize global rpc
17b94a
+     * for quota unless and until quota is enabled.
17b94a
+     * So why not put a check to save all the rpc related
17b94a
+     * ops here.
17b94a
+     */
17b94a
+    ret = sys_access(QUOTAD_PID_PATH, F_OK);
17b94a
+    if (!ret) {
17b94a
+        global_quotad_rpc = cli_quotad_clnt_rpc_init();
17b94a
+        if (!global_quotad_rpc)
17b94a
+            goto out;
17b94a
+    }
17b94a
 
17b94a
     ret = cli_cmds_register(&state);
17b94a
     if (ret)
17b94a
diff --git a/cli/src/cli.h b/cli/src/cli.h
17b94a
index 37e4d9d..c30ae9c 100644
17b94a
--- a/cli/src/cli.h
17b94a
+++ b/cli/src/cli.h
17b94a
@@ -30,6 +30,9 @@
17b94a
 #define CLI_TAB_LENGTH 8
17b94a
 #define CLI_BRICK_STATUS_LINE_LEN 78
17b94a
 
17b94a
+// Quotad pid path.
17b94a
+#define QUOTAD_PID_PATH "/var/run/gluster/quotad/quotad.pid"
17b94a
+
17b94a
 /* Geo-rep command positional arguments' index  */
17b94a
 #define GEO_REP_CMD_INDEX 1
17b94a
 #define GEO_REP_CMD_CONFIG_INDEX 4
17b94a
-- 
17b94a
1.8.3.1
17b94a