blkback.c (231883) | blkback.c (241896) |
---|---|
1/*- 2 * Copyright (c) 2009-2011 Spectra Logic Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGES. 29 * 30 * Authors: Justin T. Gibbs (Spectra Logic Corporation) 31 * Ken Merry (Spectra Logic Corporation) 32 */ 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009-2011 Spectra Logic Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGES. 29 * 30 * Authors: Justin T. Gibbs (Spectra Logic Corporation) 31 * Ken Merry (Spectra Logic Corporation) 32 */ 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/xen/blkback/blkback.c 231883 2012-02-17 22:33:46Z gibbs $"); | 34__FBSDID("$FreeBSD: head/sys/dev/xen/blkback/blkback.c 241896 2012-10-22 17:50:54Z kib $"); |
35 36/** 37 * \file blkback.c 38 * 39 * \brief Device driver supporting the vending of block storage from 40 * a FreeBSD domain to other domains. 41 */ 42 --- 2202 unchanged lines hidden (view full) --- 2245 off_t sectors_sent; 2246 struct uio xuio; 2247 struct xbb_sg *xbb_sg; 2248 struct iovec *xiovec; 2249#ifdef XBB_USE_BOUNCE_BUFFERS 2250 void **p_vaddr; 2251 int saved_uio_iovcnt; 2252#endif /* XBB_USE_BOUNCE_BUFFERS */ | 35 36/** 37 * \file blkback.c 38 * 39 * \brief Device driver supporting the vending of block storage from 40 * a FreeBSD domain to other domains. 41 */ 42 --- 2202 unchanged lines hidden (view full) --- 2245 off_t sectors_sent; 2246 struct uio xuio; 2247 struct xbb_sg *xbb_sg; 2248 struct iovec *xiovec; 2249#ifdef XBB_USE_BOUNCE_BUFFERS 2250 void **p_vaddr; 2251 int saved_uio_iovcnt; 2252#endif /* XBB_USE_BOUNCE_BUFFERS */ |
2253 int vfs_is_locked; | |
2254 int error; 2255 2256 file_data = &xbb->backend.file; 2257 sectors_sent = 0; 2258 error = 0; 2259 bzero(&xuio, sizeof(xuio)); 2260 2261 switch (operation) { --- 4 unchanged lines hidden (view full) --- 2266 xuio.uio_rw = UIO_WRITE; 2267 break; 2268 case BIO_FLUSH: { 2269 struct mount *mountpoint; 2270 2271 SDT_PROBE1(xbb, kernel, xbb_dispatch_file, flush, 2272 device_get_unit(xbb->dev)); 2273 | 2253 int error; 2254 2255 file_data = &xbb->backend.file; 2256 sectors_sent = 0; 2257 error = 0; 2258 bzero(&xuio, sizeof(xuio)); 2259 2260 switch (operation) { --- 4 unchanged lines hidden (view full) --- 2265 xuio.uio_rw = UIO_WRITE; 2266 break; 2267 case BIO_FLUSH: { 2268 struct mount *mountpoint; 2269 2270 SDT_PROBE1(xbb, kernel, xbb_dispatch_file, flush, 2271 device_get_unit(xbb->dev)); 2272 |
2274 vfs_is_locked = VFS_LOCK_GIANT(xbb->vn->v_mount); 2275 | |
2276 (void) vn_start_write(xbb->vn, &mountpoint, V_WAIT); 2277 2278 vn_lock(xbb->vn, LK_EXCLUSIVE | LK_RETRY); 2279 error = VOP_FSYNC(xbb->vn, MNT_WAIT, curthread); 2280 VOP_UNLOCK(xbb->vn, 0); 2281 2282 vn_finished_write(mountpoint); 2283 | 2273 (void) vn_start_write(xbb->vn, &mountpoint, V_WAIT); 2274 2275 vn_lock(xbb->vn, LK_EXCLUSIVE | LK_RETRY); 2276 error = VOP_FSYNC(xbb->vn, MNT_WAIT, curthread); 2277 VOP_UNLOCK(xbb->vn, 0); 2278 2279 vn_finished_write(mountpoint); 2280 |
2284 VFS_UNLOCK_GIANT(vfs_is_locked); 2285 | |
2286 goto bailout_send_response; 2287 /* NOTREACHED */ 2288 } 2289 default: 2290 panic("invalid operation %d", operation); 2291 /* NOTREACHED */ 2292 } 2293 xuio.uio_offset = (vm_offset_t)reqlist->starting_sector_number --- 67 unchanged lines hidden (view full) --- 2361 * VOP_READ(). (The uio will get modified in that call 2362 * sequence.) 2363 */ 2364 memcpy(file_data->saved_xiovecs, xuio.uio_iov, 2365 xuio.uio_iovcnt * sizeof(xuio.uio_iov[0])); 2366 } 2367#endif /* XBB_USE_BOUNCE_BUFFERS */ 2368 | 2281 goto bailout_send_response; 2282 /* NOTREACHED */ 2283 } 2284 default: 2285 panic("invalid operation %d", operation); 2286 /* NOTREACHED */ 2287 } 2288 xuio.uio_offset = (vm_offset_t)reqlist->starting_sector_number --- 67 unchanged lines hidden (view full) --- 2356 * VOP_READ(). (The uio will get modified in that call 2357 * sequence.) 2358 */ 2359 memcpy(file_data->saved_xiovecs, xuio.uio_iov, 2360 xuio.uio_iovcnt * sizeof(xuio.uio_iov[0])); 2361 } 2362#endif /* XBB_USE_BOUNCE_BUFFERS */ 2363 |
2369 vfs_is_locked = VFS_LOCK_GIANT(xbb->vn->v_mount); | |
2370 switch (operation) { 2371 case BIO_READ: 2372 2373 SDT_PROBE3(xbb, kernel, xbb_dispatch_file, read, 2374 device_get_unit(xbb->dev), xuio.uio_offset, 2375 xuio.uio_resid); 2376 2377 vn_lock(xbb->vn, LK_EXCLUSIVE | LK_RETRY); --- 59 unchanged lines hidden (view full) --- 2437 vn_finished_write(mountpoint); 2438 2439 break; 2440 } 2441 default: 2442 panic("invalid operation %d", operation); 2443 /* NOTREACHED */ 2444 } | 2364 switch (operation) { 2365 case BIO_READ: 2366 2367 SDT_PROBE3(xbb, kernel, xbb_dispatch_file, read, 2368 device_get_unit(xbb->dev), xuio.uio_offset, 2369 xuio.uio_resid); 2370 2371 vn_lock(xbb->vn, LK_EXCLUSIVE | LK_RETRY); --- 59 unchanged lines hidden (view full) --- 2431 vn_finished_write(mountpoint); 2432 2433 break; 2434 } 2435 default: 2436 panic("invalid operation %d", operation); 2437 /* NOTREACHED */ 2438 } |
2445 VFS_UNLOCK_GIANT(vfs_is_locked); | |
2446 2447#ifdef XBB_USE_BOUNCE_BUFFERS 2448 /* We only need to copy here for read operations */ 2449 if (operation == BIO_READ) { 2450 2451 for (seg_idx = 0, p_vaddr = file_data->xiovecs_vaddr, 2452 xiovec = file_data->saved_xiovecs; 2453 seg_idx < saved_uio_iovcnt; seg_idx++, --- 30 unchanged lines hidden (view full) --- 2484 */ 2485static void 2486xbb_close_backend(struct xbb_softc *xbb) 2487{ 2488 DROP_GIANT(); 2489 DPRINTF("closing dev=%s\n", xbb->dev_name); 2490 if (xbb->vn) { 2491 int flags = FREAD; | 2439 2440#ifdef XBB_USE_BOUNCE_BUFFERS 2441 /* We only need to copy here for read operations */ 2442 if (operation == BIO_READ) { 2443 2444 for (seg_idx = 0, p_vaddr = file_data->xiovecs_vaddr, 2445 xiovec = file_data->saved_xiovecs; 2446 seg_idx < saved_uio_iovcnt; seg_idx++, --- 30 unchanged lines hidden (view full) --- 2477 */ 2478static void 2479xbb_close_backend(struct xbb_softc *xbb) 2480{ 2481 DROP_GIANT(); 2482 DPRINTF("closing dev=%s\n", xbb->dev_name); 2483 if (xbb->vn) { 2484 int flags = FREAD; |
2492 int vfs_is_locked = 0; | |
2493 2494 if ((xbb->flags & XBBF_READ_ONLY) == 0) 2495 flags |= FWRITE; 2496 2497 switch (xbb->device_type) { 2498 case XBB_TYPE_DISK: 2499 if (xbb->backend.dev.csw) { 2500 dev_relthread(xbb->backend.dev.cdev, 2501 xbb->backend.dev.dev_ref); 2502 xbb->backend.dev.csw = NULL; 2503 xbb->backend.dev.cdev = NULL; 2504 } 2505 break; 2506 case XBB_TYPE_FILE: | 2485 2486 if ((xbb->flags & XBBF_READ_ONLY) == 0) 2487 flags |= FWRITE; 2488 2489 switch (xbb->device_type) { 2490 case XBB_TYPE_DISK: 2491 if (xbb->backend.dev.csw) { 2492 dev_relthread(xbb->backend.dev.cdev, 2493 xbb->backend.dev.dev_ref); 2494 xbb->backend.dev.csw = NULL; 2495 xbb->backend.dev.cdev = NULL; 2496 } 2497 break; 2498 case XBB_TYPE_FILE: |
2507 vfs_is_locked = VFS_LOCK_GIANT(xbb->vn->v_mount); | |
2508 break; 2509 case XBB_TYPE_NONE: 2510 default: 2511 panic("Unexpected backend type."); 2512 break; 2513 } 2514 2515 (void)vn_close(xbb->vn, flags, NOCRED, curthread); 2516 xbb->vn = NULL; 2517 2518 switch (xbb->device_type) { 2519 case XBB_TYPE_DISK: 2520 break; 2521 case XBB_TYPE_FILE: | 2499 break; 2500 case XBB_TYPE_NONE: 2501 default: 2502 panic("Unexpected backend type."); 2503 break; 2504 } 2505 2506 (void)vn_close(xbb->vn, flags, NOCRED, curthread); 2507 xbb->vn = NULL; 2508 2509 switch (xbb->device_type) { 2510 case XBB_TYPE_DISK: 2511 break; 2512 case XBB_TYPE_FILE: |
2522 VFS_UNLOCK_GIANT(vfs_is_locked); | |
2523 if (xbb->backend.file.cred != NULL) { 2524 crfree(xbb->backend.file.cred); 2525 xbb->backend.file.cred = NULL; 2526 } 2527 break; 2528 case XBB_TYPE_NONE: 2529 default: 2530 panic("Unexpected backend type."); --- 148 unchanged lines hidden (view full) --- 2679 * \return 0 for success, errno codes for failure. 2680 */ 2681static int 2682xbb_open_backend(struct xbb_softc *xbb) 2683{ 2684 struct nameidata nd; 2685 int flags; 2686 int error; | 2513 if (xbb->backend.file.cred != NULL) { 2514 crfree(xbb->backend.file.cred); 2515 xbb->backend.file.cred = NULL; 2516 } 2517 break; 2518 case XBB_TYPE_NONE: 2519 default: 2520 panic("Unexpected backend type."); --- 148 unchanged lines hidden (view full) --- 2669 * \return 0 for success, errno codes for failure. 2670 */ 2671static int 2672xbb_open_backend(struct xbb_softc *xbb) 2673{ 2674 struct nameidata nd; 2675 int flags; 2676 int error; |
2687 int vfs_is_locked; | |
2688 2689 flags = FREAD; 2690 error = 0; 2691 2692 DPRINTF("opening dev=%s\n", xbb->dev_name); 2693 2694 if (rootvnode == NULL) { 2695 xenbus_dev_fatal(xbb->dev, ENOENT, --- 43 unchanged lines hidden (view full) --- 2739 goto again; 2740 } 2741 } 2742 xenbus_dev_fatal(xbb->dev, error, "error opening device %s", 2743 xbb->dev_name); 2744 return (error); 2745 } 2746 | 2677 2678 flags = FREAD; 2679 error = 0; 2680 2681 DPRINTF("opening dev=%s\n", xbb->dev_name); 2682 2683 if (rootvnode == NULL) { 2684 xenbus_dev_fatal(xbb->dev, ENOENT, --- 43 unchanged lines hidden (view full) --- 2728 goto again; 2729 } 2730 } 2731 xenbus_dev_fatal(xbb->dev, error, "error opening device %s", 2732 xbb->dev_name); 2733 return (error); 2734 } 2735 |
2747 vfs_is_locked = NDHASGIANT(&nd); 2748 | |
2749 NDFREE(&nd, NDF_ONLY_PNBUF); 2750 2751 xbb->vn = nd.ni_vp; 2752 2753 /* We only support disks and files. */ 2754 if (vn_isdisk(xbb->vn, &error)) { 2755 error = xbb_open_dev(xbb); 2756 } else if (xbb->vn->v_type == VREG) { 2757 error = xbb_open_file(xbb); 2758 } else { 2759 error = EINVAL; 2760 xenbus_dev_fatal(xbb->dev, error, "%s is not a disk " 2761 "or file", xbb->dev_name); 2762 } 2763 VOP_UNLOCK(xbb->vn, 0); | 2736 NDFREE(&nd, NDF_ONLY_PNBUF); 2737 2738 xbb->vn = nd.ni_vp; 2739 2740 /* We only support disks and files. */ 2741 if (vn_isdisk(xbb->vn, &error)) { 2742 error = xbb_open_dev(xbb); 2743 } else if (xbb->vn->v_type == VREG) { 2744 error = xbb_open_file(xbb); 2745 } else { 2746 error = EINVAL; 2747 xenbus_dev_fatal(xbb->dev, error, "%s is not a disk " 2748 "or file", xbb->dev_name); 2749 } 2750 VOP_UNLOCK(xbb->vn, 0); |
2764 VFS_UNLOCK_GIANT(vfs_is_locked); | |
2765 2766 if (error != 0) { 2767 xbb_close_backend(xbb); 2768 return (error); 2769 } 2770 2771 xbb->sector_size_shift = fls(xbb->sector_size) - 1; 2772 xbb->media_num_sectors = xbb->media_size >> xbb->sector_size_shift; --- 1223 unchanged lines hidden --- | 2751 2752 if (error != 0) { 2753 xbb_close_backend(xbb); 2754 return (error); 2755 } 2756 2757 xbb->sector_size_shift = fls(xbb->sector_size) - 1; 2758 xbb->media_num_sectors = xbb->media_size >> xbb->sector_size_shift; --- 1223 unchanged lines hidden --- |