Deleted Added
full compact
ctl_backend_block.c (288259) ctl_backend_block.c (288310)
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 288259 2015-09-26 11:28:45Z mav $");
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 288310 2015-09-27 13:47:28Z 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>

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

1864 /*
1865 * For files we can use any logical block size. Prefer 512 bytes
1866 * for compatibility reasons. If file's vattr.va_blocksize
1867 * (preferred I/O block size) is bigger and multiple to chosen
1868 * logical block size -- report it as physical block size.
1869 */
1870 if (params->blocksize_bytes != 0)
1871 cbe_lun->blocksize = params->blocksize_bytes;
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>

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

1864 /*
1865 * For files we can use any logical block size. Prefer 512 bytes
1866 * for compatibility reasons. If file's vattr.va_blocksize
1867 * (preferred I/O block size) is bigger and multiple to chosen
1868 * logical block size -- report it as physical block size.
1869 */
1870 if (params->blocksize_bytes != 0)
1871 cbe_lun->blocksize = params->blocksize_bytes;
1872 else if (cbe_lun->lun_type == T_CDROM)
1873 cbe_lun->blocksize = 2048;
1872 else
1873 cbe_lun->blocksize = 512;
1874 be_lun->size_blocks = be_lun->size_bytes / cbe_lun->blocksize;
1875 cbe_lun->maxlba = (be_lun->size_blocks == 0) ?
1876 0 : (be_lun->size_blocks - 1);
1877
1878 us = ps = vattr.va_blocksize;
1879 uo = po = 0;

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

1992 return (EINVAL);
1993 }
1994 } else if (params->blocksize_bytes != 0) {
1995 dev_relthread(dev, ref);
1996 snprintf(req->error_str, sizeof(req->error_str),
1997 "requested blocksize %u < backing device "
1998 "blocksize %u", params->blocksize_bytes, tmp);
1999 return (EINVAL);
1874 else
1875 cbe_lun->blocksize = 512;
1876 be_lun->size_blocks = be_lun->size_bytes / cbe_lun->blocksize;
1877 cbe_lun->maxlba = (be_lun->size_blocks == 0) ?
1878 0 : (be_lun->size_blocks - 1);
1879
1880 us = ps = vattr.va_blocksize;
1881 uo = po = 0;

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

1994 return (EINVAL);
1995 }
1996 } else if (params->blocksize_bytes != 0) {
1997 dev_relthread(dev, ref);
1998 snprintf(req->error_str, sizeof(req->error_str),
1999 "requested blocksize %u < backing device "
2000 "blocksize %u", params->blocksize_bytes, tmp);
2001 return (EINVAL);
2000 } else
2002 } else if (cbe_lun->lun_type == T_CDROM)
2003 cbe_lun->blocksize = MAX(tmp, 2048);
2004 else
2001 cbe_lun->blocksize = tmp;
2002
2003 error = csw->d_ioctl(dev, DIOCGMEDIASIZE, (caddr_t)&otmp, FREAD,
2004 curthread);
2005 if (error) {
2006 dev_relthread(dev, ref);
2007 snprintf(req->error_str, sizeof(req->error_str),
2008 "error %d returned for DIOCGMEDIASIZE "

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

2152 "no file argument specified");
2153 return (1);
2154 }
2155 free(be_lun->dev_path, M_CTLBLK);
2156 be_lun->dev_path = strdup(value, M_CTLBLK);
2157
2158 flags = FREAD;
2159 value = ctl_get_opt(&cbe_lun->options, "readonly");
2005 cbe_lun->blocksize = tmp;
2006
2007 error = csw->d_ioctl(dev, DIOCGMEDIASIZE, (caddr_t)&otmp, FREAD,
2008 curthread);
2009 if (error) {
2010 dev_relthread(dev, ref);
2011 snprintf(req->error_str, sizeof(req->error_str),
2012 "error %d returned for DIOCGMEDIASIZE "

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

2156 "no file argument specified");
2157 return (1);
2158 }
2159 free(be_lun->dev_path, M_CTLBLK);
2160 be_lun->dev_path = strdup(value, M_CTLBLK);
2161
2162 flags = FREAD;
2163 value = ctl_get_opt(&cbe_lun->options, "readonly");
2160 if (value == NULL || strcmp(value, "on") != 0)
2164 if (value != NULL) {
2165 if (strcmp(value, "on") != 0)
2166 flags |= FWRITE;
2167 } else if (cbe_lun->lun_type == T_DIRECT)
2161 flags |= FWRITE;
2162
2163again:
2164 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, be_lun->dev_path, curthread);
2165 error = vn_open(&nd, &flags, 0, NULL);
2166 if ((error == EROFS || error == EACCES) && (flags & FWRITE)) {
2167 flags &= ~FWRITE;
2168 goto again;

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

2268 cbe_lun->flags = 0;
2269 value = ctl_get_opt(&cbe_lun->options, "ha_role");
2270 if (value != NULL) {
2271 if (strcmp(value, "primary") == 0)
2272 cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY;
2273 } else if (control_softc->flags & CTL_FLAG_ACTIVE_SHELF)
2274 cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY;
2275
2168 flags |= FWRITE;
2169
2170again:
2171 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, be_lun->dev_path, curthread);
2172 error = vn_open(&nd, &flags, 0, NULL);
2173 if ((error == EROFS || error == EACCES) && (flags & FWRITE)) {
2174 flags &= ~FWRITE;
2175 goto again;

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

2275 cbe_lun->flags = 0;
2276 value = ctl_get_opt(&cbe_lun->options, "ha_role");
2277 if (value != NULL) {
2278 if (strcmp(value, "primary") == 0)
2279 cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY;
2280 } else if (control_softc->flags & CTL_FLAG_ACTIVE_SHELF)
2281 cbe_lun->flags |= CTL_LUN_FLAG_PRIMARY;
2282
2276 if (cbe_lun->lun_type == T_DIRECT) {
2283 if (cbe_lun->lun_type == T_DIRECT ||
2284 cbe_lun->lun_type == T_CDROM) {
2277 be_lun->size_bytes = params->lun_size_bytes;
2278 if (params->blocksize_bytes != 0)
2279 cbe_lun->blocksize = params->blocksize_bytes;
2285 be_lun->size_bytes = params->lun_size_bytes;
2286 if (params->blocksize_bytes != 0)
2287 cbe_lun->blocksize = params->blocksize_bytes;
2288 else if (cbe_lun->lun_type == T_CDROM)
2289 cbe_lun->blocksize = 2048;
2280 else
2281 cbe_lun->blocksize = 512;
2282 be_lun->size_blocks = be_lun->size_bytes / cbe_lun->blocksize;
2283 cbe_lun->maxlba = (be_lun->size_blocks == 0) ?
2284 0 : (be_lun->size_blocks - 1);
2285
2286 if ((cbe_lun->flags & CTL_LUN_FLAG_PRIMARY) ||
2287 control_softc->ha_mode == CTL_HA_MODE_SER_ONLY) {

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

2756 /*retry_count*/ 0xf051);
2757 retval = CTL_RETVAL_COMPLETE;
2758 } else {
2759 ctl_set_success(&io->scsiio);
2760 }
2761 ctl_config_write_done(io);
2762 break;
2763 }
2290 else
2291 cbe_lun->blocksize = 512;
2292 be_lun->size_blocks = be_lun->size_bytes / cbe_lun->blocksize;
2293 cbe_lun->maxlba = (be_lun->size_blocks == 0) ?
2294 0 : (be_lun->size_blocks - 1);
2295
2296 if ((cbe_lun->flags & CTL_LUN_FLAG_PRIMARY) ||
2297 control_softc->ha_mode == CTL_HA_MODE_SER_ONLY) {

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

2766 /*retry_count*/ 0xf051);
2767 retval = CTL_RETVAL_COMPLETE;
2768 } else {
2769 ctl_set_success(&io->scsiio);
2770 }
2771 ctl_config_write_done(io);
2772 break;
2773 }
2774 case PREVENT_ALLOW:
2775 ctl_set_success(&io->scsiio);
2776 ctl_config_write_done(io);
2777 break;
2764 default:
2765 ctl_set_invalid_opcode(&io->scsiio);
2766 ctl_config_write_done(io);
2767 retval = CTL_RETVAL_COMPLETE;
2768 break;
2769 }
2770
2771 return (retval);

--- 92 unchanged lines hidden ---
2778 default:
2779 ctl_set_invalid_opcode(&io->scsiio);
2780 ctl_config_write_done(io);
2781 retval = CTL_RETVAL_COMPLETE;
2782 break;
2783 }
2784
2785 return (retval);

--- 92 unchanged lines hidden ---