Deleted Added
full compact
ctl_backend_block.c (275865) ctl_backend_block.c (275920)
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 275865 2014-12-17 17:30:54Z mav $");
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 275920 2014-12-18 22:32:22Z 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>

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

170 uint64_t size_blocks;
171 uint64_t size_bytes;
172 uint32_t blocksize;
173 int blocksize_shift;
174 uint16_t pblockexp;
175 uint16_t pblockoff;
176 uint16_t ublockexp;
177 uint16_t ublockoff;
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>

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

170 uint64_t size_blocks;
171 uint64_t size_bytes;
172 uint32_t blocksize;
173 int blocksize_shift;
174 uint16_t pblockexp;
175 uint16_t pblockoff;
176 uint16_t ublockexp;
177 uint16_t ublockoff;
178 uint32_t atomicblock;
179 uint32_t opttxferlen;
178 struct ctl_be_block_softc *softc;
179 struct devstat *disk_stats;
180 ctl_be_block_lun_flags flags;
181 STAILQ_ENTRY(ctl_be_block_lun) links;
182 struct ctl_be_lun ctl_be_lun;
183 struct taskqueue *io_taskqueue;
184 struct task io_task;
185 int num_threads;

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

1840 * sector long.
1841 */
1842 if (be_lun->size_bytes < be_lun->blocksize) {
1843 error = EINVAL;
1844 snprintf(req->error_str, sizeof(req->error_str),
1845 "file %s size %ju < block size %u", be_lun->dev_path,
1846 (uintmax_t)be_lun->size_bytes, be_lun->blocksize);
1847 }
180 struct ctl_be_block_softc *softc;
181 struct devstat *disk_stats;
182 ctl_be_block_lun_flags flags;
183 STAILQ_ENTRY(ctl_be_block_lun) links;
184 struct ctl_be_lun ctl_be_lun;
185 struct taskqueue *io_taskqueue;
186 struct task io_task;
187 int num_threads;

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

1842 * sector long.
1843 */
1844 if (be_lun->size_bytes < be_lun->blocksize) {
1845 error = EINVAL;
1846 snprintf(req->error_str, sizeof(req->error_str),
1847 "file %s size %ju < block size %u", be_lun->dev_path,
1848 (uintmax_t)be_lun->size_bytes, be_lun->blocksize);
1849 }
1850
1851 be_lun->opttxferlen = CTLBLK_MAX_IO_SIZE / be_lun->blocksize;
1848 return (error);
1849}
1850
1851static int
1852ctl_be_block_open_dev(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req)
1853{
1854 struct ctl_lun_create_params *params;
1855 struct vattr vattr;
1856 struct cdev *dev;
1857 struct cdevsw *devsw;
1858 char *value;
1852 return (error);
1853}
1854
1855static int
1856ctl_be_block_open_dev(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req)
1857{
1858 struct ctl_lun_create_params *params;
1859 struct vattr vattr;
1860 struct cdev *dev;
1861 struct cdevsw *devsw;
1862 char *value;
1859 int error;
1863 int error, atomic, maxio;
1860 off_t ps, pss, po, pos, us, uss, uo, uos;
1861
1862 params = &be_lun->params;
1863
1864 be_lun->dev_type = CTL_BE_BLOCK_DEV;
1865 be_lun->backend.dev.cdev = be_lun->vn->v_rdev;
1866 be_lun->backend.dev.csw = dev_refthread(be_lun->backend.dev.cdev,
1867 &be_lun->backend.dev.dev_ref);
1868 if (be_lun->backend.dev.csw == NULL)
1869 panic("Unable to retrieve device switch");
1870 if (strcmp(be_lun->backend.dev.csw->d_name, "zvol") == 0) {
1871 be_lun->dispatch = ctl_be_block_dispatch_zvol;
1872 be_lun->get_lba_status = ctl_be_block_gls_zvol;
1864 off_t ps, pss, po, pos, us, uss, uo, uos;
1865
1866 params = &be_lun->params;
1867
1868 be_lun->dev_type = CTL_BE_BLOCK_DEV;
1869 be_lun->backend.dev.cdev = be_lun->vn->v_rdev;
1870 be_lun->backend.dev.csw = dev_refthread(be_lun->backend.dev.cdev,
1871 &be_lun->backend.dev.dev_ref);
1872 if (be_lun->backend.dev.csw == NULL)
1873 panic("Unable to retrieve device switch");
1874 if (strcmp(be_lun->backend.dev.csw->d_name, "zvol") == 0) {
1875 be_lun->dispatch = ctl_be_block_dispatch_zvol;
1876 be_lun->get_lba_status = ctl_be_block_gls_zvol;
1873 } else
1877 atomic = maxio = CTLBLK_MAX_IO_SIZE;
1878 } else {
1874 be_lun->dispatch = ctl_be_block_dispatch_dev;
1879 be_lun->dispatch = ctl_be_block_dispatch_dev;
1880 atomic = 0;
1881 maxio = be_lun->backend.dev.cdev->si_iosize_max;
1882 if (maxio <= 0)
1883 maxio = DFLTPHYS;
1884 if (maxio > CTLBLK_MAX_IO_SIZE)
1885 maxio = CTLBLK_MAX_IO_SIZE;
1886 }
1875 be_lun->lun_flush = ctl_be_block_flush_dev;
1876 be_lun->unmap = ctl_be_block_unmap_dev;
1877 be_lun->getattr = ctl_be_block_getattr_dev;
1878
1879 error = VOP_GETATTR(be_lun->vn, &vattr, NOCRED);
1880 if (error) {
1881 snprintf(req->error_str, sizeof(req->error_str),
1882 "error getting vnode attributes for device %s",

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

1997 uss = us / be_lun->blocksize;
1998 uos = uo / be_lun->blocksize;
1999 if ((uss > 0) && (uss * be_lun->blocksize == us) && (uss >= uos) &&
2000 ((uss & (uss - 1)) == 0) && (uos * be_lun->blocksize == uo)) {
2001 be_lun->ublockexp = fls(uss) - 1;
2002 be_lun->ublockoff = (uss - uos) % uss;
2003 }
2004
1887 be_lun->lun_flush = ctl_be_block_flush_dev;
1888 be_lun->unmap = ctl_be_block_unmap_dev;
1889 be_lun->getattr = ctl_be_block_getattr_dev;
1890
1891 error = VOP_GETATTR(be_lun->vn, &vattr, NOCRED);
1892 if (error) {
1893 snprintf(req->error_str, sizeof(req->error_str),
1894 "error getting vnode attributes for device %s",

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

2009 uss = us / be_lun->blocksize;
2010 uos = uo / be_lun->blocksize;
2011 if ((uss > 0) && (uss * be_lun->blocksize == us) && (uss >= uos) &&
2012 ((uss & (uss - 1)) == 0) && (uos * be_lun->blocksize == uo)) {
2013 be_lun->ublockexp = fls(uss) - 1;
2014 be_lun->ublockoff = (uss - uos) % uss;
2015 }
2016
2017 be_lun->atomicblock = atomic / be_lun->blocksize;
2018 be_lun->opttxferlen = maxio / be_lun->blocksize;
2005 return (0);
2006}
2007
2008static int
2009ctl_be_block_close(struct ctl_be_block_lun *be_lun)
2010{
2011 DROP_GIANT();
2012 if (be_lun->vn) {

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

2263 be_lun->ctl_be_lun.be_lun = be_lun;
2264 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ?
2265 0 : (be_lun->size_blocks - 1);
2266 be_lun->ctl_be_lun.blocksize = be_lun->blocksize;
2267 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp;
2268 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff;
2269 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp;
2270 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff;
2019 return (0);
2020}
2021
2022static int
2023ctl_be_block_close(struct ctl_be_block_lun *be_lun)
2024{
2025 DROP_GIANT();
2026 if (be_lun->vn) {

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

2277 be_lun->ctl_be_lun.be_lun = be_lun;
2278 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ?
2279 0 : (be_lun->size_blocks - 1);
2280 be_lun->ctl_be_lun.blocksize = be_lun->blocksize;
2281 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp;
2282 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff;
2283 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp;
2284 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff;
2271 if (be_lun->dispatch == ctl_be_block_dispatch_zvol &&
2272 be_lun->blocksize != 0)
2273 be_lun->ctl_be_lun.atomicblock = CTLBLK_MAX_IO_SIZE /
2274 be_lun->blocksize;
2285 be_lun->ctl_be_lun.atomicblock = be_lun->atomicblock;
2286 be_lun->ctl_be_lun.opttxferlen = be_lun->opttxferlen;
2275 /* Tell the user the blocksize we ended up using */
2276 params->lun_size_bytes = be_lun->size_bytes;
2277 params->blocksize_bytes = be_lun->blocksize;
2278 if (params->flags & CTL_LUN_FLAG_ID_REQ) {
2279 be_lun->ctl_be_lun.req_lun_id = params->req_lun_id;
2280 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_ID_REQ;
2281 } else
2282 be_lun->ctl_be_lun.req_lun_id = 0;

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

2644 */
2645 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ?
2646 0 : (be_lun->size_blocks - 1);
2647 be_lun->ctl_be_lun.blocksize = be_lun->blocksize;
2648 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp;
2649 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff;
2650 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp;
2651 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff;
2287 /* Tell the user the blocksize we ended up using */
2288 params->lun_size_bytes = be_lun->size_bytes;
2289 params->blocksize_bytes = be_lun->blocksize;
2290 if (params->flags & CTL_LUN_FLAG_ID_REQ) {
2291 be_lun->ctl_be_lun.req_lun_id = params->req_lun_id;
2292 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_ID_REQ;
2293 } else
2294 be_lun->ctl_be_lun.req_lun_id = 0;

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

2656 */
2657 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ?
2658 0 : (be_lun->size_blocks - 1);
2659 be_lun->ctl_be_lun.blocksize = be_lun->blocksize;
2660 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp;
2661 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff;
2662 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp;
2663 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff;
2652 if (be_lun->dispatch == ctl_be_block_dispatch_zvol &&
2653 be_lun->blocksize != 0)
2654 be_lun->ctl_be_lun.atomicblock = CTLBLK_MAX_IO_SIZE /
2655 be_lun->blocksize;
2664 be_lun->ctl_be_lun.atomicblock = be_lun->atomicblock;
2665 be_lun->ctl_be_lun.opttxferlen = be_lun->opttxferlen;
2656 ctl_lun_capacity_changed(&be_lun->ctl_be_lun);
2657 if (oldsize == 0 && be_lun->size_blocks != 0)
2658 ctl_lun_online(&be_lun->ctl_be_lun);
2659 }
2660
2661 /* Tell the user the exact size we ended up using */
2662 params->lun_size_bytes = be_lun->size_bytes;
2663

--- 245 unchanged lines hidden ---
2666 ctl_lun_capacity_changed(&be_lun->ctl_be_lun);
2667 if (oldsize == 0 && be_lun->size_blocks != 0)
2668 ctl_lun_online(&be_lun->ctl_be_lun);
2669 }
2670
2671 /* Tell the user the exact size we ended up using */
2672 params->lun_size_bytes = be_lun->size_bytes;
2673

--- 245 unchanged lines hidden ---