Optimize scsi_cmnd initialization and bug fix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



struct scsi_cmnd is a fairly large data structure and is used
to construct scsi command.  On x86-64 arch, it is 448 bytes.  

In scsi_get_command(), it is a bit too paranoid in zeroing the
data structure.  Since most of the member variables will be
initialized in various stage of I/O submission, i.e., in
scsi_prep_fn, scsi_init_io, sd_init_command, scsi_init_cmd_errh,
etc.  So instead of blindly zeroing the whole structure, initialize
to some other value later on.  All it needs in scsi_get_command
is to zero out a few member variables that aren't initialized in
the I/O path.

I'm proposing the following patch to optimize scsi_cmnd initialization.
The only part that I'm not 100% sure is struct scsi_pointer SCp and
eh_eflags.  It appears to be safe, but since I don't have every scsi
controllers in the world to test, I can't say so for sure.  I'm willing
to take on the responsibility to fix any hiccup people might have with
this patch.  Comments?

p.s. de-referencing jiffies_at_alloc ought be in the if(cmd!=NULL) block.


Signed-off-by: Ken Chen <kenneth.w.chen@xxxxxxxxx>

--- ./drivers/scsi/scsi.c.orig	2005-11-23 13:04:46.607198199 -0800
+++ ./drivers/scsi/scsi.c	2005-11-23 13:05:38.154072568 -0800
@@ -258,17 +258,18 @@ struct scsi_cmnd *scsi_get_command(struc
 	if (likely(cmd != NULL)) {
 		unsigned long flags;
 
-		memset(cmd, 0, sizeof(*cmd));
+		cmd->cmd_len = 0;
+		cmd->sc_request = 0;
+		cmd->retries = 0;
 		cmd->device = dev;
 		init_timer(&cmd->eh_timeout);
-		INIT_LIST_HEAD(&cmd->list);
 		spin_lock_irqsave(&dev->list_lock, flags);
 		list_add_tail(&cmd->list, &dev->cmd_list);
 		spin_unlock_irqrestore(&dev->list_lock, flags);
+		cmd->jiffies_at_alloc = jiffies;
 	} else
 		put_device(&dev->sdev_gendev);
 
-	cmd->jiffies_at_alloc = jiffies;
 	return cmd;
 }				
 EXPORT_SYMBOL(scsi_get_command);



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux