From nobody Tue Nov 03 12:17:30 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jJndW6Wyxz6y3W8 for ; Tue, 03 Nov 2026 12:17:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jJndW56N7z4s6M for ; Tue, 03 Nov 2026 12:17:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793708255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pP5w5MqBQKGV+xMzzx0x8Fmdo3vyo7q39yzd5f/7xYk=; b=SJNbk+T0b3YhxaxPQt+TNj+iFrAFu9B5w7ibUBh0d4GUxo4DhBz2M8DWwyg/APxVpvIHxI QV6VtgN4yGrnUUZ5mimSj9KYQxTFUdaWVD6dVoGJZ6NEwSpRJaFwDQyANPB5vkoyR4wOVP fAVk3u4KMhDQ+M4QpIq+cBr6xcrJoOD/RtR5VSuprLyhjC2K7IywaHFFqet9aoPinyLgVp EpUiOPm1o28x7N8oKh1DBRGWOT+3tYUsUpeF6xLh1RMFkBZPBFjgEVXq6ZMgxnbFFE2Imu k0jHgOXZQfoS8JybWCRyu7kmpOOmf7WgYS7uHLhfLgT5Dl4gijuzgRd8Ec+WnA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793708255; b=ivrT3vm/wycyZYEvLHQo5FsZVFwY1E2AAxGavjit2poCTsItAQjxNlUuZYP5cumiXS46Qz 5x7fvjda49w2CPLSujcOjItg5wOvbrSbZ1lLYOFS91L+zns0RKojy9TVtNW2Ap2lbIyLhy SRR11+6hPmA3MaSbv3N7yAub267vlU1XEnlA/WH8eA+SEhjluK6bULnL4F3VADYfXBXjcK W3GgL1GmwniZ26rm0LkU6Tmc40Qpjc+vPQbTeQFqwYeUbrQOE6F8vjDcVxW6fvBXvrsRXG e5LALaSFl+UiT2146ZyS63G3amwSrO8loXKlqf5HD9qX4DS06miRP7L7hT8IkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793708255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pP5w5MqBQKGV+xMzzx0x8Fmdo3vyo7q39yzd5f/7xYk=; b=FhYE70X8GGuJg4rhGLzZFUvyadWNQsgtr4oLH/nBx3t85EqhTnpad+tOQ5q99eZsWHl4Ge 2K5QjGddAGVx7jaU3IlKLXvXAGra1UJg8BhWNZWfRbAAboe73Wb0qZ7i9h4LgV0aytQ9tX 38X6d18LV3dWHsfJDgWBPOF5HLvwYWaMJfVzTDjz9DqQbUJTHN6Ly7VGHq5bVfoV4Opisk AMOPGB9F79jqTTO5s1+wdyvh+Q8i052jikSDxWzQSTBe6KsognUvWOJIUeAS2jX+pOu1EW 3rSn5R22pRgj3gMGAhpTE34VXO1mtRWLWliXcGuhRddm0ZeIzBvsPG8jO7PpjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jJndW4gb2zG5b for ; Tue, 03 Nov 2026 12:17:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3151d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 03 Nov 2026 12:17:30 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: a4c5803ecd03 - main - hastd: Allow overriding the node name List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a4c5803ecd03d3a95eedd3bd988f89784ec1a8d4 Auto-Submitted: auto-generated Date: Tue, 03 Nov 2026 12:17:30 +0000 Message-Id: <6ae9d0da.3151d.338fa2d6@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=a4c5803ecd03d3a95eedd3bd988f89784ec1a8d4 commit a4c5803ecd03d3a95eedd3bd988f89784ec1a8d4 Author: Dag-Erling Smørgrav AuthorDate: 2026-11-03 12:07:29 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-11-03 12:07:29 +0000 hastd: Allow overriding the node name Normally, hastd will use the hostname, hostuuid, or hostid as node name. Allow overriding this with a new -n command-line option. The argument is treated as a replacement for the hostname, but also disables the hostuuid and hostid logic. This allows running multiple nodes on the same system, which is useful for testing. Differential Revision: https://reviews.freebsd.org/D59675 --- sbin/hastctl/hastctl.8 | 12 +++++++++++- sbin/hastctl/hastctl.c | 30 ++++++++++++++++++------------ sbin/hastd/hast.h | 2 ++ sbin/hastd/hastd.8 | 8 +++++++- sbin/hastd/hastd.c | 11 ++++++++--- sbin/hastd/parse.y | 46 +++++++++++++++++++++++++++++++++++++++------- 6 files changed, 85 insertions(+), 24 deletions(-) diff --git a/sbin/hastctl/hastctl.8 b/sbin/hastctl/hastctl.8 index f696858a8071..219b1f9dc3d0 100644 --- a/sbin/hastctl/hastctl.8 +++ b/sbin/hastctl/hastctl.8 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 8, 2016 +.Dd October 1, 2026 .Dt HASTCTL 8 .Os .Sh NAME @@ -38,27 +38,32 @@ .Op Fl e Ar extentsize .Op Fl k Ar keepdirty .Op Fl m Ar mediasize +.Op Fl n Ar nodename .Ar name ... .Nm .Cm role .Op Fl d .Op Fl c Ar config +.Op Fl n Ar nodename .Aq init | primary | secondary .Ar all | name ... .Nm .Cm list .Op Fl d .Op Fl c Ar config +.Op Fl n Ar nodename .Op Ar all | name ... .Nm .Cm status .Op Fl d .Op Fl c Ar config +.Op Fl n Ar nodename .Op Ar all | name ... .Nm .Cm dump .Op Fl d .Op Fl c Ar config +.Op Fl n Ar nodename .Op Ar all | name ... .Sh DESCRIPTION The @@ -114,6 +119,11 @@ dirty is Size of the smaller provider used as backend storage on both nodes. This option can be omitted if node providers have the same size on both sides. +.It Fl n Ar nodename +Specify a node name to use instead of the current host name as +returned by +.Xr gethostname 3 . +This is mostly useful for testing. .El .Pp If size is suffixed with a k, M, G or T, it is taken as a kilobyte, diff --git a/sbin/hastctl/hastctl.c b/sbin/hastctl/hastctl.c index 229af1dae74d..788c22572a67 100644 --- a/sbin/hastctl/hastctl.c +++ b/sbin/hastctl/hastctl.c @@ -66,22 +66,25 @@ enum { static __dead2 void usage(void) { - fprintf(stderr, "usage: %s create [-d] [-c config] [-e extentsize] [-k keepdirty]\n" - "\t\t[-m mediasize] name ...\n", + "\t\t[-m mediasize] [-n nodename] name ...\n", getprogname()); fprintf(stderr, - " %s role [-d] [-c config] all | name ...\n", + " %s role [-d] [-c config] [-n nodename] " + " all | name ...\n", getprogname()); fprintf(stderr, - " %s list [-d] [-c config] [all | name ...]\n", + " %s list [-d] [-c config] [-n nodename] " + "[all | name ...]\n", getprogname()); fprintf(stderr, - " %s status [-d] [-c config] [all | name ...]\n", + " %s status [-d] [-c config] [-n nodename] " + "[all | name ...]\n", getprogname()); fprintf(stderr, - " %s dump [-d] [-c config] [all | name ...]\n", + " %s dump [-d] [-c config] [-n nodename] " + "[all | name ...]\n", getprogname()); exit(EX_USAGE); } @@ -418,22 +421,22 @@ main(int argc, char *argv[]) if (strcmp(argv[1], "create") == 0) { cmd = CMD_CREATE; - optstr = "c:de:k:m:h"; + optstr = "c:de:hk:m:n:"; } else if (strcmp(argv[1], "role") == 0) { cmd = CMD_ROLE; - optstr = "c:dh"; + optstr = "c:dhn:"; } else if (strcmp(argv[1], "list") == 0) { cmd = CMD_LIST; - optstr = "c:dh"; + optstr = "c:dhn:"; } else if (strcmp(argv[1], "status") == 0) { cmd = CMD_STATUS; - optstr = "c:dh"; + optstr = "c:dhn:"; } else if (strcmp(argv[1], "dump") == 0) { cmd = CMD_DUMP; - optstr = "c:dh"; + optstr = "c:dhn:"; } else if (strcmp(argv[1], "stop") == 0) { cmd = CMD_STOP; - optstr = "c:dh"; + optstr = "c:dhn:"; } else usage(); @@ -465,6 +468,9 @@ main(int argc, char *argv[]) if (expand_number(optarg, &mediasize) == -1) errx(EX_USAGE, "Invalid mediasize"); break; + case 'n': + nodename = optarg; + break; case 'h': default: usage(); diff --git a/sbin/hastd/hast.h b/sbin/hastd/hast.h index a91993fc398e..2a23944d0af6 100644 --- a/sbin/hastd/hast.h +++ b/sbin/hastd/hast.h @@ -267,4 +267,6 @@ struct hast_resource { struct hastd_config *yy_config_parse(const char *config, bool exitonerror); void yy_config_free(struct hastd_config *config); +extern const char *nodename; + #endif /* !_HAST_H_ */ diff --git a/sbin/hastd/hastd.8 b/sbin/hastd/hastd.8 index 05a2d9b5e4e9..3c3088507ff9 100644 --- a/sbin/hastd/hastd.8 +++ b/sbin/hastd/hastd.8 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 21, 2019 +.Dd October 1, 2026 .Dt HASTD 8 .Os .Sh NAME @@ -34,6 +34,7 @@ .Nm .Op Fl dFh .Op Fl c Ar config +.Op Fl n Ar nodename .Op Fl P Ar pidfile .Sh DESCRIPTION The @@ -161,6 +162,11 @@ starts in the background. Print the .Nm usage message. +.It Fl n Ar nodename +Specify a node name to use instead of the current host name as +returned by +.Xr gethostname 3 . +This is mostly useful for testing. .It Fl P Ar pidfile Specify alternative location of a file where main process PID will be stored. diff --git a/sbin/hastd/hastd.c b/sbin/hastd/hastd.c index 1569dc9f8697..c5d3bb00c281 100644 --- a/sbin/hastd/hastd.c +++ b/sbin/hastd/hastd.c @@ -78,8 +78,10 @@ static bool foreground; static void usage(void) { - - errx(EX_USAGE, "[-dFh] [-c config] [-P pidfile]"); + fprintf(stderr, + "usage: %s [-dFh] [-c config] [-n nodename] [-P pidfile]\n", + getprogname()); + exit(1); } static void @@ -1197,7 +1199,7 @@ main(int argc, char *argv[]) for (;;) { int ch; - ch = getopt(argc, argv, "c:dFhP:"); + ch = getopt(argc, argv, "c:dFhn:P:"); if (ch == -1) break; switch (ch) { @@ -1207,6 +1209,9 @@ main(int argc, char *argv[]) case 'd': debuglevel++; break; + case 'n': + nodename = optarg; + break; case 'F': foreground = true; break; diff --git a/sbin/hastd/parse.y b/sbin/hastd/parse.y index 6cba61d74738..719ca834309d 100644 --- a/sbin/hastd/parse.y +++ b/sbin/hastd/parse.y @@ -55,6 +55,8 @@ extern int lineno; extern FILE *yyin; extern char *yytext; +const char *nodename; + static struct hastd_config *lconfig; static struct hast_resource *curres; static bool mynode, hadmynode; @@ -731,7 +733,23 @@ isitme(const char *name) char buf[MAXHOSTNAMELEN]; unsigned long hostid; char *pos; - size_t bufsize; + size_t bufsize, len; + + /* + * A static node name overrides all others. + */ + if (nodename != NULL) { + if (strcmp(nodename, name) == 0) + return (1); + pos = strchr(nodename, '.'); + if (pos != NULL && pos != nodename) { + len = pos - nodename; + if (len == strlen(name) && + strncmp(nodename, name, len) == 0) + return (1); + } + return (0); + } /* * First check if the given name matches our full hostname. @@ -747,9 +765,10 @@ isitme(const char *name) * Check if it matches first part of the host name. */ pos = strchr(buf, '.'); - if (pos != NULL && (size_t)(pos - buf) == strlen(name) && - strncmp(buf, name, pos - buf) == 0) { - return (1); + if (pos != NULL && pos != buf) { + len = pos - buf; + if (len == strlen(name) && strncmp(buf, name, len) == 0) + return (1); } /* @@ -801,7 +820,20 @@ node_names(char **namesp) char buf[MAXHOSTNAMELEN]; unsigned long hostid; char *pos; - size_t bufsize; + size_t bufsize, len; + + /* A static node name overrides all others. */ + if (nodename != NULL) { + pos = strchr(nodename, '.'); + if (pos != NULL && pos != nodename) { + len = pos - nodename; + (void)strlcpy(names, nodename, MIN(len + 1, sizeof(names))); + (void)strlcat(names, ", ", sizeof(names)); + } + (void)strlcat(names, nodename, sizeof(names)); + *namesp = names; + return (0); + } if (gethostname(buf, sizeof(buf)) < 0) { pjdlog_errno(LOG_ERR, "gethostname() failed"); @@ -811,8 +843,8 @@ node_names(char **namesp) /* First component of the host name. */ pos = strchr(buf, '.'); if (pos != NULL && pos != buf) { - (void)strlcpy(names, buf, MIN((size_t)(pos - buf + 1), - sizeof(names))); + len = pos - buf; + (void)strlcpy(names, buf, MIN(len + 1, sizeof(names))); (void)strlcat(names, ", ", sizeof(names)); }