> ChangeSet 1.855.4.11, 2002/10/31 12:37:07-08:00, [email protected]
> convert edd to use kobjects and sysfs.
Pat, thanks for converting the EDD code to sysfs. Is struct attribute going
to grow some form of existence test, something like I had done before?
> -static int
> -edd_populate_dir(struct edd_device *edev)
> -{
> - struct edd_attribute *attr;
> - int i;
> - int error = 0;
> -
> - for (i = 0; (attr=def_attrs[i]); i++) {
> - if (!attr->test || (attr->test && !attr->test(edev))) {
> - if ((error = edd_create_file(edev, attr))) {
> - break;
> - }
> - }
> - }
This allows attributes to be on default_attrs[] but depending on presence of
existence test (no test means true) and test result, not all attributes for
all similar objects get files created. This cleanly handles cases where not
all attributes are implemented or valid for all objects of a given type, and
keeps the object's directory free of extraneous invalid files.
There are two other alternatives I see:
1) Put all attributes on default_attrs, have them be created by
kobject_register(), then immediately delete those which fail existence -
calls to sysfs_remove_file().
2) Put only those attributes we know always exist on default_attrs, and
separately register those others who pass their existence - which would
duplicate the populate_dir() code from lib/kobject.c essentially - calls to
sysfs_create_file().
Both of these violate the kobject abstraction. I'd prefer to see an
attribute existence test used in populate_dir().
Thoughts?
Thanks,
Matt
--
Matt Domsch
Sr. Software Engineer, Lead Engineer, Architect
Dell Linux Solutions http://www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com
On Fri, 22 Nov 2002 [email protected] wrote:
> > ChangeSet 1.855.4.11, 2002/10/31 12:37:07-08:00, [email protected]
> > convert edd to use kobjects and sysfs.
>
> Pat, thanks for converting the EDD code to sysfs. Is struct attribute going
> to grow some form of existence test, something like I had done before?
Crap. I saw your email from three weeks ago, and I think I even started
replying to it. But, it must have got lost.. I'm really sorry about that.
> > -static int
> > -edd_populate_dir(struct edd_device *edev)
> > -{
> > - struct edd_attribute *attr;
> > - int i;
> > - int error = 0;
> > -
> > - for (i = 0; (attr=def_attrs[i]); i++) {
> > - if (!attr->test || (attr->test && !attr->test(edev))) {
> > - if ((error = edd_create_file(edev, attr))) {
> > - break;
> > - }
> > - }
> > - }
>
> This allows attributes to be on default_attrs[] but depending on presence of
> existence test (no test means true) and test result, not all attributes for
> all similar objects get files created. This cleanly handles cases where not
> all attributes are implemented or valid for all objects of a given type, and
> keeps the object's directory free of extraneous invalid files.
>
> There are two other alternatives I see:
> 1) Put all attributes on default_attrs, have them be created by
> kobject_register(), then immediately delete those which fail existence -
> calls to sysfs_remove_file().
> 2) Put only those attributes we know always exist on default_attrs, and
> separately register those others who pass their existence - which would
> duplicate the populate_dir() code from lib/kobject.c essentially - calls to
> sysfs_create_file().
>
> Both of these violate the kobject abstraction. I'd prefer to see an
> attribute existence test used in populate_dir().
I overlooked this part of your code, and will fix it. IMO, the proper
thing to do is Option #2 - only put those attributes we know exist in the
default_attrs[] array - and add the conditional attributes later. Though
it does duplicate code, I'd rather favor the common case where default
attributes really are default attributes, and don't need an existence
test.
-pat