Whamcloud - gitweb
LU-1301 mgs: OSD based class_dentry_readdir()
[fs/lustre-release.git] / lustre / mgs / lproc_mgs.c
index 673ab77..691ad12 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 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;
+       struct obd_device *obd = (struct obd_device *)data;
 
-        LASSERT(obd != NULL);
-        LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
-        *eof = 1;
-
-        return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
+       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;
-        struct mgs_obd *mgs = &obd->u.mgs;
-        cfs_list_t dentry_list;
-        struct l_linux_dirent *dirent, *n;
+       struct mgs_device *mgs;
+       cfs_list_t list;
+       struct mgs_direntry *dirent, *n;
+       struct lu_env env;
         int rc, len;
         ENTRY;
 
         LASSERT(obd != NULL);
-        rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
-                                  mgs->mgs_vfsmnt, &dentry_list);
+       LASSERT(obd->obd_lu_dev != NULL);
+       mgs = lu2mgs_dev(obd->obd_lu_dev);
+
+       rc = lu_env_init(&env, LCT_MG_THREAD);
+       if (rc)
+               RETURN(rc);
+
+       rc = class_dentry_readdir(&env, mgs, &list);
         if (rc) {
                 CERROR("Can't read config dir\n");
-                RETURN(rc);
+               GOTO(out, rc);
         }
-        cfs_list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
-                cfs_list_del(&dirent->lld_list);
-                len = strlen(dirent->lld_name);
-                if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
-                                          len) == 0)) {
-                        seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
-                }
-                OBD_FREE(dirent, sizeof(*dirent));
+       cfs_list_for_each_entry_safe(dirent, n, &list, list) {
+               cfs_list_del(&dirent->list);
+               len = strlen(dirent->name);
+               if (len > 7 &&
+                   strncmp(dirent->name + len - 7, "-client", len) == 0)
+                       seq_printf(seq, "%.*s\n", len - 7, dirent->name);
+               mgs_direntry_free(dirent);
         }
 
+out:
+       lu_env_fini(&env);
         RETURN(0);
 }
 
@@ -121,24 +135,37 @@ static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
 {
         struct obd_device *obd = seq->private;
+       struct mgs_device *mgs;
         struct fs_db      *fsdb;
+       struct lu_env      env;
         int                rc;
 
-        rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
+       LASSERT(obd != NULL);
+       LASSERT(obd->obd_lu_dev != NULL);
+       mgs = lu2mgs_dev(obd->obd_lu_dev);
+
+       rc = lu_env_init(&env, LCT_MG_THREAD);
+       if (rc)
+               return rc;
+
+       rc = mgs_find_or_make_fsdb(&env, mgs, MGSSELF_NAME, &fsdb);
         if (rc)
-                return rc;
+               goto out;
 
-        cfs_down(&fsdb->fsdb_sem);
+        cfs_mutex_lock(&fsdb->fsdb_mutex);
         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
-        cfs_up(&fsdb->fsdb_sem);
+        cfs_mutex_unlock(&fsdb->fsdb_mutex);
+
+out:
+       lu_env_fini(&env);
         return 0;
 }
 
 LPROC_SEQ_FOPS_RO(mgsself_srpc);
 
-int lproc_mgs_setup(struct obd_device *obd)
+int lproc_mgs_setup(struct mgs_device *mgs)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
+       struct obd_device *obd = mgs->mgs_obd;
         int rc;
 
         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
@@ -166,14 +193,13 @@ int lproc_mgs_setup(struct obd_device *obd)
         return rc;
 }
 
-int lproc_mgs_cleanup(struct obd_device *obd)
+int lproc_mgs_cleanup(struct mgs_device *mgs)
 {
-        struct mgs_obd *mgs;
+       struct obd_device *obd = mgs->mgs_obd;
 
         if (!obd)
                 return -EINVAL;
 
-        mgs = &obd->u.mgs;
         if (mgs->mgs_proc_live) {
                 /* Should be no live entries */
                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
@@ -193,7 +219,7 @@ static int mgs_live_seq_show(struct seq_file *seq, void *v)
         struct mgs_tgt_srpc_conf *srpc_tgt;
         int i;
 
-        cfs_down(&fsdb->fsdb_sem);
+        cfs_mutex_lock(&fsdb->fsdb_mutex);
 
         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
         seq_printf(seq, "flags: %#lx     gen: %d\n",
@@ -219,7 +245,7 @@ static int mgs_live_seq_show(struct seq_file *seq, void *v)
 
         lprocfs_rd_ir_state(seq, fsdb);
 
-        cfs_up(&fsdb->fsdb_sem);
+        cfs_mutex_unlock(&fsdb->fsdb_mutex);
         return 0;
 }
 
@@ -237,9 +263,8 @@ static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
 }
 LPROC_SEQ_FOPS(mgs_live);
 
-int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
+int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
         int rc;
 
         if (!mgs->mgs_proc_live)
@@ -250,10 +275,8 @@ int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
         return 0;
 }
 
-int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
+int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
 {
-        struct mgs_obd *mgs = &obd->u.mgs;
-
         if (!mgs->mgs_proc_live)
                 return 0;