diff options
Diffstat (limited to 'sbin/mdconfig')
-rw-r--r-- | sbin/mdconfig/Makefile | 1 | ||||
-rw-r--r-- | sbin/mdconfig/mdconfig.8 | 10 | ||||
-rw-r--r-- | sbin/mdconfig/mdconfig.c | 111 | ||||
-rw-r--r-- | sbin/mdconfig/tests/Makefile | 1 | ||||
-rwxr-xr-x | sbin/mdconfig/tests/mdconfig_test.sh | 22 |
5 files changed, 110 insertions, 35 deletions
diff --git a/sbin/mdconfig/Makefile b/sbin/mdconfig/Makefile index 5e102d635e93..bd835df0daec 100644 --- a/sbin/mdconfig/Makefile +++ b/sbin/mdconfig/Makefile @@ -1,4 +1,3 @@ - .include <src.opts.mk> PACKAGE=runtime diff --git a/sbin/mdconfig/mdconfig.8 b/sbin/mdconfig/mdconfig.8 index 757e38cc4841..9a86a9c686fd 100644 --- a/sbin/mdconfig/mdconfig.8 +++ b/sbin/mdconfig/mdconfig.8 @@ -31,11 +31,9 @@ .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. -.\" -.\" @(#)vnconfig.8 8.1 (Berkeley) 6/5/93 .\" from: src/usr.sbin/vnconfig/vnconfig.8,v 1.19 2000/12/27 15:30:29 .\" -.Dd August 27, 2021 +.Dd June 1, 2024 .Dt MDCONFIG 8 .Os .Sh NAME @@ -232,8 +230,6 @@ option tends to waste memory by giving unwanted double caching, but it saves time if there is memory to spare. .It Oo Cm no Oc Ns Cm reserve Allocate and reserve all needed storage from the start, rather than as needed. -.It Oo Cm no Oc Ns Cm cluster -Enable clustering on this disk. .It Oo Cm no Oc Ns Cm compress Enable/disable compression features to reduce memory usage. .It Oo Cm no Oc Ns Cm force @@ -335,7 +331,7 @@ mdconfig -rs 2g -u md3 .Ed .Pp Create a 1 gigabyte swap backed disk, initialize an -.Xr ffs 7 +.Xr ffs 4 file system on it, and mount it on .Pa /tmp : .Bd -literal -offset indent @@ -368,8 +364,8 @@ mount /dev/md1.nop /mnt .Xr fpathconf 2 , .Xr fspacectl 2 , .Xr open 2 , +.Xr ffs 4 , .Xr md 4 , -.Xr ffs 7 , .Xr gpart 8 , .Xr mdmfs 8 , .Xr malloc 9 , diff --git a/sbin/mdconfig/mdconfig.c b/sbin/mdconfig/mdconfig.c index 740f800e3e79..4b03dd81e591 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, 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; @@ -155,13 +156,13 @@ main(int argc, char **argv) mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; } else if (!strcmp(optarg, "vnode")) { mdio.md_type = MD_VNODE; - mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS; + mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; } else if (!strcmp(optarg, "swap")) { mdio.md_type = MD_SWAP; - mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS; + mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; } else if (!strcmp(optarg, "null")) { mdio.md_type = MD_NULL; - mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS; + mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; } else errx(1, "unknown type: %s", optarg); break; @@ -181,10 +182,15 @@ main(int argc, char **argv) mdio.md_options |= MD_CACHE; else if (!strcmp(optarg, "nocache")) mdio.md_options &= ~MD_CACHE; - else if (!strcmp(optarg, "cluster")) - mdio.md_options |= MD_CLUSTER; - else if (!strcmp(optarg, "nocluster")) - mdio.md_options &= ~MD_CLUSTER; + /* + * For backwards-compatibility, continue to recognize + * "cluster" + */ + else if (!strcmp(optarg, "cluster") || + !strcmp(optarg, "nocluster")) + { + warnx("Option cluster is ignored"); + } else if (!strcmp(optarg, "compress")) mdio.md_options |= MD_COMPRESS; else if (!strcmp(optarg, "nocompress")) @@ -281,13 +287,11 @@ main(int argc, char **argv) if (fflag != NULL || argc > 0) { /* Imply ``-t vnode'' */ mdio.md_type = MD_VNODE; - mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | - MD_COMPRESS; + mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; } else if (sflag != NULL) { /* Imply ``-t swap'' */ mdio.md_type = MD_SWAP; - mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | - MD_COMPRESS; + mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS; } else errx(1, "unable to determine type"); } @@ -366,12 +370,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 +383,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,11 +403,67 @@ 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; + const char *sep = ""; + + 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("%sasync", sep); + sep = ","; + } + if (mdiox.md_options & MD_CACHE) { + printf("%scache", sep); + sep = ","; + } + if (mdiox.md_options & MD_COMPRESS) { + printf("%scompress", sep); + sep = ","; + } + if (mdiox.md_options & MD_FORCE) { + printf("%sforce", sep); + sep = ","; + } + if (mdiox.md_options & MD_READONLY) { + printf("%sreadonly", sep); + sep = ","; + } + if (mdiox.md_options & MD_RESERVE) { + printf("%sreserve", sep); + sep = ","; + } + if (mdiox.md_options & MD_VERIFY) { + printf("%sverify", sep); + sep = ","; + } + if (mdiox.md_options & MD_MUSTDEALLOC) { + printf("%smustdealloc", sep); + sep = ","; + } +} + +static void md_set_file(const char *fn) { struct stat sb; @@ -500,11 +560,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)) diff --git a/sbin/mdconfig/tests/Makefile b/sbin/mdconfig/tests/Makefile index 674536a33d74..a3841f8f0dd0 100644 --- a/sbin/mdconfig/tests/Makefile +++ b/sbin/mdconfig/tests/Makefile @@ -1,4 +1,3 @@ - ATF_TESTS_SH= mdconfig_test TEST_METADATA.mdconfig_test+= required_user="root" diff --git a/sbin/mdconfig/tests/mdconfig_test.sh b/sbin/mdconfig/tests/mdconfig_test.sh index 9aaf724206b1..ea87ff5d542d 100755 --- a/sbin/mdconfig/tests/mdconfig_test.sh +++ b/sbin/mdconfig/tests/mdconfig_test.sh @@ -291,7 +291,26 @@ attach_size_rounddown_body() -x "mdconfig -r -u ${md#md} -s ${ms2}b" check_diskinfo "$md" 16384 2 $ss } -attach_size_rounddown() +attach_size_rounddown_cleanup() +{ + cleanup_common +} + +atf_test_case query_verbose cleanup +query_verbose() +{ + atf_set "descr" "mdconfig -lv should print device details" +} +query_verbose_body() +{ + atf_check -s exit:0 -o save:mdconfig.out \ + -x 'mdconfig -a -t swap -s 1m -o reserve -o force' + md=$(cat mdconfig.out) + atf_check -s exit:0 \ + -o match:"$md[[:space:]]+swap[[:space:]]+1024K[[:space:]]+[-][[:space:]]+[-][[:space:]]+force,reserve" \ + -x "mdconfig -lv -u $md" +} +query_verbose_cleanup() { cleanup_common } @@ -307,4 +326,5 @@ atf_init_test_cases() atf_add_test_case attach_swap atf_add_test_case attach_with_specific_unit_number atf_add_test_case attach_size_rounddown + atf_add_test_case query_verbose } |