Deleted Added
full compact
ctl_backend_block.c (267754) ctl_backend_block.c (268143)
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: stable/10/sys/cam/ctl/ctl_backend_block.c 267754 2014-06-22 21:28:05Z mav $");
43__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_backend_block.c 268143 2014-07-02 10:35:06Z mav $");
44
45#include <opt_kdtrace.h>
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/types.h>
51#include <sys/kthread.h>

--- 1767 unchanged lines hidden (view full) ---

1819}
1820
1821static int
1822ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
1823{
1824 struct ctl_be_block_lun *be_lun;
1825 struct ctl_lun_create_params *params;
1826 struct ctl_be_arg *file_arg;
44
45#include <opt_kdtrace.h>
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/types.h>
51#include <sys/kthread.h>

--- 1767 unchanged lines hidden (view full) ---

1819}
1820
1821static int
1822ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
1823{
1824 struct ctl_be_block_lun *be_lun;
1825 struct ctl_lun_create_params *params;
1826 struct ctl_be_arg *file_arg;
1827 char num_thread_str[16];
1827 char tmpstr[32];
1828 char tmpstr[32];
1829 char *value;
1828 int retval, num_threads, unmap;
1829 int i;
1830 int retval, num_threads, unmap;
1831 int i;
1832 int tmp_num_threads;
1830
1831 params = &req->reqdata.create;
1832 retval = 0;
1833
1834 num_threads = cbb_num_threads;
1835
1836 file_arg = NULL;
1837
1838 be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK);
1839
1840 be_lun->softc = softc;
1841 STAILQ_INIT(&be_lun->input_queue);
1842 STAILQ_INIT(&be_lun->config_write_queue);
1843 STAILQ_INIT(&be_lun->datamove_queue);
1833
1834 params = &req->reqdata.create;
1835 retval = 0;
1836
1837 num_threads = cbb_num_threads;
1838
1839 file_arg = NULL;
1840
1841 be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK);
1842
1843 be_lun->softc = softc;
1844 STAILQ_INIT(&be_lun->input_queue);
1845 STAILQ_INIT(&be_lun->config_write_queue);
1846 STAILQ_INIT(&be_lun->datamove_queue);
1844 STAILQ_INIT(&be_lun->ctl_be_lun.options);
1845 sprintf(be_lun->lunname, "cblk%d", softc->num_luns);
1846 mtx_init(&be_lun->lock, be_lun->lunname, NULL, MTX_DEF);
1847 sprintf(be_lun->lunname, "cblk%d", softc->num_luns);
1848 mtx_init(&be_lun->lock, be_lun->lunname, NULL, MTX_DEF);
1849 ctl_init_opts(&be_lun->ctl_be_lun, req);
1847
1848 be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG,
1849 NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0);
1850
1851 if (be_lun->lun_zone == NULL) {
1852 snprintf(req->error_str, sizeof(req->error_str),
1853 "%s: error allocating UMA zone", __func__);
1854 goto bailout_error;

--- 56 unchanged lines hidden (view full) ---

1911 */
1912 num_threads = 1;
1913 }
1914
1915 /*
1916 * XXX This searching loop might be refactored to be combined with
1917 * the loop above,
1918 */
1850
1851 be_lun->lun_zone = uma_zcreate(be_lun->lunname, CTLBLK_MAX_SEG,
1852 NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0);
1853
1854 if (be_lun->lun_zone == NULL) {
1855 snprintf(req->error_str, sizeof(req->error_str),
1856 "%s: error allocating UMA zone", __func__);
1857 goto bailout_error;

--- 56 unchanged lines hidden (view full) ---

1914 */
1915 num_threads = 1;
1916 }
1917
1918 /*
1919 * XXX This searching loop might be refactored to be combined with
1920 * the loop above,
1921 */
1919 unmap = 0;
1920 for (i = 0; i < req->num_be_args; i++) {
1921 if (strcmp(req->kern_be_args[i].kname, "num_threads") == 0) {
1922 struct ctl_be_arg *thread_arg;
1923 char num_thread_str[16];
1924 int tmp_num_threads;
1922 value = ctl_get_opt(&be_lun->ctl_be_lun, "num_threads");
1923 if (value != NULL) {
1924 tmp_num_threads = strtol(value, NULL, 0);
1925
1925
1926
1927 thread_arg = &req->kern_be_args[i];
1928
1929 strlcpy(num_thread_str, (char *)thread_arg->kvalue,
1930 min(thread_arg->vallen,
1931 sizeof(num_thread_str)));
1932
1933 tmp_num_threads = strtol(num_thread_str, NULL, 0);
1934
1935 /*
1936 * We don't let the user specify less than one
1937 * thread, but hope he's clueful enough not to
1938 * specify 1000 threads.
1939 */
1940 if (tmp_num_threads < 1) {
1941 snprintf(req->error_str, sizeof(req->error_str),
1942 "%s: invalid number of threads %s",
1943 __func__, num_thread_str);
1944 goto bailout_error;
1945 }
1946
1947 num_threads = tmp_num_threads;
1948 } else if (strcmp(req->kern_be_args[i].kname, "unmap") == 0 &&
1949 strcmp(req->kern_be_args[i].kvalue, "on") == 0) {
1950 unmap = 1;
1951 } else if (strcmp(req->kern_be_args[i].kname, "file") != 0 &&
1952 strcmp(req->kern_be_args[i].kname, "dev") != 0) {
1953 struct ctl_be_lun_option *opt;
1954
1955 opt = malloc(sizeof(*opt), M_CTLBLK, M_WAITOK);
1956 opt->name = malloc(strlen(req->kern_be_args[i].kname) + 1, M_CTLBLK, M_WAITOK);
1957 strcpy(opt->name, req->kern_be_args[i].kname);
1958 opt->value = malloc(strlen(req->kern_be_args[i].kvalue) + 1, M_CTLBLK, M_WAITOK);
1959 strcpy(opt->value, req->kern_be_args[i].kvalue);
1960 STAILQ_INSERT_TAIL(&be_lun->ctl_be_lun.options, opt, links);
1926 /*
1927 * We don't let the user specify less than one
1928 * thread, but hope he's clueful enough not to
1929 * specify 1000 threads.
1930 */
1931 if (tmp_num_threads < 1) {
1932 snprintf(req->error_str, sizeof(req->error_str),
1933 "%s: invalid number of threads %s",
1934 __func__, num_thread_str);
1935 goto bailout_error;
1961 }
1936 }
1937 num_threads = tmp_num_threads;
1962 }
1938 }
1939 unmap = 0;
1940 value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap");
1941 if (value != NULL && strcmp(value, "on") == 0)
1942 unmap = 1;
1963
1964 be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED;
1965 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY;
1966 if (unmap)
1967 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP;
1968 be_lun->ctl_be_lun.be_lun = be_lun;
1969 be_lun->ctl_be_lun.blocksize = be_lun->blocksize;
1970 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp;

--- 146 unchanged lines hidden (view full) ---

2117
2118 if (be_lun->io_taskqueue != NULL)
2119 taskqueue_free(be_lun->io_taskqueue);
2120 ctl_be_block_close(be_lun);
2121 if (be_lun->dev_path != NULL)
2122 free(be_lun->dev_path, M_CTLBLK);
2123 if (be_lun->lun_zone != NULL)
2124 uma_zdestroy(be_lun->lun_zone);
1943
1944 be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED;
1945 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY;
1946 if (unmap)
1947 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP;
1948 be_lun->ctl_be_lun.be_lun = be_lun;
1949 be_lun->ctl_be_lun.blocksize = be_lun->blocksize;
1950 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp;

--- 146 unchanged lines hidden (view full) ---

2097
2098 if (be_lun->io_taskqueue != NULL)
2099 taskqueue_free(be_lun->io_taskqueue);
2100 ctl_be_block_close(be_lun);
2101 if (be_lun->dev_path != NULL)
2102 free(be_lun->dev_path, M_CTLBLK);
2103 if (be_lun->lun_zone != NULL)
2104 uma_zdestroy(be_lun->lun_zone);
2105 ctl_free_opts(&be_lun->ctl_be_lun);
2125 mtx_destroy(&be_lun->lock);
2126 free(be_lun, M_CTLBLK);
2127
2128 return (retval);
2129}
2130
2131static int
2132ctl_be_block_rm(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)

--- 70 unchanged lines hidden (view full) ---

2203
2204 ctl_be_block_close(be_lun);
2205
2206 if (be_lun->disk_stats != NULL)
2207 devstat_remove_entry(be_lun->disk_stats);
2208
2209 uma_zdestroy(be_lun->lun_zone);
2210
2106 mtx_destroy(&be_lun->lock);
2107 free(be_lun, M_CTLBLK);
2108
2109 return (retval);
2110}
2111
2112static int
2113ctl_be_block_rm(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)

--- 70 unchanged lines hidden (view full) ---

2184
2185 ctl_be_block_close(be_lun);
2186
2187 if (be_lun->disk_stats != NULL)
2188 devstat_remove_entry(be_lun->disk_stats);
2189
2190 uma_zdestroy(be_lun->lun_zone);
2191
2192 ctl_free_opts(&be_lun->ctl_be_lun);
2211 free(be_lun->dev_path, M_CTLBLK);
2212
2213 free(be_lun, M_CTLBLK);
2214
2215 req->status = CTL_LUN_OK;
2216
2217 return (0);
2218

--- 361 unchanged lines hidden ---
2193 free(be_lun->dev_path, M_CTLBLK);
2194
2195 free(be_lun, M_CTLBLK);
2196
2197 req->status = CTL_LUN_OK;
2198
2199 return (0);
2200

--- 361 unchanged lines hidden ---