From patchwork Tue Jun 8 04:35:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 457267 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=-17.4 required=3.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIMWL_WL_HIGH,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=unavailable 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 E2F79C48BE8 for ; Tue, 8 Jun 2021 11:36:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6CD760FF4 for ; Tue, 8 Jun 2021 11:36:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232038AbhFHLid (ORCPT ); Tue, 8 Jun 2021 07:38:33 -0400 Received: from relay.smtp-ext.broadcom.com ([192.19.11.229]:43242 "EHLO relay.smtp-ext.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbhFHLiX (ORCPT ); Tue, 8 Jun 2021 07:38:23 -0400 Received: from localhost.localdomain (unknown [10.157.2.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay.smtp-ext.broadcom.com (Postfix) with ESMTPS id 818257DA5; Tue, 8 Jun 2021 04:28:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 818257DA5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1623151691; bh=Wy3HFS2mlfDKO2qx6LudwME4QNrPKmQJ6PqsNZG0L7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/ov7bscAn4P+vE4sT/+zbpcVODa5XbTJzIAZH7rfLzBxXte1LLFsnwaeyHBCXN4b 98ySIZfZOIrwZABuaHt//usdx371VQdDZcGO6OpzNKClP3UUHSB3YhYDqf/LIhIzNP XfkNkYAS7ZRxwE35tWQLOOr6Y7wLEQWuzGJZNLaI= From: Muneendra Kumar To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, tj@kernel.org, linux-nvme@lists.infradead.org, hare@suse.de Cc: jsmart2021@gmail.com, emilne@redhat.com, mkumar@redhat.com, Muneendra , Himanshu Madhani Subject: [PATCH v11 03/13] nvme: Added a newsysfs attribute appid_store Date: Tue, 8 Jun 2021 10:05:46 +0530 Message-Id: <20210608043556.274139-4-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210608043556.274139-1-muneendra.kumar@broadcom.com> References: <20210608043556.274139-1-muneendra.kumar@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Muneendra 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 Reviewed-by: Himanshu Madhani Reviewed-by: Hannes Reinecke Signed-off-by: Muneendra --- v11: No change v10: No change v9: No change v8: No change v7: No change v6: No change v5: Replaced APPID_LEN with FC_APPID_LEN v4: No change v3: Replaced blkcg_set_app_identifier function with blkcg_set_fc_appid 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 d9ab9e7871d0..57baddfe208b 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 @@ -3787,10 +3787,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[FC_APPID_LEN]; + int ret = 0; + + if (buf[count-1] == '\n') + count--; + + if ((count > (16+1+FC_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 > FC_APPID_LEN) + return -EINVAL; + + memset(app_id, 0x0, sizeof(app_id)); + memcpy(app_id, &buf[cgrpid_len+1], appid_len); + ret = blkcg_set_fc_appid(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 };