From owner-svn-src-all@FreeBSD.ORG Wed Jul 2 10:35:07 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 91FA8C11; Wed, 2 Jul 2014 10:35:07 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7E0DF2544; Wed, 2 Jul 2014 10:35:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s62AZ74Q083916; Wed, 2 Jul 2014 10:35:07 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s62AZ6h7083909; Wed, 2 Jul 2014 10:35:06 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201407021035.s62AZ6h7083909@svn.freebsd.org> From: Alexander Motin Date: Wed, 2 Jul 2014 10:35:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r268143 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jul 2014 10:35:07 -0000 Author: mav Date: Wed Jul 2 10:35:06 2014 New Revision: 268143 URL: http://svnweb.freebsd.org/changeset/base/268143 Log: MFC r267481, r267952: Implement small KPI to access LUN options instead doing it by hands. Modified: 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_backend.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_backend.c Wed Jul 2 10:32:44 2014 (r268142) +++ stable/10/sys/cam/ctl/ctl_backend.c Wed Jul 2 10:35:06 2014 (r268143) @@ -173,6 +173,45 @@ ctl_backend_find(char *backend_name) return (NULL); } -/* - * vim: ts=8 - */ +void +ctl_init_opts(struct ctl_be_lun *be_lun, struct ctl_lun_req *req) +{ + struct ctl_be_lun_option *opt; + int i; + + STAILQ_INIT(&be_lun->options); + for (i = 0; i < req->num_be_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); + } +} + +void +ctl_free_opts(struct ctl_be_lun *be_lun) +{ + struct ctl_be_lun_option *opt; + + while ((opt = STAILQ_FIRST(&be_lun->options)) != NULL) { + STAILQ_REMOVE_HEAD(&be_lun->options, links); + free(opt->name, M_CTL); + free(opt->value, M_CTL); + free(opt, M_CTL); + } +} + +char * +ctl_get_opt(struct ctl_be_lun *be_lun, const char *name) +{ + struct ctl_be_lun_option *opt; + + STAILQ_FOREACH(opt, &be_lun->options, links) { + if (strcmp(opt->name, name) == 0) { + return (opt->value); + } + } + return (NULL); +} Modified: stable/10/sys/cam/ctl/ctl_backend.h ============================================================================== --- stable/10/sys/cam/ctl/ctl_backend.h Wed Jul 2 10:32:44 2014 (r268142) +++ stable/10/sys/cam/ctl/ctl_backend.h Wed Jul 2 10:35:06 2014 (r268143) @@ -301,6 +301,14 @@ 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 Wed Jul 2 10:32:44 2014 (r268142) +++ stable/10/sys/cam/ctl/ctl_backend_block.c Wed Jul 2 10:35:06 2014 (r268143) @@ -1824,9 +1824,12 @@ ctl_be_block_create(struct ctl_be_block_ struct ctl_be_block_lun *be_lun; struct ctl_lun_create_params *params; struct ctl_be_arg *file_arg; + char num_thread_str[16]; char tmpstr[32]; + char *value; int retval, num_threads, unmap; int i; + int tmp_num_threads; params = &req->reqdata.create; retval = 0; @@ -1841,9 +1844,9 @@ ctl_be_block_create(struct ctl_be_block_ STAILQ_INIT(&be_lun->input_queue); STAILQ_INIT(&be_lun->config_write_queue); STAILQ_INIT(&be_lun->datamove_queue); - STAILQ_INIT(&be_lun->ctl_be_lun.options); sprintf(be_lun->lunname, "cblk%d", softc->num_luns); mtx_init(&be_lun->lock, be_lun->lunname, NULL, MTX_DEF); + ctl_init_opts(&be_lun->ctl_be_lun, req); be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG, NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); @@ -1916,50 +1919,27 @@ ctl_be_block_create(struct ctl_be_block_ * XXX This searching loop might be refactored to be combined with * the loop above, */ - unmap = 0; - for (i = 0; i < req->num_be_args; i++) { - if (strcmp(req->kern_be_args[i].kname, "num_threads") == 0) { - struct ctl_be_arg *thread_arg; - char num_thread_str[16]; - int tmp_num_threads; - - - thread_arg = &req->kern_be_args[i]; - - strlcpy(num_thread_str, (char *)thread_arg->kvalue, - min(thread_arg->vallen, - sizeof(num_thread_str))); - - tmp_num_threads = strtol(num_thread_str, NULL, 0); - - /* - * We don't let the user specify less than one - * thread, but hope he's clueful enough not to - * specify 1000 threads. - */ - if (tmp_num_threads < 1) { - snprintf(req->error_str, sizeof(req->error_str), - "%s: invalid number of threads %s", - __func__, num_thread_str); - goto bailout_error; - } + value = ctl_get_opt(&be_lun->ctl_be_lun, "num_threads"); + if (value != NULL) { + tmp_num_threads = strtol(value, NULL, 0); - num_threads = tmp_num_threads; - } else if (strcmp(req->kern_be_args[i].kname, "unmap") == 0 && - strcmp(req->kern_be_args[i].kvalue, "on") == 0) { - unmap = 1; - } else if (strcmp(req->kern_be_args[i].kname, "file") != 0 && - strcmp(req->kern_be_args[i].kname, "dev") != 0) { - struct ctl_be_lun_option *opt; - - opt = malloc(sizeof(*opt), M_CTLBLK, M_WAITOK); - opt->name = malloc(strlen(req->kern_be_args[i].kname) + 1, M_CTLBLK, M_WAITOK); - strcpy(opt->name, req->kern_be_args[i].kname); - opt->value = malloc(strlen(req->kern_be_args[i].kvalue) + 1, M_CTLBLK, M_WAITOK); - strcpy(opt->value, req->kern_be_args[i].kvalue); - STAILQ_INSERT_TAIL(&be_lun->ctl_be_lun.options, opt, links); + /* + * We don't let the user specify less than one + * thread, but hope he's clueful enough not to + * specify 1000 threads. + */ + if (tmp_num_threads < 1) { + snprintf(req->error_str, sizeof(req->error_str), + "%s: invalid number of threads %s", + __func__, num_thread_str); + goto bailout_error; } + num_threads = tmp_num_threads; } + unmap = 0; + value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap"); + if (value != NULL && strcmp(value, "on") == 0) + unmap = 1; be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED; be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY; @@ -2122,6 +2102,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); mtx_destroy(&be_lun->lock); free(be_lun, M_CTLBLK); @@ -2208,6 +2189,7 @@ ctl_be_block_rm(struct ctl_be_block_soft uma_zdestroy(be_lun->lun_zone); + ctl_free_opts(&be_lun->ctl_be_lun); free(be_lun->dev_path, M_CTLBLK); free(be_lun, M_CTLBLK); Modified: stable/10/sys/cam/ctl/ctl_backend_ramdisk.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_backend_ramdisk.c Wed Jul 2 10:32:44 2014 (r268142) +++ stable/10/sys/cam/ctl/ctl_backend_ramdisk.c Wed Jul 2 10:35:06 2014 (r268143) @@ -502,6 +502,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); mtx_destroy(&be_lun->lock); free(be_lun, M_RAMDISK); } @@ -523,8 +524,9 @@ ctl_backend_ramdisk_create(struct ctl_be struct ctl_be_ramdisk_lun *be_lun; struct ctl_lun_create_params *params; uint32_t blocksize; + char *value; char tmpstr[32]; - int i, retval, unmap; + int retval, unmap; retval = 0; params = &req->reqdata.create; @@ -543,7 +545,7 @@ ctl_backend_ramdisk_create(struct ctl_be goto bailout_error; } sprintf(be_lun->lunname, "cram%d", softc->num_luns); - STAILQ_INIT(&be_lun->ctl_be_lun.options); + ctl_init_opts(&be_lun->ctl_be_lun, req); if (params->flags & CTL_LUN_FLAG_DEV_TYPE) be_lun->ctl_be_lun.lun_type = params->device_type; @@ -581,21 +583,9 @@ ctl_backend_ramdisk_create(struct ctl_be be_lun->softc = softc; unmap = 0; - for (i = 0; i < req->num_be_args; i++) { - if (strcmp(req->kern_be_args[i].kname, "unmap") == 0 && - strcmp(req->kern_be_args[i].kvalue, "on") == 0) { - unmap = 1; - } else { - struct ctl_be_lun_option *opt; - - opt = malloc(sizeof(*opt), M_RAMDISK, M_WAITOK); - opt->name = malloc(strlen(req->kern_be_args[i].kname) + 1, M_RAMDISK, M_WAITOK); - strcpy(opt->name, req->kern_be_args[i].kname); - opt->value = malloc(strlen(req->kern_be_args[i].kvalue) + 1, M_RAMDISK, M_WAITOK); - strcpy(opt->value, req->kern_be_args[i].kvalue); - STAILQ_INSERT_TAIL(&be_lun->ctl_be_lun.options, opt, links); - } - } + value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap"); + if (value != NULL && strcmp(value, "on") == 0) + unmap = 1; be_lun->flags = CTL_BE_RAMDISK_LUN_UNCONFIGURED; be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY; @@ -728,6 +718,7 @@ bailout_error: if (be_lun->io_taskqueue != NULL) { taskqueue_free(be_lun->io_taskqueue); } + ctl_free_opts(&be_lun->ctl_be_lun); mtx_destroy(&be_lun->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 Wed Jul 2 10:32:44 2014 (r268142) +++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.c Wed Jul 2 10:35:06 2014 (r268143) @@ -2311,22 +2311,18 @@ cfiscsi_lun_enable(void *arg, struct ctl { struct cfiscsi_softc *softc; struct cfiscsi_target *ct; - struct ctl_be_lun_option *opt; const char *target = NULL, *target_alias = NULL; const char *lun = NULL; unsigned long tmp; softc = (struct cfiscsi_softc *)arg; - STAILQ_FOREACH(opt, - &control_softc->ctl_luns[lun_id]->be_lun->options, links) { - if (strcmp(opt->name, "cfiscsi_target") == 0) - target = opt->value; - else if (strcmp(opt->name, "cfiscsi_target_alias") == 0) - target_alias = opt->value; - else if (strcmp(opt->name, "cfiscsi_lun") == 0) - lun = opt->value; - } + target = ctl_get_opt(control_softc->ctl_luns[lun_id]->be_lun, + "cfiscsi_target"); + target_alias = ctl_get_opt(control_softc->ctl_luns[lun_id]->be_lun, + "cfiscsi_target_alias"); + lun = ctl_get_opt(control_softc->ctl_luns[lun_id]->be_lun, + "cfiscsi_lun"); if (target == NULL && lun == NULL) return (0);