From: Milan Broz on
On 07/29/2010 09:56 PM, Karel Zak wrote:
>> Sure it does. Sysfs attributes need to be created _before_ uevents are
>> sent out. The current behavior is that all blockdev attributes are
>> safely created before the event is sent. These loop attributes are
>> created _after_ the event is sent.
>>
>> The question is if we can rely on the fact, that 'add' events never
>> want to look at any of these attributes, and all can be deferred to

The problem is that add_disk() initializes kobject and announces device.
How can I add some new attributes (subdir) with the current code
before it happens?

And why it is problem at all? After configuration there is always change
event and at this time attributes are there.

Milan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Kay Sievers on
On Thu, Jul 29, 2010 at 22:24, Milan Broz <mbroz(a)redhat.com> wrote:
> On 07/29/2010 09:56 PM, Karel Zak wrote:
>>> Sure it does. Sysfs attributes need to be created _before_ uevents are
>>> sent out. The current behavior is that all blockdev attributes are
>>> safely created before the event is sent. These loop attributes are
>>> created _after_ the event is sent.
>>>
>>> The question is if we can rely on the fact, that 'add' events never
>>> want to look at any of these attributes, and all can be deferred to
>
> The problem is that add_disk() initializes kobject and announces device.
> How can I add some new attributes (subdir) with the current code
> before it happens?

Use attribute groups, and assign them to the class, or in this case to
the device before it is registered. All this stuff is created by the
core before the event is sent out. It also takes care of the subdir,
instead rolling your own kobject stuff, does proper error handling,
and cleans-up things in the proper order, without any further custom
code.

Alternatively, these attributes could be created and removed/created
with the ioctl, and before the 'change' event, only if there is an
active backing file, but I would expect the attribute group at the
device to work just fine.

> And why it is problem at all? After configuration there is always change
> event and at this time attributes are there.

As said, if we can rely on this fact, and there will never be any
attribute now, or added in the future, to this block of attributes,
this might be just fine, that's why I ask ...

We spent a lot of time to get the sysfs timing right, fix all the
subsystems, and make udev work with all sorts of attributes which have
been created like this. To add out-of-band attribute creation timing
today, there needs to be a very good reason to do so.

If you need any help with a try to a switch to the attribute group,
please let me know.

Kay
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Kay Sievers on
On Fri, Jul 30, 2010 at 09:37, Karel Zak <kzak(a)redhat.com> wrote:
> On Thu, Jul 29, 2010 at 06:07:31PM +0200, Kay Sievers wrote:
>> Sure it does. Sysfs attributes need to be created _before_ uevents are
>> sent out. The current behavior is that all blockdev attributes are
>> safely created before the event is sent.
>
>  Hmm... I see that in add_disk(), the "queue" subdirectory is created
>  after disk registration (the register_disk() calls kobject_uevent()).
>  Is it true?

Might be. Then seems nobody has tried using this stuff from udev. :)

blk_register_queue() probably needs to move to register_disk(), where
the uevent is delayed until all stuff is properly created.

Kay
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Kay Sievers on
On Fri, Jul 30, 2010 at 09:43, Kay Sievers <kay.sievers(a)vrfy.org> wrote:
> On Fri, Jul 30, 2010 at 09:37, Karel Zak <kzak(a)redhat.com> wrote:
>> On Thu, Jul 29, 2010 at 06:07:31PM +0200, Kay Sievers wrote:
>>> Sure it does. Sysfs attributes need to be created _before_ uevents are
>>> sent out. The current behavior is that all blockdev attributes are
>>> safely created before the event is sent.
>>
>>  Hmm... I see that in add_disk(), the "queue" subdirectory is created
>>  after disk registration (the register_disk() calls kobject_uevent()).
>>  Is it true?
>
> Might be. Then seems nobody has tried using this stuff from udev. :)
>
> blk_register_queue() probably needs to move to register_disk(), where
> the uevent is delayed until all stuff is properly created.

Seems, someone should finally move register_disk() from
fs/partition/check.c to block/genhd.c, where it belongs, and merge the
code into add_disk(), where the control over the event timing is
easily possible.

Kay
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Kay Sievers on
On Fri, Jul 30, 2010 at 16:22, Milan Broz <mbroz(a)redhat.com> wrote:
> On 07/30/2010 06:36 AM, Kay Sievers wrote:
>
>> Alternatively, these attributes could be created and removed/created
>> with the ioctl, and before the 'change' event, only if there is an
>> active backing file, but I would expect the attribute group at the
>> device to work just fine.
> I have no idea how you can add attribute group before add_disk() which
> initializes kobj (it ends with BUG_ON in internal_create_group
> - because !kobj->sd). Perhaps I missed something?

Attribute groups handle the creation of a kobject (subdir) for you,
you only supply a name to the group. Without a name, they will put all
the attributes in the root of the device.

The 'struct device' has a member **groups, and that can have a list of
attribute groups assigned. You assign them before you register the
device, and the core will take care of everything.

> Anyway, second approach works - now is loop attributes available only
> when loop is configured and before CHANGE uevent is sent.
>
> Ok with that?

Sounds good, nothing to complain from a sysfs timing perspective.

Now you have do decide if you prefer that over the attribute group
approach. :) The code with attribute groups, instead of custom kobject
stuff, might be a bit easier to understand.

Thanks,
Kay
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/