ctl_backend_block.c (276179) | ctl_backend_block.c (276237) |
---|---|
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 276179 2014-12-24 13:49:40Z mav $"); | 43__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_backend_block.c 276237 2014-12-26 09:44:32Z 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> --- 120 unchanged lines hidden (view full) --- 172 uint64_t size_blocks; 173 uint64_t size_bytes; 174 uint32_t blocksize; 175 int blocksize_shift; 176 uint16_t pblockexp; 177 uint16_t pblockoff; 178 uint16_t ublockexp; 179 uint16_t ublockoff; | 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> --- 120 unchanged lines hidden (view full) --- 172 uint64_t size_blocks; 173 uint64_t size_bytes; 174 uint32_t blocksize; 175 int blocksize_shift; 176 uint16_t pblockexp; 177 uint16_t pblockoff; 178 uint16_t ublockexp; 179 uint16_t ublockoff; |
180 uint32_t atomicblock; 181 uint32_t opttxferlen; |
|
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; --- 1655 unchanged lines hidden (view full) --- 1843 * sector long. 1844 */ 1845 if (be_lun->size_bytes < be_lun->blocksize) { 1846 error = EINVAL; 1847 snprintf(req->error_str, sizeof(req->error_str), 1848 "file %s size %ju < block size %u", be_lun->dev_path, 1849 (uintmax_t)be_lun->size_bytes, be_lun->blocksize); 1850 } | 182 struct ctl_be_block_softc *softc; 183 struct devstat *disk_stats; 184 ctl_be_block_lun_flags flags; 185 STAILQ_ENTRY(ctl_be_block_lun) links; 186 struct ctl_be_lun ctl_be_lun; 187 struct taskqueue *io_taskqueue; 188 struct task io_task; 189 int num_threads; --- 1655 unchanged lines hidden (view full) --- 1845 * sector long. 1846 */ 1847 if (be_lun->size_bytes < be_lun->blocksize) { 1848 error = EINVAL; 1849 snprintf(req->error_str, sizeof(req->error_str), 1850 "file %s size %ju < block size %u", be_lun->dev_path, 1851 (uintmax_t)be_lun->size_bytes, be_lun->blocksize); 1852 } |
1853 1854 be_lun->opttxferlen = CTLBLK_MAX_IO_SIZE / be_lun->blocksize; |
|
1851 return (error); 1852} 1853 1854static int 1855ctl_be_block_open_dev(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req) 1856{ 1857 struct ctl_lun_create_params *params; 1858 struct vattr vattr; 1859 struct cdev *dev; 1860 struct cdevsw *devsw; 1861 char *value; | 1855 return (error); 1856} 1857 1858static int 1859ctl_be_block_open_dev(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req) 1860{ 1861 struct ctl_lun_create_params *params; 1862 struct vattr vattr; 1863 struct cdev *dev; 1864 struct cdevsw *devsw; 1865 char *value; |
1862 int error; | 1866 int error, atomic, maxio; |
1863 off_t ps, pss, po, pos, us, uss, uo, uos; 1864 1865 params = &be_lun->params; 1866 1867 be_lun->dev_type = CTL_BE_BLOCK_DEV; 1868 be_lun->backend.dev.cdev = be_lun->vn->v_rdev; 1869 be_lun->backend.dev.csw = dev_refthread(be_lun->backend.dev.cdev, 1870 &be_lun->backend.dev.dev_ref); 1871 if (be_lun->backend.dev.csw == NULL) 1872 panic("Unable to retrieve device switch"); 1873 if (strcmp(be_lun->backend.dev.csw->d_name, "zvol") == 0) { 1874 be_lun->dispatch = ctl_be_block_dispatch_zvol; 1875 be_lun->get_lba_status = ctl_be_block_gls_zvol; | 1867 off_t ps, pss, po, pos, us, uss, uo, uos; 1868 1869 params = &be_lun->params; 1870 1871 be_lun->dev_type = CTL_BE_BLOCK_DEV; 1872 be_lun->backend.dev.cdev = be_lun->vn->v_rdev; 1873 be_lun->backend.dev.csw = dev_refthread(be_lun->backend.dev.cdev, 1874 &be_lun->backend.dev.dev_ref); 1875 if (be_lun->backend.dev.csw == NULL) 1876 panic("Unable to retrieve device switch"); 1877 if (strcmp(be_lun->backend.dev.csw->d_name, "zvol") == 0) { 1878 be_lun->dispatch = ctl_be_block_dispatch_zvol; 1879 be_lun->get_lba_status = ctl_be_block_gls_zvol; |
1876 } else | 1880 atomic = maxio = CTLBLK_MAX_IO_SIZE; 1881 } else { |
1877 be_lun->dispatch = ctl_be_block_dispatch_dev; | 1882 be_lun->dispatch = ctl_be_block_dispatch_dev; |
1883 atomic = 0; 1884 maxio = be_lun->backend.dev.cdev->si_iosize_max; 1885 if (maxio <= 0) 1886 maxio = DFLTPHYS; 1887 if (maxio > CTLBLK_MAX_IO_SIZE) 1888 maxio = CTLBLK_MAX_IO_SIZE; 1889 } |
|
1878 be_lun->lun_flush = ctl_be_block_flush_dev; 1879 be_lun->unmap = ctl_be_block_unmap_dev; 1880 be_lun->getattr = ctl_be_block_getattr_dev; 1881 1882 error = VOP_GETATTR(be_lun->vn, &vattr, NOCRED); 1883 if (error) { 1884 snprintf(req->error_str, sizeof(req->error_str), 1885 "error getting vnode attributes for device %s", --- 114 unchanged lines hidden (view full) --- 2000 uss = us / be_lun->blocksize; 2001 uos = uo / be_lun->blocksize; 2002 if ((uss > 0) && (uss * be_lun->blocksize == us) && (uss >= uos) && 2003 ((uss & (uss - 1)) == 0) && (uos * be_lun->blocksize == uo)) { 2004 be_lun->ublockexp = fls(uss) - 1; 2005 be_lun->ublockoff = (uss - uos) % uss; 2006 } 2007 | 1890 be_lun->lun_flush = ctl_be_block_flush_dev; 1891 be_lun->unmap = ctl_be_block_unmap_dev; 1892 be_lun->getattr = ctl_be_block_getattr_dev; 1893 1894 error = VOP_GETATTR(be_lun->vn, &vattr, NOCRED); 1895 if (error) { 1896 snprintf(req->error_str, sizeof(req->error_str), 1897 "error getting vnode attributes for device %s", --- 114 unchanged lines hidden (view full) --- 2012 uss = us / be_lun->blocksize; 2013 uos = uo / be_lun->blocksize; 2014 if ((uss > 0) && (uss * be_lun->blocksize == us) && (uss >= uos) && 2015 ((uss & (uss - 1)) == 0) && (uos * be_lun->blocksize == uo)) { 2016 be_lun->ublockexp = fls(uss) - 1; 2017 be_lun->ublockoff = (uss - uos) % uss; 2018 } 2019 |
2020 be_lun->atomicblock = atomic / be_lun->blocksize; 2021 be_lun->opttxferlen = maxio / be_lun->blocksize; |
|
2008 return (0); 2009} 2010 2011static int 2012ctl_be_block_close(struct ctl_be_block_lun *be_lun) 2013{ 2014 DROP_GIANT(); 2015 if (be_lun->vn) { --- 250 unchanged lines hidden (view full) --- 2266 be_lun->ctl_be_lun.be_lun = be_lun; 2267 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ? 2268 0 : (be_lun->size_blocks - 1); 2269 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 2270 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; 2271 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff; 2272 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp; 2273 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff; | 2022 return (0); 2023} 2024 2025static int 2026ctl_be_block_close(struct ctl_be_block_lun *be_lun) 2027{ 2028 DROP_GIANT(); 2029 if (be_lun->vn) { --- 250 unchanged lines hidden (view full) --- 2280 be_lun->ctl_be_lun.be_lun = be_lun; 2281 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ? 2282 0 : (be_lun->size_blocks - 1); 2283 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 2284 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; 2285 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff; 2286 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp; 2287 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff; |
2274 if (be_lun->dispatch == ctl_be_block_dispatch_zvol && 2275 be_lun->blocksize != 0) 2276 be_lun->ctl_be_lun.atomicblock = CTLBLK_MAX_IO_SIZE / 2277 be_lun->blocksize; | 2288 be_lun->ctl_be_lun.atomicblock = be_lun->atomicblock; 2289 be_lun->ctl_be_lun.opttxferlen = be_lun->opttxferlen; |
2278 /* Tell the user the blocksize we ended up using */ 2279 params->lun_size_bytes = be_lun->size_bytes; 2280 params->blocksize_bytes = be_lun->blocksize; 2281 if (params->flags & CTL_LUN_FLAG_ID_REQ) { 2282 be_lun->ctl_be_lun.req_lun_id = params->req_lun_id; 2283 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_ID_REQ; 2284 } else 2285 be_lun->ctl_be_lun.req_lun_id = 0; --- 361 unchanged lines hidden (view full) --- 2647 */ 2648 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ? 2649 0 : (be_lun->size_blocks - 1); 2650 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 2651 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; 2652 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff; 2653 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp; 2654 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff; | 2290 /* Tell the user the blocksize we ended up using */ 2291 params->lun_size_bytes = be_lun->size_bytes; 2292 params->blocksize_bytes = be_lun->blocksize; 2293 if (params->flags & CTL_LUN_FLAG_ID_REQ) { 2294 be_lun->ctl_be_lun.req_lun_id = params->req_lun_id; 2295 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_ID_REQ; 2296 } else 2297 be_lun->ctl_be_lun.req_lun_id = 0; --- 361 unchanged lines hidden (view full) --- 2659 */ 2660 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ? 2661 0 : (be_lun->size_blocks - 1); 2662 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 2663 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; 2664 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff; 2665 be_lun->ctl_be_lun.ublockexp = be_lun->ublockexp; 2666 be_lun->ctl_be_lun.ublockoff = be_lun->ublockoff; |
2655 if (be_lun->dispatch == ctl_be_block_dispatch_zvol && 2656 be_lun->blocksize != 0) 2657 be_lun->ctl_be_lun.atomicblock = CTLBLK_MAX_IO_SIZE / 2658 be_lun->blocksize; | 2667 be_lun->ctl_be_lun.atomicblock = be_lun->atomicblock; 2668 be_lun->ctl_be_lun.opttxferlen = be_lun->opttxferlen; |
2659 ctl_lun_capacity_changed(&be_lun->ctl_be_lun); 2660 if (oldsize == 0 && be_lun->size_blocks != 0) 2661 ctl_lun_online(&be_lun->ctl_be_lun); 2662 } 2663 2664 /* Tell the user the exact size we ended up using */ 2665 params->lun_size_bytes = be_lun->size_bytes; 2666 --- 245 unchanged lines hidden --- | 2669 ctl_lun_capacity_changed(&be_lun->ctl_be_lun); 2670 if (oldsize == 0 && be_lun->size_blocks != 0) 2671 ctl_lun_online(&be_lun->ctl_be_lun); 2672 } 2673 2674 /* Tell the user the exact size we ended up using */ 2675 params->lun_size_bytes = be_lun->size_bytes; 2676 --- 245 unchanged lines hidden --- |