All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcin Slusarz <marcin.slusarz@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Subject: Re: [PATCH] fs: add roundup_to_blocksize and bytes_to_blocks helper functions
Date: Sun, 26 Apr 2009 19:21:57 +0200	[thread overview]
Message-ID: <49F49835.8090807@gmail.com> (raw)
In-Reply-To: <20090422141035.efbb1540.akpm@linux-foundation.org>

Andrew Morton pisze:
> On Sun, 19 Apr 2009 20:42:15 +0200
> Marcin Slusarz <marcin.slusarz@gmail.com> wrote:
> 
>> bytes_to_blocks is open coded in more than 30 places
>> roundup_to_blocksize is open coded in more than 15 places
>>
> 
> It would be nice to document these a bit.  Kernel-wide helpers..

ok

>
>> ---
>>  include/linux/fs.h |   12 ++++++++++++
>>  1 files changed, 12 insertions(+), 0 deletions(-)
>>
>> diff --git a/include/linux/fs.h b/include/linux/fs.h
>> index e766be0..1b4e5b6 100644
>> --- a/include/linux/fs.h
>> +++ b/include/linux/fs.h
>> @@ -2451,5 +2451,17 @@ int proc_nr_files(struct ctl_table *table, int write, struct file *filp,
>>  
>>  int get_filesystem_list(char * buf);
>>  
>> +static inline
>> +unsigned long long roundup_to_blocksize(unsigned long long bytes, struct super_block *sb)
>> +{
>> +	return (bytes + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1);
> 
> This is ALIGN(bytes, sb->s_blocksize).  Dunno if that's any clearer though.

thanks, I didn't know about it

>> +}
>> +
>> +static inline
>> +blkcnt_t bytes_to_blocks(unsigned long long bytes, struct super_block *sb)
>> +{
>> +	return (bytes + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
>> +}
> 
> I wonder whether `unsigned long long' was the best choice of type here.
> 
> Probably `bytes' should be loff_t.

loff_t is long long.

So bytes_to_blocks(-6000, sb/*bs=4096, bsb=12*/) would return 4503599627370495

> roundup_to_blocksize() could/should return loff_t too, I think.

And roundup_to_blocksize(-6000, sb/*bs=4096, bsb=12*/) would return -4096

Bit surprising ;)

> roundup_to_blocksize() isn't a terribly good name, IMO.  The name
> conveys no sense of what the function returns.  It _sounds_ like it
> returns a "block size".  But it doesn't - it returns a loff_t. 
> round_up_file_offset_to_block_size() is a bit long though :(

I can't find any better name, sorry.

Marcin


      parent reply	other threads:[~2009-04-26 17:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-19 18:42 [PATCH] fs: add roundup_to_blocksize and bytes_to_blocks helper functions Marcin Slusarz
2009-04-19 18:51 ` [PATCH] filesystems: start using roundup_to_blocksize and bytes_to_blocks Marcin Slusarz
2009-04-20 19:07   ` Dave Kleikamp
2009-04-20 20:22     ` Dave Kleikamp
2009-04-22 21:10 ` [PATCH] fs: add roundup_to_blocksize and bytes_to_blocks helper functions Andrew Morton
2009-04-22 21:40   ` Dave Kleikamp
2009-04-22 21:52     ` Andrew Morton
2009-04-26 17:21   ` Marcin Slusarz [this message]

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=49F49835.8090807@gmail.com \
    --to=marcin.slusarz@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shaggy@linux.vnet.ibm.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.