Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1511121 > unrolled thread
| Started by | Richard Weinberger <richard.weinberger@gmail.com> |
|---|---|
| First post | 2016-10-28 15:10 +0200 |
| Last post | 2016-10-28 16:00 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [RFC v1 08/14] bus1: implement peer management context Richard Weinberger <richard.weinberger@gmail.com> - 2016-10-28 15:10 +0200
Re: [RFC v1 08/14] bus1: implement peer management context Tom Gundersen <teg@jklm.no> - 2016-10-28 15:30 +0200
Re: [RFC v1 08/14] bus1: implement peer management context Richard Weinberger <richard@nod.at> - 2016-10-28 16:00 +0200
| From | Richard Weinberger <richard.weinberger@gmail.com> |
|---|---|
| Date | 2016-10-28 15:10 +0200 |
| Subject | Re: [RFC v1 08/14] bus1: implement peer management context |
| Message-ID | <sxf4Z-hO-7@gated-at.bofh.it> |
On Wed, Oct 26, 2016 at 9:18 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
> + /* initialize constant fields */
> + peer->id = atomic64_inc_return(&peer_ids);
> + peer->flags = 0;
> + peer->cred = get_cred(current_cred());
> + peer->pid_ns = get_pid_ns(task_active_pid_ns(current));
> + peer->user = user;
> + peer->debugdir = NULL;
> + init_waitqueue_head(&peer->waitq);
> + bus1_active_init(&peer->active);
> +
> + /* initialize data section */
> + mutex_init(&peer->data.lock);
> +
> + /* initialize peer-private section */
> + mutex_init(&peer->local.lock);
> +
> + if (!IS_ERR_OR_NULL(bus1_debugdir)) {
How can bus1_debugdir contain an error code? AFACT it is either a
valid dentry or NULL.
> + char idstr[22];
> +
> + snprintf(idstr, sizeof(idstr), "peer-%llx", peer->id);
> +
> + peer->debugdir = debugfs_create_dir(idstr, bus1_debugdir);
> + if (!peer->debugdir) {
> + pr_err("cannot create debugfs dir for peer %llx\n",
> + peer->id);
> + } else if (!IS_ERR_OR_NULL(peer->debugdir)) {
> + bus1_debugfs_create_atomic_x("active", S_IRUGO,
> + peer->debugdir,
> + &peer->active.count);
> + }
> + }
> +
> + bus1_active_activate(&peer->active);
This is a no-nop since bus1_active_init() set ->count to BUS1_ACTIVE_NEW.
> + return peer;
> +}
> +
> +static int bus1_peer_disconnect(struct bus1_peer *peer)
> +{
> + bus1_active_deactivate(&peer->active);
> + bus1_active_drain(&peer->active, &peer->waitq);
> +
> + if (!bus1_active_cleanup(&peer->active, &peer->waitq,
> + NULL, NULL))
> + return -ESHUTDOWN;
> +
> + return 0;
> +}
> +
> +/**
> + * bus1_peer_free() - destroy peer
> + * @peer: peer to destroy, or NULL
> + *
> + * Destroy a peer object that was previously allocated via bus1_peer_new().
> + * This synchronously waits for any outstanding operations on this peer to
> + * finish, then releases all linked resources and deallocates the peer in an
> + * rcu-delayed manner.
> + *
> + * If NULL is passed, this is a no-op.
> + *
> + * Return: NULL is returned.
What about making the function of type void?
> +struct bus1_peer *bus1_peer_free(struct bus1_peer *peer)
> +{
> + if (!peer)
> + return NULL;
> +
> + /* disconnect from environment */
> + bus1_peer_disconnect(peer);
> +
> + /* deinitialize peer-private section */
> + mutex_destroy(&peer->local.lock);
> +
> + /* deinitialize data section */
> + mutex_destroy(&peer->data.lock);
> +
> + /* deinitialize constant fields */
> + debugfs_remove_recursive(peer->debugdir);
> + bus1_active_deinit(&peer->active);
> + peer->user = bus1_user_unref(peer->user);
> + put_pid_ns(peer->pid_ns);
> + put_cred(peer->cred);
> + kfree_rcu(peer, rcu);
> +
> + return NULL;
> +}
--
Thanks,
//richard
[toc] | [next] | [standalone]
| From | Tom Gundersen <teg@jklm.no> |
|---|---|
| Date | 2016-10-28 15:30 +0200 |
| Message-ID | <sxfol-oo-15@gated-at.bofh.it> |
| In reply to | #1511121 |
On Fri, Oct 28, 2016 at 3:05 PM, Richard Weinberger
<richard.weinberger@gmail.com> wrote:
> On Wed, Oct 26, 2016 at 9:18 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
>> + /* initialize constant fields */
>> + peer->id = atomic64_inc_return(&peer_ids);
>> + peer->flags = 0;
>> + peer->cred = get_cred(current_cred());
>> + peer->pid_ns = get_pid_ns(task_active_pid_ns(current));
>> + peer->user = user;
>> + peer->debugdir = NULL;
>> + init_waitqueue_head(&peer->waitq);
>> + bus1_active_init(&peer->active);
>> +
>> + /* initialize data section */
>> + mutex_init(&peer->data.lock);
>> +
>> + /* initialize peer-private section */
>> + mutex_init(&peer->local.lock);
>> +
>> + if (!IS_ERR_OR_NULL(bus1_debugdir)) {
>
> How can bus1_debugdir contain an error code? AFACT it is either a
> valid dentry or NULL.
If debugfs is not enabled it will be ERR_PTR(-ENODEV).
>> + char idstr[22];
>> +
>> + snprintf(idstr, sizeof(idstr), "peer-%llx", peer->id);
>> +
>> + peer->debugdir = debugfs_create_dir(idstr, bus1_debugdir);
>> + if (!peer->debugdir) {
>> + pr_err("cannot create debugfs dir for peer %llx\n",
>> + peer->id);
>> + } else if (!IS_ERR_OR_NULL(peer->debugdir)) {
>> + bus1_debugfs_create_atomic_x("active", S_IRUGO,
>> + peer->debugdir,
>> + &peer->active.count);
>> + }
>> + }
>> +
>> + bus1_active_activate(&peer->active);
>
> This is a no-nop since bus1_active_init() set ->count to BUS1_ACTIVE_NEW.
bus1_active_activate() changes count from BUS1_ACTIVE_NEW to 0.
>> + return peer;
>> +}
>> +
>> +static int bus1_peer_disconnect(struct bus1_peer *peer)
>> +{
>> + bus1_active_deactivate(&peer->active);
>> + bus1_active_drain(&peer->active, &peer->waitq);
>> +
>> + if (!bus1_active_cleanup(&peer->active, &peer->waitq,
>> + NULL, NULL))
>> + return -ESHUTDOWN;
>> +
>> + return 0;
>> +}
>> +
>> +/**
>> + * bus1_peer_free() - destroy peer
>> + * @peer: peer to destroy, or NULL
>> + *
>> + * Destroy a peer object that was previously allocated via bus1_peer_new().
>> + * This synchronously waits for any outstanding operations on this peer to
>> + * finish, then releases all linked resources and deallocates the peer in an
>> + * rcu-delayed manner.
>> + *
>> + * If NULL is passed, this is a no-op.
>> + *
>> + * Return: NULL is returned.
>
> What about making the function of type void?
We are consistently returning the type being freed so we can do
foo->bar = bar_free(bar);
Just a matter of style though.
>> +struct bus1_peer *bus1_peer_free(struct bus1_peer *peer)
>> +{
>> + if (!peer)
>> + return NULL;
>> +
>> + /* disconnect from environment */
>> + bus1_peer_disconnect(peer);
>> +
>> + /* deinitialize peer-private section */
>> + mutex_destroy(&peer->local.lock);
>> +
>> + /* deinitialize data section */
>> + mutex_destroy(&peer->data.lock);
>> +
>> + /* deinitialize constant fields */
>> + debugfs_remove_recursive(peer->debugdir);
>> + bus1_active_deinit(&peer->active);
>> + peer->user = bus1_user_unref(peer->user);
>> + put_pid_ns(peer->pid_ns);
>> + put_cred(peer->cred);
>> + kfree_rcu(peer, rcu);
>> +
>> + return NULL;
>> +}
>
> --
> Thanks,
> //richard
[toc] | [prev] | [next] | [standalone]
| From | Richard Weinberger <richard@nod.at> |
|---|---|
| Date | 2016-10-28 16:00 +0200 |
| Message-ID | <sxfRn-Aj-7@gated-at.bofh.it> |
| In reply to | #1511126 |
On 28.10.2016 15:23, Tom Gundersen wrote:
> On Fri, Oct 28, 2016 at 3:05 PM, Richard Weinberger
> <richard.weinberger@gmail.com> wrote:
>> On Wed, Oct 26, 2016 at 9:18 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
>>> + /* initialize constant fields */
>>> + peer->id = atomic64_inc_return(&peer_ids);
>>> + peer->flags = 0;
>>> + peer->cred = get_cred(current_cred());
>>> + peer->pid_ns = get_pid_ns(task_active_pid_ns(current));
>>> + peer->user = user;
>>> + peer->debugdir = NULL;
>>> + init_waitqueue_head(&peer->waitq);
>>> + bus1_active_init(&peer->active);
>>> +
>>> + /* initialize data section */
>>> + mutex_init(&peer->data.lock);
>>> +
>>> + /* initialize peer-private section */
>>> + mutex_init(&peer->local.lock);
>>> +
>>> + if (!IS_ERR_OR_NULL(bus1_debugdir)) {
>>
>> How can bus1_debugdir contain an error code? AFACT it is either a
>> valid dentry or NULL.
>
> If debugfs is not enabled it will be ERR_PTR(-ENODEV).
I thought you handle that earlier. But just figured that you check only
for NULL after doing debugfs_create_dir(). This confused me.
>>> + char idstr[22];
>>> +
>>> + snprintf(idstr, sizeof(idstr), "peer-%llx", peer->id);
>>> +
>>> + peer->debugdir = debugfs_create_dir(idstr, bus1_debugdir);
>>> + if (!peer->debugdir) {
>>> + pr_err("cannot create debugfs dir for peer %llx\n",
>>> + peer->id);
>>> + } else if (!IS_ERR_OR_NULL(peer->debugdir)) {
>>> + bus1_debugfs_create_atomic_x("active", S_IRUGO,
>>> + peer->debugdir,
>>> + &peer->active.count);
>>> + }
>>> + }
>>> +
>>> + bus1_active_activate(&peer->active);
>>
>> This is a no-nop since bus1_active_init() set ->count to BUS1_ACTIVE_NEW.
>
> bus1_active_activate() changes count from BUS1_ACTIVE_NEW to 0.
Too many "active" words. ;)
Now it makes sense. BUS1_ACTIVE_NEW is state "NEW"
and the unnamed state "ready to use" is a counter >= 0.
Thanks,
//richard
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web