From patchwork Mon Oct 19 07:42:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar M X-Patchwork-Id: 11844487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1558B1580 for ; Mon, 19 Oct 2020 14:36:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E373B222E7 for ; Mon, 19 Oct 2020 14:36:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="IaitxpAe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729539AbgJSOgw (ORCPT ); Mon, 19 Oct 2020 10:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729493AbgJSOgw (ORCPT ); Mon, 19 Oct 2020 10:36:52 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D64C0613CE for ; Mon, 19 Oct 2020 07:36:52 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id e7so46686pfn.12 for ; Mon, 19 Oct 2020 07:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jab7UiBrSBcDJgJGPi3vgYoEAB2gbCP7BwMD0y+Jt7A=; b=IaitxpAePj2EdF/gbaY0p0aPhbkgFC+nlbJCjsUkLwLMYi7n0R7I3sjRbE5XNJLskg 7qYIoVt1FErM42U4PP4wPuKtabMik6er1ZoGTzmh8VkMP+z/uIFk1CXPIW81O1ekamup 1ujf8UIETkHYDohSY/6tXail8QLAvtTBfMr/8= 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; bh=Jab7UiBrSBcDJgJGPi3vgYoEAB2gbCP7BwMD0y+Jt7A=; b=kA+7jsIpROsfPAaAOJOH2ahEcT+fu0nim6L2nEI6SlheyQnWqDmo3vzBgY6C6MHa2U /l1q0+ESWr1taZurF/399BDRSKtKrdNnPXxPgg8LauJPVvbc+lG9/kiRCyEt/15ILTFO tFL4M66HPptdBH6Wdwn8LIssmdXCm6+NslQizhb9jiGthw6DtJvcy82USP/KWpo3bBQ4 AitY9sFz4W105Ki9zfNd1nS6dadfBH1S8/QJfDvWp53N05zOtD2cFnQF6zQBUtiCIuyr 9ya1LZRh1qdiKZJp+aXepbl5mAoU7OK3pcFMItGgO7j4o4BaEMv1h+xTUFplR1pm8Uba ZyDA== X-Gm-Message-State: AOAM5326EhctK6iLyFHknTisHR/iDm9JBxwHOEay2URYpK4mELJn5qgx XQJtBuQElnkpG0Vq26knjXuNaRG9ldirmNiC X-Google-Smtp-Source: ABdhPJwmmk6blB8qpEr0fgye8elVjKECa5Jt8AW2N5FEUas8YJvglKJJdr5eGngTsk9qfu5RZWvxoA== X-Received: by 2002:aa7:9e05:0:b029:158:ca8c:fe36 with SMTP id y5-20020aa79e050000b0290158ca8cfe36mr17679134pfq.62.1603118211789; Mon, 19 Oct 2020 07:36:51 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id kb15sm53377pjb.17.2020.10.19.07.36.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 07:36:51 -0700 (PDT) From: Muneendra To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, tj@kernel.org, linux-nvme@lists.infradead.org Cc: jsmart2021@gmail.com, emilne@redhat.com, mkumar@redhat.com, pbonzini@redhat.com, Muneendra Subject: [RFC v2 03/18] nvme: Added a newsysfs attribute appid_store Date: Mon, 19 Oct 2020 13:12:58 +0530 Message-Id: <1603093393-12875-4-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603093393-12875-1-git-send-email-muneendra.kumar@broadcom.com> References: <1603093393-12875-1-git-send-email-muneendra.kumar@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Added a new sysfs attribute appid_store under /sys/class/fc/fc_udev_device/* With this new interface the user can set the application identfier in the blkcg associted with cgroup id. Once the application identifer has set with this interface it allows identification of traffic sources at an individual cgroup based Applications (ex:virtual machine (VM))level in both host and fabric infrastructure(FC). Below is the interface provided to set the app_id echo ":" >> /sys/class/fc/fc_udev_device/appid_store echo "457E:100000109b521d27" >> /sys/class/fc/fc_udev_device/appid_store Signed-off-by: Muneendra --- v2: New Patch --- drivers/nvme/host/fc.c | 73 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index eae43bb444e0..6d6cc06fd54a 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -9,7 +9,7 @@ #include #include #include - +#include #include "nvme.h" #include "fabrics.h" #include @@ -3768,10 +3768,81 @@ static ssize_t nvme_fc_nvme_discovery_store(struct device *dev, return count; } + +/*parse the Cgroup id from a buf and returns the length of cgrpid*/ +static int fc_parse_cgrpid(const char *buf, u64 *id) +{ + char cgrp_id[16+1]; + int cgrpid_len, j; + + memset(cgrp_id, 0x0, sizeof(cgrp_id)); + for (cgrpid_len = 0, j = 0; cgrpid_len < 17; cgrpid_len++) { + if (buf[cgrpid_len] != ':') + cgrp_id[cgrpid_len] = buf[cgrpid_len]; + else { + j = 1; + break; + } + } + if (!j) + return -EINVAL; + if (kstrtou64(cgrp_id, 16, id) < 0) + return -EINVAL; + return cgrpid_len; +} + +/* + * fc_update_appid :parses and updates the appid in the blkcg associated with + * cgroupid. + * @buf: buf contains both cgrpid and appid info + * @count: size of the buffer + */ +static int fc_update_appid(const char *buf, size_t count) +{ + u64 cgrp_id; + int appid_len = 0; + int cgrpid_len = 0; + char app_id[APPID_LEN]; + int ret = 0; + + if (buf[count-1] == '\n') + count--; + + if ((count > (16+1+APPID_LEN)) || (!strchr(buf, ':'))) + return -EINVAL; + + cgrpid_len = fc_parse_cgrpid(buf, &cgrp_id); + if (cgrpid_len < 0) + return -EINVAL; + /*appid len is count - cgrpid_len -1 (: + \n) */ + appid_len = count - cgrpid_len - 1; + if (appid_len > APPID_LEN) + return -EINVAL; + + memset(app_id, 0x0, sizeof(app_id)); + memcpy(app_id, &buf[cgrpid_len+1], appid_len); + ret = blkcg_set_app_identifier(app_id, cgrp_id, sizeof(app_id)); + if (ret < 0) + return ret; + return count; +} + +static ssize_t fc_appid_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int ret = 0; + + ret = fc_update_appid(buf, count); + if (ret < 0) + return -EINVAL; + return count; +} static DEVICE_ATTR(nvme_discovery, 0200, NULL, nvme_fc_nvme_discovery_store); +static DEVICE_ATTR(appid_store, 0200, NULL, fc_appid_store); static struct attribute *nvme_fc_attrs[] = { &dev_attr_nvme_discovery.attr, + &dev_attr_appid_store.attr, NULL };