From f9970c0a704c4f1c70a21d416284ce91cf4c102b Mon Sep 17 00:00:00 2001 From: Lei Feng Date: Tue, 10 May 2022 21:51:26 -0400 Subject: [PATCH] EX-5249 utils: show pin information in 'lfs pcc state' command If xattr lustre.pin exists, show its content in 'lfs pcc state' command. Change-Id: I867ea3b246fc3b7d10e166d754c081c8afc462d5 Signed-off-by: Lei Feng Test-Parameters: trivial Reviewed-on: https://review.whamcloud.com/47287 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yingjin Qian Reviewed-by: Andreas Dilger --- lustre/doc/lfs-pcc-state.1 | 7 +++++-- lustre/utils/lfs.c | 31 ++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lustre/doc/lfs-pcc-state.1 b/lustre/doc/lfs-pcc-state.1 index f3ee271..89f5df0 100644 --- a/lustre/doc/lfs-pcc-state.1 +++ b/lustre/doc/lfs-pcc-state.1 @@ -2,7 +2,7 @@ .SH NAME lfs pcc state \- display current PCC state of file .SH SYNOPSIS -.BR "lfs pcc state " "\fIFILE \fR...>" +.BR "lfs pcc state " "<\fIFILE\fR ...>" .SH DESCRIPTION Display the current PCC cache state of .I FILE @@ -23,7 +23,10 @@ is the number of processes that have the local cache file open, and .B flags shows additional file states, including .B attaching -for files that are not fully copied into cache, +for files that are not fully copied into cache. +The +.B pin +shows the pin information if they exist. .SH EXAMPLES .TP .B $ lfs pcc state /mnt/lustre/file diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 58f4eae..27c207e 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -12474,6 +12474,7 @@ static int lfs_pcc_state(int argc, char **argv) const char *path; char fullpath[PATH_MAX]; struct lu_pcc_state state; + char buff[XATTR_SIZE_MAX]; optind = 1; @@ -12505,21 +12506,37 @@ static int lfs_pcc_state(int argc, char **argv) continue; } + rc2 = getxattr(path, XATTR_LUSTRE_PIN, buff, sizeof(buff)); + if (rc2 < 0) { + if (errno != ENODATA) { + if (rc == 0) + rc = -errno; + fprintf(stderr, + "%s: cannot get PCC pin xattr of '%s': %s\n", + argv[0], path, strerror(errno)); + continue; + } else { + rc2 = 0; + } + } + buff[rc2] = '\0'; + printf("file: %s", path); printf(", type: %s", pcc_type2string(state.pccs_type)); if (state.pccs_type == LU_PCC_NONE && state.pccs_open_count == 0) { if (state.pccs_flags & PCC_STATE_FL_ATTACHING) printf(", flags: attaching"); - printf("\n"); - continue; + } else { + printf(", PCC_file: %s", state.pccs_path); + if (state.pccs_flags & PCC_STATE_FL_UNLINKED) + printf(" (unlinked)"); + printf(", open_count: %u", state.pccs_open_count); + printf(", flags: %x", state.pccs_flags); } - printf(", PCC_file: %s", state.pccs_path); - if (state.pccs_flags & PCC_STATE_FL_UNLINKED) - printf(" (unlinked)"); - printf(", open_count: %u", state.pccs_open_count); - printf(", flags: %x", state.pccs_flags); + if (buff[0] != '\0') + printf(", pin: %s", buff); printf("\n"); } return rc; -- 1.8.3.1