Make struct ctl_be_lun first element of struct ctl_be_*_lun.

It allows to remove some extra pointer dereferences and slightly tightens
up the code by unification.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
This commit is contained in:
Alexander Motin 2020-05-28 21:30:29 +00:00
parent 6f05ed08c2
commit 767300e87a
4 changed files with 38 additions and 47 deletions

View File

@ -3083,7 +3083,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
break;
if (lun->backend->lun_info != NULL) {
retval = lun->backend->lun_info(lun->be_lun->be_lun, sb);
retval = lun->backend->lun_info(lun->be_lun, sb);
if (retval != 0)
break;
}
@ -4751,7 +4751,7 @@ ctl_free_lun(struct ctl_lun *lun)
/*
* Tell the backend to free resources, if this LUN has a backend.
*/
lun->be_lun->lun_shutdown(lun->be_lun->be_lun);
lun->be_lun->lun_shutdown(lun->be_lun);
lun->ie_reportcnt = UINT32_MAX;
callout_drain(&lun->ie_callout);
@ -6708,7 +6708,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
data = page_index->page_data;
if (lun->backend->lun_attr != NULL &&
(val = lun->backend->lun_attr(lun->be_lun->be_lun, "blocksavail"))
(val = lun->backend->lun_attr(lun->be_lun, "blocksavail"))
!= UINT64_MAX) {
phdr = (struct scsi_log_param_header *)data;
scsi_ulto2b(0x0001, phdr->param_code);
@ -6721,7 +6721,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
}
if (lun->backend->lun_attr != NULL &&
(val = lun->backend->lun_attr(lun->be_lun->be_lun, "blocksused"))
(val = lun->backend->lun_attr(lun->be_lun, "blocksused"))
!= UINT64_MAX) {
phdr = (struct scsi_log_param_header *)data;
scsi_ulto2b(0x0002, phdr->param_code);
@ -6734,7 +6734,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
}
if (lun->backend->lun_attr != NULL &&
(val = lun->backend->lun_attr(lun->be_lun->be_lun, "poolblocksavail"))
(val = lun->backend->lun_attr(lun->be_lun, "poolblocksavail"))
!= UINT64_MAX) {
phdr = (struct scsi_log_param_header *)data;
scsi_ulto2b(0x00f1, phdr->param_code);
@ -6747,7 +6747,7 @@ ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
}
if (lun->backend->lun_attr != NULL &&
(val = lun->backend->lun_attr(lun->be_lun->be_lun, "poolblocksused"))
(val = lun->backend->lun_attr(lun->be_lun, "poolblocksused"))
!= UINT64_MAX) {
phdr = (struct scsi_log_param_header *)data;
scsi_ulto2b(0x00f2, phdr->param_code);
@ -13386,8 +13386,7 @@ ctl_thresh_thread(void *arg)
continue;
}
mtx_unlock(&softc->ctl_lock); // XXX
val = lun->backend->lun_attr(
lun->be_lun->be_lun, attr);
val = lun->backend->lun_attr(lun->be_lun, attr);
mtx_lock(&softc->ctl_lock);
if (val == UINT64_MAX)
continue;

View File

@ -80,7 +80,8 @@ typedef enum {
MODULE_DEPEND(name, cam, 1, 1, 1)
typedef void (*be_callback_t)(void *be_lun);
struct ctl_be_lun;
typedef void (*be_callback_t)(struct ctl_be_lun *be_lun);
/*
* The lun_type field is the SCSI device type of this particular LUN. In
@ -147,7 +148,6 @@ struct ctl_be_lun {
uint8_t lun_type; /* passed to CTL */
ctl_backend_lun_flags flags; /* passed to CTL */
ctl_lun_serseq serseq; /* passed to CTL */
void *be_lun; /* passed to CTL */
uint64_t maxlba; /* passed to CTL */
uint32_t blocksize; /* passed to CTL */
uint16_t pblockexp; /* passed to CTL */
@ -178,8 +178,8 @@ typedef int (*be_func_t)(union ctl_io *io);
typedef void (*be_vfunc_t)(union ctl_io *io);
typedef int (*be_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
struct thread *td);
typedef int (*be_luninfo_t)(void *be_lun, struct sbuf *sb);
typedef uint64_t (*be_lunattr_t)(void *be_lun, const char *attrname);
typedef int (*be_luninfo_t)(struct ctl_be_lun *be_lun, struct sbuf *sb);
typedef uint64_t (*be_lunattr_t)(struct ctl_be_lun *be_lun, const char *attrname);
struct ctl_backend_driver {
char name[CTL_BE_NAME_LEN]; /* passed to CTL */

View File

@ -152,6 +152,7 @@ typedef uint64_t (*cbb_getattr_t)(struct ctl_be_block_lun *be_lun,
* and a backend block LUN, and between a backend block LUN and a CTL LUN.
*/
struct ctl_be_block_lun {
struct ctl_be_lun cbe_lun; /* Must be first element. */
struct ctl_lun_create_params params;
char *dev_path;
ctl_be_block_type dev_type;
@ -168,7 +169,6 @@ struct ctl_be_block_lun {
struct devstat *disk_stats;
ctl_be_block_lun_flags flags;
SLIST_ENTRY(ctl_be_block_lun) links;
struct ctl_be_lun cbe_lun;
struct taskqueue *io_taskqueue;
struct task io_task;
int num_threads;
@ -272,11 +272,11 @@ static int ctl_be_block_rm(struct ctl_be_block_softc *softc,
struct ctl_lun_req *req);
static int ctl_be_block_modify(struct ctl_be_block_softc *softc,
struct ctl_lun_req *req);
static void ctl_be_block_lun_shutdown(void *be_lun);
static void ctl_be_block_lun_shutdown(struct ctl_be_lun *cbe_lun);
static int ctl_be_block_config_write(union ctl_io *io);
static int ctl_be_block_config_read(union ctl_io *io);
static int ctl_be_block_lun_info(void *be_lun, struct sbuf *sb);
static uint64_t ctl_be_block_lun_attr(void *be_lun, const char *attrname);
static int ctl_be_block_lun_info(struct ctl_be_lun *cbe_lun, struct sbuf *sb);
static uint64_t ctl_be_block_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname);
static int ctl_be_block_init(void);
static int ctl_be_block_shutdown(void);
@ -1724,12 +1724,10 @@ static int
ctl_be_block_submit(union ctl_io *io)
{
struct ctl_be_block_lun *be_lun;
struct ctl_be_lun *cbe_lun;
DPRINTF("entered\n");
cbe_lun = CTL_BACKEND_LUN(io);
be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io);
/*
* Make sure we only get SCSI I/O.
@ -2210,7 +2208,6 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK);
cbe_lun = &be_lun->cbe_lun;
cbe_lun->be_lun = be_lun;
be_lun->params = req->reqdata.create;
be_lun->softc = softc;
STAILQ_INIT(&be_lun->input_queue);
@ -2574,9 +2571,9 @@ ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
}
static void
ctl_be_block_lun_shutdown(void *lun)
ctl_be_block_lun_shutdown(struct ctl_be_lun *cbe_lun)
{
struct ctl_be_block_lun *be_lun = lun;
struct ctl_be_block_lun *be_lun = (struct ctl_be_block_lun *)cbe_lun;
struct ctl_be_block_softc *softc = be_lun->softc;
taskqueue_drain_all(be_lun->io_taskqueue);
@ -2607,7 +2604,7 @@ ctl_be_block_config_write(union ctl_io *io)
DPRINTF("entered\n");
cbe_lun = CTL_BACKEND_LUN(io);
be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
be_lun = (struct ctl_be_block_lun *)cbe_lun;
retval = 0;
switch (io->scsiio.cdb[0]) {
@ -2686,13 +2683,11 @@ static int
ctl_be_block_config_read(union ctl_io *io)
{
struct ctl_be_block_lun *be_lun;
struct ctl_be_lun *cbe_lun;
int retval = 0;
DPRINTF("entered\n");
cbe_lun = CTL_BACKEND_LUN(io);
be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
be_lun = (struct ctl_be_block_lun *)CTL_BACKEND_LUN(io);
switch (io->scsiio.cdb[0]) {
case SERVICE_ACTION_IN:
@ -2726,13 +2721,11 @@ ctl_be_block_config_read(union ctl_io *io)
}
static int
ctl_be_block_lun_info(void *be_lun, struct sbuf *sb)
ctl_be_block_lun_info(struct ctl_be_lun *cbe_lun, struct sbuf *sb)
{
struct ctl_be_block_lun *lun;
struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)cbe_lun;
int retval;
lun = (struct ctl_be_block_lun *)be_lun;
retval = sbuf_printf(sb, "\t<num_threads>");
if (retval != 0)
goto bailout;
@ -2746,9 +2739,9 @@ ctl_be_block_lun_info(void *be_lun, struct sbuf *sb)
}
static uint64_t
ctl_be_block_lun_attr(void *be_lun, const char *attrname)
ctl_be_block_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname)
{
struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)be_lun;
struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)cbe_lun;
if (lun->getattr == NULL)
return (UINT64_MAX);

View File

@ -106,6 +106,7 @@ typedef enum {
} ctl_be_ramdisk_lun_flags;
struct ctl_be_ramdisk_lun {
struct ctl_be_lun cbe_lun; /* Must be first element. */
struct ctl_lun_create_params params;
int indir;
uint8_t **pages;
@ -120,7 +121,6 @@ struct ctl_be_ramdisk_lun {
struct ctl_be_ramdisk_softc *softc;
ctl_be_ramdisk_lun_flags flags;
SLIST_ENTRY(ctl_be_ramdisk_lun) links;
struct ctl_be_lun cbe_lun;
struct taskqueue *io_taskqueue;
struct task io_task;
STAILQ_HEAD(, ctl_io_hdr) cont_queue;
@ -146,7 +146,7 @@ static int ctl_backend_ramdisk_submit(union ctl_io *io);
static void ctl_backend_ramdisk_worker(void *context, int pending);
static int ctl_backend_ramdisk_config_read(union ctl_io *io);
static int ctl_backend_ramdisk_config_write(union ctl_io *io);
static uint64_t ctl_backend_ramdisk_lun_attr(void *be_lun, const char *attrname);
static uint64_t ctl_backend_ramdisk_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname);
static int ctl_backend_ramdisk_ioctl(struct cdev *dev, u_long cmd,
caddr_t addr, int flag, struct thread *td);
static int ctl_backend_ramdisk_rm(struct ctl_be_ramdisk_softc *softc,
@ -155,7 +155,7 @@ static int ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc *softc,
struct ctl_lun_req *req);
static int ctl_backend_ramdisk_modify(struct ctl_be_ramdisk_softc *softc,
struct ctl_lun_req *req);
static void ctl_backend_ramdisk_lun_shutdown(void *be_lun);
static void ctl_backend_ramdisk_lun_shutdown(struct ctl_be_lun *cbe_lun);
static struct ctl_backend_driver ctl_be_ramdisk_driver =
{
@ -367,7 +367,7 @@ static int
ctl_backend_ramdisk_cmp(union ctl_io *io)
{
struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
uint8_t *page;
uint8_t info[8];
uint64_t lba;
@ -404,8 +404,8 @@ ctl_backend_ramdisk_cmp(union ctl_io *io)
static int
ctl_backend_ramdisk_move_done(union ctl_io *io)
{
struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
struct ctl_be_ramdisk_lun *be_lun =
(struct ctl_be_ramdisk_lun *)CTL_BACKEND_LUN(io);
#ifdef CTL_TIME_IO
struct bintime cur_bt;
#endif
@ -481,7 +481,7 @@ static void
ctl_backend_ramdisk_rw(union ctl_io *io)
{
struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
struct ctl_sg_entry *sg_entries;
uint8_t *page;
uint64_t lba;
@ -593,7 +593,7 @@ static int
ctl_backend_ramdisk_gls(union ctl_io *io)
{
struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
struct scsi_get_lba_status_data *data;
uint8_t *page;
u_int lbaoff;
@ -647,7 +647,7 @@ static void
ctl_backend_ramdisk_delete(struct ctl_be_lun *cbe_lun, off_t lba, off_t len,
int anchor)
{
struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
uint8_t *page;
uint64_t p, lp;
u_int lbaoff;
@ -689,7 +689,7 @@ static void
ctl_backend_ramdisk_ws(union ctl_io *io)
{
struct ctl_be_lun *cbe_lun = CTL_BACKEND_LUN(io);
struct ctl_be_ramdisk_lun *be_lun = cbe_lun->be_lun;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
struct ctl_lba_len_flags *lbalen = ARGS(io);
uint8_t *page;
uint64_t lba;
@ -823,9 +823,9 @@ ctl_backend_ramdisk_config_write(union ctl_io *io)
}
static uint64_t
ctl_backend_ramdisk_lun_attr(void *arg, const char *attrname)
ctl_backend_ramdisk_lun_attr(struct ctl_be_lun *cbe_lun, const char *attrname)
{
struct ctl_be_ramdisk_lun *be_lun = arg;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
uint64_t val;
val = UINT64_MAX;
@ -971,7 +971,6 @@ ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc *softc,
be_lun = malloc(sizeof(*be_lun), M_RAMDISK, M_ZERO | M_WAITOK);
cbe_lun = &be_lun->cbe_lun;
cbe_lun->be_lun = be_lun;
cbe_lun->options = nvlist_clone(req->args_nvl);
be_lun->params = req->reqdata.create;
be_lun->softc = softc;
@ -1246,9 +1245,9 @@ ctl_backend_ramdisk_modify(struct ctl_be_ramdisk_softc *softc,
}
static void
ctl_backend_ramdisk_lun_shutdown(void *lun)
ctl_backend_ramdisk_lun_shutdown(struct ctl_be_lun *cbe_lun)
{
struct ctl_be_ramdisk_lun *be_lun = lun;
struct ctl_be_ramdisk_lun *be_lun = (struct ctl_be_ramdisk_lun *)cbe_lun;
struct ctl_be_ramdisk_softc *softc = be_lun->softc;
taskqueue_drain_all(be_lun->io_taskqueue);