mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-25 11:37:56 +00:00
c3fb2891f0
a da(4) instance going away while GEOM is still probing it. In this case, the GEOM disk class instance has been created by disk_create(), and the taste of the disk is queued in the GEOM event queue. While that event is queued, the da(4) instance goes away. When the open call comes into the da(4) driver, it dereferences the freed (but non-NULL) peripheral pointer provided by GEOM, which results in a panic. The solution is to add a callback to the GEOM disk code that is called when all of its resources are cleaned up. This is implemented inside GEOM by adding an optional callback that is called when all consumers have detached from a provider, and the provider is about to be deleted. scsi_cd.c, scsi_da.c: In the register routine for the cd(4) and da(4) routines, acquire a reference to the CAM peripheral instance just before we call disk_create(). Use the new GEOM disk d_gone() callback to register a callback (dadiskgonecb()/cddiskgonecb()) that decrements the peripheral reference count once GEOM has finished cleaning up its resources. In the cd(4) driver, clean up open and close behavior slightly. GEOM makes sure we only get one open() and one close call, so there is no need to set an open flag and decrement the reference count if we are not the first open. In the cd(4) driver, use cam_periph_release_locked() in a couple of error scenarios to avoid extra mutex calls. geom.h: Add a new, optional, providergone callback that is called when a provider is about to be deleted. geom_disk.h: Add a new d_gone() callback to the GEOM disk interface. Bump the DISK_VERSION to version 2. This probably should have been done after a couple of previous changes, especially the addition of the d_getattr() callback. geom_disk.c: Add a providergone callback for the disk class, g_disk_providergone(), that calls the user's d_gone() callback if it exists. Bump the DISK_VERSION to 2. geom_subr.c: In g_destroy_provider(), call the providergone callback if it has been provided. In g_new_geomf(), propagate the class's providergone callback to the new geom instance. blkfront.c: Callers of disk_create() are supposed to pass in DISK_VERSION, not an explicit disk API version number. Update the blkfront driver to do that. disk.9: Update the disk(9) man page to include information on the new d_gone() callback, as well as the previously added d_getattr() callback, d_descr field, and HBA PCI ID fields. MFC after: 5 days
120 lines
3.8 KiB
C
120 lines
3.8 KiB
C
/*-
|
|
* Copyright (c) 2003 Poul-Henning Kamp
|
|
* All rights reserved.
|
|
*
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
* DARPA CHATS research program.
|
|
*
|
|
* 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.
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
* products derived from this software without specific prior written
|
|
* permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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$
|
|
*/
|
|
|
|
#ifndef _GEOM_GEOM_DISK_H_
|
|
#define _GEOM_GEOM_DISK_H_
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/queue.h>
|
|
#include <sys/_lock.h>
|
|
#include <sys/_mutex.h>
|
|
#include <sys/disk.h>
|
|
|
|
struct disk;
|
|
|
|
typedef int disk_open_t(struct disk *);
|
|
typedef int disk_close_t(struct disk *);
|
|
typedef void disk_strategy_t(struct bio *bp);
|
|
typedef int disk_getattr_t(struct bio *bp);
|
|
typedef void disk_gone_t(struct disk *);
|
|
typedef int disk_ioctl_t(struct disk *, u_long cmd, void *data,
|
|
int fflag, struct thread *td);
|
|
/* NB: disk_ioctl_t SHALL be cast'able to d_ioctl_t */
|
|
|
|
struct g_geom;
|
|
struct devstat;
|
|
|
|
struct disk {
|
|
/* Fields which are private to geom_disk */
|
|
struct g_geom *d_geom;
|
|
struct devstat *d_devstat;
|
|
int d_destroyed;
|
|
|
|
/* Shared fields */
|
|
u_int d_flags;
|
|
const char *d_name;
|
|
u_int d_unit;
|
|
struct bio_queue_head *d_queue;
|
|
struct mtx *d_lock;
|
|
|
|
/* Disk methods */
|
|
disk_open_t *d_open;
|
|
disk_close_t *d_close;
|
|
disk_strategy_t *d_strategy;
|
|
disk_ioctl_t *d_ioctl;
|
|
dumper_t *d_dump;
|
|
disk_getattr_t *d_getattr;
|
|
disk_gone_t *d_gone;
|
|
|
|
/* Info fields from driver to geom_disk.c. Valid when open */
|
|
u_int d_sectorsize;
|
|
off_t d_mediasize;
|
|
u_int d_fwsectors;
|
|
u_int d_fwheads;
|
|
u_int d_maxsize;
|
|
u_int d_stripeoffset;
|
|
u_int d_stripesize;
|
|
char d_ident[DISK_IDENT_SIZE];
|
|
char d_descr[DISK_IDENT_SIZE];
|
|
uint16_t d_hba_vendor;
|
|
uint16_t d_hba_device;
|
|
uint16_t d_hba_subvendor;
|
|
uint16_t d_hba_subdevice;
|
|
|
|
/* Fields private to the driver */
|
|
void *d_drv1;
|
|
};
|
|
|
|
#define DISKFLAG_NEEDSGIANT 0x1
|
|
#define DISKFLAG_OPEN 0x2
|
|
#define DISKFLAG_CANDELETE 0x4
|
|
#define DISKFLAG_CANFLUSHCACHE 0x8
|
|
|
|
struct disk *disk_alloc(void);
|
|
void disk_create(struct disk *disk, int version);
|
|
void disk_destroy(struct disk *disk);
|
|
void disk_gone(struct disk *disk);
|
|
void disk_attr_changed(struct disk *dp, const char *attr, int flag);
|
|
|
|
#define DISK_VERSION_00 0x58561059
|
|
#define DISK_VERSION_01 0x5856105a
|
|
#define DISK_VERSION_02 0x5856105b
|
|
#define DISK_VERSION DISK_VERSION_02
|
|
|
|
#endif /* _KERNEL */
|
|
#endif /* _GEOM_GEOM_DISK_H_ */
|