From patchwork Wed Oct 14 07:38:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 7391121 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A58F0BEEA4 for ; Wed, 14 Oct 2015 07:40:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AE802207A6 for ; Wed, 14 Oct 2015 07:40:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B163C20793 for ; Wed, 14 Oct 2015 07:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752936AbbJNHiv (ORCPT ); Wed, 14 Oct 2015 03:38:51 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:35442 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752912AbbJNHis (ORCPT ); Wed, 14 Oct 2015 03:38:48 -0400 Received: by padcn9 with SMTP id cn9so15575906pad.2; Wed, 14 Oct 2015 00:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=opP1NKbcKkeFWXPwZDDMK6ASU8lnsfYv1DVQ3otoPIY=; b=WYNoe2oYCson9wTIpzScgKbrbl5uWZHGS93bq3FMbOFUMTNu7+G2TMnt414aNQRbqt sfh5uZGRMEghkhAkUDyBTWq0rWqh9a7/UY1TiwUh2fsbFlFXE8G9cqW33BJXhKIc4TM/ ArcXYmIFaTfQkAq63vp4gC9/HRZ6H0FXOgapUmhVf9ot36ykvsnPe2BdFNDYqaMYz6+o sn5k+onxLFRmn0gTLYma7QE1HiH8Lm8FralvsN7pDzR0Fbuc6xSn/R+t2SWCSk5wESM5 muCMeQ68zIqj8erqPzKjJq1NDWfR6uKM2un1sBOvq0eBSE0Dfevy9i685HZHeta6Gvre STqA== X-Received: by 10.68.234.200 with SMTP id ug8mr2202913pbc.13.1444808326799; Wed, 14 Oct 2015 00:38:46 -0700 (PDT) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id qr8sm4147173pbb.47.2015.10.14.00.38.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Oct 2015 00:38:46 -0700 (PDT) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Andrew Morton Cc: Minchan Kim , Nitin Gupta , Sergey Senozhatsky , Herbert Xu , "David S. Miller" , Stephan Mueller , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Sergey Senozhatsky , Joonsoo Kim Subject: [PATCH v4 5/8] zram: make stream find and release functions static Date: Wed, 14 Oct 2015 16:38:21 +0900 Message-Id: <1444808304-29320-6-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444808304-29320-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1444808304-29320-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Senozhatsky Hide (make static) zstrm find and release function and introduce zcomp_compress_begin()/zcomp_compress_end(). We will have begin and end functions around compression (this patch) and decompression (next patch). So the work flow is evolving to: zstrm = foo_begin(); foo(zstrm); foo_end(zstrm); where foo is compress or decompress zcomp functions. This patch is a preparation to make crypto API-powered zcomp possible. The reasoning is that some crypto compression backends require zstrm for decompression. Acked-by: Minchan Kim Signed-off-by: Sergey Senozhatsky Signed-off-by: Joonsoo Kim --- drivers/block/zram/zcomp.c | 27 +++++++++++++++++++++++++-- drivers/block/zram/zcomp.h | 8 ++++++-- drivers/block/zram/zram_drv.c | 6 +++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 5cb13ca..52d5b04 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -296,16 +296,39 @@ bool zcomp_set_max_streams(struct zcomp *comp, int num_strm) return comp->set_max_streams(comp, num_strm); } -struct zcomp_strm *zcomp_strm_find(struct zcomp *comp) +static struct zcomp_strm *zcomp_strm_find(struct zcomp *comp) { return comp->strm_find(comp); } -void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm) +static void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm) { comp->strm_release(comp, zstrm); } +/* Never return NULL, may sleep */ +struct zcomp_strm *zcomp_compress_begin(struct zcomp *comp) +{ + return zcomp_strm_find(comp); +} + +void zcomp_compress_end(struct zcomp *comp, struct zcomp_strm *zstrm) +{ + zcomp_strm_release(comp, zstrm); +} + +/* May return NULL, may sleep */ +struct zcomp_strm *zcomp_decompress_begin(struct zcomp *comp) +{ + return NULL; +} + +void zcomp_decompress_end(struct zcomp *comp, struct zcomp_strm *zstrm) +{ + if (zstrm) + zcomp_strm_release(comp, zstrm); +} + int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, const unsigned char *src, size_t *dst_len) { diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 46e2b9f..616e013 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -56,12 +56,16 @@ bool zcomp_available_algorithm(const char *comp); struct zcomp *zcomp_create(const char *comp, int max_strm); void zcomp_destroy(struct zcomp *comp); -struct zcomp_strm *zcomp_strm_find(struct zcomp *comp); -void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm); + +struct zcomp_strm *zcomp_compress_begin(struct zcomp *comp); +void zcomp_compress_end(struct zcomp *comp, struct zcomp_strm *zstrm); int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, const unsigned char *src, size_t *dst_len); +struct zcomp_strm *zcomp_decompress_begin(struct zcomp *comp); +void zcomp_decompress_end(struct zcomp *comp, struct zcomp_strm *zstrm); + int zcomp_decompress(struct zcomp *comp, const unsigned char *src, size_t src_len, unsigned char *dst); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 3e8d8ff..83a06f2 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -673,7 +673,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, goto out; } - zstrm = zcomp_strm_find(zram->comp); + zstrm = zcomp_compress_begin(zram->comp); user_mem = kmap_atomic(page); if (is_partial_io(bvec)) { @@ -744,7 +744,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, memcpy(cmem, src, clen); } - zcomp_strm_release(zram->comp, zstrm); + zcomp_compress_end(zram->comp, zstrm); zstrm = NULL; zs_unmap_object(meta->mem_pool, handle); @@ -764,7 +764,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, atomic64_inc(&zram->stats.pages_stored); out: if (zstrm) - zcomp_strm_release(zram->comp, zstrm); + zcomp_compress_end(zram->comp, zstrm); if (is_partial_io(bvec)) kfree(uncmem); return ret;