From patchwork Tue Dec 22 00:11:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 346840 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.2 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_NONE, 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 89286C433DB for ; Tue, 22 Dec 2020 07:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62E0C2312E for ; Tue, 22 Dec 2020 07:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726012AbgLVHGO (ORCPT ); Tue, 22 Dec 2020 02:06:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725953AbgLVHGO (ORCPT ); Tue, 22 Dec 2020 02:06:14 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD41C061248 for ; Mon, 21 Dec 2020 23:05:07 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id n3so958064pjm.1 for ; Mon, 21 Dec 2020 23:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bj0ywLX1Dytm3bNGxLBpKQt6mxKZvvcyYt5wumiQIoc=; b=OmBxd7jIGSGGSZNo6SlV72f8QuQVV2lx67x9V+skFVSxucjDWQeklU9mS/dyMMcT6L tINC2loRxccwWnbd+kx5n25bhv0XE8XSUxVCDqvau1QAbEE3zKWh+4ziFaoLxLlyhT0w WSosBmV0b7wdB0IsWV5N++TdYdaY0wziW7agw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references; bh=bj0ywLX1Dytm3bNGxLBpKQt6mxKZvvcyYt5wumiQIoc=; b=UFkfs5IqK0pBJgoovl0F1kGpOULaREi91PtmPLFYpwe9haFPU9GUX5FVDOVKbJPTBu gBEqxnhiA4h8c+5nNseNDkjbb3pAaacmL50dXeXpM/qUkqxqy3uKpO3yQSjXPK4GIgmv x6FIxDQ4PmwZov4u3lap8Fh83zEOUG63JYxMj2yLyl7Fu2YrUaKrXCkuHuQ/E8Cr+BGe Dnf4i3OrENaVvruZ8ZrThAugea0jrRcxmnUzM/gT0utsLQl1iYbUtBwIt6UCz0svYYqQ iHIoR5fsyY/KPEtta0LK0x62EypVbVT9uzRdSOPJc0WonvG9eOlWXMifI3ofcO4TXiqF SLuA== MIME-Version: 1.0 X-Gm-Message-State: AOAM530raX1pM8AmpVa3AKng6POGIl4vT+q10KHkA7ErGIU/8mL7aUFn JxpKWSaFGZpR3funniXybnbtls+/cypucvRC+nFYsmyapcEEt1l1ENAIqKrBoQILuuzI4PYi8bs Na0m3TnHRT1nDM8xXB5+BCHc= X-Google-Smtp-Source: ABdhPJxx1NX/ek7yHJ7HcWijunOIdc836ANIwX7IqNadXAWsM3cVonIDAaFgrPXK590UbvLiA3GrBw== X-Received: by 2002:a17:90a:ba88:: with SMTP id t8mr20697707pjr.229.1608620706848; Mon, 21 Dec 2020 23:05:06 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id t9sm12466082pgh.41.2020.12.21.23.05.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 23:05:05 -0800 (PST) From: Muneendra 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, pbonzini@redhat.com, Muneendra Subject: [PATCH v6 03/16] nvme: Added a newsysfs attribute appid_store Date: Tue, 22 Dec 2020 05:41:45 +0530 Message-Id: <1608595918-21954-4-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1608595918-21954-1-git-send-email-muneendra.kumar@broadcom.com> References: <1608595918-21954-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 --- 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 3c002bdcace3..ed689ba773b1 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 @@ -3821,10 +3821,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 };