From nobody Sat Apr 09 21:48:26 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C85171A8B149; Sat, 9 Apr 2022 21:48:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KbTJV65bwz4dPj; Sat, 9 Apr 2022 21:48:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649540907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JeACgAFV9eAY0VqRN/6KbYz6mYkOOmjbg/iBmBZb8Us=; b=rdlNJevS4qrAvJ/hJK81o8mONQCBdeNyXTgbf5/YZFSVZZOyI7ha9APeWwv/YLH+UfD7pi wkeddj9UN3X0IFSaUm8F1tNIVI6PIqYIBYijT1N8vIpJ9i+dR0v9eAgKkIn/XC2S3DtJ2o Z4CxUG11A2bfDQWuYyOyqgZWMynP3M7Vj64TwsSmrldBnvfu8Uyx9kNlTvyzrOF4MMeSGE l4MfQYPWCHGd/hjEYZQOTadrygpYJIkzNWehIsXtmGMifOrMBubcih/dU3Xn6kM08Pm1pd tfm35bPh/OXMNnq9TcMkK1P+hoyc5cDkPRrNE6F54iJxMo7GojWEoxGVfCAAMg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 767AF219B0; Sat, 9 Apr 2022 21:48:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 239LmQCa093193; Sat, 9 Apr 2022 21:48:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 239LmQbY093192; Sat, 9 Apr 2022 21:48:26 GMT (envelope-from git) Date: Sat, 9 Apr 2022 21:48:26 GMT Message-Id: <202204092148.239LmQbY093192@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: a5229a255ea9 - main - Implement procstat(1) advlocks command List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a5229a255ea9e67fe935da1f566be803c1e7f99f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649540907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JeACgAFV9eAY0VqRN/6KbYz6mYkOOmjbg/iBmBZb8Us=; b=ql+m1kcU+/asR7z0Rm/qa/1anisx4HgEmGLigXG5l6V758NEMCL3aum53OcpbFFJvxUbOQ /Ym55a3RO48LXV3ikVH5XLXRstKPJIp/GPAh7uoRPzbJS40Wlx9yMCA3F8ObancFQV4qKS sWyZyouKwt5d8FDBcLg6Xhai/Wlo14NpmMsVj2z6gn+qlkeBbEzkZxhRFXuLD5tS5ryX8j MwFt8tSoAw4AllraweBaXlc1bI8IFHTbN9USbvZjfZ+o5Peuk9HK07A2iHPIm6TnsfVTRF vsq1leXbpJEVeEiMT+4EchLhMsAaO5HFiDA6FT1M9o8kithJ1KN+zAxjIyGa0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649540907; a=rsa-sha256; cv=none; b=SgqDRzGfFT9c+WwNGSBLkXoHJi3RgLdtSUlXrZYfhwueIy3B9N4kyyl1BcsmRk2MmubZfm hAX60b9UI0aSZoNmqrDCO+/8+Y5cdwTWjV5YRNFGn8vxNV2P62kUKOksQrBWfICQM8B5Cq YPMrg5QMd8o6QqPwvb9xZ6xYgc4KPRcx1wm89jKYOX5cNLEfXE9yJozOkg6X+1tLxBvVC9 k+5eKOKFckIMitc+c3SjhGBFUrucNy38b1AyY99fJoVhlCKewtJu21Q2CClH0TIGcmZ0Bn 4IORIg5K8a53tiSombKp9FCwZY6x3aoR3PDh3HS00VLV9AFpR4DqA9z3HYgBqw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a5229a255ea9e67fe935da1f566be803c1e7f99f commit a5229a255ea9e67fe935da1f566be803c1e7f99f Author: Konstantin Belousov AuthorDate: 2022-04-02 14:13:17 +0000 Commit: Konstantin Belousov CommitDate: 2022-04-09 21:47:50 +0000 Implement procstat(1) advlocks command to display list of the advisory file locks in the system. Example output $ procstat advlock RW TYPE PID SYSID FSID RDEV INO START LEN PATH RO FCNTL 5836 0 0x878700ff02 0xffffffffffffffff 57 0 0 /tmp/2 RW FLOCK -1 0 0x878700ff02 0xffffffffffffffff 13 0 0 /tmp/1 Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D34834 --- usr.bin/procstat/Makefile | 1 + usr.bin/procstat/procstat.c | 2 + usr.bin/procstat/procstat.h | 1 + usr.bin/procstat/procstat_advlock.c | 102 ++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) diff --git a/usr.bin/procstat/Makefile b/usr.bin/procstat/Makefile index 0b88f2f4634a..85bff9dae3e2 100644 --- a/usr.bin/procstat/Makefile +++ b/usr.bin/procstat/Makefile @@ -5,6 +5,7 @@ PROG= procstat MAN= procstat.1 SRCS= procstat.c \ + procstat_advlock.c \ procstat_args.c \ procstat_auxv.c \ procstat_basic.c \ diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c index 220f63f2703e..2388c035b431 100644 --- a/usr.bin/procstat/procstat.c +++ b/usr.bin/procstat/procstat.c @@ -87,6 +87,8 @@ static const struct procstat_cmd pacmd_table[] = { /* procstat parameters and arguments */ static const struct procstat_cmd cmd_table[] = { + { "advlock", "advisory_locks", NULL, &procstat_advlocks, &cmdopt_none, + PS_CMP_PLURAL | PS_CMP_SUBSTR | PS_MODE_NO_KINFO_PROC }, { "argument", "arguments", NULL, &procstat_args, &cmdopt_none, PS_CMP_PLURAL | PS_CMP_SUBSTR }, { "auxv", "auxv", NULL, &procstat_auxv, &cmdopt_none, PS_CMP_NORMAL }, diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h index 5b54d4c4ff2f..d3bd12d42ffd 100644 --- a/usr.bin/procstat/procstat.h +++ b/usr.bin/procstat/procstat.h @@ -57,6 +57,7 @@ struct kinfo_proc; void kinfo_proc_sort(struct kinfo_proc *kipp, int count); const char * kinfo_proc_thread_name(const struct kinfo_proc *kipp); +void procstat_advlocks(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_args(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_auxv(struct procstat *prstat, struct kinfo_proc *kipp); void procstat_basic(struct procstat *prstat, struct kinfo_proc *kipp); diff --git a/usr.bin/procstat/procstat_advlock.c b/usr.bin/procstat/procstat_advlock.c new file mode 100644 index 000000000000..e0b256a8023a --- /dev/null +++ b/usr.bin/procstat/procstat_advlock.c @@ -0,0 +1,102 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 The FreeBSD Foundation + * + * Portions of this software were developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "procstat.h" + +void +procstat_advlocks(struct procstat *prstat, struct kinfo_proc *kipp __unused) +{ + struct advlock_list *advl; + struct advlock *a; + static const char advisory_lock_item[] = "advisory_lock"; + + if ((procstat_opts & PS_OPT_NOHEADER) == 0) + xo_emit("{T:/%2s %5s %5s %5s %18s %18s %8s %9s %9s %s}\n", + "RW", "TYPE", "PID", "SYSID", "FSID", "RDEV", "INO", + "START", "LEN", "PATH"); + + xo_open_list(advisory_lock_item); + advl = procstat_getadvlock(prstat); + if (advl == NULL) { + xo_close_list(advisory_lock_item); + return; + } + + STAILQ_FOREACH(a, advl, next) { + xo_open_instance(advisory_lock_item); + switch (a->rw) { + case PS_ADVLOCK_RO: + xo_emit("{:rw/%s} ", "RO"); + break; + case PS_ADVLOCK_RW: + xo_emit("{:rw/%s} ", "RW"); + break; + default: + xo_emit("{:rw/%s} ", "??"); + break; + } + switch (a->type) { + case PS_ADVLOCK_TYPE_FLOCK: + xo_emit("{:type/%s} ", "FLOCK"); + break; + case PS_ADVLOCK_TYPE_PID: + xo_emit("{:type/%s} ", "FCNTL"); + break; + case PS_ADVLOCK_TYPE_REMOTE: + xo_emit("{:type/%s} ", "LOCKD"); + break; + default: + xo_emit("{:type/%s} ", "?????"); + break; + } + xo_emit("{:pid/%5d} ", a->pid); + xo_emit("{:sysid/%5d} ", a->sysid); + xo_emit("{:fsid/%18#jx} ", (uintmax_t)a->file_fsid); + xo_emit("{:rdev/%#18jx} ", (uintmax_t)a->file_rdev); + xo_emit("{:ino/%8ju} ", (uintmax_t)a->file_fileid); + xo_emit("{:start/%9ju} ", (uintmax_t)a->start); + xo_emit("{:len/%9ju} ", (uintmax_t)a->len); + xo_emit("{:path/%s}", a->path == NULL ? "" : a->path); + xo_emit("\n"); + xo_close_instance(advisory_lock_item); + } + xo_close_list(advisory_lock_item); + procstat_freeadvlock(prstat, advl); +}