Deleted Added
full compact
ctl_backend_block.c (288215) ctl_backend_block.c (288220)
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 288215 2015-09-25 10:14:39Z mav $");
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 288220 2015-09-25 16:34:59Z 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>

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

458 * At this point, we have a write and the DMA completed
459 * successfully. We now have to queue it to the task queue to
460 * execute the backend I/O. That is because we do blocking
461 * memory allocations, and in the file backing case, blocking I/O.
462 * This move done routine is generally called in the SIM's
463 * interrupt context, and therefore we cannot block.
464 */
465 mtx_lock(&be_lun->queue_lock);
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>

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

458 * At this point, we have a write and the DMA completed
459 * successfully. We now have to queue it to the task queue to
460 * execute the backend I/O. That is because we do blocking
461 * memory allocations, and in the file backing case, blocking I/O.
462 * This move done routine is generally called in the SIM's
463 * interrupt context, and therefore we cannot block.
464 */
465 mtx_lock(&be_lun->queue_lock);
466 /*
467 * XXX KDM make sure that links is okay to use at this point.
468 * Otherwise, we either need to add another field to ctl_io_hdr,
469 * or deal with resource allocation here.
470 */
471 STAILQ_INSERT_TAIL(&be_lun->datamove_queue, &io->io_hdr, links);
472 mtx_unlock(&be_lun->queue_lock);
466 STAILQ_INSERT_TAIL(&be_lun->datamove_queue, &io->io_hdr, links);
467 mtx_unlock(&be_lun->queue_lock);
473
474 taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task);
475
476 return (0);
477}
478
479static void
480ctl_be_block_biodone(struct bio *bio)
481{

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

581
582 binuptime(&beio->ds_t0);
583 mtx_lock(&be_lun->io_lock);
584 devstat_start_transaction(beio->lun->disk_stats, &beio->ds_t0);
585 mtx_unlock(&be_lun->io_lock);
586
587 (void) vn_start_write(be_lun->vn, &mountpoint, V_WAIT);
588
468 taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task);
469
470 return (0);
471}
472
473static void
474ctl_be_block_biodone(struct bio *bio)
475{

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

575
576 binuptime(&beio->ds_t0);
577 mtx_lock(&be_lun->io_lock);
578 devstat_start_transaction(beio->lun->disk_stats, &beio->ds_t0);
579 mtx_unlock(&be_lun->io_lock);
580
581 (void) vn_start_write(be_lun->vn, &mountpoint, V_WAIT);
582
589 if (MNT_SHARED_WRITES(mountpoint)
590 || ((mountpoint == NULL)
591 && MNT_SHARED_WRITES(be_lun->vn->v_mount)))
583 if (MNT_SHARED_WRITES(mountpoint) ||
584 ((mountpoint == NULL) && MNT_SHARED_WRITES(be_lun->vn->v_mount)))
592 lock_flags = LK_SHARED;
593 else
594 lock_flags = LK_EXCLUSIVE;
585 lock_flags = LK_SHARED;
586 else
587 lock_flags = LK_EXCLUSIVE;
595
596 vn_lock(be_lun->vn, lock_flags | LK_RETRY);
588 vn_lock(be_lun->vn, lock_flags | LK_RETRY);
597
598 error = VOP_FSYNC(be_lun->vn, beio->io_arg ? MNT_NOWAIT : MNT_WAIT,
599 curthread);
600 VOP_UNLOCK(be_lun->vn, 0);
601
602 vn_finished_write(mountpoint);
603
604 mtx_lock(&be_lun->io_lock);
605 devstat_end_transaction(beio->lun->disk_stats, beio->io_len,

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

711 }
712 }
713 } else {
714 struct mount *mountpoint;
715 int lock_flags;
716
717 (void)vn_start_write(be_lun->vn, &mountpoint, V_WAIT);
718
589 error = VOP_FSYNC(be_lun->vn, beio->io_arg ? MNT_NOWAIT : MNT_WAIT,
590 curthread);
591 VOP_UNLOCK(be_lun->vn, 0);
592
593 vn_finished_write(mountpoint);
594
595 mtx_lock(&be_lun->io_lock);
596 devstat_end_transaction(beio->lun->disk_stats, beio->io_len,

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

702 }
703 }
704 } else {
705 struct mount *mountpoint;
706 int lock_flags;
707
708 (void)vn_start_write(be_lun->vn, &mountpoint, V_WAIT);
709
719 if (MNT_SHARED_WRITES(mountpoint)
720 || ((mountpoint == NULL)
710 if (MNT_SHARED_WRITES(mountpoint) || ((mountpoint == NULL)
721 && MNT_SHARED_WRITES(be_lun->vn->v_mount)))
722 lock_flags = LK_SHARED;
723 else
724 lock_flags = LK_EXCLUSIVE;
711 && MNT_SHARED_WRITES(be_lun->vn->v_mount)))
712 lock_flags = LK_SHARED;
713 else
714 lock_flags = LK_EXCLUSIVE;
725
726 vn_lock(be_lun->vn, lock_flags | LK_RETRY);
727
728 /*
729 * UFS pays attention to IO_DIRECT for writes. The write
730 * is done asynchronously. (Normally the write would just
731 * get put into cache.
732 *
733 * UFS pays attention to IO_SYNC for writes. It will

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

1535 ctl_data_submit_done(io);
1536 return;
1537 }
1538
1539 io->io_hdr.status &= ~CTL_STATUS_MASK;
1540 io->io_hdr.status |= CTL_STATUS_NONE;
1541
1542 mtx_lock(&be_lun->queue_lock);
715 vn_lock(be_lun->vn, lock_flags | LK_RETRY);
716
717 /*
718 * UFS pays attention to IO_DIRECT for writes. The write
719 * is done asynchronously. (Normally the write would just
720 * get put into cache.
721 *
722 * UFS pays attention to IO_SYNC for writes. It will

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

1524 ctl_data_submit_done(io);
1525 return;
1526 }
1527
1528 io->io_hdr.status &= ~CTL_STATUS_MASK;
1529 io->io_hdr.status |= CTL_STATUS_NONE;
1530
1531 mtx_lock(&be_lun->queue_lock);
1543 /*
1544 * XXX KDM make sure that links is okay to use at this point.
1545 * Otherwise, we either need to add another field to ctl_io_hdr,
1546 * or deal with resource allocation here.
1547 */
1548 STAILQ_INSERT_TAIL(&be_lun->input_queue, &io->io_hdr, links);
1549 mtx_unlock(&be_lun->queue_lock);
1532 STAILQ_INSERT_TAIL(&be_lun->input_queue, &io->io_hdr, links);
1533 mtx_unlock(&be_lun->queue_lock);
1550
1551 taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task);
1552}
1553
1554static void
1555ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
1556 union ctl_io *io)
1557{
1558 struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun;

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

1773 * Make sure we only get SCSI I/O.
1774 */
1775 KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, ("Non-SCSI I/O (type "
1776 "%#x) encountered", io->io_hdr.io_type));
1777
1778 PRIV(io)->len = 0;
1779
1780 mtx_lock(&be_lun->queue_lock);
1534 taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task);
1535}
1536
1537static void
1538ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
1539 union ctl_io *io)
1540{
1541 struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun;

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

1756 * Make sure we only get SCSI I/O.
1757 */
1758 KASSERT(io->io_hdr.io_type == CTL_IO_SCSI, ("Non-SCSI I/O (type "
1759 "%#x) encountered", io->io_hdr.io_type));
1760
1761 PRIV(io)->len = 0;
1762
1763 mtx_lock(&be_lun->queue_lock);
1781 /*
1782 * XXX KDM make sure that links is okay to use at this point.
1783 * Otherwise, we either need to add another field to ctl_io_hdr,
1784 * or deal with resource allocation here.
1785 */
1786 STAILQ_INSERT_TAIL(&be_lun->input_queue, &io->io_hdr, links);
1787 mtx_unlock(&be_lun->queue_lock);
1788 taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task);
1789
1790 return (CTL_RETVAL_COMPLETE);
1791}
1792
1793static int

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

2317 req->status = CTL_LUN_WARNING;
2318 }
2319 }
2320 num_threads = cbb_num_threads;
2321 } else {
2322 num_threads = 1;
2323 }
2324
1764 STAILQ_INSERT_TAIL(&be_lun->input_queue, &io->io_hdr, links);
1765 mtx_unlock(&be_lun->queue_lock);
1766 taskqueue_enqueue(be_lun->io_taskqueue, &be_lun->io_task);
1767
1768 return (CTL_RETVAL_COMPLETE);
1769}
1770
1771static int

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

2295 req->status = CTL_LUN_WARNING;
2296 }
2297 }
2298 num_threads = cbb_num_threads;
2299 } else {
2300 num_threads = 1;
2301 }
2302
2325 /*
2326 * XXX This searching loop might be refactored to be combined with
2327 * the loop above,
2328 */
2329 value = ctl_get_opt(&cbe_lun->options, "num_threads");
2330 if (value != NULL) {
2331 tmp_num_threads = strtol(value, NULL, 0);
2332
2333 /*
2334 * We don't let the user specify less than one
2335 * thread, but hope he's clueful enough not to
2336 * specify 1000 threads.

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

2510 params = &req->reqdata.rm;
2511
2512 mtx_lock(&softc->lock);
2513 STAILQ_FOREACH(be_lun, &softc->lun_list, links) {
2514 if (be_lun->cbe_lun.lun_id == params->lun_id)
2515 break;
2516 }
2517 mtx_unlock(&softc->lock);
2303 value = ctl_get_opt(&cbe_lun->options, "num_threads");
2304 if (value != NULL) {
2305 tmp_num_threads = strtol(value, NULL, 0);
2306
2307 /*
2308 * We don't let the user specify less than one
2309 * thread, but hope he's clueful enough not to
2310 * specify 1000 threads.

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

2484 params = &req->reqdata.rm;
2485
2486 mtx_lock(&softc->lock);
2487 STAILQ_FOREACH(be_lun, &softc->lun_list, links) {
2488 if (be_lun->cbe_lun.lun_id == params->lun_id)
2489 break;
2490 }
2491 mtx_unlock(&softc->lock);
2518
2519 if (be_lun == NULL) {
2520 snprintf(req->error_str, sizeof(req->error_str),
2521 "LUN %u is not managed by the block backend",
2522 params->lun_id);
2523 goto bailout_error;
2524 }
2525 cbe_lun = &be_lun->cbe_lun;
2526

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

2578
2579 ctl_free_opts(&cbe_lun->options);
2580 free(be_lun->dev_path, M_CTLBLK);
2581 mtx_destroy(&be_lun->queue_lock);
2582 mtx_destroy(&be_lun->io_lock);
2583 free(be_lun, M_CTLBLK);
2584
2585 req->status = CTL_LUN_OK;
2492 if (be_lun == NULL) {
2493 snprintf(req->error_str, sizeof(req->error_str),
2494 "LUN %u is not managed by the block backend",
2495 params->lun_id);
2496 goto bailout_error;
2497 }
2498 cbe_lun = &be_lun->cbe_lun;
2499

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

2551
2552 ctl_free_opts(&cbe_lun->options);
2553 free(be_lun->dev_path, M_CTLBLK);
2554 mtx_destroy(&be_lun->queue_lock);
2555 mtx_destroy(&be_lun->io_lock);
2556 free(be_lun, M_CTLBLK);
2557
2558 req->status = CTL_LUN_OK;
2586
2587 return (0);
2588
2589bailout_error:
2559 return (0);
2560
2561bailout_error:
2590
2591 req->status = CTL_LUN_ERROR;
2562 req->status = CTL_LUN_ERROR;
2592
2593 return (0);
2594}
2595
2596static int
2597ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
2598{
2599 struct ctl_lun_modify_params *params;
2600 struct ctl_be_block_lun *be_lun;

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

2606 params = &req->reqdata.modify;
2607
2608 mtx_lock(&softc->lock);
2609 STAILQ_FOREACH(be_lun, &softc->lun_list, links) {
2610 if (be_lun->cbe_lun.lun_id == params->lun_id)
2611 break;
2612 }
2613 mtx_unlock(&softc->lock);
2563 return (0);
2564}
2565
2566static int
2567ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
2568{
2569 struct ctl_lun_modify_params *params;
2570 struct ctl_be_block_lun *be_lun;

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

2576 params = &req->reqdata.modify;
2577
2578 mtx_lock(&softc->lock);
2579 STAILQ_FOREACH(be_lun, &softc->lun_list, links) {
2580 if (be_lun->cbe_lun.lun_id == params->lun_id)
2581 break;
2582 }
2583 mtx_unlock(&softc->lock);
2614
2615 if (be_lun == NULL) {
2616 snprintf(req->error_str, sizeof(req->error_str),
2617 "LUN %u is not managed by the block backend",
2618 params->lun_id);
2619 goto bailout_error;
2620 }
2621 cbe_lun = &be_lun->cbe_lun;
2622

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

2683
2684static void
2685ctl_be_block_lun_shutdown(void *be_lun)
2686{
2687 struct ctl_be_block_lun *lun;
2688 struct ctl_be_block_softc *softc;
2689
2690 lun = (struct ctl_be_block_lun *)be_lun;
2584 if (be_lun == NULL) {
2585 snprintf(req->error_str, sizeof(req->error_str),
2586 "LUN %u is not managed by the block backend",
2587 params->lun_id);
2588 goto bailout_error;
2589 }
2590 cbe_lun = &be_lun->cbe_lun;
2591

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

2652
2653static void
2654ctl_be_block_lun_shutdown(void *be_lun)
2655{
2656 struct ctl_be_block_lun *lun;
2657 struct ctl_be_block_softc *softc;
2658
2659 lun = (struct ctl_be_block_lun *)be_lun;
2691
2692 softc = lun->softc;
2693
2694 mtx_lock(&softc->lock);
2695 lun->flags |= CTL_BE_BLOCK_LUN_UNCONFIGURED;
2696 if (lun->flags & CTL_BE_BLOCK_LUN_WAITING)
2697 wakeup(lun);
2698 mtx_unlock(&softc->lock);
2660 softc = lun->softc;
2661
2662 mtx_lock(&softc->lock);
2663 lun->flags |= CTL_BE_BLOCK_LUN_UNCONFIGURED;
2664 if (lun->flags & CTL_BE_BLOCK_LUN_WAITING)
2665 wakeup(lun);
2666 mtx_unlock(&softc->lock);
2699
2700}
2701
2702static void
2703ctl_be_block_lun_config_status(void *be_lun, ctl_lun_config_status status)
2704{
2705 struct ctl_be_block_lun *lun;
2706 struct ctl_be_block_softc *softc;
2707

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

2740
2741static int
2742ctl_be_block_config_write(union ctl_io *io)
2743{
2744 struct ctl_be_block_lun *be_lun;
2745 struct ctl_be_lun *cbe_lun;
2746 int retval;
2747
2667}
2668
2669static void
2670ctl_be_block_lun_config_status(void *be_lun, ctl_lun_config_status status)
2671{
2672 struct ctl_be_block_lun *lun;
2673 struct ctl_be_block_softc *softc;
2674

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

2707
2708static int
2709ctl_be_block_config_write(union ctl_io *io)
2710{
2711 struct ctl_be_block_lun *be_lun;
2712 struct ctl_be_lun *cbe_lun;
2713 int retval;
2714
2748 retval = 0;
2749
2750 DPRINTF("entered\n");
2751
2752 cbe_lun = (struct ctl_be_lun *)io->io_hdr.ctl_private[
2753 CTL_PRIV_BACKEND_LUN].ptr;
2754 be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
2755
2715 DPRINTF("entered\n");
2716
2717 cbe_lun = (struct ctl_be_lun *)io->io_hdr.ctl_private[
2718 CTL_PRIV_BACKEND_LUN].ptr;
2719 be_lun = (struct ctl_be_block_lun *)cbe_lun->be_lun;
2720
2721 retval = 0;
2756 switch (io->scsiio.cdb[0]) {
2757 case SYNCHRONIZE_CACHE:
2758 case SYNCHRONIZE_CACHE_16:
2759 case WRITE_SAME_10:
2760 case WRITE_SAME_16:
2761 case UNMAP:
2762 /*
2763 * The upper level CTL code will filter out any CDBs with

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

2865
2866static int
2867ctl_be_block_lun_info(void *be_lun, struct sbuf *sb)
2868{
2869 struct ctl_be_block_lun *lun;
2870 int retval;
2871
2872 lun = (struct ctl_be_block_lun *)be_lun;
2722 switch (io->scsiio.cdb[0]) {
2723 case SYNCHRONIZE_CACHE:
2724 case SYNCHRONIZE_CACHE_16:
2725 case WRITE_SAME_10:
2726 case WRITE_SAME_16:
2727 case UNMAP:
2728 /*
2729 * The upper level CTL code will filter out any CDBs with

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

2831
2832static int
2833ctl_be_block_lun_info(void *be_lun, struct sbuf *sb)
2834{
2835 struct ctl_be_block_lun *lun;
2836 int retval;
2837
2838 lun = (struct ctl_be_block_lun *)be_lun;
2873 retval = 0;
2874
2875 retval = sbuf_printf(sb, "\t<num_threads>");
2839
2840 retval = sbuf_printf(sb, "\t<num_threads>");
2876
2877 if (retval != 0)
2878 goto bailout;
2841 if (retval != 0)
2842 goto bailout;
2879
2880 retval = sbuf_printf(sb, "%d", lun->num_threads);
2843 retval = sbuf_printf(sb, "%d", lun->num_threads);
2881
2882 if (retval != 0)
2883 goto bailout;
2844 if (retval != 0)
2845 goto bailout;
2884
2885 retval = sbuf_printf(sb, "</num_threads>\n");
2886
2887bailout:
2846 retval = sbuf_printf(sb, "</num_threads>\n");
2847
2848bailout:
2888
2889 return (retval);
2890}
2891
2892static uint64_t
2893ctl_be_block_lun_attr(void *be_lun, const char *attrname)
2894{
2895 struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)be_lun;
2896

--- 21 unchanged lines hidden ---
2849 return (retval);
2850}
2851
2852static uint64_t
2853ctl_be_block_lun_attr(void *be_lun, const char *attrname)
2854{
2855 struct ctl_be_block_lun *lun = (struct ctl_be_block_lun *)be_lun;
2856

--- 21 unchanged lines hidden ---