Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Jul 2014 03:34:52 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r268280 - head/sys/cam/ctl
Message-ID:  <201407050334.s653Yq7n071085@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sat Jul  5 03:34:52 2014
New Revision: 268280
URL: http://svnweb.freebsd.org/changeset/base/268280

Log:
  Make options KPI more generic to allow it to be used for ports too,
  not only for LUNs.

Modified:
  head/sys/cam/ctl/ctl.c
  head/sys/cam/ctl/ctl.h
  head/sys/cam/ctl/ctl_backend.c
  head/sys/cam/ctl/ctl_backend.h
  head/sys/cam/ctl/ctl_backend_block.c
  head/sys/cam/ctl/ctl_backend_ramdisk.c
  head/sys/cam/ctl/ctl_frontend_iscsi.c

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl.c	Sat Jul  5 03:34:52 2014	(r268280)
@@ -2954,7 +2954,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;
 
@@ -9579,7 +9579,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));
@@ -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));

Modified: head/sys/cam/ctl/ctl.h
==============================================================================
--- head/sys/cam/ctl/ctl.h	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl.h	Sat Jul  5 03:34:52 2014	(r268280)
@@ -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: head/sys/cam/ctl/ctl_backend.c
==============================================================================
--- head/sys/cam/ctl/ctl_backend.c	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl_backend.c	Sat Jul  5 03:34:52 2014	(r268280)
@@ -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: head/sys/cam/ctl/ctl_backend.h
==============================================================================
--- head/sys/cam/ctl/ctl_backend.h	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl_backend.h	Sat Jul  5 03:34:52 2014	(r268280)
@@ -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: head/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- head/sys/cam/ctl/ctl_backend_block.c	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl_backend_block.c	Sat Jul  5 03:34:52 2014	(r268280)
@@ -1857,7 +1857,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);
@@ -1874,7 +1875,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__);
@@ -1919,7 +1920,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);
 
@@ -1937,7 +1938,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;
 
@@ -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_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: head/sys/cam/ctl/ctl_backend_ramdisk.c
==============================================================================
--- head/sys/cam/ctl/ctl_backend_ramdisk.c	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl_backend_ramdisk.c	Sat Jul  5 03:34:52 2014	(r268280)
@@ -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: head/sys/cam/ctl/ctl_frontend_iscsi.c
==============================================================================
--- head/sys/cam/ctl/ctl_frontend_iscsi.c	Sat Jul  5 03:27:31 2014	(r268279)
+++ head/sys/cam/ctl/ctl_frontend_iscsi.c	Sat Jul  5 03:34:52 2014	(r268280)
@@ -2106,7 +2106,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));
@@ -2366,11 +2367,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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407050334.s653Yq7n071085>