Commit Graph

67 Commits

Author SHA1 Message Date
Colin Percival
8b8a7c43a9 Instrument "boot holds" for the benefit of the TSLOG framework. These
are places where the "main thread" of the booting kernel (either the
thread which later becomes swapper or the thread which later becomes
init) has to stop and wait for action to take place in another thread
before continuing.

There are currently three such holds:
1. The intr_config_hooks SYSINIT waits for hooks registered via the
config_intrhook_establish function; this allows (typically) devices
which need interrupts enabled to complete their initialization to do
so before root is mounted.

2. The g_waitidle function waits for the GEOM event queue to be empty;
this ensures that all of the disks which have been attached have been
tasted before we attempt to mount root.

3. The vfs_mountroot_wait function (in addition to calling g_waitidle)
waits for holds registered via root_mount_hold; among other things, this
is used by the USB subsystem to ensure that we don't fail to mount root
if it's located on a USB disk which takes a while to probe.
2017-12-31 09:23:52 +00:00
Pedro F. Giffuni
3728855a0f 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.
2017-11-27 15:17:37 +00:00
Konstantin Belousov
dff9131e58 Remove asserts that Giant is not held on entrance into geom KPI, which
outlived their usefulness.  This allows to remove drop/pickup Giant
wrappers around GEOM calls.

Discussed with:	alfred, imp, phk
Sponsored by:	The FreeBSD Foundation
2016-05-20 08:22:20 +00:00
Andrey V. Elsukov
362073c089 We have two functions from where a geom orphan method could be called:
g_orphan_register and g_resize_provider_event. Both are called from the
event queue. Also we have GEOM_DEV class, which does deferred destroy
for its consumers via g_dev_destroy (also called from the event queue).
So it is possible, that for some consumers an orphan method will be
called twice. This triggers panic in g_dev_orphan.
Check that consumer isn't already orphaned before call orphan method.

MFC after:	2 weeks
2014-05-19 16:05:42 +00:00
Alexander Motin
50199fa0d0 Make g_wither_washer() to not loop by itself, but only when there was some
more topology change done that may require its attention.  Add few missing
g_do_wither() calls in respective places to signal it.

This fixes potential infinite loop here when some provider is withered, but
still opened or connected for some reason and so can not be destroyed.  For
example, see r227009 and r227510.
2013-03-24 03:15:20 +00:00
Alexander Motin
3631c6382f Implement media change notification for DA and CD removable media devices.
It includes three parts:
 1) Modifications to CAM to detect media media changes and report them to
disk(9) layer. For modern SATA (and potentially UAS) devices it utilizes
Asynchronous Notification mechanism to receive events from hardware.
Active polling with TEST UNIT READY commands with 3 seconds period is used
for incapable hardware. After that both CD and DA drivers work the same way,
detecting two conditions: "NOT READY: Medium not present" after medium was
detected previously, and "UNIT ATTENTION: Not ready to ready change, medium
may have changed". First one reported to disk(9) as media removal, second
as media insert/change. To reliably receive second event new
AC_UNIT_ATTENTION async added to make UAs broadcasted to all periphs by
generic error handling code in cam_periph_error().
 2) Modifications to GEOM core to handle media remove and change events.
Media removal handled by spoiling all consumers attached to the provider.
Media change event also schedules provider retaste after spoiling to probe
new media. New flag G_CF_ORPHAN was added to consumers to reflect that
consumer is in process of destruction. It allows retaste to create new
geom instance of the same class, while previous one is still dying.
 3) Modifications to some GEOM classes: DEV -- to report media change
events to devd; VFS -- to handle spoiling same as orphan to prevent
accessing replaced media. PART class already handles spoiling alike to
orphan.

Reviewed by:	silence on geom@ and scsi@
Tested by:	avg
Sponsored by:	iXsystems, Inc. / PC-BSD
MFC after:	2 months
2012-07-29 11:51:48 +00:00
Alexander Motin
20a5d5dc60 Workaround the problem introduced by combination of r162200 and r215687.
r162200 delays provider orphanization until all running requests complete,
to workaround broken orphan() method implementation in some classes.
r215687 removes persistent periodic (10Hz) event thread wake ups.
Together these changes can indefinitely delay orphanization until some
other event wake up the event thread. One consequence of this is inability
of CAM to destroy device disconnected when busy and, as consequence, create
new one after reconnection.

While the best solution would be to revert r162200, it is not easy, as
some classes still look broken in that way. Instead conditionally wake up
event thread if there are some providers waiting for orphanization.

MFC after:	1 week
2011-11-01 08:57:49 +00:00
Justin T. Gibbs
416494d7c9 Plumb device physical path reporting from CAM devices, through GEOM and
DEVFS, and make it accessible via the diskinfo utility.

Extend GEOM's generic attribute query mechanism into generic disk consumers.
sys/geom/geom_disk.c:
sys/geom/geom_disk.h:
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
	- Allow disk providers to implement a new method which can override
	  the default BIO_GETATTR response, d_getattr(struct bio *).  This
	  function returns -1 if not handled, otherwise it returns 0 or an
	  errno to be passed to g_io_deliver().

sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
	- Don't copy the serial number to dp->d_ident anymore, as the CAM XPT
	  is now responsible for returning this information via
	  d_getattr()->(a)dagetattr()->xpt_getatr().

sys/geom/geom_dev.c:
	- Implement a new ioctl, DIOCGPHYSPATH, which returns the GEOM
	  attribute "GEOM::physpath", if possible.  If the attribute request
	  returns a zero-length string, ENOENT is returned.

usr.sbin/diskinfo/diskinfo.c:
	- If the DIOCGPHYSPATH ioctl is successful, report physical path
	  data when diskinfo is executed with the '-v' option.

Submitted by:	will
Reviewed by:	gibbs
Sponsored by:	Spectra Logic Corporation

Add generic attribute change notification support to GEOM.

sys/sys/geom/geom.h:
	Add a new attrchanged method field to both g_class
	and g_geom.

sys/sys/geom/geom.h:
sys/geom/geom_event.c:
	- Provide the g_attr_changed() function that providers
	  can use to advertise attribute changes.
	- Perform delivery of attribute change notifications
	  from a thread context via the standard GEOM event
	  mechanism.

sys/geom/geom_subr.c:
	Inherit the attrchanged method from class to geom (class instance).

sys/geom/geom_disk.c:
	Provide disk_attr_changed() to provide g_attr_changed() access
	to consumers of the disk API.

sys/cam/scsi/scsi_pass.c:
sys/cam/scsi/scsi_da.c:
sys/geom/geom_dev.c:
sys/geom/geom_disk.c:
	Use attribute changed events to track updates to physical path
	information.

sys/cam/scsi/scsi_da.c:
	Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
	events for this driver.  When this event occurs, and
	the updated buffer type references our physical path
	attribute, emit a GEOM attribute changed event via the
	disk_attr_changed() API.

sys/cam/scsi/scsi_pass.c:
	Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
	events for this driver.  When this event occurs, update
	the physical patch devfs alias for this pass instance.

Submitted by:	gibbs
Sponsored by:	Spectra Logic Corporation
2011-06-14 17:10:32 +00:00
Jaakko Heinonen
f7842e00f5 Use g_eventlock to protect against losing wakeups in the g_event process
and replace tsleep(9) with msleep(9) which doesn't use a timeout. The
previously used timeout caused the event process to wake up ten times
per second on an idle system.

one_event() is now called with the topology lock held and it returns
with both the topology and event locks held when there are no more
events in the queue.

Reported by:	mav, Marius Nünnerich
Reviewed by:	freebsd-geom
2010-11-22 16:47:53 +00:00
Jaakko Heinonen
9d142a6ee6 Extend the g_eventlock mutex coverage in one_event() to include setting
of the EV_DONE flag and use the mutex to protect against losing wakeups
in g_waitfor_event().

Reported by:	davidxu
Tested by:	davidxu
Discussed on:	freebsd-current
2010-11-03 16:19:35 +00:00
Matt Jacob
59ccfe8176 Try and narrow the gap in which you act on an event that has been canceled.
Obtained from:	Jaako Heinonen
MFC after:	1 month
2010-06-08 22:40:02 +00:00
Pawel Jakub Dawidek
3ea5d7ec24 When orphaning a provider, cancel events related to it.
Without this change the following situation was possible:

1. Provider is orphaned from within class' access() method on last write
   close - orphan provider event is send.
2. GEOM detects last write close on a provider and sends new provider event.
3. g_orphan_register() is called, and calls all orphan methods of attached
   consumers.
4. New provider event is executed on orphaned provider, all classes can
   taste already orphaned provider, and some may attach consumers to it.
   Those consumers will never go away, because the g_orphan_register()
   was already called.

We end up with a zombie provider.

With this change, at step 3, we will cancel new provider event.

How to repeat this problem:

	# mdconfig -a -t malloc -s 10m
	# geli init -i 0 md0
	# geli attach md0
	# newfs -L test /dev/md0.eli
	# mount /dev/ufs/test /mnt/tmp
	# geli detach -l md0.eli
	# umount /mnt/tmp
	# glabel status
            Name  Status  Components
        ufs/test  N/A     N/A

Reviewed by:	phk
Approved by:	re (kensmith)
2007-09-27 20:18:34 +00:00
Pawel Jakub Dawidek
d6b910d295 Delay an orphan event if provider has still in-flight I/O requests.
This way GEOM classes can safely detach from provider when an orphan
event is received. This fixes 'detach with active requests' panic for
gstripe/gconcat under load.

PR:		kern/102766
Submitted by:	mjacob
OK'ed by:	phk
MFC after:	1 week
2006-09-10 09:11:54 +00:00
Poul-Henning Kamp
e4da09c03f Remove a race condition that could result in processes being stuck
waiting for geom events to happen:

Instead of maintaining a count of outstanding events, simply look if
the queue is empty.  Make sure to not remove events from the queue
until they are executed in order to not open a new race.

Much work by:	pjd
Tested by:	kris
MT6:		yes, should be.
2005-09-04 19:14:19 +00:00
Pawel Jakub Dawidek
d246aa55e7 Correct typo. 2005-05-18 21:53:08 +00:00
Pawel Jakub Dawidek
b8005b9b24 Introduce g_waitidlelock() function which is simlar to g_waitidle(),
but should be called with the topology lock held and returns with the
topology lock held and empty event queue.

Approved by:	phk (sometime ago)
2004-11-09 23:20:50 +00:00
Poul-Henning Kamp
9197ce2ee5 Add a new per-thread private flag: TDP_GEOM.
This flag gets set whenever the thread posts an event on the GEOM
event queue, and if the flag is set when the thread is prepared
to return to userland from the kernel, g_waitidle() will be called
to make sure that the posted events have completed.

This can replace an insufficient number of g_waitidle() calls in
various other places, and has the advantage of being failsafe:  Any
system call which does a VOP_OPEN()/VOP_CLOSE will now correctly
wait for any geom events it posted as part of spoils or tastes.

Assert that topology and Giant is not held in g_waitidle().
2004-10-23 20:49:17 +00:00
Poul-Henning Kamp
1b464bd889 Make withering water tight.
When we orphan/wither a provider, an attached geom+consumer could
end up being withered as a result and it may be in front of us in
the normal object scanning order so we need to do multi-pass.  On
the other hand, there may be withering stuff we can't get rid off
(yet), so we need to keep track of both the existence of withering
stuff and if there is more we can do at this time.
2004-07-08 16:17:14 +00:00
Poul-Henning Kamp
3d1d5bc3c3 Rearrange some of the GEOM debugging tools to be more structured.
Retire g_sanity() and corresponding debugflag (0x8)

  Retire g_{stall,release}_events().

  Under #ifdef DIAGNOSTIC:

    Make g_valid_obj() an official function and have it return an an
    non-zero integer which indicates the kind of object when found.

    Implement G_VALID_{CLASS,GEOM,CONSUMER,PROVIDER}() macros based
    on g_valid_obj().

    Sprinkle calls to these macros liberally over the infrastructure.

    Always check that we do not free a live object.
2004-03-10 08:49:08 +00:00
Pawel Jakub Dawidek
18e88d825c Now we have g_topology_assert_not(), so use it to detect deadlocks.
Approved by:	phk, scottl (mentor)
2004-02-10 15:55:17 +00:00
Poul-Henning Kamp
793ffa8e55 Don't mingle malloc/g_event flags.
Spotted by:	pjd@
2004-02-02 10:58:07 +00:00
Poul-Henning Kamp
57ab2e0468 Make sure to keep track of canceled events.
Submitted by:	Pawel Jakub Dawidek <nick@garage.freebsd.pl>
2004-01-23 21:09:38 +00:00
Poul-Henning Kamp
8592d7a760 Prevent withering of the provider we're orphaning from happening until
we do it ourselves.

Nailed by:	Simon Heath <heath@cng.fr>
2003-12-23 11:37:05 +00:00
Poul-Henning Kamp
d0265773dc KASSERT against multiple orphanings of providers. 2003-12-07 10:04:43 +00:00
Poul-Henning Kamp
e0d617c1f7 Fix a harmless bug and add a ')' in a debugging printf.
Submitted by: "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
2003-11-18 07:54:12 +00:00
Poul-Henning Kamp
b144e6ffeb Destroy providers maked with G_PF_WITHER when the last consumer has detached. 2003-10-12 11:34:35 +00:00
David E. O'Brien
50b1faef38 Use __FBSDID().
Approved by:	phk
2003-06-11 06:49:16 +00:00
Poul-Henning Kamp
a1a9b44569 Add missing va_end() calls.
Noticed by:	tmm
2003-06-07 10:16:53 +00:00
Poul-Henning Kamp
9dfffbc959 Get rid of trivial function g_destroy_event(). 2003-05-02 05:26:19 +00:00
Poul-Henning Kamp
c8589ad169 Add a new flag, EV_CANCELED, and use it to make g_waitfor_event() return
EAGAIN if an event got canceled.
2003-05-01 19:43:52 +00:00
Poul-Henning Kamp
2ab31b05ba When events on a reference is cancelled, check our doorstep first,
it might be an orphan.
2003-05-01 19:24:00 +00:00
Poul-Henning Kamp
0a9c130c06 Introduce a g_waitfor_event() function which posts an event and waits for
it to be run (or cancelled) and use this instead of home-rolled versions.
2003-04-23 21:28:27 +00:00
Poul-Henning Kamp
a974614b05 More of the event stuff can now be private to geom_event.c 2003-04-23 20:54:42 +00:00
Poul-Henning Kamp
8cd1535a24 Rename g_call_me() to g_post_event(), and give it a flag
argument to determine if we can M_WAITOK in malloc.
2003-04-23 20:46:12 +00:00
Poul-Henning Kamp
d98777f8db Remove the now unused hardcoded g_post_event() event support. 2003-04-23 20:25:33 +00:00
Poul-Henning Kamp
9ab3ea7841 Turn EV_NEW_PROVIDER into a g_call_me() event. 2003-04-23 20:16:13 +00:00
Poul-Henning Kamp
f2e9a09494 Convert EV_SPOILED event to use g_call_me(). 2003-04-23 20:06:38 +00:00
Poul-Henning Kamp
9972896c00 Turn the hardwired NEW_CLASS event into a g_call_me() event. 2003-04-23 19:34:38 +00:00
Poul-Henning Kamp
b5cba4167f Move the shutdown eventhandler stuff to a more logical place. 2003-04-23 19:15:27 +00:00
Poul-Henning Kamp
3924ad705e Time has run from the "run GEOM in userland" harness, and the new regression
test is built to test GEOM as running in the kernel.

This commit is basically "unifdef -D_KERNEL" to remove the mainly #include
related code to support the userland-harness.
2003-04-13 09:02:06 +00:00
Poul-Henning Kamp
2b454c0ae5 Fix a bug which resulted in orphanization getting confused every now
and then.
2003-04-12 16:36:19 +00:00
Poul-Henning Kamp
316aed030e Add handling for cancelled events in the g_call_me() methods. 2003-04-02 21:10:04 +00:00
Poul-Henning Kamp
afcbcfaed0 Change events to have an array of "void *" references, and give the
event posting functions varargs to fill these.

Attribute g_call_me() to appropriate g_geom's where necessary.

Add a flag argument to g_call_me() methods which will be used to signal
cancellation of events in the future.

This commit should be a no-op.
2003-04-02 20:41:18 +00:00
Poul-Henning Kamp
fbf79df3b8 Save a lock: Grab the stall_events SX lock exclusively so it also serialize
OAM reqests.
2003-03-24 13:35:06 +00:00
Poul-Henning Kamp
dddc28bfe0 Introduce g_cancel_events() and use it a couple of places where it makes
sense.
2003-03-23 23:01:40 +00:00
Poul-Henning Kamp
d943f1b0b9 Introduce an SX lock which allows us to stall event processing
during OAM operations.
2003-03-23 21:58:09 +00:00
Poul-Henning Kamp
20d2026b4e #ifdef notyet a bit of code which needs not yet committed refcounting to
work correctly.
2003-03-16 16:29:04 +00:00
Poul-Henning Kamp
e582990901 If we run out of consumers while orphaning them, and the provider's geom
is withering, destroy the provider when done.

This was exposed by the recent change to geom_dev's orphaning logic.
2003-03-10 23:41:41 +00:00
Poul-Henning Kamp
f48b881942 Stamp out Danglish. 2003-03-09 10:02:31 +00:00
Warner Losh
a163d034fa Back out M_* changes, per decision of the TRB.
Approved by: trb
2003-02-19 05:47:46 +00:00