From: Kimberly Brown <kimbrow...@gmail.com>  Sent: Friday, March 1, 2019 11:18 
AM
> 
> +/*
> + * Channel-level attribute_group callback function. Returns the permission 
> for
> + * each attribute, and returns 0 if an attribute is not visible.
> + */
> +static umode_t vmbus_chan_attr_is_visible(struct kobject *kobj,
> +                                       struct attribute *attr, int idx)
> +{
> +     const struct vmbus_channel *channel =
> +             container_of(kobj, struct vmbus_channel, kobj);
> +
> +     /* Hide the monitor attributes if the monitor mechanism is not used. */
> +     if (!channel->offermsg.monitor_allocated &&
> +         (attr == &chan_attr_pending.attr ||
> +          attr == &chan_attr_latency.attr ||
> +          attr == &chan_attr_monitor_id.attr))
> +             return 0;
> +
> +     return attr->mode;
> +}
> +
> +static struct attribute_group vmbus_chan_group = {
> +     .attrs = vmbus_chan_attrs,
> +     .is_visible = vmbus_chan_attr_is_visible
> +};
> +
>  static struct kobj_type vmbus_chan_ktype = {
>       .sysfs_ops = &vmbus_chan_sysfs_ops,
>       .release = vmbus_chan_release,
> -     .default_attrs = vmbus_chan_attrs,

Just to double-check my understanding, removing the default_attrs
here means that in vmbus_add_channel_kobj(), the call to
kobject_init_and_add() will only create the sub-directory that is the
channel number.  The sub-directory will be empty.  Then the new
call to sysfs_create_group() that you added below will populate
the subdirectory, as filtered by vmbus_chan_attr_is_visible().

>  };
> 
>  /*
> @@ -1571,6 +1624,12 @@ int vmbus_add_channel_kobj(struct hv_device *dev, 
> struct
> vmbus_channel *channel)
>       if (ret)
>               return ret;
> 
> +     ret = sysfs_create_group(kobj, &vmbus_chan_group);
> +     if (ret) {
> +             pr_err("Unable to set up channel sysfs files\n");
> +             return ret;

In this error case, the previously created sub-directory that is the
channel number needs to be deleted/cleaned up.

> +     }
> +

Michael

Reply via email to