svn commit: r268678 - stable/10/sys/cam/ctl
Alexander Motin
mav at FreeBSD.org
Tue Jul 15 16:58:40 UTC 2014
Author: mav
Date: Tue Jul 15 16:58:38 2014
New Revision: 268678
URL: http://svnweb.freebsd.org/changeset/base/268678
Log:
MFC r268280:
Make options KPI more generic to allow it to be used for ports too,
not only for LUNs.
Modified:
stable/10/sys/cam/ctl/ctl.c
stable/10/sys/cam/ctl/ctl.h
stable/10/sys/cam/ctl/ctl_backend.c
stable/10/sys/cam/ctl/ctl_backend.h
stable/10/sys/cam/ctl/ctl_backend_block.c
stable/10/sys/cam/ctl/ctl_backend_ramdisk.c
stable/10/sys/cam/ctl/ctl_frontend_iscsi.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sys/cam/ctl/ctl.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl.c Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl.c Tue Jul 15 16:58:38 2014 (r268678)
@@ -2956,7 +2956,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd,
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;
@@ -9582,7 +9582,8 @@ ctl_inquiry_evpd_devid(struct ctl_scsiio
*/
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));
@@ -9966,7 +9967,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));
@@ -9975,7 +9977,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);
@@ -9997,7 +9999,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));
Modified: stable/10/sys/cam/ctl/ctl.h
==============================================================================
--- stable/10/sys/cam/ctl/ctl.h Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl.h Tue Jul 15 16:58:38 2014 (r268678)
@@ -186,6 +186,22 @@ void ctl_config_write_done(union ctl_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_ */
Modified: stable/10/sys/cam/ctl/ctl_backend.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_backend.c Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl_backend.c Tue Jul 15 16:58:38 2014 (r268678)
@@ -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);
}
Modified: stable/10/sys/cam/ctl/ctl_backend.h
==============================================================================
--- stable/10/sys/cam/ctl/ctl_backend.h Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl_backend.h Tue Jul 15 16:58:38 2014 (r268678)
@@ -180,12 +180,6 @@ typedef void (*be_lun_config_t)(void *be
* 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
*/
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_ */
Modified: stable/10/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_backend_block.c Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl_backend_block.c Tue Jul 15 16:58:38 2014 (r268678)
@@ -1860,7 +1860,8 @@ ctl_be_block_create(struct ctl_be_block_
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);
@@ -1877,7 +1878,7 @@ ctl_be_block_create(struct ctl_be_block_
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__);
@@ -1922,7 +1923,7 @@ ctl_be_block_create(struct ctl_be_block_
* 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);
@@ -1940,7 +1941,7 @@ ctl_be_block_create(struct ctl_be_block_
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;
@@ -2105,7 +2106,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);
@@ -2193,7 +2194,7 @@ ctl_be_block_rm(struct ctl_be_block_soft
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);
Modified: stable/10/sys/cam/ctl/ctl_backend_ramdisk.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_backend_ramdisk.c Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl_backend_ramdisk.c Tue Jul 15 16:58:38 2014 (r268678)
@@ -505,7 +505,7 @@ ctl_backend_ramdisk_rm(struct ctl_be_ram
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
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
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);
}
Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Tue Jul 15 16:57:30 2014 (r268677)
+++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Tue Jul 15 16:58:38 2014 (r268678)
@@ -2110,7 +2110,8 @@ cfiscsi_devid(struct ctl_scsiio *ctsio,
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));
@@ -2370,11 +2371,11 @@ cfiscsi_lun_enable(void *arg, struct ctl
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)
More information about the svn-src-stable
mailing list