From: Andreas Rohner <andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
To: Ryusuke Konishi
<konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 2/3] nilfs2: add nilfs_sufile_set_suinfo to update segment usage info
Date: Fri, 24 Jan 2014 13:34:36 +0100 [thread overview]
Message-ID: <52E25DDC.2060502@gmx.net> (raw)
In-Reply-To: <20140124.205623.400541300.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
On 2014-01-24 12:56, Ryusuke Konishi wrote:
> On Tue, 21 Jan 2014 15:00:29 +0100, Andreas Rohner wrote:
>> This patch introduces the nilfs_sufile_set_suinfo function, which
>> expects an array of nilfs_suinfo_update structures and updates the
>> segment usage information accordingly.
>>
>> This is basically a helper function for the newly introduced
>> NILFS_IOCTL_SET_SUINFO ioctl.
>>
>> Signed-off-by: Andreas Rohner <andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
>> ---
>> fs/nilfs2/sufile.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> fs/nilfs2/sufile.h | 2 +-
>> 2 files changed, 92 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
>> index 3127e9f..81c3438 100644
>> --- a/fs/nilfs2/sufile.c
>> +++ b/fs/nilfs2/sufile.c
>> @@ -870,6 +870,97 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, __u64 segnum, void *buf,
>> }
>>
>> /**
>> + * nilfs_sufile_set_suinfo -
>
> Please fill the summary line of function even though
> nilfs_sufile_get_suinfo() function lacks it.
>
> * nilfs_sufile_set_suinfo - update segment usage information
>
>> + * @sufile: inode of segment usage file
>> + * @buf: array of suinfo
>> + * @supsz: byte size of suinfo
>> + * @nsup: size of suinfo array
>> + *
>> + * Description: Takes an array of nilfs_suinfo_update structs and updates
>> + * segment usage accordingly.
>> + *
>> + * Return Value: On success, 0 is returned and .... On error, one of the
>> + * following negative error codes is returned.
>> + *
>> + * %-EIO - I/O error.
>> + *
>> + * %-ENOMEM - Insufficient amount of memory available.
>> + *
>> + * %-EINVAL - Invalid segment number in input
>> + */
>> +ssize_t nilfs_sufile_set_suinfo(struct inode *sufile, void *buf,
>> + unsigned supsz, size_t nsup)
>> +{
>> + struct buffer_head *bh;
>> + struct nilfs_suinfo_update *sup, *supv = buf;
>> + struct nilfs_segment_usage *su;
>> + void *kaddr;
>> + unsigned long blkoff, prev_blkoff;
>> + size_t nerr = 0;
>> + int ret = 0;
>> +
>> + if (unlikely(nsup == 0))
>> + goto out;
>> +
>> + down_write(&NILFS_MDT(sufile)->mi_sem);
>> + for (sup = supv; sup < supv + nsup; sup++) {
>> + if (unlikely(sup->sup_segnum >=
>> + nilfs_sufile_get_nsegments(sufile))) {
>> + printk(KERN_WARNING
>> + "%s: invalid segment number: %llu\n", __func__,
>> + (unsigned long long)sup->sup_segnum);
>> + nerr++;
>> + }
>> + }
>> + if (nerr > 0) {
>> + ret = -EINVAL;
>> + goto out_sem;
>> + }
>
> Seems that you can exit from inside the loop:
>
> for (sup = supv; sup < supv + nsup; sup++) {
> if (unlikely(sup->sup_segnum >=
> nilfs_sufile_get_nsegments(sufile))) {
> printk(KERN_WARNING
> "%s: invalid segment number: %llu\n", __func__,
> (unsigned long long)sup->sup_segnum);
> ret = -EINVAL;
> goto out_sem;
> }
> }
Yes. I copied that from nilfs_sufile_updatev.
>> +
>> + sup = supv;
>> + blkoff = nilfs_sufile_get_blkoff(sufile, sup->sup_segnum);
>> + ret = nilfs_mdt_get_block(sufile, blkoff, 1, NULL, &bh);
>> + if (ret < 0)
>> + goto out_sem;
>> +
>> + for (;;) {
>> + kaddr = kmap_atomic(bh->b_page);
>> + su = nilfs_sufile_block_get_segment_usage(
>> + sufile, sup->sup_segnum, bh, kaddr);
>> +
>> + if (nilfs_suinfo_update_lastmod(sup))
>> + su->su_lastmod = cpu_to_le64(sup->sup_sui.sui_lastmod);
>> +
>> + if (nilfs_suinfo_update_nblocks(sup))
>> + su->su_nblocks = cpu_to_le32(sup->sup_sui.sui_nblocks);
>> +
>> + if (nilfs_suinfo_update_flags(sup))
>> + su->su_flags = cpu_to_le32(sup->sup_sui.sui_flags);
>
> You must also update the counter value of sh_ncleansegs, sh_ndirtysegs
> in the nilfs_sufile_header struct of sufile header block based on the
> change of these flags.
>
> In addition, you should ignore NILFS_SEGMENT_USAGE_ACTIVE_FLAG as
> below because this flag is a virtual flag set by running nilfs kernel
> code. The flag bit should not be written to sufile on disk.
>
> (sui_flags & ~(1UL << NILFS_SEGMENT_USAGE_ACTIVE))
Yes. I didn't think of that.
>> +
>> + kunmap_atomic(kaddr);
>> +
>> + if (++sup >= supv + nsup)
>
> You must not use the automatic pointer operation of C language for
> nilfs_suinfo_update because it may be extended in a future release.
> This "++sup" breaks forward compatibility of the ioctl.
>
> You should do this by:
>
> sup = (void *)sup + supsz;
>
> Note that pointer type is automatically converted for "void *" type
> variables.
Makes sense. I guess I blindly copied that from nilfs_sufile_updatev,
but with a simple array of __u64 it works of course. With a structure,
that is subject to change, not so much any more.
>> + break;
>> + prev_blkoff = blkoff;
>> + blkoff = nilfs_sufile_get_blkoff(sufile, sup->sup_segnum);
>> + if (blkoff == prev_blkoff)
>> + continue;
>> +
>> + /* get different block */
>
> You must mark bh that this function changed as dirty with
> mark_buffer_dirty(bh). Otherwise, the change will be gone.
>
>
>> + brelse(bh);
>> + ret = nilfs_mdt_get_block(sufile, blkoff, 1, NULL, &bh);
>> + if (unlikely(ret < 0))
>> + goto out_sem;
>> + }
>> + brelse(bh);
>> +
>
> The sufile should be marked as dirty (if any change happened):
>
> nilfs_mdt_mark_dirty(sufile);
Of course. I am sorry that's a really stupid error. I will fix it right
away.
Thanks for your review. I am really embarrassed about all the stupid
avoidable errors.
br,
Andreas Rohner
--
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-01-24 12:34 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-21 13:59 [PATCH v2 0/5] nilfs-utils: skip inefficient gc operations Andreas Rohner
[not found] ` <cover.1390310509.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-21 13:59 ` [PATCH v2 1/5] nilfs-utils: cldconfig add an option to set minimal free blocks Andreas Rohner
[not found] ` <22b5b3ac403052d3044dc8c1bebe323191376c03.1390310509.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-21 14:10 ` dexen deVries
2014-01-21 14:38 ` Andreas Rohner
2014-01-21 14:53 ` Andreas Rohner
2014-01-23 17:49 ` Vyacheslav Dubeyko
[not found] ` <B1FCAEBD-EB58-4A06-BD6B-7D4FB533D9F1-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-23 18:31 ` Andreas Rohner
2014-01-21 13:59 ` [PATCH v2 2/5] nilfs-utils: cleanerd: add custom error value to enable fast retry Andreas Rohner
[not found] ` <e9d3dd17318a994fe7e2c100368212e0b4029e13.1390310509.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-23 17:49 ` Vyacheslav Dubeyko
[not found] ` <FE7FB751-68F4-48C3-A97A-782F4F6E69FE-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-23 19:08 ` Andreas Rohner
2014-01-21 13:59 ` [PATCH v2 3/5] nilfs-utils: refactoring of nilfs_reclaim_segment to add minblocks param Andreas Rohner
[not found] ` <36ef66ee15b3de8ca00815a6baa7bf6b62ca57d4.1390310509.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 18:04 ` Ryusuke Konishi
2014-01-21 13:59 ` [PATCH v2 4/5] nilfs-utils: add support for NILFS_IOCTL_SET_SUINFO ioctl Andreas Rohner
[not found] ` <72f8c37258d08ba9793b0c1bb0374dd8efcd4756.1390310509.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-23 17:49 ` Vyacheslav Dubeyko
[not found] ` <62FA32DB-83AC-4570-BD73-618C169390FE-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-23 19:17 ` Andreas Rohner
[not found] ` <52E16AE4.4000303-hi6Y0CQ0nG0@public.gmane.org>
2014-01-25 16:16 ` Vyacheslav Dubeyko
2014-01-24 18:26 ` Ryusuke Konishi
[not found] ` <20140125.032633.184837411.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-24 20:00 ` Andreas Rohner
[not found] ` <52E2C643.3070704-hi6Y0CQ0nG0@public.gmane.org>
2014-01-25 18:52 ` Ryusuke Konishi
2014-01-26 10:00 ` Ryusuke Konishi
[not found] ` <20140126.190004.443429632.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-26 11:24 ` Andreas Rohner
2014-01-21 13:59 ` [PATCH v2 5/5] nilfs-utils: man: add description of min_free_blocks_threshold Andreas Rohner
2014-01-21 14:00 ` [PATCH v2 1/3] nilfs2: add new nilfs_suinfo_update struct Andreas Rohner
[not found] ` <cec6a449ddf5ae9da2928cdddfb96ebcb2789eee.1390312777.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-21 14:00 ` [PATCH v2 2/3] nilfs2: add nilfs_sufile_set_suinfo to update segment usage info Andreas Rohner
[not found] ` <2fd48b2d524a59a02bdad13c0c194de3e5b55cc7.1390312777.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 11:56 ` Ryusuke Konishi
[not found] ` <20140124.205623.400541300.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-24 12:34 ` Andreas Rohner [this message]
[not found] ` <52E25DDC.2060502-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 16:34 ` Ryusuke Konishi
2014-01-21 14:00 ` [PATCH v2 3/3] nilfs2: implementation of NILFS_IOCTL_SET_SUINFO ioctl Andreas Rohner
[not found] ` <6fb5a6d45afca9ae2599c471c0e42805ed1b6c55.1390312777.git.andreas.rohner-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 13:20 ` Ryusuke Konishi
[not found] ` <20140124.222016.110509397.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-24 13:44 ` Andreas Rohner
[not found] ` <52E26E46.3030702-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 15:23 ` Ryusuke Konishi
2014-01-24 4:56 ` [PATCH v2 1/3] nilfs2: add new nilfs_suinfo_update struct Ryusuke Konishi
[not found] ` <20140124.135635.27780504.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-24 12:11 ` Andreas Rohner
[not found] ` <52E25883.3010307-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 12:37 ` Ryusuke Konishi
2014-01-22 23:46 ` [PATCH v2 0/5] nilfs-utils: skip inefficient gc operations Michael L. Semon
[not found] ` <52E05863.90604-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-23 10:25 ` Andreas Rohner
[not found] ` <52E0EE08.3040703-hi6Y0CQ0nG0@public.gmane.org>
2014-01-23 20:57 ` Michael L. Semon
2014-01-23 17:48 ` Vyacheslav Dubeyko
[not found] ` <85EBEC6B-CA69-472A-8DDD-8E056F809EC4-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-23 18:12 ` Andreas Rohner
[not found] ` <52E15B9E.6040307-hi6Y0CQ0nG0@public.gmane.org>
2014-01-24 8:02 ` Vyacheslav Dubeyko
[not found] ` <FC7F25C5-1E72-4DF5-B860-FBCE36E91EAB-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-24 14:18 ` Andreas Rohner
[not found] ` <52E27651.6070207-hi6Y0CQ0nG0@public.gmane.org>
2014-01-25 16:33 ` Vyacheslav Dubeyko
[not found] ` <82ACC3FC-BE83-483F-99D8-D13F4D02C58F-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2014-01-26 6:57 ` Ryusuke Konishi
[not found] ` <20140126.155740.56352351.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2014-01-26 10: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=52E25DDC.2060502@gmx.net \
--to=andreas.rohner-hi6y0cq0ng0@public.gmane.org \
--cc=konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org \
--cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@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.