Deleted Added
full compact
ctl_backend_block.c (273809) ctl_backend_block.c (274154)
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 273809 2014-10-29 03:14:29Z mav $");
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 274154 2014-11-06 00:48:36Z 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>

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

140 struct ctl_be_block_filedata file;
141};
142
143struct ctl_be_block_io;
144struct ctl_be_block_lun;
145
146typedef void (*cbb_dispatch_t)(struct ctl_be_block_lun *be_lun,
147 struct ctl_be_block_io *beio);
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>

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

140 struct ctl_be_block_filedata file;
141};
142
143struct ctl_be_block_io;
144struct ctl_be_block_lun;
145
146typedef void (*cbb_dispatch_t)(struct ctl_be_block_lun *be_lun,
147 struct ctl_be_block_io *beio);
148typedef uint64_t (*cbb_getattr_t)(struct ctl_be_block_lun *be_lun,
149 const char *attrname);
148
149/*
150 * Backend LUN structure. There is a 1:1 mapping between a block device
151 * and a backend block LUN, and between a backend block LUN and a CTL LUN.
152 */
153struct ctl_be_block_lun {
154 struct ctl_lun_create_params params;
155 struct ctl_block_disk *disk;
156 char lunname[32];
157 char *dev_path;
158 ctl_be_block_type dev_type;
159 struct vnode *vn;
160 union ctl_be_block_bedata backend;
161 cbb_dispatch_t dispatch;
162 cbb_dispatch_t lun_flush;
163 cbb_dispatch_t unmap;
150
151/*
152 * Backend LUN structure. There is a 1:1 mapping between a block device
153 * and a backend block LUN, and between a backend block LUN and a CTL LUN.
154 */
155struct ctl_be_block_lun {
156 struct ctl_lun_create_params params;
157 struct ctl_block_disk *disk;
158 char lunname[32];
159 char *dev_path;
160 ctl_be_block_type dev_type;
161 struct vnode *vn;
162 union ctl_be_block_bedata backend;
163 cbb_dispatch_t dispatch;
164 cbb_dispatch_t lun_flush;
165 cbb_dispatch_t unmap;
166 cbb_getattr_t getattr;
164 uma_zone_t lun_zone;
165 uint64_t size_blocks;
166 uint64_t size_bytes;
167 uint32_t blocksize;
168 int blocksize_shift;
169 uint16_t pblockexp;
170 uint16_t pblockoff;
171 struct ctl_be_block_softc *softc;

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

235static void ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun,
236 struct ctl_be_block_io *beio);
237static void ctl_be_block_flush_dev(struct ctl_be_block_lun *be_lun,
238 struct ctl_be_block_io *beio);
239static void ctl_be_block_unmap_dev(struct ctl_be_block_lun *be_lun,
240 struct ctl_be_block_io *beio);
241static void ctl_be_block_dispatch_dev(struct ctl_be_block_lun *be_lun,
242 struct ctl_be_block_io *beio);
167 uma_zone_t lun_zone;
168 uint64_t size_blocks;
169 uint64_t size_bytes;
170 uint32_t blocksize;
171 int blocksize_shift;
172 uint16_t pblockexp;
173 uint16_t pblockoff;
174 struct ctl_be_block_softc *softc;

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

238static void ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun,
239 struct ctl_be_block_io *beio);
240static void ctl_be_block_flush_dev(struct ctl_be_block_lun *be_lun,
241 struct ctl_be_block_io *beio);
242static void ctl_be_block_unmap_dev(struct ctl_be_block_lun *be_lun,
243 struct ctl_be_block_io *beio);
244static void ctl_be_block_dispatch_dev(struct ctl_be_block_lun *be_lun,
245 struct ctl_be_block_io *beio);
246static uint64_t ctl_be_block_getattr_dev(struct ctl_be_block_lun *be_lun,
247 const char *attrname);
243static void ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun,
244 union ctl_io *io);
245static void ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
246 union ctl_io *io);
247static void ctl_be_block_worker(void *context, int pending);
248static int ctl_be_block_submit(union ctl_io *io);
249static int ctl_be_block_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
250 int flag, struct thread *td);

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

267static int ctl_be_block_modify(struct ctl_be_block_softc *softc,
268 struct ctl_lun_req *req);
269static void ctl_be_block_lun_shutdown(void *be_lun);
270static void ctl_be_block_lun_config_status(void *be_lun,
271 ctl_lun_config_status status);
272static int ctl_be_block_config_write(union ctl_io *io);
273static int ctl_be_block_config_read(union ctl_io *io);
274static int ctl_be_block_lun_info(void *be_lun, struct sbuf *sb);
248static void ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun,
249 union ctl_io *io);
250static void ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
251 union ctl_io *io);
252static void ctl_be_block_worker(void *context, int pending);
253static int ctl_be_block_submit(union ctl_io *io);
254static int ctl_be_block_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
255 int flag, struct thread *td);

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

272static int ctl_be_block_modify(struct ctl_be_block_softc *softc,
273 struct ctl_lun_req *req);
274static void ctl_be_block_lun_shutdown(void *be_lun);
275static void ctl_be_block_lun_config_status(void *be_lun,
276 ctl_lun_config_status status);
277static int ctl_be_block_config_write(union ctl_io *io);
278static int ctl_be_block_config_read(union ctl_io *io);
279static int ctl_be_block_lun_info(void *be_lun, struct sbuf *sb);
280static uint64_t ctl_be_block_lun_attr(void *be_lun, const char *attrname);
275int ctl_be_block_init(void);
276
277static struct ctl_backend_driver ctl_be_block_driver =
278{
279 .name = "block",
280 .flags = CTL_BE_FLAG_HAS_CONFIG,
281 .init = ctl_be_block_init,
282 .data_submit = ctl_be_block_submit,
283 .data_move_done = ctl_be_block_move_done,
284 .config_read = ctl_be_block_config_read,
285 .config_write = ctl_be_block_config_write,
286 .ioctl = ctl_be_block_ioctl,
281int ctl_be_block_init(void);
282
283static struct ctl_backend_driver ctl_be_block_driver =
284{
285 .name = "block",
286 .flags = CTL_BE_FLAG_HAS_CONFIG,
287 .init = ctl_be_block_init,
288 .data_submit = ctl_be_block_submit,
289 .data_move_done = ctl_be_block_move_done,
290 .config_read = ctl_be_block_config_read,
291 .config_write = ctl_be_block_config_write,
292 .ioctl = ctl_be_block_ioctl,
287 .lun_info = ctl_be_block_lun_info
293 .lun_info = ctl_be_block_lun_info,
294 .lun_attr = ctl_be_block_lun_attr
288};
289
290MALLOC_DEFINE(M_CTLBLK, "ctlblk", "Memory used for CTL block backend");
291CTL_BACKEND_DECLARE(cbb, ctl_be_block_driver);
292
293static uma_zone_t beio_zone;
294
295static struct ctl_be_block_io *

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

1007 * Fire off all allocated requests!
1008 */
1009 while ((bio = TAILQ_FIRST(&queue)) != NULL) {
1010 TAILQ_REMOVE(&queue, bio, bio_queue);
1011 (*dev_data->csw->d_strategy)(bio);
1012 }
1013}
1014
295};
296
297MALLOC_DEFINE(M_CTLBLK, "ctlblk", "Memory used for CTL block backend");
298CTL_BACKEND_DECLARE(cbb, ctl_be_block_driver);
299
300static uma_zone_t beio_zone;
301
302static struct ctl_be_block_io *

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

1014 * Fire off all allocated requests!
1015 */
1016 while ((bio = TAILQ_FIRST(&queue)) != NULL) {
1017 TAILQ_REMOVE(&queue, bio, bio_queue);
1018 (*dev_data->csw->d_strategy)(bio);
1019 }
1020}
1021
1022static uint64_t
1023ctl_be_block_getattr_dev(struct ctl_be_block_lun *be_lun, const char *attrname)
1024{
1025 struct ctl_be_block_devdata *dev_data = &be_lun->backend.dev;
1026 struct diocgattr_arg arg;
1027 int error;
1028
1029 if (dev_data->csw == NULL || dev_data->csw->d_ioctl == NULL)
1030 return (UINT64_MAX);
1031 strlcpy(arg.name, attrname, sizeof(arg.name));
1032 arg.len = sizeof(arg.value.off);
1033 error = dev_data->csw->d_ioctl(dev_data->cdev,
1034 DIOCGATTR, (caddr_t)&arg, FREAD, curthread);
1035 if (error != 0)
1036 return (UINT64_MAX);
1037 return (arg.value.off);
1038}
1039
1015static void
1016ctl_be_block_cw_done_ws(struct ctl_be_block_io *beio)
1017{
1018 union ctl_io *io;
1019
1020 io = beio->io;
1021 ctl_free_beio(beio);
1022 if ((io->io_hdr.flags & CTL_FLAG_ABORT) ||

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

1642 if (be_lun->backend.dev.csw == NULL)
1643 panic("Unable to retrieve device switch");
1644 if (strcmp(be_lun->backend.dev.csw->d_name, "zvol") == 0)
1645 be_lun->dispatch = ctl_be_block_dispatch_zvol;
1646 else
1647 be_lun->dispatch = ctl_be_block_dispatch_dev;
1648 be_lun->lun_flush = ctl_be_block_flush_dev;
1649 be_lun->unmap = ctl_be_block_unmap_dev;
1040static void
1041ctl_be_block_cw_done_ws(struct ctl_be_block_io *beio)
1042{
1043 union ctl_io *io;
1044
1045 io = beio->io;
1046 ctl_free_beio(beio);
1047 if ((io->io_hdr.flags & CTL_FLAG_ABORT) ||

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

1667 if (be_lun->backend.dev.csw == NULL)
1668 panic("Unable to retrieve device switch");
1669 if (strcmp(be_lun->backend.dev.csw->d_name, "zvol") == 0)
1670 be_lun->dispatch = ctl_be_block_dispatch_zvol;
1671 else
1672 be_lun->dispatch = ctl_be_block_dispatch_dev;
1673 be_lun->lun_flush = ctl_be_block_flush_dev;
1674 be_lun->unmap = ctl_be_block_unmap_dev;
1675 be_lun->getattr = ctl_be_block_getattr_dev;
1650
1651 error = VOP_GETATTR(be_lun->vn, &vattr, NOCRED);
1652 if (error) {
1653 snprintf(req->error_str, sizeof(req->error_str),
1654 "error getting vnode attributes for device %s",
1655 be_lun->dev_path);
1656 return (error);
1657 }

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

1988 if (tmp_num_threads < 1) {
1989 snprintf(req->error_str, sizeof(req->error_str),
1990 "invalid number of threads %s",
1991 num_thread_str);
1992 goto bailout_error;
1993 }
1994 num_threads = tmp_num_threads;
1995 }
1676
1677 error = VOP_GETATTR(be_lun->vn, &vattr, NOCRED);
1678 if (error) {
1679 snprintf(req->error_str, sizeof(req->error_str),
1680 "error getting vnode attributes for device %s",
1681 be_lun->dev_path);
1682 return (error);
1683 }

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

2014 if (tmp_num_threads < 1) {
2015 snprintf(req->error_str, sizeof(req->error_str),
2016 "invalid number of threads %s",
2017 num_thread_str);
2018 goto bailout_error;
2019 }
2020 num_threads = tmp_num_threads;
2021 }
1996 unmap = 0;
2022 unmap = (be_lun->dispatch == ctl_be_block_dispatch_zvol);
1997 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "unmap");
2023 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "unmap");
1998 if (value != NULL && strcmp(value, "on") == 0)
1999 unmap = 1;
2024 if (value != NULL)
2025 unmap = (strcmp(value, "on") == 0);
2000
2001 be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED;
2002 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY;
2003 if (be_lun->vn == NULL)
2004 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_OFFLINE;
2005 if (unmap)
2006 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP;
2007 be_lun->ctl_be_lun.be_lun = be_lun;

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

2577
2578 retval = sbuf_printf(sb, "</num_threads>\n");
2579
2580bailout:
2581
2582 return (retval);
2583}
2584
2026
2027 be_lun->flags = CTL_BE_BLOCK_LUN_UNCONFIGURED;
2028 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY;
2029 if (be_lun->vn == NULL)
2030 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_OFFLINE;
2031 if (unmap)
2032 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP;
2033 be_lun->ctl_be_lun.be_lun = be_lun;

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

2603
2604 retval = sbuf_printf(sb, "</num_threads>\n");
2605
2606bailout:
2607
2608 return (retval);
2609}
2610
2611static uint64_t
2612ctl_be_block_lun_attr(void *be_lun, const char *attrname)
2613{
2614 struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)be_lun;
2615
2616 if (lun->getattr == NULL)
2617 return (UINT64_MAX);
2618 return (lun->getattr(lun, attrname));
2619}
2620
2585int
2586ctl_be_block_init(void)
2587{
2588 struct ctl_be_block_softc *softc;
2589 int retval;
2590
2591 softc = &backend_block_softc;
2592 retval = 0;
2593
2594 mtx_init(&softc->lock, "ctlblock", NULL, MTX_DEF);
2595 beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io),
2596 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
2597 STAILQ_INIT(&softc->disk_list);
2598 STAILQ_INIT(&softc->lun_list);
2599
2600 return (retval);
2601}
2621int
2622ctl_be_block_init(void)
2623{
2624 struct ctl_be_block_softc *softc;
2625 int retval;
2626
2627 softc = &backend_block_softc;
2628 retval = 0;
2629
2630 mtx_init(&softc->lock, "ctlblock", NULL, MTX_DEF);
2631 beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io),
2632 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
2633 STAILQ_INIT(&softc->disk_list);
2634 STAILQ_INIT(&softc->lun_list);
2635
2636 return (retval);
2637}