Re: [PATCH] Introduce {sysfs,device}_create_file_mode

From: Anton Vorontsov
Date: Wed May 12 2010 - 15:08:25 EST


On Wed, May 12, 2010 at 11:38:06AM -0700, Greg KH wrote:
> On Wed, May 12, 2010 at 10:15:46PM +0400, Anton Vorontsov wrote:
> > We need to create attributes with different modes across devices.
> > We can do this by modifying attr.mode between device_create_file
> > invocations, but that is racy in case of globally defined attrs.
> >
> > Luckily, there's sysfs_add_file_mode() function that seems to do
> > exactly what we want, and if we use it, we don't need any locks
> > to avoid races. Though, it isn't exposed via device-drivers core
> > API.
>
> But you race the creation of the device notifying userspace, and then
> the file being created, right?

Yep, you've raised that question once, like 3 years ago. :-)

http://lkml.org/lkml/2007/4/11/452
http://lkml.org/lkml/2007/4/12/144

In short: we can't use attr groups since the attributes creation
is conditional. And we especially don't want to use the attr groups
for attrs with different modes. But it's not a problem, because...

> Or is that properly taken care of elsewhere?

Yep, userland should just listen to uevents, we're sending
'changed' event at the end of the registration. Attributes
may appear and disappear dynamically, battery handling
userland have to cope with that anyway.

> > Greg, does the patch look OK? If so, I'd like it to go
> > via battery-2.6.git tree, along with patches that need
> > that one.
>
> Looks good with one minor problem:
>
> > --- a/drivers/base/core.c
> > +++ b/drivers/base/core.c
> > @@ -440,6 +440,27 @@ struct kset *devices_kset;
> > * device_create_file - create sysfs attribute file for device.
>
> That should be "device_create_file_mode"

Thanks for catching! Will change.

> Make that change and then feel free to take it through your tree with
> an:
> Acked-by: Greg Kroah-Hartman <gregkh@xxxxxxx>
> on it.

--
Anton Vorontsov
email: cbouatmailru@xxxxxxxxx
irc://irc.freenode.net/bd2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/