All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Mansfield <patmans@us.ibm.com>
To: James Bottomley <James.Bottomley@steeleye.com>
Cc: SCSI Mailing List <linux-scsi@vger.kernel.org>,
	Mike Anderson <andmike@us.ibm.com>
Subject: Re: Round II on sysfs attributes
Date: Fri, 23 May 2003 11:30:03 -0700	[thread overview]
Message-ID: <20030523113003.A15369@beaverton.ibm.com> (raw)
In-Reply-To: <1053707904.1810.4.camel@mulgrave>; from James.Bottomley@steeleye.com on Fri, May 23, 2003 at 12:38:24PM -0400

On Fri, May 23, 2003 at 12:38:24PM -0400, James Bottomley wrote:
> 
> The attached patch makes the sysfs attributes a property of the host
> template (I can't really see a reason why the actual attributes need to
> change per host, so I think the template is the better place for them).
> 
> I've also provided helper functions to modify the attributes in the LLD
> init routines.
> 
> An illustration of how this works for the 53c700 will follow.
> 
> James

Any examples of potential LLDD specific host attributes?

Looks good for modifying attributes.

For additional attributes, why not an LLDD specific function to add and
remove them?

> diff -Nru a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
> --- a/drivers/scsi/hosts.c	Fri May 23 12:35:11 2003
> +++ b/drivers/scsi/hosts.c	Fri May 23 12:35:11 2003
> @@ -321,7 +321,12 @@
>             shost_tp->eh_host_reset_handler == NULL) {
>  		printk(KERN_ERR "ERROR: SCSI host `%s' has no error handling\nERROR: This is not a safe way to run your SCSI host\nERROR: The error handling must be added to this driver\n", shost_tp->proc_name);
>  		dump_stack();
> -        } 
> +        }
> +	if(shost_tp->shost_attrs == NULL)
> +		/* if its not set in the template, use the default */
> +		 shost_tp->shost_attrs = scsi_sysfs_shost_attrs;
> +	if(shost_tp->sdev_attrs == NULL)
> +		 shost_tp->sdev_attrs = scsi_sysfs_sdev_attrs;
>  	gfp_mask = GFP_KERNEL;
>  	if (shost_tp->unchecked_isa_dma && xtr_bytes)
>  		gfp_mask |= __GFP_DMA;

Code style nit: in the above and elsewhere use "if (", "for (" instead of
"if(" or  "for(".

> +int scsi_sysfs_modify_shost_attribute(struct class_device_attribute ***class_attrs,
> +				      struct class_device_attribute *attr)
> +{
> +	int modify = 0;
> +	int num_attrs;
> +
> +	if(*class_attrs == NULL)
> +		*class_attrs = scsi_sysfs_shost_attrs;
> +
> +	for(num_attrs=0; (*class_attrs)[num_attrs] != NULL; num_attrs++)
> +		if(strcmp((*class_attrs)[num_attrs]->attr.name, attr->attr.name) == 0)
> +			modify = num_attrs;
> +
> +	if(*class_attrs == scsi_sysfs_shost_attrs || !modify) {
> +		struct class_device_attribute **tmp_attrs = kmalloc(sizeof(struct class_device_attribute)*(num_attrs + (modify ? 0 : 1)), GFP_KERNEL);
> +		if(tmp_attrs == NULL)
> +			return -ENOMEM;
> +		memcpy(tmp_attrs, *class_attrs, sizeof(struct class_device_attribute)*num_attrs);
> +		if(*class_attrs != scsi_sysfs_shost_attrs)
> +			kfree(*class_attrs);
> +		*class_attrs = tmp_attrs;

For completeness, an allocated *class_attrs should be freed on LLDD module
exit. Same for the sdev attrs.

-- Patrick Mansfield

  reply	other threads:[~2003-05-23 18:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-23 16:38 Round II on sysfs attributes James Bottomley
2003-05-23 18:30 ` Patrick Mansfield [this message]
2003-05-23 19:37   ` James Bottomley
2003-05-23 18:51 ` Mike Anderson
2003-05-23 19:43   ` James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030523113003.A15369@beaverton.ibm.com \
    --to=patmans@us.ibm.com \
    --cc=James.Bottomley@steeleye.com \
    --cc=andmike@us.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.