public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Muthu Kumar <muthu.lkml@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	martin.petersen@oracle.com
Subject: Re: [PATCH] Fix setting bio flags in drivers (sd_dif/floppy).
Date: Thu, 01 Mar 2012 23:03:40 +0100	[thread overview]
Message-ID: <4F4FF23C.8080201@kernel.dk> (raw)
In-Reply-To: <CAFR8uecR0+dYeY47ztGvg02uCPXv8TTi_cbaBqc+Cq-v=NMe4Q@mail.gmail.com>

On 03/01/2012 10:20 PM, Muthu Kumar wrote:
> On Thu, Mar 1, 2012 at 12:25 PM, Jens Axboe <axboe@kernel.dk> wrote:
>> On 2012-03-01 21:23, Muthu Kumar wrote:
>>>>>                       kunmap_atomic(sdt, KM_USER0);
>>>>>               }
>>>>>
>>>>> -             bio->bi_flags |= BIO_MAPPED_INTEGRITY;
>>>>> +             bio->bi_flags |= (1 << BIO_MAPPED_INTEGRITY);
>>>>>       }
>>>>>
>>>>>       return 0;
>>>>
>>>> urgh.  This isn't the first time.
>>>>
>>>> It's too easy for people to make this mistake.  I'm not sure what a
>>>> good fix would be - I don't think sparse can save us with __bitwise or
>>>> similar.
>>>>
>>>> The approach we took in buffer_head.h with BH_Foo and BUFFER_FNS
>>>> accessors worked pretty well.
>>>>
>>>
>>> Does this look good? BTW, I used the non-atomic variants __set/__clear
>>> to match the behavior of current usage.
>>> If this looks good, I can send the proper patch as attachment (so no
>>> line wraps :)
>>
>> Lets not wrap this in macros, it just makes the code harder to read.
>> Making the BIO_ flags a bit shift value was a mistake in hindsight, too
>> easy to get wrong.
>>
>> If we're going to be changing everything anyway, it'd be better to have
>> __ variants if we really need the bit shifts, and the non __ variants be
>> the value. Similar to what is done for request flags.
>>
>> --
>> Jens Axboe
>>
> 
> 
> You mean, like this? (sparing the gmail line wrap)
> 
> diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> index 4053cbd..035e1ef 100644
> --- a/include/linux/blk_types.h
> +++ b/include/linux/blk_types.h
> @@ -83,19 +83,35 @@ struct bio {
>  /*
>   * bio flags
>   */
> -#define BIO_UPTODATE   0       /* ok after I/O completion */
> -#define BIO_RW_BLOCK   1       /* RW_AHEAD set, and read/write would block */
> -#define BIO_EOF                2       /* out-out-bounds error */
> -#define BIO_SEG_VALID  3       /* bi_phys_segments valid */
> -#define BIO_CLONED     4       /* doesn't own data */
> -#define BIO_BOUNCED    5       /* bio is a bounce bio */
> -#define BIO_USER_MAPPED 6      /* contains user pages */
> -#define BIO_EOPNOTSUPP 7       /* not supported */
> -#define BIO_NULL_MAPPED 8      /* contains invalid user pages */
> -#define BIO_FS_INTEGRITY 9     /* fs owns integrity data, not block layer */
> -#define BIO_QUIET      10      /* Make BIO Quiet */
> -#define BIO_MAPPED_INTEGRITY 11/* integrity metadata has been remapped */
> -#define bio_flagged(bio, flag) ((bio)->bi_flags & (1 << (flag)))
> +enum bio_flag_bits {
> +    __BIO_UPTODATE,             /* ok after I/O completion */
> +    __BIO_RW_BLOCK,             /* RW_AHEAD set, and read/write would block */
> +    __BIO_EOF,                  /* out-out-bounds error */
> +    __BIO_SEG_VALID,            /* bi_phys_segments valid */
> +    __BIO_CLONED,               /* doesn't own data */
> +    __BIO_BOUNCED,              /* bio is a bounce bio */
> +    __BIO_USER_MAPPED,          /* contains user pages */
> +    __BIO_EOPNOTSUPP,           /* not supported */
> +    __BIO_NULL_MAPPED,          /* contains invalid user pages */
> +    __BIO_FS_INTEGRITY,         /* fs owns integrity data, not block layer */
> +    __BIO_QUIET,                /* Make BIO Quiet */
> +    __BIO_MAPPED_INTEGRITY,     /* integrity metadata has been remapped */
> +};
> +
> +#define BIO_UPTODATE            (1 << __BIO_UPTODATE)
> +#define BIO_RW_BLOCK            (1 << __BIO_RW_BLOCK)
> +#define BIO_EOF                 (1 << __BIO_EOF)
> +#define BIO_SEG_VALID           (1 << __BIO_SEG_VALID)
> +#define BIO_CLONED              (1 << __BIO_CLONED)
> +#define BIO_BOUNCED             (1 << __BIO_BOUNCED)
> +#define BIO_USER_MAPPED         (1 << __BIO_USER_MAPPED)
> +#define BIO_EOPNOTSUPP          (1 << __BIO_EOPNOTSUPP)
> +#define BIO_NULL_MAPPED         (1 << __BIO_NULL_MAPPED)
> +#define BIO_FS_INTEGRITY        (1 << __BIO_FS_INTEGRITY)
> +#define BIO_QUIET               (1 << __BIO_QUIET)
> +#define BIO_MAPPED_INTEGRITY    (1 << __BIO_MAPPED_INTEGRITY)
> +
> +#define bio_flagged(bio, flag) ((bio)->bi_flags & (flag))
> 
>  /*
>   * top 4 bits of bio flags indicate the pool this bio came from

Yes, exactly. Only problem is that it would be a big patch, and old code
would still compile. We'd probably need to make all those a bit
different, ala

+#define BIO_F_UPTODATE         (1 << __BIO_UPTODATE)

to be completely safe and catch any use case.

-- 
Jens Axboe


  reply	other threads:[~2012-03-01 22:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29 23:22 [PATCH] Fix setting bio flags in drivers (sd_dif/floppy) Muthu Kumar
2012-03-01  0:08 ` Linus Torvalds
2012-03-01  0:20   ` Andrew Morton
2012-03-01  8:23   ` Jens Axboe
2012-03-01  0:12 ` Andrew Morton
2012-03-01  0:22   ` Martin K. Petersen
2012-03-01 20:23   ` Muthu Kumar
2012-03-01 20:25     ` Jens Axboe
2012-03-01 21:20       ` Muthu Kumar
2012-03-01 22:03         ` Jens Axboe [this message]
2012-03-01 23:27           ` Muthu Kumar

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=4F4FF23C.8080201@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=muthu.lkml@gmail.com \
    --cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox