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