From: Donald Hunter <donald.hunter@gmail.com>
To: David Vernet <void@manifault.com>
Cc: bpf@vger.kernel.org, linux-doc@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, Yonghong Song <yhs@meta.com>
Subject: Re: [PATCH bpf-next v3] docs/bpf: Add documentation for BPF_MAP_TYPE_SK_STORAGE
Date: Thu, 08 Dec 2022 16:35:14 +0000 [thread overview]
Message-ID: <m2wn71yhtp.fsf@gmail.com> (raw)
In-Reply-To: <m2r0xagkwp.fsf@gmail.com> (Donald Hunter's message of "Thu, 08 Dec 2022 12:05:58 +0000")
Donald Hunter <donald.hunter@gmail.com> writes:
> David Vernet <void@manifault.com> writes:
>
>> On Wed, Dec 07, 2022 at 10:27:21AM +0000, Donald Hunter wrote:
>>> +
>>> +This snippet shows how to retrieve socket-local storage in a BPF program:
>>> +
>>> +.. code-block:: c
>>> +
>>> + SEC("sockops")
>>> + int _sockops(struct bpf_sock_ops *ctx)
>>> + {
>>> + struct my_storage *storage;
>>> + struct bpf_sock *sk;
>>> +
>>> + sk = ctx->sk;
>>> + if (!sk)
>>> + return 1;
>>
>> Don't feel strongly about this one, but IMO it's nice for examples to
>> illustrate code that's as close to real and pristine as possible. To
>> that point, should this example perhaps be updated to return -ENOENT
>> here, and -ENOMEM below?
>
> Will do.
>
After digging into this a bit more I notice that the sockops programs in
tools/testing/selftests/bpf/progs mostly return 1 in all cases.
I'm assuming that sockops programs should return valid values for
some op types such as BPF_SOCK_OPS_TIMEOUT_INIT. Other than that I can't
find a definitive list. Do you know if valid return values are
enumerated anywhere, or do I need to dig some more?
>>> +
>>> + storage = bpf_sk_storage_get(&socket_storage, sk, 0,
>>> + BPF_LOCAL_STORAGE_GET_F_CREATE);
>>> + if (!storage)
>>> + return 1;
>>> +
>>> + /* Use 'storage' here */
>>
>> Let's return 0 at the end to make the example program technically
>> correct.
>
> Will do.
>
>>> + }
>>
>> Thanks,
>> David
next prev parent reply other threads:[~2022-12-08 16:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 10:27 [PATCH bpf-next v3] docs/bpf: Add documentation for BPF_MAP_TYPE_SK_STORAGE Donald Hunter
2022-12-07 16:41 ` Yonghong Song
2022-12-07 21:13 ` David Vernet
2022-12-08 12:05 ` Donald Hunter
2022-12-08 16:35 ` Donald Hunter [this message]
2022-12-08 17:19 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2wn71yhtp.fsf@gmail.com \
--to=donald.hunter@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=linux-doc@vger.kernel.org \
--cc=void@manifault.com \
--cc=yhs@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.