From nobody Fri May 10 04:45:36 2024 X-Original-To: dev-commits-src-main@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 4VbGXc6vTmz5KnpC; Fri, 10 May 2024 04:45:36 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VbGXc632nz4jcP; Fri, 10 May 2024 04:45:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715316336; 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=mE87muFYlNR+eR1+drvQ9VxWAtIb7CAGiRYt1jq4DdI=; b=U0ldFaRD3a9rgaMuGJ8UjfDAtznhehMhUwXni2wDbq9ogiFhsv/C3FQIzCWdYYETdC34SE VEXeY0NdKJ24vp3M+jk1mCfzjy+1rwsff0FPdk2DIyzaR7X9bdpwBktAITvL/AMk8cGklM 188tARIQ5FkAKeYQH62MS5eI+rwJv1qCWNRe6NzTqYqq4h0CIOeDEhKyxFe+pIeaP7d6YG vOHog3N3CjzCrwedADY4XpKc01Nqlev+4Zu78ydJASTKsimQJLV24I1HrBz2NvAIfFc+0A 8KWqvsO7Obn9GriofreHUT9c5pSolCqD38CK7dqDHf9aFdflksGtnx+gww5vsg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715316336; a=rsa-sha256; cv=none; b=Lm+E1kFGD0S2izbSoMFwpKonTl4zcJ78gyFgxo257FSO5nWr+kp3YJLkupmd3Bft/tQ5TH h/18dmaQJG/rB4B5srr2lFGazz1N2PmSTVX6zPAeFCg3azLxzjy330xRUG9EsW1fgKWXB1 0vr5KiWgAIsVfzojvvB8sJkm7aLcWSY3HMPPhgqyQzgQ2Vrc1q8OlV64uf7lSvmOvOo0Gh TDLr0vYXDN6yTmvi00BAtomnhQLtG2guKchucDfjwM1MM0RFyDqIET4kv0G/Ovo4MfZ7vU aQSP14GoDxPASTuzV8AAvnwTRWEQ0MdQFPJO0EpDdEc8xkdwKfg6pLJAGUqAsQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715316336; 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=mE87muFYlNR+eR1+drvQ9VxWAtIb7CAGiRYt1jq4DdI=; b=JnN+OCFuRXf+xgsY0uNEuHX7K+hEmiip30HEtu5pMtwg21+9N24MQ8kUDUWf1MUmfpCRJf pwMBEt+86dmtpPG5kYtRY9jazRmgWN7TtBL8mKNa918b/WHgFyT1IRBWeM1mCBgDhJM8jm qB2nDpLHzI6FotqcP2EFNnHwJSTv6hxjUeJfnHj+AurPWHapUReOM9VTFsXQwp1/bENUXy XRc4sJJVmAGk9iZtcKpRhwC/Uq4foVEpboRDKZovUHrPZRrl/Yfq7m1dLiTYZDf1I0ZPaH tjqBbR6V2+qgVrXQYJlhAUtoH9OwUnE3zHQP+BFKeXTPplmmOakN9plbtx3sAw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VbGXc5YWVzNhT; Fri, 10 May 2024 04:45:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44A4jaH4006413; Fri, 10 May 2024 04:45:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44A4ja1S006410; Fri, 10 May 2024 04:45:36 GMT (envelope-from git) Date: Fri, 10 May 2024 04:45:36 GMT Message-Id: <202405100445.44A4ja1S006410@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: b01988d5e570 - main - mdconfig: Print options when listing devices List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b01988d5e570158534110ca309fe93112c5c62f1 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b01988d5e570158534110ca309fe93112c5c62f1 commit b01988d5e570158534110ca309fe93112c5c62f1 Author: Ricardo Branco AuthorDate: 2024-05-10 04:42:22 +0000 Commit: Warner Losh CommitDate: 2024-05-10 04:43:09 +0000 mdconfig: Print options when listing devices PR: 278624 Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1210 --- sbin/mdconfig/mdconfig.c | 90 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 740f800e3e79..d49eb6ed08e5 100644 --- a/sbin/mdconfig/mdconfig.c +++ b/sbin/mdconfig/mdconfig.c @@ -56,7 +56,7 @@ static struct md_ioctl mdio; static enum {UNSET, ATTACH, DETACH, RESIZE, LIST} action = UNSET; -static int nflag; +static int md_fd, nflag; static void usage(void) __dead2; static void md_set_file(const char *); @@ -65,6 +65,7 @@ static int md_query(const char *, const int, const char *); static int md_list(const char *, int, const char *); static char *geom_config_get(struct gconf *g, const char *name); static void md_prthumanval(char *length); +static void print_options(const char *s, const char *); #define OPT_VERBOSE 0x01 #define OPT_UNIT 0x02 @@ -86,11 +87,11 @@ usage(void) " mdconfig -l [-v] [-n] [-f file] [-u unit]\n" " mdconfig file\n"); fprintf(stderr, "\t\ttype = {malloc, vnode, swap}\n"); - fprintf(stderr, "\t\toption = {cache, cluster, compress, force,\n"); - fprintf(stderr, "\t\t mustdealloc, readonly, reserve, ro,\n"); - fprintf(stderr, "\t\t verify}\n"); + fprintf(stderr, "\t\toption = {async, cache, cluster, compress,\n"); + fprintf(stderr, "\t\t force, mustdealloc, readonly, ro,\n"); + fprintf(stderr, "\t\t reserve, verify}\n"); fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%db (B),\n"); - fprintf(stderr, "\t\t %%dk (kB), %%dm (MB), %%dg (GB), \n"); + fprintf(stderr, "\t\t %%dk (kB), %%dm (MB), %%dg (GB),\n"); fprintf(stderr, "\t\t %%dt (TB), or %%dp (PB)\n"); exit(1); } @@ -98,7 +99,7 @@ usage(void) int main(int argc, char **argv) { - int ch, fd, i, vflag; + int ch, i, vflag; char *p; char *fflag = NULL, *sflag = NULL, *tflag = NULL, *uflag = NULL; @@ -366,12 +367,12 @@ main(int argc, char **argv) if (!kld_isloaded("g_md") && kld_load("geom_md") == -1) err(1, "failed to load geom_md module"); - fd = open(_PATH_DEV MDCTL_NAME, O_RDWR, 0); - if (fd < 0) + md_fd = open(_PATH_DEV MDCTL_NAME, O_RDWR, 0); + if (md_fd < 0) err(1, "open(%s%s)", _PATH_DEV, MDCTL_NAME); if (action == ATTACH) { - i = ioctl(fd, MDIOCATTACH, &mdio); + i = ioctl(md_fd, MDIOCATTACH, &mdio); if (i < 0) err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME); if (mdio.md_options & MD_AUTOUNIT) @@ -379,13 +380,13 @@ main(int argc, char **argv) } else if (action == DETACH) { if (mdio.md_options & MD_AUTOUNIT) errx(1, "-d requires -u"); - i = ioctl(fd, MDIOCDETACH, &mdio); + i = ioctl(md_fd, MDIOCDETACH, &mdio); if (i < 0) err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME); } else if (action == RESIZE) { if (mdio.md_options & MD_AUTOUNIT) errx(1, "-r requires -u"); - i = ioctl(fd, MDIOCRESIZE, &mdio); + i = ioctl(md_fd, MDIOCRESIZE, &mdio); if (i < 0) err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME); } else if (action == LIST) { @@ -399,10 +400,70 @@ main(int argc, char **argv) return (md_query(uflag, vflag, fflag)); } else usage(); - close(fd); + close(md_fd); return (0); } +static void +print_options(const char *dev, const char *file) +{ + struct md_ioctl mdiox; + int unit; + char sep = '\0'; + + if (sscanf(dev, "md%d", &unit) != 1) + err(1, "invalid device: %s", dev); + + memset(&mdiox, 0, sizeof(mdiox)); + mdiox.md_version = MDIOVERSION; + mdiox.md_unit = unit; + mdiox.md_file = file[0] == '-' ? NULL : strdup(file); + + if (ioctl(md_fd, MDIOCQUERY, &mdiox) < 0) + err(1, "ioctl(%s%s)", _PATH_DEV, MDCTL_NAME); + + if (mdiox.md_file != NULL) + free(mdiox.md_file); + + printf("\t"); + if (mdiox.md_options & MD_ASYNC) { + printf("%casync", sep); + sep = ','; + } + if (mdiox.md_options & MD_CACHE) { + printf("%ccache", sep); + sep = ','; + } + if (mdiox.md_options & MD_CLUSTER) { + printf("%ccluster", sep); + sep = ','; + } + if (mdiox.md_options & MD_COMPRESS) { + printf("%ccompress", sep); + sep = ','; + } + if (mdiox.md_options & MD_FORCE) { + printf("%cforce", sep); + sep = ','; + } + if (mdiox.md_options & MD_READONLY) { + printf("%creadonly", sep); + sep = ','; + } + if (mdiox.md_options & MD_RESERVE) { + printf("%creserve", sep); + sep = ','; + } + if (mdiox.md_options & MD_VERIFY) { + printf("%cverify", sep); + sep = ','; + } + if (mdiox.md_options & MD_MUSTDEALLOC) { + printf("%cmustdealloc", sep); + sep = ','; + } +} + static void md_set_file(const char *fn) { @@ -500,11 +561,12 @@ md_list(const char *units, int opt, const char *fflag) if (file == NULL) file = "-"; printf("\t%s", file); - file = NULL; label = geom_config_get(gc, "label"); if (label == NULL) - label = ""; + label = "-"; printf("\t%s", label); + print_options(pp->lg_name, file); + file = label = NULL; } opt |= OPT_DONE; if ((opt & OPT_LIST) && !(opt & OPT_VERBOSE))