All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about scsi_host_alloc
@ 2007-07-18 11:00 jidong xiao
  2007-07-18 11:26 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: jidong xiao @ 2007-07-18 11:00 UTC (permalink / raw)
  To: linux-scsi

I see this function,struct Scsi_Host *scsi_host_alloc(struct
scsi_host_template *, int), I am wondering what does the second
parameter used for?Say,

/**
 * scsi_host_alloc - register a scsi host adapter instance.
 * @sht:	pointer to scsi host template
 * @privsize:	extra bytes to allocate for driver
 *
 * Note:
 * 	Allocate a new Scsi_Host and perform basic initialization.
 * 	The host is not published to the scsi midlayer until scsi_add_host
 * 	is called.
 *
 * Return value:
 * 	Pointer to a new Scsi_Host
 **/
struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)

I mean the privsize, i.e. extra bytes, why do we need such extra
bytes?Who will use it?

Regards
Jason Xiao

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question about scsi_host_alloc
  2007-07-18 11:00 Question about scsi_host_alloc jidong xiao
@ 2007-07-18 11:26 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2007-07-18 11:26 UTC (permalink / raw)
  To: jidong xiao; +Cc: linux-scsi

On Wed, Jul 18, 2007 at 07:00:01PM +0800, jidong xiao wrote:
> I see this function,struct Scsi_Host *scsi_host_alloc(struct
> scsi_host_template *, int), I am wondering what does the second
> parameter used for?Say,
> 
> I mean the privsize, i.e. extra bytes, why do we need such extra
> bytes?Who will use it?

It's for the use of the driver.  Many drivers have a struct containing
additional information, such as:

struct scsi_qla_host {
        /* Linux adapter configuration data */
        struct Scsi_Host *host; /* pointer to host data */
        struct scsi_qla_host *next;
        struct device_reg __iomem *iobase;      /* Base Memory-mapped I/O addres
s */
[....]
        struct nvram nvram;
        int nvram_valid;
};

...
        struct scsi_qla_host *ha;
        host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
        ha = (struct scsi_qla_host *)host->hostdata;

It means the driver doesn't need to allocate the private data separately,
so it's a little more efficient.  You also don't need to worry about
reference counting it; it will be freed when the Scsi_Host is freed.

-- 
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-07-18 11:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-18 11:00 Question about scsi_host_alloc jidong xiao
2007-07-18 11:26 ` Matthew Wilcox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.