Re: [PATCH 1/3 RFC] Driver core: Add offline/online device operations
From: Rafael J. Wysocki
Date: Fri May 03 2013 - 07:40:37 EST
On Thursday, May 02, 2013 05:29:33 PM Toshi Kani wrote:
> On Thu, 2013-05-02 at 02:58 +0200, Rafael J. Wysocki wrote:
> > On Tuesday, April 30, 2013 05:38:38 PM Toshi Kani wrote:
> > > On Mon, 2013-04-29 at 14:26 +0200, Rafael J. Wysocki wrote:
> > > > From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
> :
> > > > + */
> > > > +int device_offline(struct device *dev)
> > > > +{
> > > > + int ret;
> > > > +
> > > > + if (dev->offline_disabled)
> > > > + return -EPERM;
> > > > +
> > > > + ret = device_for_each_child(dev, NULL, device_check_offline);
> > > > + if (ret)
> > > > + return ret;
> > > > +
> > > > + device_lock(dev);
> > > > + if (device_supports_offline(dev)) {
> > > > + if (dev->offline) {
> > > > + ret = 1;
> > > > + } else {
> > > > + ret = dev->bus->offline(dev);
> > > > + if (!ret) {
> > > > + kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
> > > > + dev->offline = true;
> > >
> > > Shouldn't this offline flag be set before sending KOBJ_OFFLINE?
> > >
> > > > + }
> > > > + }
> > > > + }
> > > > + device_unlock(dev);
> > > > +
> > > > + return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * device_online - Put the device back online after successful device_offline().
> > > > + * @dev: Device to be put back online.
> > > > + *
> > > > + * If device_offline() has been successfully executed for @dev, but the device
> > > > + * has not been removed subsequently, execute its bus type's .online() callback
> > > > + * to indicate that the device can be used again.
> > >
> > > There is another use-case for online(). When a device like CPU is
> > > hot-added, it is added in offline. I am not sure why, but it has been
> > > this way. So, we need to call online() to make a new device available
> > > for use after a hot-add.
> >
> > Actually, in the CPU case that is left to user space as far as I can say.
> > That is, the device appears initially offline and user space is supposed to
> > bring it online via sysfs.
> >
> > > > + *
> > > > + * Call under device_offline_lock.
> > > > + */
> > > > +int device_online(struct device *dev)
> > > > +{
> > > > + int ret = 0;
> > > > +
> > > > + device_lock(dev);
> > > > + if (device_supports_offline(dev)) {
> > > > + if (dev->offline) {
> > > > + ret = dev->bus->online(dev);
> > > > + if (!ret) {
> > > > + kobject_uevent(&dev->kobj, KOBJ_ONLINE);
> > > > + dev->offline = false;
> > >
> > > Same comment as KOBJ_OFFLINE.
> >
> > I wonder why the ordering may be important?
>
> I do not think it causes any race condition (so this isn't a big deal),
> but it seems to make more sense to emit an ONLINE/OFFLINE event after
> its object is marked online/offline.
Well, dev->offline only matters for device_offline() and device_online()
themselves at this time.
Thanks,
Rafael
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
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/