Whamcloud - gitweb
LU-2729 mgs: fix cleanup of nonexistant MGSSELF_NAME proc file
[fs/lustre-release.git] / lustre / mgs / lproc_mgs.c
index 691ad12..65513fd 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #ifdef LPROCFS
 
-static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
-                                 int *eof, void *data)
-{
-       struct obd_device *obd = (struct obd_device *)data;
-
-       LASSERT(obd != NULL);
-#if 0
-       /* will be fixed in the subsequent patch */
-       LASSERT(mnt_get_devname(obd->u.mgs.mgs_vfsmnt));
-       *eof = 1;
-
-       return snprintf(page, count, "%s\n",
-                       mnt_get_devname(obd->u.mgs.mgs_vfsmnt));
-#else
-       return 0;
-#endif
-}
-
 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
 {
         struct obd_device *obd = seq->private;
@@ -152,9 +134,9 @@ static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
         if (rc)
                goto out;
 
-        cfs_mutex_lock(&fsdb->fsdb_mutex);
+       mutex_lock(&fsdb->fsdb_mutex);
         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
-        cfs_mutex_unlock(&fsdb->fsdb_mutex);
+       mutex_unlock(&fsdb->fsdb_mutex);
 
 out:
        lu_env_fini(&env);
@@ -163,15 +145,17 @@ out:
 
 LPROC_SEQ_FOPS_RO(mgsself_srpc);
 
-int lproc_mgs_setup(struct mgs_device *mgs)
+int lproc_mgs_setup(struct mgs_device *mgs, char *osd_name)
 {
        struct obd_device *obd = mgs->mgs_obd;
-        int rc;
+       struct obd_device *osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
+       int                osd_len = strlen(osd_name) - strlen("-osd");
+       int                rc;
 
         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
                                     &mgs_fs_fops, obd);
-        rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
-                                    &mgsself_srpc_fops, obd);
+       rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0400,
+                                   &mgsself_srpc_fops, obd);
 
         mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
                                               NULL, NULL);
@@ -190,16 +174,45 @@ int lproc_mgs_setup(struct mgs_device *mgs)
                 obd->obd_proc_exports_entry = NULL;
         }
 
-        return rc;
+       mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
+                                               obd->obd_proc_entry,
+                                               "../../%s/%.*s",
+                                               osd_obd->obd_type->typ_name,
+                                               osd_len, /* Strip "-osd". */
+                                               osd_name);
+       if (mgs->mgs_proc_osd == NULL)
+               rc = -ENOMEM;
+
+       mgs->mgs_proc_mntdev = lprocfs_add_symlink("mntdev",
+                                                  obd->obd_proc_entry,
+                                                  "osd/mntdev");
+       if (mgs->mgs_proc_mntdev == NULL)
+               rc = -ENOMEM;
+
+       mgs->mgs_proc_fstype = lprocfs_add_symlink("fstype",
+                                                  obd->obd_proc_entry,
+                                                  "osd/fstype");
+       if (mgs->mgs_proc_fstype == NULL)
+               rc = -ENOMEM;
+
+       return rc;
 }
 
-int lproc_mgs_cleanup(struct mgs_device *mgs)
+void lproc_mgs_cleanup(struct mgs_device *mgs)
 {
        struct obd_device *obd = mgs->mgs_obd;
 
-        if (!obd)
-                return -EINVAL;
+       if (obd == NULL)
+               return;
 
+       if (mgs->mgs_proc_osd != NULL)
+               lprocfs_remove(&mgs->mgs_proc_osd);
+
+       if (mgs->mgs_proc_fstype != NULL)
+               lprocfs_remove(&mgs->mgs_proc_fstype);
+
+       if (mgs->mgs_proc_mntdev)
+               lprocfs_remove(&mgs->mgs_proc_mntdev);
         if (mgs->mgs_proc_live) {
                 /* Should be no live entries */
                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
@@ -207,10 +220,9 @@ int lproc_mgs_cleanup(struct mgs_device *mgs)
                 mgs->mgs_proc_live = NULL;
         }
         lprocfs_free_per_client_stats(obd);
+       lprocfs_obd_cleanup(obd);
         lprocfs_free_obd_stats(obd);
         lprocfs_free_md_stats(obd);
-
-        return lprocfs_obd_cleanup(obd);
 }
 
 static int mgs_live_seq_show(struct seq_file *seq, void *v)
@@ -219,16 +231,16 @@ static int mgs_live_seq_show(struct seq_file *seq, void *v)
         struct mgs_tgt_srpc_conf *srpc_tgt;
         int i;
 
-        cfs_mutex_lock(&fsdb->fsdb_mutex);
+       mutex_lock(&fsdb->fsdb_mutex);
 
         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
         seq_printf(seq, "flags: %#lx     gen: %d\n",
                    fsdb->fsdb_flags, fsdb->fsdb_gen);
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
-                 if (cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
+               if (test_bit(i, fsdb->fsdb_mdt_index_map))
                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
-                 if (cfs_test_bit(i, fsdb->fsdb_ost_index_map))
+               if (test_bit(i, fsdb->fsdb_ost_index_map))
                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
 
         seq_printf(seq, "\nSecure RPC Config Rules:\n");
@@ -245,7 +257,7 @@ static int mgs_live_seq_show(struct seq_file *seq, void *v)
 
         lprocfs_rd_ir_state(seq, fsdb);
 
-        cfs_mutex_unlock(&fsdb->fsdb_mutex);
+       mutex_unlock(&fsdb->fsdb_mutex);
         return 0;
 }
 
@@ -269,8 +281,8 @@ int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
 
         if (!mgs->mgs_proc_live)
                 return 0;
-        rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
-                                &mgs_live_fops, fsdb);
+       rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644,
+                               &mgs_live_fops, fsdb);
 
         return 0;
 }
@@ -280,14 +292,14 @@ int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
         if (!mgs->mgs_proc_live)
                 return 0;
 
-        lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
+       /* didn't create the proc file for MGSSELF_NAME */
+       if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
+               lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
         return 0;
 }
 
 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
         { "uuid",            lprocfs_rd_uuid,        0, 0 },
-        { "fstype",          lprocfs_rd_fstype,      0, 0 },
-        { "mntdev",          lprocfs_mgs_rd_mntdev,  0, 0 },
         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
         { "evict_client",    0, lprocfs_wr_evict_client, 0 },