Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvme-fc: convert assoc_active flag to bit op

Convert the assoc_active boolean flag to a bitop on the flags field.
The bit ops will provide atomicity.

To make this change, the flags field was converted to a long type,
which also affects the FCCTRL_TERMIO flag. Both FCCTRL_TERMIO and
now ASSOC_ACTIVE flags are set/cleared by bit operations.

Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

James Smart and committed by
Jens Axboe
eb4ee8f1 f56bf76f

+13 -24
+13 -24
drivers/nvme/host/fc.c
··· 127 127 unsigned long dev_loss_end; 128 128 } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ 129 129 130 - enum nvme_fcctrl_flags { 131 - FCCTRL_TERMIO = (1 << 0), 132 - }; 130 + /* fc_ctrl flags values - specified as bit positions */ 131 + #define ASSOC_ACTIVE 0 132 + #define FCCTRL_TERMIO 1 133 133 134 134 struct nvme_fc_ctrl { 135 135 spinlock_t lock; ··· 140 140 u32 cnum; 141 141 142 142 bool ioq_live; 143 - bool assoc_active; 144 143 atomic_t err_work_active; 145 144 u64 association_id; 146 145 ··· 152 153 struct work_struct err_work; 153 154 154 155 struct kref ref; 155 - u32 flags; 156 + unsigned long flags; 156 157 u32 iocnt; 157 158 wait_queue_head_t ioabort_wait; 158 159 ··· 1520 1521 opstate = atomic_xchg(&op->state, FCPOP_STATE_ABORTED); 1521 1522 if (opstate != FCPOP_STATE_ACTIVE) 1522 1523 atomic_set(&op->state, opstate); 1523 - else if (ctrl->flags & FCCTRL_TERMIO) 1524 + else if (test_bit(FCCTRL_TERMIO, &ctrl->flags)) 1524 1525 ctrl->iocnt++; 1525 1526 spin_unlock_irqrestore(&ctrl->lock, flags); 1526 1527 ··· 1557 1558 1558 1559 if (opstate == FCPOP_STATE_ABORTED) { 1559 1560 spin_lock_irqsave(&ctrl->lock, flags); 1560 - if (ctrl->flags & FCCTRL_TERMIO) { 1561 + if (test_bit(FCCTRL_TERMIO, &ctrl->flags)) { 1561 1562 if (!--ctrl->iocnt) 1562 1563 wake_up(&ctrl->ioabort_wait); 1563 1564 } ··· 2385 2386 { 2386 2387 struct nvme_fc_ctrl *ctrl = to_fc_ctrl(arg); 2387 2388 struct nvme_fc_fcp_op *aen_op; 2388 - unsigned long flags; 2389 - bool terminating = false; 2390 2389 blk_status_t ret; 2391 2390 2392 - spin_lock_irqsave(&ctrl->lock, flags); 2393 - if (ctrl->flags & FCCTRL_TERMIO) 2394 - terminating = true; 2395 - spin_unlock_irqrestore(&ctrl->lock, flags); 2396 - 2397 - if (terminating) 2391 + if (test_bit(FCCTRL_TERMIO, &ctrl->flags)) 2398 2392 return; 2399 2393 2400 2394 aen_op = &ctrl->aen_ops[0]; ··· 2596 2604 struct nvme_fc_rport *rport = ctrl->rport; 2597 2605 u32 cnt; 2598 2606 2599 - if (ctrl->assoc_active) 2607 + if (test_and_set_bit(ASSOC_ACTIVE, &ctrl->flags)) 2600 2608 return 1; 2601 2609 2602 - ctrl->assoc_active = true; 2603 2610 cnt = atomic_inc_return(&rport->act_ctrl_cnt); 2604 2611 if (cnt == 1) 2605 2612 nvme_fc_rport_active_on_lport(rport); ··· 2613 2622 struct nvme_fc_lport *lport = rport->lport; 2614 2623 u32 cnt; 2615 2624 2616 - /* ctrl->assoc_active=false will be set independently */ 2625 + /* clearing of ctrl->flags ASSOC_ACTIVE bit is in association delete */ 2617 2626 2618 2627 cnt = atomic_dec_return(&rport->act_ctrl_cnt); 2619 2628 if (cnt == 0) { ··· 2755 2764 __nvme_fc_delete_hw_queue(ctrl, &ctrl->queues[0], 0); 2756 2765 out_free_queue: 2757 2766 nvme_fc_free_queue(&ctrl->queues[0]); 2758 - ctrl->assoc_active = false; 2767 + clear_bit(ASSOC_ACTIVE, &ctrl->flags); 2759 2768 nvme_fc_ctlr_inactive_on_rport(ctrl); 2760 2769 2761 2770 return ret; ··· 2772 2781 { 2773 2782 unsigned long flags; 2774 2783 2775 - if (!ctrl->assoc_active) 2784 + if (!test_and_clear_bit(ASSOC_ACTIVE, &ctrl->flags)) 2776 2785 return; 2777 - ctrl->assoc_active = false; 2778 2786 2779 2787 spin_lock_irqsave(&ctrl->lock, flags); 2780 - ctrl->flags |= FCCTRL_TERMIO; 2788 + set_bit(FCCTRL_TERMIO, &ctrl->flags); 2781 2789 ctrl->iocnt = 0; 2782 2790 spin_unlock_irqrestore(&ctrl->lock, flags); 2783 2791 ··· 2827 2837 /* wait for all io that had to be aborted */ 2828 2838 spin_lock_irq(&ctrl->lock); 2829 2839 wait_event_lock_irq(ctrl->ioabort_wait, ctrl->iocnt == 0, ctrl->lock); 2830 - ctrl->flags &= ~FCCTRL_TERMIO; 2840 + clear_bit(FCCTRL_TERMIO, &ctrl->flags); 2831 2841 spin_unlock_irq(&ctrl->lock); 2832 2842 2833 2843 nvme_fc_term_aen_ops(ctrl); ··· 3099 3109 ctrl->dev = lport->dev; 3100 3110 ctrl->cnum = idx; 3101 3111 ctrl->ioq_live = false; 3102 - ctrl->assoc_active = false; 3103 3112 atomic_set(&ctrl->err_work_active, 0); 3104 3113 init_waitqueue_head(&ctrl->ioabort_wait); 3105 3114