All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Eric Blake <eblake@redhat.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH 3/9] nbd: BLOCK_STATUS for standard get_block_status function: server part
Date: Fri, 16 Feb 2018 14:09:13 +0300	[thread overview]
Message-ID: <2b30632c-4028-2726-fd61-81ae3893cfd4@virtuozzo.com> (raw)
In-Reply-To: <ac33f176-0f15-107f-1c64-4fa3bac77520@redhat.com>

16.02.2018 02:02, Eric Blake wrote:
> On 02/15/2018 07:51 AM, Vladimir Sementsov-Ogievskiy wrote:
>> Minimal realization: only one extent in server answer is supported.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>   include/block/nbd.h |  33 ++++++
>>   nbd/common.c        |  10 ++
>>   nbd/server.c        | 310 
>> +++++++++++++++++++++++++++++++++++++++++++++++++++-
>>   3 files changed, 352 insertions(+), 1 deletion(-)
>>
>
>> @@ -200,9 +227,15 @@ enum {
>>   #define NBD_REPLY_TYPE_NONE          0
>>   #define NBD_REPLY_TYPE_OFFSET_DATA   1
>>   #define NBD_REPLY_TYPE_OFFSET_HOLE   2
>> +#define NBD_REPLY_TYPE_BLOCK_STATUS  5
>
> Stale; see nbd.git commit 56c77720 which changed this to 3.

Very unpleasant surprise. I understand that this is still experimental 
extension, but actually we use it =5 in production about one year. Can 
we revert it to 5?

>
>> +++ b/nbd/server.c
>> @@ -82,6 +82,15 @@ struct NBDExport {
>>     static QTAILQ_HEAD(, NBDExport) exports = 
>> QTAILQ_HEAD_INITIALIZER(exports);
>>   +/* NBDExportMetaContexts represents list of selected by
>> + * NBD_OPT_SET_META_CONTEXT contexts to be exported. */
>
> represents a list of contexts to be exported, as selected by 
> NBD_OPT_SET_META_CONTEXT.
>
>> +typedef struct NBDExportMetaContexts {
>> +    char export_name[NBD_MAX_NAME_SIZE + 1];
>
> Would this work as const char * pointing at some other storage, 
> instead of having to copy into this storage?

I'll think about

>
>> +    bool valid; /* means that negotiation of the option finished 
>> without
>> +                   errors */
>> +    bool base_allocation; /* export base:allocation context (block 
>> status) */
>> +} NBDExportMetaContexts;
>> +
>>   struct NBDClient {
>
>> @@ -636,6 +646,201 @@ static QIOChannel 
>> *nbd_negotiate_handle_starttls(NBDClient *client,
>>       return QIO_CHANNEL(tioc);
>>   }
>>   +/* nbd_alloc_read_size_string
>> + *
>> + * Read string in format
>> + *   uint32_t len
>> + *   len bytes string (not 0-terminated)
>> + * String is allocated and pointer returned as @buf
>> + *
>> + * Return -errno on I/O error, 0 if option was completely handled by
>> + * sending a reply about inconsistent lengths, or 1 on success. */
>> +static int nbd_alloc_read_size_string(NBDClient *client, char **buf,
>> +                                      Error **errp)
>> +{
>> +    int ret;
>> +    uint32_t len;
>> +
>> +    ret = nbd_opt_read(client, &len, sizeof(len), errp);
>> +    if (ret <= 0) {
>> +        return ret;
>> +    }
>> +    cpu_to_be32s(&len);
>> +
>> +    *buf = g_try_malloc(len + 1);
>
> I'd rather check that len is sane prior to trying to malloc. 
> Otherwise, a malicious client can convince us to waste time/space 
> doing a large malloc before we finally realize that we can't read that 
> many bytes after all.  And in fact, if you check len in advance, you 
> can probably just use g_malloc() instead of g_try_malloc() 
> (g_try_malloc() makes sense on a 1M allocation, where we can still 
> allocate smaller stuff in reporting the error; but since NBD limits 
> strings to 4k, if we fail at allocating 4k, we are probably already so 
> hosed that our attempts to report the failure will also run out of 
> memory and abort, so why not just abort now).

reasonable, will do

>
>> +    if (*buf == NULL) {
>> +        error_setg(errp, "No memory");
>> +        return -ENOMEM;
>> +    }
>> +    (*buf)[len] = '\0';
>> +
>> +    ret = nbd_opt_read(client, *buf, len, errp);
>> +    if (ret <= 0) {
>> +        g_free(*buf);
>> +        *buf = NULL;
>> +    }
>> +
>> +    return ret;
>> +}
>> +
>> +/* nbd_read_size_string
>
> Will resume review here...
>


-- 
Best regards,
Vladimir

  reply	other threads:[~2018-02-16 11:09 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 13:51 [Qemu-devel] [PATCH 0/9] nbd block status base:allocation Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 1/9] nbd/server: add nbd_opt_invalid helper Vladimir Sementsov-Ogievskiy
2018-02-15 22:01   ` Eric Blake
2018-03-02 12:40     ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 2/9] nbd: change indenting in nbd.h Vladimir Sementsov-Ogievskiy
2018-02-15 22:03   ` Eric Blake
2018-02-15 13:51 ` [Qemu-devel] [PATCH 3/9] nbd: BLOCK_STATUS for standard get_block_status function: server part Vladimir Sementsov-Ogievskiy
2018-02-15 23:02   ` Eric Blake
2018-02-16 11:09     ` Vladimir Sementsov-Ogievskiy [this message]
2018-02-16 11:45       ` Eric Blake
2018-02-16 13:21   ` Eric Blake
2018-02-16 14:43     ` Vladimir Sementsov-Ogievskiy
2018-02-16 17:01       ` Eric Blake
2018-03-01 11:36         ` Vladimir Sementsov-Ogievskiy
2018-03-02 15:07     ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 4/9] block/nbd-client: save first fatal error in nbd_iter_error Vladimir Sementsov-Ogievskiy
2018-02-16 17:35   ` Eric Blake
2018-02-15 13:51 ` [Qemu-devel] [PATCH 5/9] nbd/client: fix error messages in nbd_handle_reply_err Vladimir Sementsov-Ogievskiy
2018-02-16 17:38   ` Eric Blake
2018-03-01 11:38     ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 6/9] nbd: BLOCK_STATUS for standard get_block_status function: client part Vladimir Sementsov-Ogievskiy
2018-02-16 20:40   ` Eric Blake
2018-03-09 18:47     ` Vladimir Sementsov-Ogievskiy
2018-03-12  9:06     ` Vladimir Sementsov-Ogievskiy
2018-03-12  9:23     ` Vladimir Sementsov-Ogievskiy
2018-03-12  9:48     ` Vladimir Sementsov-Ogievskiy
2018-03-12 13:13     ` Vladimir Sementsov-Ogievskiy
2018-03-12 14:00       ` Eric Blake
2018-02-15 13:51 ` [Qemu-devel] [PATCH 7/9] iotests.py: tiny refactor: move system imports up Vladimir Sementsov-Ogievskiy
2018-02-16 20:44   ` Eric Blake
2018-03-09 18:54     ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 8/9] iotests: add file_path helper Vladimir Sementsov-Ogievskiy
2018-02-16 20:46   ` Eric Blake
2018-02-20  5:42     ` Jeff Cody
2018-03-12 10:04       ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 9/9] iotests: new test 206 for NBD BLOCK_STATUS Vladimir Sementsov-Ogievskiy
2018-02-16 21:02   ` Eric Blake
2018-03-01 11:51     ` Vladimir Sementsov-Ogievskiy
2018-03-01 18:23       ` Eric Blake
2018-02-22 19:30 ` [Qemu-devel] [PATCH 0/9] nbd block status base:allocation no-reply
2018-02-23 14:02 ` no-reply
2018-02-24  6:48 ` no-reply
2018-02-26 16:57 ` [Qemu-devel] [PATCH v2 0/2] nbd block status initial patches Eric Blake
2018-02-26 16:57   ` [Qemu-devel] [PATCH v2 1/2] nbd: BLOCK_STATUS constants Eric Blake
2018-03-01 12:06     ` Vladimir Sementsov-Ogievskiy
2018-02-26 16:57   ` [Qemu-devel] [PATCH v2 2/2] nbd/client: fix error messages in nbd_handle_reply_err Eric Blake
2018-03-01 12:10     ` Vladimir Sementsov-Ogievskiy
2018-03-01 18:25       ` Eric Blake
2018-03-09 19:08 ` [Qemu-devel] [PATCH 0/9] nbd block status base:allocation Eric Blake
2018-03-09 19:28   ` Vladimir Sementsov-Ogievskiy

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=2b30632c-4028-2726-fd61-81ae3893cfd4@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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.