ctl_backend_block.c (267429) | ctl_backend_block.c (267481) |
---|---|
1/*- 2 * Copyright (c) 2003 Silicon Graphics International Corp. 3 * Copyright (c) 2009-2011 Spectra Logic Corporation 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 26 unchanged lines hidden (view full) --- 35 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend_block.c#5 $ 36 */ 37/* 38 * CAM Target Layer driver backend for block devices. 39 * 40 * Author: Ken Merry <ken@FreeBSD.org> 41 */ 42#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Silicon Graphics International Corp. 3 * Copyright (c) 2009-2011 Spectra Logic Corporation 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 26 unchanged lines hidden (view full) --- 35 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend_block.c#5 $ 36 */ 37/* 38 * CAM Target Layer driver backend for block devices. 39 * 40 * Author: Ken Merry <ken@FreeBSD.org> 41 */ 42#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 267429 2014-06-12 21:50:46Z mav $"); | 43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 267481 2014-06-14 17:47:44Z mav $"); |
44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/types.h> 49#include <sys/kthread.h> 50#include <sys/bio.h> 51#include <sys/fcntl.h> --- 1765 unchanged lines hidden (view full) --- 1817} 1818 1819static int 1820ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) 1821{ 1822 struct ctl_be_block_lun *be_lun; 1823 struct ctl_lun_create_params *params; 1824 struct ctl_be_arg *file_arg; | 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/types.h> 49#include <sys/kthread.h> 50#include <sys/bio.h> 51#include <sys/fcntl.h> --- 1765 unchanged lines hidden (view full) --- 1817} 1818 1819static int 1820ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) 1821{ 1822 struct ctl_be_block_lun *be_lun; 1823 struct ctl_lun_create_params *params; 1824 struct ctl_be_arg *file_arg; |
1825 char num_thread_str[16]; |
|
1825 char tmpstr[32]; | 1826 char tmpstr[32]; |
1827 char *value; |
|
1826 int retval, num_threads, unmap; 1827 int i; | 1828 int retval, num_threads, unmap; 1829 int i; |
1830 int tmp_num_threads; |
|
1828 1829 params = &req->reqdata.create; 1830 retval = 0; 1831 1832 num_threads = cbb_num_threads; 1833 1834 file_arg = NULL; 1835 1836 be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK); 1837 1838 be_lun->softc = softc; 1839 STAILQ_INIT(&be_lun->input_queue); 1840 STAILQ_INIT(&be_lun->config_write_queue); 1841 STAILQ_INIT(&be_lun->datamove_queue); | 1831 1832 params = &req->reqdata.create; 1833 retval = 0; 1834 1835 num_threads = cbb_num_threads; 1836 1837 file_arg = NULL; 1838 1839 be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK); 1840 1841 be_lun->softc = softc; 1842 STAILQ_INIT(&be_lun->input_queue); 1843 STAILQ_INIT(&be_lun->config_write_queue); 1844 STAILQ_INIT(&be_lun->datamove_queue); |
1842 STAILQ_INIT(&be_lun->ctl_be_lun.options); | |
1843 sprintf(be_lun->lunname, "cblk%d", softc->num_luns); 1844 mtx_init(&be_lun->lock, be_lun->lunname, NULL, MTX_DEF); | 1845 sprintf(be_lun->lunname, "cblk%d", softc->num_luns); 1846 mtx_init(&be_lun->lock, be_lun->lunname, NULL, MTX_DEF); |
1847 ctl_init_opts(&be_lun->ctl_be_lun, req); |
|
1845 1846 be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG, 1847 NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); 1848 1849 if (be_lun->lun_zone == NULL) { 1850 snprintf(req->error_str, sizeof(req->error_str), 1851 "%s: error allocating UMA zone", __func__); 1852 goto bailout_error; --- 56 unchanged lines hidden (view full) --- 1909 */ 1910 num_threads = 1; 1911 } 1912 1913 /* 1914 * XXX This searching loop might be refactored to be combined with 1915 * the loop above, 1916 */ | 1848 1849 be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG, 1850 NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); 1851 1852 if (be_lun->lun_zone == NULL) { 1853 snprintf(req->error_str, sizeof(req->error_str), 1854 "%s: error allocating UMA zone", __func__); 1855 goto bailout_error; --- 56 unchanged lines hidden (view full) --- 1912 */ 1913 num_threads = 1; 1914 } 1915 1916 /* 1917 * XXX This searching loop might be refactored to be combined with 1918 * the loop above, 1919 */ |
1917 unmap = 0; 1918 for (i = 0; i < req->num_be_args; i++) { 1919 if (strcmp(req->kern_be_args[i].kname, "num_threads") == 0) { 1920 struct ctl_be_arg *thread_arg; 1921 char num_thread_str[16]; 1922 int tmp_num_threads; | 1920 value = ctl_get_opt(&be_lun->ctl_be_lun, "num_threads"); 1921 if (value != NULL) { 1922 tmp_num_threads = strtol(value, NULL, 0); |
1923 | 1923 |
1924 1925 thread_arg = &req->kern_be_args[i]; 1926 1927 strlcpy(num_thread_str, (char *)thread_arg->kvalue, 1928 min(thread_arg->vallen, 1929 sizeof(num_thread_str))); 1930 1931 tmp_num_threads = strtol(num_thread_str, NULL, 0); 1932 1933 /* 1934 * We don't let the user specify less than one 1935 * thread, but hope he's clueful enough not to 1936 * specify 1000 threads. 1937 */ 1938 if (tmp_num_threads < 1) { 1939 snprintf(req->error_str, sizeof(req->error_str), 1940 "%s: invalid number of threads %s", 1941 __func__, num_thread_str); 1942 goto bailout_error; 1943 } 1944 1945 num_threads = tmp_num_threads; 1946 } else if (strcmp(req->kern_be_args[i].kname, "unmap") == 0 && 1947 strcmp(req->kern_be_args[i].kvalue, "on") == 0) { 1948 unmap = 1; 1949 } else if (strcmp(req->kern_be_args[i].kname, "file") != 0 && 1950 strcmp(req->kern_be_args[i].kname, "dev") != 0) { 1951 struct ctl_be_lun_option *opt; 1952 1953 opt = malloc(sizeof(*opt), M_CTLBLK, M_WAITOK); 1954 opt->name = malloc(strlen(req->kern_be_args[i].kname) + 1, M_CTLBLK, M_WAITOK); 1955 strcpy(opt->name, req->kern_be_args[i].kname); 1956 opt->value = malloc(strlen(req->kern_be_args[i].kvalue) + 1, M_CTLBLK, M_WAITOK); 1957 strcpy(opt->value, req->kern_be_args[i].kvalue); 1958 STAILQ_INSERT_TAIL(&be_lun->ctl_be_lun.options, opt, links); | 1924 /* 1925 * We don't let the user specify less than one 1926 * thread, but hope he's clueful enough not to 1927 * specify 1000 threads. 1928 */ 1929 if (tmp_num_threads < 1) { 1930 snprintf(req->error_str, sizeof(req->error_str), 1931 "%s: invalid number of threads %s", 1932 __func__, num_thread_str); 1933 goto bailout_error; |
1959 } | 1934 } |
1935 num_threads = tmp_num_threads; |
|
1960 } | 1936 } |
1937 unmap = 0; 1938 value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap"); 1939 if (value != NULL && strcmp(value, "on") == 0) 1940 unmap = 1; |
|
1961 1962 be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED; 1963 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY; 1964 if (unmap) 1965 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP; 1966 be_lun->ctl_be_lun.be_lun = be_lun; 1967 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 1968 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; --- 146 unchanged lines hidden (view full) --- 2115 2116 if (be_lun->io_taskqueue != NULL) 2117 taskqueue_free(be_lun->io_taskqueue); 2118 ctl_be_block_close(be_lun); 2119 if (be_lun->dev_path != NULL) 2120 free(be_lun->dev_path, M_CTLBLK); 2121 if (be_lun->lun_zone != NULL) 2122 uma_zdestroy(be_lun->lun_zone); | 1941 1942 be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED; 1943 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY; 1944 if (unmap) 1945 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP; 1946 be_lun->ctl_be_lun.be_lun = be_lun; 1947 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 1948 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; --- 146 unchanged lines hidden (view full) --- 2095 2096 if (be_lun->io_taskqueue != NULL) 2097 taskqueue_free(be_lun->io_taskqueue); 2098 ctl_be_block_close(be_lun); 2099 if (be_lun->dev_path != NULL) 2100 free(be_lun->dev_path, M_CTLBLK); 2101 if (be_lun->lun_zone != NULL) 2102 uma_zdestroy(be_lun->lun_zone); |
2103 ctl_free_opts(&be_lun->ctl_be_lun); |
|
2123 mtx_destroy(&be_lun->lock); 2124 free(be_lun, M_CTLBLK); 2125 2126 return (retval); 2127} 2128 2129static int 2130ctl_be_block_rm(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) --- 70 unchanged lines hidden (view full) --- 2201 2202 ctl_be_block_close(be_lun); 2203 2204 if (be_lun->disk_stats != NULL) 2205 devstat_remove_entry(be_lun->disk_stats); 2206 2207 uma_zdestroy(be_lun->lun_zone); 2208 | 2104 mtx_destroy(&be_lun->lock); 2105 free(be_lun, M_CTLBLK); 2106 2107 return (retval); 2108} 2109 2110static int 2111ctl_be_block_rm(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) --- 70 unchanged lines hidden (view full) --- 2182 2183 ctl_be_block_close(be_lun); 2184 2185 if (be_lun->disk_stats != NULL) 2186 devstat_remove_entry(be_lun->disk_stats); 2187 2188 uma_zdestroy(be_lun->lun_zone); 2189 |
2190 ctl_free_opts(&be_lun->ctl_be_lun); |
|
2209 free(be_lun->dev_path, M_CTLBLK); 2210 2211 free(be_lun, M_CTLBLK); 2212 2213 req->status = CTL_LUN_OK; 2214 2215 return (0); 2216 --- 361 unchanged lines hidden --- | 2191 free(be_lun->dev_path, M_CTLBLK); 2192 2193 free(be_lun, M_CTLBLK); 2194 2195 req->status = CTL_LUN_OK; 2196 2197 return (0); 2198 --- 361 unchanged lines hidden --- |