DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

rm_dev(D2sdi)


rm_dev -- remove a device

Synopsis

   #include <sys/sdi.h>
   #include <sys/ddi.h>

int prefixrm_dev(struct scsi_adr *sa);

Description

The rm_dev( ) prepares a peripheral device for removal from the system. It is required in target drivers that support hot insertion and removal.

Arguments


sa
SCSI address of device to be removed

Return values

This function should return SDI_RET_OK on success or SDI_RET_ERR on failure. It should fail if the device does not exist or has pending jobs.

Usage

The rm_dev( ) entry point routine prepares a device for removal from the system. This usually entails flushing any cache on the device, and possibly spinning down or unmounting the device. It also removes the specified device from the driver's internal structures. After it removes the devices from its internal structures, it must call the sdi_clrconfig(D3sdi) function.

The rm_dev( ) entry point is registered with SDI through the sdi_target_hotregister(D3sdi) function that is called from the rinit(D2sdi) entry point routine.

Context and synchronization

Non-blockable context. Interrupts are enabled but processes are not yet or no longer available.

Applicable hardware

All

Version applicability

sdi: 3, 4 target drivers.

See Also

sdi_clrconfig(D3sdi), hba_info(D4sdi), scsi_adr(D4sdi), sdi_target_hotregister(D3sdi)

``SDI peripheral hot add/remove'' in HDK Technical Reference

Examples

Following is a simplified example of how an rm_dev routine might be written.
   #define DKINDEX(x)      (x / DK_MAX_SLICE)
   #define DK_MAX_SLICE        512
   

/* * int * sd01rm_dev() * the function to support hot removal of disk drives. * This will spin down the disk and remove it from its internal * structures, sd01_dp. * * returns SDI_RET_ERR or SDI_RET_OK * will fail if the device doesn't exist, is not owned by sd01, * is open. */ int sd01rm_dev(struct scsi_adr *sa) { struct sdi_edt *edtp; struct disk *dp; int index; int part;

ASSERT(sa); edtp = sdi_rxedt(sa->scsi_ctl, sa->scsi_bus, sa->scsi_target, sa->scsi_lun);

if ((edtp == NULL) || /* no device */ (edtp->curdrv == NULL) || /* no owner */ (edtp->curdrv->maj.b_maj != Sd01_bmajor)) /* not mine */ return SDI_RET_ERR;

dp = sd01_dp[DKINDEX(edtp->curdrv->maj.first_minor)];

/* Requested to remove a disk that doesn't exit, return error */ if (dp == NULL) return SDI_RET_ERR;

/* check if the disk is open */ if (sd01_dk_open(dp)) return SDI_RET_ERR; /* flush cache and spin down the disk */ sd01cmd(dp, SS_LOAD, 0, NULL, 0, 0, SCB_READ, FALSE);

sd01_dp[index]=NULL; sd01_dk_free(dp);

sdi_clrconfig(edtp->curdrv, SDI_REMOVE|SDI_DISCLAIM, NULL);

return SDI_RET_OK; }


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005