History log of /freebsd-current/sys/geom/geom_ctl.c
Revision Date Author Comments
# bbf221e3 25-Dec-2023 Mark Johnston <markj@FreeBSD.org>

geom: Report copyout() errors in g_ctl_ioctl_ctl()

Despite the name, req->serror is used in some cases to copy non-error
messages to userspace. So, report errors when copying out so long as
they don't clobber an earlier error.

Reviewed by: mav, imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43146


# fdafd315 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 90e29718 16-Jul-2022 Kirk McKusick <mckusick@FreeBSD.org>

Clarify when GEOM utilities exit with success or failure.

Historically, GEOM utilities (gpart(8), gstripe(8), gmirror(8),
etc) used the gctl_error() routine to report errors. If they called
gctl_error() they would exit with EXIT_FAILURE, otherwise they would
return with EXIT_SUCCESS. If they used gctl_error() to output an
informational message, for example when run with the -v (verbose)
option, they would mistakenly exit with EXIT_FAILURE. A further
limitation of the gctl_error() function was that it could only be
called once. Messages from any additional calls to gctl_error()
would be silently discarded.

To resolve these problems a new function, gctl_msg() has been added.
It can be called multiple times to output multiple messages. It
also has an additional errno argument which should be zero if it is
an informational message or an errno value (EINVAL, EBUSY, etc) if
it is an error. When done the gctl_post_messages() function should
be called to indicate that all messages have been posted. If any
of the messages had a non-zero errno, the utility will EXIT_FAILURE.
If only informational messages (with zero errno) were posted, the
utility will EXIT_SUCCESS.

Tested by: Peter Holm
PR: 265184
MFC after: 1 week


# 7f16b501 12-Mar-2022 Alexander Motin <mav@FreeBSD.org>

GEOM: Introduce partial confxml API

Traditionally the GEOM's primary channel of information from kernel to
user-space was confxml, fetched by libgeom through kern.geom.confxml
sysctl. It is convenient and informative, representing full state of
GEOM in a single XML document. But problems start to arise on systems
with hundreds of disks, where the full confxml size reaches many
megabytes, taking significant time to first write it and then parse.

This patch introduces alternative solution, allowing to fetch much
smaller XML document, subset of the full confxml, limited to 64KB and
representing only one specified geom and optionally its parents. It
uses existing GEOM control interface, extended with new "getxml" verb.
In case of any error, such as the buffer overflow, it just transparently
falls back to traditional full confxml. This patch uses the new API in
user-space GEOM tools where it is possible.

Reviewed by: imp
MFC after: 2 month
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D34529


# dd7a5bc1 07-Mar-2022 Alexander Motin <mav@FreeBSD.org>

GEOM: Make G_F_CTLDUMP also dump result.

MFC after: 1 month


# 01b9c48b 07-Mar-2022 Alexander Motin <mav@FreeBSD.org>

GEOM: Skip copyin() for GCTL_PARAM_WR parameters.

Kernel does not read those parameters, so copyin is pointless.

While there, replace some KASSERT()s with CTASSERT()s.

MFC after: 1 month


# c8cc5689 19-Feb-2022 Kirk McKusick <mckusick@FreeBSD.org>

Provide an interface that allows GEOM modules to return multiple messages.

The gctl_error() function provides GEOM modules with the ability
to report only a single message. When running with the verbose
flag, commands that handle multiple devices may want to report a
message for each of the devices on which it operates. This commit
adds the gctl_msg() function that can be called multiple times
to post messages. When finished issuing messages, the application
must either call gctl_post_messages() or call gctl_error() to cause
the messages to be reported to the calling process.

Tested by: Peter Holm


# a2b559df 20-Oct-2020 Robert Wing <rew@FreeBSD.org>

geom_ctl.c: remove stale header files

- Remove "opt_geom.h", no kernel options are used.

- Remove <sys/sysctl.h>, no sysctl functionality is used here.

- Remove <sys/bio.h>, requirements for bio moved out in r112534.

- Remove <sys/lock.h> and <sys/mutex.h>, last used by DROP_GIANT() and
PICKUP_GIANT(), which were removed in r115624.

- Remove <sys/disk.h> and <sys/kernel.h>, not used.

Reviewed by: phk, kevans (mentor)
Approved by: phk, kevans (mentor)
Differential Revision: https://reviews.freebsd.org/D26805


# d40bc607 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

geom: clean up empty lines in .c and .h files


# a450ecfd 26-Jul-2020 Xin LI <delphij@FreeBSD.org>

gctl_get_geom: Skip validation of g_class.

The caller from kernel is expected to provide an valid g_class
pointer, instead of traversing the global g_class list, just
use that pointer directly instead.

Reviewed by: mav
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D25811


# 0ab851aa 21-Jul-2020 Xin LI <delphij@FreeBSD.org>

gctl_get_class, gctl_get_geom and gctl_get_provider: provide feedback
when the requested argument is missing.

Reviewed by: cem
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D25738


# 283a5a37 23-Nov-2019 Warner Losh <imp@FreeBSD.org>

We don't even need Giant here. It isn't protecting anything internal
to geom, and nothing we call requires it to be held. It's left over
from a time when the latter wasn't the case. Retire it.

Reviewed in concept: scottl@


# 1e00bb45 16-Oct-2019 Chuck Silvers <chs@FreeBSD.org>

Add a new gctl_get_paraml_opt() interface to extract optional parameters from
the request. It is the same as gctl_get_paraml() except that the request
is not marked with an error if the parameter is not present.

Approved by: imp (mentor)
Reviewed by: cem
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D21972


# cd2e9086 20-Feb-2019 Mark Johnston <markj@FreeBSD.org>

Define a constant for the maximum number of GEOM_CTL arguments.

Reviewed by: eugen
MFC with: r344305
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D19271


# 60a92c78 19-Feb-2019 Mark Johnston <markj@FreeBSD.org>

Impose a limit on the number of GEOM_CTL arguments.

Otherwise a privileged user can trigger a memory allocation of
unbounded size, or an integer overflow in the subsequent
geom_alloc_copyin() call, leading to out-of-bounds accesses.

Hard-code a large limit to circumvent this problem.

admbug: 854
Reported by: Anonymous of the Shellphish Grill Team
Reviewed by: ae
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D19251


# 3728855a 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/geom: adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# b99bce73 27-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

geom: unsign some types to match their definitions and avoid overflows.

In struct:gctl_req, nargs is unsigned.

In mirror:
g_mirror_syncreqs is unsigned.

In raid:
in struct:g_raid_volume, v_disks_count is unsigned.

In virstor:
in struct:g_virstor_softc, n_components is unsigned.

MFC after: 2 weeks


# 524d7a4d 23-Jan-2014 Andrey V. Elsukov <ae@FreeBSD.org>

Always free sbuf in gctl_free().

MFC after: 1 week


# d14a7ff1 23-Jan-2014 Andrey V. Elsukov <ae@FreeBSD.org>

Remove another unneeded NULL check from geom_alloc_copyin().
Do copyout in case of gctl version mismatch and fix sbuf leak in
g_ctl_ioctl_ctl().

MFC after: 1 week


# 7f0e13df 23-Jan-2014 Andrey V. Elsukov <ae@FreeBSD.org>

In gctl_copyin() remove unused error variable.
geom_alloc_copyin() can't return ENOMEM, so describe its fail as bad
control request. Add check for NULL pointer in gctl_dump(), since it
can be NULL when geom_alloc_copyin() failed.

MFC after: 1 week


# 625ee733 23-Jan-2014 Andrey V. Elsukov <ae@FreeBSD.org>

Fix typo in r261084.
Add to the gctl_error() an ability to specify error description even
if numeric error code is already specified. Also by default set
error code to EINVAL.

PR: 185852
MFC after: 1 week


# ee839ce8 23-Jan-2014 Andrey V. Elsukov <ae@FreeBSD.org>

malloc() with M_WAITOK doesn't return NULL.

MFC after: 1 week


# 23b70c1a 04-Jan-2011 Konstantin Belousov <kib@FreeBSD.org>

Finish r210923, 210926. Mark some devices as eternal.

MFC after: 2 weeks


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 2616144e 09-Aug-2008 Dag-Erling Smørgrav <des@FreeBSD.org>

Add sbuf_new_auto as a shortcut for the very common case of creating a
completely dynamic sbuf.

Obtained from: Varnish
MFC after: 2 weeks


# a92b7d49 30-Mar-2007 Xin LI <delphij@FreeBSD.org>

- Be more verbose when saying "foo" not found.
- In gctl_get_geom(), don't issue error when we were not
provided with an parameter, like gctl_get_provider() did.

Reviewed by: pjd


# 41063f93 07-Apr-2006 Marcel Moolenaar <marcel@FreeBSD.org>

Change gctl_set_param() to return an error instead of setting an
error on the request. Add a wrapper, gctl_set_param_err(), that
sets the error on the request from the error returned by
gctl_set_param() and update current callers of gctl_set_param()
to call gctl_set_param_err() instead.
This makes gctl_set_param() much more usable in situations where
the caller knows better what to do with certain (apparent) error
conditions and setting an error on the request is not one of the
things that need to be done.


# 40fcaded 18-Sep-2005 Marcel Moolenaar <marcel@FreeBSD.org>

o Don't cause a panic when the control request lacks a verb.
o Don't set the error twice when the named class does not exist.
It causes ioctl(2) to return with error EEXIST.


# 52d71e1a 16-Aug-2005 Poul-Henning Kamp <phk@FreeBSD.org>

remove stale comments


# cdae8431 08-Apr-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Fix a long-standing bug. Error string has to be copyied from the user
process context.

Approved by: phk
MFC after: 3 days


# e8cde1ac 17-Jan-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Discontinue zero-length g_ctl arguments as "just give him this pointer"
transfers. The necessary context for calling copyin() isn't available
anyway and automatic code-validation chokes on this.


# 85986ce0 23-Oct-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Don't call g_waitidle(), it happens automagically now.


# 89c9c53d 16-Jun-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# dc08ffec 21-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Device megapatch 4/6:

Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.


# 70cd7713 26-Sep-2003 Poul-Henning Kamp <phk@FreeBSD.org>

The present defaults for the open and close for device drivers which
provide no methods does not make any sense, and is not used by any
driver.

It is a pretty hard to come up with even a theoretical concept of
a device driver which would always fail open and close with ENODEV.

Change the defaults to be nullopen() and nullclose() which simply
does nothing.

Remove explicit initializations to these from the drivers which
already used them.


# fd02a423 02-Jul-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Only dump 512 bytes of debugging.

Always wait for things to settle before returning.


# 50b1faef 11-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID().

Approved by: phk


# b61e8fed 07-Jun-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Make sure we return an error message if the geom parameter is not
located.


# a1a9b445 07-Jun-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Add missing va_end() calls.

Noticed by: tmm


# d6c5e716 04-Jun-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Introduce g_provider_by_name() function, and use it.


# 786a6905 02-Jun-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Return an indicative error message.


# 83d771de 01-Jun-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Simplify the GEOM OAM api: Drop the request type, and let everything
hinge on the "verb" parameter which the class gets to interpret as
it sees fit.

Move the entire request into the kernel and move changed parameters
back when done.


# 1ee055e6 04-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Add gctl_set_param() function.


# 3e7b7bb1 01-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Plug memory leaks.


# c4da4e46 02-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Back out all the stuff that didn't belong in the last commit.


# e65ab0f8 02-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Use g_slice_spoiled() rather than g_std_spoiled().

Remember to free the buffer we got from g_read_data().


# ca3d750e 23-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Introduce gctl_get_paraml() which gets a parameter only if it has the
right length.


# fb9483af 23-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Make gctl_error() take printfline varargs.


# ea9ab6be 22-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Implement handling of CONFIG_GEOM OAM request.


# 70b4ddbb 22-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Collapse meta arguments into regular arguments, the distinction is
more trouble than it is worth.


# 68f15640 03-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Make sure we don't ignore error codes.


# 4a1e273c 01-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Remove the old config interface, the new OAM is sufficiently functional
now.


# afa2a5aa 31-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Remove some debugging in the new OAM[*] and add a debug flag for other
parts of it.

[*] I've been asked what "OAM" means: It's an acronym used in the
telecom industry, "Operations And Maintenance", and there it covers
anything from a single unlabeled led on the frontpanel the the full
nightmare of CMIP for SS7.


# 63728c47 27-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Run a revision on the OAM api.

Use prefix gctl_ systematically.
Add flag with access perms for each argument.
Add ro/rw versions of argument building functions.
General cleanup.


# d49d7ca5 24-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Turn /dev/geom.ctl from a GEOM class into a plain character device driver
instead, it will never see a disk-I/O transaction, so this is a lot simpler.


# 3117e544 23-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Marshalling stuff for OAM API.


# b4b138c2 18-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Including <sys/stdint.h> is (almost?) universally only to be able to use
%j in printfs, so put a newsted include in <sys/systm.h> where the printf
prototype lives and save everybody else the trouble.


# a163d034 18-Feb-2003 Warner Losh <imp@FreeBSD.org>

Back out M_* changes, per decision of the TRB.

Approved by: trb


# 44956c98 21-Jan-2003 Alfred Perlstein <alfred@FreeBSD.org>

Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.


# e6e14239 06-Nov-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Straighten up the geom.ctl config interface definitions.

Sponsored by: DARPA & NAI Labs


# 3f12caa1 20-Oct-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Now that the sectorsize and mediasize are properties of the provider,
don't take the detour over the I/O path to discover them using getattr(),
we can just pick them out directly.

Do note though, that for now they are only valid after the first open
of the underlying disk device due compatibility with the old disk_create()
API. This will change in the future so they will always be valid.

Sponsored by: DARPA & NAI Labs.


# 9b232f14 20-Oct-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Make it possible to specify also via geom_t ID in the geom.ctl config ioctl.

Sponsored by: DARPA & NAI Labs.


# 6b4abfd6 14-Oct-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Implement the GEOMCONFIGGEOM ioctl which can be used to manually create
and configure an instance of a class on a give provider.

Sponsored by: DARPA & NAI Labs


# 3101ed1b 13-Oct-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Add the outline of the "/dev/geom.ctl" handling code.

Sponsored by: DARPA & NAI Labs.