From patchwork Thu Nov 26 10:47:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7876FC63697 for ; Thu, 26 Nov 2020 10:47:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0439620DD4 for ; Thu, 26 Nov 2020 10:47:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="X6r9NINy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388343AbgKZKr3 (ORCPT ); Thu, 26 Nov 2020 05:47:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388289AbgKZKr1 (ORCPT ); Thu, 26 Nov 2020 05:47:27 -0500 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E8FC0617A7 for ; Thu, 26 Nov 2020 02:47:27 -0800 (PST) Received: by mail-ed1-x543.google.com with SMTP id u19so442279edx.2 for ; Thu, 26 Nov 2020 02:47:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LltlK60r4LyNjCoDNXMYJYASHu9Oufj7+fCgendHkG0=; b=X6r9NINyvryxJSxhnnk2PepkAAJHwTb0DMnxHZvJrOl5PagBUJx/VvkzRU6U2fviTO JPXqqy5xxeoBBmwUiTOwh58eJcwGS7U9vQI/5NolzBtEbHDAxEShHw67ES3mjYy2ZOF/ 6RxKSJUmxxvN1DncPGGupYOQtiZnl2SQZ2zgJvvd4TfEMRMzprrj6gSS6kFqRuIe4eW7 YjcXdr6/d8z2tf62JgQDOhnpnXvHSdlxr0ICUSYbVGJga21Lik4/Lk5r3G7d5i1ja0Z6 kPEWKkCbGW6TDJuhN5f0na1Pk9MoeU5jvBiaBusXAsMnWUgNhSRPBB/pyV7pWE14bxWJ LqGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LltlK60r4LyNjCoDNXMYJYASHu9Oufj7+fCgendHkG0=; b=VIQN7P/XlJm09zSbSsPA1FCuz+8MnlYhyxBQKkBp83dNiFf0SrBhT8LsYS5f0oeBOC vLsdpMMHdKoogQ2hKJ+n+WPMAEX7xyvcXxn1M6QHLmDMv5pC7GHMmm+PmetiOoaxhWU2 Cj+qUgKm8gsHjb39v4yVzhL20o1q/ZwaBvnhHMRZl34H4mtLf8Yy7Q35xvIvJuah4tc/ vwFzv7xGg7mKMKqP9ya2BgU4azQMOl/V+P3tCFtB3JN1DQ/Xt4leReCD491RIX0Dt+vd yPRb14LH7vGW1S6n83mR4RPEEojo2KFGyiN9wupmVvkRTVD5fKro6p/15GBd3BWURTSn uKYw== X-Gm-Message-State: AOAM5321xng29ytN9gi8+VExbyU/jq4lknPC1Qb7sh0juM8K/NIH3ZOd SiN88uWwwTPJ3rfkK2BpAXMDoyBFUjleFw== X-Google-Smtp-Source: ABdhPJwoDV4EfqWlXfeQL+BDnymsqkx+rBeCMSdV7ywJ2n2N9o4mKL2tr0OF1P3U5NAYJGlEVHGY7g== X-Received: by 2002:a05:6402:17f0:: with SMTP id t16mr1828766edy.107.1606387645664; Thu, 26 Nov 2020 02:47:25 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:25 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Md Haris Iqbal Subject: [PATCH for-next 1/8] block/rnbd-clt: Make path parameter optional for map_device Date: Thu, 26 Nov 2020 11:47:16 +0100 Message-Id: <20201126104723.150674-2-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Md Haris Iqbal During map_device if the given session exists, then the path parameter is not used. In such a case, the path parameter is redundant. This commit makes the path parameter optional for map_device. When the path parameter is not given, if the session exists then that is used to establish the rtrs connection. If the session does not exist, and the path parameter is also missing, then map_device fails. Signed-off-by: Md Haris Iqbal Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt-sysfs.c | 1 - drivers/block/rnbd/rnbd-clt.c | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index 4f4474eecadb..e7b41ec7cd6a 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -37,7 +37,6 @@ enum { }; static const unsigned int rnbd_opt_mandatory[] = { - RNBD_OPT_PATH, RNBD_OPT_DEV_PATH, RNBD_OPT_SESSNAME, }; diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index 8b2411ccbda9..edefa0761a81 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -1193,6 +1193,12 @@ find_and_get_or_create_sess(const char *sessname, else if (!first) return sess; + if (!path_cnt) { + pr_err("Session %s not found, and path parameter not given", sessname); + err = -ENXIO; + goto put_sess; + } + rtrs_ops = (struct rtrs_clt_ops) { .priv = sess, .link_ev = rnbd_clt_link_ev, From patchwork Thu Nov 26 10:47:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CA94C63777 for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D60C20DD4 for ; Thu, 26 Nov 2020 10:47:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="YsQprvax" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388347AbgKZKrb (ORCPT ); Thu, 26 Nov 2020 05:47:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388341AbgKZKr2 (ORCPT ); Thu, 26 Nov 2020 05:47:28 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1049CC061A04 for ; Thu, 26 Nov 2020 02:47:28 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id cq7so1781061edb.4 for ; Thu, 26 Nov 2020 02:47:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K4l2Xqa78nl3oR6VwhQJgJaGGROL4T6jCJNlZ9gmwMo=; b=YsQprvaxw13SmjJexNHzbTRRUYnFqy5roaSWRaF1Sct3CIs09LIO6qF8rA/f0RfsKm wKcqVrw5c4EZFI/WrQd8i8hqEmnOEIBKDj54A+pWrWpC2KuIJNVmrtsD05k9zRgDxiy3 mFQJBjbp3cXM72XKuIF8EzL6ytE++S+P7L5rFNeMo56BjeaaK+ULUQWAaxx3Vd1qVdWX 3XHO/+wxBDPt3acl5BMG5o1zlmFs+EOGTYhSSeypHpoe+fCyXgbiZND/v6+mhaI4gA1K 2wXjxEbMtr1CqyQm3347BQTibeB1GGtHRTi28A85bCIsWdWCAbzdFfZK6jI4gr3vO9sX SHnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K4l2Xqa78nl3oR6VwhQJgJaGGROL4T6jCJNlZ9gmwMo=; b=gFR4K42/09RdBHtchIqK0mcqstZuGDKr56LEsn/Gs8UaQ/FmNAyAfF3HNoH57PSKYc WTb2+NLHHWjI3uKhAd/fXZnYAXlSCy7thgjGvt3i5n+QnX20O0SHaMM5VUxr2P+tegGJ KnV3g7SLYb7sNl6SFNw6AOcIj+NxSDE3SFbzjElv30jpiyIM2keg7Ue+SbA301SzJ76X fjsR1WH5sizLnVpUJu1OuJwSUBzI7tOugPXDrgVZ0kMNVEsA1TfTvWDGXtu+XIG7fRMT tTiHEUz2iKjpnTOr5na2OdYLnb8Cq2m7nrDCUtm3JDihDg4uivvb+Hyj6L/HeHPR+NhE sAXA== X-Gm-Message-State: AOAM5304xReTUUZcCm9zGOfFcZuBIaJqxhdOsUrilvTgSjJ5oULqk6Wr XRVaFxMjPfLx1N+PpZdL0frd7wQILQeW/w== X-Google-Smtp-Source: ABdhPJzs4COBh7IKll7uR58uJBngUFAxQWSDYvrsmjMWQdv4xbgTlO3aPUpH87lLRB6jZPi6Bk7iWg== X-Received: by 2002:a50:e8c7:: with SMTP id l7mr1948772edn.356.1606387646564; Thu, 26 Nov 2020 02:47:26 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:26 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Guoqing Jiang , Gioh Kim , Md Haris Iqbal Subject: [PATCH for-next 2/8] block/rnbd-clt: support mapping two devices with the same name from different servers Date: Thu, 26 Nov 2020 11:47:17 +0100 Message-Id: <20201126104723.150674-3-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Guoqing Jiang Previously, we can't map same device name from different sessions due to the limitation of sysfs naming mechanism. root@clt2:~# ls -l /sys/class/rnbd-client/ctl/devices/ total 0 lrwxrwxrwx 1 root 0 Sep 2 16:31 !dev!nullb1 -> ../../../block/rnbd0 We only use the device name in above, which caused device with the same name can't be mapped from another server. To address the issue, the sessname is appended to the node to differentiate where the device comes from. Also, we need to check if the pathname is existed in a specific session instead of search it in global sess_list. Signed-off-by: Guoqing Jiang Signed-off-by: Gioh Kim Reviewed-by: Md Haris Iqbal Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt-sysfs.c | 4 ++++ drivers/block/rnbd/rnbd-clt.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index e7b41ec7cd6a..5d3c3c80dab4 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -480,6 +480,10 @@ static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf, if (ret >= len) return -ENAMETOOLONG; + ret = snprintf(buf, len, "%s@%s", buf, dev->sess->sessname); + if (ret >= len) + return -ENAMETOOLONG; + return 0; } diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index edefa0761a81..1bb495e50931 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -1410,13 +1410,16 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess, return ERR_PTR(ret); } -static bool __exists_dev(const char *pathname) +static bool __exists_dev(const char *pathname, const char *sessname) { struct rnbd_clt_session *sess; struct rnbd_clt_dev *dev; bool found = false; list_for_each_entry(sess, &sess_list, list) { + if (sessname && strncmp(sess->sessname, sessname, + sizeof(sess->sessname))) + continue; mutex_lock(&sess->lock); list_for_each_entry(dev, &sess->devs_list, list) { if (!strncmp(dev->pathname, pathname, @@ -1433,12 +1436,12 @@ static bool __exists_dev(const char *pathname) return found; } -static bool exists_devpath(const char *pathname) +static bool exists_devpath(const char *pathname, const char *sessname) { bool found; mutex_lock(&sess_lock); - found = __exists_dev(pathname); + found = __exists_dev(pathname, sessname); mutex_unlock(&sess_lock); return found; @@ -1451,7 +1454,7 @@ static bool insert_dev_if_not_exists_devpath(const char *pathname, bool found; mutex_lock(&sess_lock); - found = __exists_dev(pathname); + found = __exists_dev(pathname, sess->sessname); if (!found) { mutex_lock(&sess->lock); list_add_tail(&dev->list, &sess->devs_list); @@ -1481,7 +1484,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, struct rnbd_clt_dev *dev; int ret; - if (exists_devpath(pathname)) + if (unlikely(exists_devpath(pathname, sessname))) return ERR_PTR(-EEXIST); sess = find_and_get_or_create_sess(sessname, paths, path_cnt, port_nr); From patchwork Thu Nov 26 10:47:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D135C64E75 for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E70D92158C for ; Thu, 26 Nov 2020 10:47:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="TezphtH3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388350AbgKZKrb (ORCPT ); Thu, 26 Nov 2020 05:47:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388342AbgKZKr3 (ORCPT ); Thu, 26 Nov 2020 05:47:29 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC2CAC061A47 for ; Thu, 26 Nov 2020 02:47:28 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id u19so442361edx.2 for ; Thu, 26 Nov 2020 02:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z6hb7z/DWIkudEPm3vHYGG/k8WfnzjeNa9z9bipOSoo=; b=TezphtH3hj1KhCiOFtqlvZsJQjZmzMST0p+6BdJal3kHIE+/iYQ4dK0Qh/P8Yq4R8g KDNXJrONRhrVaOAAUVw5MUmYJ0TsESgxolRqj9zB8s0uh3AWdXPq7JgB1XKfrnTsTqIF bCI4CPV6h98QZopwAFC1vikP5M7gyT1wKZHCD6g4j3U40PdxM8ZrTxqubDdKK63v2JLF dtXD8lM4y3jUSt1furbMnGQwlseMS1/rdfiT1X0PKItWDjYQYJ6GUUTydT/f0pk/UBqo zbK8gIrR5Nax5SNJo5gz2Br98PBh4a0PZ2+8D9LJZ2K1bxYNvrYjB203JO+h/Xz7xswA qrdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z6hb7z/DWIkudEPm3vHYGG/k8WfnzjeNa9z9bipOSoo=; b=iVq4cPYpJLQ8r/bD2fvacAvsz/0pTsLCg8JRB6zajdEOzFplxrULhxTiJX6CS8WyHg YAjJJ4CTDxHMDFIJGlAxdahKyEnV4tf7pEETCe3b1KyYFJbnCtJdXPHdwgPtADodi2L+ Q8xOYB1oID7cWKg5AJFWkwDnxixgW1PvwOe10fVCE1CQzlCGpjxa5AZ3ncxz5C7epzZw WXua+9vKQ8ySerFrHUSUYrJLg5+i3KcZynYh2bltJMngoL8EALmBm//a++5ImaLtujAN vK1cb/Vs9v5BJEagebe/llI+co+SEKqo7abJ7uB7k2Zg1e1rrL1/j1yj2/e4OoVSh5sA oDfw== X-Gm-Message-State: AOAM530AOCS72CIK+QbxAU382zQfVTs0nqrSKE1w5xir6zChc8sSiYZU NkzxIIXT2ppoIt1R8bm9oyStTKXwakRDwQ== X-Google-Smtp-Source: ABdhPJxjCduv2Iy1x9DNI8UO3Ewtpg8qsG8FT/IV7Bja7s0p3sf0hwLh2c96ygPG9dx52UQMj/U4GA== X-Received: by 2002:a05:6402:1ac4:: with SMTP id ba4mr1884416edb.383.1606387647493; Thu, 26 Nov 2020 02:47:27 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:27 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Gioh Kim Subject: [PATCH for-next 3/8] Documentation/ABI/rnbd-clt: fix typo in sysfs-class-rnbd-client Date: Thu, 26 Nov 2020 11:47:18 +0100 Message-Id: <20201126104723.150674-4-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gioh Kim /sys/block/rnbd is created, not /sys/block/rnbd_client/rnbd Signed-off-by: Gioh Kim Signed-off-by: Jack Wang --- Documentation/ABI/testing/sysfs-class-rnbd-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-rnbd-client b/Documentation/ABI/testing/sysfs-class-rnbd-client index 00c0286733d4..ca3267b81886 100644 --- a/Documentation/ABI/testing/sysfs-class-rnbd-client +++ b/Documentation/ABI/testing/sysfs-class-rnbd-client @@ -66,7 +66,7 @@ Description: Expected format is the following:: The rnbd_server prepends the received from client with and tries to open the / block device. On success, - a /dev/rnbd device file, a /sys/block/rnbd_client/rnbd/ + a /dev/rnbd device file, a /sys/block/rnbd/ directory and an entry in /sys/class/rnbd-client/ctl/devices will be created. From patchwork Thu Nov 26 10:47:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A389C64E7A for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 302B320DD4 for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="CnWoSEng" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388342AbgKZKrb (ORCPT ); Thu, 26 Nov 2020 05:47:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388340AbgKZKra (ORCPT ); Thu, 26 Nov 2020 05:47:30 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D64A5C0613D4 for ; Thu, 26 Nov 2020 02:47:29 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id y4so1776276edy.5 for ; Thu, 26 Nov 2020 02:47:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X8yu13oIh/JXch52+JZCHnrSj26jPVrm5ONB1ko1hmI=; b=CnWoSEngNJgDdzaaG4hLtojTeGeo/LNkJ6HhOvHH7dd2xUmOUxcuw8dsptvfWLGDdN d0tyitpMpSZyzOOQm4L+bb7q54i5Nd5xc8/+qbfu5vMbfJhrCQf6dSz+4wKvQCZrkAtb 2WZQkYv+/bwd0WvZC7ztw1kQR7mp7ghIOXJ90+UGmGcijusMvd61MNMfqrGjjkhuwr6E 91T/e/h3rCNB86PbJWNmOQbjUMjAU+g5fsC2I9qAgyQ89KoVaZZEVOYQcTPdpZblmyCc evytewJEgi1UfqpunNWqLsCw+xlyM35smdPH7qBngo7Om6fW8brdtElFbImlPfdBssLD 9b0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X8yu13oIh/JXch52+JZCHnrSj26jPVrm5ONB1ko1hmI=; b=FZV1ZGF/R6rR42LRRowwKVJ3+AyOyWXOypRNeeqglqSUBW2/SRJ9u9F95fJJ2ndZmk YNQoemxdR/qCpeZoZnjG1M0+T1nKv47HGbVyk9JXuILzErqxuKwqK544e7hnYAj6xZ4S wC1/OXNfa8q2lrwgDfxVrksjcJq7+oB4Z4zhtmMmjkPdpZERzmPZ5z5ShdwcvlEo80wC xhHg6QvS87Q+vFd1ISUeEeo2WPOBWZheFv7DxJpi9ZqiaDiFDuG0NHiCS1zOzBtCQefR 5iVH4/D7xJFq1elWCKhfN7Iqa+1gHoSnij/74x4+u6dqW4kuN9GK+8FTWddMK2h1I51l +ybw== X-Gm-Message-State: AOAM533nayBbfmjntOaUKU9GTyuDU1t16I4oTXsjrdPap60S2uJcKtX/ HEAcZViO/iBmCpEKmJ4xJyuu4UKmX8LgWA== X-Google-Smtp-Source: ABdhPJwuFBL2g1I02Q62kidqcObfxhPUEeEohUJHmcwE2kWifTRNBp1Qmu5ZoP5+LlHcLq072AACvg== X-Received: by 2002:a50:f30f:: with SMTP id p15mr1984602edm.4.1606387648435; Thu, 26 Nov 2020 02:47:28 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:28 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Gioh Kim Subject: [PATCH for-next 4/8] Documentation/ABI/rnbd-clt: session name is appended to the device path Date: Thu, 26 Nov 2020 11:47:19 +0100 Message-Id: <20201126104723.150674-5-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gioh Kim When mapping a device, /sys/devices/virtual/rnbd-client/ctl/devices/ was created. But we found out that it had a problem when mapping the same file on different servers. So we append the session name after the device_id as below. /sys/devices/virtual/rnbd-client/ctl/devices/@ Signed-off-by: Gioh Kim Signed-off-by: Jack Wang --- Documentation/ABI/testing/sysfs-class-rnbd-client | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-rnbd-client b/Documentation/ABI/testing/sysfs-class-rnbd-client index ca3267b81886..2aa05b3e348e 100644 --- a/Documentation/ABI/testing/sysfs-class-rnbd-client +++ b/Documentation/ABI/testing/sysfs-class-rnbd-client @@ -95,12 +95,12 @@ Description: Expected format is the following:: --------------------------------- After mapping, the device file can be found by: - o The symlink /sys/class/rnbd-client/ctl/devices/ + o The symlink /sys/class/rnbd-client/ctl/devices/@ points to /sys/block/. The last part of the symlink destination is the same as the device name. By extracting the last part of the path the path to the device /dev/ can be build. - * /dev/block/$(cat /sys/class/rnbd-client/ctl/devices//dev) + * /dev/block/$(cat /sys/class/rnbd-client/ctl/devices/@/dev) How to find the of the device is described on the next section. @@ -110,7 +110,7 @@ Date: Feb 2020 KernelVersion: 5.7 Contact: Jack Wang Danil Kipnis Description: For each device mapped on the client a new symbolic link is created as - /sys/class/rnbd-client/ctl/devices/, which points + /sys/class/rnbd-client/ctl/devices/@, which points to the block device created by rnbd (/sys/block/rnbd/). The of each device is created as follows: From patchwork Thu Nov 26 10:47:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEA50C64E7C for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D0E52158C for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="Iww8gclc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388352AbgKZKrb (ORCPT ); Thu, 26 Nov 2020 05:47:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388341AbgKZKrb (ORCPT ); Thu, 26 Nov 2020 05:47:31 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EEEC0617A7 for ; Thu, 26 Nov 2020 02:47:30 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id a16so2259058ejj.5 for ; Thu, 26 Nov 2020 02:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nScNWpcvWCbr9GrL76w7aGhuZfbqsjrDUOvB71U8dg8=; b=Iww8gclc9LmTtuenEOthHM14L/k5WIoRTAk6KUaPwNV0L9C8AUtqPNjZd7Pp0JfbU2 /ovdkwyxkXy83L3IsoIw8/1SH+0v401h5+De5dXfjoZlLX2d1tiSp4N7Oro+LaAcnDeq JEe28b0/O/dTFYzVFQMap0ntRKW9MHd8+smQ1Lg2cvN0o/3O+7cIFfyofkGdmSpSSjNd aDB5qhi3km+GUOxMVvIE1+tjjIVIrEoOdFqCLPQjnCxVVdM/Ja3yCgoTK66E7WgGhop3 iF7g1QYfdGUjOYUkABWpblj7yLCsWSL4TOjs/38NoDYubjRQ6czxR0a8mzju0yTe51ui uqEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nScNWpcvWCbr9GrL76w7aGhuZfbqsjrDUOvB71U8dg8=; b=tX5rLrsnmyYWs9h7M0/XrjRkwtAidg8fA4h7R/KhCkX0uvT6lXouoBe3LwJXoNuPVx rqnU9j84wDkVrVhONR2eGU0ki9fwDZfi5aixKGfpmtaiPnX97FPxO7joBNteqHN7UMfN qDJhMBr16IMGqLAgn962CWIm1IwgRkm1UuHoF5WXn1JBBIXmk4r+ewdC2aOB29TUYabR gGzyHOeRRZVSgGBWendEMnqlf6wgT6MzXl3tvg07LJwhoP6hQyPwR62OJ2OuM4kPbiL2 QcN5EPpZyGWvZQoJe68hZdZTvekXImjsD9gnUAXikTpmWflfJt1f9fxuhRDRWJhZZop6 8uRg== X-Gm-Message-State: AOAM5334qmS2YfHBN1EFSShfVRThe7StDLHXhq7p3qqn4g1QcMdI9TU8 sqzeV3C6e7rqo20LQI0YmLtHjp1/1OBlow== X-Google-Smtp-Source: ABdhPJx60qB6RglE6+ICc0AAzUmB43Ch2I8WiLFqh2gVgdNB1+wwp990Tg6XnJR01n7gyQs98a2/JQ== X-Received: by 2002:a17:906:b18:: with SMTP id u24mr2126860ejg.501.1606387649335; Thu, 26 Nov 2020 02:47:29 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:28 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Lutz Pogrell , Gioh Kim Subject: [PATCH for-next 5/8] block/rnbd-srv: close a mapped device from server side. Date: Thu, 26 Nov 2020 11:47:20 +0100 Message-Id: <20201126104723.150674-6-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Lutz Pogrell The forceful close of an exported device is required for the use case, when the client side hangs, is crashed, or is not accessible. There have been cases observed, where only some of the devices are to be cleaned up, but the session shall remain. When the device is to be exported to a different client host, server side cleanup is required. Signed-off-by: Lutz Pogrell Reviewed-by: Gioh Kim Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-srv-sysfs.c | 38 ++++++++++++++++++++++++++++- drivers/block/rnbd/rnbd-srv.c | 19 +++++++++++++-- drivers/block/rnbd/rnbd-srv.h | 4 ++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c index 106775c074d1..08ffb492ebfa 100644 --- a/drivers/block/rnbd/rnbd-srv-sysfs.c +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c @@ -120,10 +120,46 @@ static ssize_t mapping_path_show(struct kobject *kobj, static struct kobj_attribute rnbd_srv_dev_session_mapping_path_attr = __ATTR_RO(mapping_path); +static ssize_t rnbd_srv_dev_session_force_close_show(struct kobject *kobj, + struct kobj_attribute *attr, char *page) +{ + return scnprintf(page, PAGE_SIZE, "Usage: echo 1 > %s\n", + attr->attr.name); +} + +static ssize_t rnbd_srv_dev_session_force_close_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct rnbd_srv_sess_dev *sess_dev; + + sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj); + + if (!sysfs_streq(buf, "1")) { + rnbd_srv_err(sess_dev, "%s: invalid value: '%s'\n", + attr->attr.name, buf); + return -EINVAL; + } + + rnbd_srv_info(sess_dev, "force close requested\n"); + + /* first remove sysfs itself to avoid deadlock */ + sysfs_remove_file_self(&sess_dev->kobj, &attr->attr); + rnbd_srv_sess_dev_force_close(sess_dev); + + return count; +} + +static struct kobj_attribute rnbd_srv_dev_session_force_close_attr = + __ATTR(force_close, 0644, + rnbd_srv_dev_session_force_close_show, + rnbd_srv_dev_session_force_close_store); + static struct attribute *rnbd_srv_default_dev_sessions_attrs[] = { &rnbd_srv_dev_session_access_mode_attr.attr, &rnbd_srv_dev_session_ro_attr.attr, &rnbd_srv_dev_session_mapping_path_attr.attr, + &rnbd_srv_dev_session_force_close_attr.attr, NULL, }; @@ -145,7 +181,7 @@ static void rnbd_srv_sess_dev_release(struct kobject *kobj) struct rnbd_srv_sess_dev *sess_dev; sess_dev = container_of(kobj, struct rnbd_srv_sess_dev, kobj); - rnbd_destroy_sess_dev(sess_dev); + rnbd_destroy_sess_dev(sess_dev, sess_dev->keep_id); } static struct kobj_type rnbd_srv_sess_dev_ktype = { diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index e1bc8b4cd592..d1ee72ed8384 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -212,12 +212,20 @@ static void rnbd_put_srv_dev(struct rnbd_srv_dev *dev) kref_put(&dev->kref, destroy_device_cb); } -void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev) +void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) { DECLARE_COMPLETION_ONSTACK(dc); - xa_erase(&sess_dev->sess->index_idr, sess_dev->device_id); + if (keep_id) + /* free the resources for the id but don't */ + /* allow to re-use the id itself because it */ + /* is still used by the client */ + xa_cmpxchg(&sess_dev->sess->index_idr, sess_dev->device_id, + sess_dev, NULL, 0); + else + xa_erase(&sess_dev->sess->index_idr, sess_dev->device_id); synchronize_rcu(); + sess_dev->destroy_comp = &dc; rnbd_put_sess_dev(sess_dev); wait_for_completion(&dc); /* wait for inflights to drop to zero */ @@ -328,6 +336,13 @@ static int rnbd_srv_link_ev(struct rtrs_srv *rtrs, } } +void rnbd_srv_sess_dev_force_close(struct rnbd_srv_sess_dev *sess_dev) +{ + rnbd_srv_destroy_dev_session_sysfs(sess_dev); + sess_dev->keep_id = true; + +} + static int process_msg_close(struct rtrs_srv *rtrs, struct rnbd_srv_session *srv_sess, void *data, size_t datalen, const void *usr, diff --git a/drivers/block/rnbd/rnbd-srv.h b/drivers/block/rnbd/rnbd-srv.h index 5a8544b5e74f..b157371c25ed 100644 --- a/drivers/block/rnbd/rnbd-srv.h +++ b/drivers/block/rnbd/rnbd-srv.h @@ -56,6 +56,7 @@ struct rnbd_srv_sess_dev { struct rnbd_srv_dev *dev; struct kobject kobj; u32 device_id; + bool keep_id; fmode_t open_flags; struct kref kref; struct completion *destroy_comp; @@ -63,6 +64,7 @@ struct rnbd_srv_sess_dev { enum rnbd_access_mode access_mode; }; +void rnbd_srv_sess_dev_force_close(struct rnbd_srv_sess_dev *sess_dev); /* rnbd-srv-sysfs.c */ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, @@ -73,6 +75,6 @@ int rnbd_srv_create_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev); void rnbd_srv_destroy_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev); int rnbd_srv_create_sysfs_files(void); void rnbd_srv_destroy_sysfs_files(void); -void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev); +void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id); #endif /* RNBD_SRV_H */ From patchwork Thu Nov 26 10:47:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BEA1C64E7B for ; Thu, 26 Nov 2020 10:47:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8AB920DD4 for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="Lc+W67Hr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388341AbgKZKrc (ORCPT ); Thu, 26 Nov 2020 05:47:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388340AbgKZKrb (ORCPT ); Thu, 26 Nov 2020 05:47:31 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 931E7C0613D4 for ; Thu, 26 Nov 2020 02:47:31 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id d17so342826ejy.9 for ; Thu, 26 Nov 2020 02:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LoZdjc+EEym8aqHt4kiTDOTP1U08c51WASyvgO99dkc=; b=Lc+W67HrjUAN0y+dJrInUdaNYqCoXPhcTUhclxy+/ViGaYNNngChrEjXO95JusyQv1 sPJVf9qE33z55eRoWLsWuEns7IKH8vt4dEZ+sCGrc8PYcN2qthVlYblS8U2BgKI72s3i ptWW0938fgaMl8l6jBEpQHBirw5XLpSJw6xVEgq59pP3FMrXh8DtJG3G+46wXitpC5mz btijiA5URyhDVdxJuBnBRDZ0Tq2vZhCSfyGEkW3/LJVT9ESuWRRVVJz0nkJkHCDXH4IK zv0xhgag+uYx2OkS32EjhTT+Niv82o8eglzi29ieiaNfqu1mLPBixx2BYeITfQ7EG4It JiNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LoZdjc+EEym8aqHt4kiTDOTP1U08c51WASyvgO99dkc=; b=RNUXDOCjo5xGYdfUidnZMv3pwABAWQmX2WibbU6ZN9G+m9En7DNLTE44vBzTYf/hpR hFyKHrJGofp4EGN621Dj8HYOodpyszwYFi4D4gN1ZSkLlhTlladpp7/+4wD7WjOwHCia GtOQ9ayPcmi0AhV6rT+jVRsT3UXrKd7V3NZosLJkjq4FMEKJjYyI8syIL85cyEWaMylU hdfjAawe/+Rvs9imk5l22BVDSUU2lWK/IIPZHL6jClJhYonWRttoexJ+EHOts6UZbUj2 MuGGnHuXiuMaotYLtCumhorzCFkC2giUbcCoowuRhy4Dx+zB8GiaBVlk4mya83RFBgkP 6EKA== X-Gm-Message-State: AOAM5320RZPMOctKkoRYB2quAbLZjXb4b/2hfja0Nyem0BlFOIMGuxU7 WJ6jhkrxSH4d+R3BQXUzcw0oh7V/l94X4A== X-Google-Smtp-Source: ABdhPJxmJ/4CVN+23ANkNxVHaDnY1UrCMVspZBvkJbWgZ5JZHq0+rr55ym5yzjmcCUMvqDwUk3r6vw== X-Received: by 2002:a17:906:604e:: with SMTP id p14mr2126458ejj.515.1606387650148; Thu, 26 Nov 2020 02:47:30 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:29 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com Subject: [PATCH for-next 6/8] Documentation/ABI/rnbd-srv: add document for force_close Date: Thu, 26 Nov 2020 11:47:21 +0100 Message-Id: <20201126104723.150674-7-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org describe force_close of device Signed-off-by: Jack Wang --- Documentation/ABI/testing/sysfs-class-rnbd-server | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-rnbd-server b/Documentation/ABI/testing/sysfs-class-rnbd-server index ba60a90c0e45..6c5996cd7cfb 100644 --- a/Documentation/ABI/testing/sysfs-class-rnbd-server +++ b/Documentation/ABI/testing/sysfs-class-rnbd-server @@ -48,3 +48,11 @@ Date: Feb 2020 KernelVersion: 5.7 Contact: Jack Wang Danil Kipnis Description: Contains the device access mode: ro, rw or migration. + +What: /sys/class/rnbd-server/ctl/devices//sessions//force_close +Date: Nov 2020 +KernelVersion: 5.10 +Contact: Jack Wang Danil Kipnis +Description: Write "1" to the file to close the device on server side. Please + note that the client side device will not be closed, read or + write to the device will get -ENOTCONN. From patchwork Thu Nov 26 10:47:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7880EC64E8A for ; Thu, 26 Nov 2020 10:47:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 370DA21D40 for ; Thu, 26 Nov 2020 10:47:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="EPdz6+Cw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388360AbgKZKre (ORCPT ); Thu, 26 Nov 2020 05:47:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388371AbgKZKre (ORCPT ); Thu, 26 Nov 2020 05:47:34 -0500 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8679AC0613D4 for ; Thu, 26 Nov 2020 02:47:32 -0800 (PST) Received: by mail-ej1-x641.google.com with SMTP id mc24so2253671ejb.6 for ; Thu, 26 Nov 2020 02:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=89v079U432pNB380YF5DCvbaMnPCcXZlFPoWl982ARA=; b=EPdz6+CwHOo3zXI3fcS+IB/TmT0SbtM6X+1QcHJxTOSCKFZzapNrQUIbIS40BLnbPL U7KU3jDWhwe6rjLAar55z05bbtrihbMXwkFGLdVcEfxEMlI8k3qOaN+wIZuC1XG7iqvX I/QUoOKYdkwu+ReWqjlQJ4qXSWT3ZlukgYAlwNPyjDKwZ3+/ShY8UXDiK99OpyvfrnIH Vvu5f7H8ttlBs+LVTRZ1eijvgd74Kss0wu3e8BP6gxjx1k7DEFTmeiBP/mfIJTsZ1pDF hLemGCxQKUPJkSupCWsdRVI1PzViuaxsGF6Lj6q9JvLPm5muKQmqXgamrouPncmNZf/T VCyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=89v079U432pNB380YF5DCvbaMnPCcXZlFPoWl982ARA=; b=XUyUxlR1I1eQoeg1FA5p00Y+uJIJEvQw2dhxZjuQEZ2wdyiABQ1WFf77L+hmOHl2DU N7Now6N4k9jdJHqNNhEA2jSbehxNUg/hAF+So8lO+vNvLFE2C2MuFvSnn2QtWqcHAG9H 9paiVeiNhv+8bfRhbhdfZIge1jYb4uB+DPdA4k8L7NxZywbNDMk+7On3JyP3TwQ6kd0i 1QbcuRqa1iptx3lRiBYOBBl732SF13FOhNXYP/7tnDx7sPky/wkBoDrT8ICcvae54bjz gl1Xqz+BXa9D0R2//EZeyPt9+ou95ULjuLo/HRaIKaUNMWYHYGhsOQXlth28soKVuG+k yePQ== X-Gm-Message-State: AOAM533DmUZ3laTnendj70hus9z9pa9w8OGQOHsJMJXpyCh0/rFa2vCd znfsjAR4A2lTPHO6HTBbaavK4mgKr2w8zA== X-Google-Smtp-Source: ABdhPJxlFirjF1XPWyzEcppZ9gGDiwRGfqAILNnQztMw76Pp693hYyJ7H4WF7FE0gmE5OUiTJ5lqhg== X-Received: by 2002:a17:906:b53:: with SMTP id v19mr2118147ejg.250.1606387651154; Thu, 26 Nov 2020 02:47:31 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:30 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Guoqing Jiang , Md Haris Iqbal Subject: [PATCH for-next 7/8] block/rnbd: call kobject_put in the failure path Date: Thu, 26 Nov 2020 11:47:22 +0100 Message-Id: <20201126104723.150674-8-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Guoqing Jiang Per the comment of kobject_init_and_add, we need to cleanup the memory by call kobject_put. Also we need to call kobject_del for the other failure cases if the kobject_init_and_add doesn't fail. Signed-off-by: Guoqing Jiang Reviewed-by: Md Haris Iqbal Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt-sysfs.c | 4 +++- drivers/block/rnbd/rnbd-srv-sysfs.c | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index 5d3c3c80dab4..e3c3270b0cee 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -450,9 +450,11 @@ static int rnbd_clt_add_dev_kobj(struct rnbd_clt_dev *dev) ret = kobject_init_and_add(&dev->kobj, &rnbd_dev_ktype, gd_kobj, "%s", "rnbd"); - if (ret) + if (ret) { rnbd_clt_err(dev, "Failed to create device sysfs dir, err: %d\n", ret); + kobject_put(&dev->kobj); + } return ret; } diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c index 08ffb492ebfa..05ffe488ddc6 100644 --- a/drivers/block/rnbd/rnbd-srv-sysfs.c +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c @@ -47,13 +47,17 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, ret = kobject_init_and_add(&dev->dev_kobj, &dev_ktype, rnbd_devs_kobj, dev_name); - if (ret) + if (ret) { + kobject_put(&dev->dev_kobj); return ret; + } dev->dev_sessions_kobj = kobject_create_and_add("sessions", &dev->dev_kobj); - if (!dev->dev_sessions_kobj) - goto put_dev_kobj; + if (!dev->dev_sessions_kobj) { + ret = -ENOMEM; + goto free_dev_kobj; + } bdev_kobj = &disk_to_dev(bdev->bd_disk)->kobj; ret = sysfs_create_link(&dev->dev_kobj, bdev_kobj, "block_dev"); @@ -64,7 +68,8 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, put_sess_kobj: kobject_put(dev->dev_sessions_kobj); -put_dev_kobj: +free_dev_kobj: + kobject_del(&dev->dev_kobj); kobject_put(&dev->dev_kobj); return ret; } @@ -196,18 +201,17 @@ int rnbd_srv_create_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev) ret = kobject_init_and_add(&sess_dev->kobj, &rnbd_srv_sess_dev_ktype, sess_dev->dev->dev_sessions_kobj, "%s", sess_dev->sess->sessname); - if (ret) + if (ret) { + kobject_put(&sess_dev->kobj); return ret; + } ret = sysfs_create_group(&sess_dev->kobj, &rnbd_srv_default_dev_session_attr_group); - if (ret) - goto err; - - return 0; - -err: - kobject_put(&sess_dev->kobj); + if (ret) { + kobject_del(&sess_dev->kobj); + kobject_put(&sess_dev->kobj); + } return ret; } From patchwork Thu Nov 26 10:47:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11933205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59972C64E7D for ; Thu, 26 Nov 2020 10:47:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFA9721527 for ; Thu, 26 Nov 2020 10:47:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cloud.ionos.com header.i=@cloud.ionos.com header.b="QSRGZm4L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388368AbgKZKre (ORCPT ); Thu, 26 Nov 2020 05:47:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388360AbgKZKrd (ORCPT ); Thu, 26 Nov 2020 05:47:33 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75F34C0617A7 for ; Thu, 26 Nov 2020 02:47:33 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id k4so1812562edl.0 for ; Thu, 26 Nov 2020 02:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4cvh6HyOuMNhHZbDU7N8V5pKfLuDMvs/XUaQs3r6Mgo=; b=QSRGZm4LWcLrV18IP8RyMgz8YSZ1BOaXwqudeV3nmtr/yyHNO3HwkN1zbHbuPzPgAx ifmg+7LH9YKC+v902Xzt/6RYPr3dxQdVQfMDPil5iv21N381eLSrz5N6iGhihJflyRhs LMu6yCW676GrRofZ7HTU83iFeTKN9D13ZuHrI/pRXRHYKci2XHlTH94702fIM6gXEm8G HOrUaYFAktNrb4tuBX1Xz9ypiD6+ZZtFuxkzs9T/75LXPtu3UY2DoO5lYnkKlhLwJ5NS m4JojMtRoLgR85luuHeAKogCbl1VItLPKkWAUOvLBNpMyZz3L31+EimWKdw1pTZU7YWB Sn6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4cvh6HyOuMNhHZbDU7N8V5pKfLuDMvs/XUaQs3r6Mgo=; b=tcKKxwOK7nekuacfDAtEFoHP093PMpGmTG6FQ0b3RkO/0aOxwioWkxHpLSyfV8evAw RKg+UkLi0GdUPb6ONz7kSNBO9zzU5n8VfKg7g1VmCOThvhuUDS95a8vC6uyyQO8tmecj /VLSRfFUuvMhEnpKieKCYRN1mjG6jeVxpktgEnFMEQVs8tNJIvCd2fBT7EhWJEp62C9o TlFdBmPGkSde9NBMDTob5oogd5D9B3kz986YljC5F8SK8z0F6LRTp0MvD87jWR+h9ofB Ii/banv9DsZUfZ2YW7Ju87EOhqJIj2VlzBOodiO3jvNe/NefXED81P1a4Qof6sMGTZqx dQsw== X-Gm-Message-State: AOAM53381DkhQSG+sLoWORAeME2DmrCZZEdcx2PGIy/CD6IO2qcI4PKj qWssPaa1OCVwRsmWSiRylAnKXRCAyYTl0Q== X-Google-Smtp-Source: ABdhPJztqAjyBMAx1ImaIT5o/MfvoiimNXM1RYHKOOUyjR6fl/9GRChdDtF4kuTkESvXsz4/h/fMjg== X-Received: by 2002:a05:6402:176e:: with SMTP id da14mr1907624edb.245.1606387652067; Thu, 26 Nov 2020 02:47:32 -0800 (PST) Received: from jwang-Latitude-5491.fritz.box ([2001:16b8:4961:8400:6960:35a2:747a:e0ad]) by smtp.gmail.com with ESMTPSA id f19sm2910053edm.70.2020.11.26.02.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Nov 2020 02:47:31 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Md Haris Iqbal , Lutz Pogrell Subject: [PATCH for-next 8/8] block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name Date: Thu, 26 Nov 2020 11:47:23 +0100 Message-Id: <20201126104723.150674-9-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> References: <20201126104723.150674-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Md Haris Iqbal For every rnbd_clt_dev, we alloc the pathname and blk_symlink_name statically to NAME_MAX which is 255 bytes. In most of the cases we only need less than 10 bytes, so 500 bytes per block device are wasted. This commit dynamically allocates memory buffer for pathname and blk_symlink_name. Signed-off-by: Md Haris Iqbal Reviewed-by: Lutz Pogrell Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt-sysfs.c | 12 ++++++++++-- drivers/block/rnbd/rnbd-clt.c | 14 +++++++++++--- drivers/block/rnbd/rnbd-clt.h | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index e3c3270b0cee..c3c96a567568 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -434,6 +434,7 @@ void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev) */ if (strlen(dev->blk_symlink_name) && try_module_get(THIS_MODULE)) { sysfs_remove_link(rnbd_devs_kobj, dev->blk_symlink_name); + kfree(dev->blk_symlink_name); module_put(THIS_MODULE); } } @@ -492,10 +493,17 @@ static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf, static int rnbd_clt_add_dev_symlink(struct rnbd_clt_dev *dev) { struct kobject *gd_kobj = &disk_to_dev(dev->gd)->kobj; - int ret; + int ret, len; + + len = strlen(dev->pathname) + strlen(dev->sess->sessname) + 2; + dev->blk_symlink_name = kzalloc(len, GFP_KERNEL); + if (!dev->blk_symlink_name) { + rnbd_clt_err(dev, "Failed to allocate memory for blk_symlink_name\n"); + goto out_err; + } ret = rnbd_clt_get_path_name(dev, dev->blk_symlink_name, - sizeof(dev->blk_symlink_name)); + len); if (ret) { rnbd_clt_err(dev, "Failed to get /sys/block symlink path, err: %d\n", ret); diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index 1bb495e50931..34bc6083b58d 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -59,6 +59,7 @@ static void rnbd_clt_put_dev(struct rnbd_clt_dev *dev) ida_simple_remove(&index_ida, dev->clt_device_id); mutex_unlock(&ida_lock); kfree(dev->hw_queues); + kfree(dev->pathname); rnbd_clt_put_sess(dev->sess); mutex_destroy(&dev->lock); kfree(dev); @@ -1387,10 +1388,17 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess, pathname, sess->sessname, ret); goto out_queues; } + + dev->pathname = kzalloc(strlen(pathname) + 1, GFP_KERNEL); + if (!dev->pathname) { + ret = -ENOMEM; + goto out_queues; + } + strlcpy(dev->pathname, pathname, strlen(pathname) + 1); + dev->clt_device_id = ret; dev->sess = sess; dev->access_mode = access_mode; - strlcpy(dev->pathname, pathname, sizeof(dev->pathname)); mutex_init(&dev->lock); refcount_set(&dev->refcount, 1); dev->dev_state = DEV_STATE_INIT; @@ -1422,8 +1430,8 @@ static bool __exists_dev(const char *pathname, const char *sessname) continue; mutex_lock(&sess->lock); list_for_each_entry(dev, &sess->devs_list, list) { - if (!strncmp(dev->pathname, pathname, - sizeof(dev->pathname))) { + if (strlen(dev->pathname) == strlen(pathname) && + !strcmp(dev->pathname, pathname)) { found = true; break; } diff --git a/drivers/block/rnbd/rnbd-clt.h b/drivers/block/rnbd/rnbd-clt.h index ed33654aa486..b193d5904050 100644 --- a/drivers/block/rnbd/rnbd-clt.h +++ b/drivers/block/rnbd/rnbd-clt.h @@ -108,7 +108,7 @@ struct rnbd_clt_dev { u32 clt_device_id; struct mutex lock; enum rnbd_clt_dev_state dev_state; - char pathname[NAME_MAX]; + char *pathname; enum rnbd_access_mode access_mode; bool read_only; bool rotational; @@ -126,7 +126,7 @@ struct rnbd_clt_dev { struct list_head list; struct gendisk *gd; struct kobject kobj; - char blk_symlink_name[NAME_MAX]; + char *blk_symlink_name; refcount_t refcount; struct work_struct unmap_on_rmmod_work; };