ctl_backend_block.c (275568) | ctl_backend_block.c (275865) |
---|---|
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 275568 2014-12-06 20:39:25Z mav $"); | 43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 275865 2014-12-17 17:30:54Z 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> --- 116 unchanged lines hidden (view full) --- 168 cbb_getattr_t getattr; 169 uma_zone_t lun_zone; 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; | 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> --- 116 unchanged lines hidden (view full) --- 168 cbb_getattr_t getattr; 169 uma_zone_t lun_zone; 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; |
|
176 struct ctl_be_block_softc *softc; 177 struct devstat *disk_stats; 178 ctl_be_block_lun_flags flags; 179 STAILQ_ENTRY(ctl_be_block_lun) links; 180 struct ctl_be_lun ctl_be_lun; 181 struct taskqueue *io_taskqueue; 182 struct task io_task; 183 int num_threads; --- 1550 unchanged lines hidden (view full) --- 1734 return (error); 1735} 1736 1737static int 1738ctl_be_block_open_file(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req) 1739{ 1740 struct ctl_be_block_filedata *file_data; 1741 struct ctl_lun_create_params *params; | 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; --- 1550 unchanged lines hidden (view full) --- 1736 return (error); 1737} 1738 1739static int 1740ctl_be_block_open_file(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req) 1741{ 1742 struct ctl_be_block_filedata *file_data; 1743 struct ctl_lun_create_params *params; |
1744 char *value; |
|
1742 struct vattr vattr; | 1745 struct vattr vattr; |
1743 off_t pss; | 1746 off_t ps, pss, po, pos, us, uss, uo, uos; |
1744 int error; 1745 1746 error = 0; 1747 file_data = &be_lun->backend.file; 1748 params = &be_lun->params; 1749 1750 be_lun->dev_type = CTL_BE_BLOCK_FILE; 1751 be_lun->dispatch = ctl_be_block_dispatch_file; --- 43 unchanged lines hidden (view full) --- 1795 * for compatibility reasons. If file's vattr.va_blocksize 1796 * (preferred I/O block size) is bigger and multiple to chosen 1797 * logical block size -- report it as physical block size. 1798 */ 1799 if (params->blocksize_bytes != 0) 1800 be_lun->blocksize = params->blocksize_bytes; 1801 else 1802 be_lun->blocksize = 512; | 1747 int error; 1748 1749 error = 0; 1750 file_data = &be_lun->backend.file; 1751 params = &be_lun->params; 1752 1753 be_lun->dev_type = CTL_BE_BLOCK_FILE; 1754 be_lun->dispatch = ctl_be_block_dispatch_file; --- 43 unchanged lines hidden (view full) --- 1798 * for compatibility reasons. If file's vattr.va_blocksize 1799 * (preferred I/O block size) is bigger and multiple to chosen 1800 * logical block size -- report it as physical block size. 1801 */ 1802 if (params->blocksize_bytes != 0) 1803 be_lun->blocksize = params->blocksize_bytes; 1804 else 1805 be_lun->blocksize = 512; |
1803 pss = vattr.va_blocksize / be_lun->blocksize; 1804 if ((pss > 0) && (pss * be_lun->blocksize == vattr.va_blocksize) && 1805 ((pss & (pss - 1)) == 0)) { | 1806 1807 us = ps = vattr.va_blocksize; 1808 uo = po = 0; 1809 1810 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "pblocksize"); 1811 if (value != NULL) 1812 ctl_expand_number(value, &ps); 1813 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "pblockoffset"); 1814 if (value != NULL) 1815 ctl_expand_number(value, &po); 1816 pss = ps / be_lun->blocksize; 1817 pos = po / be_lun->blocksize; 1818 if ((pss > 0) && (pss * be_lun->blocksize == ps) && (pss >= pos) && 1819 ((pss & (pss - 1)) == 0) && (pos * be_lun->blocksize == po)) { |
1806 be_lun->pblockexp = fls(pss) - 1; | 1820 be_lun->pblockexp = fls(pss) - 1; |
1807 be_lun->pblockoff = 0; | 1821 be_lun->pblockoff = (pss - pos) % pss; |
1808 } 1809 | 1822 } 1823 |
1824 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "ublocksize"); 1825 if (value != NULL) 1826 ctl_expand_number(value, &us); 1827 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "ublockoffset"); 1828 if (value != NULL) 1829 ctl_expand_number(value, &uo); 1830 uss = us / be_lun->blocksize; 1831 uos = uo / be_lun->blocksize; 1832 if ((uss > 0) && (uss * be_lun->blocksize == us) && (uss >= uos) && 1833 ((uss & (uss - 1)) == 0) && (uos * be_lun->blocksize == uo)) { 1834 be_lun->ublockexp = fls(uss) - 1; 1835 be_lun->ublockoff = (uss - uos) % uss; 1836 } 1837 |
|
1810 /* 1811 * Sanity check. The media size has to be at least one 1812 * sector long. 1813 */ 1814 if (be_lun->size_bytes < be_lun->blocksize) { 1815 error = EINVAL; 1816 snprintf(req->error_str, sizeof(req->error_str), 1817 "file %s size %ju < block size %u", be_lun->dev_path, --- 4 unchanged lines hidden (view full) --- 1822 1823static int 1824ctl_be_block_open_dev(struct ctl_be_block_lun *be_lun, struct ctl_lun_req *req) 1825{ 1826 struct ctl_lun_create_params *params; 1827 struct vattr vattr; 1828 struct cdev *dev; 1829 struct cdevsw *devsw; | 1838 /* 1839 * Sanity check. The media size has to be at least one 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, --- 4 unchanged lines hidden (view full) --- 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; |
|
1830 int error; | 1859 int error; |
1831 off_t ps, pss, po, pos; | 1860 off_t ps, pss, po, pos, us, uss, uo, uos; |
1832 1833 params = &be_lun->params; 1834 1835 be_lun->dev_type = CTL_BE_BLOCK_DEV; 1836 be_lun->backend.dev.cdev = be_lun->vn->v_rdev; 1837 be_lun->backend.dev.csw = dev_refthread(be_lun->backend.dev.cdev, 1838 &be_lun->backend.dev.dev_ref); 1839 if (be_lun->backend.dev.csw == NULL) --- 97 unchanged lines hidden (view full) --- 1937 if (error) 1938 ps = po = 0; 1939 else { 1940 error = devsw->d_ioctl(dev, DIOCGSTRIPEOFFSET, 1941 (caddr_t)&po, FREAD, curthread); 1942 if (error) 1943 po = 0; 1944 } | 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) --- 97 unchanged lines hidden (view full) --- 1966 if (error) 1967 ps = po = 0; 1968 else { 1969 error = devsw->d_ioctl(dev, DIOCGSTRIPEOFFSET, 1970 (caddr_t)&po, FREAD, curthread); 1971 if (error) 1972 po = 0; 1973 } |
1974 us = ps; 1975 uo = po; 1976 1977 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "pblocksize"); 1978 if (value != NULL) 1979 ctl_expand_number(value, &ps); 1980 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "pblockoffset"); 1981 if (value != NULL) 1982 ctl_expand_number(value, &po); |
|
1945 pss = ps / be_lun->blocksize; 1946 pos = po / be_lun->blocksize; 1947 if ((pss > 0) && (pss * be_lun->blocksize == ps) && (pss >= pos) && 1948 ((pss & (pss - 1)) == 0) && (pos * be_lun->blocksize == po)) { 1949 be_lun->pblockexp = fls(pss) - 1; 1950 be_lun->pblockoff = (pss - pos) % pss; 1951 } 1952 | 1983 pss = ps / be_lun->blocksize; 1984 pos = po / be_lun->blocksize; 1985 if ((pss > 0) && (pss * be_lun->blocksize == ps) && (pss >= pos) && 1986 ((pss & (pss - 1)) == 0) && (pos * be_lun->blocksize == po)) { 1987 be_lun->pblockexp = fls(pss) - 1; 1988 be_lun->pblockoff = (pss - pos) % pss; 1989 } 1990 |
1991 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "ublocksize"); 1992 if (value != NULL) 1993 ctl_expand_number(value, &us); 1994 value = ctl_get_opt(&be_lun->ctl_be_lun.options, "ublockoffset"); 1995 if (value != NULL) 1996 ctl_expand_number(value, &uo); 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 |
|
1953 return (0); 1954} 1955 1956static int 1957ctl_be_block_close(struct ctl_be_block_lun *be_lun) 1958{ 1959 DROP_GIANT(); 1960 if (be_lun->vn) { --- 196 unchanged lines hidden (view full) --- 2157 } 2158 } else { 2159 /* 2160 * For processor devices, we don't have any size. 2161 */ 2162 be_lun->blocksize = 0; 2163 be_lun->pblockexp = 0; 2164 be_lun->pblockoff = 0; | 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) { --- 196 unchanged lines hidden (view full) --- 2209 } 2210 } else { 2211 /* 2212 * For processor devices, we don't have any size. 2213 */ 2214 be_lun->blocksize = 0; 2215 be_lun->pblockexp = 0; 2216 be_lun->pblockoff = 0; |
2217 be_lun->ublockexp = 0; 2218 be_lun->ublockoff = 0; |
|
2165 be_lun->size_blocks = 0; 2166 be_lun->size_bytes = 0; 2167 be_lun->ctl_be_lun.maxlba = 0; 2168 2169 /* 2170 * Default to just 1 thread for processor devices. 2171 */ 2172 num_threads = 1; --- 34 unchanged lines hidden (view full) --- 2207 if (be_lun->dispatch != ctl_be_block_dispatch_dev) 2208 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_SERSEQ_READ; 2209 be_lun->ctl_be_lun.be_lun = be_lun; 2210 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ? 2211 0 : (be_lun->size_blocks - 1); 2212 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 2213 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; 2214 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff; | 2219 be_lun->size_blocks = 0; 2220 be_lun->size_bytes = 0; 2221 be_lun->ctl_be_lun.maxlba = 0; 2222 2223 /* 2224 * Default to just 1 thread for processor devices. 2225 */ 2226 num_threads = 1; --- 34 unchanged lines hidden (view full) --- 2261 if (be_lun->dispatch != ctl_be_block_dispatch_dev) 2262 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_SERSEQ_READ; 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; |
|
2215 if (be_lun->dispatch == ctl_be_block_dispatch_zvol && 2216 be_lun->blocksize != 0) 2217 be_lun->ctl_be_lun.atomicblock = CTLBLK_MAX_IO_SIZE / 2218 be_lun->blocksize; 2219 /* Tell the user the blocksize we ended up using */ 2220 params->lun_size_bytes = be_lun->size_bytes; 2221 params->blocksize_bytes = be_lun->blocksize; 2222 if (params->flags & CTL_LUN_FLAG_ID_REQ) { --- 363 unchanged lines hidden (view full) --- 2586 * XXX: Note that this field is being updated without locking, 2587 * which might cause problems on 32-bit architectures. 2588 */ 2589 be_lun->ctl_be_lun.maxlba = (be_lun->size_blocks == 0) ? 2590 0 : (be_lun->size_blocks - 1); 2591 be_lun->ctl_be_lun.blocksize = be_lun->blocksize; 2592 be_lun->ctl_be_lun.pblockexp = be_lun->pblockexp; 2593 be_lun->ctl_be_lun.pblockoff = be_lun->pblockoff; | 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; 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) { --- 363 unchanged lines hidden (view full) --- 2642 * XXX: Note that this field is being updated without locking, 2643 * which might cause problems on 32-bit architectures. 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; |
|
2594 if (be_lun->dispatch == ctl_be_block_dispatch_zvol && 2595 be_lun->blocksize != 0) 2596 be_lun->ctl_be_lun.atomicblock = CTLBLK_MAX_IO_SIZE / 2597 be_lun->blocksize; 2598 ctl_lun_capacity_changed(&be_lun->ctl_be_lun); 2599 if (oldsize == 0 && be_lun->size_blocks != 0) 2600 ctl_lun_online(&be_lun->ctl_be_lun); 2601 } --- 249 unchanged lines hidden --- | 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; 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 } --- 249 unchanged lines hidden --- |