From: Girish Shilamkar Date: Sun, 19 May 2013 08:27:00 +0000 (+0800) Subject: LU-946 lprocfs: List open files in filesystem X-Git-Tag: 2.5.54~4 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=94cb946d1360c0df541423ec10487545e4697aa7;hp=6c5e48383bc10dc0a798b56c898e5a90293246b6 LU-946 lprocfs: List open files in filesystem Added lprocfs file on MDT to list open files in per-export directory for mdt. Test-Parameters: testlist=sanity,sanityn Signed-off-by: Girish Shilamkar Signed-off-by: Emoly Liu Change-Id: If8f233d95dca4cd4c4044d85bd117a027dabd80e Reviewed-on: http://review.whamcloud.com/6386 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Swapnil Pimpale --- diff --git a/lustre/mdt/mdt_fs.c b/lustre/mdt/mdt_fs.c index 8621475..f9cf90e 100644 --- a/lustre/mdt/mdt_fs.c +++ b/lustre/mdt/mdt_fs.c @@ -42,6 +42,14 @@ #include "mdt_internal.h" +static const struct file_operations mdt_open_files_seq_fops = { + .owner = THIS_MODULE, + .open = lprocfs_mdt_open_files_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + int mdt_export_stats_init(struct obd_device *obd, struct obd_export *exp, void *localdata) @@ -75,7 +83,15 @@ int mdt_export_stats_init(struct obd_device *obd, rc = lprocfs_nid_ldlm_stats_init(tmp); if (rc) GOTO(clean, rc); - } + + rc = lprocfs_seq_create(tmp->nid_proc, "open_files", + 0444, &mdt_open_files_seq_fops, tmp); + if (rc) { + CWARN("%s: error adding the open_files file: rc = %d\n", + obd->obd_name, rc); + GOTO(clean, rc); + } + } RETURN(0); clean: return rc; diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 6c9d9fe..330c771 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -1068,6 +1068,10 @@ void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars); void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars); int mdt_procfs_init(struct mdt_device *mdt, const char *name); void mdt_procfs_fini(struct mdt_device *mdt); + +/* lustre/mdt_mdt_lproc.c */ +int lprocfs_mdt_open_files_seq_open(struct inode *inode, + struct file *file); void mdt_rename_counter_tally(struct mdt_thread_info *info, struct mdt_device *mdt, struct ptlrpc_request *req, diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index 4abb532..0ee5148 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -1051,6 +1051,59 @@ struct lprocfs_vars lprocfs_mds_module_vars[] = { { 0 } }; +int lprocfs_mdt_print_open_files(cfs_hash_t *hs, cfs_hash_bd_t *bd, + cfs_hlist_node_t *hnode, void *v) +{ + struct obd_export *exp = cfs_hash_object(hs, hnode); + struct seq_file *seq = v; + + if (exp->exp_lock_hash != NULL) { + struct mdt_export_data *med = &exp->exp_mdt_data; + struct mdt_file_data *mfd; + + spin_lock(&med->med_open_lock); + cfs_list_for_each_entry(mfd, &med->med_open_head, mfd_list) { + seq_printf(seq, DFID"\n", + PFID(mdt_object_fid(mfd->mfd_object))); + } + spin_unlock(&med->med_open_lock); + } + + return 0; +} + +int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v) +{ + struct nid_stat *stats = seq->private; + struct obd_device *obd = stats->nid_obd; + + cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid, + lprocfs_mdt_print_open_files, seq); + + return 0; +} + +int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file) +{ + struct proc_dir_entry *dp = PDE(inode); + struct seq_file *seq; + struct nid_stat *tmp; + int rc; + + if (LPROCFS_ENTRY_CHECK(dp)) + return -ENOENT; + + tmp = dp->data; + rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL); + if (rc != 0) + return rc; + + seq = file->private_data; + seq->private = tmp; + + return 0; +} + void mdt_counter_incr(struct ptlrpc_request *req, int opcode) { struct obd_export *exp = req->rq_export; diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index cbc48ff..1012ab9 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -2498,10 +2498,10 @@ int lprocfs_exp_rd_nid(char *page, char **start, off_t off, int count, } struct exp_uuid_cb_data { - char *page; - int count; - int *eof; - int *len; + char *page; + int count; + int *eof; + int *len; }; static void diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e2e2b96..b9f8686 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -9189,6 +9189,39 @@ test_154c() { } run_test 154c "lfs path2fid and fid2path multiple arguments" +test_154d() { + [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] && + skip "Need MDS version at least 2.5.53" && return + + if remote_mds; then + nid=$($LCTL list_nids | sed "s/\./\\\./g") + else + nid="0@lo" + fi + local proc_ofile="mdt.*.exports.'$nid'.open_files" + local fd + local cmd + + rm -f $DIR/$tfile + touch $DIR/$tfile + + fid=$($LFS path2fid $DIR/$tfile) + # Open the file + fd=$(free_fd) + cmd="exec $fd<$DIR/$tfile" + eval $cmd + fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile) + echo $fid_list | grep $fid + rc=$? + + cmd="exec $fd>/dev/null" + eval $cmd + if [ $rc -ne 0 ]; then + error "FID $fid not found in open files list $fid_list" + fi +} +run_test 154d "Verify open file fid" + test_155_small_load() { local temp=$TMP/$tfile local file=$DIR/$tfile diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index 9340b37..142c870 100644 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -2571,6 +2571,82 @@ test_75() { } run_test 75 "osc: upcall after unuse lock===================" +test_76() { #LU-946 + [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] && + skip "Need MDS version at least 2.5.53" && return + + remote_mds_nodsh && skip "remote MDS with nodsh" && return + local fcount=2048 + local fd + local cmd + local mdt_idx + local mds_idx + declare -a fd_list + declare -a fid_list + + if remote_mds; then + nid=$($LCTL list_nids | sed "s/\./\\\./g") + else + nid="0@lo" + fi + + rm -rf $DIR/$tdir + test_mkdir -p $DIR/$tdir + if [ $MDSCOUNT -gt 1 ]; then + mdt_idx=$($LFS getdirstripe -i $DIR/$tdir) + else + mdt_idx=0 + fi + mds_idx=$((mdt_idx + 1)) + proc_ofile="mdt.*$mdt_idx.exports.'$nid'.open_files" + + cancel_lru_locks mdc + + echo -n "open files " + ulimit -n 8096 + for (( i = 0; i < $fcount; i++ )) ; do + touch $DIR/$tdir/f_$i + fd=$(free_fd) + cmd="exec $fd<$DIR/$tdir/f_$i" + eval $cmd + fd_list[i]=$fd + echo -n "." + done + echo + + fid_list=($(do_facet mds$mds_idx $LCTL get_param -n $proc_ofile)) + + # Possible errors in openfiles FID list. + # 1. Missing FIDs. Check 1 + # 2. Extra FIDs. Check 1 + # 3. Duplicated FID. Check 2 + # 4. Invalid FIDs. Check 2 + # 5. Valid FID, points to some other file. Check 3 + + # Check 1 + [ ${#fid_list[@]} -ne $fcount ] && + error "${#fid_list[@]} != $fcount open files" + + for (( i = 0; i < $fcount; i++ )) ; do + cmd="exec ${fd_list[i]}