From: Andreas Rohner <andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
To: Vyacheslav Dubeyko <slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/6] nilfs2: add helper function to go through all entries of meta data file
Date: Mon, 17 Mar 2014 10:24:25 +0100 [thread overview]
Message-ID: <5326BF49.7030703@gmx.net> (raw)
In-Reply-To: <1395039080.2205.11.camel@slavad-CELSIUS-H720>
On 2014-03-17 07:51, Vyacheslav Dubeyko wrote:
> On Sun, 2014-03-16 at 11:47 +0100, Andreas Rohner wrote:
>> This patch introduces the nilfs_palloc_scan_entries() function,
>> which takes an inode of one of nilfs' meta data files and iterates
>> through all of its entries. For each entry the callback function
>> pointer that is given as a parameter is called. The data parameter
>> is passed to the callback function, so that it may receive
>> parameters and return results.
>>
>> Signed-off-by: Andreas Rohner <andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
>> ---
>> fs/nilfs2/alloc.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> fs/nilfs2/alloc.h | 6 +++
>> 2 files changed, 127 insertions(+)
>>
>> diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c
>> index 741fd02..0edd85a 100644
>> --- a/fs/nilfs2/alloc.c
>> +++ b/fs/nilfs2/alloc.c
>> @@ -545,6 +545,127 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inode,
>> }
>>
>> /**
>> + * nilfs_palloc_scan_entries - scan through every entry and execute dofunc
>> + * @inode: inode of metadata file using this allocator
>> + * @dofunc: function executed for every entry
>> + * @data: data pointer passed to dofunc
>> + *
>> + * Description: nilfs_palloc_scan_entries() walks through every allocated entry
>> + * of a metadata file and executes dofunc on it. It passes a data pointer to
>> + * dofunc, which can be used as an input parameter or for returning of results.
>> + *
>> + * Return Value: On success, 0 is returned. On error, a
>> + * negative error code is returned.
>> + */
>> +int nilfs_palloc_scan_entries(struct inode *inode,
>> + void (*dofunc)(struct inode *,
>> + struct nilfs_palloc_req *,
>> + void *),
>> + void *data)
>> +{
>> + struct buffer_head *desc_bh, *bitmap_bh;
>> + struct nilfs_palloc_group_desc *desc;
>> + struct nilfs_palloc_req req;
>> + unsigned char *bitmap;
>> + void *desc_kaddr, *bitmap_kaddr;
>> + unsigned long group, maxgroup, ngroups;
>> + unsigned long n, m, entries_per_group, groups_per_desc_block;
>> + unsigned long i, j, pos;
>> + unsigned long blkoff, prev_blkoff;
>> + int ret;
>> +
>
> I think that it really makes sense to split this function's code between
> several small functions. It improves code style and readability of
> function. Moreover, it makes function more easy understandable.
Ok I could move one of the inner for-loops into a separate function.
>> + ngroups = nilfs_palloc_groups_count(inode);
>> + maxgroup = ngroups - 1;
>> + entries_per_group = nilfs_palloc_entries_per_group(inode);
>> + groups_per_desc_block = nilfs_palloc_groups_per_desc_block(inode);
>> +
>> + for (group = 0; group < ngroups;) {
>> + ret = nilfs_palloc_get_desc_block(inode, group, 0, &desc_bh);
>> + if (ret == -ENOENT)
>
> I suggest to add comment here.
Ok.
-ENOENT basically means, that the description block is not allocated
yet, which is not an error. ngroups is a very big constant value and
does not contain the actual number of groups, but rather the maximum
number of groups. So the only way to tell if it is the last group is by
-ENOENT error.
>> + return 0;
>> + else if (ret < 0)
>> + return ret;
>> + req.pr_desc_bh = desc_bh;
>> + desc_kaddr = kmap(desc_bh->b_page);
>> + desc = nilfs_palloc_block_get_group_desc(inode, group,
>> + desc_bh, desc_kaddr);
>> + n = nilfs_palloc_rest_groups_in_desc_block(inode, group,
>> + maxgroup);
>> +
>> + for (i = 0; i < n; i++, desc++, group++) {
>> + m = entries_per_group -
>> + nilfs_palloc_group_desc_nfrees(inode,
>> + group, desc);
>
> Looks weird. It makes sense to split on several functions or to use
> variable.
>
>> + if (!m)
>> + continue;
>> +
>> + ret = nilfs_palloc_get_bitmap_block(
>> + inode, group, 0, &bitmap_bh);
>
> Ditto. Looks weird.
>
>> + if (ret == -ENOENT) {
>> + ret = 0;
>> + goto out_desc;
>
> It needs to add comment here. Otherwise, it looks weird because anyway
> we go to out_desc. Maybe to combine:
>
> if (unlikely(ret < 0)) {
> if (ret == -ENOENT)
> ret = 0;
> goto out_desc;
> }
>
> Anyway, it needs to comment why we assign zero for the case of -ENOENT.
Hmm in this case -ENOENT should be considered an error. If m > 0 then
nilfs_palloc_get_bitmap_block() should not return -ENOENT.
>> + } else if (ret < 0)
>> + goto out_desc;
>> +
>> + req.pr_bitmap_bh = bitmap_bh;
>> + bitmap_kaddr = kmap(bitmap_bh->b_page);
>> + bitmap = bitmap_kaddr + bh_offset(bitmap_bh);
>> + /* entry blkoff is always bigger than 0 */
>> + blkoff = 0;
>> + pos = 0;
>> +
>> + for (j = 0; j < m; ++j, ++pos) {
>> + pos = nilfs_find_next_bit(bitmap,
>> + entries_per_group, pos);
>> +
>> + if (pos >= entries_per_group)
>> + break;
>> +
>> + /* found an entry */
>> + req.pr_entry_nr =
>> + entries_per_group * group + pos;
>> +
>> + prev_blkoff = blkoff;
>> + blkoff = nilfs_palloc_entry_blkoff(inode,
>> + req.pr_entry_nr);
>> +
>> + if (blkoff != prev_blkoff) {
>> + if (prev_blkoff)
>> + brelse(req.pr_entry_bh);
>> +
>> + ret = nilfs_palloc_get_entry_block(
>> + inode, req.pr_entry_nr,
>> + 0, &req.pr_entry_bh);
>
> Ahhhh. Look weird. :) Split on small functions with clear names, anyway.
> It really improves the code from any point of view.
Ok.
> Thanks,
> Vyacheslav Dubeyko.
>
>> + if (ret < 0)
>> + goto out_entry;
>> + }
>> +
>> + dofunc(inode, &req, data);
>> + }
>> +
>> + if (blkoff)
>> + brelse(req.pr_entry_bh);
>> + kunmap(bitmap_bh->b_page);
>> + brelse(bitmap_bh);
>> + }
>> +
>> + kunmap(desc_bh->b_page);
>> + brelse(desc_bh);
>> + }
>> +
>> + return 0;
>> +
>> +out_entry:
>> + kunmap(bitmap_bh->b_page);
>> + brelse(bitmap_bh);
>> +
>> +out_desc:
>> + kunmap(desc_bh->b_page);
>> + brelse(desc_bh);
>> + return ret;
>> +}
>> +
>> +/**
>> * nilfs_palloc_commit_alloc_entry - finish allocation of a persistent object
>> * @inode: inode of metadata file using this allocator
>> * @req: nilfs_palloc_req structure exchanged for the allocation
>> diff --git a/fs/nilfs2/alloc.h b/fs/nilfs2/alloc.h
>> index 4bd6451..0592035 100644
>> --- a/fs/nilfs2/alloc.h
>> +++ b/fs/nilfs2/alloc.h
>> @@ -77,6 +77,7 @@ int nilfs_palloc_freev(struct inode *, __u64 *, size_t);
>> #define nilfs_set_bit_atomic ext2_set_bit_atomic
>> #define nilfs_clear_bit_atomic ext2_clear_bit_atomic
>> #define nilfs_find_next_zero_bit find_next_zero_bit_le
>> +#define nilfs_find_next_bit find_next_bit_le
>>
>> /**
>> * struct nilfs_bh_assoc - block offset and buffer head association
>> @@ -106,5 +107,10 @@ void nilfs_palloc_setup_cache(struct inode *inode,
>> struct nilfs_palloc_cache *cache);
>> void nilfs_palloc_clear_cache(struct inode *inode);
>> void nilfs_palloc_destroy_cache(struct inode *inode);
>> +int nilfs_palloc_scan_entries(struct inode *,
>> + void (*dofunc)(struct inode *,
>> + struct nilfs_palloc_req *,
>> + void *),
>> + void *);
>>
>> #endif /* _NILFS_ALLOC_H */
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-03-17 9:24 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-16 10:47 [PATCH 0/6] nilfs2: implement tracking of live blocks Andreas Rohner
[not found] ` <cover.1394966728.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-16 10:47 ` [PATCH 1/6] nilfs2: add helper function to go through all entries of meta data file Andreas Rohner
[not found] ` <2adbf1034ab4b129223553746577f6ec0e699869.1394966729.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-17 6:51 ` Vyacheslav Dubeyko
2014-03-17 9:24 ` Andreas Rohner [this message]
2014-03-16 10:47 ` [PATCH 2/6] nilfs2: add new timestamp to seg usage and function to change su_nblocks Andreas Rohner
[not found] ` <12561ce5e2cf8ae07fdda05e16c357f37d17c62f.1394966729.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-16 13:00 ` Vyacheslav Dubeyko
[not found] ` <2FD47FE0-3468-4EF4-AAAE-4A636C640C44-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-03-16 12:24 ` Andreas Rohner
[not found] ` <53259801.5080409-hi6Y0CQ0nG0@public.gmane.org>
2014-03-16 13:34 ` Vyacheslav Dubeyko
[not found] ` <0ED0D5DA-9AE9-44B8-8936-1680DE2B64C5-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-03-16 16:02 ` Andreas Rohner
2014-03-16 14:06 ` Vyacheslav Dubeyko
[not found] ` <ED41900C-6380-44C1-AC7E-EB8DF74EBFBD-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-03-16 13:31 ` Ryusuke Konishi
[not found] ` <20140316.223111.52181167.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-03-16 16:19 ` Andreas Rohner
2014-03-16 10:47 ` [PATCH 3/6] nilfs2: scan dat entries at snapshot creation/deletion time Andreas Rohner
[not found] ` <29dee92595249b713fff1e4903d5d76556926eec.1394966729.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-17 7:04 ` Vyacheslav Dubeyko
2014-03-17 9:35 ` Andreas Rohner
[not found] ` <5326C1E5.10108-hi6Y0CQ0nG0@public.gmane.org>
2014-03-17 9:54 ` Vyacheslav Dubeyko
2014-03-16 10:47 ` [PATCH 4/6] nilfs2: add ioctl() to clean snapshot flags from dat entries Andreas Rohner
[not found] ` <be7d3bd13015117222aac43194c0fdb9c5d0046f.1394966729.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-17 13:19 ` Vyacheslav Dubeyko
2014-03-17 13:49 ` Andreas Rohner
[not found] ` <5326FD51.7000209-hi6Y0CQ0nG0@public.gmane.org>
2014-03-18 7:10 ` Vyacheslav Dubeyko
2014-03-18 8:38 ` Andreas Rohner
2014-03-16 10:47 ` [PATCH 5/6] nilfs2: add counting of live blocks for blocks that are overwritten Andreas Rohner
[not found] ` <25dd8a8bb6943ffa3e0663848363135585a48109.1394966729.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-18 11:50 ` Vyacheslav Dubeyko
2014-03-18 14:02 ` Andreas Rohner
2014-03-16 10:47 ` [PATCH 6/6] nilfs2: add counting of live blocks for deleted files Andreas Rohner
2014-03-16 10:49 ` [PATCH 1/4] nilfs-utils: remove reliance on sui_nblocks to read segment Andreas Rohner
[not found] ` <36b7f57861b69c7fdb9d9e54a21df6f5c7f21061.1394966935.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-16 10:49 ` [PATCH 2/4] nilfs-utils: add cost-benefit and greedy policies Andreas Rohner
[not found] ` <cc43be2e6bba5367fd2982dc0df5255b884bdace.1394966935.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-03-16 12:55 ` Ryusuke Konishi
[not found] ` <20140316.215545.291456562.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-03-16 15:50 ` Andreas Rohner
2014-03-16 10:49 ` [PATCH 3/4] nilfs-utils: add support for nilfs_clean_snapshot_flags() Andreas Rohner
2014-03-16 10:49 ` [PATCH 4/4] nilfs-utils: add extra flags to nilfs_vdesc and update sui_nblocks Andreas Rohner
2014-03-16 11:01 ` [PATCH 0/6] nilfs2: implement tracking of live blocks Andreas Rohner
[not found] ` <532584A2.8000004-hi6Y0CQ0nG0@public.gmane.org>
2014-03-16 12:34 ` Vyacheslav Dubeyko
[not found] ` <3EC9549C-84A7-49B5-9BE1-34A7337BFFDC-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-03-16 11:36 ` Andreas Rohner
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=5326BF49.7030703@gmx.net \
--to=andreas.rohner-hi6y0cq0ng0@public.gmane.org \
--cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.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.