diff --git a/sbin/geom/class/concat/gconcat.8 b/sbin/geom/class/concat/gconcat.8 index e47cedf96870..f0e4d7555def 100644 --- a/sbin/geom/class/concat/gconcat.8 +++ b/sbin/geom/class/concat/gconcat.8 @@ -1,185 +1,191 @@ .\" Copyright (c) 2004 Pawel Jakub Dawidek .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" 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. .\" .\" $FreeBSD$ .\" .Dd May 21, 2004 .Dt GCONCAT 8 .Os .Sh NAME .Nm gconcat .Nd "disk concatenation control utility" .Sh SYNOPSIS .Nm .Cm create .Op Fl v .Ar name .Ar dev1 .Ar dev2 .Op Ar dev3 Op Ar ... .Nm .Cm destroy .Op Fl fv .Ar name .Op Ar name2 Op Ar ... .Nm .Cm label .Op Fl v .Ar name .Ar dev1 .Ar dev2 .Op Ar dev3 Op Ar ... .Nm .Cm stop .Op Fl fv .Ar name .Op Ar name2 Op Ar ... .Nm .Cm clear .Op Fl v .Ar dev1 .Op Ar dev2 Op Ar ... .Nm +.Cm dump +.Ar dev1 +.Op Ar dev2 Op Ar ... +.Nm .Cm list .Op Ar prov Op Ar ... .Nm .Cm load .Op Fl v .Nm .Cm unload .Op Fl v .Sh DESCRIPTION The .Nm utility is used for device concatenation configuration. The concatenation can be configured using two different methods: .Dq manual or .Dq automatic . When using the .Dq manual method, no metadata are stored on the devices, so the concatenated device has to be configured by hand every time it is needed. The .Dq automatic method uses on-disk metadata to detect devices. Once devices are labeled, they will be automatically detected and configured. .Pp The first argument to .Nm indicates an action to be performed: .Bl -tag -width ".Cm destroy" .It Cm create Concatenate the given devices with specified .Ar name . This is the .Dq manual method. The kernel module .Pa geom_concat.ko will be loaded if it is not loaded already. .It Cm label Concatenate the given devices with the specified .Ar name . This is the .Dq automatic method, where metadata are stored in every device's last sector. The kernel module .Pa geom_concat.ko will be loaded if it is not loaded already. .It Cm stop Turn off existing concatenate device by its .Ar name . This command does not touch on-disk metadata! .It Cm destroy Same as .Cm stop . .It Cm clear Clear metadata on the given devices. +.It Cm dump +Dump metadata stored on the given devices. .It Cm list List all or the given currently configured devices. .It Cm load Load .Pa geom_concat.ko kernel module. .It Cm unload Unload .Pa geom_concat.ko kernel module. .El .Pp Additional options: .Bl -tag -width indent .It Fl f Force the removal of the specified concatenated device. .It Fl v Be more verbose. .El .Sh SYSCTL VARIABLES The following .Xr sysctl 8 variables can be used to control the behavior of the .Nm CONCAT GEOM class. The default value is shown next to each variable. .Bl -tag -width indent .It Va kern.geom.concat.debug : No 0 Debug level of the .Nm CONCAT GEOM class. This can be set to a number between 0 and 3, both included. If set to 0 minimal debug information is printed, and if set to 3 the maximum amount of debug information in printed. .El .Sh EXAMPLES The following example shows how to configure four disks for automatic concatenation, create a file system on it, and mount it: .Bd -literal -offset indent gconcat label -v data /dev/da0 /dev/da1 /dev/da2 /dev/da3 newfs /dev/data.concat mount /dev/data.concat /mnt [...] umount /mnt gconcat stop data gconcat unload .Ed .Sh DIAGNOSTICS Exit status is 0 on success, and 1 if the command fails. .Sh SEE ALSO .Xr geom 4 , .Xr loader.conf 5 , .Xr geom 8 , .Xr mount 8 , .Xr newfs 8 , .Xr sysctl 8 , .Xr umount 8 , .Xr vinum 8 .Sh HISTORY The .Nm utility appeared in .Fx 5.3 . .Sh AUTHORS .An Pawel Jakub Dawidek Aq pjd@FreeBSD.org diff --git a/sbin/geom/class/concat/geom_concat.c b/sbin/geom/class/concat/geom_concat.c index 3042b5f4a46b..49e6101916f4 100644 --- a/sbin/geom/class/concat/geom_concat.c +++ b/sbin/geom/class/concat/geom_concat.c @@ -1,205 +1,259 @@ /*- * Copyright (c) 2004 Pawel Jakub Dawidek * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include "core/geom.h" #include "misc/subr.h" uint32_t lib_version = G_LIB_VERSION; uint32_t version = G_CONCAT_VERSION; static void concat_main(struct gctl_req *req, unsigned flags); -static void concat_label(struct gctl_req *req); static void concat_clear(struct gctl_req *req); +static void concat_dump(struct gctl_req *req); +static void concat_label(struct gctl_req *req); struct g_command class_commands[] = { { "clear", G_FLAG_VERBOSE, concat_main, G_NULL_OPTS }, { "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, NULL, G_NULL_OPTS }, { "destroy", G_FLAG_VERBOSE, NULL, { { 'f', "force", NULL, G_TYPE_NONE }, G_OPT_SENTINEL } }, + { "dump", 0, concat_main, G_NULL_OPTS }, { "label", G_FLAG_VERBOSE | G_FLAG_LOADKLD, concat_main, G_NULL_OPTS }, { "stop", G_FLAG_VERBOSE, NULL, { { 'f', "force", NULL, G_TYPE_NONE }, G_OPT_SENTINEL } }, G_CMD_SENTINEL }; static int verbose = 0; void usage(const char *name); void usage(const char *name) { fprintf(stderr, "usage: %s create [-v] [dev3 [...]]\n", name); fprintf(stderr, " %s destroy [-fv] [name2 [...]]\n", name); fprintf(stderr, " %s label [-v] [dev3 [...]]\n", name); fprintf(stderr, " %s stop [-fv] [name2 [...]]\n", name); fprintf(stderr, " %s clear [-v] [dev2 [...]]\n", name); + fprintf(stderr, " %s dump [dev2 [...]]\n", name); } static void concat_main(struct gctl_req *req, unsigned flags) { const char *name; if ((flags & G_FLAG_VERBOSE) != 0) verbose = 1; name = gctl_get_asciiparam(req, "verb"); if (name == NULL) { gctl_error(req, "No '%s' argument.", "verb"); return; } if (strcmp(name, "label") == 0) concat_label(req); else if (strcmp(name, "clear") == 0) concat_clear(req); + else if (strcmp(name, "dump") == 0) + concat_dump(req); else gctl_error(req, "Unknown command: %s.", name); } static void concat_label(struct gctl_req *req) { struct g_concat_metadata md; u_char sector[512]; const char *name; char param[16]; unsigned i; int *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); return; } if (*nargs <= 2) { gctl_error(req, "Too few arguments."); return; } /* * Clear last sector first to spoil all components if device exists. */ for (i = 1; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); error = g_metadata_clear(name, NULL); if (error != 0) { gctl_error(req, "Can't store metadata on %s: %s.", name, strerror(error)); return; } } strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic)); md.md_version = G_CONCAT_VERSION; name = gctl_get_asciiparam(req, "arg0"); if (name == NULL) { gctl_error(req, "No 'arg%u' argument.", 0); return; } strlcpy(md.md_name, name, sizeof(md.md_name)); md.md_id = arc4random(); md.md_all = *nargs - 1; /* * Ok, store metadata. */ for (i = 1; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); md.md_no = i - 1; concat_metadata_encode(&md, sector); error = g_metadata_store(name, sector, sizeof(sector)); if (error != 0) { fprintf(stderr, "Can't store metadata on %s: %s.\n", name, strerror(error)); gctl_error(req, "Not fully done."); continue; } if (verbose) printf("Metadata value stored on %s.\n", name); } } static void concat_clear(struct gctl_req *req) { const char *name; char param[16]; unsigned i; int *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); return; } if (*nargs < 1) { gctl_error(req, "Too few arguments."); return; } for (i = 0; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); error = g_metadata_clear(name, G_CONCAT_MAGIC); if (error != 0) { fprintf(stderr, "Can't clear metadata on %s: %s.\n", name, strerror(error)); gctl_error(req, "Not fully done."); continue; } if (verbose) printf("Metadata cleared on %s.\n", name); } } + +static void +concat_metadata_dump(const struct g_concat_metadata *md) +{ + + printf(" Magic string: %s\n", md->md_magic); + printf(" Metadata version: %u\n", (u_int)md->md_version); + printf(" Device name: %s\n", md->md_name); + printf(" Device ID: %u\n", (u_int)md->md_id); + printf(" Disk number: %u\n", (u_int)md->md_no); + printf("Total number of disks: %u\n", (u_int)md->md_all); +} + +static void +concat_dump(struct gctl_req *req) +{ + struct g_concat_metadata md, tmpmd; + const char *name; + char param[16]; + int *nargs, error, i; + + nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); + if (nargs == NULL) { + gctl_error(req, "No '%s' argument.", "nargs"); + return; + } + if (*nargs < 1) { + gctl_error(req, "Too few arguments."); + return; + } + + for (i = 0; i < *nargs; i++) { + snprintf(param, sizeof(param), "arg%u", i); + name = gctl_get_asciiparam(req, param); + + error = g_metadata_read(name, (u_char *)&tmpmd, sizeof(tmpmd), + G_CONCAT_MAGIC); + if (error != 0) { + fprintf(stderr, "Can't read metadata from %s: %s.\n", + name, strerror(error)); + gctl_error(req, "Not fully done."); + continue; + } + concat_metadata_decode((u_char *)&tmpmd, &md); + printf("Metadata on %s:\n", name); + concat_metadata_dump(&md); + printf("\n"); + } +} diff --git a/sbin/geom/class/label/geom_label.c b/sbin/geom/class/label/geom_label.c index edb0d7e4ef9e..1c301c3bdb5d 100644 --- a/sbin/geom/class/label/geom_label.c +++ b/sbin/geom/class/label/geom_label.c @@ -1,194 +1,245 @@ /*- * Copyright (c) 2004 Pawel Jakub Dawidek * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include "core/geom.h" #include "misc/subr.h" uint32_t lib_version = G_LIB_VERSION; uint32_t version = G_LABEL_VERSION; static void label_main(struct gctl_req *req, unsigned flags); -static void label_label(struct gctl_req *req); static void label_clear(struct gctl_req *req); +static void label_dump(struct gctl_req *req); +static void label_label(struct gctl_req *req); struct g_command class_commands[] = { { "clear", G_FLAG_VERBOSE, label_main, G_NULL_OPTS }, { "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, NULL, G_NULL_OPTS }, { "destroy", G_FLAG_VERBOSE, NULL, { { 'f', "force", NULL, G_TYPE_NONE }, G_OPT_SENTINEL } }, + { "dump", 0, label_main, G_NULL_OPTS }, { "label", G_FLAG_VERBOSE | G_FLAG_LOADKLD, label_main, G_NULL_OPTS }, { "stop", G_FLAG_VERBOSE, NULL, { { 'f', "force", NULL, G_TYPE_NONE }, G_OPT_SENTINEL } }, G_CMD_SENTINEL }; static int verbose = 0; void usage(const char *name); void usage(const char *name) { fprintf(stderr, "usage: %s create [-v] \n", name); fprintf(stderr, " %s destroy [-fv] [name2 [...]]\n", name); fprintf(stderr, " %s label [-v] \n", name); fprintf(stderr, " %s stop [-fv] [name2 [...]]\n", name); fprintf(stderr, " %s clear [-v] [dev2 [...]]\n", name); + fprintf(stderr, " %s dump [dev2 [...]]\n", name); } static void label_main(struct gctl_req *req, unsigned flags) { const char *name; if ((flags & G_FLAG_VERBOSE) != 0) verbose = 1; name = gctl_get_asciiparam(req, "verb"); if (name == NULL) { gctl_error(req, "No '%s' argument.", "verb"); return; } if (strcmp(name, "label") == 0) label_label(req); else if (strcmp(name, "clear") == 0) label_clear(req); + else if (strcmp(name, "dump") == 0) + label_dump(req); else gctl_error(req, "Unknown command: %s.", name); } static void label_label(struct gctl_req *req) { struct g_label_metadata md; const char *name, *label; u_char sector[512]; int *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); return; } if (*nargs != 2) { gctl_error(req, "Invalid number of arguments."); return; } /* * Clear last sector first to spoil all components if device exists. */ name = gctl_get_asciiparam(req, "arg1"); if (name == NULL) { gctl_error(req, "No 'arg%u' argument.", 1); return; } error = g_metadata_clear(name, NULL); if (error != 0) { gctl_error(req, "Can't store metadata on %s: %s.", name, strerror(error)); return; } strlcpy(md.md_magic, G_LABEL_MAGIC, sizeof(md.md_magic)); md.md_version = G_LABEL_VERSION; label = gctl_get_asciiparam(req, "arg0"); if (label == NULL) { gctl_error(req, "No 'arg%u' argument.", 0); return; } strlcpy(md.md_label, label, sizeof(md.md_label)); /* * Ok, store metadata. */ label_metadata_encode(&md, sector); error = g_metadata_store(name, sector, sizeof(sector)); if (error != 0) { fprintf(stderr, "Can't store metadata on %s: %s.\n", name, strerror(error)); gctl_error(req, "Not done."); } if (verbose) printf("Metadata value stored on %s.\n", name); } static void label_clear(struct gctl_req *req) { const char *name; char param[16]; unsigned i; int *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); return; } if (*nargs < 1) { gctl_error(req, "Too few arguments."); return; } for (i = 0; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); error = g_metadata_clear(name, G_LABEL_MAGIC); if (error != 0) { fprintf(stderr, "Can't clear metadata on %s: %s.\n", name, strerror(error)); gctl_error(req, "Not fully done."); continue; } if (verbose) printf("Metadata cleared on %s.\n", name); } } + +static void +label_metadata_dump(const struct g_label_metadata *md) +{ + + printf(" Magic string: %s\n", md->md_magic); + printf("Metadata version: %u\n", (u_int)md->md_version); + printf(" Label: %s\n", md->md_label); +} + +static void +label_dump(struct gctl_req *req) +{ + struct g_label_metadata md, tmpmd; + const char *name; + char param[16]; + int *nargs, error, i; + + nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); + if (nargs == NULL) { + gctl_error(req, "No '%s' argument.", "nargs"); + return; + } + if (*nargs < 1) { + gctl_error(req, "Too few arguments."); + return; + } + + for (i = 0; i < *nargs; i++) { + snprintf(param, sizeof(param), "arg%u", i); + name = gctl_get_asciiparam(req, param); + + error = g_metadata_read(name, (u_char *)&tmpmd, sizeof(tmpmd), + G_LABEL_MAGIC); + if (error != 0) { + fprintf(stderr, "Can't read metadata from %s: %s.\n", + name, strerror(error)); + gctl_error(req, "Not fully done."); + continue; + } + label_metadata_decode((u_char *)&tmpmd, &md); + printf("Metadata on %s:\n", name); + label_metadata_dump(&md); + printf("\n"); + } +} diff --git a/sbin/geom/class/label/glabel.8 b/sbin/geom/class/label/glabel.8 index cbf7615e2d4f..15ccdb0def6e 100644 --- a/sbin/geom/class/label/glabel.8 +++ b/sbin/geom/class/label/glabel.8 @@ -1,215 +1,221 @@ .\" Copyright (c) 2004 Pawel Jakub Dawidek .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" 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. .\" .\" $FreeBSD$ .\" .Dd July 2, 2004 .Dt GLABEL 8 .Os .Sh NAME .Nm glabel .Nd "disk labelization control utility" .Sh SYNOPSIS .Nm .Cm create .Op Fl v .Ar name .Ar dev .Nm .Cm destroy .Op Fl fv .Ar name .Op Ar name Op Ar ... .Nm .Cm label .Op Fl v .Ar name .Ar dev .Nm .Cm stop .Op Fl fv .Ar name .Op Ar name Op Ar ... .Nm .Cm clear .Op Fl v .Ar dev .Op Ar dev Op Ar ... .Nm +.Cm dump +.Ar dev +.Op Ar dev Op Ar ... +.Nm .Cm list .Op Ar prov Op Ar ... .Nm .Cm load .Op Fl v .Nm .Cm unload .Op Fl v .Sh DESCRIPTION The .Nm utility is used for GEOM providers labelization. A label can be set up on a GEOM provider in two ways: .Dq manual or .Dq automatic . When using the .Dq manual method, no metadata are stored on the devices, so a label has to be configured by hand every time it is needed. The .Dq automatic method uses on-disk metadata to store the label and detect it automatically in the future. .Pp This class also provides volume label detection for file systems. Those labels cannot be set with .Nm , but must be set with the appropriate file system utility, e.g.\& for UFS the file system label is set with .Xr tunefs 8 . Currently supported file systems are: .Pp .Bl -bullet -offset indent -compact .It UFS1 (directory .Pa /dev/ufs/ ) . .It UFS2 (directory .Pa /dev/ufs/ ) . .It MSDOSFS (FAT12, FAT16, FAT32) (directory .Pa /dev/msdosfs/ ) . .It CD ISO9660 (directory .Pa /dev/iso9660/ ) . .El .Pp Non file-system labels are created in the directory .Pa /dev/label/ . .Pp The first argument to .Nm indicates an action to be performed: .Bl -tag -width ".Cm destroy" .It Cm create Create temporary label .Ar name for the given provider. This is the .Dq manual method. The kernel module .Pa geom_label.ko will be loaded if it is not loaded already. .It Cm label Set up a label .Ar name for the given provider. This is the .Dq automatic method, where metadata is stored in provider's last sector. The kernel module .Pa geom_label.ko will be loaded if it is not loaded already. .It Cm stop Turn off the given label by its .Ar name . This command does not touch on-disk metadata! .It Cm destroy Same as .Cm stop . .It Cm clear Clear metadata on the given devices. +.It Cm dump +Dump metadata stored on the given devices. .It Cm list List all currently configured devices, or list the given devices. .It Cm load Load .Pa geom_label.ko kernel module. .It Cm unload Unload .Pa geom_label.ko kernel module. .El .Pp Additional options: .Bl -tag -width indent .It Fl f Force the removal of the specified labels. .It Fl v Be more verbose. .El .Sh SYSCTL VARIABLES The following .Xr sysctl 8 variables can be used to control the behavior of the .Nm LABEL GEOM class. The default value is shown next to each variable. .Bl -tag -width indent .It Va kern.geom.label.debug : No 0 Debug level of the .Nm LABEL GEOM class. This can be set to a number between 0 and 2, both included. If set to 0 minimal debug information is printed, and if set to 2 the maximum amount of debug information in printed. .El .Sh EXAMPLES The following example shows how to set up a label for disk .Dq Li da2 , create a file system on it, and mount it: .Bd -literal -offset indent glabel label -v usr /dev/da2 newfs /dev/label/usr mount /dev/label/usr /usr [...] umount /usr glabel stop usr glabel unload .Ed .Pp The next example shows how to set up a label for a UFS file system: .Bd -literal -offset indent tunefs -L data /dev/da4s1a mount /dev/ufs/data /mnt/data .Ed .Sh DIAGNOSTICS Exit status is 0 on success, and 1 if the command fails. .Sh SEE ALSO .Xr geom 4 , .Xr loader.conf 5 , .Xr geom 8 , .Xr mount 8 , .Xr newfs 8 , .Xr sysctl 8 , .Xr tunefs 8 , .Xr umount 8 .Sh HISTORY The .Nm utility appeared in .Fx 5.3 . .Sh AUTHORS .An Pawel Jakub Dawidek Aq pjd@FreeBSD.org diff --git a/sbin/geom/class/stripe/geom_stripe.c b/sbin/geom/class/stripe/geom_stripe.c index cde761380893..5b6a9a353a78 100644 --- a/sbin/geom/class/stripe/geom_stripe.c +++ b/sbin/geom/class/stripe/geom_stripe.c @@ -1,224 +1,279 @@ /*- * Copyright (c) 2004 Pawel Jakub Dawidek * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include "core/geom.h" #include "misc/subr.h" uint32_t lib_version = G_LIB_VERSION; uint32_t version = G_STRIPE_VERSION; static intmax_t stripesize = 4096; static void stripe_main(struct gctl_req *req, unsigned flags); -static void stripe_label(struct gctl_req *req); static void stripe_clear(struct gctl_req *req); +static void stripe_dump(struct gctl_req *req); +static void stripe_label(struct gctl_req *req); struct g_command class_commands[] = { { "clear", G_FLAG_VERBOSE, stripe_main, G_NULL_OPTS }, { "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, NULL, { { 's', "stripesize", &stripesize, G_TYPE_NUMBER }, G_OPT_SENTINEL } }, { "destroy", G_FLAG_VERBOSE, NULL, { { 'f', "force", NULL, G_TYPE_NONE }, G_OPT_SENTINEL } }, + { "dump", 0, stripe_main, G_NULL_OPTS }, { "label", G_FLAG_VERBOSE | G_FLAG_LOADKLD, stripe_main, { { 's', "stripesize", &stripesize, G_TYPE_NUMBER }, G_OPT_SENTINEL } }, { "stop", G_FLAG_VERBOSE, NULL, { { 'f', "force", NULL, G_TYPE_NONE }, G_OPT_SENTINEL } }, G_CMD_SENTINEL }; static int verbose = 0; void usage(const char *name); void usage(const char *name) { fprintf(stderr, "usage: %s create [-v] [-s stripesize] [dev3 [...]]\n", name); fprintf(stderr, " %s destroy [-fv] [name2 [...]]\n", name); fprintf(stderr, " %s label [-v] [-s stripesize] [dev3 [...]]\n", name); fprintf(stderr, " %s stop [-fv] [name2 [...]]\n", name); fprintf(stderr, " %s clear [-v] [dev2 [...]]\n", name); + fprintf(stderr, " %s dump [dev2 [...]]\n", name); } static void stripe_main(struct gctl_req *req, unsigned flags) { const char *name; if ((flags & G_FLAG_VERBOSE) != 0) verbose = 1; name = gctl_get_asciiparam(req, "verb"); if (name == NULL) { gctl_error(req, "No '%s' argument.", "verb"); return; } if (strcmp(name, "label") == 0) stripe_label(req); else if (strcmp(name, "clear") == 0) stripe_clear(req); + else if (strcmp(name, "dump") == 0) + stripe_dump(req); else gctl_error(req, "Unknown command: %s.", name); } static void stripe_label(struct gctl_req *req) { struct g_stripe_metadata md; intmax_t *stripesizep; u_char sector[512]; const char *name; char param[16]; unsigned i; int *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); return; } if (*nargs <= 2) { gctl_error(req, "Too few arguments."); return; } /* * Clear last sector first to spoil all components if device exists. */ for (i = 1; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); error = g_metadata_clear(name, NULL); if (error != 0) { gctl_error(req, "Can't store metadata on %s: %s.", name, strerror(error)); return; } } strlcpy(md.md_magic, G_STRIPE_MAGIC, sizeof(md.md_magic)); md.md_version = G_STRIPE_VERSION; name = gctl_get_asciiparam(req, "arg0"); if (name == NULL) { gctl_error(req, "No 'arg%u' argument.", 0); return; } strlcpy(md.md_name, name, sizeof(md.md_name)); md.md_id = arc4random(); md.md_all = *nargs - 1; stripesizep = gctl_get_paraml(req, "stripesize", sizeof(*stripesizep)); if (stripesizep == NULL) { gctl_error(req, "No '%s' argument.", "stripesize"); return; } md.md_stripesize = *stripesizep; /* * Ok, store metadata. */ for (i = 1; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); md.md_no = i - 1; stripe_metadata_encode(&md, sector); error = g_metadata_store(name, sector, sizeof(sector)); if (error != 0) { fprintf(stderr, "Can't store metadata on %s: %s.\n", name, strerror(error)); gctl_error(req, "Not fully done."); continue; } if (verbose) printf("Metadata value stored on %s.\n", name); } } static void stripe_clear(struct gctl_req *req) { const char *name; char param[16]; unsigned i; int *nargs, error; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { gctl_error(req, "No '%s' argument.", "nargs"); return; } if (*nargs < 1) { gctl_error(req, "Too few arguments."); return; } for (i = 0; i < (unsigned)*nargs; i++) { snprintf(param, sizeof(param), "arg%u", i); name = gctl_get_asciiparam(req, param); error = g_metadata_clear(name, G_STRIPE_MAGIC); if (error != 0) { fprintf(stderr, "Can't clear metadata on %s: %s.\n", name, strerror(error)); gctl_error(req, "Not fully done."); continue; } if (verbose) printf("Metadata cleared on %s.\n", name); } } + +static void +stripe_metadata_dump(const struct g_stripe_metadata *md) +{ + + printf(" Magic string: %s\n", md->md_magic); + printf(" Metadata version: %u\n", (u_int)md->md_version); + printf(" Device name: %s\n", md->md_name); + printf(" Device ID: %u\n", (u_int)md->md_id); + printf(" Disk number: %u\n", (u_int)md->md_no); + printf("Total number of disks: %u\n", (u_int)md->md_all); + printf(" Stripe size: %u\n", (u_int)md->md_stripesize); +} + +static void +stripe_dump(struct gctl_req *req) +{ + struct g_stripe_metadata md, tmpmd; + const char *name; + char param[16]; + int *nargs, error, i; + + nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); + if (nargs == NULL) { + gctl_error(req, "No '%s' argument.", "nargs"); + return; + } + if (*nargs < 1) { + gctl_error(req, "Too few arguments."); + return; + } + + for (i = 0; i < *nargs; i++) { + snprintf(param, sizeof(param), "arg%u", i); + name = gctl_get_asciiparam(req, param); + + error = g_metadata_read(name, (u_char *)&tmpmd, sizeof(tmpmd), + G_STRIPE_MAGIC); + if (error != 0) { + fprintf(stderr, "Can't read metadata from %s: %s.\n", + name, strerror(error)); + gctl_error(req, "Not fully done."); + continue; + } + stripe_metadata_decode((u_char *)&tmpmd, &md); + printf("Metadata on %s:\n", name); + stripe_metadata_dump(&md); + printf("\n"); + } +} diff --git a/sbin/geom/class/stripe/gstripe.8 b/sbin/geom/class/stripe/gstripe.8 index 327cd9a1e893..59b0709afbf3 100644 --- a/sbin/geom/class/stripe/gstripe.8 +++ b/sbin/geom/class/stripe/gstripe.8 @@ -1,210 +1,216 @@ .\" Copyright (c) 2004 Pawel Jakub Dawidek .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" 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. .\" .\" $FreeBSD$ .\" .Dd May 21, 2004 .Dt GSTRIPE 8 .Os .Sh NAME .Nm gstripe .Nd "control utility for striped devices" .Sh SYNOPSIS .Nm .Cm create .Op Fl v .Op Fl s Ar stripesize .Ar name .Ar dev1 .Ar dev2 .Op Ar dev3 Op Ar ... .Nm .Cm destroy .Op Fl fv .Ar name .Op Ar name2 Op Ar ... .Nm .Cm label .Op Fl v .Op Fl s Ar stripesize .Ar name .Ar dev1 .Ar dev2 .Op Ar dev3 Op Ar ... .Nm .Cm stop .Op Fl fv .Ar name .Op Ar name2 Op Ar ... .Nm .Cm clear .Op Fl v .Ar dev1 .Op Ar dev2 Op Ar ... .Nm +.Cm dump +.Ar dev1 +.Op Ar dev2 Op Ar ... +.Nm .Cm list .Op Ar prov Op Ar ... .Nm .Cm load .Op Fl v .Nm .Cm unload .Op Fl v .Sh DESCRIPTION The .Nm utility is used for setting up stripe on two or more disks. The striped device can be configured using two different methods: .Dq manual or .Dq automatic . When using the .Dq manual method, no metadata are stored on the devices, so the striped device has to be configured by hand every time it is needed. The .Dq automatic method uses on-disk metadata to detect devices. Once devices are labeled, they will be automatically detected and configured. .Pp The first argument to .Nm indicates an action to be performed: .Bl -tag -width ".Cm destroy" .It Cm create Set up a striped device from the given devices with specified .Ar name . This is the .Dq manual method. The kernel module .Pa geom_stripe.ko will be loaded if it is not loaded already. .It Cm label Set up a striped device from the given devices with the specified .Ar name . This is the .Dq automatic method, where metadata are stored in every device's last sector. The kernel module .Pa geom_stripe.ko will be loaded if it is not loaded already. .It Cm stop Turn off existing striped device by its .Ar name . This command does not touch on-disk metadata! .It Cm destroy Same as .Cm stop . .It Cm clear Clear metadata on the given devices. +.It Cm dump +Dump metadata stored on the given devices. .It Cm list List all or the given currently configured devices. .It Cm load Load .Pa geom_stripe.ko kernel module. .It Cm unload Unload .Pa geom_stripe.ko kernel module. .El .Pp Additional options: .Bl -tag -width ".Fl s Ar stripesize" .It Fl f Force the removal of the specified striped device. .It Fl s Ar stripesize Specifies size of stripe block. .It Fl v Be more verbose. .El .Sh SYSCTL VARIABLES The following .Xr sysctl 8 variables can be used to control the behavior of the .Nm STRIPE GEOM class. The default value is shown next to each variable. .Bl -tag -width indent .It Va kern.geom.stripe.debug : No 0 Debug level of the .Nm STRIPE GEOM class. This can be set to a number between 0 and 3, both included. If set to 0 minimal debug information is printed, and if set to 3 the maximum amount of debug information in printed. .It Va kern.geom.stripe.fast : No 1 If set to a non-zero value enable .Dq "fast mode" instead of the normal .Dq "economic mode" . Compared to .Dq "economic mode" .Dq "fast mode" uses more memory, but it is much faster for smaller stripe sizes. If enough memory cannot be allocated .Nm STRIPE will fall back to .Dq "economic mode" . .It Va kern.geom.stripe.maxmem : No 1310720 Maximum amount of memory that can be consumed by .Dq "fast mode" (in bytes). This .Xr sysctl 8 variable is read-only and can only be set as a tunable in .Xr loader.conf 5 . .El .Sh EXAMPLES The following example shows how to set up striped device from four disks for automatic configuration, create a file system on it, and mount it: .Bd -literal -offset indent gstripe label -v -s 4096 data /dev/da0 /dev/da1 /dev/da2 /dev/da3 newfs /dev/data.stripe mount /dev/data.stripe /mnt [...] umount /mnt gstripe stop data gstripe unload .Ed .Sh DIAGNOSTICS Exit status is 0 on success, and 1 if the command fails. .Sh SEE ALSO .Xr geom 4 , .Xr loader.conf 5 , .Xr geom 8 , .Xr mount 8 , .Xr newfs 8 , .Xr sysctl 8 , .Xr umount 8 , .Xr vinum 8 .Sh HISTORY The .Nm utility appeared in .Fx 5.3 . .Sh AUTHORS .An Pawel Jakub Dawidek Aq pjd@FreeBSD.org