Use memcmp for check sample data to zeroes.

Signed-off-by: Timofey Titovets <[email protected]>
---
 fs/btrfs/heuristic.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/fs/btrfs/heuristic.c b/fs/btrfs/heuristic.c
index 5336638a3b7c..4557ea1db373 100644
--- a/fs/btrfs/heuristic.c
+++ b/fs/btrfs/heuristic.c
@@ -73,6 +73,21 @@ static struct list_head *heuristic_alloc_workspace(void)
        return ERR_PTR(-ENOMEM);
 }

+static bool sample_zeroed(struct workspace *workspace)
+{
+       u32 i;
+       u8 zero[READ_SIZE];
+
+       memset(&zero, 0, sizeof(zero));
+
+       for (i = 0; i < workspace->sample_size; i += sizeof(zero)) {
+               if (memcmp(&workspace->sample[i], &zero, sizeof(zero)))
+                       return false;
+       }
+
+       return true;
+}
+
 static int heuristic(struct list_head *ws, struct inode *inode,
                     u64 start, u64 end)
 {
@@ -110,6 +125,9 @@ static int heuristic(struct list_head *ws, struct inode 
*inode,

        workspace->sample_size = b;

+       if (sample_zeroed(workspace))
+               return 1;
+
        memset(workspace->bucket, 0, sizeof(*workspace->bucket)*BUCKET_SIZE);

        for (a = 0; a < workspace->sample_size; a++) {
--
2.14.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to