Improve the bio(4) API for incoming changes to arcmsr(4) (and perhaps
other drivers in the future): - Added BIOC_SVCHECKING to the BIOCVOL ioctl, to know if a volume is running a consistency check. - Added three more volume levels for the BIOCVOL ioctl. - Added BIOC_SDPASSTHRU to the BIOCDISK ioctl, to know if a disk is in pass-through mode. - Added BIOCDISK_NOVOL; it's used with the same reason than BIOCDISK, but it's used only to get information about the physical disks connected in a controller (regardless if they are in a volume set or not). - Added BIOC_SSDELHOTSPARE, BIOC_SSPASTHRU, BIOC_SSDELPASSTHRU, BIOC_SSCHECKSTART_VOL and BIOC_SSCHECKSTOPVOL; to remove a hot-spare, add and remove a pass-through disk and to start/stop a consistency check in a volume. - Added the BIOC_VOLOPS ioctl; to create/remove a volume set. - Removed the BIOCCREATERAID ioctl, it was too limited for my needs. - Added compatibility ioctls for BIOCDISK and BIOCVOL, enabled via COMPAT_30.
This commit is contained in:
parent
e9596bf19e
commit
59a09b45c9
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bio.c,v 1.4 2007/12/05 07:06:50 ad Exp $ */
|
||||
/* $NetBSD: bio.c,v 1.5 2008/01/02 23:45:03 xtraeme Exp $ */
|
||||
/* $OpenBSD: bio.c,v 1.9 2007/03/20 02:35:55 marco Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -28,7 +28,9 @@
|
|||
/* A device controller ioctl tunnelling device. */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: bio.c,v 1.4 2007/12/05 07:06:50 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bio.c,v 1.5 2008/01/02 23:45:03 xtraeme Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
|
@ -104,6 +106,10 @@ bioioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
{
|
||||
struct bio_locate *locate;
|
||||
struct bio_common *common;
|
||||
#ifdef COMPAT_30
|
||||
struct bioc_disk *bd;
|
||||
struct bioc_vol *bv;
|
||||
#endif
|
||||
char name[16];
|
||||
int error;
|
||||
|
||||
|
@ -111,7 +117,12 @@ bioioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
case BIOCLOCATE:
|
||||
case BIOCINQ:
|
||||
case BIOCDISK:
|
||||
case BIOCDISK_NOVOL:
|
||||
case BIOCVOL:
|
||||
#ifdef COMPAT_30
|
||||
case OBIOCDISK:
|
||||
case OBIOCVOL:
|
||||
#endif
|
||||
error = kauth_authorize_device_passthru(l->l_cred, dev,
|
||||
KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READCONF, addr);
|
||||
if (error)
|
||||
|
@ -119,6 +130,7 @@ bioioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
break;
|
||||
case BIOCBLINK:
|
||||
case BIOCSETSTATE:
|
||||
case BIOCVOLOPS:
|
||||
error = kauth_authorize_device_passthru(l->l_cred, dev,
|
||||
KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITECONF, addr);
|
||||
if (error)
|
||||
|
@ -154,7 +166,7 @@ bioioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
switch (cmd) {
|
||||
case BIOCLOCATE:
|
||||
locate = (struct bio_locate *)addr;
|
||||
error = copyinstr(locate->bl_name, name, 16, NULL);
|
||||
error = copyinstr(locate->bl_name, name, sizeof(name), NULL);
|
||||
if (error != 0)
|
||||
return error;
|
||||
locate->bl_cookie = bio_lookup(name);
|
||||
|
@ -170,6 +182,44 @@ bioioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
|
|||
return ENOENT;
|
||||
}
|
||||
mutex_exit(&bio_lock);
|
||||
#ifdef COMPAT_30
|
||||
switch (cmd) {
|
||||
case OBIOCDISK:
|
||||
{
|
||||
bd = malloc(sizeof(*bd), M_DEVBUF, M_WAITOK|M_ZERO);
|
||||
|
||||
memcpy(bd, addr, sizeof(struct obioc_disk));
|
||||
error = bio_delegate_ioctl(
|
||||
(struct bio_mapping *)common->bc_cookie,
|
||||
BIOCDISK, bd);
|
||||
if (error) {
|
||||
free(bd, M_DEVBUF);
|
||||
return error;
|
||||
}
|
||||
|
||||
memcpy(addr, bd, sizeof(struct obioc_disk));
|
||||
free(bd, M_DEVBUF);
|
||||
return 0;
|
||||
}
|
||||
case OBIOCVOL:
|
||||
{
|
||||
bv = malloc(sizeof(*bv), M_DEVBUF, M_WAITOK|M_ZERO);
|
||||
|
||||
memcpy(bv, addr, sizeof(struct obioc_vol));
|
||||
error = bio_delegate_ioctl(
|
||||
(struct bio_mapping *)common->bc_cookie,
|
||||
BIOCVOL, bv);
|
||||
if (error) {
|
||||
free(bv, M_DEVBUF);
|
||||
return error;
|
||||
}
|
||||
|
||||
memcpy(addr, bv, sizeof(struct obioc_vol));
|
||||
free(bv, M_DEVBUF);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
error = bio_delegate_ioctl(
|
||||
(struct bio_mapping *)common->bc_cookie, cmd, addr);
|
||||
return error;
|
||||
|
@ -185,8 +235,7 @@ bio_register(struct device *dev, int (*ioctl)(struct device *, u_long, void *))
|
|||
if (!bio_lock_initialized)
|
||||
bio_initialize();
|
||||
|
||||
bm = (struct bio_mapping *)malloc(sizeof(*bm), M_DEVBUF,
|
||||
M_NOWAIT|M_ZERO);
|
||||
bm = malloc(sizeof(*bm), M_DEVBUF, M_NOWAIT|M_ZERO);
|
||||
if (bm == NULL)
|
||||
return ENOMEM;
|
||||
bm->bm_dev = dev;
|
||||
|
|
100
sys/dev/biovar.h
100
sys/dev/biovar.h
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: biovar.h,v 1.5 2007/12/07 11:51:21 xtraeme Exp $ */
|
||||
/* $NetBSD: biovar.h,v 1.6 2008/01/02 23:45:03 xtraeme Exp $ */
|
||||
/* $OpenBSD: biovar.h,v 1.26 2007/03/19 03:02:08 marco Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -33,8 +33,15 @@
|
|||
* cookie.
|
||||
*/
|
||||
|
||||
#ifndef _DEV_BIOVAR_H_
|
||||
#define _DEV_BIOVAR_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
struct bio_common {
|
||||
void *bc_cookie;
|
||||
};
|
||||
|
@ -60,7 +67,8 @@ struct bioc_inq {
|
|||
int bi_nodisk; /* nr of total disks */
|
||||
};
|
||||
|
||||
#define BIOCDISK _IOWR('B', 33, struct bioc_disk)
|
||||
#define BIOCDISK_NOVOL _IOWR('b', 38, struct bioc_disk)
|
||||
#define BIOCDISK _IOWR('B', 33, struct bioc_disk)
|
||||
/* structure that represents a disk in a RAID volume */
|
||||
struct bioc_disk {
|
||||
void *bd_cookie;
|
||||
|
@ -87,6 +95,8 @@ struct bioc_disk {
|
|||
#define BIOC_SDUNUSED_S "Unused"
|
||||
#define BIOC_SDSCRUB 0x06
|
||||
#define BIOC_SDSCRUB_S "Scrubbing"
|
||||
#define BIOC_SDPASSTHRU 0x07
|
||||
#define BIOC_SDPASSTHRU_S "Pass through"
|
||||
#define BIOC_SDINVALID 0xff
|
||||
#define BIOC_SDINVALID_S "Invalid"
|
||||
uint64_t bd_size; /* size of the disk */
|
||||
|
@ -94,8 +104,30 @@ struct bioc_disk {
|
|||
char bd_vendor[32]; /* scsi string */
|
||||
char bd_serial[32]; /* serial number */
|
||||
char bd_procdev[16]; /* processor device */
|
||||
|
||||
bool bd_disknovol; /* disk not associated with volumes */
|
||||
};
|
||||
|
||||
/* COMPATIBILITY */
|
||||
#ifdef _KERNEL
|
||||
#define OBIOCDISK _IOWR('B', 33, struct obioc_disk)
|
||||
/* structure that represents a disk in a RAID volume (compat) */
|
||||
struct obioc_disk {
|
||||
void *bd_cookie;
|
||||
uint16_t bd_channel;
|
||||
uint16_t bd_target;
|
||||
uint16_t bd_lun;
|
||||
uint16_t bd_other_id;
|
||||
int bd_volid;
|
||||
int bd_diskid;
|
||||
int bd_status;
|
||||
uint64_t bd_size;
|
||||
char bd_vendor[32];
|
||||
char bd_serial[32];
|
||||
char bd_procdev[16];
|
||||
};
|
||||
#endif
|
||||
|
||||
#define BIOCVOL _IOWR('B', 34, struct bioc_vol)
|
||||
/* structure that represents a RAID volume */
|
||||
struct bioc_vol {
|
||||
|
@ -120,16 +152,42 @@ struct bioc_vol {
|
|||
#define BIOC_SVREBUILD_S "Rebuild"
|
||||
#define BIOC_SVMIGRATING 0x06
|
||||
#define BIOC_SVMIGRATING_S "Migrating"
|
||||
#define BIOC_SVCHECKING 0x07
|
||||
#define BIOC_SVCHECKING_S "Checking"
|
||||
#define BIOC_SVINVALID 0xff
|
||||
#define BIOC_SVINVALID_S "Invalid"
|
||||
uint64_t bv_size; /* size of the disk */
|
||||
int bv_level; /* raid level */
|
||||
#define BIOC_SVOL_UNUSED 0xaa
|
||||
#define BIOC_SVOL_HOTSPARE 0xbb
|
||||
#define BIOC_SVOL_PASSTHRU 0xcc
|
||||
|
||||
int bv_nodisk; /* nr of drives */
|
||||
|
||||
char bv_dev[16]; /* device */
|
||||
char bv_vendor[32]; /* scsi string */
|
||||
|
||||
uint16_t bv_stripe_size; /* stripe size */
|
||||
};
|
||||
|
||||
/* COMPATIBILITY */
|
||||
#ifdef _KERNEL
|
||||
#define OBIOCVOL _IOWR('B', 34, struct obioc_vol)
|
||||
/* structure that represents a RAID volume */
|
||||
struct obioc_vol {
|
||||
void *bv_cookie;
|
||||
int bv_volid;
|
||||
int16_t bv_percent;
|
||||
uint16_t bv_seconds;
|
||||
int bv_status;
|
||||
uint64_t bv_size;
|
||||
int bv_level;
|
||||
int bv_nodisk;
|
||||
char bv_dev[16];
|
||||
char bv_vendor[32];
|
||||
};
|
||||
#endif
|
||||
|
||||
#define BIOCALARM _IOWR('B', 35, struct bioc_alarm)
|
||||
struct bioc_alarm {
|
||||
void *ba_cookie;
|
||||
|
@ -168,25 +226,31 @@ struct bioc_setstate {
|
|||
#define BIOC_SSOFFLINE 0x01 /* offline disk */
|
||||
#define BIOC_SSHOTSPARE 0x02 /* mark as hotspare */
|
||||
#define BIOC_SSREBUILD 0x03 /* rebuild on this disk */
|
||||
#define BIOC_SSDELHOTSPARE 0x04 /* unmark as hotspare */
|
||||
#define BIOC_SSPASSTHRU 0x05 /* mark as pass-through */
|
||||
#define BIOC_SSDELPASSTHRU 0x06 /* unmark as pass-through */
|
||||
#define BIOC_SSCHECKSTART_VOL 0x07 /* start consistency check in vol# */
|
||||
#define BIOC_SSCHECKSTOP_VOL 0x08 /* stop consistency check in vol# */
|
||||
int bs_volid; /* volume id for rebuild */
|
||||
};
|
||||
|
||||
#define BIOCCREATERAID _IOWR('B', 38, struct bioc_createraid)
|
||||
struct bioc_createraid {
|
||||
#define BIOCVOLOPS _IOWR('B', 39, struct bioc_volops)
|
||||
struct bioc_volops {
|
||||
void *bc_cookie;
|
||||
char *bc_dev_list;
|
||||
uint16_t bc_dev_list_len;
|
||||
uint16_t bc_level;
|
||||
uint64_t bc_size; /* size of the volume set */
|
||||
uint64_t bc_other_id; /* unused for now */
|
||||
uint32_t bc_devmask; /* device mask for the volume set */
|
||||
|
||||
uint16_t bc_channel;
|
||||
uint16_t bc_target;
|
||||
uint16_t bc_lun;
|
||||
uint16_t bc_stripe; /* stripe size */
|
||||
uint16_t bc_level; /* RAID level requested */
|
||||
|
||||
int bc_opcode;
|
||||
#define BIOC_VCREATE_VOLUME 0x00 /* create new volume */
|
||||
#define BIOC_VREMOVE_VOLUME 0x01 /* remove volume */
|
||||
int bc_volid; /* volume id to be created/removed */
|
||||
};
|
||||
|
||||
/* kernel and userspace defines */
|
||||
#define BIOC_INQ 0x0001
|
||||
#define BIOC_DISK 0x0002
|
||||
#define BIOC_VOL 0x0004
|
||||
#define BIOC_ALARM 0x0008
|
||||
#define BIOC_BLINK 0x0010
|
||||
#define BIOC_SETSTATE 0x0020
|
||||
#define BIOC_CREATERAID 0x0040
|
||||
|
||||
/* user space defines */
|
||||
#define BIOC_DEVLIST 0x10000
|
||||
#endif /* ! _DEV_BIOVAR_H_ */
|
||||
|
|
Loading…
Reference in New Issue