All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@dreamhost.com>
To: Yehuda Sadeh Weinraub <yehudasa@gmail.com>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [PATCH 4/4] rbd: use a single value of snap_name to mean no snap
Date: Tue, 28 Feb 2012 21:35:13 -0800	[thread overview]
Message-ID: <4F4DB911.9060506@dreamhost.com> (raw)
In-Reply-To: <CAC-hyiGGAnKM92YyfUsbW17pW4a2_E0gO5Z_x5B+fNqZjDWtgA@mail.gmail.com>

On 02/28/2012 08:53 PM, Yehuda Sadeh Weinraub wrote:
> On Tue, Feb 28, 2012 at 7:35 PM, Alex Elder<elder@dreamhost.com>  wrote:
>>  From Josh Durgin<josh.durgin@dreamhost.com>
>>
>> There's already a constant for this anyway.
>>
>> (I changed Josh's code to use memcmp() and memcpy() instead. -Alex)
>>
>> Signed-off-by: Alex Elder<elder@dreamhost.com>
>> ---
>>   drivers/block/rbd.c |    8 +++-----
>>   1 files changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
>> index 3d0f8cf..25ed3c0 100644
>> --- a/drivers/block/rbd.c
>> +++ b/drivers/block/rbd.c
>> @@ -563,10 +563,7 @@ static int rbd_header_set_snap(struct rbd_device *dev,
>>
>>         down_write(&header->snap_rwsem);
>>
>> -       if (!snap_name ||
>> -           !*snap_name ||
>> -           strcmp(snap_name, "-") == 0 ||
>> -           strcmp(snap_name, RBD_SNAP_HEAD_NAME) == 0) {
>> +       if (!memcmp(snap_name, RBD_SNAP_HEAD_NAME, sizeof
>
> The original code checked for snap_name, we don't do it here. Also, do
> we know that snap_name is pointing to at least
> sizeof(RBD_SNAP_HEAD_NAME)? if not (or in any case) we should use
> strcmp instead of memcmp. Also, sizeof(x) instead of sizeof x.

This function is only called in one place, within this file.
That place passes rbd_dev->snap_name as the "snap_name" argument.
rbd_dev->snap_name is an array.  So if rbd_dev is a valid structure,
rbd_dev->snap_name will not be a null pointer.

The size of that string is RBD_MAX_SNAP_NAME_LEN.  It would be
an error for sizeof(RBD_SNAP_HEAD_NAME) to exceed that length,
but I could add a check for that.  (Checking at build time would
be best but sizeof() is not available then.)

I'll put in a BUG_ON() or something, or will see if I can put in
some other kind of check.

					-Alex

>
>> RBD_SNAP_HEAD_NAME)) {
>>                 if (header->total_snaps)
>>                         snapc->seq = header->snap_seq;
>>                 else
>> @@ -2213,7 +2210,8 @@ static ssize_t rbd_add(struct bus_type *bus,
>>         }
>>
>>         if (rbd_dev->snap_name[0] == 0)
>> -               rbd_dev->snap_name[0] = '-';
>> +               memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME,
>> +                       sizeof RBD_SNAP_HEAD_NAME);
>>
>>         rbd_dev->obj_len = strlen(rbd_dev->obj);
>>         snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",
>> --
>> 1.7.5.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html


  reply	other threads:[~2012-02-29  5:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  3:31 [PATCH 0/4] rbd: miscellaneous cleanups Alex Elder
2012-02-29  3:35 ` [PATCH 1/4] rbd: a few small cleanups Alex Elder
2012-03-02 19:44   ` Sage Weil
2012-03-02 23:22     ` Alex Elder
2012-02-29  3:35 ` [PATCH 2/4] rbd: make ceph_parse_options() return a pointer Alex Elder
2012-02-29  3:35 ` [PATCH 3/4] rbd: do not duplicate ceph_client pointer in rbd_device Alex Elder
2012-02-29  3:35 ` [PATCH 4/4] rbd: use a single value of snap_name to mean no snap Alex Elder
2012-02-29  4:53   ` Yehuda Sadeh Weinraub
2012-02-29  5:35     ` Alex Elder [this message]
2012-03-02 19:46 ` [PATCH 0/4] rbd: miscellaneous cleanups Sage Weil

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=4F4DB911.9060506@dreamhost.com \
    --to=elder@dreamhost.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=yehudasa@gmail.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.