* Attr Groups in sysfs.
@ 2011-04-18 9:45 Gasparini Andrea
2011-04-18 14:14 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Gasparini Andrea @ 2011-04-18 9:45 UTC (permalink / raw)
To: kernelnewbies
Hi,
I've a pattern similar to this in sysfs: /sys/.../mykobj/myattr_group/attr.
And I've some different attr groups, but I'm willing to group also the
get/set functions and recognize at runtime which kobj,group,and
attribute is called inside the functions.
But, if I'm not wrong the attribute functions are called:
static ssize_t some_attribute_set(struct kobject *kobj,
struct container_attribute *attr, const char *buf, size_t count)
And I can get the "mykobj" name with kobj->name,
and attribute names by attr->attr.name.
I'm missing only the myattr_group name... anyone has a clue of how can
I access this?
Just for completeness, I'm working on a 2.6.38 kernel, and I'm
declaring the groups this way:
struct container_attribute {
struct attribute attr;
ssize_t (*show)(struct kobject *, struct container_attribute *, char *);
ssize_t (*store)(struct kobject *, struct container_attribute *,
const char *, size_t);
};
static struct attribute *lot_of_attrs[] = {
first_attribute.attr,
and_so_on.attr,
NULL,
};
static struct attribute_group my_attr_group_0 = {
.name = "myattr_group_0",
.attrs = lots_of_attrs,
};
And adding to my kobject this way:
retval = sysfs_create_group(mykobj, &my_attr_group_0);
Thanks, bye!
--
-gaspa-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Attr Groups in sysfs.
2011-04-18 9:45 Attr Groups in sysfs Gasparini Andrea
@ 2011-04-18 14:14 ` Greg KH
2011-04-18 14:29 ` Gasparini Andrea
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2011-04-18 14:14 UTC (permalink / raw)
To: kernelnewbies
On Mon, Apr 18, 2011 at 11:45:23AM +0200, Gasparini Andrea wrote:
> Hi,
>
> I've a pattern similar to this in sysfs: /sys/.../mykobj/myattr_group/attr.
> And I've some different attr groups, but I'm willing to group also the
> get/set functions and recognize at runtime which kobj,group,and
> attribute is called inside the functions.
>
> But, if I'm not wrong the attribute functions are called:
>
> static ssize_t some_attribute_set(struct kobject *kobj,
> struct container_attribute *attr, const char *buf, size_t count)
>
> And I can get the "mykobj" name with kobj->name,
> and attribute names by attr->attr.name.
>
> I'm missing only the myattr_group name... anyone has a clue of how can
> I access this?
You can't.
> Just for completeness, I'm working on a 2.6.38 kernel, and I'm
> declaring the groups this way:
>
> struct container_attribute {
> struct attribute attr;
> ssize_t (*show)(struct kobject *, struct container_attribute *, char *);
> ssize_t (*store)(struct kobject *, struct container_attribute *,
> const char *, size_t);
> };
>
> static struct attribute *lot_of_attrs[] = {
> first_attribute.attr,
> and_so_on.attr,
> NULL,
> };
>
> static struct attribute_group my_attr_group_0 = {
> .name = "myattr_group_0",
> .attrs = lots_of_attrs,
> };
>
> And adding to my kobject this way:
> retval = sysfs_create_group(mykobj, &my_attr_group_0);
Ick, no, please don't do that, you want the group to be created before
the device shows up to userspace, otherwise you just raced with
userspace and bad things will happen.
Why are you using a struct kobject directly and not a struct device
instead? Please don't use kobjects unless you are doing something very
strange, and even then, please reconsider.
Care to explain what you are using sysfs for?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Attr Groups in sysfs.
2011-04-18 14:14 ` Greg KH
@ 2011-04-18 14:29 ` Gasparini Andrea
2011-04-18 16:08 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Gasparini Andrea @ 2011-04-18 14:29 UTC (permalink / raw)
To: kernelnewbies
Hi,
On Mon, Apr 18, 2011 at 4:14 PM, Greg KH <greg@kroah.com> wrote:
>> I'm missing only the myattr_group name... anyone has a clue of how can
>> I access this?
>
> You can't.
ok.
>> And adding to my kobject this way:
>> ? ? retval = sysfs_create_group(mykobj, &my_attr_group_0);
>
> Ick, no, please don't do that, you want the group to be created before
> the device shows up to userspace, otherwise you just raced with
> userspace and bad things will happen.
Understand, you're completely right.
I'll try to refactor in a different way to avoid race.
> Why are you using a struct kobject directly and not a struct device
> instead? ?Please don't use kobjects unless you are doing something very
> strange, and even then, please reconsider.
>
> Care to explain what you are using sysfs for?
Sure, It's quite complicated, in fact ;)
I'm doing an "extension" for a video device, in terms of a module that
handle some addictional logic that do some sort of stats about the
stream passed through it.
For example, I've a certain number of areas inside a frame, given in
form of (x,y,width,heigth) that behave to the same device, so I'd like
to call them: mydev/region_{0,1,2...}/{x,y,width,height}
That's why I'd like to have the "region_0" name, so I can distinguish
between the right attribute group.
Too caotic perhaps? (suggestions and existing examples are obviuosly welcome)
> thanks,
Thank *you* ;)
bye
--
-gaspa-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Attr Groups in sysfs.
2011-04-18 14:29 ` Gasparini Andrea
@ 2011-04-18 16:08 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2011-04-18 16:08 UTC (permalink / raw)
To: kernelnewbies
On Mon, Apr 18, 2011 at 04:29:57PM +0200, Gasparini Andrea wrote:
> Hi,
>
> On Mon, Apr 18, 2011 at 4:14 PM, Greg KH <greg@kroah.com> wrote:
> >> I'm missing only the myattr_group name... anyone has a clue of how can
> >> I access this?
> >
> > You can't.
>
> ok.
>
> >> And adding to my kobject this way:
> >> ? ? retval = sysfs_create_group(mykobj, &my_attr_group_0);
> >
> > Ick, no, please don't do that, you want the group to be created before
> > the device shows up to userspace, otherwise you just raced with
> > userspace and bad things will happen.
>
> Understand, you're completely right.
> I'll try to refactor in a different way to avoid race.
>
> > Why are you using a struct kobject directly and not a struct device
> > instead? ?Please don't use kobjects unless you are doing something very
> > strange, and even then, please reconsider.
> >
> > Care to explain what you are using sysfs for?
>
> Sure, It's quite complicated, in fact ;)
> I'm doing an "extension" for a video device, in terms of a module that
> handle some addictional logic that do some sort of stats about the
> stream passed through it.
> For example, I've a certain number of areas inside a frame, given in
> form of (x,y,width,heigth) that behave to the same device, so I'd like
> to call them: mydev/region_{0,1,2...}/{x,y,width,height}
>
> That's why I'd like to have the "region_0" name, so I can distinguish
> between the right attribute group.
That's fine, but again, don't use a kobject, use the normal struct
device you already have in your driver for this device.
But wait, don't nest attributes that deep, an attribute group should
only be one level deep on a device, otherwise you are thinking it is a
real device that lives there, and userspace tools might have a hard time
finding the data.
Or, create a new "device" called region_*, attach it to a bus for your
device, and then use the attribute group for that device.
Yeah, it's a bit complex, but you are trying to get sysfs and the driver
model to do things it was not designed for, so you will have to write
more code than you might have thought.
Have you looked at the media device framework that the v4l layer now
provides you? That might have enough functionality for what you are
wanting to do here.
And of course, you need to document your sysfs files properly with
entries in Documentation/ABI/
Good luck,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-04-18 16:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-18 9:45 Attr Groups in sysfs Gasparini Andrea
2011-04-18 14:14 ` Greg KH
2011-04-18 14:29 ` Gasparini Andrea
2011-04-18 16:08 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).