From patchwork Mon Aug 15 17:36:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 9281697 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BFA82607FD for ; Mon, 15 Aug 2016 17:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B29D828E14 for ; Mon, 15 Aug 2016 17:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A72A128E10; Mon, 15 Aug 2016 17:41:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD94F28E10 for ; Mon, 15 Aug 2016 17:41:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u7FHbX9s003298; Mon, 15 Aug 2016 13:37:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u7FHbVGb029637 for ; Mon, 15 Aug 2016 13:37:31 -0400 Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7FHbVgR021123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 15 Aug 2016 13:37:31 -0400 Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 508FA80B20; Mon, 15 Aug 2016 17:37:30 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id c52so2341178qte.1; Mon, 15 Aug 2016 10:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4/igbw8GCVoJIwdrviQDBAxU1s54Jfs/GN18FpjDejk=; b=aJ9R2N3+Hbpphsj5z5TO93EMXXse4NGyNOYXyn48dNX9amChIk4RGStsEeSPvPszrv WJ5axiaccnB48Y6nP6gk3lTYYi9GvJJg/EtdGvpGT0sdQezvulK6ltxmzVMvgMQSD+Pn HXcNXTx+dXTJf0eXfchRsmxmlcPhTJmD4y9KKLC+oH4GLXpGLIlnIdYKP3QaEurYiqR7 S7zA38hYoSEcfFwtTwoTjrSbfHGYKR15erlQHOcph7NApnxJj4kUhNETvvSVTAgMVpvK 9ID3ujJ3A8aZPlAJztttjIYZwEODw2r5NWU2i/zXP8zDAsylfuk5Vr+5YkAhZdgt5QKP QPMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4/igbw8GCVoJIwdrviQDBAxU1s54Jfs/GN18FpjDejk=; b=bQ235Euk/OzvGinzuJMgCIrHpr50WKRmR161VZePMjABomQDjyC3+zERVrKpg9KXhN haE1bJs8tGChihm3RzdDp15juHBYV2AbbJ6yTccFmvT604qEX0rHN+6Vpf0jZAgHkDTo yn69QKFAhhe6eeJegYUGQ16AM58rjRMEA82+W+72JqAtCnJw5x+6ORICq/z3QaboYAJL +VzLEuv+69HjDaYX0q/k5qhdb8uRbfVXU6pnieNwhGnmnG20aqvnN27n/y3cCPJJ7MDa zps/H3Gy60Y7v9ETpbK3wC23Fp5We543OFTMZLDrdnw6nhg0lTDe2UMIWdJZt7wKoEQG wOag== X-Gm-Message-State: AEkooutxFH0Fu0GP7rln9ONGcHHYCyH9iwTqdzZxB0zSDpZZwbpdbs8BN5aLlwBglPF91w== X-Received: by 10.237.49.5 with SMTP id 5mr33940815qtg.136.1471282649586; Mon, 15 Aug 2016 10:37:29 -0700 (PDT) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id n128sm11636084qkc.36.2016.08.15.10.37.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Aug 2016 10:37:29 -0700 (PDT) From: Ram Pai To: LKML , linux-raid@vger.kernel.org, dm-devel@redhat.com, linux-doc@vger.kernel.org Date: Mon, 15 Aug 2016 10:36:39 -0700 Message-Id: <1471282613-31006-3-git-send-email-linuxram@us.ibm.com> In-Reply-To: <1471282613-31006-1-git-send-email-linuxram@us.ibm.com> References: <1471282613-31006-1-git-send-email-linuxram@us.ibm.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 15 Aug 2016 17:37:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 15 Aug 2016 17:37:30 +0000 (UTC) for IP:'209.85.216.195' DOMAIN:'mail-qt0-f195.google.com' HELO:'mail-qt0-f195.google.com' FROM:'ram.n.pai@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.082 (BAYES_50, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.216.195 mail-qt0-f195.google.com 209.85.216.195 mail-qt0-f195.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-loop: dm-devel@redhat.com Cc: shli@kernel.org, snitzer@redhat.com, agk@redhat.com, corbet@lwn.net Subject: [dm-devel] [RFC PATCH 02/16] DM: Ability to choose the compressor. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP Ability to create a block device with a compression algorithm of the users choice. Currently lzo and nx842 compressors are supported. If the compressor algorithm is not specified the default setting in /sys/modules/dm-inplace-compress/parameters/compress is used. Signed-off-by: Ram Pai --- drivers/md/dm-inplace-compress.c | 129 ++++++++++++++++++++++++++++---------- drivers/md/dm-inplace-compress.h | 8 ++- 2 files changed, 103 insertions(+), 34 deletions(-) diff --git a/drivers/md/dm-inplace-compress.c b/drivers/md/dm-inplace-compress.c index c3c3750..70d6c0e 100644 --- a/drivers/md/dm-inplace-compress.c +++ b/drivers/md/dm-inplace-compress.c @@ -20,8 +20,62 @@ static struct dm_icomp_compressor_data compressors[] = { .name = "lzo", .comp_len = lzo_comp_len, }, + [DMCP_COMP_ALG_842] = { + .name = "842", + .comp_len = nx842_comp_len, + }, +}; +static int default_compressor = -1; + +#define DMCP_ALGO_LENGTH 9 +static char dm_icomp_algorithm[DMCP_ALGO_LENGTH] = "lzo"; +static struct kparam_string dm_icomp_compressor_kparam = { + .string = dm_icomp_algorithm, + .maxlen = sizeof(dm_icomp_algorithm), }; -static int default_compressor; +static int dm_icomp_compressor_param_set(const char *, + const struct kernel_param *); +static struct kernel_param_ops dm_icomp_compressor_param_ops = { + .set = dm_icomp_compressor_param_set, + .get = param_get_string, +}; +module_param_cb(compress_algorithm, &dm_icomp_compressor_param_ops, + &dm_icomp_compressor_kparam, 0644); + +static int dm_icomp_get_compressor(const char *s) +{ + int r, val_len; + + if (crypto_has_comp(s, 0, 0)) { + for (r = 0; r < ARRAY_SIZE(compressors); r++) { + val_len = strlen(compressors[r].name); + if (strncmp(s, compressors[r].name, val_len) == 0) + return r; + } + } + return -1; +} + +static int dm_icomp_compressor_param_set(const char *val, + const struct kernel_param *kp) +{ + int ret; + char str[kp->str->maxlen], *s; + int val_len = strlen(val)+1; + + strlcpy(str, val, val_len); + s = strim(str); + ret = dm_icomp_get_compressor(s); + if (ret < 0) { + DMWARN("Compressor %s not supported", s); + return -1; + } + DMWARN("compressor is %s", s); + default_compressor = ret; + strlcpy(dm_icomp_algorithm, compressors[ret].name, + sizeof(dm_icomp_algorithm)); + return 0; +} static struct kmem_cache *dm_icomp_req_cachep; static struct kmem_cache *dm_icomp_io_range_cachep; @@ -417,7 +471,7 @@ static int dm_icomp_read_or_create_super(struct dm_icomp_info *info) ret = -EINVAL; goto out; } - if (!crypto_has_comp(compressors[super->comp_alg].name, 0, 0)) { + if (!crypto_has_comp(compressors[info->comp_alg].name, 0, 0)) { info->ti->error = "Compressor algorithm doesn't support"; ret = -EINVAL; @@ -436,7 +490,6 @@ static int dm_icomp_read_or_create_super(struct dm_icomp_info *info) new_super = true; } - info->comp_alg = super->comp_alg; if (dm_icomp_alloc_compressor(info)) { ret = -ENOMEM; goto out; @@ -467,50 +520,56 @@ out: } /* - * / + * [ / ] + * [ ] */ static int dm_icomp_ctr(struct dm_target *ti, unsigned int argc, char **argv) { struct dm_icomp_info *info; - char write_mode[15]; + char mode[15]; + int par = 0; int ret, i; - if (argc < 2) { - ti->error = "Invalid argument count"; - return -EINVAL; - } - info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) { ti->error = "dm-inplace-compress: Cannot allocate context"; return -ENOMEM; } info->ti = ti; - - if (sscanf(argv[1], "%s", write_mode) != 1) { - ti->error = "Invalid argument"; - ret = -EINVAL; - goto err_para; - } - - if (strcmp(write_mode, "writeback") == 0) { - if (argc != 3) { + info->comp_alg = default_compressor; + while (++par < argc) { + if (sscanf(argv[par], "%s", mode) != 1) { ti->error = "Invalid argument"; ret = -EINVAL; goto err_para; } - info->write_mode = DMCP_WRITE_BACK; - if (sscanf(argv[2], "%u", &info->writeback_delay) != 1) { - ti->error = "Invalid argument"; - ret = -EINVAL; - goto err_para; + + if (strcmp(mode, "writeback") == 0) { + info->write_mode = DMCP_WRITE_BACK; + if (sscanf(argv[++par], "%u", + &info->writeback_delay) != 1) { + ti->error = "Invalid argument"; + ret = -EINVAL; + goto err_para; + } + } else if (strcmp(mode, "writethrough") == 0) { + info->write_mode = DMCP_WRITE_THROUGH; + } else if (strcmp(mode, "compressor") == 0) { + if (sscanf(argv[++par], "%s", mode) != 1) { + ti->error = "Invalid argument"; + ret = -EINVAL; + goto err_para; + } + ret = dm_icomp_get_compressor(mode); + if (ret >= 0) { + DMWARN("compressor is %s", mode); + info->comp_alg = ret; + } else { + ti->error = "Unsupported compressor"; + ret = -EINVAL; + goto err_para; + } } - } else if (strcmp(write_mode, "writethrough") == 0) { - info->write_mode = DMCP_WRITE_THROUGH; - } else { - ti->error = "Invalid argument"; - ret = -EINVAL; - goto err_para; } if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), @@ -1407,16 +1466,20 @@ static struct target_type dm_icomp_target = { static int __init dm_icomp_init(void) { int r; + int arr_size = ARRAY_SIZE(compressors); - for (r = 0; r < ARRAY_SIZE(compressors); r++) + for (r = 0; r < arr_size; r++) if (crypto_has_comp(compressors[r].name, 0, 0)) break; - if (r >= ARRAY_SIZE(compressors)) { + if (r >= arr_size) { DMWARN("No crypto compressors are supported"); return -EINVAL; } - default_compressor = r; + strlcpy(dm_icomp_algorithm, compressors[r].name, + sizeof(dm_icomp_algorithm)); + DMWARN(" %s crypto compressor used ", + compressors[default_compressor].name); r = -ENOMEM; dm_icomp_req_cachep = kmem_cache_create("dm_icomp_requests", diff --git a/drivers/md/dm-inplace-compress.h b/drivers/md/dm-inplace-compress.h index e07b9b7..b61ff0d 100644 --- a/drivers/md/dm-inplace-compress.h +++ b/drivers/md/dm-inplace-compress.h @@ -10,7 +10,8 @@ struct dm_icomp_super_block { u8 comp_alg; } __packed; -#define DMCP_COMP_ALG_LZO 0 +#define DMCP_COMP_ALG_LZO 1 +#define DMCP_COMP_ALG_842 0 #ifdef __KERNEL__ struct dm_icomp_compressor_data { @@ -23,6 +24,11 @@ static inline int lzo_comp_len(int comp_len) return lzo1x_worst_compress(comp_len); } +static inline int nx842_comp_len(int comp_len) +{ + return comp_len; +} + /* * Minium logical sector size of this target is 4096 byte, which is a block. * Data of a block is compressed. Compressed data is round up to 512B, which is