Whamcloud - gitweb
b=20591 fix race on obd_device::md_stats
[fs/lustre-release.git] / lustre / mdt / mdt_lproc.c
index 39285bc..d9347fc 100644 (file)
@@ -74,31 +74,63 @@ static const char *mdt_proc_names[LPROC_MDT_NR] = {
 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
 {
         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
-        int result;
+        struct obd_device *obd = ld->ld_obd;
+        struct lprocfs_static_vars lvars;
+        int rc;
         ENTRY;
 
         LASSERT(name != NULL);
-        mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry;
+
+        lprocfs_mdt_init_vars(&lvars);
+        rc = lprocfs_obd_setup(obd, lvars.obd_vars);
+        if (rc) {
+                CERROR("Can't init lprocfs, rc %d\n", rc);
+                return rc;
+        }
+        ptlrpc_lprocfs_register_obd(obd);
+
+        mdt->mdt_proc_entry = obd->obd_proc_entry;
         LASSERT(mdt->mdt_proc_entry != NULL);
 
-        result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
-                              mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
-        if (result == 0)
-                result = lu_time_named_init(&ld->ld_site->ls_time_stats,
-                                            "site_time", mdt->mdt_proc_entry,
-                                            lu_time_names,
-                                            ARRAY_SIZE(lu_time_names));
-        RETURN(result);
+        rc = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
+                          mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
+        if (rc == 0)
+                rc = lu_time_named_init(&ld->ld_site->ls_time_stats,
+                                        "site_time", mdt->mdt_proc_entry,
+                                         lu_time_names,
+                                         ARRAY_SIZE(lu_time_names));
+        if (rc)
+                return rc;
+
+        obd->obd_proc_exports_entry = proc_mkdir("exports",
+                                                 obd->obd_proc_entry);
+        if (obd->obd_proc_exports_entry)
+                lprocfs_add_simple(obd->obd_proc_exports_entry,
+                                   "clear", lprocfs_nid_stats_clear_read,
+                                   lprocfs_nid_stats_clear_write, obd, NULL);
+        rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_NR);
+
+        RETURN(rc);
 }
 
 int mdt_procfs_fini(struct mdt_device *mdt)
 {
         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
+        struct obd_device *obd = ld->ld_obd;
+
         if (mdt->mdt_proc_entry) {
                 lu_time_fini(&ld->ld_site->ls_time_stats);
                 lu_time_fini(&mdt->mdt_stats);
                 mdt->mdt_proc_entry = NULL;
         }
+        if (obd->obd_proc_exports_entry) {
+                lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
+                obd->obd_proc_exports_entry = NULL;
+        }
+        ptlrpc_lprocfs_unregister_obd(obd);
+        lprocfs_free_md_stats(obd);
+        lprocfs_obd_cleanup(obd);
+
         RETURN(0);
 }
 
@@ -599,7 +631,7 @@ static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
                 GOTO(failed, rc = -EFAULT);
         }
         kernbuf[count] = '\0';
+
         if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
                 /* empty string is special case */
                 down_write(&mdt->mdt_squash_sem);
@@ -655,6 +687,7 @@ static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
                         mdt->mdt_som_conf ? "en" : "dis");
 }
 
+#ifdef HAVE_QUOTA_SUPPORT
 static int mdt_quota_off(struct mdt_device *mdt)
 {
         struct md_device *next = mdt->mdt_child;
@@ -667,6 +700,12 @@ static int mdt_quota_off(struct mdt_device *mdt)
         lu_env_fini(&env);
         return rc;
 }
+#else
+static int mdt_quota_off(struct mdt_device *mdt)
+{
+        return 0;
+}
+#endif
 
 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
                               unsigned long count, void *data)
@@ -726,6 +765,30 @@ static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
         return count;
 }
 
+/* Temporary; for testing purposes only */
+static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
+                              unsigned long count, void *data)
+{
+        struct obd_device *obd = data;
+        struct obd_export *exp = NULL;
+        struct obd_uuid uuid;
+        char tmpbuf[sizeof(struct obd_uuid)];
+
+        sscanf(buffer, "%40s", tmpbuf);
+
+        obd_str2uuid(&uuid, tmpbuf);
+        exp = cfs_hash_lookup(obd->obd_uuid_hash, &uuid);
+        if (exp == NULL) {
+                CERROR("%s: no export %s found\n",
+                       obd->obd_name, obd_uuid2str(&uuid));
+        } else {
+                mdt_hsm_copytool_send(exp);
+                class_export_put(exp);
+        }
+
+        return count;
+}
+
 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
         { "uuid",                       lprocfs_rd_uuid,                 0, 0 },
         { "recovery_status",            lprocfs_obd_rd_recovery_status,  0, 0 },
@@ -754,9 +817,10 @@ static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
         { "root_squash",                lprocfs_rd_root_squash,
                                         lprocfs_wr_root_squash,             0 },
         { "nosquash_nids",              lprocfs_rd_nosquash_nids,
-                                        lprocfs_wr_nosquash_nids,          0 },
+                                        lprocfs_wr_nosquash_nids,           0 },
         { "som",                        lprocfs_rd_mdt_som,
                                         lprocfs_wr_mdt_som, 0 },
+        { "mdccomm",                    0, lprocfs_mdt_wr_mdc,              0 },
         { 0 }
 };