Encapsulate the checks that I do before detaching a disk(9) provider
in a pre-detachment routine, disk_predetach().
This commit is contained in:
parent
3431c6b695
commit
a76a7fd159
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: subr_disk.c,v 1.95 2009/04/04 07:30:10 ad Exp $ */
|
||||
/* $NetBSD: subr_disk.c,v 1.96 2009/05/19 23:42:05 dyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
|
||||
@ -67,7 +67,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.95 2009/04/04 07:30:10 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.96 2009/05/19 23:42:05 dyoung Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
@ -216,6 +216,25 @@ disk_attach(struct disk *diskp)
|
||||
diskp->dk_stats = iostat_alloc(IOSTAT_DISK, diskp, diskp->dk_name);
|
||||
}
|
||||
|
||||
int
|
||||
disk_predetach(struct disk *dk, int (*lastclose)(device_t),
|
||||
device_t self, int flags)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = 0;
|
||||
mutex_enter(&dk->dk_openlock);
|
||||
if (dk->dk_openmask == 0)
|
||||
; /* nothing to do */
|
||||
else if ((flags & DETACH_FORCE) == 0)
|
||||
rc = EBUSY;
|
||||
else if (lastclose != NULL)
|
||||
rc = (*lastclose)(self);
|
||||
mutex_exit(&dk->dk_openlock);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Detach a disk.
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: disk.h,v 1.52 2009/04/04 07:30:09 ad Exp $ */
|
||||
/* $NetBSD: disk.h,v 1.53 2009/05/19 23:42:05 dyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
|
||||
@ -497,6 +497,7 @@ extern int disk_count; /* number of disks in global disklist */
|
||||
struct proc;
|
||||
|
||||
void disk_attach(struct disk *);
|
||||
int disk_predetach(struct disk *, int (*)(device_t), device_t, int);
|
||||
void disk_detach(struct disk *);
|
||||
void disk_init(struct disk *, const char *, const struct dkdriver *);
|
||||
void disk_destroy(struct disk *);
|
||||
|
Loading…
Reference in New Issue
Block a user