From 78dfeefe1a3fb5ff0c71b403d14d54f00105510c Mon Sep 17 00:00:00 2001
From: shaver <shaver>
Date: Wed, 3 Dec 2003 21:39:49 +0000
Subject: [PATCH] Instrumentation for reproducing and verifying 1897
 (open-count leaked if close is interrupted on the client). r=robert.

---
 lustre/include/linux/obd.h     |  2 ++
 lustre/mds/handler.c           |  1 +
 lustre/mds/lproc_mds.c         | 12 ++++++++++++
 lustre/mds/mds_open.c          |  3 +++
 lustre/tests/llmount-upcall.sh |  6 ++++++
 5 files changed, 24 insertions(+)
 create mode 100755 lustre/tests/llmount-upcall.sh

diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h
index 03ea9c9b1c..8c85be5087 100644
--- a/lustre/include/linux/obd.h
+++ b/lustre/include/linux/obd.h
@@ -258,6 +258,8 @@ struct mds_obd {
         struct file                     *mds_lov_objid_filp;
         unsigned long                   *mds_client_bitmap;
         struct semaphore                 mds_orphan_recovery_sem;
+
+        atomic_t                         mds_open_count;
 };
 
 struct echo_obd {
diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c
index 0f0a6084a2..82e16ac60f 100644
--- a/lustre/mds/handler.c
+++ b/lustre/mds/handler.c
@@ -1301,6 +1301,7 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
         spin_lock_init(&mds->mds_transno_lock);
         mds->mds_max_mdsize = sizeof(struct lov_mds_md);
         mds->mds_max_cookiesize = sizeof(struct llog_cookie);
+        atomic_set(&mds->mds_open_count, 0);
 
         obd->obd_namespace = ldlm_namespace_new("mds_server",
                                                 LDLM_NAMESPACE_SERVER);
diff --git a/lustre/mds/lproc_mds.c b/lustre/mds/lproc_mds.c
index fe883d91d2..59b3401a7d 100644
--- a/lustre/mds/lproc_mds.c
+++ b/lustre/mds/lproc_mds.c
@@ -49,6 +49,17 @@ static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
 }
 
+static int lprocfs_mds_rd_filesopen(char *page, char **start, off_t off,
+                                    int count, int *eof, void *data)
+{
+        struct obd_device *obd = data;
+        LASSERT(obd != NULL);
+        *eof = 1;
+
+        return snprintf(page, count, "%d\n",
+                        atomic_read(&obd->u.mds.mds_open_count));
+}
+
 static int lprocfs_mds_rd_recovery_status(char *page, char **start, off_t off,
                                           int count, int *eof, void *data)
 {
@@ -150,6 +161,7 @@ struct lprocfs_vars lprocfs_mds_obd_vars[] = {
         { "fstype",       lprocfs_rd_fstype,      0, 0 },
         { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
         { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
+        { "filesopen",    lprocfs_mds_rd_filesopen,   0, 0 },
         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
         { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
         { "recovery_status", lprocfs_mds_rd_recovery_status, 0, 0 },
diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c
index 89f2edb91e..4f6df75dab 100644
--- a/lustre/mds/mds_open.c
+++ b/lustre/mds/mds_open.c
@@ -963,6 +963,8 @@ int mds_open(struct mds_update_record *rec, int offset,
                 else
                         ldlm_put_lock_into_req(req, &parent_lockh, parent_mode);
         }
+        if (rc == 0)
+                atomic_inc(&mds->mds_open_count);
         RETURN(rc);
 }
 
@@ -1085,6 +1087,7 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd,
         mds_mfd_destroy(mfd);
 
  cleanup:
+        atomic_dec(&mds->mds_open_count);
         if (req) {
                 rc = mds_finish_transno(mds, pending_dir, handle, req, rc, 0);
         } else if (handle) {
diff --git a/lustre/tests/llmount-upcall.sh b/lustre/tests/llmount-upcall.sh
new file mode 100755
index 0000000000..f5a1ef72d8
--- /dev/null
+++ b/lustre/tests/llmount-upcall.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+LUSTRE=`dirname $0`/..
+exec >> /tmp/recovery-`hostname`.log
+exec 2>&1
+
+$LUSTRE/utils/lconf --recover --verbose --tgt_uuid $2 --client_uuid $3 --conn_uuid $4 $LUSTRE/tests/local.xml
-- 
GitLab