From 43fb3a65e3aebe25328eca1cd5bd6350acab1d34 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Sat, 5 Jul 2014 03:34:52 +0000 Subject: [PATCH] Make options KPI more generic to allow it to be used for ports too, not only for LUNs. --- sys/cam/ctl/ctl.c | 13 ++++++++----- sys/cam/ctl/ctl.h | 16 ++++++++++++++++ sys/cam/ctl/ctl_backend.c | 32 +++++++++++++++---------------- sys/cam/ctl/ctl_backend.h | 16 +--------------- sys/cam/ctl/ctl_backend_block.c | 13 +++++++------ sys/cam/ctl/ctl_backend_ramdisk.c | 9 +++++---- sys/cam/ctl/ctl_frontend_iscsi.c | 9 +++++---- 7 files changed, 58 insertions(+), 50 deletions(-) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 85e43e26d08..d6a4ab26159 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -2954,7 +2954,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct sbuf *sb; struct ctl_lun *lun; struct ctl_lun_list *list; - struct ctl_be_lun_option *opt; + struct ctl_option *opt; list = (struct ctl_lun_list *)addr; @@ -9579,7 +9579,8 @@ ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len) */ desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_T10; desc->length = sizeof(*t10id) + devid_len; - if (lun == NULL || (val = ctl_get_opt(lun->be_lun, "vendor")) == NULL) { + if (lun == NULL || (val = ctl_get_opt(&lun->be_lun->options, + "vendor")) == NULL) { strncpy((char *)t10id->vendor, CTL_VENDOR, sizeof(t10id->vendor)); } else { memset(t10id->vendor, ' ', sizeof(t10id->vendor)); @@ -9963,7 +9964,8 @@ ctl_inquiry_std(struct ctl_scsiio *ctsio) * We have 8 bytes for the vendor name, and 16 bytes for the device * name and 4 bytes for the revision. */ - if (lun == NULL || (val = ctl_get_opt(lun->be_lun, "vendor")) == NULL) { + if (lun == NULL || (val = ctl_get_opt(&lun->be_lun->options, + "vendor")) == NULL) { strcpy(inq_ptr->vendor, CTL_VENDOR); } else { memset(inq_ptr->vendor, ' ', sizeof(inq_ptr->vendor)); @@ -9972,7 +9974,7 @@ ctl_inquiry_std(struct ctl_scsiio *ctsio) } if (lun == NULL) { strcpy(inq_ptr->product, CTL_DIRECT_PRODUCT); - } else if ((val = ctl_get_opt(lun->be_lun, "product")) == NULL) { + } else if ((val = ctl_get_opt(&lun->be_lun->options, "product")) == NULL) { switch (lun->be_lun->lun_type) { case T_DIRECT: strcpy(inq_ptr->product, CTL_DIRECT_PRODUCT); @@ -9994,7 +9996,8 @@ ctl_inquiry_std(struct ctl_scsiio *ctsio) * XXX make this a macro somewhere so it automatically gets * incremented when we make changes. */ - if (lun == NULL || (val = ctl_get_opt(lun->be_lun, "revision")) == NULL) { + if (lun == NULL || (val = ctl_get_opt(&lun->be_lun->options, + "revision")) == NULL) { strncpy(inq_ptr->revision, "0001", sizeof(inq_ptr->revision)); } else { memset(inq_ptr->revision, ' ', sizeof(inq_ptr->revision)); diff --git a/sys/cam/ctl/ctl.h b/sys/cam/ctl/ctl.h index 99fadc85a47..71c37ca4d1a 100644 --- a/sys/cam/ctl/ctl.h +++ b/sys/cam/ctl/ctl.h @@ -186,6 +186,22 @@ void ctl_config_write_done(union ctl_io *io); void ctl_portDB_changed(int portnum); void ctl_init_isc_msg(void); +/* + * KPI to manipulate LUN/port options + */ + +struct ctl_option { + STAILQ_ENTRY(ctl_option) links; + char *name; + char *value; +}; +typedef STAILQ_HEAD(ctl_options, ctl_option) ctl_options_t; + +struct ctl_be_arg; +void ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args); +void ctl_free_opts(ctl_options_t *opts); +char * ctl_get_opt(ctl_options_t *opts, const char *name); + #endif /* _KERNEL */ #endif /* _CTL_H_ */ diff --git a/sys/cam/ctl/ctl_backend.c b/sys/cam/ctl/ctl_backend.c index 16e43eb660b..9178c9db00c 100644 --- a/sys/cam/ctl/ctl_backend.c +++ b/sys/cam/ctl/ctl_backend.c @@ -174,29 +174,29 @@ ctl_backend_find(char *backend_name) } void -ctl_init_opts(struct ctl_be_lun *be_lun, struct ctl_lun_req *req) +ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args) { - struct ctl_be_lun_option *opt; + struct ctl_option *opt; int i; - STAILQ_INIT(&be_lun->options); - for (i = 0; i < req->num_be_args; i++) { + STAILQ_INIT(opts); + for (i = 0; i < num_args; i++) { opt = malloc(sizeof(*opt), M_CTL, M_WAITOK); - opt->name = malloc(strlen(req->kern_be_args[i].kname) + 1, M_CTL, M_WAITOK); - strcpy(opt->name, req->kern_be_args[i].kname); - opt->value = malloc(strlen(req->kern_be_args[i].kvalue) + 1, M_CTL, M_WAITOK); - strcpy(opt->value, req->kern_be_args[i].kvalue); - STAILQ_INSERT_TAIL(&be_lun->options, opt, links); + opt->name = malloc(strlen(args[i].kname) + 1, M_CTL, M_WAITOK); + strcpy(opt->name, args[i].kname); + opt->value = malloc(strlen(args[i].kvalue) + 1, M_CTL, M_WAITOK); + strcpy(opt->value, args[i].kvalue); + STAILQ_INSERT_TAIL(opts, opt, links); } } void -ctl_free_opts(struct ctl_be_lun *be_lun) +ctl_free_opts(ctl_options_t *opts) { - struct ctl_be_lun_option *opt; + struct ctl_option *opt; - while ((opt = STAILQ_FIRST(&be_lun->options)) != NULL) { - STAILQ_REMOVE_HEAD(&be_lun->options, links); + while ((opt = STAILQ_FIRST(opts)) != NULL) { + STAILQ_REMOVE_HEAD(opts, links); free(opt->name, M_CTL); free(opt->value, M_CTL); free(opt, M_CTL); @@ -204,11 +204,11 @@ ctl_free_opts(struct ctl_be_lun *be_lun) } char * -ctl_get_opt(struct ctl_be_lun *be_lun, const char *name) +ctl_get_opt(ctl_options_t *opts, const char *name) { - struct ctl_be_lun_option *opt; + struct ctl_option *opt; - STAILQ_FOREACH(opt, &be_lun->options, links) { + STAILQ_FOREACH(opt, opts, links) { if (strcmp(opt->name, name) == 0) { return (opt->value); } diff --git a/sys/cam/ctl/ctl_backend.h b/sys/cam/ctl/ctl_backend.h index 640a7f990e2..c2066c52746 100644 --- a/sys/cam/ctl/ctl_backend.h +++ b/sys/cam/ctl/ctl_backend.h @@ -180,12 +180,6 @@ typedef void (*be_lun_config_t)(void *be_lun, * The links field is for CTL internal use only, and should not be used by * the backend. */ -struct ctl_be_lun_option { - STAILQ_ENTRY(ctl_be_lun_option) links; - char *name; - char *value; -}; - struct ctl_be_lun { uint8_t lun_type; /* passed to CTL */ ctl_backend_lun_flags flags; /* passed to CTL */ @@ -202,7 +196,7 @@ struct ctl_be_lun { be_lun_config_t lun_config_status; /* passed to CTL */ struct ctl_backend_driver *be; /* passed to CTL */ void *ctl_lun; /* used by CTL */ - STAILQ_HEAD(, ctl_be_lun_option) options; /* passed to CTL */ + ctl_options_t options; /* passed to CTL */ STAILQ_ENTRY(ctl_be_lun) links; /* used by CTL */ }; @@ -301,14 +295,6 @@ int ctl_lun_online(struct ctl_be_lun *be_lun); */ void ctl_lun_capacity_changed(struct ctl_be_lun *be_lun); -/* - * KPI to manipulate LUN options - */ -struct ctl_lun_req; -void ctl_init_opts(struct ctl_be_lun *be_lun, struct ctl_lun_req *req); -void ctl_free_opts(struct ctl_be_lun *be_lun); -char * ctl_get_opt(struct ctl_be_lun *be_lun, const char *name); - #endif /* _KERNEL */ #endif /* _CTL_BACKEND_H_ */ diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index c7ec8999b47..477a5348ba0 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -1857,7 +1857,8 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) sprintf(be_lun->lunname, "cblk%d", softc->num_luns); mtx_init(&be_lun->io_lock, "cblk io lock", NULL, MTX_DEF); mtx_init(&be_lun->queue_lock, "cblk queue lock", NULL, MTX_DEF); - ctl_init_opts(&be_lun->ctl_be_lun, req); + ctl_init_opts(&be_lun->ctl_be_lun.options, + req->num_be_args, req->kern_be_args); be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG, NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); @@ -1874,7 +1875,7 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) be_lun->ctl_be_lun.lun_type = T_DIRECT; if (be_lun->ctl_be_lun.lun_type == T_DIRECT) { - value = ctl_get_opt(&be_lun->ctl_be_lun, "file"); + value = ctl_get_opt(&be_lun->ctl_be_lun.options, "file"); if (value == NULL) { snprintf(req->error_str, sizeof(req->error_str), "%s: no file argument specified", __func__); @@ -1919,7 +1920,7 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) * XXX This searching loop might be refactored to be combined with * the loop above, */ - value = ctl_get_opt(&be_lun->ctl_be_lun, "num_threads"); + value = ctl_get_opt(&be_lun->ctl_be_lun.options, "num_threads"); if (value != NULL) { tmp_num_threads = strtol(value, NULL, 0); @@ -1937,7 +1938,7 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) num_threads = tmp_num_threads; } unmap = 0; - value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap"); + value = ctl_get_opt(&be_lun->ctl_be_lun.options, "unmap"); if (value != NULL && strcmp(value, "on") == 0) unmap = 1; @@ -2102,7 +2103,7 @@ bailout_error: free(be_lun->dev_path, M_CTLBLK); if (be_lun->lun_zone != NULL) uma_zdestroy(be_lun->lun_zone); - ctl_free_opts(&be_lun->ctl_be_lun); + ctl_free_opts(&be_lun->ctl_be_lun.options); mtx_destroy(&be_lun->queue_lock); mtx_destroy(&be_lun->io_lock); free(be_lun, M_CTLBLK); @@ -2190,7 +2191,7 @@ ctl_be_block_rm(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) uma_zdestroy(be_lun->lun_zone); - ctl_free_opts(&be_lun->ctl_be_lun); + ctl_free_opts(&be_lun->ctl_be_lun.options); free(be_lun->dev_path, M_CTLBLK); mtx_destroy(&be_lun->queue_lock); mtx_destroy(&be_lun->io_lock); diff --git a/sys/cam/ctl/ctl_backend_ramdisk.c b/sys/cam/ctl/ctl_backend_ramdisk.c index df014799c01..e1545e639e4 100644 --- a/sys/cam/ctl/ctl_backend_ramdisk.c +++ b/sys/cam/ctl/ctl_backend_ramdisk.c @@ -505,7 +505,7 @@ ctl_backend_ramdisk_rm(struct ctl_be_ramdisk_softc *softc, if (retval == 0) { taskqueue_drain(be_lun->io_taskqueue, &be_lun->io_task); taskqueue_free(be_lun->io_taskqueue); - ctl_free_opts(&be_lun->ctl_be_lun); + ctl_free_opts(&be_lun->ctl_be_lun.options); mtx_destroy(&be_lun->queue_lock); free(be_lun, M_RAMDISK); } @@ -548,7 +548,8 @@ ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc *softc, goto bailout_error; } sprintf(be_lun->lunname, "cram%d", softc->num_luns); - ctl_init_opts(&be_lun->ctl_be_lun, req); + ctl_init_opts(&be_lun->ctl_be_lun.options, + req->num_be_args, req->kern_be_args); if (params->flags & CTL_LUN_FLAG_DEV_TYPE) be_lun->ctl_be_lun.lun_type = params->device_type; @@ -586,7 +587,7 @@ ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc *softc, be_lun->softc = softc; unmap = 0; - value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap"); + value = ctl_get_opt(&be_lun->ctl_be_lun.options, "unmap"); if (value != NULL && strcmp(value, "on") == 0) unmap = 1; @@ -721,7 +722,7 @@ bailout_error: if (be_lun->io_taskqueue != NULL) { taskqueue_free(be_lun->io_taskqueue); } - ctl_free_opts(&be_lun->ctl_be_lun); + ctl_free_opts(&be_lun->ctl_be_lun.options); mtx_destroy(&be_lun->queue_lock); free(be_lun, M_RAMDISK); } diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c index 2e610ba1445..b55075526ef 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.c +++ b/sys/cam/ctl/ctl_frontend_iscsi.c @@ -2106,7 +2106,8 @@ cfiscsi_devid(struct ctl_scsiio *ctsio, int alloc_len) desc->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_ASCII; desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_T10; desc->length = sizeof(*t10id) + devid_len; - if (lun == NULL || (val = ctl_get_opt(lun->be_lun, "vendor")) == NULL) { + if (lun == NULL || (val = ctl_get_opt(&lun->be_lun->options, + "vendor")) == NULL) { strncpy((char *)t10id->vendor, CTL_VENDOR, sizeof(t10id->vendor)); } else { memset(t10id->vendor, ' ', sizeof(t10id->vendor)); @@ -2366,11 +2367,11 @@ cfiscsi_lun_enable(void *arg, struct ctl_id target_id, int lun_id) softc = (struct cfiscsi_softc *)arg; - target = ctl_get_opt(control_softc->ctl_luns[lun_id]->be_lun, + target = ctl_get_opt(&control_softc->ctl_luns[lun_id]->be_lun->options, "cfiscsi_target"); - target_alias = ctl_get_opt(control_softc->ctl_luns[lun_id]->be_lun, + target_alias = ctl_get_opt(&control_softc->ctl_luns[lun_id]->be_lun->options, "cfiscsi_target_alias"); - lun = ctl_get_opt(control_softc->ctl_luns[lun_id]->be_lun, + lun = ctl_get_opt(&control_softc->ctl_luns[lun_id]->be_lun->options, "cfiscsi_lun"); if (target == NULL && lun == NULL)