From patchwork Mon Sep 30 18:54:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11167135 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 A3ABF16C1 for ; Mon, 30 Sep 2019 18:59:55 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8C361224F0 for ; Mon, 30 Sep 2019 18:59:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C361224F0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 1E4CE5C3FDE; Mon, 30 Sep 2019 11:58:31 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp4.ccs.ornl.gov (smtp4.ccs.ornl.gov [160.91.203.40]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 3814A5C3AE2 for ; Mon, 30 Sep 2019 11:57:09 -0700 (PDT) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp4.ccs.ornl.gov (Postfix) with ESMTP id 91C5E100543A; Mon, 30 Sep 2019 14:56:56 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 8F1C7B4; Mon, 30 Sep 2019 14:56:56 -0400 (EDT) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Mon, 30 Sep 2019 14:54:54 -0400 Message-Id: <1569869810-23848-36-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1569869810-23848-1-git-send-email-jsimmons@infradead.org> References: <1569869810-23848-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 035/151] lustre: jobstats: move jobstats code into separate file. X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Ben Evans We'll be enhancing jobstats in future patches. To make that easier, move the jobstats code into a separate file. Note: the OpenSFS version of this patch added a hash table to cache content read from the environment, but we don't use environment values in this branch. WC-bug-id: https://jira.whamcloud.com/browse/LU-9221 Lustre-commit: 08479b74ec35 ("LU-9221 jobstats: Create a pid-based hash for jobid values") Signed-off-by: Ben Evans Reviewed-on: https://review.whamcloud.com/25208 Reviewed-by: Andreas Dilger Reviewed-by: Andrew Perepechko Reviewed-by: Oleg Drokin Signed-off-by: NeilBrown Signed-off-by: James Simmons --- fs/lustre/obdclass/Makefile | 3 +- fs/lustre/obdclass/class_obd.c | 43 --------------------- fs/lustre/obdclass/jobid.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 fs/lustre/obdclass/jobid.c diff --git a/fs/lustre/obdclass/Makefile b/fs/lustre/obdclass/Makefile index a8f30ee..96fce1b 100644 --- a/fs/lustre/obdclass/Makefile +++ b/fs/lustre/obdclass/Makefile @@ -7,4 +7,5 @@ obdclass-y := llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o \ genops.o obd_sysfs.o lprocfs_status.o lprocfs_counters.o \ lustre_handles.o lustre_peer.o statfs_pack.o linkea.o \ obdo.o obd_config.o obd_mount.o lu_object.o lu_ref.o \ - cl_object.o cl_page.o cl_lock.o cl_io.o kernelcomm.o + cl_object.o cl_page.o cl_lock.o cl_io.o kernelcomm.o \ + jobid.o diff --git a/fs/lustre/obdclass/class_obd.c b/fs/lustre/obdclass/class_obd.c index d8fc0db..8b6032a 100644 --- a/fs/lustre/obdclass/class_obd.c +++ b/fs/lustre/obdclass/class_obd.c @@ -76,49 +76,6 @@ int at_extra = 30; EXPORT_SYMBOL(at_extra); -char obd_jobid_var[JOBSTATS_JOBID_VAR_MAX_LEN + 1] = JOBSTATS_DISABLE; -char obd_jobid_node[LUSTRE_JOBID_SIZE + 1]; - -/* Get jobid of current process from stored variable or calculate - * it from pid and user_id. - * - * Historically this was also done by reading the environment variable - * stored in between the "env_start" & "env_end" of task struct. - * This is now deprecated. - */ -int lustre_get_jobid(char *jobid) -{ - char tmp_jobid[LUSTRE_JOBID_SIZE] = { 0 }; - - /* Jobstats isn't enabled */ - if (strcmp(obd_jobid_var, JOBSTATS_DISABLE) == 0) - goto out_cache_jobid; - - /* Use process name + fsuid as jobid */ - if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) { - snprintf(tmp_jobid, LUSTRE_JOBID_SIZE, "%s.%u", - current->comm, - from_kuid(&init_user_ns, current_fsuid())); - goto out_cache_jobid; - } - - /* Whole node dedicated to single job */ - if (strcmp(obd_jobid_var, JOBSTATS_NODELOCAL) == 0) { - strcpy(tmp_jobid, obd_jobid_node); - goto out_cache_jobid; - } - - return -ENOENT; - -out_cache_jobid: - /* Only replace the job ID if it changed. */ - if (strcmp(jobid, tmp_jobid) != 0) - strcpy(jobid, tmp_jobid); - - return 0; -} -EXPORT_SYMBOL(lustre_get_jobid); - static int class_resolve_dev_name(u32 len, const char *name) { int rc; diff --git a/fs/lustre/obdclass/jobid.c b/fs/lustre/obdclass/jobid.c new file mode 100644 index 0000000..3655a2e --- /dev/null +++ b/fs/lustre/obdclass/jobid.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.gnu.org/licenses/gpl-2.0.html + * + * GPL HEADER END + */ +/* + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + * + * Copyright (c) 2011, 2014, Intel Corporation. + * + * Copyright 2017 Cray Inc, all rights reserved. + * Author: Ben Evans. + * + */ + +#define DEBUG_SUBSYSTEM S_RPC +#include +#ifdef HAVE_UIDGID_HEADER +#include +#endif + +#include +#include +#include + +char obd_jobid_var[JOBSTATS_JOBID_VAR_MAX_LEN + 1] = JOBSTATS_DISABLE; +char obd_jobid_node[LUSTRE_JOBID_SIZE + 1]; + +/* Get jobid of current process from stored variable or calculate + * it from pid and user_id. + * + * Historically this was also done by reading the environment variable + * stored in between the "env_start" & "env_end" of task struct. + * This is now deprecated. + */ + +int lustre_get_jobid(char *jobid) +{ + char tmp_jobid[LUSTRE_JOBID_SIZE] = { 0 }; + + /* Jobstats isn't enabled */ + if (strcmp(obd_jobid_var, JOBSTATS_DISABLE) == 0) + goto out_cache_jobid; + + /* Use process name + fsuid as jobid */ + if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) { + snprintf(tmp_jobid, LUSTRE_JOBID_SIZE, "%s.%u", + current->comm, + from_kuid(&init_user_ns, current_fsuid())); + goto out_cache_jobid; + } + + /* Whole node dedicated to single job */ + if (strcmp(obd_jobid_var, JOBSTATS_NODELOCAL) == 0) { + strcpy(tmp_jobid, obd_jobid_node); + goto out_cache_jobid; + } + + return -ENOENT; + +out_cache_jobid: + /* Only replace the job ID if it changed. */ + if (strcmp(jobid, tmp_jobid) != 0) + strcpy(jobid, tmp_jobid); + + return 0; +} +EXPORT_SYMBOL(lustre_get_jobid);