Skip to contentSkip to conversation

nfsdctl: check for listeners before starting threads

PATCH In review Olga Kornievskaia 2 participants 2 messages Mar 23 – Mar 29

Subsystems (2)
lore
Share & tools
lore

Olga Kornievskaia

author reviewer
#0 lore raw

PATCH v2 1/1 nfsdctl: check for listeners before starting threads

When a thread command is executed and yet no listeners have been added prior to it, instead of failing with EIO error print an informative error. Also, "thread 0" command should not error regardless of the listener status.

---
 utils/nfsdctl/nfsdctl.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
utils/nfsdctl/nfsdctl.c +22 -0
index 6a20d180..ac23e753 100644
@@ -162,6 +162,8 @@ static const char *nfsd4_ops[] = {
 	[OP_REMOVEXATTR]	= "OP_REMOVEXATTR",
 };
 
+static int fetch_current_listeners(struct nl_sock *sock);
+
 static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
 			 void *arg)
 {
@@ -721,6 +723,7 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
 	int *pool_threads = NULL;
 	int minthreads = -1;
 	int opt, pools = 0;
+	bool zero_threads = false;
 
 	optind = 1;
 	while ((opt = getopt_long(argc, argv, "hm:", threads_options, NULL)) != -1) {
@@ -762,12 +765,31 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
 			}
 
 			pool_threads[i] = strtol(targv[i], &endptr, 0);
+			if (!pool_threads[i])
+				zero_threads = true;
 			if (!endptr || *endptr != '\0') {
 				xlog(L_ERROR, "Invalid threads value %s.", argv[1]);
 				return 1;
 			}
 		}
 	}
+	/* check if there are active listeners added */
+	if (fetch_current_listeners(sock)) {
+		xlog(L_ERROR, "Unable to determine if listeners were added");
+		return 1;
+	}
+	if (!nfsd_socket_count) {
+		if (zero_threads) {
+			/* Note: we can never have a server with threads and no
+			 * listener. If we ever add functionality to remove
+			 * listeners on an active server, we need to revisit this.
+			 */
+			return 0;
+		}
+		xlog(L_ERROR, "No active listeners added, not starting threads");
+		return 1;
+	}
+
 	return threads_doit(sock, cmd, 0, 0, pools, pool_threads, NULL, minthreads);
 }
 
Signature · 1 line
2.52.0
#1 lore raw
Quoted 6 lines · Olga Kornievskaia

When a thread command is executed and yet no listeners have been added prior to it, instead of failing with EIO error print an informative error. Also, "thread 0" command should not error regardless of the listener status.

Committed... (tag: nfs-utils-2-9-1-rc2)

steved.

Quoted 57 lines
---
  utils/nfsdctl/nfsdctl.c | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)
utils/nfsdctl/nfsdctl.c +22 -0
index 6a20d180..ac23e753 100644
@@ -162,6 +162,8 @@ static const char *nfsd4_ops[] = {
  	[OP_REMOVEXATTR]	= "OP_REMOVEXATTR",
  };
 
+static int fetch_current_listeners(struct nl_sock *sock);
+
  static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
  			 void *arg)
  {
@@ -721,6 +723,7 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
  	int *pool_threads = NULL;
  	int minthreads = -1;
  	int opt, pools = 0;
+	bool zero_threads = false;
 
  	optind = 1;
  	while ((opt = getopt_long(argc, argv, "hm:", threads_options, NULL)) != -1) {
@@ -762,12 +765,31 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
  			}
 
  			pool_threads[i] = strtol(targv[i], &endptr, 0);
+			if (!pool_threads[i])
+				zero_threads = true;
  			if (!endptr || *endptr != '\0') {
  				xlog(L_ERROR, "Invalid threads value %s.", argv[1]);
  				return 1;
  			}
  		}
  	}
+	/* check if there are active listeners added */
+	if (fetch_current_listeners(sock)) {
+		xlog(L_ERROR, "Unable to determine if listeners were added");
+		return 1;
+	}
+	if (!nfsd_socket_count) {
+		if (zero_threads) {
+			/* Note: we can never have a server with threads and no
+			 * listener. If we ever add functionality to remove
+			 * listeners on an active server, we need to revisit this.
+			 */
+			return 0;
+		}
+		xlog(L_ERROR, "No active listeners added, not starting threads");
+		return 1;
+	}
+
  	return threads_doit(sock, cmd, 0, 0, pools, pool_threads, NULL, minthreads);
  }