Deleted Added
full compact
ctl_backend_block.c (271309) ctl_backend_block.c (271794)
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 271309 2014-09-09 11:38:29Z mav $");
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 271794 2014-09-18 17:25:20Z 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>

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

2273 int error;
2274 struct ctl_lun_modify_params *params;
2275
2276 params = &req->reqdata.modify;
2277
2278 if (params->lun_size_bytes != 0) {
2279 be_lun->size_bytes = params->lun_size_bytes;
2280 } else {
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>

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

2273 int error;
2274 struct ctl_lun_modify_params *params;
2275
2276 params = &req->reqdata.modify;
2277
2278 if (params->lun_size_bytes != 0) {
2279 be_lun->size_bytes = params->lun_size_bytes;
2280 } else {
2281 vn_lock(be_lun->vn, LK_SHARED | LK_RETRY);
2281 error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred);
2282 error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred);
2283 VOP_UNLOCK(be_lun->vn, 0);
2282 if (error != 0) {
2283 snprintf(req->error_str, sizeof(req->error_str),
2284 "error calling VOP_GETATTR() for file %s",
2285 be_lun->dev_path);
2286 return (error);
2287 }
2288
2289 be_lun->size_bytes = vattr.va_size;
2290 }
2291
2292 return (0);
2293}
2294
2295static int
2296ctl_be_block_modify_dev(struct ctl_be_block_lun *be_lun,
2297 struct ctl_lun_req *req)
2298{
2284 if (error != 0) {
2285 snprintf(req->error_str, sizeof(req->error_str),
2286 "error calling VOP_GETATTR() for file %s",
2287 be_lun->dev_path);
2288 return (error);
2289 }
2290
2291 be_lun->size_bytes = vattr.va_size;
2292 }
2293
2294 return (0);
2295}
2296
2297static int
2298ctl_be_block_modify_dev(struct ctl_be_block_lun *be_lun,
2299 struct ctl_lun_req *req)
2300{
2299 struct cdev *dev;
2300 struct cdevsw *devsw;
2301 struct ctl_be_block_devdata *dev_data;
2301 int error;
2302 struct ctl_lun_modify_params *params;
2303 uint64_t size_bytes;
2304
2305 params = &req->reqdata.modify;
2306
2302 int error;
2303 struct ctl_lun_modify_params *params;
2304 uint64_t size_bytes;
2305
2306 params = &req->reqdata.modify;
2307
2307 dev = be_lun->vn->v_rdev;
2308 devsw = dev->si_devsw;
2309 if (!devsw->d_ioctl) {
2308 dev_data = &be_lun->backend.dev;
2309 if (!dev_data->csw->d_ioctl) {
2310 snprintf(req->error_str, sizeof(req->error_str),
2311 "%s: no d_ioctl for device %s!", __func__,
2312 be_lun->dev_path);
2313 return (ENODEV);
2314 }
2315
2310 snprintf(req->error_str, sizeof(req->error_str),
2311 "%s: no d_ioctl for device %s!", __func__,
2312 be_lun->dev_path);
2313 return (ENODEV);
2314 }
2315
2316 error = devsw->d_ioctl(dev, DIOCGMEDIASIZE,
2316 error = dev_data->csw->d_ioctl(dev_data->cdev, DIOCGMEDIASIZE,
2317 (caddr_t)&size_bytes, FREAD,
2318 curthread);
2319 if (error) {
2320 snprintf(req->error_str, sizeof(req->error_str),
2321 "%s: error %d returned for DIOCGMEDIASIZE ioctl "
2322 "on %s!", __func__, error, be_lun->dev_path);
2323 return (error);
2324 }

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

2341 return (0);
2342}
2343
2344static int
2345ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
2346{
2347 struct ctl_lun_modify_params *params;
2348 struct ctl_be_block_lun *be_lun;
2317 (caddr_t)&size_bytes, FREAD,
2318 curthread);
2319 if (error) {
2320 snprintf(req->error_str, sizeof(req->error_str),
2321 "%s: error %d returned for DIOCGMEDIASIZE ioctl "
2322 "on %s!", __func__, error, be_lun->dev_path);
2323 return (error);
2324 }

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

2341 return (0);
2342}
2343
2344static int
2345ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
2346{
2347 struct ctl_lun_modify_params *params;
2348 struct ctl_be_block_lun *be_lun;
2349 uint64_t oldsize;
2349 int error;
2350
2351 params = &req->reqdata.modify;
2352
2353 mtx_lock(&softc->lock);
2354
2355 be_lun = NULL;
2356

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

2371 if (params->lun_size_bytes < be_lun->blocksize) {
2372 snprintf(req->error_str, sizeof(req->error_str),
2373 "%s: LUN size %ju < blocksize %u", __func__,
2374 params->lun_size_bytes, be_lun->blocksize);
2375 goto bailout_error;
2376 }
2377 }
2378
2350 int error;
2351
2352 params = &req->reqdata.modify;
2353
2354 mtx_lock(&softc->lock);
2355
2356 be_lun = NULL;
2357

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

2372 if (params->lun_size_bytes < be_lun->blocksize) {
2373 snprintf(req->error_str, sizeof(req->error_str),
2374 "%s: LUN size %ju < blocksize %u", __func__,
2375 params->lun_size_bytes, be_lun->blocksize);
2376 goto bailout_error;
2377 }
2378 }
2379
2379 vn_lock(be_lun->vn, LK_SHARED | LK_RETRY);
2380
2380 oldsize = be_lun->size_bytes;
2381 if (be_lun->vn->v_type == VREG)
2382 error = ctl_be_block_modify_file(be_lun, req);
2383 else
2384 error = ctl_be_block_modify_dev(be_lun, req);
2381 if (be_lun->vn->v_type == VREG)
2382 error = ctl_be_block_modify_file(be_lun, req);
2383 else
2384 error = ctl_be_block_modify_dev(be_lun, req);
2385
2386 VOP_UNLOCK(be_lun->vn, 0);
2387
2388 if (error != 0)
2389 goto bailout_error;
2390
2385 if (error != 0)
2386 goto bailout_error;
2387
2391 be_lun->size_blocks = be_lun->size_bytes >> be_lun->blocksize_shift;
2388 if (be_lun->size_bytes != oldsize) {
2389 be_lun->size_blocks = be_lun->size_bytes >>
2390 be_lun->blocksize_shift;
2392
2391
2393 /*
2394 * The maximum LBA is the size - 1.
2395 *
2396 * XXX: Note that this field is being updated without locking,
2397 * which might cause problems on 32-bit architectures.
2398 */
2399 be_lun->ctl_be_lun.maxlba = be_lun->size_blocks - 1;
2400 ctl_lun_capacity_changed(&be_lun->ctl_be_lun);
2392 /*
2393 * The maximum LBA is the size - 1.
2394 *
2395 * XXX: Note that this field is being updated without locking,
2396 * which might cause problems on 32-bit architectures.
2397 */
2398 be_lun->ctl_be_lun.maxlba = be_lun->size_blocks - 1;
2399 ctl_lun_capacity_changed(&be_lun->ctl_be_lun);
2400 }
2401
2402 /* Tell the user the exact size we ended up using */
2403 params->lun_size_bytes = be_lun->size_bytes;
2404
2405 req->status = CTL_LUN_OK;
2406
2407 return (0);
2408

--- 194 unchanged lines hidden ---
2401
2402 /* Tell the user the exact size we ended up using */
2403 params->lun_size_bytes = be_lun->size_bytes;
2404
2405 req->status = CTL_LUN_OK;
2406
2407 return (0);
2408

--- 194 unchanged lines hidden ---