Re: [PATCH] libfc: fix seconds_since_last_reset miscalculation

2016-11-17 Thread Johannes Thumshirn
On Wed, Nov 16, 2016 at 05:58:14PM +0100, Arnd Bergmann wrote:
> On Tuesday, November 15, 2016 4:05:31 PM CET Johannes Thumshirn wrote:
> > On Tue, Nov 15, 2016 at 02:50:17PM +, Bart Van Assche wrote:
> > > On Tue, 2016-11-15 at 10:18 +0100, Johannes Thumshirn wrote:
> > > > On Tue, Nov 08, 2016 at 03:04:43PM +, Bart Van Assche wrote:
> > > > > I think the above code will miscalculate seconds_since_last_reset
> > > > > if 
> > > > > 'jiffies' wraps around after an lport has been created and before 
> > > > > seconds_since_last_reset is computed. Shouldn't
> > > > > seconds_since_last_reset 
> > > > > be computed as follows?
> > > > > 
> > > > >   fc_stats->seconds_since_last_reset = (jiffies - boot_time) /
> > > > > HZ;
> > > > 
> > > > But what happens when jiffies - boot_time becomes negative? Then we
> > > > reintroduce the bug again and have 'fcoeadm -s' show weird values.
> > > 
> > > Hello Johannes,
> > > 
> > > If your concern is about 'jiffies' wrapping around on 32-bit systems
> > > then you should use get_jiffies_64(). get_jiffies_64() - boot_time
> > > can't become negative. It namely takes several million years before a
> > > 64-bit HZ counter wraps around.
> > 
> > You're right. I'll respin using get_jiffies_64() and resent once it is 
> > tested.
> 
> Sorry for the bug I introduced and for not noticing this thread earlier.
> Looking at this again now, I think it's clear that the bug was simply
> mixing up the left and right side of the subtraction, the simple fix
> would be
> 
> diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
> index 2d3133f62463..fe643f2195f0 100644
> --- a/drivers/scsi/libfc/fc_lport.c
> +++ b/drivers/scsi/libfc/fc_lport.c
> @@ -311,7 +311,7 @@ struct fc_host_statistics *fc_get_host_stats(struct 
> Scsi_Host *shost)
>   fc_stats = >host_stats;
>   memset(fc_stats, 0, sizeof(struct fc_host_statistics));
>  
> - fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) / HZ;
> + fc_stats->seconds_since_last_reset = (jiffies - lport->boot_time) / HZ;
>  
>   for_each_possible_cpu(cpu) {
>   struct fc_stats *stats;
> 
> This works correctly across jiffies overflows, as long as there is at least 
> one
> reset for every jiffies overflow (49 days or more). If we can have longer 
> times
> between resets, then we could either use get_jiffies_64() or 
> ktime_get_seconds().

Yes I was going to resend this today, but I'm trapped in the s390 pit...

Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-11-15 Thread Johannes Thumshirn
On Tue, Nov 15, 2016 at 03:31:27PM +0100, Steffen Maier wrote:
> Hi Johannes,
> 
> On 11/15/2016 12:56 PM, Johannes Thumshirn wrote:
> > On Tue, Oct 25, 2016 at 09:43:14AM +0200, Johannes Thumshirn wrote:
> > > On Fri, Oct 14, 2016 at 09:38:21AM +0200, Johannes Thumshirn wrote:
> > > > On Thu, Oct 13, 2016 at 05:55:11PM +0200, Steffen Maier wrote:
> > > > > Hm, still behaves for me like I reported for v2:
> > > > > http://marc.info/?l=linux-scsi=147637177902937=2
> > 
> > [...]
> > 
> > > > 
> > > > The rational behind this is, in fc_req_to_bsgjob() we're assigning
> > > > job->request as req->cmd and job->request_len = req->cmd_len. But 
> > > > without
> > > > checkinf job->request_len we don't know whether we're save to touch
> > > > job->request (a.k.a. bsg_request).
> > > 
> > > Hi Steffen,
> > > Did you have any chance testing this? I hacked fcping to work with 
> > > non-FCoE
> > > and rports as well and tested with FCoE and lpfc. No problems seen from my
> > > side. I've also pused the series (With this change folded in) to my git
> > > tree at [1] if this helps you in any way.
> > > 
> > > [1] 
> > > https://git.kernel.org/cgit/linux/kernel/git/jth/linux.git/log/?h=scsi-bsg-rewrite-v4
> > > 
> > 
> > So I finally have a test system up and running. I have good and bad news. 
> > The
> > good news is, I can't get the system crashing with my patches, the bad news 
> > is
> > I can't get zfcp_ping and zfcp_show to output something but HBA_STATUS_ERROR
> > with my patches and without.
> 
> Assuming you run the latest package version on s390x:
> 
> Do steps 2 and 3 of the procedure in
> http://www.ibm.com/support/knowledgecenter/linuxonibm/com.ibm.linux.z.lhdd/lhdd_t_fcp_api_runappl.html
> help?

No, I do have a correct /etc/hba.conf:
$ grep libzfcphbaapi /etc/hba.conf 
com.ibm.libzfcphbaapi /usr/lib64/libzfcphbaapi.so.0
and bumping the log level via export LIB_ZFCP_HBAAPI_LOG_LEVEL=1 just adds 
'(vlib.c:105)_initvlib: libzfcphbaapi.so loaded at Nov 15 15:43:23' to the 1st
line of zfcp_ping output.

Here's the full output:
$ zfcp_ping -v -a 0.0.fc00 -d 0x50050763051b473a
(vlib.c:105)_initvlib: libzfcphbaapi.so loaded at Nov 15 15:45:33
Sending PNG from BUS_ID=0.0.fc00 WWPN=0xc05076e0f3002344 ID=0x760c1c
dev=/dev/bsg/fc_host1 speed=8 GBit/s
--- REQUEST cmd = 0x0401 ---
03 00 00 00 fa 01 00 00 
04 01 00 01 00 00 00 00 
00 00 00 01 00 02 00 08 
50 05 07 63 05 1b 47 3a 
00 00 00 00 
--- RESPONSE rc = 0x1 ---
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 
--- REQUEST cmd = 0x0401 ---
03 00 00 00 fa 01 00 00 
04 01 00 01 00 00 00 00 
00 00 00 01 00 02 00 08 
50 05 07 63 05 1b 47 3a 
00 00 00 00 
--- RESPONSE rc = 0x1 ---
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 
--- REQUEST cmd = 0x0401 ---
03 00 00 00 fa 01 00 00 
04 01 00 01 00 00 00 00 
00 00 00 01 00 02 00 08 
50 05 07 63 05 1b 47 3a 
00 00 00 00 
--- RESPONSE rc = 0x1 ---
00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 
00 00 00 00 
Error received for FPNG request, aborting.

-- ping statistics ---
min/avg/max = 0.000/0.000/0.000 ms
--

I agree this looks a bit suspicious and I'll add some debugs in the kernel to
see what's going on.

> 
> The only other thing I can think of from the top of my head is that BSG
> ioctls are sensitive regarding ABI and I once had the kernel ioctl return
> EINVAL due to unmatching kernel-headers and libzfcphbaapi maps this EINVAL
> to HBA_STATUS_ERROR because there is no more specifically suitable HBA
> constant [old SUSE bugs 834498 and 834500].
> 
> > And btw, I renamed the branch to fc-bsg-rewrite-v4 in case you want to clone
> > from it (it has patch 2/16 changed to the v3 submission).
> > 
> > Can you please have a look with your setup?
> 
> I'm going to re-test hopefully within the next few days.

That'll be great, thanks.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] libfc: fix seconds_since_last_reset miscalculation

2016-11-15 Thread Johannes Thumshirn
On Tue, Nov 15, 2016 at 02:50:17PM +, Bart Van Assche wrote:
> On Tue, 2016-11-15 at 10:18 +0100, Johannes Thumshirn wrote:
> > On Tue, Nov 08, 2016 at 03:04:43PM +, Bart Van Assche wrote:
> > > I think the above code will miscalculate seconds_since_last_reset
> > > if 
> > > 'jiffies' wraps around after an lport has been created and before 
> > > seconds_since_last_reset is computed. Shouldn't
> > > seconds_since_last_reset 
> > > be computed as follows?
> > > 
> > >   fc_stats->seconds_since_last_reset = (jiffies - boot_time) /
> > > HZ;
> > 
> > But what happens when jiffies - boot_time becomes negative? Then we
> > reintroduce the bug again and have 'fcoeadm -s' show weird values.
> 
> Hello Johannes,
> 
> If your concern is about 'jiffies' wrapping around on 32-bit systems
> then you should use get_jiffies_64(). get_jiffies_64() - boot_time
> can't become negative. It namely takes several million years before a
> 64-bit HZ counter wraps around.

You're right. I'll respin using get_jiffies_64() and resent once it is tested.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-11-16 Thread Johannes Thumshirn
On Tue, Nov 15, 2016 at 04:39:33PM +0100, Johannes Thumshirn wrote:
> On Tue, Nov 15, 2016 at 03:31:27PM +0100, Steffen Maier wrote:
> > Hi Johannes,
> > 
> > On 11/15/2016 12:56 PM, Johannes Thumshirn wrote:
> > > On Tue, Oct 25, 2016 at 09:43:14AM +0200, Johannes Thumshirn wrote:
> > > > On Fri, Oct 14, 2016 at 09:38:21AM +0200, Johannes Thumshirn wrote:
> > > > > On Thu, Oct 13, 2016 at 05:55:11PM +0200, Steffen Maier wrote:
> > > > > > Hm, still behaves for me like I reported for v2:
> > > > > > http://marc.info/?l=linux-scsi=147637177902937=2
> > > 
> > > [...]
> > > 
> > > > > 
> > > > > The rational behind this is, in fc_req_to_bsgjob() we're assigning
> > > > > job->request as req->cmd and job->request_len = req->cmd_len. But 
> > > > > without
> > > > > checkinf job->request_len we don't know whether we're save to touch
> > > > > job->request (a.k.a. bsg_request).
> > > > 
> > > > Hi Steffen,
> > > > Did you have any chance testing this? I hacked fcping to work with 
> > > > non-FCoE
> > > > and rports as well and tested with FCoE and lpfc. No problems seen from 
> > > > my
> > > > side. I've also pused the series (With this change folded in) to my git
> > > > tree at [1] if this helps you in any way.
> > > > 
> > > > [1] 
> > > > https://git.kernel.org/cgit/linux/kernel/git/jth/linux.git/log/?h=scsi-bsg-rewrite-v4
> > > > 
> > > 
> > > So I finally have a test system up and running. I have good and bad news. 
> > > The
> > > good news is, I can't get the system crashing with my patches, the bad 
> > > news is
> > > I can't get zfcp_ping and zfcp_show to output something but 
> > > HBA_STATUS_ERROR
> > > with my patches and without.
> 
> Please ignore my last mails, apparently it's a wise idea to check which user
> id one has before running zfcp_ping...
> 
> The good news for this is, I can now recreate the crashes you have and thus
> have a chance to fix them :-)

So JFTR, I was able to fix the 1 problem introduced by this patch, it's the
follwoing hunk:
@@ -3726,9 +3729,9 @@ fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport 
*rport,
if (i->f->dd_bsg_size)
job->dd_data = (void *)[1];
spin_lock_init(>job_lock);
-   job->request = (struct fc_bsg_request *)req->cmd;
+   bsg_request = (struct fc_bsg_request *)req->cmd;
    job->request_len = req->cmd_len;
-   job->reply = req->sense;
+   bsg_reply = req->sense;
job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer
 * allocated */
if (req->bio) {

But as fc_req_to_bsgjob() get's deleted in Patch 15/16 the problem is
re-introduced. Unfortunately the fix isn't as trivial as for 2/16 so I'm still
trying to nail it down.

Thanks,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mvsas: fix command_active typo

2016-11-16 Thread Johannes Thumshirn
On Wed, Nov 16, 2016 at 04:08:34PM +0100, Arnd Bergmann wrote:
> gcc-7 notices that the condition in mvs_94xx_command_active looks
> suspicious:
> 
> drivers/scsi/mvsas/mv_94xx.c: In function 'mvs_94xx_command_active':
> drivers/scsi/mvsas/mv_94xx.c:671:15: error: '<<' in boolean context, did you 
> mean '<' ? [-Werror=int-in-bool-context]
> 
> This was introduced when the mv_printk() statement got added,
> and leads to the condition being ignored. This is probably harmless.
> 
> Changing '&&' to '&' makes the code look reasonable, as we check the
> command bit before setting and printing it.
> 
> Fixes: a4632aae8b66 ("[SCSI] mvsas: Add new macros and functions")
> Signed-off-by: Arnd Bergmann <a...@arndb.de>
> ---

Looks reasonable,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: use PCI layer IRQ affinity in lpfc

2016-11-18 Thread Johannes Thumshirn
On Fri, Nov 18, 2016 at 05:22:11AM -0800, Christoph Hellwig wrote:
> On Fri, Nov 18, 2016 at 02:13:12PM +0100, Johannes Thumshirn wrote:
> > This is what /proc/interrupts looks like after booting from the lpfc HBA,
> > with your patches:
> > 
> > ettrick:~ # grep lpfc /proc/interrupts 
> >   44: 2056 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 5242880-edge lpfc
> >   46: 2186 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 5244928-edge lpfc
> >   48:   69 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6815744-edge lpfc:sp
> >   49: 2060 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6815745-edge lpfc:fp
> >   51:   64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6817792-edge lpfc:sp
> >   52: 1074 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6817793-edge lpfc:fp
> > ettrick:~ # for irq in 44 46 48 49 51 52; do echo -n "$irq: "; \
> > >  cat /proc/irq/$irq/smp_affinity; done
> > 44: 
> > 46: 
> > 48: 
> > 49: 
> > 51: 
> > 52: 
> > ettrick:~ # 
> > 
> > Anything else you want me to look at?
> 
> Looks like you have non SLI-4 devices, which doesn't support
> multiple queues, so patch 2 shouldn't have made a difference anyway.
> 
> But even with an SLI-4 device we'd need some actual I/O from different
> CPUs to it to see how the interrupts were spread.

Hmmm
c79:/suse/jthumshirn # fio --rw=randread --name=test --direct=1 \
> --size=1G --time_based --runtime=30s --filename=/dev/sdk \
> --group_reporting --max-jobs=24 --ioengine=libaio --numjobs=24 \
> --iodepth=128
[...]
c79:/suse/jthumshirn # grep lpfc /proc/interrupts 
  51:  2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3674112-edge lpfc:0
  52:  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3674113-edge lpfc:1
  53:  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3674114-edge lpfc:2
  54:  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3674115-edge lpfc:3
  56: 907298 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3676160-edge lpfc:0
  57:  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3676161-edge lpfc:1
  58:  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3676162-edge lpfc:2
  59:  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI 
3676163-edge lpfc:3
c79:/suse/jthumshirn # for irq in 51 52 53 54 56 57 58 59; do echo -n "$irq: ";\
> cat /proc/irq/$irq/smp_affinity; done
51: ,7007
52: ,00038038
53: ,001c01c0
54: ,00e00e00
56: ,7007
57: ,00038038
58: ,001c01c0
59: ,00e00e00

c79:/suse/jthumshirn # lspci -s 07:00.2 -vvv | grep "Product Name"
Product Name: Emulex OneConnect OCe14102-UM 10GbE 2-Port SFP+ PCIe 3.0 
Universal CNA, FCoE PF
c79:/suse/jthumshirn # lspci -s 07:00.2 -vvv | grep "MSI-X"
Capabilities: [48] MSI-X: Enable+ Count=8 Masked-
c79:/suse/jthumshirn # systemctl status irqbalance.service
● irqbalance.service - irqbalance daemon
   Loaded: loaded (/usr/lib/systemd/system/irqbalance.service; disabled; vendor 
preset: enabled)
   Active: inactive (dead)

Where did I mess up?
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: use PCI layer IRQ affinity in lpfc

2016-11-18 Thread Johannes Thumshirn
Hi Christoph,

On Thu, Nov 17, 2016 at 04:14:51PM +0100, Christoph Hellwig wrote:
> This series has two patches: the first is a simple conversion of
> lpfc to use pci_alloc_irq_vectors.  The second is more interesting,
> and makes use of the PCI_IRQ_AFFINITY option to use the core interrupt
> affinity assignment that takes nodes into account and can be easily
> queried.  It also ensures we propagate this information to blk-mq
> to make sure the block layer queues are properly aligned to the
> interrupt vectors.
> 
> Note that these patches require core IRQ changes from a stable
> branch in the tip tree to be pulled in first:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/for-block
> 
> Also be aware that I don't have any lpfc hardware to actually test these.

This is what /proc/interrupts looks like after booting from the lpfc HBA,
with your patches:

ettrick:~ # grep lpfc /proc/interrupts 
  44: 2056 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 5242880-edge lpfc
  46: 2186 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 5244928-edge lpfc
  48:   69 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6815744-edge lpfc:sp
  49: 2060 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6815745-edge lpfc:fp
  51:   64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6817792-edge lpfc:sp
  52: 1074 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6817793-edge lpfc:fp
ettrick:~ # for irq in 44 46 48 49 51 52; do echo -n "$irq: "; \
>  cat /proc/irq/$irq/smp_affinity; done
44: 
46: 
48: 
49: 
51: 
52: 
ettrick:~ # 

Anything else you want me to look at?

Apart from that, for the whole series:
Tested-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] bfa: turn bfa_mem_{kva,dma}_setup into inline functions

2016-11-18 Thread Johannes Thumshirn
On Wed, Nov 16, 2016 at 04:14:27PM +0100, Arnd Bergmann wrote:
> These two macros cause lots of warnings with gcc-7:
> 
> drivers/scsi/bfa/bfa_svc.c: In function 'bfa_fcxp_meminfo':
> drivers/scsi/bfa/bfa_svc.c:521:103: error: '*' in boolean context, suggest 
> '&&' instead [-Werror=int-in-bool-context]
> 
> Using inline functions makes them much more readable and avoids
> the warnings.
> 
> Signed-off-by: Arnd Bergmann <a...@arndb.de>
> ---

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: use PCI layer IRQ affinity in lpfc

2016-11-18 Thread Johannes Thumshirn
On Fri, Nov 18, 2016 at 05:22:11AM -0800, Christoph Hellwig wrote:
> On Fri, Nov 18, 2016 at 02:13:12PM +0100, Johannes Thumshirn wrote:
> > This is what /proc/interrupts looks like after booting from the lpfc HBA,
> > with your patches:
> > 
> > ettrick:~ # grep lpfc /proc/interrupts 
> >   44: 2056 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 5242880-edge lpfc
> >   46: 2186 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 5244928-edge lpfc
> >   48:   69 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6815744-edge lpfc:sp
> >   49: 2060 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6815745-edge lpfc:fp
> >   51:   64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6817792-edge lpfc:sp
> >   52: 1074 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PCI-MSI 6817793-edge lpfc:fp
> > ettrick:~ # for irq in 44 46 48 49 51 52; do echo -n "$irq: "; \
> > >  cat /proc/irq/$irq/smp_affinity; done
> > 44: 
> > 46: 
> > 48: 
> > 49: 
> > 51: 
> > 52: 
> > ettrick:~ # 
> > 
> > Anything else you want me to look at?
> 
> Looks like you have non SLI-4 devices, which doesn't support
> multiple queues, so patch 2 shouldn't have made a difference anyway.

We've found a host with SLI-4, I'll check this one as well.

> 
> But even with an SLI-4 device we'd need some actual I/O from different
> CPUs to it to see how the interrupts were spread.

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RESEND v4 00/15] Convert FibreChannel bsg code to use bsg-lib

2016-11-17 Thread Johannes Thumshirn
This series converts the current bsg usage in the FibreChannel drivers over
to use bsg-lib. SAS will follow once FC is in a good enough shape.

I did take some inspiration from a similar patchset from Mike Christie
dating back to 2011 but it's not a 1:1 copy. Patch 15/16 is heavily based
on his series and attribution is given to him in the commit message.

It is currently regression tested on FCoE and lpfc using the 'fcns',
'fcrls' and 'fcping' (see my FC_BSG_RPT_ELS patch for fcping) utilities and
zfcp_show/zfcp_ping on s390x.

The idea for this change arose when discussing racy sysfs handling the FC
bsg code with Christoph and is a next step in moving all bsg clients to
bsg-lib to eventually clean up the in kernel bsg API.

Changes to v1:
* Reduce the number of individual patches (44 -> 16)
* Fix s390 build failure (forgotten to kill fc_bsg_job from zfcp_ext.h)
* Fix build failure on configs without CONFIG_BLK_DEV_BSGLIB
* Make bsg_job_get() call kref_get_unless_zero() and use it in 
scsi_transport_fc.c

Changes to v2:
* Add Hannes' Reviewd-by tags
* Address Hannes' comment about kref handling in 8/16
* Move CONFIG_BLK_DEV_BSGLIB dependency to patch 12/16 as per 0day results

Changes to v3:
* Rebase on mkp/4.10/scsi-queue (and fixup the new lpfc bsg function)
* Move checks for request and reply len before accessing them (hopefully fixes 
zfcp)
* Added Tyrel's Acked-bys
* Added Christoph's Reviewed-bys
* Squashed bsg_job_done patches as requested by Christoph
* Fixed the hopefully last bisection breaking point
* Fixed kernel panic on s390 with patch 2/15
* Fixed kernel panic on s390 with patch 5/15
* Fixed zfcp_show output on s390 with patch 4/15


Johannes Thumshirn (15):
  scsi: Get rid of struct fc_bsg_buffer
  scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  scsi: fc: Export fc_bsg_jobdone and use it in FC drivers
  scsi: fc: provide fc_bsg_to_shost() helper
  scsi: fc: provide fc_bsg_to_rport() helper
  scsi: libfc: don't set FC_RQST_STATE_DONE before calling
fc_bsg_jobdone()
  scsi: fc: implement kref backed reference counting
  block: add reference counting for struct bsg_job
  scsi: change FC drivers to use 'struct bsg_job'
  scsi: fc: Use bsg_destroy_job
  scsi: fc: use bsg_softirq_done
  scsi: fc: use bsg_job_done
  block: add bsg_job_put() and bsg_job_get()
  scsi: fc: move FC transport's bsg code to bsg-lib
  block: unexport bsg_softirq_done() again

 block/bsg-lib.c  |  23 +-
 drivers/s390/scsi/zfcp_ext.h |   4 +-
 drivers/s390/scsi/zfcp_fc.c  |  36 ++--
 drivers/scsi/Kconfig |   1 +
 drivers/scsi/bfa/bfad_bsg.c  |  62 +++---
 drivers/scsi/bfa/bfad_im.h   |   4 +-
 drivers/scsi/ibmvscsi/ibmvfc.c   |  40 ++--
 drivers/scsi/libfc/fc_lport.c|  47 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 387 +++--
 drivers/scsi/lpfc/lpfc_crtn.h|   4 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 449 ++-
 drivers/scsi/qla2xxx/qla_def.h   |   2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |   4 +-
 drivers/scsi/qla2xxx/qla_iocb.c  |  13 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  52 +++--
 drivers/scsi/qla2xxx/qla_mr.c|  15 +-
 drivers/scsi/scsi_transport_fc.c | 433 +++--
 include/linux/bsg-lib.h  |   4 +
 include/scsi/libfc.h |   2 +-
 include/scsi/scsi_transport_fc.h |  62 ++
 20 files changed, 770 insertions(+), 874 deletions(-)

-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] libfc: fix seconds_since_last_reset miscalculation

2016-11-17 Thread Johannes Thumshirn
Commit 540eb1eef 'scsi: libfc: fix seconds_since_last_reset calculation'
removed the use of 'struct timespec' from fc_get_host_stats(). This broke the
output of 'fcoeadm -s' after kernel 4.8-rc1.

Fixes: 540eb1eef ('scsi: libfc: fix seconds_since_last_reset calculation')
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/libfc/fc_lport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 04ce7cf..50c7167 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -308,7 +308,7 @@ struct fc_host_statistics *fc_get_host_stats(struct 
Scsi_Host *shost)
fc_stats = >host_stats;
memset(fc_stats, 0, sizeof(struct fc_host_statistics));
 
-   fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) / HZ;
+   fc_stats->seconds_since_last_reset = (jiffies - lport->boot_time) / HZ;
 
for_each_possible_cpu(cpu) {
struct fc_stats *stats;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RESEND v4 08/15] block: add reference counting for struct bsg_job

2016-11-17 Thread Johannes Thumshirn
Add reference counting to 'struct bsg_job' so we can implement a reuqest
timeout handler for bsg_jobs, which is needed for Fibre Channel.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c | 7 +--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,8 +32,10 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct bsg_job *job)
+static void bsg_destroy_job(struct kref *kref)
 {
+   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+
put_device(job->dev);   /* release reference for the request */
 
kfree(job->request_payload.sg_list);
@@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq)
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
-   bsg_destroy_job(job);
+   kref_put(>kref, bsg_destroy_job);
 }
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
@@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct 
request *req)
job->dev = dev;
/* take a reference for the request */
get_device(job->dev);
+   kref_init(>kref);
return 0;
 
 failjob_rls_rqst_payload:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -40,6 +40,8 @@ struct bsg_job {
struct device *dev;
struct request *req;
 
+   struct kref kref;
+
/* Transport/driver specific request/reply structs */
void *request;
void *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RESEND v4 15/15] block: unexport bsg_softirq_done() again

2016-11-17 Thread Johannes Thumshirn
Unexport bsg_softirq_done() again, we don't need it outside of bsg-lib.c
anymore now that scsi_transport_fc is a pure bsg-lib client.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c | 3 +--
 include/linux/bsg-lib.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 803ec40..2d1df5c 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -96,13 +96,12 @@ void bsg_job_done(struct bsg_job *job, int result,
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-void bsg_softirq_done(struct request *rq)
+static void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
bsg_job_put(job);
 }
-EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index b708db9..657a718 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_softirq_done(struct request *rq);
 void bsg_job_put(struct bsg_job *job);
 int __must_check bsg_job_get(struct bsg_job *job);
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mpt2sas: Fix secure erase premature termination.

2016-11-21 Thread Johannes Thumshirn
On Mon, Nov 21, 2016 at 10:41:38AM +0100, Greg KH wrote:
> On Mon, Nov 21, 2016 at 03:05:38PM +0530, Suganath Prabu Subramani wrote:
> > Commit id and other details are given below:
> > 
> > commit 18f6084a989ba1b38702f9af37a2e4049a924be6
> > Author: Andrey Grodzovsky <andrey2...@gmail.com>
> > Date:   Thu Nov 10 09:35:27 2016 -0500
> > 
> >     scsi: mpt3sas: Fix secure erase premature termination
> > 
> 
> For what?  I have no context here...

Hi, 

Let me chime in and give you some context. Once upon a time there have been
two LSI/Avago/Broadcom SAS HBA drivers called mpt2sas and mpt3sas. Luckily
they got merged and so we only have to fix bugs in one file instead all of 
it's copies. This was around commit c84b06a48c4d8ac8270624453132f3fa1a4a0f9d
which went in v4.4. This patch looks like the mpt2sas version of above fix for
stable kernels before the mpt{2,3}sas unification (a.k.a pre-4.4).

Hope that helps.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] hpsa: destroy sas transport properties before scsi_host

2016-11-21 Thread Johannes Thumshirn
On Mon, Nov 21, 2016 at 03:04:29PM +0100, Martin Wilck wrote:
> Unloading the hpsa driver causes warnings
> 
> [ 1063.793652] WARNING: CPU: 1 PID: 4850 at ../fs/sysfs/group.c:237 
> device_del+0x54/0x240()
> [ 1063.793659] sysfs group 81cf21a0 not found for kobject 'port-2:0'
> 
> with two different stacks:
> 1)
> [ 1063.793774]  [] device_del+0x54/0x240
> [ 1063.793780]  [] transport_remove_classdev+0x4a/0x60
> [ 1063.793784]  [] 
> attribute_container_device_trigger+0xa6/0xb0
> [ 1063.793802]  [] sas_port_delete+0x126/0x160 
> [scsi_transport_sas]
> [ 1063.793819]  [] hpsa_free_sas_port+0x3c/0x70 [hpsa]
> 
> 2)
> [ 1063.797103]  [] device_del+0x54/0x240
> [ 1063.797118]  [] sas_port_delete+0x12e/0x160 
> [scsi_transport_sas]
> [ 1063.797134]  [] hpsa_free_sas_port+0x3c/0x70 [hpsa]
> 
> This is caused by the fact that host device hostX is deleted before the
> SAS transport devices hostX/port-a:b.
> 
> This patch fixes this by reverting the order of device deletions.
> 
> References: bsc#1010946
> Signed-off-by: Martin Wilck <mwi...@suse.de>
> ---

With the References changed to the bug link like in patch 1/2 
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] hpsa: cleanup sas_phy structures in sysfs when unloading

2016-11-21 Thread Johannes Thumshirn
On Mon, Nov 21, 2016 at 03:04:28PM +0100, Martin Wilck wrote:
> When the hpsa module is unloaded using rmmod, dangling
> symlinks remain under /sys/class/sas_phy. Fix this by
> calling sas_phy_delete() rather than sas_phy_free (which,
> according to comments, should not be called for PHYs that
> have been set up successfully, anyway).
> 
> References: bsc#1010946.

I don't think the SUSE bugzilla tag is of relevance upstream. But for sake of
completeness we could add a 
Link: https://bugzilla.suse.com/show_bug.cgi?id=1010946

> Signed-off-by: Martin Wilck <mwi...@suse.de>

Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

> ---
>  drivers/scsi/hpsa.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
> index efe2f36..8ec77c3 100644
> --- a/drivers/scsi/hpsa.c
> +++ b/drivers/scsi/hpsa.c
> @@ -9547,9 +9547,9 @@ static void hpsa_free_sas_phy(struct hpsa_sas_phy 
> *hpsa_sas_phy)
>   struct sas_phy *phy = hpsa_sas_phy->phy;
>  
>   sas_port_delete_phy(hpsa_sas_phy->parent_port->port, phy);
> - sas_phy_free(phy);
>   if (hpsa_sas_phy->added_to_port)
>   list_del(_sas_phy->phy_list_entry);
> + sas_phy_delete(phy);
>   kfree(hpsa_sas_phy);
>  }
>  
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: SG does not ignore dxferp (direct io + mmap)

2016-11-21 Thread Johannes Thumshirn
On Mon, Nov 21, 2016 at 04:15:52PM +0100, Johannes Thumshirn wrote:
> On Mon, Nov 21, 2016 at 04:55:29PM +0200, Eyal Ben David wrote:
> > Thanks for your reply,
> > 
> > On RHEL system it does not occur.
> > 
> > So far I have seen the problem on Ubuntu 16.04 and Fedora 22 (both
> > with kernel 4.4.x)

As Ewan already pointed out, do you have commit
5ecee0a3ee8d74b6950cb41e8989b0c2174568d4 applied in your kernels? It went in
4.6 and got stable backported from there till 2.6.something. I'm trying this
patch myself to see whether it is the required change or not.

Byte,
    Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: SG does not ignore dxferp (direct io + mmap)

2016-11-21 Thread Johannes Thumshirn
On Mon, Nov 21, 2016 at 04:55:29PM +0200, Eyal Ben David wrote:
> Thanks for your reply,
> 
> On RHEL system it does not occur.
> 
> So far I have seen the problem on Ubuntu 16.04 and Fedora 22 (both
> with kernel 4.4.x)

FWIW:
jthumshirn@linux-x5ow:~$ sudo ./sg_mmap_read -d /dev/sg0 -l 0 | hexdump 
000 c033 d08e 00bc 8e7c 8ec0 bed8 7c00 00bf
010 b906 0200 f3fc 50a4 1c68 cb06 b9fb 0004
020 bebd 8007 007e 7c00 0f0b 0e85 8301 10c5
030 f1e2 18cd 5688 5500 46c6 0511 46c6 0010
040
jthumshirn@linux-x5ow:~$ sudo ./sg_mmap_read -d /dev/sg0 -l 0 -m | hexdump 
000 c033 d08e 00bc 8e7c 8ec0 bed8 7c00 00bf
010 b906 0200 f3fc 50a4 1c68 cb06 b9fb 0004
020 bebd 8007 007e 7c00 0f0b 0e85 8301 10c5
030 f1e2 18cd 5688 5500 46c6 0511 46c6 0010
040
jthumshirn@linux-x5ow:~$ sudo ./sg_mmap_read -d /dev/sg0 -l 0 -m -b | hexdump 
000 c033 d08e 00bc 8e7c 8ec0 bed8 7c00 00bf
010 b906 0200 f3fc 50a4 1c68 cb06 b9fb 0004
020 bebd 8007 007e 7c00 0f0b 0e85 8301 10c5
030 f1e2 18cd 5688 5500 46c6 0511 46c6 0010
040
jthumshirn@linux-x5ow:~$ uname -r
4.8.4-1-default

root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 | hexdump
000 caec 1dfe 3fdc 5b26 5775 eff6 a760 d612
010 c43c 8551 cfb8 4630 5e61 0750 44f3 c99e
020 5718 84fd 073f e2f5 0f30 f1fa 1e1a 51e6
030 3379 217a 7d0f 8040 11cd 261f 3f8b 6de2
040
root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 -m | hexdump
000 cd00 5f33 8809  0002   
010 0007    f000  7fff 
020     6e9d 57ac  
030        
040
root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 -m -b | hexdump
000 4c00 bd7e 8805  0002   
010 002f    f000  7fff 
020     6e9d 57ac  
030        
040
root@glass:~ # uname -r
4.4.21-69-default
root@glass:~ # 


Bt:
root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 -| hexdump
000 46c0 b3b0 8804  0002   
010 0021    f000  7fff 
020     6e9d 57ac  
030 626c 3170 6f5f 2070 2020 2020 3d20 3020
040
root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 -| hexdump
000        
*
040
root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 -| hexdump
000        
*
040
root@glass:~ # ~jthumshirn/sg_mmap_read -d /dev/sg0 -l 0 -| hexdump
000 73db ffe0 7a7d 1bf6 85cf 39ab a094 7802
010 959c 5b58 dc6f 1a36 5e7d 0afe d5be 3d41
020 691e 36ee 458c 14d2 06ed 371b 24dd 1f45
030 428a 24a0 866a 4a19 4954 e46a afe9 f3df
040
glass:~ # 

Maybe we have a race here.

for i in $(seq 1 100); do 
sudo ./sg_mmap_read -d /dev/sg0 -l 0 -m -b | hexdump
done
on 4.8 works fine.

On the 4.4 host it has some hickups.

I'll have a look at it.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-11-15 Thread Johannes Thumshirn
On Tue, Oct 25, 2016 at 09:43:14AM +0200, Johannes Thumshirn wrote:
> On Fri, Oct 14, 2016 at 09:38:21AM +0200, Johannes Thumshirn wrote:
> > On Thu, Oct 13, 2016 at 05:55:11PM +0200, Steffen Maier wrote:
> > > Hm, still behaves for me like I reported for v2:
> > > http://marc.info/?l=linux-scsi=147637177902937=2

[...]

> > 
> > The rational behind this is, in fc_req_to_bsgjob() we're assigning
> > job->request as req->cmd and job->request_len = req->cmd_len. But without
> > checkinf job->request_len we don't know whether we're save to touch
> > job->request (a.k.a. bsg_request).
> 
> Hi Steffen,
> Did you have any chance testing this? I hacked fcping to work with non-FCoE
> and rports as well and tested with FCoE and lpfc. No problems seen from my
> side. I've also pused the series (With this change folded in) to my git 
> tree at [1] if this helps you in any way.
> 
> [1] 
> https://git.kernel.org/cgit/linux/kernel/git/jth/linux.git/log/?h=scsi-bsg-rewrite-v4
> 

So I finally have a test system up and running. I have good and bad news. The
good news is, I can't get the system crashing with my patches, the bad news is
I can't get zfcp_ping and zfcp_show to output something but HBA_STATUS_ERROR
with my patches and without.

And btw, I renamed the branch to fc-bsg-rewrite-v4 in case you want to clone
from it (it has patch 2/16 changed to the v3 submission).

Can you please have a look with your setup?

Thanks,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Need some pointers to debug a target hang

2016-10-30 Thread Johannes Thumshirn
On Sat, Oct 29, 2016 at 03:53:25PM -0700, Nicholas A. Bellinger wrote:
> Hi Johannes & Zhu,
> 
> On Tue, 2016-10-18 at 23:29 -0700, Nicholas A. Bellinger wrote:
> > On Tue, 2016-10-18 at 19:35 +0200, Johannes Thumshirn wrote:
> > > On Tue, Oct 18, 2016 at 09:01:34AM +0200, Johannes Thumshirn wrote:
> > > 
> > > [...]
> > > 
> > > > > 
> > > > > This is likely the missing SCF_ACK_KREF assignment in >= v4.1.y:
> > > > > 
> > > > > http://www.spinics.net/lists/target-devel/msg13530.html
> > > 
> > > Sorry to disappoint you but it didn't fix my issue. Is there any debug 
> > > data I
> > > can give you, or do you have an advice where I could start looking?
> > > 
> > > I have to admit I only tested the patch on our downstream kernel and not 
> > > the
> > > upstream kernel, I'll repeat the tests on 4.8 final tomorrow.
> > > 
> > 
> > Is it possible to generate vmcore to have a look in crash + gdb..?
> > 
> > 
> 
> Just curious if you've been able to verify the above patch for
> v4.8.y iscsi-target ports on your specific config(s)..?
> 
> To confirm, using v4.1.y + patch I've not run into any further
> se_cmd->cmd_kref leaks and/or hung tasks with iscsi-target ports due to
> high backend device I/O latency, resulting in host timeouts + ABORT_TASK
> + session reinstatement to occur while waiting for outstanding se_cmd
> backend I/O to complete.

Unfortunately v4.8.5 which has above patch included (I double checked to be
sure) shows the same effects. 

Here's my "reproducer":

 VM1 (target)   VM2 (Initiator)
    ===
dd if=/dev/sda of=/dev/null bs=1 (given sda 
is the iscsi LUN)

Wait a little bit (~10 secs)

 dmsetup suspend dm-0
 watch -n1 'ps aux |\
  grep -E "\[iscsi" | grep -v grep'

I'll build a kernel with all target stuff builtin and full debug symbols.
Let's see if I can find out something.

Thanks,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 09/12] SRP transport: Move queuecommand() wait code to SCSI core

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:55:00PM -0700, Bart Van Assche wrote:
> Additionally, rename srp_wait_for_queuecommand() into
> scsi_wait_for_queuecommand() and add a comment about the
> queuecommand() call from scsi_send_eh_cmnd().
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Reviewed-by: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/12] blk-mq: Add a kick_requeue_list argument to blk_mq_requeue_request()

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:53:39PM -0700, Bart Van Assche wrote:
> Most blk_mq_requeue_request() and blk_mq_add_to_requeue_list() calls
> are followed by kicking the requeue list. Hence add an argument to
> these two functions that allows to kick the requeue list. This was
> proposed by Christoph Hellwig.
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Cc: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/4] hpsa: correct lockup detector pci_disable_device

2016-10-27 Thread Johannes Thumshirn
On Thu, Oct 27, 2016 at 11:01:41AM +0200, Hannes Reinecke wrote:
> On 10/27/2016 12:21 AM, Don Brace wrote:
> > need to check if the device is already disabled first
> > 
> > Reviewed-by: Scott Benesh <scott.ben...@microsemi.com>
> > Reviewed-by: Scott Teel <scott.t...@microsemi.com>
> > Signed-off-by: Don Brace <don.br...@microsemi.com>
> > ---
> >  drivers/scsi/hpsa.c |3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
> > index d007ec1..798fb20 100644
> > --- a/drivers/scsi/hpsa.c
> > +++ b/drivers/scsi/hpsa.c
> > @@ -8456,7 +8456,8 @@ static void controller_lockup_detected(struct 
> > ctlr_info *h)
> > spin_unlock_irqrestore(>lock, flags);
> > dev_warn(>pdev->dev, "Controller lockup detected: 0x%08x after %d\n",
> > lockup_detected, h->heartbeat_sample_interval / HZ);
> > -   pci_disable_device(h->pdev);
> > +   if (pci_is_enabled(h->pdev))
> > +   pci_disable_device(h->pdev);
> > fail_all_outstanding_cmds(h);
> >  }
> >  
> > 
> Meh.
> Why is pci_disable_device() not checking for it?

It does:
1607 void pci_disable_device(struct pci_dev *dev)
1608 {
[...]
1615 dev_WARN_ONCE(>dev, atomic_read(>enable_cnt) <= 0,
1616   "disabling already-disabled device");
[...]
1624 }
1625 EXPORT_SYMBOL(pci_disable_device);

Which is the motivation behind this patch I think.

Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 03/12] blk-mq: Introduce blk_mq_queue_stopped()

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:52:05PM -0700, Bart Van Assche wrote:
> The function blk_queue_stopped() allows to test whether or not a
> traditional request queue has been stopped. Introduce a helper
> function that allows block drivers to query easily whether or not
> one or more hardware contexts of a blk-mq queue have been stopped.
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Reviewed-by: Hannes Reinecke <h...@suse.com>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 07/12] dm: Use BLK_MQ_S_STOPPED instead of QUEUE_FLAG_STOPPED in blk-mq code

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:54:07PM -0700, Bart Van Assche wrote:
> Instead of manipulating both QUEUE_FLAG_STOPPED and BLK_MQ_S_STOPPED
> in the dm start and stop queue functions, only manipulate the latter
> flag. Change blk_queue_stopped() tests into blk_mq_queue_stopped().
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Reviewed-by: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 10/12] SRP transport, scsi-mq: Wait for .queue_rq() if necessary

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:55:34PM -0700, Bart Van Assche wrote:
> Ensure that if scsi-mq is enabled that scsi_wait_for_queuecommand()
> waits until ongoing shost->hostt->queuecommand() calls have finished.
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Reviewed-by: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/12] blk-mq: Introduce blk_mq_hctx_stopped()

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:51:33PM -0700, Bart Van Assche wrote:
> Multiple functions test the BLK_MQ_S_STOPPED bit so introduce
> a helper function that performs this test.
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Cc: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 04/12] blk-mq: Move more code into blk_mq_direct_issue_request()

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:52:35PM -0700, Bart Van Assche wrote:
> Move the "hctx stopped" test and the insert request calls into
> blk_mq_direct_issue_request(). Rename that function into
> blk_mq_try_issue_directly() to reflect its new semantics. Pass
> the hctx pointer to that function instead of looking it up a
> second time. These changes avoid that code has to be duplicated
> in the next patch.
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Cc: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 04/12] blk-mq: Move more code into blk_mq_direct_issue_request()

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:52:35PM -0700, Bart Van Assche wrote:
> Move the "hctx stopped" test and the insert request calls into
> blk_mq_direct_issue_request(). Rename that function into
> blk_mq_try_issue_directly() to reflect its new semantics. Pass
> the hctx pointer to that function instead of looking it up a
> second time. These changes avoid that code has to be duplicated
> in the next patch.
> 
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Cc: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/12] blk-mq: Do not invoke .queue_rq() for a stopped queue

2016-10-27 Thread Johannes Thumshirn
On Wed, Oct 26, 2016 at 03:50:44PM -0700, Bart Van Assche wrote:
> The meaning of the BLK_MQ_S_STOPPED flag is "do not call
> .queue_rq()". Hence modify blk_mq_make_request() such that requests
> are queued instead of issued if a queue has been stopped.
> 
> Reported-by: Ming Lei <tom.leim...@gmail.com>
> Signed-off-by: Bart Van Assche <bart.vanass...@sandisk.com>
> Reviewed-by: Christoph Hellwig <h...@lst.de>

Looks good,
Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Avoid that SCSI device removal through sysfs triggers a deadlock

2016-10-28 Thread Johannes Thumshirn
On Thu, Oct 27, 2016 at 08:38:03AM -0700, Bart Van Assche wrote:
> On 10/27/2016 02:46 AM, Johannes Thumshirn wrote:
> > On Wed, Oct 26, 2016 at 11:44:51AM -0700, Bart Van Assche wrote:
> > > +static void scsi_remove_device_async(struct scsi_device *sdev)
> > > +{
> > > + if (scsi_device_get(sdev) < 0)
> > 
> > Nit: the < 0 could be dropped, scsi_device_get returns either -ENXIO or
> > 0. But no reason to respin.
> > 
> > Anyways,
> > Reviewed-by: Johannes Thumshirn <jthumsh...@suse.de>
> 
> Hello Johannes,
> 
> Thanks for the review. But I'd like to clarify that I added the "< 0" on
> purpose. Some *_get*() functions in the Linux kernel return 0 upon failure
> (e.g. kref_get_unless_zero()) and others a negative value (e.g.
> scsi_device_get()). The "< 0" part avoids that someone who reads this code
> has to look up what return value convention scsi_device_get() uses.

OK, that makes sense to me.

Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-30 Thread Johannes Thumshirn
On Fri, Oct 28, 2016 at 11:53:46AM +0200, Steffen Maier wrote:

[...]

> > > 
> > > > @@ -3937,6 +3944,7 @@ fc_bsg_request_handler(struct request_queue *q, 
> > > > struct Scsi_Host *shost,
> > > > struct request *req;
> > > > struct fc_bsg_job *job;
> > > > enum fc_dispatch_result ret;
> > > > +   struct fc_bsg_reply *bsg_reply;
> > > > 
> > > > if (!get_device(dev))
> > > > return;
> > > > @@ -3973,8 +3981,9 @@ fc_bsg_request_handler(struct request_queue *q, 
> > > > struct Scsi_Host *shost,
> > > > /* check if we have the msgcode value at least */
> > > > if (job->request_len < sizeof(uint32_t)) {
> > > > BUG_ON(job->reply_len < sizeof(uint32_t));
> > > > -   job->reply->reply_payload_rcv_len = 0;
> > > > -   job->reply->result = -ENOMSG;
> > > > +   bsg_reply = job->reply;
> > > > +   bsg_reply->reply_payload_rcv_len = 0;
> > > > +   bsg_reply->result = -ENOMSG;
> 
> Compiler optimization re-ordered above two lines and the first pointer
> derefence is bsg_reply->result [field offset 0] where bsg_reply is NULL.
> The assignment tries to write to memory at address NULL causing the kernel
> page fault.
> 
> Does your suggested change for [PATCH v3 02/16], shuffling the
> job->request_len checks, address above kernel page fault?

This is what I hope at least. I'm sorry but I don't have any experience with 
s390
and zfcp at all. I still need to get a test environment set up, but all the
people knowing how to do are rather busy at the moment. All my tests on x86_64
with FCoE and lpfc haven't had a problem so far.

Thanks,
Johannes
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 33/44] scsi: libfc: don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone() as
fc_bsg_jobdone() calls blk_complete_requeust() which raises a soft-IRQ that
ends up in fc_bsg_sofirq_done() and fc_bsg_softirq_done() sets the
FC_RQST_STATE_DONE flag.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/libfc/fc_lport.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 156708a..53d13721 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1911,7 +1911,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   job->state_flags |= FC_RQST_STATE_DONE;
fc_bsg_jobdone(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
@@ -1947,7 +1946,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   job->state_flags |= FC_RQST_STATE_DONE;
fc_bsg_jobdone(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 29/44] qla2xxx: use fc_bsg_to_rport() to access a bsg_job's rport

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/qla2xxx/qla_bsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 109b852..917eafe 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -264,7 +264,7 @@ qla2x00_process_els(struct fc_bsg_job *bsg_job)
uint16_t nextlid = 0;
 
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
-   rport = bsg_job->rport;
+   rport = fc_bsg_to_rport(bsg_job);
fcport = *(fc_port_t **) rport->dd_data;
host = rport_to_shost(rport);
vha = shost_priv(host);
@@ -2485,7 +2485,7 @@ qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
bsg_reply->reply_payload_rcv_len = 0;
 
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
-   rport = bsg_job->rport;
+   rport = fc_bsg_to_rport(bsg_job);
host = rport_to_shost(rport);
vha = shost_priv(host);
} else {
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/44] scsi: fc: remove job_done method from struct fc_bsg_job

2016-10-11 Thread Johannes Thumshirn
Now that we've converted all LLDDs over to use fc_bsg_jobdone() directly,
remove the function pointer from struct fc_bsg_job.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 1 -
 include/scsi/scsi_transport_fc.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index b0ce417..4149dac 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3744,7 +3744,6 @@ fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport 
*rport,
if (ret)
goto failjob_rls_rqst_payload;
}
-   job->job_done = fc_bsg_jobdone;
if (rport)
job->dev = >dev;
else
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index f90044a..9ef583f 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -637,7 +637,6 @@ struct fc_bsg_job {
spinlock_t job_lock;
unsigned int state_flags;
unsigned int ref_cnt;
-   void (*job_done)(struct fc_bsg_job *);
 
struct fc_bsg_request *request;
struct fc_bsg_reply *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/44] bfa: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/bfa/bfad_bsg.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index e49a6c8..d3094270 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3135,8 +3135,7 @@ bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
struct request_queue *request_q = job->req->q;
void *payload_kbuf;
@@ -3358,8 +3357,7 @@ int
 bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
 {
struct bfa_bsg_data *bsg_data;
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
bfa_bsg_fcpt_t *bsg_fcpt;
struct bfad_fcxp*drv_fcxp;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 23/44] libfc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/libfc/fc_lport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 4bed7ec..c60fdb9 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2087,7 +2087,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
struct request *rsp = job->req->next_rq;
-   struct Scsi_Host *shost = job->shost;
+   struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_lport *lport = shost_priv(shost);
struct fc_rport *rport;
struct fc_rport_priv *rdata;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 30/44] lpfc: use fc_bsg_to_rport() to access a bsg_job's rport

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/lpfc/lpfc_bsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index bfcc37d..dae7cc3 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -386,7 +386,7 @@ lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_reply *bsg_reply = job->reply;
struct ulp_bde64 *bpl = NULL;
@@ -660,7 +660,7 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 25/44] zfcp: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 87f6330..813c286 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -905,7 +905,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
-   adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
+   adapter = shost_priv(fc_bsg_to_shost(job));
 
switch (gs_type) {
case FC_FST_ALIAS:
@@ -987,7 +987,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
 
-   shost = job->rport ? rport_to_shost(job->rport) : job->shost;
+   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 24/44] ibmvfc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/ibmvscsi/ibmvfc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 1001d4a..f7b50af 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1702,7 +1702,7 @@ static void ibmvfc_bsg_timeout_done(struct ibmvfc_event 
*evt)
  **/
 static int ibmvfc_bsg_timeout(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
unsigned long port_id = (unsigned long)job->dd_data;
struct ibmvfc_event *evt;
struct ibmvfc_tmf *tmf;
@@ -1815,7 +1815,7 @@ unlock_out:
  **/
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
struct fc_rport *rport = job->rport;
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 34/44] scsi: fc: implement kref backed reference counting

2016-10-11 Thread Johannes Thumshirn
Implement kref backed reference counting instead of rolling our own. This
elimnates the need of the following fields in 'struct fc_bsg_job':
* ref_cnt
* state_flags
* job_lock
bringing us close to unification of 'struct fc_bsg_job' and 'struct bsg_job'.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 38 +-
 include/scsi/scsi_transport_fc.h |  4 +---
 2 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 96b3a2e..b0e28af 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3560,16 +3560,9 @@ fc_vport_sched_delete(struct work_struct *work)
  * @job:   fc_bsg_job that is to be torn down
  */
 static void
-fc_destroy_bsgjob(struct fc_bsg_job *job)
+fc_destroy_bsgjob(struct kref *kref)
 {
-   unsigned long flags;
-
-   spin_lock_irqsave(>job_lock, flags);
-   if (job->ref_cnt) {
-   spin_unlock_irqrestore(>job_lock, flags);
-   return;
-   }
-   spin_unlock_irqrestore(>job_lock, flags);
+   struct fc_bsg_job *job = container_of(kref, struct fc_bsg_job, kref);
 
put_device(job->dev);   /* release reference for the request */
 
@@ -3620,15 +3613,9 @@ EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
 static void fc_bsg_softirq_done(struct request *rq)
 {
struct fc_bsg_job *job = rq->special;
-   unsigned long flags;
-
-   spin_lock_irqsave(>job_lock, flags);
-   job->state_flags |= FC_RQST_STATE_DONE;
-   job->ref_cnt--;
-   spin_unlock_irqrestore(>job_lock, flags);
 
blk_end_request_all(rq, rq->errors);
-   fc_destroy_bsgjob(job);
+   kref_put(>kref, fc_destroy_bsgjob);
 }
 
 /**
@@ -3642,24 +3629,18 @@ fc_bsg_job_timeout(struct request *req)
struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_internal *i = to_fc_internal(shost->transportt);
-   unsigned long flags;
-   int err = 0, done = 0;
+   int err = 0, inflight = 0;
 
if (rport && rport->port_state == FC_PORTSTATE_BLOCKED)
return BLK_EH_RESET_TIMER;
 
-   spin_lock_irqsave(>job_lock, flags);
-   if (job->state_flags & FC_RQST_STATE_DONE)
-   done = 1;
-   else
-   job->ref_cnt++;
-   spin_unlock_irqrestore(>job_lock, flags);
+   inflight = kref_get_unless_zero(>kref);
 
-   if (!done && i->f->bsg_timeout) {
+   if (inflight && i->f->bsg_timeout) {
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   job->ref_cnt--;
+   kref_put(>kref, fc_destroy_bsgjob);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
@@ -3667,7 +3648,7 @@ fc_bsg_job_timeout(struct request *req)
}
 
/* the blk_end_sync_io() doesn't check the error */
-   if (done)
+   if (!inflight)
return BLK_EH_NOT_HANDLED;
else
return BLK_EH_HANDLED;
@@ -3730,7 +3711,6 @@ fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport 
*rport,
job->req = req;
if (i->f->dd_bsg_size)
job->dd_data = (void *)[1];
-   spin_lock_init(>job_lock);
bsg_request = (struct fc_bsg_request *)req->cmd;
job->request_len = req->cmd_len;
bsg_reply = req->sense;
@@ -3752,7 +3732,7 @@ fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport 
*rport,
job->dev = >shost_gendev;
get_device(job->dev);   /* take a reference for the request */
 
-   job->ref_cnt = 1;
+   kref_init(>kref);
 
return 0;
 
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index 9f53fe3..8ae5680 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -634,9 +634,7 @@ struct fc_bsg_job {
struct fc_rport *rport;
struct device *dev;
struct request *req;
-   spinlock_t job_lock;
-   unsigned int state_flags;
-   unsigned int ref_cnt;
+   struct kref kref;
 
struct fc_bsg_request *request;
struct fc_bsg_reply *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 32/44] ibmvfc: use fc_bsg_to_rport() to access a bsg_job's rport

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/ibmvscsi/ibmvfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index f7b50af..35114d9 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1816,7 +1816,7 @@ unlock_out:
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
union ibmvfc_iu rsp_iu;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 28/44] zfcp: use fc_bsg_to_rport() to access a bsg_job's rport

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 813c286..1977a66 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -938,7 +938,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
@@ -986,8 +986,9 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
 
-   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
+   shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 21/44] lpfc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/lpfc/lpfc_bsg.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 447a7af..bfcc37d 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -384,7 +384,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
 static int
 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
struct lpfc_rport_data *rdata = job->rport->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
@@ -658,7 +658,7 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
 static int
 lpfc_bsg_rport_els(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
struct lpfc_rport_data *rdata = job->rport->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
@@ -1202,7 +1202,7 @@ lpfc_bsg_ct_unsol_abort(struct lpfc_hba *phba, struct 
hbq_dmabuf *dmabuf)
 static int
 lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
struct fc_bsg_request *bsg_request = job->request;
struct set_ct_event *event_req;
@@ -1287,7 +1287,7 @@ job_error:
 static int
 lpfc_bsg_hba_get_event(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -1625,7 +1625,7 @@ no_dd_data:
 static int
 lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -2201,10 +2201,10 @@ lpfc_bsg_diag_loopback_mode(struct fc_bsg_job *job)
struct lpfc_hba *phba;
int rc;
 
-   shost = job->shost;
+   shost = fc_bsg_to_shost(job);
if (!shost)
return -ENODEV;
-   vport = (struct lpfc_vport *)job->shost->hostdata;
+   vport = shost_priv(shost);
if (!vport)
return -ENODEV;
phba = vport->phba;
@@ -2241,10 +2241,10 @@ lpfc_sli4_bsg_diag_mode_end(struct fc_bsg_job *job)
uint32_t timeout;
int rc, i;
 
-   shost = job->shost;
+   shost = fc_bsg_to_shost(job);
if (!shost)
return -ENODEV;
-   vport = (struct lpfc_vport *)job->shost->hostdata;
+   vport = shost_priv(shost);
if (!vport)
return -ENODEV;
phba = vport->phba;
@@ -2325,12 +2325,12 @@ lpfc_sli4_bsg_link_diag_test(struct fc_bsg_job *job)
struct diag_status *diag_status_reply;
int mbxstatus, rc = 0;
 
-   shost = job->shost;
+   shost = fc_bsg_to_shost(job);
if (!shost) {
rc = -ENODEV;
goto job_error;
}
-   vport = (struct lpfc_vport *)job->shost->hostdata;
+   vport = shost_priv(shost);
if (!vport) {
rc = -ENODEV;
goto job_error;
@@ -3018,7 +3018,7 @@ err_post_rxbufs_exit:
 static int
 lpfc_bsg_diag_loopback_run(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct fc_bsg_reply *bsg_reply = job->reply;
struct lpfc_hba *phba = vport->phba;
struct lpfc_bsg_event *evt;
@@ -3322,7 +3322,7 @@ loopback_test_exit:
 static int
 lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct fc_bsg_reply *bsg_reply = job->reply;
struct lpfc_hba *phba = vport->phba;
struct get_mgmt_rev_reply *event_reply;
@@ -4933,7 +4933,7 @@ job_cont:
 static int
 lpfc_bsg_mbox_cmd(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct fc_bsg_reques

[PATCH 19/44] scsi: fc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 9744476..d6d18ce 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3639,7 +3639,7 @@ static enum blk_eh_timer_return
 fc_bsg_job_timeout(struct request *req)
 {
struct fc_bsg_job *job = (void *) req->special;
-   struct Scsi_Host *shost = job->shost;
+   struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_internal *i = to_fc_internal(shost->transportt);
unsigned long flags;
int err = 0, done = 0;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/44] scsi: fc: Export fc_bsg_jobdone

2016-10-11 Thread Johannes Thumshirn
Export fc_bsg_jobdone so drivers can use it directly instead of doing
the round-trip via struct fc_bsg_job::job_done().

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 4 ++--
 include/scsi/scsi_transport_fc.h | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index eafc7555..b0ce417 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3583,8 +3583,7 @@ fc_destroy_bsgjob(struct fc_bsg_job *job)
  *  completed
  * @job:   fc_bsg_job that is complete
  */
-static void
-fc_bsg_jobdone(struct fc_bsg_job *job)
+void fc_bsg_jobdone(struct fc_bsg_job *job)
 {
struct request *req = job->req;
struct request *rsp = req->next_rq;
@@ -3611,6 +3610,7 @@ fc_bsg_jobdone(struct fc_bsg_job *job)
}
blk_complete_request(req);
 }
+EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
 
 /**
  * fc_bsg_softirq_done - softirq done routine for destroying the bsg requests
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index 921b097..f90044a 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -842,5 +842,6 @@ struct fc_vport *fc_vport_create(struct Scsi_Host *shost, 
int channel,
struct fc_vport_identifiers *);
 int fc_vport_terminate(struct fc_vport *vport);
 int fc_block_scsi_eh(struct scsi_cmnd *cmnd);
+void fc_bsg_jobdone(struct fc_bsg_job *job);
 
 #endif /* SCSI_TRANSPORT_FC_H */
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 27/44] scsi: fc: use fc_bsg_to_rport() to access a bsg_job's rport

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index d6d18ce..96b3a2e 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3640,11 +3640,12 @@ fc_bsg_job_timeout(struct request *req)
 {
struct fc_bsg_job *job = (void *) req->special;
struct Scsi_Host *shost = fc_bsg_to_shost(job);
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_internal *i = to_fc_internal(shost->transportt);
unsigned long flags;
int err = 0, done = 0;
 
-   if (job->rport && job->rport->port_state == FC_PORTSTATE_BLOCKED)
+   if (rport && rport->port_state == FC_PORTSTATE_BLOCKED)
return BLK_EH_RESET_TIMER;
 
spin_lock_irqsave(>job_lock, flags);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 26/44] scsi: fc: provide fc_bsg_to_rport() helper

2016-10-11 Thread Johannes Thumshirn
Provide fc_bsg_to_rport() helper that will become handy when we're moving
from struct fc_bsg_job to a plain struct bsg_job.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 include/scsi/scsi_transport_fc.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index efb9488..9f53fe3 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -824,6 +824,11 @@ static inline struct Scsi_Host *fc_bsg_to_shost(struct 
fc_bsg_job *job)
return job->shost;
 }
 
+static inline struct fc_rport *fc_bsg_to_rport(struct fc_bsg_job *job)
+{
+   return job->rport;
+}
+
 struct scsi_transport_template *fc_attach_transport(
struct fc_function_template *);
 void fc_release_transport(struct scsi_transport_template *);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/44] qla2xxx: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/qla2xxx/qla_bsg.c | 54 +-
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 9293d5a..109b852 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1,4 +1,4 @@
-/*
+   /*
  * QLogic Fibre Channel HBA Driver
  * Copyright (c)  2003-2014 QLogic Corporation
  *
@@ -122,7 +122,7 @@ qla24xx_fcp_prio_cfg_valid(scsi_qla_host_t *vha,
 static int
 qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
 {
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(host);
@@ -271,7 +271,7 @@ qla2x00_process_els(struct fc_bsg_job *bsg_job)
ha = vha->hw;
type = "FC_BSG_RPT_ELS";
} else {
-   host = bsg_job->shost;
+   host = fc_bsg_to_shost(bsg_job);
vha = shost_priv(host);
ha = vha->hw;
type = "FC_BSG_HST_ELS_NOLOGIN";
@@ -432,7 +432,7 @@ qla2x00_process_ct(struct fc_bsg_job *bsg_job)
 {
srb_t *sp;
struct fc_bsg_request *bsg_request = bsg_job->request;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = (DRIVER_ERROR << 16);
@@ -710,7 +710,7 @@ qla2x00_process_loopback(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval;
@@ -950,7 +950,7 @@ static int
 qla84xx_reset(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_request *bsg_request = bsg_job->request;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
@@ -987,7 +987,7 @@ qla84xx_updatefw(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct verify_chip_entry_84xx *mn = NULL;
@@ -1099,7 +1099,7 @@ qla84xx_mgmt_cmd(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
struct access_chip_84xx *mn = NULL;
@@ -1297,7 +1297,7 @@ qla24xx_iidma(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_request *bsg_request = bsg_job->request;
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
int rval = 0;
struct qla_port_param *port_param = NULL;
@@ -1455,7 +1455,7 @@ static int
 qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
@@ -1492,7 +1492,7 @@ static int
 qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval = 0;
@@ -1528,7 +1528,7 @@ static int
 qla2x00_update_fru_versions(struct fc_bsg_job *bsg_job)
 {
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
-   struct Scsi_Host *host = bsg_job->shost;
+   struct Scsi_Host *host = fc_bsg_to_shost(bsg_job);
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int rval

[PATCH 31/44] libfc: use fc_bsg_to_rport() to access a bsg_job's rport

2016-10-11 Thread Johannes Thumshirn
Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/libfc/fc_lport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index c60fdb9..156708a 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2102,7 +2102,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
 
switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
@@ -2112,7 +2112,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
break;
 
case FC_BSG_RPT_CT:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 35/44] block: add reference counting for struct bsg_job

2016-10-11 Thread Johannes Thumshirn
Add reference counting to 'struct bsg_job' so we can implement a reuqest
timeout handler for bsg_jobs, which is needed for Fibre Channel.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 block/bsg-lib.c | 7 +--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,8 +32,10 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct bsg_job *job)
+static void bsg_destroy_job(struct kref *kref)
 {
+   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+
put_device(job->dev);   /* release reference for the request */
 
kfree(job->request_payload.sg_list);
@@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq)
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
-   bsg_destroy_job(job);
+   kref_put(>kref, bsg_destroy_job);
 }
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
@@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct 
request *req)
job->dev = dev;
/* take a reference for the request */
get_device(job->dev);
+   kref_init(>kref);
return 0;
 
 failjob_rls_rqst_payload:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -40,6 +40,8 @@ struct bsg_job {
struct device *dev;
struct request *req;
 
+   struct kref kref;
+
/* Transport/driver specific request/reply structs */
void *request;
void *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 38/44] scsi: fc: Use bsg_destroy_job

2016-10-11 Thread Johannes Thumshirn
fc_destroy_bsgjob() and bsg_destroy_job() are now 1:1 copies, so use the
later.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 20 ++--
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index a0e150a..4b9324f 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3554,23 +3555,6 @@ fc_vport_sched_delete(struct work_struct *work)
  * BSG support
  */
 
-
-/**
- * fc_destroy_bsgjob - routine to teardown/delete a fc bsg job
- * @job:   fc_bsg_job that is to be torn down
- */
-static void
-fc_destroy_bsgjob(struct kref *kref)
-{
-   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
-
-   put_device(job->dev);   /* release reference for the request */
-
-   kfree(job->request_payload.sg_list);
-   kfree(job->reply_payload.sg_list);
-   kfree(job);
-}
-
 /**
  * fc_bsg_jobdone - completion routine for bsg requests that the LLD has
  *  completed
@@ -3640,7 +3624,7 @@ fc_bsg_job_timeout(struct request *req)
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   kref_put(>kref, fc_destroy_bsgjob);
+   kref_put(>kref, bsg_destroy_job);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/44] ibmvfc: Use fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Use fc_bsg_jobdone() directly instead of the struct bsg_job::job_done()
callback.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/ibmvscsi/ibmvfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 8b55279..21c9d28 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1939,7 +1939,7 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/44] libfc: Use fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Use fc_bsg_jobdone() directly instead of the struct bsg_job::job_done()
callback.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/libfc/fc_lport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index a1c12e7..8811fe0 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1912,7 +1912,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
kfree(info);
return;
}
@@ -1947,7 +1947,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
kfree(info);
}
fc_frame_free(fp);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/44] lpfc: Use fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Use fc_bsg_jobdone() directly instead of the struct bsg_job::job_done()
callback.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/lpfc/lpfc_bsg.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 27b5930..1db9cca 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -644,7 +644,7 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -1136,7 +1136,7 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct 
lpfc_sli_ring *pring,
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(>ct_ev_lock, flags);
-   job->job_done(job);
+   fc_bsg_jobdone(job);
spin_lock_irqsave(>ct_ev_lock, flags);
}
}
@@ -1361,7 +1361,7 @@ lpfc_bsg_hba_get_event(struct fc_bsg_job *job)
spin_unlock_irqrestore(>ct_ev_lock, flags);
job->dd_data = NULL;
bsg_reply->result = 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return 0;
 
 job_error:
@@ -1458,7 +1458,7 @@ lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -1886,7 +1886,7 @@ job_error:
bsg_reply->result = rc;
/* complete the job back to userspace if no error */
if (rc == 0)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 }
 
@@ -2175,7 +2175,7 @@ job_error:
bsg_reply->result = rc;
/* complete the job back to userspace if no error */
if (rc == 0)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 }
 
@@ -2289,7 +2289,7 @@ loopback_mode_end_exit:
bsg_reply->result = rc;
/* complete the job back to userspace if no error */
if (rc == 0)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 }
 
@@ -2441,7 +2441,7 @@ job_error:
bsg_reply->result = rc;
/* complete the job back to userspace if no error */
if (rc == 0)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 }
 
@@ -3301,7 +3301,7 @@ loopback_test_exit:
job->dd_data = NULL;
/* complete the job back to userspace if no error */
if (rc == IOCB_SUCCESS)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 }
 
@@ -3344,7 +3344,7 @@ lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job)
 job_error:
bsg_reply->result = rc;
if (rc == 0)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 }
 
@@ -3409,7 +3409,7 @@ lpfc_bsg_issue_mbox_cmpl(struct lpfc_hba *phba, 
LPFC_MBOXQ_t *pmboxq)
 
if (job) {
bsg_reply->result = 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -3655,7 +3655,7 @@ lpfc_bsg_issue_read_mbox_ext_cmpl(struct lpfc_hba *phba, 
LPFC_MBOXQ_t *pmboxq)
 
/* if the job is still active, call job done */
if (job)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 
return;
 }
@@ -3690,7 +3690,7 @@ lpfc_bsg_issue_write_mbox_ext_cmpl(struct lpfc_hba *phba, 
LPFC_MBOXQ_t *pmboxq)
 
/* if the job is still active, call job done */
if (job)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 
return;
 }
@@ -4131,7 +4131,7 @@ lpfc_bsg_sli_cfg_write_cmd_ext(struct lpfc_hba *phba, 
struct fc_bsg_job *job,
/* wait for additoinal external buffers */
 
bsg_reply->result = 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return SLI_CONFIG_HANDLED;
 
 job_error:
@@ -4357,7 +4357,7 @@ lpfc_bsg_read_ebuf_get(struct lpfc_hba *phba, struct 
fc_bsg_job *job)
}
 
bsg_reply->result = 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 
return SLI_CONFIG_HANDLED;
 }
@@ -4473,7 +4473,7 @@ lpfc_bsg_write_ebuf_set(struct lpfc_hba *phba, struct 
fc_bsg_job *job,
 
/* wait for additoinal external buffers */
bsg_reply->result = 0;
-   job->job_done(job);
+   fc

[PATCH 18/44] scsi: fc: provide fc_bsg_to_shost() helper

2016-10-11 Thread Johannes Thumshirn
Provide fc_bsg_to_shost() helper that will become handy when we're moving from
struct fc_bsg_job to a plain struct bsg_job.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 include/scsi/scsi_transport_fc.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index eca8ed7..efb9488 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -819,6 +819,11 @@ fc_vport_set_state(struct fc_vport *vport, enum 
fc_vport_state new_state)
vport->vport_state = new_state;
 }
 
+static inline struct Scsi_Host *fc_bsg_to_shost(struct fc_bsg_job *job)
+{
+   return job->shost;
+}
+
 struct scsi_transport_template *fc_attach_transport(
struct fc_function_template *);
 void fc_release_transport(struct scsi_transport_template *);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/44] scsi: Get rid of struct fc_bsg_buffer

2016-10-11 Thread Johannes Thumshirn
struct fc_bsg_buffer is just a clone of struct bsg_buffer from bsg-lib,
so use this one instead.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/lpfc/lpfc_bsg.c |  3 ++-
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h | 12 +++-
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 05dcc2a..1002627 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -211,7 +212,7 @@ lpfc_alloc_bsg_buffers(struct lpfc_hba *phba, unsigned int 
size,
 
 static unsigned int
 lpfc_bsg_copy_data(struct lpfc_dmabuf *dma_buffers,
-  struct fc_bsg_buffer *bsg_buffers,
+  struct bsg_buffer *bsg_buffers,
   unsigned int bytes_to_transfer, int to_buffers)
 {
 
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 0f3a386..8ff2067 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3671,7 +3671,7 @@ fc_bsg_job_timeout(struct request *req)
 }
 
 static int
-fc_bsg_map_buffer(struct fc_bsg_buffer *buf, struct request *req)
+fc_bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments);
 
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index bf66ea6..921b097 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -28,6 +28,7 @@
 #define SCSI_TRANSPORT_FC_H
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -624,13 +625,6 @@ struct fc_host_attrs {
 #define fc_host_dev_loss_tmo(x) \
(((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
 
-
-struct fc_bsg_buffer {
-   unsigned int payload_len;
-   int sg_cnt;
-   struct scatterlist *sg_list;
-};
-
 /* Values for fc_bsg_job->state_flags (bitflags) */
 #define FC_RQST_STATE_INPROGRESS   0
 #define FC_RQST_STATE_DONE 1
@@ -659,8 +653,8 @@ struct fc_bsg_job {
 */
 
/* DMA payloads for the request/response */
-   struct fc_bsg_buffer request_payload;
-   struct fc_bsg_buffer reply_payload;
+   struct bsg_buffer request_payload;
+   struct bsg_buffer reply_payload;
 
void *dd_data;  /* Used for driver-specific storage */
 };
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/44] scsi: fc: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 37 +++--
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 8ff2067..eafc7555 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3588,9 +3588,10 @@ fc_bsg_jobdone(struct fc_bsg_job *job)
 {
struct request *req = job->req;
struct request *rsp = req->next_rq;
+   struct fc_bsg_reply *bsg_reply = job->reply;
int err;
 
-   err = job->req->errors = job->reply->result;
+   err = job->req->errors = bsg_reply->result;
 
if (err < 0)
/* we're only returning the result field in the reply */
@@ -3602,10 +3603,10 @@ fc_bsg_jobdone(struct fc_bsg_job *job)
req->resid_len = 0;
 
if (rsp) {
-   WARN_ON(job->reply->reply_payload_rcv_len > rsp->resid_len);
+   WARN_ON(bsg_reply->reply_payload_rcv_len > rsp->resid_len);
 
/* set reply (bidi) residual */
-   rsp->resid_len -= min(job->reply->reply_payload_rcv_len,
+   rsp->resid_len -= min(bsg_reply->reply_payload_rcv_len,
  rsp->resid_len);
}
blk_complete_request(req);
@@ -3701,6 +3702,8 @@ fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport 
*rport,
struct fc_internal *i = to_fc_internal(shost->transportt);
struct request *rsp = req->next_rq;
struct fc_bsg_job *job;
+   struct fc_bsg_request *bsg_request;
+   struct fc_bsg_reply *bsg_reply;
int ret;
 
BUG_ON(req->special);
@@ -3726,9 +3729,9 @@ fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport 
*rport,
if (i->f->dd_bsg_size)
job->dd_data = (void *)[1];
spin_lock_init(>job_lock);
-   job->request = (struct fc_bsg_request *)req->cmd;
+   bsg_request = (struct fc_bsg_request *)req->cmd;
job->request_len = req->cmd_len;
-   job->reply = req->sense;
+   bsg_reply = req->sense;
job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer
 * allocated */
if (req->bio) {
@@ -3779,11 +3782,13 @@ fc_bsg_host_dispatch(struct request_queue *q, struct 
Scsi_Host *shost,
 struct fc_bsg_job *job)
 {
struct fc_internal *i = to_fc_internal(shost->transportt);
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
int cmdlen = sizeof(uint32_t);  /* start with length of msgcode */
int ret;
 
/* Validate the host command */
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_HST_ADD_RPORT:
cmdlen += sizeof(struct fc_bsg_host_add_rport);
break;
@@ -3815,7 +3820,7 @@ fc_bsg_host_dispatch(struct request_queue *q, struct 
Scsi_Host *shost,
case FC_BSG_HST_VENDOR:
cmdlen += sizeof(struct fc_bsg_host_vendor);
if ((shost->hostt->vendor_id == 0L) ||
-   (job->request->rqst_data.h_vendor.vendor_id !=
+   (bsg_request->rqst_data.h_vendor.vendor_id !=
shost->hostt->vendor_id)) {
ret = -ESRCH;
goto fail_host_msg;
@@ -3840,8 +3845,8 @@ fc_bsg_host_dispatch(struct request_queue *q, struct 
Scsi_Host *shost,
 fail_host_msg:
/* return the errno failure code as the only status */
BUG_ON(job->reply_len < sizeof(uint32_t));
-   job->reply->reply_payload_rcv_len = 0;
-   job->reply->result = ret;
+   bsg_reply->reply_payload_rcv_len = 0;
+   bsg_reply->result = ret;
job->reply_len = sizeof(uint32_t);
fc_bsg_jobdone(job);
return FC_DISPATCH_UNLOCKED;
@@ -3878,11 +3883,13 @@ fc_bsg_rport_dispatch(struct request_queue *q, struct 
Scsi_Host *shost,
 struct fc_rport *rport, struct fc_bsg_job *job)
 {
struct fc_internal *i = to_fc_internal(shost->transportt);
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
int cmdlen = sizeof(uint32_t);  /* start with length of msgcode */
int ret;
 
/* Validate the rport command */
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
cmdlen += sizeof(stru

[PATCH 06/44] qla2xxx: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/qla2xxx/qla_bsg.c  | 264 +++-
 drivers/scsi/qla2xxx/qla_iocb.c |   5 +-
 drivers/scsi/qla2xxx/qla_isr.c  |  46 ---
 drivers/scsi/qla2xxx/qla_mr.c   |  10 +-
 4 files changed, 189 insertions(+), 136 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 643014f..40f7c10 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -17,8 +17,9 @@ qla2x00_bsg_job_done(void *data, void *ptr, int res)
srb_t *sp = (srb_t *)ptr;
struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
struct fc_bsg_job *bsg_job = sp->u.bsg_job;
+   struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 
-   bsg_job->reply->result = res;
+   bsg_reply->result = res;
bsg_job->job_done(bsg_job);
sp->free(vha, sp);
 }
@@ -29,12 +30,14 @@ qla2x00_bsg_sp_free(void *data, void *ptr)
srb_t *sp = (srb_t *)ptr;
struct scsi_qla_host *vha = sp->fcport->vha;
struct fc_bsg_job *bsg_job = sp->u.bsg_job;
+   struct fc_bsg_request *bsg_request = bsg_job->request;
+
struct qla_hw_data *ha = vha->hw;
struct qla_mt_iocb_rqst_fx00 *piocb_rqst;
 
if (sp->type == SRB_FXIOCB_BCMD) {
piocb_rqst = (struct qla_mt_iocb_rqst_fx00 *)
-   _job->request->rqst_data.h_vendor.vendor_cmd[1];
+   _request->rqst_data.h_vendor.vendor_cmd[1];
 
if (piocb_rqst->flags & SRB_FXDISC_REQ_DMA_VALID)
dma_unmap_sg(>pdev->dev,
@@ -119,6 +122,8 @@ static int
 qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
 {
struct Scsi_Host *host = bsg_job->shost;
+   struct fc_bsg_request *bsg_request = bsg_job->request;
+   struct fc_bsg_reply *bsg_reply = bsg_job->reply;
scsi_qla_host_t *vha = shost_priv(host);
struct qla_hw_data *ha = vha->hw;
int ret = 0;
@@ -131,7 +136,7 @@ qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
}
 
/* Get the sub command */
-   oper = bsg_job->request->rqst_data.h_vendor.vendor_cmd[1];
+   oper = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
 
/* Only set config is allowed if config memory is not allocated */
if (!ha->fcp_prio_cfg && (oper != QLFC_FCP_PRIO_SET_CONFIG)) {
@@ -145,10 +150,10 @@ qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
ha->fcp_prio_cfg->attributes &=
~FCP_PRIO_ATTR_ENABLE;
qla24xx_update_all_fcp_prio(vha);
-   bsg_job->reply->result = DID_OK;
+   bsg_reply->result = DID_OK;
} else {
ret = -EINVAL;
-   bsg_job->reply->result = (DID_ERROR << 16);
+   bsg_reply->result = (DID_ERROR << 16);
goto exit_fcp_prio_cfg;
}
break;
@@ -160,10 +165,10 @@ qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
ha->fcp_prio_cfg->attributes |=
FCP_PRIO_ATTR_ENABLE;
qla24xx_update_all_fcp_prio(vha);
-   bsg_job->reply->result = DID_OK;
+   bsg_reply->result = DID_OK;
} else {
ret = -EINVAL;
-   bsg_job->reply->result = (DID_ERROR << 16);
+   bsg_reply->result = (DID_ERROR << 16);
goto exit_fcp_prio_cfg;
}
}
@@ -173,12 +178,12 @@ qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
len = bsg_job->reply_payload.payload_len;
if (!len || len > FCP_PRIO_CFG_SIZE) {
ret = -EINVAL;
-   bsg_job->reply->result = (DID_ERROR << 16);
+   bsg_reply->result = (DID_ERROR << 16);
goto exit_fcp_prio_cfg;
}
 
-   bsg_job->reply->result = DID_OK;
-   bsg_job->reply->reply_payload_rcv_len =
+   bsg_reply->result = DID_OK;
+   bsg_reply->reply_payload_rcv_len =
sg_copy_from_buffer(
bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, ha->fcp_prio_cfg,

[PATCH 04/44] ibmvfc: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/ibmvscsi/ibmvfc.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index ab67ec4..8b55279 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1821,28 +1821,30 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
struct ibmvfc_event *evt;
union ibmvfc_iu rsp_iu;
unsigned long flags, port_id = -1;
-   unsigned int code = job->request->msgcode;
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   unsigned int code = bsg_request->msgcode;
int rc = 0, req_seg, rsp_seg, issue_login = 0;
u32 fc_flags, rsp_len;
 
ENTER;
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
if (rport)
port_id = rport->port_id;
 
switch (code) {
case FC_BSG_HST_ELS_NOLOGIN:
-   port_id = (job->request->rqst_data.h_els.port_id[0] << 16) |
-   (job->request->rqst_data.h_els.port_id[1] << 8) |
-   job->request->rqst_data.h_els.port_id[2];
+   port_id = (bsg_request->rqst_data.h_els.port_id[0] << 16) |
+   (bsg_request->rqst_data.h_els.port_id[1] << 8) |
+   bsg_request->rqst_data.h_els.port_id[2];
case FC_BSG_RPT_ELS:
fc_flags = IBMVFC_FC_ELS;
break;
case FC_BSG_HST_CT:
issue_login = 1;
-   port_id = (job->request->rqst_data.h_ct.port_id[0] << 16) |
-   (job->request->rqst_data.h_ct.port_id[1] << 8) |
-   job->request->rqst_data.h_ct.port_id[2];
+   port_id = (bsg_request->rqst_data.h_ct.port_id[0] << 16) |
+   (bsg_request->rqst_data.h_ct.port_id[1] << 8) |
+   bsg_request->rqst_data.h_ct.port_id[2];
case FC_BSG_RPT_CT:
fc_flags = IBMVFC_FC_CT_IU;
break;
@@ -1931,12 +1933,12 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
if (rsp_iu.passthru.common.status)
rc = -EIO;
else
-   job->reply->reply_payload_rcv_len = rsp_len;
+   bsg_reply->reply_payload_rcv_len = rsp_len;
 
spin_lock_irqsave(vhost->host->host_lock, flags);
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->job_done(job);
rc = 0;
 out:
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/44] zfcp: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 237688a..4c4023f 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -900,8 +900,9 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
u32 preamble_word1;
u8 gs_type;
struct zfcp_adapter *adapter;
+   struct fc_bsg_request *bsg_request = job->request;
 
-   preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
+   preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
@@ -938,6 +939,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
struct fc_rport *rport = job->rport;
+   struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
 
@@ -949,7 +951,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
d_id = port->d_id;
put_device(>dev);
} else
-   d_id = ntoh24(job->request->rqst_data.h_els.port_id);
+   d_id = ntoh24(bsg_request->rqst_data.h_els.port_id);
 
els->handler = zfcp_fc_ct_els_job_handler;
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
@@ -983,6 +985,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
+   struct fc_bsg_request *bsg_request = job->request;
 
shost = job->rport ? rport_to_shost(job->rport) : job->shost;
adapter = (struct zfcp_adapter *)shost->hostdata[0];
@@ -994,7 +997,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
ct_els->resp = job->reply_payload.sg_list;
ct_els->handler_data = job;
 
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
case FC_BSG_HST_ELS_NOLOGIN:
return zfcp_fc_exec_els_job(job, adapter);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/44] zfcp: Use fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Use fc_bsg_jobdone() directly instead of the struct bsg_job::job_done()
callback.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 4c4023f..40d8f06 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/44] bfa: Use fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Use fc_bsg_jobdone() directly instead of the struct bsg_job::job_done()
callback.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/bfa/bfad_bsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 48366d8..25889b9 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,7 @@ bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3556,7 @@ out:
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 
return rc;
 }
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/44] Convert FibreChannel bsg code to use bsg-lib

2016-10-11 Thread Johannes Thumshirn
This series converts the current bsg usage in the FibreChannel drivers over
to use bsg-lib. SAS will follow but 44 patches are big enough for one shot,
so I didn't want to include SAS in there as well.

It looks a bit huge but most of the patches are only code movement and slow
API conversions so everything still works and builds when doing git bisects.

I did take some inspiration from a similar patchset from Mike Christie
dating back to 2011 but it's not a 1:1 copy. Patch 43/44 is heavily based
on his series and attribution is given to him in the commit message.

It is currently regression tested on FCoE using the 'fcns' and
'fcrls'utilities.  I'm still trying to figure out how to test the other
LLDDs. So any pointer from the respective maintainers are appreciated
although the LLDD changes are purely mechanical. All they do is change from
'struct fc_bsg_job' to 'struct bsg_job' and corresponding changes in order
to get the series bisectable.

The idea for this change arose when discussing racy sysfs handling the FC
bsg code with Christoph and is a next step in moving all bsg clients to
bsg-lib to eventually clean up the in kernel bsg API.

Johannes Thumshirn (44):
  scsi: Get rid of struct fc_bsg_buffer
  bfa: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  zfcp: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  ibmvfc: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  lpfc: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  qla2xxx: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  libfc: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  scsi: fc: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  scsi: fc: Export fc_bsg_jobdone
  zfcp: Use fc_bsg_jobdone()
  bfa: Use fc_bsg_jobdone()
  ibmvfc: Use fc_bsg_jobdone()
  libfc: Use fc_bsg_jobdone()
  lpfc: Use fc_bsg_jobdone()
  qla2xxx: Use fc_bsg_jobdone()
  scsi: fc: remove job_done method from struct fc_bsg_job
  scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done
  scsi: fc: provide fc_bsg_to_shost() helper
  scsi: fc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  bfa: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  lpfc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  qla2xxx: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  libfc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  ibmvfc: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  zfcp: use fc_bsg_to_shost() to access a bsg_job's Scsi_Host
  scsi: fc: provide fc_bsg_to_rport() helper
  scsi: fc: use fc_bsg_to_rport() to access a bsg_job's rport
  zfcp: use fc_bsg_to_rport() to access a bsg_job's rport
  qla2xxx: use fc_bsg_to_rport() to access a bsg_job's rport
  lpfc: use fc_bsg_to_rport() to access a bsg_job's rport
  libfc: use fc_bsg_to_rport() to access a bsg_job's rport
  ibmvfc: use fc_bsg_to_rport() to access a bsg_job's rport
  scsi: libfc: don't set FC_RQST_STATE_DONE before calling
fc_bsg_jobdone()
  scsi: fc: implement kref backed reference counting
  block: add reference counting for struct bsg_job
  scsi: change FC drivers to use 'struct bsg_job'
  block: export bsg_destroy_job
  scsi: fc: Use bsg_destroy_job
  block: export bsg_softirq_done
  scsi: fc: use bsg_softirq_done
  scsi: fc: use bsg_job_done
  block: add bsg_job_put() and bsg_job_get()
  scsi: fc: move FC transport's bsg code to bsg-lib
  block: unexport bsg_softirq_done() again

 block/bsg-lib.c  |  19 +-
 drivers/s390/scsi/zfcp_fc.c  |  33 +--
 drivers/scsi/bfa/bfad_bsg.c  |  62 +++---
 drivers/scsi/bfa/bfad_im.h   |   4 +-
 drivers/scsi/ibmvscsi/ibmvfc.c   |  40 ++--
 drivers/scsi/libfc/fc_lport.c|  47 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 375 +++-
 drivers/scsi/lpfc/lpfc_crtn.h|   4 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 449 ++-
 drivers/scsi/qla2xxx/qla_def.h   |   2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |   4 +-
 drivers/scsi/qla2xxx/qla_iocb.c  |  13 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  52 +++--
 drivers/scsi/qla2xxx/qla_mr.c|  15 +-
 drivers/scsi/scsi_transport_fc.c | 409 ++-
 include/linux/bsg-lib.h  |   4 +
 include/scsi/libfc.h |   2 +-
 include/scsi/scsi_transport_fc.h |  62 ++
 18 files changed, 742 insertions(+), 854 deletions(-)

-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/44] bfa: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/bfa/bfad_bsg.c | 40 +++-
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d1ad020..48366d8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3132,7 +3132,9 @@ bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, 
void *iocmd,
 static int
 bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
 {
-   uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
struct bfad_im_port_s *im_port =
(struct bfad_im_port_s *) job->shost->hostdata[0];
struct bfad_s *bfad = im_port->bfad;
@@ -3175,8 +3177,8 @@ bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
 
/* Fill the BSG job reply data */
job->reply_len = job->reply_payload.payload_len;
-   job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
-   job->reply->result = rc;
+   bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
+   bsg_reply->result = rc;
 
job->job_done(job);
return rc;
@@ -3184,9 +3186,9 @@ error:
/* free the command buffer */
kfree(payload_kbuf);
 out:
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->reply_len = sizeof(uint32_t);
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
return rc;
 }
 
@@ -3362,18 +3364,20 @@ bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
struct bfad_fcxp*drv_fcxp;
struct bfa_fcs_lport_s *fcs_port;
struct bfa_fcs_rport_s *fcs_rport;
-   uint32_t command_type = job->request->msgcode;
+   struct fc_bsg_request *bsg_request = bsg_request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t command_type = bsg_request->msgcode;
unsigned long flags;
struct bfad_buf_info *rsp_buf_info;
void *req_kbuf = NULL, *rsp_kbuf = NULL;
int rc = -EINVAL;
 
job->reply_len  = sizeof(uint32_t); /* Atleast uint32_t reply_len */
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
 
/* Get the payload passed in from userspace */
-   bsg_data = (struct bfa_bsg_data *) (((char *)job->request) +
-   sizeof(struct fc_bsg_request));
+   bsg_data = (struct bfa_bsg_data *) (((char *)bsg_request) +
+   sizeof(struct fc_bsg_request));
if (bsg_data == NULL)
goto out;
 
@@ -3517,13 +3521,13 @@ bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
/* fill the job->reply data */
if (drv_fcxp->req_status == BFA_STATUS_OK) {
job->reply_len = drv_fcxp->rsp_len;
-   job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
-   job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
+   bsg_reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
+   bsg_reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
} else {
-   job->reply->reply_payload_rcv_len =
+   bsg_reply->reply_payload_rcv_len =
sizeof(struct fc_bsg_ctels_reply);
job->reply_len = sizeof(uint32_t);
-   job->reply->reply_data.ctels_reply.status =
+   bsg_reply->reply_data.ctels_reply.status =
FC_CTELS_STATUS_REJECT;
}
 
@@ -3549,7 +3553,7 @@ out_free_mem:
kfree(bsg_fcpt);
kfree(drv_fcxp);
 out:
-   job->reply->result = rc;
+   bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
job->job_done(job);
@@ -3560,9 +3564,11 @@ out:
 int
 bfad_im_bsg_request(struct fc_bsg_job *job)
 {
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
uint32_t rc = BFA_STATUS_OK;
 
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_HST_VENDOR:
/* Process BSG HST Vendor requests */
rc = bfad_im_bsg_vendor_request(job);
@@ -3575,8 +3581,8 @@ bfad_im_bsg_request(struct fc_bsg_job *job)
rc = bfad_im_bsg_els_ct_request(job);

[PATCH 05/44] lpfc: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/lpfc/lpfc_bsg.c | 194 +++
 1 file changed, 121 insertions(+), 73 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 1002627..27b5930 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -299,6 +299,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
 {
struct bsg_job_data *dd_data;
struct fc_bsg_job *job;
+   struct fc_bsg_reply *bsg_reply;
IOCB_t *rsp;
struct lpfc_dmabuf *bmp, *cmp, *rmp;
struct lpfc_nodelist *ndlp;
@@ -313,6 +314,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
spin_lock_irqsave(>ct_ev_lock, flags);
job = dd_data->set_job;
if (job) {
+   bsg_reply = job->reply;
/* Prevent timeout handling from trying to abort job */
job->dd_data = NULL;
}
@@ -351,7 +353,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
}
} else {
rsp_size = rsp->un.genreq64.bdl.bdeSize;
-   job->reply->reply_payload_rcv_len =
+   bsg_reply->reply_payload_rcv_len =
lpfc_bsg_copy_data(rmp, >reply_payload,
   rsp_size, 0);
}
@@ -368,7 +370,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
/* Complete the job if the job is still active */
 
if (job) {
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->job_done(job);
}
return;
@@ -385,6 +387,7 @@ lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
struct lpfc_hba *phba = vport->phba;
struct lpfc_rport_data *rdata = job->rport->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
+   struct fc_bsg_reply *bsg_reply = job->reply;
struct ulp_bde64 *bpl = NULL;
uint32_t timeout;
struct lpfc_iocbq *cmdiocbq = NULL;
@@ -399,7 +402,7 @@ lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
int iocb_stat;
 
/* in case no data is transferred */
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
 
/* allocate our bsg tracking structure */
dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
@@ -543,7 +546,7 @@ no_ndlp:
kfree(dd_data);
 no_dd_data:
/* make error code available to userspace */
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->dd_data = NULL;
return rc;
 }
@@ -572,6 +575,7 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
 {
struct bsg_job_data *dd_data;
struct fc_bsg_job *job;
+   struct fc_bsg_reply *bsg_reply;
IOCB_t *rsp;
struct lpfc_nodelist *ndlp;
struct lpfc_dmabuf *pcmd = NULL, *prsp = NULL;
@@ -589,6 +593,7 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
spin_lock_irqsave(>ct_ev_lock, flags);
job = dd_data->set_job;
if (job) {
+   bsg_reply = job->reply;
/* Prevent timeout handling from trying to abort job  */
job->dd_data = NULL;
}
@@ -610,17 +615,17 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
if (job) {
if (rsp->ulpStatus == IOSTAT_SUCCESS) {
rsp_size = rsp->un.elsreq64.bdl.bdeSize;
-   job->reply->reply_payload_rcv_len =
+   bsg_reply->reply_payload_rcv_len =
sg_copy_from_buffer(job->reply_payload.sg_list,
job->reply_payload.sg_cnt,
prsp->virt,
rsp_size);
} else if (rsp->ulpStatus == IOSTAT_LS_RJT) {
-   job->reply->reply_payload_rcv_len =
+   bsg_reply->reply_payload_rcv_len =
sizeof(struct fc_bsg_ctels_reply);
/* LS_RJT data returned in word 4 */
rjt_data = (uint8_t *)>un.ulpWord[4];
-   els_reply = >reply->reply_data.ctels_reply;
+   els_reply = _reply->reply_data.ctels_reply;
els_reply->status = FC_CTELS_STATUS_REJECT;
els_reply->rjt_data.action = rjt_data[3];
els_reply->rjt_data.reason_code = rjt_data[2];
@@ -638,7 +643,7 @@ lpfc_bsg_rport

[PATCH 17/44] scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done

2016-10-11 Thread Johannes Thumshirn
Unify the interfaces of fc_bsg_jobdone and bsg_job_done. This will reduce the
diff when moving from 'struct fc_bsg_job' to a plain 'struct bsg_job' later
on.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  3 +-
 drivers/scsi/libfc/fc_lport.c|  6 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 68 +++-
 drivers/scsi/qla2xxx/qla_bsg.c   | 66 +-
 drivers/scsi/scsi_transport_fc.c | 22 +++--
 include/scsi/scsi_transport_fc.h |  3 +-
 8 files changed, 116 insertions(+), 60 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 40d8f06..87f6330 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 25889b9..e49a6c8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,8 @@ bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3557,8 @@ out:
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
 
return rc;
 }
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 21c9d28..1001d4a 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1939,7 +1939,8 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 8811fe0..4bed7ec 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1912,7 +1912,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
}
@@ -1947,7 +1948,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
}
fc_frame_free(fp);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 1db9cca..447a7af 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,8 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -644,7 +645,8 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -1136,7 +1138,8 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct 
lpfc_sli_ring *pring,
job->dd_data = NULL;
/* complete the job back to use

[PATCH 07/44] libfc: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-11 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/libfc/fc_lport.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 04ce7cf..a1c12e7 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1901,13 +1901,14 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
 {
struct fc_bsg_info *info = info_arg;
struct fc_bsg_job *job = info->job;
+   struct fc_bsg_reply *bsg_reply = job->reply;
struct fc_lport *lport = info->lport;
struct fc_frame_header *fh;
size_t len;
void *buf;
 
if (IS_ERR(fp)) {
-   job->reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
+   bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
@@ -1928,23 +1929,23 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
(unsigned short)fc_frame_payload_op(fp);
 
/* Save the reply status of the job */
-   job->reply->reply_data.ctels_reply.status =
+   bsg_reply->reply_data.ctels_reply.status =
(cmd == info->rsp_code) ?
FC_CTELS_STATUS_OK : FC_CTELS_STATUS_REJECT;
}
 
-   job->reply->reply_payload_rcv_len +=
+   bsg_reply->reply_payload_rcv_len +=
fc_copy_buffer_to_sglist(buf, len, info->sg, >nents,
 >offset, NULL);
 
if (fr_eof(fp) == FC_EOF_T &&
(ntoh24(fh->fh_f_ctl) & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) ==
(FC_FC_LAST_SEQ | FC_FC_END_SEQ)) {
-   if (job->reply->reply_payload_rcv_len >
+   if (bsg_reply->reply_payload_rcv_len >
job->reply_payload.payload_len)
-   job->reply->reply_payload_rcv_len =
+   bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
-   job->reply->result = 0;
+   bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
job->job_done(job);
kfree(info);
@@ -2081,6 +2082,8 @@ static int fc_lport_ct_request(struct fc_bsg_job *job,
  */
 int fc_lport_bsg_request(struct fc_bsg_job *job)
 {
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
struct request *rsp = job->req->next_rq;
struct Scsi_Host *shost = job->shost;
struct fc_lport *lport = shost_priv(shost);
@@ -2089,13 +2092,13 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
int rc = -EINVAL;
u32 did, tov;
 
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
if (rsp)
rsp->resid_len = job->reply_payload.payload_len;
 
mutex_lock(>lp_mutex);
 
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
rport = job->rport;
if (!rport)
@@ -2117,7 +2120,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
break;
 
case FC_BSG_HST_CT:
-   did = ntoh24(job->request->rqst_data.h_ct.port_id);
+   did = ntoh24(bsg_request->rqst_data.h_ct.port_id);
if (did == FC_FID_DIR_SERV) {
rdata = lport->dns_rdata;
if (!rdata)
@@ -2135,7 +2138,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
break;
 
case FC_BSG_HST_ELS_NOLOGIN:
-   did = ntoh24(job->request->rqst_data.h_els.port_id);
+   did = ntoh24(bsg_request->rqst_data.h_els.port_id);
rc = fc_lport_els_request(job, lport, did, lport->e_d_tov);
break;
}
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/44] qla2xxx: Use fc_bsg_jobdone()

2016-10-11 Thread Johannes Thumshirn
Use fc_bsg_jobdone() directly instead of the struct bsg_job::job_done()
callback.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/qla2xxx/qla_bsg.c | 44 +-
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 40f7c10..1bca77b 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -20,7 +20,7 @@ qla2x00_bsg_job_done(void *data, void *ptr, int res)
struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 
bsg_reply->result = res;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
sp->free(vha, sp);
 }
 
@@ -242,7 +242,7 @@ qla24xx_proc_fcp_prio_cfg_cmd(struct fc_bsg_job *bsg_job)
}
 exit_fcp_prio_cfg:
if (!ret)
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return ret;
 }
 
@@ -939,7 +939,7 @@ done_unmap_req_sg:
bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
if (!rval)
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return rval;
 }
 
@@ -972,7 +972,7 @@ qla84xx_reset(struct fc_bsg_job *bsg_job)
ql_dbg(ql_dbg_user, vha, 0x7031,
"Vendor request 84xx reset completed.\n");
bsg_reply->result = DID_OK;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
}
 
return rval;
@@ -1085,7 +1085,7 @@ done_unmap_sg:
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
 
if (!rval)
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return rval;
 }
 
@@ -1282,7 +1282,7 @@ exit_mgmt:
dma_pool_free(ha->s_dma_pool, mn, mn_dma);
 
if (!rval)
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return rval;
 }
 
@@ -1368,7 +1368,7 @@ qla24xx_iidma(struct fc_bsg_job *bsg_job)
}
 
bsg_reply->result = DID_OK;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
}
 
return rval;
@@ -1476,7 +1476,7 @@ qla2x00_read_optrom(struct fc_bsg_job *bsg_job)
ha->optrom_buffer = NULL;
ha->optrom_state = QLA_SWAITING;
mutex_unlock(>optrom_mutex);
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return rval;
 }
 
@@ -1511,7 +1511,7 @@ qla2x00_update_optrom(struct fc_bsg_job *bsg_job)
ha->optrom_buffer = NULL;
ha->optrom_state = QLA_SWAITING;
mutex_unlock(>optrom_mutex);
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return rval;
 }
 
@@ -1561,7 +1561,7 @@ dealloc:
 done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
 
return 0;
 }
@@ -1610,7 +1610,7 @@ done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->reply_payload_rcv_len = sizeof(*sr);
bsg_reply->result = DID_OK << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
 
return 0;
 }
@@ -1655,7 +1655,7 @@ dealloc:
 done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
 
return 0;
 }
@@ -1699,7 +1699,7 @@ dealloc:
 done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
 
return 0;
 }
@@ -1747,7 +1747,7 @@ done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->reply_payload_rcv_len = sizeof(*i2c);
bsg_reply->result = DID_OK << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
 
return 0;
 }
@@ -1925,7 +1925,7 @@ done:
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->reply_payload_rcv_len = 0;
bsg_reply->result = (DID_OK) << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
/* Always return success, vendor rsp carries correct status */
return 0;
 }
@@ -2090,7 +2090,7 @@ qla26xx_serdes_op(struct fc_bsg_job *bsg_job)
 
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
bsg_reply->result = DID_OK << 16;
-   bsg_job->job_done(bsg_job);
+   fc_bsg_jobdone(bsg_job);
return 0;
 }
 
@@ -2131,7 +2131,7 @@ qla8044_serdes_op(struct fc_bsg_job *bsg_job)
 
bsg_job->reply_len = sizeof(struct fc_bsg_reply);
   

[PATCH 44/44] block: unexport bsg_softirq_done() again

2016-10-11 Thread Johannes Thumshirn
Unexport bsg_softirq_done() again, we don't need it outside of bsg-lib.c
anymore now that scsi_transport_fc is a pure bsg-lib client.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 block/bsg-lib.c | 3 +--
 include/linux/bsg-lib.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 4bf3a98..71f3865 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -93,14 +93,13 @@ EXPORT_SYMBOL_GPL(bsg_job_done);
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-void bsg_softirq_done(struct request *rq)
+static void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
bsg_job_put(job);
 }
-EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 267d7ee..a458d36 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_softirq_done(struct request *rq);
 void bsg_job_put(struct bsg_job *job);
 void bsg_job_get(struct bsg_job *job);
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 41/44] scsi: fc: use bsg_job_done

2016-10-11 Thread Johannes Thumshirn
fc_bsg_jobdone() and bsg_job_done() are 1:1 copies now so use the bsg-lib one
instead of the FC private implementation.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
 drivers/scsi/libfc/fc_lport.c|  4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 44 
 drivers/scsi/scsi_transport_fc.c | 41 +++--
 include/scsi/scsi_transport_fc.h |  2 --
 8 files changed, 50 insertions(+), 87 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index b1b4129..a0f9c82 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -893,7 +893,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
+   bsg_job_done(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index cdc25e6..a9a0016 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3179,7 +3179,7 @@ bfad_im_bsg_vendor_request(struct bsg_job *job)
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
return rc;
 error:
@@ -3555,7 +3555,7 @@ out:
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
 
return rc;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 9fd8975..85aa8ab 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1940,7 +1940,7 @@ static int ibmvfc_bsg_request(struct bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 58a3ccb..40d9038 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1911,7 +1911,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
@@ -1946,7 +1946,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
}
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index ca21f25..a862437 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -645,7 +645,7 @@ lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -1138,7 +1138,7 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct 
lpfc_sli_ring *pring,
job->dd_data = NULL;
/* complete the job back to u

[PATCH 42/44] block: add bsg_job_put() and bsg_job_get()

2016-10-11 Thread Johannes Thumshirn
Add bsg_job_put() and bsg_job_get() so don't need to export
bsg_destroy_job() any more.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 block/bsg-lib.c  | 17 ++---
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/linux/bsg-lib.h  |  3 ++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 5d24d25..4bf3a98 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,7 +32,7 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-void bsg_destroy_job(struct kref *kref)
+static void bsg_destroy_job(struct kref *kref)
 {
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
 
@@ -42,7 +42,18 @@ void bsg_destroy_job(struct kref *kref)
kfree(job->reply_payload.sg_list);
kfree(job);
 }
-EXPORT_SYMBOL_GPL(bsg_destroy_job);
+
+void bsg_job_put(struct bsg_job *job)
+{
+   kref_put(>kref, bsg_destroy_job);
+}
+EXPORT_SYMBOL_GPL(bsg_job_put);
+
+void bsg_job_get(struct bsg_job *job)
+{
+   kref_get(>kref);
+}
+EXPORT_SYMBOL_GPL(bsg_job_get);
 
 /**
  * bsg_job_done - completion routine for bsg requests
@@ -87,7 +98,7 @@ void bsg_softirq_done(struct request *rq)
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
-   kref_put(>kref, bsg_destroy_job);
+   bsg_job_put(job);
 }
 EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 720ddc9..34652e2 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3577,7 +3577,7 @@ fc_bsg_job_timeout(struct request *req)
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   kref_put(>kref, bsg_destroy_job);
+   bsg_job_put(job);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 09f3044..267d7ee 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,8 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_destroy_job(struct kref *kref);
 void bsg_softirq_done(struct request *rq);
+void bsg_job_put(struct bsg_job *job);
+void bsg_job_get(struct bsg_job *job);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 43/44] scsi: fc: move FC transport's bsg code to bsg-lib

2016-10-11 Thread Johannes Thumshirn
Now that all conversions are done, move the FibreChannel bsg code over to the
bsg library.

This patch is derived from work done by Mike Christie in 2011 [1] but only the
iscsi parts got merged back then.

[1] http://marc.info/?l=linux-scsi=131149780921009=2

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Suggested-by: Christoph Hellwig <h...@lst.de>
---
 drivers/scsi/scsi_transport_fc.c | 287 ++-
 1 file changed, 43 insertions(+), 244 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 34652e2..d1ee077 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3591,111 +3591,12 @@ fc_bsg_job_timeout(struct request *req)
return BLK_EH_HANDLED;
 }
 
-static int
-fc_bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
-{
-   size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments);
-
-   BUG_ON(!req->nr_phys_segments);
-
-   buf->sg_list = kzalloc(sz, GFP_KERNEL);
-   if (!buf->sg_list)
-   return -ENOMEM;
-   sg_init_table(buf->sg_list, req->nr_phys_segments);
-   buf->sg_cnt = blk_rq_map_sg(req->q, req, buf->sg_list);
-   buf->payload_len = blk_rq_bytes(req);
-   return 0;
-}
-
-
-/**
- * fc_req_to_bsgjob - Allocate/create the fc_bsg_job structure for the
- *   bsg request
- * @shost: SCSI Host corresponding to the bsg object
- * @rport: (optional) FC Remote Port corresponding to the bsg object
- * @req:   BSG request that needs a job structure
- */
-static int
-fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport *rport,
-   struct request *req)
-{
-   struct fc_internal *i = to_fc_internal(shost->transportt);
-   struct request *rsp = req->next_rq;
-   struct bsg_job *job;
-   struct fc_bsg_request *bsg_request;
-   struct fc_bsg_reply *bsg_reply;
-   int ret;
-
-   BUG_ON(req->special);
-
-   job = kzalloc(sizeof(struct bsg_job) + i->f->dd_bsg_size,
-   GFP_KERNEL);
-   if (!job)
-   return -ENOMEM;
-
-   /*
-* Note: this is a bit silly.
-* The request gets formatted as a SGIO v4 ioctl request, which
-* then gets reformatted as a blk request, which then gets
-* reformatted as a fc bsg request. And on completion, we have
-* to wrap return results such that SGIO v4 thinks it was a scsi
-* status.  I hope this was all worth it.
-*/
-
-   req->special = job;
-   job->req = req;
-   if (i->f->dd_bsg_size)
-   job->dd_data = (void *)[1];
-   bsg_request = (struct fc_bsg_request *)req->cmd;
-   job->request_len = req->cmd_len;
-   bsg_reply = req->sense;
-   job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer
-* allocated */
-   if (req->bio) {
-   ret = fc_bsg_map_buffer(>request_payload, req);
-   if (ret)
-   goto failjob_rls_job;
-   }
-   if (rsp && rsp->bio) {
-   ret = fc_bsg_map_buffer(>reply_payload, rsp);
-   if (ret)
-   goto failjob_rls_rqst_payload;
-   }
-   if (rport)
-   job->dev = >dev;
-   else
-   job->dev = >shost_gendev;
-   get_device(job->dev);   /* take a reference for the request */
-
-   kref_init(>kref);
-
-   return 0;
-
-
-failjob_rls_rqst_payload:
-   kfree(job->request_payload.sg_list);
-failjob_rls_job:
-   kfree(job);
-   return -ENOMEM;
-}
-
-
-enum fc_dispatch_result {
-   FC_DISPATCH_BREAK,  /* on return, q is locked, break from q loop */
-   FC_DISPATCH_LOCKED, /* on return, q is locked, continue on */
-   FC_DISPATCH_UNLOCKED,   /* on return, q is unlocked, continue on */
-};
-
-
 /**
  * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD
- * @q: fc host request queue
  * @shost: scsi host rport attached to
  * @job:   bsg job to be processed
  */
-static enum fc_dispatch_result
-fc_bsg_host_dispatch(struct request_queue *q, struct Scsi_Host *shost,
-struct bsg_job *job)
+static int fc_bsg_host_dispatch(struct Scsi_Host *shost, struct bsg_job *job)
 {
struct fc_internal *i = to_fc_internal(shost->transportt);
struct fc_bsg_request *bsg_request = job->request;
@@ -3756,7 +3657,7 @@ fc_bsg_host_dispatch(struct request_queue *q, struct 
Scsi_Host *shost,
 
ret = i->f->bsg_request(job);
if (!ret)
-   return FC_DISPATCH_UNLOCKED;
+   return 0;
 
 fail_host_msg:
/* return the errno failure code as the only status */
@@ -3766,7 +3667,7 @@ fail_host_msg:
job->repl

[PATCH 36/44] scsi: change FC drivers to use 'struct bsg_job'

2016-10-11 Thread Johannes Thumshirn
Change FC drivers to use 'struct bsg_job' from bsg-lib.h instead of 'struct
fc_bsg_job' from scsi_transport_fc.h and remove 'struct fc_bsg_job'.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c  | 15 
 drivers/scsi/bfa/bfad_bsg.c  | 10 +++---
 drivers/scsi/bfa/bfad_im.h   |  4 +--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  9 ++---
 drivers/scsi/libfc/fc_lport.c| 10 +++---
 drivers/scsi/lpfc/lpfc_bsg.c | 74 
 drivers/scsi/lpfc/lpfc_crtn.h|  4 +--
 drivers/scsi/qla2xxx/qla_bsg.c   | 61 +
 drivers/scsi/qla2xxx/qla_def.h   |  2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |  4 +--
 drivers/scsi/qla2xxx/qla_iocb.c  |  8 ++---
 drivers/scsi/qla2xxx/qla_isr.c   |  6 ++--
 drivers/scsi/qla2xxx/qla_mr.c|  5 +--
 drivers/scsi/scsi_transport_fc.c | 20 +--
 include/scsi/libfc.h |  2 +-
 include/scsi/scsi_transport_fc.h | 63 ++
 16 files changed, 136 insertions(+), 161 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 1977a66..b1b4129 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "zfcp_ext.h"
@@ -885,7 +886,7 @@ out_free:
 
 static void zfcp_fc_ct_els_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data;
struct fc_bsg_reply *jr = job->reply;
 
@@ -895,7 +896,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
-static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
+static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
 {
u32 preamble_word1;
u8 gs_type;
@@ -925,7 +926,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
 
 static void zfcp_fc_ct_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fc_wka_port *wka_port;
 
wka_port = zfcp_fc_job_wka_port(job);
@@ -934,7 +935,7 @@ static void zfcp_fc_ct_job_handler(void *data)
zfcp_fc_ct_els_job_handler(data);
 }
 
-static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_els_job(struct bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
@@ -957,7 +958,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
 }
 
-static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_ct_job(struct bsg_job *job,
   struct zfcp_adapter *adapter)
 {
int ret;
@@ -980,7 +981,7 @@ static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
return ret;
 }
 
-int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_exec_bsg_job(struct bsg_job *job)
 {
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
@@ -1010,7 +1011,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
}
 }
 
-int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_timeout_bsg_job(struct bsg_job *job)
 {
/* hardware tracks timeout, reset bsg timeout to not interfere */
return -EAGAIN;
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d3094270..cdc25e6 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3130,7 +3130,7 @@ bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, 
void *iocmd,
 }
 
 static int
-bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
+bfad_im_bsg_vendor_request(struct bsg_job *job)
 {
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -3314,7 +3314,7 @@ bfad_fcxp_free_mem(struct bfad_s *bfad, struct 
bfad_buf_info *buf_base,
 }
 
 int
-bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp,
+bfad_fcxp_bsg_send(struct bsg_job *job, struct bfad_fcxp *drv_fcxp,
   bfa_bsg_fcpt_t *bsg_fcpt)
 {
struct bfa_fcxp_s *hal_fcxp;
@@ -3354,7 +3354,7 @@ bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct 
bfad_fcxp *drv_fcxp,
 }
 
 int
-bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
+bfad_im_bsg_els_ct_request(struct bsg_job *job)
 {
struct bfa_bsg_data *bsg_data;
struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
@@ -3562,7 +3562,7 @@ out:
 }
 
 int
-bfad_im_bsg_request(struct fc_bsg_job *job)
+bfad_im_bsg_request(struct bsg_job *job)
 {
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -3590,7 +3590,7 @@ bfad

[PATCH 40/44] scsi: fc: use bsg_softirq_done

2016-10-11 Thread Johannes Thumshirn
bsg_softirq_done() and fc_bsg_softirq_done() are copies of each other, so
ditch the fc specific one.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 4b9324f..1ae6d86 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3591,18 +3591,6 @@ void fc_bsg_jobdone(struct bsg_job *job, int result,
 EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
 
 /**
- * fc_bsg_softirq_done - softirq done routine for destroying the bsg requests
- * @rq:BSG request that holds the job to be destroyed
- */
-static void fc_bsg_softirq_done(struct request *rq)
-{
-   struct bsg_job *job = rq->special;
-
-   blk_end_request_all(rq, rq->errors);
-   kref_put(>kref, fc_destroy_bsgjob);
-}
-
-/**
  * fc_bsg_job_timeout - handler for when a bsg request timesout
  * @req:   request that timed out
  */
@@ -4036,7 +4024,7 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct 
fc_host_attrs *fc_host)
 
q->queuedata = shost;
queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
-   blk_queue_softirq_done(q, fc_bsg_softirq_done);
+   blk_queue_softirq_done(q, bsg_softirq_done);
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT);
 
@@ -4082,7 +4070,7 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport 
*rport)
 
q->queuedata = rport;
queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
-   blk_queue_softirq_done(q, fc_bsg_softirq_done);
+   blk_queue_softirq_done(q, bsg_softirq_done);
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 39/44] block: export bsg_softirq_done

2016-10-11 Thread Johannes Thumshirn
Export bsg_softirq_done so it can be used by clients of bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 block/bsg-lib.c | 3 ++-
 include/linux/bsg-lib.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 6b99c7f..5d24d25 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -82,13 +82,14 @@ EXPORT_SYMBOL_GPL(bsg_job_done);
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-static void bsg_softirq_done(struct request *rq)
+void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
kref_put(>kref, bsg_destroy_job);
 }
+EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 67f7de6..09f3044 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -70,5 +70,6 @@ int bsg_setup_queue(struct device *dev, struct request_queue 
*q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
 void bsg_destroy_job(struct kref *kref);
+void bsg_softirq_done(struct request *rq);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 37/44] block: export bsg_destroy_job

2016-10-11 Thread Johannes Thumshirn
Export bsg_destroy_job so we can use it from clients of bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 block/bsg-lib.c | 3 ++-
 include/linux/bsg-lib.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 632fb40..6b99c7f 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,7 +32,7 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct kref *kref)
+void bsg_destroy_job(struct kref *kref)
 {
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
 
@@ -42,6 +42,7 @@ static void bsg_destroy_job(struct kref *kref)
kfree(job->reply_payload.sg_list);
kfree(job);
 }
+EXPORT_SYMBOL_GPL(bsg_destroy_job);
 
 /**
  * bsg_job_done - completion routine for bsg requests
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 58e0717..67f7de6 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,5 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
+void bsg_destroy_job(struct kref *kref);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 07/16] scsi: libfc: don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone()

2016-10-13 Thread Johannes Thumshirn
Don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone() as
fc_bsg_jobdone() calls blk_complete_requeust() which raises a soft-IRQ that
ends up in fc_bsg_sofirq_done() and fc_bsg_softirq_done() sets the
FC_RQST_STATE_DONE flag.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/scsi/libfc/fc_lport.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 9ba340c..34570cf 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1916,7 +1916,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   job->state_flags |= FC_RQST_STATE_DONE;
fc_bsg_jobdone(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
@@ -1952,7 +1951,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   job->state_flags |= FC_RQST_STATE_DONE;
fc_bsg_jobdone(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 15/16] scsi: fc: move FC transport's bsg code to bsg-lib

2016-10-13 Thread Johannes Thumshirn
Now that all conversions are done, move the FibreChannel bsg code over to the
bsg library.

This patch is derived from work done by Mike Christie in 2011 [1] but only the
iscsi parts got merged back then.

[1] http://marc.info/?l=linux-scsi=131149780921009=2

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/scsi/scsi_transport_fc.c | 287 ++-
 1 file changed, 43 insertions(+), 244 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 7fae045..916d488 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3591,111 +3591,12 @@ struct fc_vport *
return BLK_EH_HANDLED;
 }
 
-static int
-fc_bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
-{
-   size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments);
-
-   BUG_ON(!req->nr_phys_segments);
-
-   buf->sg_list = kzalloc(sz, GFP_KERNEL);
-   if (!buf->sg_list)
-   return -ENOMEM;
-   sg_init_table(buf->sg_list, req->nr_phys_segments);
-   buf->sg_cnt = blk_rq_map_sg(req->q, req, buf->sg_list);
-   buf->payload_len = blk_rq_bytes(req);
-   return 0;
-}
-
-
-/**
- * fc_req_to_bsgjob - Allocate/create the fc_bsg_job structure for the
- *   bsg request
- * @shost: SCSI Host corresponding to the bsg object
- * @rport: (optional) FC Remote Port corresponding to the bsg object
- * @req:   BSG request that needs a job structure
- */
-static int
-fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport *rport,
-   struct request *req)
-{
-   struct fc_internal *i = to_fc_internal(shost->transportt);
-   struct request *rsp = req->next_rq;
-   struct bsg_job *job;
-   struct fc_bsg_request *bsg_request;
-   struct fc_bsg_reply *bsg_reply;
-   int ret;
-
-   BUG_ON(req->special);
-
-   job = kzalloc(sizeof(struct bsg_job) + i->f->dd_bsg_size,
-   GFP_KERNEL);
-   if (!job)
-   return -ENOMEM;
-
-   /*
-* Note: this is a bit silly.
-* The request gets formatted as a SGIO v4 ioctl request, which
-* then gets reformatted as a blk request, which then gets
-* reformatted as a fc bsg request. And on completion, we have
-* to wrap return results such that SGIO v4 thinks it was a scsi
-* status.  I hope this was all worth it.
-*/
-
-   req->special = job;
-   job->req = req;
-   if (i->f->dd_bsg_size)
-   job->dd_data = (void *)[1];
-   bsg_request = (struct fc_bsg_request *)req->cmd;
-   job->request_len = req->cmd_len;
-   bsg_reply = req->sense;
-   job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer
-* allocated */
-   if (req->bio) {
-   ret = fc_bsg_map_buffer(>request_payload, req);
-   if (ret)
-   goto failjob_rls_job;
-   }
-   if (rsp && rsp->bio) {
-   ret = fc_bsg_map_buffer(>reply_payload, rsp);
-   if (ret)
-   goto failjob_rls_rqst_payload;
-   }
-   if (rport)
-   job->dev = >dev;
-   else
-   job->dev = >shost_gendev;
-   get_device(job->dev);   /* take a reference for the request */
-
-   kref_init(>kref);
-
-   return 0;
-
-
-failjob_rls_rqst_payload:
-   kfree(job->request_payload.sg_list);
-failjob_rls_job:
-   kfree(job);
-   return -ENOMEM;
-}
-
-
-enum fc_dispatch_result {
-   FC_DISPATCH_BREAK,  /* on return, q is locked, break from q loop */
-   FC_DISPATCH_LOCKED, /* on return, q is locked, continue on */
-   FC_DISPATCH_UNLOCKED,   /* on return, q is unlocked, continue on */
-};
-
-
 /**
  * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD
- * @q: fc host request queue
  * @shost: scsi host rport attached to
  * @job:   bsg job to be processed
  */
-static enum fc_dispatch_result
-fc_bsg_host_dispatch(struct request_queue *q, struct Scsi_Host *shost,
-struct bsg_job *job)
+static int fc_bsg_host_dispatch(struct Scsi_Host *shost, struct bsg_job *job)
 {
struct fc_internal *i = to_fc_internal(shost->transportt);
struct fc_bsg_request *bsg_request = job->request;
@@ -3756,7 +3657,7 @@ enum fc_dispatch_result {
 
ret = i->f->bsg_request(job);
if (!ret)
-   return FC_DISPATCH_UNLOCKED;
+   return 0;
 
 fail_host_msg:
/* return the errno failure code as the only status */
@@ -3766,7 +3667,7 @@ enum fc_dispatch_result {
job->reply_len = sizeof(uint32_t);
bsg_job_done(job, bsg_rep

[PATCH v3 16/16] block: unexport bsg_softirq_done() again

2016-10-13 Thread Johannes Thumshirn
Unexport bsg_softirq_done() again, we don't need it outside of bsg-lib.c
anymore now that scsi_transport_fc is a pure bsg-lib client.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c | 3 +--
 include/linux/bsg-lib.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 803ec40..2d1df5c 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -96,13 +96,12 @@ void bsg_job_done(struct bsg_job *job, int result,
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-void bsg_softirq_done(struct request *rq)
+static void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
bsg_job_put(job);
 }
-EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index b708db9..657a718 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_softirq_done(struct request *rq);
 void bsg_job_put(struct bsg_job *job);
 int __must_check bsg_job_get(struct bsg_job *job);
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 04/16] scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done

2016-10-13 Thread Johannes Thumshirn
Unify the interfaces of fc_bsg_jobdone and bsg_job_done. This will reduce the
diff when moving from 'struct fc_bsg_job' to a plain 'struct bsg_job' later
on.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  3 +-
 drivers/scsi/libfc/fc_lport.c|  6 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 68 +++-
 drivers/scsi/qla2xxx/qla_bsg.c   | 66 +-
 drivers/scsi/scsi_transport_fc.c | 22 +++--
 include/scsi/scsi_transport_fc.h |  3 +-
 8 files changed, 116 insertions(+), 60 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 40d8f06..87f6330 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 25889b9..e49a6c8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,8 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3557,8 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
 
return rc;
 }
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index f14e9c1..6070361 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1945,7 +1945,8 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 33e2881..000188f 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1917,7 +1917,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
}
@@ -1952,7 +1953,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
}
fc_frame_free(fp);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 1db9cca..447a7af 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,8 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -644,7 +645,8 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -1136,7 +1138,8 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(&

[PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_fc.c  |   9 +-
 drivers/scsi/bfa/bfad_bsg.c  |  40 +++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  22 ++--
 drivers/scsi/libfc/fc_lport.c|  23 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 194 +---
 drivers/scsi/qla2xxx/qla_bsg.c   | 264 ++-
 drivers/scsi/qla2xxx/qla_iocb.c  |   5 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  46 ---
 drivers/scsi/qla2xxx/qla_mr.c|  10 +-
 drivers/scsi/scsi_transport_fc.c |  37 +++---
 10 files changed, 387 insertions(+), 263 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 237688a..4c4023f 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -900,8 +900,9 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
u32 preamble_word1;
u8 gs_type;
struct zfcp_adapter *adapter;
+   struct fc_bsg_request *bsg_request = job->request;
 
-   preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
+   preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
@@ -938,6 +939,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
struct fc_rport *rport = job->rport;
+   struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
 
@@ -949,7 +951,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
d_id = port->d_id;
put_device(>dev);
} else
-   d_id = ntoh24(job->request->rqst_data.h_els.port_id);
+   d_id = ntoh24(bsg_request->rqst_data.h_els.port_id);
 
els->handler = zfcp_fc_ct_els_job_handler;
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
@@ -983,6 +985,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
+   struct fc_bsg_request *bsg_request = job->request;
 
shost = job->rport ? rport_to_shost(job->rport) : job->shost;
adapter = (struct zfcp_adapter *)shost->hostdata[0];
@@ -994,7 +997,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
ct_els->resp = job->reply_payload.sg_list;
ct_els->handler_data = job;
 
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
case FC_BSG_HST_ELS_NOLOGIN:
return zfcp_fc_exec_els_job(job, adapter);
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d1ad020..48366d8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3132,7 +3132,9 @@
 static int
 bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
 {
-   uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
struct bfad_im_port_s *im_port =
(struct bfad_im_port_s *) job->shost->hostdata[0];
struct bfad_s *bfad = im_port->bfad;
@@ -3175,8 +3177,8 @@
 
/* Fill the BSG job reply data */
job->reply_len = job->reply_payload.payload_len;
-   job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
-   job->reply->result = rc;
+   bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
+   bsg_reply->result = rc;
 
job->job_done(job);
return rc;
@@ -3184,9 +3186,9 @@
/* free the command buffer */
kfree(payload_kbuf);
 out:
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->reply_len = sizeof(uint32_t);
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
return rc;
 }
 
@@ -3362,18 +3364,20 @@ struct bfad_buf_info *
struct bfad_fcxp*drv_fcxp;
struct bfa_fcs_lport_s *fcs_port;
struct bfa_fcs_rport_s *fcs_rport;
-   uint32_t command_type = job->request->msgcode;
+   struct fc_bsg_request *bsg_request = bsg_request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t command_type = bsg_request->msgcode;
unsigned long flags;

[PATCH v3 03/16] scsi: fc: Export fc_bsg_jobdone and use it in FC drivers

2016-10-13 Thread Johannes Thumshirn
Export fc_bsg_jobdone so drivers can use it directly instead of doing
the round-trip via struct fc_bsg_job::job_done() and use it in the LLDDs.

As we've converted all LLDDs over to use fc_bsg_jobdone() directly,
we can remove the function pointer from struct fc_bsg_job as well.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
 drivers/scsi/libfc/fc_lport.c|  4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 44 
 drivers/scsi/scsi_transport_fc.c |  5 ++---
 include/scsi/scsi_transport_fc.h |  2 +-
 8 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 4c4023f..40d8f06 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 48366d8..25889b9 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,7 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3556,7 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 
return rc;
 }
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 7c17a7e..f14e9c1 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1945,7 +1945,7 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 23bb114..33e2881 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1917,7 +1917,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
kfree(info);
return;
}
@@ -1952,7 +1952,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
kfree(info);
}
fc_frame_free(fp);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 27b5930..1db9cca 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -644,7 +644,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -1136,7 +1136,7 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(>ct_ev_lock, flags);
-   job->job_done(job);
+   fc_bsg_jobdone(job);
spin_lock_irqsave(>ct_ev_lock, flags);
}
}
@@ -1361,7 +1361,7 @@ struct lpfc_dmabufext {
spin_unlock_irqrestore(>ct_ev_lock, flags);
job->dd_data = NULL;
bsg_reply->result = 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return 0;
 
 job_error:
@@ -1458,7 +1458,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result 

[PATCH v3 00/16] Convert FibreChannel bsg code to use bsg-lib

2016-10-13 Thread Johannes Thumshirn
This series converts the current bsg usage in the FibreChannel drivers over
to use bsg-lib. SAS will follow once FC is in a good enough shape.

I did take some inspiration from a similar patchset from Mike Christie
dating back to 2011 but it's not a 1:1 copy. Patch 15/16 is heavily based
on his series and attribution is given to him in the commit message.

It is currently regression tested on FCoE using the 'fcns' and
'fcrls' utilities.  I'm still trying to figure out how to test the other
LLDDs. So any pointer from the respective maintainers are appreciated
although the LLDD changes are purely mechanical. All they do is change from
'struct fc_bsg_job' to 'struct bsg_job' and corresponding changes in order
to get the series bisectable.

The idea for this change arose when discussing racy sysfs handling the FC
bsg code with Christoph and is a next step in moving all bsg clients to
bsg-lib to eventually clean up the in kernel bsg API.

Changes to v1:
* Reduce the number of individual patches (44 -> 16)
* Fix s390 build failure (forgotten to kill fc_bsg_job from zfcp_ext.h)
* Fix build failure on configs without CONFIG_BLK_DEV_BSGLIB
* Make bsg_job_get() call kref_get_unless_zero() and use it in 
scsi_transport_fc.c

Changes to v2:
* Add Hannes' Reviewd-by tags
* Address Hannes' comment about kref handling in 8/16
* Move CONFIG_BLK_DEV_BSGLIB dependency to patch 12/16 as per 0day results

Johannes Thumshirn (16):
  scsi: Get rid of struct fc_bsg_buffer
  scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  scsi: fc: Export fc_bsg_jobdone and use it in FC drivers
  scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done
  scsi: fc: provide fc_bsg_to_shost() helper
  scsi: fc: provide fc_bsg_to_rport() helper
  scsi: libfc: don't set FC_RQST_STATE_DONE before calling
fc_bsg_jobdone()
  scsi: fc: implement kref backed reference counting
  block: add reference counting for struct bsg_job
  scsi: change FC drivers to use 'struct bsg_job'
  scsi: fc: Use bsg_destroy_job
  scsi: fc: use bsg_softirq_done
  scsi: fc: use bsg_job_done
  block: add bsg_job_put() and bsg_job_get()
  scsi: fc: move FC transport's bsg code to bsg-lib
  block: unexport bsg_softirq_done() again

 block/bsg-lib.c  |  23 +-
 drivers/s390/scsi/zfcp_ext.h |   4 +-
 drivers/s390/scsi/zfcp_fc.c  |  33 +--
 drivers/scsi/Kconfig |   1 +
 drivers/scsi/bfa/bfad_bsg.c  |  62 +++---
 drivers/scsi/bfa/bfad_im.h   |   4 +-
 drivers/scsi/ibmvscsi/ibmvfc.c   |  40 ++--
 drivers/scsi/libfc/fc_lport.c|  47 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 375 +++-
 drivers/scsi/lpfc/lpfc_crtn.h|   4 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 449 ++-
 drivers/scsi/qla2xxx/qla_def.h   |   2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |   4 +-
 drivers/scsi/qla2xxx/qla_iocb.c  |  13 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  52 +++--
 drivers/scsi/qla2xxx/qla_mr.c|  15 +-
 drivers/scsi/scsi_transport_fc.c | 409 ++-
 include/linux/bsg-lib.h  |   4 +
 include/scsi/libfc.h |   2 +-
 include/scsi/scsi_transport_fc.h |  62 ++
 20 files changed, 748 insertions(+), 857 deletions(-)

-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 01/16] scsi: Get rid of struct fc_bsg_buffer

2016-10-13 Thread Johannes Thumshirn
struct fc_bsg_buffer is just a clone of struct bsg_buffer from bsg-lib,
so use this one instead.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/scsi/lpfc/lpfc_bsg.c |  3 ++-
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h | 12 +++-
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 05dcc2a..1002627 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -211,7 +212,7 @@ struct lpfc_dmabufext {
 
 static unsigned int
 lpfc_bsg_copy_data(struct lpfc_dmabuf *dma_buffers,
-  struct fc_bsg_buffer *bsg_buffers,
+  struct bsg_buffer *bsg_buffers,
   unsigned int bytes_to_transfer, int to_buffers)
 {
 
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 0f3a386..8ff2067 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3671,7 +3671,7 @@ static void fc_bsg_softirq_done(struct request *rq)
 }
 
 static int
-fc_bsg_map_buffer(struct fc_bsg_buffer *buf, struct request *req)
+fc_bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments);
 
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index bf66ea6..921b097 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -28,6 +28,7 @@
 #define SCSI_TRANSPORT_FC_H
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -624,13 +625,6 @@ struct fc_host_attrs {
 #define fc_host_dev_loss_tmo(x) \
(((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
 
-
-struct fc_bsg_buffer {
-   unsigned int payload_len;
-   int sg_cnt;
-   struct scatterlist *sg_list;
-};
-
 /* Values for fc_bsg_job->state_flags (bitflags) */
 #define FC_RQST_STATE_INPROGRESS   0
 #define FC_RQST_STATE_DONE 1
@@ -659,8 +653,8 @@ struct fc_bsg_job {
 */
 
/* DMA payloads for the request/response */
-   struct fc_bsg_buffer request_payload;
-   struct fc_bsg_buffer reply_payload;
+   struct bsg_buffer request_payload;
+   struct bsg_buffer reply_payload;
 
void *dd_data;  /* Used for driver-specific storage */
 };
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 12/24] libfc: Clarify ramp-down messages

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 03:10:48PM +0200, Hannes Reinecke wrote:
> When the queue depth is reduced we should print out the reason
> for this; it might be due to a queue full condition.
> 
> Signed-off-by: Hannes Reinecke <h...@suse.com>
> ---

Acked-by: Johannes Thumshirn <j...@kernel.org>
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 06/16] scsi: fc: provide fc_bsg_to_rport() helper

2016-10-13 Thread Johannes Thumshirn
Provide fc_bsg_to_rport() helper that will become handy when we're moving
from struct fc_bsg_job to a plain struct bsg_job. Also move all LLDDs to use
the new helper.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_fc.c  | 5 +++--
 drivers/scsi/ibmvscsi/ibmvfc.c   | 2 +-
 drivers/scsi/libfc/fc_lport.c| 4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 4 ++--
 drivers/scsi/qla2xxx/qla_bsg.c   | 4 ++--
 drivers/scsi/scsi_transport_fc.c | 3 ++-
 include/scsi/scsi_transport_fc.h | 5 +
 7 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 813c286..1977a66 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -938,7 +938,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
@@ -986,8 +986,9 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
 
-   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
+   shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 02df1f1..4c73fc7 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1822,7 +1822,7 @@ static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, 
unsigned int port_id)
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
union ibmvfc_iu rsp_iu;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index a3fb355..9ba340c 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2107,7 +2107,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
 
switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
@@ -2117,7 +2117,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
break;
 
case FC_BSG_RPT_CT:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index bfcc37d..dae7cc3 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -386,7 +386,7 @@ struct lpfc_dmabufext {
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_reply *bsg_reply = job->reply;
struct ulp_bde64 *bpl = NULL;
@@ -660,7 +660,7 @@ struct lpfc_dmabufext {
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 109b852..917eafe 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -264,7 +264,7 @@
uint16_t nextlid = 0;
 
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
-   rport = bsg_job->rport;
+   rport = fc_bsg_to_rport(bsg_job);
fcport = *(fc_port_t **) rport->dd_data;
host = rport_to_shost(rport);
vha = shost_priv(host);
@@ -2485,7 +2485,7 @@
bsg_reply->reply_payload_rcv_len = 0;
 
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
-   rport = bsg_job->rport;
+   rport = fc_bsg_to_rpor

[PATCH v3 09/16] block: add reference counting for struct bsg_job

2016-10-13 Thread Johannes Thumshirn
Add reference counting to 'struct bsg_job' so we can implement a reuqest
timeout handler for bsg_jobs, which is needed for Fibre Channel.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c | 7 +--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,8 +32,10 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct bsg_job *job)
+static void bsg_destroy_job(struct kref *kref)
 {
+   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+
put_device(job->dev);   /* release reference for the request */
 
kfree(job->request_payload.sg_list);
@@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq)
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
-   bsg_destroy_job(job);
+   kref_put(>kref, bsg_destroy_job);
 }
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
@@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct 
request *req)
job->dev = dev;
/* take a reference for the request */
get_device(job->dev);
+   kref_init(>kref);
return 0;
 
 failjob_rls_rqst_payload:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -40,6 +40,8 @@ struct bsg_job {
struct device *dev;
struct request *req;
 
+   struct kref kref;
+
/* Transport/driver specific request/reply structs */
void *request;
void *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 11/16] scsi: fc: Use bsg_destroy_job

2016-10-13 Thread Johannes Thumshirn
fc_destroy_bsgjob() and bsg_destroy_job() are now 1:1 copies, so use the
later. As bsg_destroy_job() comes from bsg-lib we need to select it in Kconfig
once CONFOG_SCSI_FC_ATTRS is active.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c  |  7 +--
 drivers/scsi/Kconfig |  1 +
 drivers/scsi/scsi_transport_fc.c | 23 ++-
 include/linux/bsg-lib.h  |  1 +
 4 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 632fb40..9f1e8fd 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,9 +32,12 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct kref *kref)
+void bsg_destroy_job(struct kref *kref)
 {
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+   struct request *rq = job->req;
+
+   blk_end_request_all(rq, rq->errors);
 
put_device(job->dev);   /* release reference for the request */
 
@@ -42,6 +45,7 @@ static void bsg_destroy_job(struct kref *kref)
kfree(job->reply_payload.sg_list);
kfree(job);
 }
+EXPORT_SYMBOL_GPL(bsg_destroy_job);
 
 /**
  * bsg_job_done - completion routine for bsg requests
@@ -85,7 +89,6 @@ static void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
-   blk_end_request_all(rq, rq->errors);
kref_put(>kref, bsg_destroy_job);
 }
 
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3e2bdb9..2774756 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -263,6 +263,7 @@ config SCSI_SPI_ATTRS
 config SCSI_FC_ATTRS
tristate "FiberChannel Transport Attributes"
depends on SCSI && NET
+   select BLK_DEV_BSGLIB
select SCSI_NETLINK
help
  If you wish to export transport-specific information about
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index eadc80f..d2d0a27 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3554,26 +3555,6 @@ struct fc_vport *
  * BSG support
  */
 
-
-/**
- * fc_destroy_bsgjob - routine to teardown/delete a fc bsg job
- * @job:   fc_bsg_job that is to be torn down
- */
-static void
-fc_destroy_bsgjob(struct kref *kref)
-{
-   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
-   struct request *rq = job->req;
-
-   blk_end_request_all(rq, rq->errors);
-
-   put_device(job->dev);   /* release reference for the request */
-
-   kfree(job->request_payload.sg_list);
-   kfree(job->reply_payload.sg_list);
-   kfree(job);
-}
-
 /**
  * fc_bsg_jobdone - completion routine for bsg requests that the LLD has
  *  completed
@@ -3642,7 +3623,7 @@ static void fc_bsg_softirq_done(struct request *rq)
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   kref_put(>kref, fc_destroy_bsgjob);
+   kref_put(>kref, bsg_destroy_job);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 58e0717..67f7de6 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,5 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
+void bsg_destroy_job(struct kref *kref);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 14/16] block: add bsg_job_put() and bsg_job_get()

2016-10-13 Thread Johannes Thumshirn
Add bsg_job_put() and bsg_job_get() so don't need to export
bsg_destroy_job() any more.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c  | 17 ++---
 drivers/scsi/scsi_transport_fc.c |  4 ++--
 include/linux/bsg-lib.h  |  3 ++-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 6661f82..803ec40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,7 +32,7 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-void bsg_destroy_job(struct kref *kref)
+static void bsg_destroy_job(struct kref *kref)
 {
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
struct request *rq = job->req;
@@ -45,7 +45,18 @@ void bsg_destroy_job(struct kref *kref)
kfree(job->reply_payload.sg_list);
kfree(job);
 }
-EXPORT_SYMBOL_GPL(bsg_destroy_job);
+
+void bsg_job_put(struct bsg_job *job)
+{
+   kref_put(>kref, bsg_destroy_job);
+}
+EXPORT_SYMBOL_GPL(bsg_job_put);
+
+int bsg_job_get(struct bsg_job *job)
+{
+   return kref_get_unless_zero(>kref);
+}
+EXPORT_SYMBOL_GPL(bsg_job_get);
 
 /**
  * bsg_job_done - completion routine for bsg requests
@@ -89,7 +100,7 @@ void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
-   kref_put(>kref, bsg_destroy_job);
+   bsg_job_put(job);
 }
 EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 720ddc9..7fae045 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3571,13 +3571,13 @@ struct fc_vport *
if (rport && rport->port_state == FC_PORTSTATE_BLOCKED)
return BLK_EH_RESET_TIMER;
 
-   inflight = kref_get_unless_zero(>kref);
+   inflight = bsg_job_get(job);
 
if (inflight && i->f->bsg_timeout) {
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   kref_put(>kref, bsg_destroy_job);
+   bsg_job_put(job);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 09f3044..b708db9 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,8 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_destroy_job(struct kref *kref);
 void bsg_softirq_done(struct request *rq);
+void bsg_job_put(struct bsg_job *job);
+int __must_check bsg_job_get(struct bsg_job *job);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 08/16] scsi: fc: implement kref backed reference counting

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 01:42:06PM +0200, Hannes Reinecke wrote:
> On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> > Implement kref backed reference counting instead of rolling our own. This
> > elimnates the need of the following fields in 'struct fc_bsg_job':
> > * ref_cnt
> > * state_flags
> > * job_lock
> > bringing us close to unification of 'struct fc_bsg_job' and 'struct 
> > bsg_job'.
> > 
> > Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
> > ---
> >  drivers/scsi/scsi_transport_fc.c | 38 
> > +-
> >  include/scsi/scsi_transport_fc.h |  4 +---
> >  2 files changed, 10 insertions(+), 32 deletions(-)
> > 
> > diff --git a/drivers/scsi/scsi_transport_fc.c 
> > b/drivers/scsi/scsi_transport_fc.c
> > index 96b3a2e..b0e28af 100644
> > --- a/drivers/scsi/scsi_transport_fc.c
> > +++ b/drivers/scsi/scsi_transport_fc.c
> > @@ -3560,16 +3560,9 @@ fc_vport_sched_delete(struct work_struct *work)
> >   * @job:   fc_bsg_job that is to be torn down
> >   */
> >  static void
> > -fc_destroy_bsgjob(struct fc_bsg_job *job)
> > +fc_destroy_bsgjob(struct kref *kref)
> >  {
> > -   unsigned long flags;
> > -
> > -   spin_lock_irqsave(>job_lock, flags);
> > -   if (job->ref_cnt) {
> > -   spin_unlock_irqrestore(>job_lock, flags);
> > -   return;
> > -   }
> > -   spin_unlock_irqrestore(>job_lock, flags);
> > +   struct fc_bsg_job *job = container_of(kref, struct fc_bsg_job, kref);
> >  
> > put_device(job->dev);   /* release reference for the request */
> >  
> > @@ -3620,15 +3613,9 @@ EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
> >  static void fc_bsg_softirq_done(struct request *rq)
> >  {
> > struct fc_bsg_job *job = rq->special;
> > -   unsigned long flags;
> > -
> > -   spin_lock_irqsave(>job_lock, flags);
> > -   job->state_flags |= FC_RQST_STATE_DONE;
> > -   job->ref_cnt--;
> > -   spin_unlock_irqrestore(>job_lock, flags);
> >  
> > blk_end_request_all(rq, rq->errors);
> > -   fc_destroy_bsgjob(job);
> > +   kref_put(>kref, fc_destroy_bsgjob);
> >  }
> >  
> >  /**
> Hmm. blk_end_request_all() (potentially) triggers a recursion into all
> .end_io callbacks, which might end up doing god-knows-what.
> With some delays in doing so
> During that time we have no idea that bsg_softirq_done() is actually
> running, and we might clash with eg. timeouts or somesuch.
> 
> Maybe it's an idea to move blk_end_request_all into the kref destroy
> callback; that way we're guaranteed to call it only once and would avoid
> this situation.

This _could_ explain the panic with zfcp. Fixed that for v3.

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 05/16] scsi: fc: provide fc_bsg_to_shost() helper

2016-10-13 Thread Johannes Thumshirn
Provide fc_bsg_to_shost() helper that will become handy when we're moving from
struct fc_bsg_job to a plain struct bsg_job. Also use this little helper in
the LLDDs.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_fc.c  |  4 +--
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  4 +--
 drivers/scsi/libfc/fc_lport.c|  2 +-
 drivers/scsi/lpfc/lpfc_bsg.c | 32 
 drivers/scsi/qla2xxx/qla_bsg.c   | 54 
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h |  5 
 8 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 87f6330..813c286 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -905,7 +905,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
-   adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
+   adapter = shost_priv(fc_bsg_to_shost(job));
 
switch (gs_type) {
case FC_FST_ALIAS:
@@ -987,7 +987,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
 
-   shost = job->rport ? rport_to_shost(job->rport) : job->shost;
+   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index e49a6c8..d3094270 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3135,8 +3135,7 @@
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
struct request_queue *request_q = job->req->q;
void *payload_kbuf;
@@ -3358,8 +3357,7 @@ struct bfad_buf_info *
 bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
 {
struct bfa_bsg_data *bsg_data;
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
bfa_bsg_fcpt_t *bsg_fcpt;
struct bfad_fcxp*drv_fcxp;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 6070361..02df1f1 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1708,7 +1708,7 @@ static void ibmvfc_bsg_timeout_done(struct ibmvfc_event 
*evt)
  **/
 static int ibmvfc_bsg_timeout(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
unsigned long port_id = (unsigned long)job->dd_data;
struct ibmvfc_event *evt;
struct ibmvfc_tmf *tmf;
@@ -1821,7 +1821,7 @@ static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, 
unsigned int port_id)
  **/
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
struct fc_rport *rport = job->rport;
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 000188f..a3fb355 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2092,7 +2092,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
struct request *rsp = job->req->next_rq;
-   struct Scsi_Host *shost = job->shost;
+   struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_lport *lport = shost_priv(shost);
struct fc_rport *rport;
struct fc_rport_priv *rdata;
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 447a7af..bfcc37d 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -384,7 +384,7 @@ struct lpfc_dmabufext {
 static int
 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport 

[PATCH v3 13/16] scsi: fc: use bsg_job_done

2016-10-13 Thread Johannes Thumshirn
fc_bsg_jobdone() and bsg_job_done() are 1:1 copies now so use the bsg-lib one
instead of the FC private implementation.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
 drivers/scsi/libfc/fc_lport.c|  4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 44 
 drivers/scsi/scsi_transport_fc.c | 41 +++--
 include/scsi/scsi_transport_fc.h |  2 --
 8 files changed, 50 insertions(+), 87 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index b1b4129..a0f9c82 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -893,7 +893,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
+   bsg_job_done(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index cdc25e6..a9a0016 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3179,7 +3179,7 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
return rc;
 error:
@@ -3555,7 +3555,7 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
 
return rc;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index f59b0a1..78b72c2 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1946,7 +1946,7 @@ static int ibmvfc_bsg_request(struct bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 9845667..518e3b0 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1916,7 +1916,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
@@ -1951,7 +1951,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
}
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index ca21f25..a862437 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -645,7 +645,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -1138,7 +1138,7 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrest

[PATCH v3 08/16] scsi: fc: implement kref backed reference counting

2016-10-13 Thread Johannes Thumshirn
Implement kref backed reference counting instead of rolling our own. This
elimnates the need of the following fields in 'struct fc_bsg_job':
* ref_cnt
* state_flags
* job_lock
bringing us close to unification of 'struct fc_bsg_job' and 'struct bsg_job'.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/scsi/scsi_transport_fc.c | 40 +++-
 include/scsi/scsi_transport_fc.h |  4 +---
 2 files changed, 12 insertions(+), 32 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 96b3a2e..610a985 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3560,16 +3560,12 @@ struct fc_vport *
  * @job:   fc_bsg_job that is to be torn down
  */
 static void
-fc_destroy_bsgjob(struct fc_bsg_job *job)
+fc_destroy_bsgjob(struct kref *kref)
 {
-   unsigned long flags;
+   struct fc_bsg_job *job = container_of(kref, struct fc_bsg_job, kref);
+   struct request *rq = job->req;
 
-   spin_lock_irqsave(>job_lock, flags);
-   if (job->ref_cnt) {
-   spin_unlock_irqrestore(>job_lock, flags);
-   return;
-   }
-   spin_unlock_irqrestore(>job_lock, flags);
+   blk_end_request_all(rq, rq->errors);
 
put_device(job->dev);   /* release reference for the request */
 
@@ -3620,15 +3616,8 @@ void fc_bsg_jobdone(struct fc_bsg_job *job, int result,
 static void fc_bsg_softirq_done(struct request *rq)
 {
struct fc_bsg_job *job = rq->special;
-   unsigned long flags;
 
-   spin_lock_irqsave(>job_lock, flags);
-   job->state_flags |= FC_RQST_STATE_DONE;
-   job->ref_cnt--;
-   spin_unlock_irqrestore(>job_lock, flags);
-
-   blk_end_request_all(rq, rq->errors);
-   fc_destroy_bsgjob(job);
+   kref_put(>kref, fc_destroy_bsgjob);
 }
 
 /**
@@ -3642,24 +3631,18 @@ static void fc_bsg_softirq_done(struct request *rq)
struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_internal *i = to_fc_internal(shost->transportt);
-   unsigned long flags;
-   int err = 0, done = 0;
+   int err = 0, inflight = 0;
 
if (rport && rport->port_state == FC_PORTSTATE_BLOCKED)
return BLK_EH_RESET_TIMER;
 
-   spin_lock_irqsave(>job_lock, flags);
-   if (job->state_flags & FC_RQST_STATE_DONE)
-   done = 1;
-   else
-   job->ref_cnt++;
-   spin_unlock_irqrestore(>job_lock, flags);
+   inflight = kref_get_unless_zero(>kref);
 
-   if (!done && i->f->bsg_timeout) {
+   if (inflight && i->f->bsg_timeout) {
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   job->ref_cnt--;
+   kref_put(>kref, fc_destroy_bsgjob);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
@@ -3667,7 +3650,7 @@ static void fc_bsg_softirq_done(struct request *rq)
}
 
/* the blk_end_sync_io() doesn't check the error */
-   if (done)
+   if (!inflight)
return BLK_EH_NOT_HANDLED;
else
return BLK_EH_HANDLED;
@@ -3730,7 +3713,6 @@ static void fc_bsg_softirq_done(struct request *rq)
job->req = req;
if (i->f->dd_bsg_size)
job->dd_data = (void *)[1];
-   spin_lock_init(>job_lock);
bsg_request = (struct fc_bsg_request *)req->cmd;
job->request_len = req->cmd_len;
bsg_reply = req->sense;
@@ -3752,7 +3734,7 @@ static void fc_bsg_softirq_done(struct request *rq)
job->dev = >shost_gendev;
get_device(job->dev);   /* take a reference for the request */
 
-   job->ref_cnt = 1;
+   kref_init(>kref);
 
return 0;
 
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index 9f53fe3..8ae5680 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -634,9 +634,7 @@ struct fc_bsg_job {
struct fc_rport *rport;
struct device *dev;
struct request *req;
-   spinlock_t job_lock;
-   unsigned int state_flags;
-   unsigned int ref_cnt;
+   struct kref kref;
 
struct fc_bsg_request *request;
struct fc_bsg_reply *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 10/16] scsi: change FC drivers to use 'struct bsg_job'

2016-10-13 Thread Johannes Thumshirn
Change FC drivers to use 'struct bsg_job' from bsg-lib.h instead of 'struct
fc_bsg_job' from scsi_transport_fc.h and remove 'struct fc_bsg_job'.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 drivers/s390/scsi/zfcp_ext.h |  4 +--
 drivers/s390/scsi/zfcp_fc.c  | 15 
 drivers/scsi/bfa/bfad_bsg.c  | 10 +++---
 drivers/scsi/bfa/bfad_im.h   |  4 +--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  9 ++---
 drivers/scsi/libfc/fc_lport.c| 10 +++---
 drivers/scsi/lpfc/lpfc_bsg.c | 74 
 drivers/scsi/lpfc/lpfc_crtn.h|  4 +--
 drivers/scsi/qla2xxx/qla_bsg.c   | 61 +
 drivers/scsi/qla2xxx/qla_def.h   |  2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |  4 +--
 drivers/scsi/qla2xxx/qla_iocb.c  |  8 ++---
 drivers/scsi/qla2xxx/qla_isr.c   |  6 ++--
 drivers/scsi/qla2xxx/qla_mr.c|  5 +--
 drivers/scsi/scsi_transport_fc.c | 20 +--
 include/scsi/libfc.h |  2 +-
 include/scsi/scsi_transport_fc.h | 63 ++
 17 files changed, 138 insertions(+), 163 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index c8fed9f..968a0ab 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -84,8 +84,8 @@ extern void zfcp_fc_enqueue_event(struct zfcp_adapter *,
 extern void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *);
 extern int zfcp_fc_gs_setup(struct zfcp_adapter *);
 extern void zfcp_fc_gs_destroy(struct zfcp_adapter *);
-extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *);
-extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *);
+extern int zfcp_fc_exec_bsg_job(struct bsg_job *);
+extern int zfcp_fc_timeout_bsg_job(struct bsg_job *);
 extern void zfcp_fc_sym_name_update(struct work_struct *);
 extern unsigned int zfcp_fc_port_scan_backoff(void);
 extern void zfcp_fc_conditional_port_scan(struct zfcp_adapter *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 1977a66..b1b4129 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "zfcp_ext.h"
@@ -885,7 +886,7 @@ void zfcp_fc_sym_name_update(struct work_struct *work)
 
 static void zfcp_fc_ct_els_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data;
struct fc_bsg_reply *jr = job->reply;
 
@@ -895,7 +896,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
-static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
+static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
 {
u32 preamble_word1;
u8 gs_type;
@@ -925,7 +926,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
 
 static void zfcp_fc_ct_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fc_wka_port *wka_port;
 
wka_port = zfcp_fc_job_wka_port(job);
@@ -934,7 +935,7 @@ static void zfcp_fc_ct_job_handler(void *data)
zfcp_fc_ct_els_job_handler(data);
 }
 
-static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_els_job(struct bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
@@ -957,7 +958,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
 }
 
-static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_ct_job(struct bsg_job *job,
   struct zfcp_adapter *adapter)
 {
int ret;
@@ -980,7 +981,7 @@ static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
return ret;
 }
 
-int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_exec_bsg_job(struct bsg_job *job)
 {
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
@@ -1010,7 +1011,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
}
 }
 
-int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_timeout_bsg_job(struct bsg_job *job)
 {
/* hardware tracks timeout, reset bsg timeout to not interfere */
return -EAGAIN;
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d3094270..cdc25e6 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3130,7 +3130,7 @@
 }
 
 static int
-bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
+bfad_im_bsg_vendor_request(struct bsg_job *job)
 {
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -3314,7 +3314,7 @@ str

[PATCH v3 12/16] scsi: fc: use bsg_softirq_done

2016-10-13 Thread Johannes Thumshirn
bsg_softirq_done() and fc_bsg_softirq_done() are copies of each other, so
ditch the fc specific one.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
Reviewed-by: Hannes Reinecke <h...@suse.com>
---
 block/bsg-lib.c  |  3 ++-
 drivers/scsi/scsi_transport_fc.c | 15 ++-
 include/linux/bsg-lib.h  |  1 +
 3 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 9f1e8fd..6661f82 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -85,12 +85,13 @@ void bsg_job_done(struct bsg_job *job, int result,
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-static void bsg_softirq_done(struct request *rq)
+void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
kref_put(>kref, bsg_destroy_job);
 }
+EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index d2d0a27..1ae6d86 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3591,17 +3591,6 @@ void fc_bsg_jobdone(struct bsg_job *job, int result,
 EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
 
 /**
- * fc_bsg_softirq_done - softirq done routine for destroying the bsg requests
- * @rq:BSG request that holds the job to be destroyed
- */
-static void fc_bsg_softirq_done(struct request *rq)
-{
-   struct bsg_job *job = rq->special;
-
-   kref_put(>kref, fc_destroy_bsgjob);
-}
-
-/**
  * fc_bsg_job_timeout - handler for when a bsg request timesout
  * @req:   request that timed out
  */
@@ -4035,7 +4024,7 @@ enum fc_dispatch_result {
 
q->queuedata = shost;
queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
-   blk_queue_softirq_done(q, fc_bsg_softirq_done);
+   blk_queue_softirq_done(q, bsg_softirq_done);
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT);
 
@@ -4081,7 +4070,7 @@ enum fc_dispatch_result {
 
q->queuedata = rport;
queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
-   blk_queue_softirq_done(q, fc_bsg_softirq_done);
+   blk_queue_softirq_done(q, bsg_softirq_done);
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
 
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 67f7de6..09f3044 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -70,5 +70,6 @@ int bsg_setup_queue(struct device *dev, struct request_queue 
*q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
 void bsg_destroy_job(struct kref *kref);
+void bsg_softirq_done(struct request *rq);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 05:15:25PM +0200, Steffen Maier wrote:
> I'm puzzled.
> 
> $ git bisect start fc_bsg master
> Bisecting: 8 revisions left to test after this (roughly 3 steps)
> [005d51510eee6102636d5dbb06310531c5d46151] scsi: fc: implement kref backed
> reference counting
> $ git bisect bad
> Bisecting: 3 revisions left to test after this (roughly 2 steps)
> [bef6da201de1bb81bb4d9511f9a155862efc251f] scsi: Unify interfaces of
> fc_bsg_jobdone and bsg_job_done
> $ git bisect bad
> Bisecting: 1 revision left to test after this (roughly 1 step)
> [3087864ce3d7282f59021245d8a5f83ef1caef18] scsi: don't use
> fc_bsg_job::request and fc_bsg_job::reply directly
> $ git bisect bad
> Bisecting: 0 revisions left to test after this (roughly 0 steps)
> [81aea44720d22d2e0c4a2613ae8b1c256ef6b0cb] scsi: Get rid of struct
> fc_bsg_buffer
> > $ git bisect good
> > 3087864ce3d7282f59021245d8a5f83ef1caef18 is the first bad commit
> > commit 3087864ce3d7282f59021245d8a5f83ef1caef18
> > Author: Johannes Thumshirn <jthumsh...@suse.de>
> > Date:   Wed Oct 12 15:06:28 2016 +0200
> > 
> > scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly
> > 
> > Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
> > helper variables bsg_request and bsg_reply. This will be helpfull  when
> > transitioning to bsg-lib.
> > 
> > Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
> > 
> > :04 04 140c4b6829d5cfaec4079716e0795f63f8bc3bd2 
> > 0d9fe225615679550be91fbd9f84c09ab1e280fc M  drivers
> 
> From there (on the reverse bisect path) I get the following Oops,
> except for the full patch set having another stack trace as in my previous
> mail (dying in zfcp code).
> 

[...]

> 
> > @@ -3937,6 +3944,7 @@ fc_bsg_request_handler(struct request_queue *q, 
> > struct Scsi_Host *shost,
> > struct request *req;
> > struct fc_bsg_job *job;
> > enum fc_dispatch_result ret;
> > +   struct fc_bsg_reply *bsg_reply;
> > 
> > if (!get_device(dev))
> > return;
> > @@ -3973,8 +3981,9 @@ fc_bsg_request_handler(struct request_queue *q, 
> > struct Scsi_Host *shost,
> > /* check if we have the msgcode value at least */
> > if (job->request_len < sizeof(uint32_t)) {
> > BUG_ON(job->reply_len < sizeof(uint32_t));
> > -   job->reply->reply_payload_rcv_len = 0;
> > -   job->reply->result = -ENOMSG;
> > +   bsg_reply = job->reply;
> > +   bsg_reply->reply_payload_rcv_len = 0;
> > +   bsg_reply->result = -ENOMSG;
> > job->reply_len = sizeof(uint32_t);
> > fc_bsg_jobdone(job);
> > spin_lock_irq(q->queue_lock);
> > 

Ahm and what exactly can break here? It's just assigning variables. Now
I'm puzzled too.

I'll have to look into it tomorrow.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 05:55:11PM +0200, Steffen Maier wrote:
> Hm, still behaves for me like I reported for v2:
> http://marc.info/?l=linux-scsi=147637177902937=2
> 
Well given what you've wrote for v2 it's kinda expected.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 05/16] scsi: fc: provide fc_bsg_to_shost() helper

2016-10-12 Thread Johannes Thumshirn
Provide fc_bsg_to_shost() helper that will become handy when we're moving from
struct fc_bsg_job to a plain struct bsg_job. Also use this little helper in
the LLDDs.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 drivers/s390/scsi/zfcp_fc.c  |  4 +--
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  4 +--
 drivers/scsi/libfc/fc_lport.c|  2 +-
 drivers/scsi/lpfc/lpfc_bsg.c | 32 
 drivers/scsi/qla2xxx/qla_bsg.c   | 54 
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h |  5 
 8 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 87f6330..813c286 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -905,7 +905,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
-   adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
+   adapter = shost_priv(fc_bsg_to_shost(job));
 
switch (gs_type) {
case FC_FST_ALIAS:
@@ -987,7 +987,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
 
-   shost = job->rport ? rport_to_shost(job->rport) : job->shost;
+   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index e49a6c8..d3094270 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3135,8 +3135,7 @@ bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
struct request_queue *request_q = job->req->q;
void *payload_kbuf;
@@ -3358,8 +3357,7 @@ int
 bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
 {
struct bfa_bsg_data *bsg_data;
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
bfa_bsg_fcpt_t *bsg_fcpt;
struct bfad_fcxp*drv_fcxp;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 1001d4a..f7b50af 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1702,7 +1702,7 @@ static void ibmvfc_bsg_timeout_done(struct ibmvfc_event 
*evt)
  **/
 static int ibmvfc_bsg_timeout(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
unsigned long port_id = (unsigned long)job->dd_data;
struct ibmvfc_event *evt;
struct ibmvfc_tmf *tmf;
@@ -1815,7 +1815,7 @@ unlock_out:
  **/
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
struct fc_rport *rport = job->rport;
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 4bed7ec..c60fdb9 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2087,7 +2087,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
struct request *rsp = job->req->next_rq;
-   struct Scsi_Host *shost = job->shost;
+   struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_lport *lport = shost_priv(shost);
struct fc_rport *rport;
struct fc_rport_priv *rdata;
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 447a7af..bfcc37d 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -384,7 +384,7 @@ lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
 static int
 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vp

[PATCH v2 09/16] block: add reference counting for struct bsg_job

2016-10-12 Thread Johannes Thumshirn
Add reference counting to 'struct bsg_job' so we can implement a reuqest
timeout handler for bsg_jobs, which is needed for Fibre Channel.

Signed-off-by: Johannes Thumshirn <jthumsh...@suse.de>
---
 block/bsg-lib.c | 7 +--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,8 +32,10 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct bsg_job *job)
+static void bsg_destroy_job(struct kref *kref)
 {
+   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+
put_device(job->dev);   /* release reference for the request */
 
kfree(job->request_payload.sg_list);
@@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq)
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
-   bsg_destroy_job(job);
+   kref_put(>kref, bsg_destroy_job);
 }
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
@@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct 
request *req)
job->dev = dev;
/* take a reference for the request */
get_device(job->dev);
+   kref_init(>kref);
return 0;
 
 failjob_rls_rqst_payload:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -40,6 +40,8 @@ struct bsg_job {
struct device *dev;
struct request *req;
 
+   struct kref kref;
+
/* Transport/driver specific request/reply structs */
void *request;
void *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


<    3   4   5   6   7   8   9   10   11   12   >