Skip to contentSkip to conversation

2.5.28 small REQ_SPECIAL abstraction

PATCH James Bottomley 4 participants 9 messages Jul 28, 2002 – Jul 29, 2002 SCSI

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines

You are right the

Quoted 3 lines

rq->flags &= REQ_QUEUED;
and the
if (blk_rq_tagged(rq))

blk_queue_end_tag(q, rq);

Quoted 1 line

should be just removed and things are fine.

They only survive becouse they don't provide a tag for the request in first place.

Quoted 1 line

Thanks for pointing it out.

Please don't remove this.

insert_special isn't just used to start new requests, it's also used to queue incoming requests that cannot be processed by the device (host adapter, queue_full etc.).

In this latter case, the tag is already begun, so it needs to go back with end_tag (we start a new tag when the device begins processing again).

I own up to introducing the &= REQ_QUEUED rubbish---I was just keeping the original placement of the flag clearing code, but now we need to preserve whether the request was queued or not for the blk_rq_tagged check. On reflection it would have been better just to set the flags to REQ_SPECIAL | REQ_BARRIER after the end tag code.

Quoted 3 lines · [email protected] said:

But the crap still got merged, sigh... Yet again an excellent point of why stuff like this should go through the maintainer. Apparently Linus blindly applies this stuff.

Hmm, well I sent it to you and you are the Maintainer.

James

P.S. I just got back into the US from a long flight, I'll give this more mature reflection tomorrow.

#1 lore raw
Quoted 17 lines · James Bottomley
Quoted 9 lines

You are right the

Quoted 3 lines

rq->flags &= REQ_QUEUED;
and the
if (blk_rq_tagged(rq))

blk_queue_end_tag(q, rq);

Quoted 1 line

should be just removed and things are fine.

They only survive becouse they don't provide a tag for the request in first place.

Quoted 1 line

Thanks for pointing it out.

Please don't remove this.

insert_special isn't just used to start new requests, it's also used to queue incoming requests that cannot be processed by the device (host adapter, queue_full etc.).

Quoted 8 lines

In this latter case, the tag is already begun, so it needs to go back with end_tag (we start a new tag when the device begins processing again).

I own up to introducing the &= REQ_QUEUED rubbish---I was just keeping the original placement of the flag clearing code, but now we need to preserve whether the request was queued or not for the blk_rq_tagged check. On reflection it would have been better just to set the flags to REQ_SPECIAL | REQ_BARRIER after the end tag code.

I think you are missing the point. The stuff should not be in the _generic_ blk_insert_request(). As I posted in my first reply to Martin, SCSI needs to clear the tag before calling blk_insert_request() if it needs to.

Quoted 6 lines
Quoted 3 lines · [email protected] said:

But the crap still got merged, sigh... Yet again an excellent point of why stuff like this should go through the maintainer. Apparently Linus blindly applies this stuff.

Hmm, well I sent it to you and you are the Maintainer.

I've never seen it?!

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 27 lines · Jens Axboe
Quoted 17 lines · James Bottomley
Quoted 9 lines

You are right the

Quoted 3 lines

rq->flags &= REQ_QUEUED;
and the
if (blk_rq_tagged(rq))

blk_queue_end_tag(q, rq);

Quoted 1 line

should be just removed and things are fine.

They only survive becouse they don't provide a tag for the request in first place.

Quoted 1 line

Thanks for pointing it out.

Please don't remove this.

insert_special isn't just used to start new requests, it's also used to queue incoming requests that cannot be processed by the device (host adapter, queue_full etc.).

Quoted 8 lines

In this latter case, the tag is already begun, so it needs to go back with end_tag (we start a new tag when the device begins processing again).

I own up to introducing the &= REQ_QUEUED rubbish---I was just keeping the original placement of the flag clearing code, but now we need to preserve whether the request was queued or not for the blk_rq_tagged check. On reflection it would have been better just to set the flags to REQ_SPECIAL | REQ_BARRIER after the end tag code.

Quoted 4 lines

I think you are missing the point. The stuff should not be in the _generic_ blk_insert_request(). As I posted in my first reply to Martin, SCSI needs to clear the tag before calling blk_insert_request() if it needs to.

Here's the patch to fix it, btw. Linus, please apply.

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.509 -> 1.510
# drivers/block/ll_rw_blk.c 1.96 -> 1.97
# drivers/scsi/scsi_lib.c 1.29 -> 1.30
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/07/29 [email protected] 1.510

# undo REQ_QUEUED breakage in recent blk_insert_request() introduction
# --------------------------------------------
#
diff -Nru a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
--- a/drivers/block/ll_rw_blk.c	Mon Jul 29 07:53:43 2002
+++ b/drivers/block/ll_rw_blk.c	Mon Jul 29 07:53:43 2002
@@ -1253,7 +1253,7 @@
  *    host that is unable to accept a particular command.
  */
 void blk_insert_request(request_queue_t *q, struct request *rq,
-		int at_head, void *data)
+			int at_head, void *data)
 {
 	unsigned long flags;

@@ -1262,15 +1262,11 @@
* must not attempt merges on this) and that it acts as a soft
* barrier
*/
- rq->flags &= REQ_QUEUED;
rq->flags |= REQ_SPECIAL | REQ_BARRIER;

rq->special = data;

spin_lock_irqsave(q->queue_lock, flags);
- /* If command is tagged, release the tag */
- if(blk_rq_tagged(rq))
- blk_queue_end_tag(q, rq);
_elv_add_request(q, rq, !at_head, 0); q->request_fn(q); spin_unlock_irqrestore(q->queue_lock, flags);

drivers/scsi/scsi_lib.c +6 -0
diff -Nru a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
@@ -74,6 +74,9 @@
 {
 	request_queue_t *q = &SCpnt->device->request_queue;
 
+	if (blk_rq_tagged(SCpnt->request))
+		blk_queue_end_tag(q, SCpnt->request);
+
 	blk_insert_request(q, SCpnt->request, at_head, SCpnt);
 	return 0;
 }
@@ -101,6 +104,9 @@
 int scsi_insert_special_req(Scsi_Request * SRpnt, int at_head)
 {
 	request_queue_t *q = &SRpnt->sr_device->request_queue;
+
+	if (blk_rq_tagged(SRpnt->sr_request))
+		blk_queue_end_tag(q, SRpnt->sr_request);
 
 	blk_insert_request(q, SRpnt->sr_request, at_head, SRpnt);
 	return 0;
Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 7 lines · Jens Axboe
Quoted 5 lines

I think you are missing the point. The stuff should not be in the _generic_ blk_insert_request(). As I posted in my first reply to Martin, SCSI needs to clear the tag before calling blk_insert_request() if it needs to.

Here's the patch to fix it, btw. Linus, please apply.

I can't apply this while I think it looks horribly broken.

Your patch makes scsi_lib call blk_queue_end_tag() without holding the queue spinlock.

Which looks horribly broken, since it _will_ corrupt the queues.

In fact, it looks about a million times more broken than the code that Martin submitted.

Please explain to me why I am wrong.

Linus

PS. I actually do tend to look as the patches I apply. Right now it looks like you're wrong, and Martin is right.

#4 lore raw
Quoted 16 lines · Linus Torvalds
Quoted 7 lines · Jens Axboe
Quoted 5 lines

I think you are missing the point. The stuff should not be in the _generic_ blk_insert_request(). As I posted in my first reply to Martin, SCSI needs to clear the tag before calling blk_insert_request() if it needs to.

Here's the patch to fix it, btw. Linus, please apply.

I can't apply this while I think it looks horribly broken.

Your patch makes scsi_lib call blk_queue_end_tag() without holding the queue spinlock.

Quoted 6 lines

Which looks horribly broken, since it _will_ corrupt the queues.

In fact, it looks about a million times more broken than the code that Martin submitted.

Please explain to me why I am wrong.

Duh yes, the locking is broken of course :/

Ok I'd rather just make a __blk_insert_request as well, and have SCSI grab the lock itself.

Quoted 4 lines

Linus

PS. I actually do tend to look as the patches I apply. Right now it looks like you're wrong, and Martin is right.

I think Martin's was wrong in concept, mine was wrong in implementation.

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.509 -> 1.510
# drivers/block/ll_rw_blk.c 1.96 -> 1.97
# drivers/scsi/scsi_lib.c 1.29 -> 1.30
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/07/29 [email protected] 1.510

# blk_insert_request + REQ_QUEUED fixed
# --------------------------------------------
#
diff -Nru a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
--- a/drivers/block/ll_rw_blk.c	Mon Jul 29 08:33:16 2002
+++ b/drivers/block/ll_rw_blk.c	Mon Jul 29 08:33:16 2002
@@ -1233,6 +1233,23 @@
 	return rq;
 }

+void __blk_insert_request(request_queue_t *q, struct request *rq,
+ int at_head, void *data)
+{
+ /*
+ * tell I/O scheduler that this isn't a regular read/write (ie it
+ * must not attempt merges on this) and that it acts as a soft
+ * barrier
+ */
+ rq->flags &= REQ_QUEUED;
+ rq->flags |= REQ_SPECIAL | REQ_BARRIER;
+
+ rq->special = data;
+
+ _elv_add_request(q, rq, !at_head, 0);
+ q->request_fn(q);
+}
+
/**
* blk_insert_request - insert a special request in to a request queue
* @q: request queue where request should be inserted
@@ -1253,24 +1270,11 @@
* host that is unable to accept a particular command.
*/
void blk_insert_request(request_queue_t *q, struct request *rq,
- int at_head, void *data)
+ int at_head, void *data)
{
unsigned long flags;

- /*
- * tell I/O scheduler that this isn't a regular read/write (ie it
- * must not attempt merges on this) and that it acts as a soft
- * barrier
- */
- rq->flags &= REQ_QUEUED;
- rq->flags |= REQ_SPECIAL | REQ_BARRIER;
-
- rq->special = data;
-
spin_lock_irqsave(q->queue_lock, flags);
- /* If command is tagged, release the tag */
- if(blk_rq_tagged(rq))
- blk_queue_end_tag(q, rq);
_elv_add_request(q, rq, !at_head, 0); q->request_fn(q); spin_unlock_irqrestore(q->queue_lock, flags);
@@ -2125,6 +2129,7 @@
EXPORT_SYMBOL(blk_get_request); EXPORT_SYMBOL(__blk_get_request); EXPORT_SYMBOL(blk_put_request);
+EXPORT_SYMBOL(__blk_insert_request);
EXPORT_SYMBOL(blk_insert_request);

EXPORT_SYMBOL(blk_queue_prep_rq);

drivers/scsi/scsi_lib.c +16 -2
diff -Nru a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
@@ -73,8 +73,15 @@
 int scsi_insert_special_cmd(Scsi_Cmnd * SCpnt, int at_head)
 {
 	request_queue_t *q = &SCpnt->device->request_queue;
+	unsigned long flags;
 
-	blk_insert_request(q, SCpnt->request, at_head, SCpnt);
+	spin_lock_irqsave(q->queue_lock, flags);
+
+	if (blk_rq_tagged(SCpnt->request))
+		blk_queue_end_tag(q, SCpnt->request);
+
+	__blk_insert_request(q, SCpnt->request, at_head, SCpnt);
+	spin_unlock_irqrestore(q->queue_lock, flags);
 	return 0;
 }
 
@@ -101,8 +108,15 @@
 int scsi_insert_special_req(Scsi_Request * SRpnt, int at_head)
 {
 	request_queue_t *q = &SRpnt->sr_device->request_queue;
+	unsigned long flags;
+
+	spin_lock_irqsave(q->queue_lock, flags);
+
+	if (blk_rq_tagged(SRpnt->sr_request))
+		blk_queue_end_tag(q, SRpnt->sr_request);
 
-	blk_insert_request(q, SRpnt->sr_request, at_head, SRpnt);
+	__blk_insert_request(q, SRpnt->sr_request, at_head, SRpnt);
+	spin_unlock_irqrestore(q->queue_lock, flags);
 	return 0;
 }
 
Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 2 lines · Jens Axboe

I think Martin's was wrong in concept, mine was wrong in implementation.

I don't understand why you think the concept is wrong. Right now all users clearly do want to free the tag on re-issue, and doing so clearly cleans up the code and avoids duplication.

So I still don't see the advantage of your patch, even once you've fixed the locking issue.

HOWEVER, if you really think that some future users might not want to have the tag played with, how about making the "at_head" thing a flags field, and letting people say so by having "INSERT_NOTAG" (and making the existing bit be INSERT_ATHEAD).

So then the SCSI users would look like

	blk_insert_request(q, SRpnt->sr_request,
		at_head ? INSERT_ATHEAD : 0,
		SRpnt)

while your future non-tag user might do

	blk_insert_request(q, newreq,
		INSERT_ATHEAD | INSERT_NOTAG,
		channel);

_without_ having that unnecessary code duplication.

Linus

#6 lore raw
Quoted 4 lines · Linus Torvalds
Quoted 1 line · Jens Axboe
Quoted 8 lines
Quoted 1 line

I think Martin's was wrong in concept, mine was wrong in implementation.

I don't understand why you think the concept is wrong. Right now all users clearly do want to free the tag on re-issue, and doing so clearly cleans up the code and avoids duplication.

So I still don't see the advantage of your patch, even once you've fixed the locking issue.

Ok... I had two issues with the patch. 1) it did

	rq->flags &= REQ_QUEUED;

which is just broken. 2) it combined the act of inserting back into the block queue with clearing the tag associated with the request. #1 is clearly a bug that should be fixed regardless of what we do. Right now, yes, the only user of blk_insert_request (SCSI) needs the tag cleared. I still don't think that's a reason to mingle the two different tasks into one. Code duplication is not an argument, the two scsi_insert_* should be folded into one. The only difference is SRpnt->sr_request vs SCpnt->request after all.

Quoted 11 lines

HOWEVER, if you really think that some future users might not want to have the tag played with, how about making the "at_head" thing a flags field, and letting people say so by having "INSERT_NOTAG" (and making the existing bit be INSERT_ATHEAD).

So then the SCSI users would look like

	blk_insert_request(q, SRpnt->sr_request,
		at_head ? INSERT_ATHEAD : 0,
		SRpnt)
Quoted 7 lines

while your future non-tag user might do

	blk_insert_request(q, newreq,
		INSERT_ATHEAD | INSERT_NOTAG,
		channel);

_without_ having that unnecessary code duplication.

*shrug* I guess we could do that. I don't see any immediate use beyond at_head/back and tag clearing.

I'll back down, it's not a matter of life and death after all. Here's the minimal patch that corrects the flag thing, and also makes blk_insert_request() conform to kernel style. Are we all happy?

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.509 -> 1.510
# drivers/block/ll_rw_blk.c 1.96 -> 1.97
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/07/29 [email protected] 1.510

# fix REQ_QUEUED clearing in blk_insert_request()
# --------------------------------------------
#
diff -Nru a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
--- a/drivers/block/ll_rw_blk.c	Mon Jul 29 12:42:43 2002
+++ b/drivers/block/ll_rw_blk.c	Mon Jul 29 12:42:43 2002
@@ -1253,7 +1253,7 @@
  *    host that is unable to accept a particular command.
  */
 void blk_insert_request(request_queue_t *q, struct request *rq,
-		int at_head, void *data)
+			int at_head, void *data)
 {
 	unsigned long flags;

@@ -1262,15 +1262,18 @@
* must not attempt merges on this) and that it acts as a soft
* barrier
*/
- rq->flags &= REQ_QUEUED;
rq->flags |= REQ_SPECIAL | REQ_BARRIER;

rq->special = data;

spin_lock_irqsave(q->queue_lock, flags);
- /* If command is tagged, release the tag */
- if(blk_rq_tagged(rq))
+
+ /*
+ * If command is tagged, release the tag
+ */
+ if (blk_rq_tagged(rq))
blk_queue_end_tag(q, rq);
+
_elv_add_request(q, rq, !at_head, 0); q->request_fn(q); spin_unlock_irqrestore(q->queue_lock, flags);

Signature · 1 line
Jens Axboe
#7 lore raw
Quoted 2 lines · [email protected] said:

Ok... I had two issues with the patch. 1) it did

	rq->flags &= REQ_QUEUED; 

Yes, that was inherited from SCSI. Previously it just cleared flags and then set REQ_BARRIER|REQ_SPECIAL. Now I needed to clear flags but preserve the state of REQ_QUEUED, which is what that code is doing, otherwise the blk_rq_tagged() would always fail lower down.

Quoted 3 lines

I'll back down, it's not a matter of life and death after all. Here's the minimal patch that corrects the flag thing, and also makes blk_insert_request() conform to kernel style. Are we all happy?

I'm happy (as long as it works on my SCSI card).

James

#8 lore raw
Quoted 9 lines · James Bottomley
Quoted 2 lines · [email protected] said:

Ok... I had two issues with the patch. 1) it did

	rq->flags &= REQ_QUEUED; 

Yes, that was inherited from SCSI. Previously it just cleared flags and then set REQ_BARRIER|REQ_SPECIAL. Now I needed to clear flags but preserve the state of REQ_QUEUED, which is what that code is doing, otherwise the blk_rq_tagged() would always fail lower down.

Quoted 8 lines
Quoted 3 lines

I'll back down, it's not a matter of life and death after all. Here's the minimal patch that corrects the flag thing, and also makes blk_insert_request() conform to kernel style. Are we all happy?

I'm happy (as long as it works on my SCSI card).

James

BTW.> I just noticed quite a "bunch" of single line functions in the SCIS code. Sort of like:

int scsi_warp_foo(xxx)

{
     foor(whis and that);
}.

EXPORT_SYMBOL(scsi_wrap_foo);

All of them just eat space on the stack during execution. Would you mind moving them over to scsi.h and making them static inline?

We all know that SCSI has sometimes problems with the limited stack depth during kernel code execution time, esp on "Black Big Boxen"... Well the above "tactics" doesn't hlep buch, but a bit is a bit is a bit and "a man/farmer doesn't foregive someone still alive"... :-).