linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <fdmanana@gmail.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Subject: Re: [PATCH v4 07/18] btrfs: dedup: Implement btrfs_dedup_calc_hash interface
Date: Fri, 15 Jan 2016 09:41:17 +0800	[thread overview]
Message-ID: <56984E3D.50703@cn.fujitsu.com> (raw)
In-Reply-To: <CAL3q7H4gpHUCZrBK6WLJMhDaj+j_gJJguZwTVzLO6E0eR0fgNw@mail.gmail.com>



Filipe Manana wrote on 2016/01/14 10:08 +0000:
> On Thu, Jan 14, 2016 at 5:57 AM, Qu Wenruo <quwenruo@cn.fujitsu.com> wrote:
>> From: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
>>
>> Unlike in-memory or on-disk dedup method, only SHA256 hash method is
>> supported yet, so implement btrfs_dedup_calc_hash() interface using
>> SHA256.
>>
>> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
>> Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
>> ---
>>   fs/btrfs/dedup.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 57 insertions(+)
>>
>> diff --git a/fs/btrfs/dedup.c b/fs/btrfs/dedup.c
>> index d6ee576..8860916 100644
>> --- a/fs/btrfs/dedup.c
>> +++ b/fs/btrfs/dedup.c
>> @@ -465,3 +465,60 @@ int btrfs_dedup_search(struct inode *inode, u64 file_pos,
>>          }
>>          return ret;
>>   }
>> +
>> +static int hash_data(struct btrfs_dedup_info *dedup_info, const char *data,
>> +                    u64 length, struct btrfs_dedup_hash *hash)
>> +{
>> +       struct crypto_shash *tfm = dedup_info->dedup_driver;
>> +       struct {
>> +               struct shash_desc desc;
>> +               char ctx[crypto_shash_descsize(tfm)];
>> +       } sdesc;
>> +       int ret;
>> +
>> +       sdesc.desc.tfm = tfm;
>> +       sdesc.desc.flags = 0;
>> +
>> +       ret = crypto_shash_digest(&sdesc.desc, data, length,
>> +                                 (char *)(hash->hash));
>> +       return ret;
>> +}
>> +
>> +int btrfs_dedup_calc_hash(struct btrfs_root *root, struct inode *inode,
>> +                         u64 start, struct btrfs_dedup_hash *hash)
>> +{
>> +       struct page *p;
>> +       struct btrfs_dedup_info *dedup_info = root->fs_info->dedup_info;
>> +       char *data;
>> +       int i;
>> +       int ret;
>> +       u64 dedup_bs;
>> +       u64 sectorsize = root->sectorsize;
>> +
>> +       if (!dedup_info || !hash)
>> +               return 0;
>> +
>> +       WARN_ON(!IS_ALIGNED(start, sectorsize));
>> +
>> +       dedup_bs = dedup_info->blocksize;
>> +       sectorsize = root->sectorsize;
>> +
>> +       data = kmalloc(dedup_bs, GFP_NOFS);
>> +       if (!data)
>> +               return -ENOMEM;
>> +       for (i = 0; sectorsize * i < dedup_bs; i++) {
>> +               char *d;
>> +
>> +               /* TODO: Add support for subpage size case */
>> +               p = find_get_page(inode->i_mapping,
>> +                                 (start >> PAGE_CACHE_SHIFT) + i);
>> +               WARN_ON(!p);
>
> If !p, we should return with an error too, otherwise we'll get a null
> pointer dereference below.

Right, and that's also true for all the caller of find_get_page() in btrfs.

I'll also locate and fix them in another patch before btrfs dedup patchset.

Thanks for the review and hint.
Qu

>
>> +               d = kmap_atomic(p);
>> +               memcpy((data + sectorsize * i), d, sectorsize);
>> +               kunmap_atomic(d);
>> +               page_cache_release(p);
>> +       }
>> +       ret = hash_data(dedup_info, data, dedup_bs, hash);
>> +       kfree(data);
>> +       return ret;
>> +}
>> --
>> 2.7.0
>>
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" 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:[~2016-01-15  1:41 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14  5:57 [PATCH v4 00/14][For 4.6] Btrfs: Add inband (write time) de-duplication framework Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 01/18] btrfs: dedup: Introduce dedup framework and its header Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 02/18] btrfs: dedup: Introduce function to initialize dedup info Qu Wenruo
2016-01-14 21:33   ` kbuild test robot
2016-01-14  5:57 ` [PATCH v4 03/18] btrfs: dedup: Introduce function to add hash into in-memory tree Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 04/18] btrfs: dedup: Introduce function to remove hash from " Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 05/18] btrfs: delayed-ref: Add support for atomic increasing extent ref Qu Wenruo
2016-01-14  9:56   ` Filipe Manana
2016-01-15  1:16     ` Qu Wenruo
2016-01-20  3:25       ` Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 06/18] btrfs: dedup: Introduce function to search for an existing hash Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 07/18] btrfs: dedup: Implement btrfs_dedup_calc_hash interface Qu Wenruo
2016-01-14 10:08   ` Filipe Manana
2016-01-15  1:41     ` Qu Wenruo [this message]
2016-01-14  5:57 ` [PATCH v4 08/18] btrfs: ordered-extent: Add support for dedup Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 09/18] btrfs: dedup: Inband in-memory only de-duplication implement Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 10/18] btrfs: dedup: Add basic tree structure for on-disk dedup method Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 11/18] btrfs: dedup: Introduce interfaces to resume and cleanup dedup info Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 12/18] btrfs: dedup: Add support for on-disk hash search Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 13/18] btrfs: dedup: Add support to delete hash for on-disk backend Qu Wenruo
2016-01-14 10:19   ` Filipe Manana
2016-01-15  1:43     ` Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 14/18] btrfs: dedup: Add support for adding " Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 15/18] btrfs: dedup: Add ioctl for inband deduplication Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 16/18] btrfs: dedup: add an inode nodedup flag Qu Wenruo
2016-01-14  5:57 ` [PATCH v4 17/18] btrfs: dedup: add a property handler for online dedup Qu Wenruo
2016-01-14  9:56   ` Filipe Manana
2016-01-14 19:04     ` Darrick J. Wong
2016-01-15  1:37     ` Qu Wenruo
2016-01-15  9:19       ` Filipe Manana
2016-01-15  9:33         ` Qu Wenruo
2016-01-15 12:36         ` Duncan
2016-01-15 15:22           ` Filipe Manana
2016-01-16  2:53             ` Duncan
2016-01-14  5:57 ` [PATCH v4 18/18] btrfs: dedup: add per-file online dedup control Qu Wenruo

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=56984E3D.50703@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=fdmanana@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wangxg.fnst@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).