Whamcloud - gitweb
LU-2163 lprocfs: fix jobstats initialization race
[fs/lustre-release.git] / lustre / mgs / mgs_internal.h
index 0e1fb7e..9ad6174 100644 (file)
 #ifndef _MGS_INTERNAL_H
 #define _MGS_INTERNAL_H
 
-#ifdef __KERNEL__
-# include <linux/fs.h>
-#endif
 #include <libcfs/libcfs.h>
-#include <lustre/lustre_idl.h>
-#include <lustre_lib.h>
-#include <lustre_dlm.h>
 #include <lustre_log.h>
 #include <lustre_export.h>
+#include <dt_object.h>
 
 #define MGSSELF_NAME    "_mgs"
 
@@ -130,13 +125,8 @@ struct fs_db {
         void             *fsdb_ost_index_map;  /* bitmap of used indicies */
         void             *fsdb_mdt_index_map;  /* bitmap of used indicies */
         int               fsdb_mdt_count;
-        /* COMPAT_146 these items must be recorded out of the old client log */
         char             *fsdb_clilov;       /* COMPAT_146 client lov name */
         char             *fsdb_clilmv;
-        char             *fsdb_mdtlov;       /* COMPAT_146 mds lov name */
-        char             *fsdb_mdtlmv;
-        char             *fsdb_mdc;          /* COMPAT_146 mdc name */
-        /* end COMPAT_146 */
         unsigned long     fsdb_flags;
         __u32             fsdb_gen;
 
@@ -153,7 +143,6 @@ struct fs_db {
         struct mgs_nidtbl    fsdb_nidtbl;
 
         /* async thread to notify clients */
-        struct obd_device   *fsdb_obd;
        struct mgs_device   *fsdb_mgs;
         cfs_waitq_t          fsdb_notify_waitq;
         cfs_completion_t     fsdb_notify_comp;
@@ -167,9 +156,30 @@ struct fs_db {
         unsigned int         fsdb_notify_count;
 };
 
-/* mgs_llog.c */
-int class_dentry_readdir(const struct lu_env *env,
-                        struct mgs_device *mgs, cfs_list_t *list);
+struct mgs_device {
+       struct dt_device                 mgs_dt_dev;
+       struct ptlrpc_service           *mgs_service;
+       struct dt_device                *mgs_bottom;
+       struct obd_export               *mgs_bottom_exp;
+       struct dt_object                *mgs_configs_dir;
+       struct dt_object                *mgs_nidtbl_dir;
+       cfs_list_t                       mgs_fs_db_list;
+       cfs_spinlock_t                   mgs_lock; /* covers mgs_fs_db_list */
+       cfs_proc_dir_entry_t            *mgs_proc_live;
+       cfs_proc_dir_entry_t            *mgs_proc_mntdev;
+       cfs_time_t                       mgs_start_time;
+       struct obd_device               *mgs_obd;
+       struct local_oid_storage        *mgs_los;
+       cfs_mutex_t                      mgs_mutex;
+};
+
+/* this is a top object */
+struct mgs_object {
+       struct lu_object_header mgo_header;
+       struct dt_object        mgo_obj;
+       int                     mgo_no_attrs;
+       int                     mgo_reserved;
+};
 
 int mgs_init_fsdb_list(struct mgs_device *mgs);
 int mgs_cleanup_fsdb_list(struct mgs_device *mgs);
@@ -181,8 +191,6 @@ int mgs_check_index(const struct lu_env *env, struct mgs_device *mgs, struct mgs
 int mgs_check_failnid(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti);
 int mgs_write_log_target(const struct lu_env *env, struct mgs_device *mgs, struct mgs_target_info *mti,
                          struct fs_db *fsdb);
-int mgs_upgrade_sv_14(const struct lu_env *env, struct mgs_device *mgs,
-                     struct mgs_target_info *mti, struct fs_db *fsdb);
 int mgs_erase_log(const struct lu_env *env, struct mgs_device *mgs,
                  char *name);
 int mgs_erase_logs(const struct lu_env *env, struct mgs_device *mgs,
@@ -225,24 +233,24 @@ int  mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
                           void *localdata);
 int mgs_client_free(struct obd_export *exp);
-int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt);
-int mgs_fs_cleanup(struct obd_device *obddev);
+int mgs_fs_setup(const struct lu_env *env, struct mgs_device *m);
+int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
 
 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
 #ifdef LPROCFS
-int lproc_mgs_setup(struct mgs_device *mgs);
+int lproc_mgs_setup(struct mgs_device *mgs, char *osd_name);
 int lproc_mgs_cleanup(struct mgs_device *mgs);
 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb);
 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb);
 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars);
 #else
-static inline int lproc_mgs_setup(struct obd_device *dev)
+static inline int lproc_mgs_setup(struct mgs_device *mgs)
 {return 0;}
-static inline int lproc_mgs_cleanup(struct obd_device *obd)
+static inline int lproc_mgs_cleanup(struct mgs_device *mgs)
 {return 0;}
-static inline int lproc_mgs_add_live(struct mgs_device *obd, struct fs_db *fsdb)
+static inline int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
 {return 0;}
-static inline int lproc_mgs_del_live(struct mgs_device *obd, struct fs_db *fsdb)
+static inline int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
 {return 0;}
 static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
 {
@@ -262,9 +270,129 @@ enum {
 void mgs_counter_incr(struct obd_export *exp, int opcode);
 void mgs_stats_counter_init(struct lprocfs_stats *stats);
 
+struct temp_comp {
+       struct mgs_target_info  *comp_tmti;
+       struct mgs_target_info  *comp_mti;
+       struct fs_db            *comp_fsdb;
+       struct obd_device       *comp_obd;
+};
+
+struct mgs_thread_info {
+       struct lustre_cfg_bufs  mgi_bufs;
+       char                    mgi_fsname[MTI_NAME_MAXLEN];
+       struct cfg_marker       mgi_marker;
+       struct temp_comp        mgi_comp;
+};
+
+extern struct lu_context_key mgs_thread_key;
+
+static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
+{
+       struct mgs_thread_info *info;
+
+       info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
+       LASSERT(info != NULL);
+       return info;
+}
+
+extern const struct lu_device_operations mgs_lu_ops;
+
+static inline int lu_device_is_mgs(struct lu_device *d)
+{
+       return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mgs_lu_ops);
+}
+
+static inline struct mgs_device* lu2mgs_dev(struct lu_device *d)
+{
+       LASSERT(lu_device_is_mgs(d));
+       return container_of0(d, struct mgs_device, mgs_dt_dev.dd_lu_dev);
+}
+
 static inline struct mgs_device *exp2mgs_dev(struct obd_export *exp)
 {
-       return &exp->exp_obd->u.mgs;
+       return lu2mgs_dev(exp->exp_obd->obd_lu_dev);
+}
+
+static inline struct lu_device *mgs2lu_dev(struct mgs_device *d)
+{
+       return (&d->mgs_dt_dev.dd_lu_dev);
+}
+
+static inline struct mgs_device *dt2mgs_dev(struct dt_device *d)
+{
+       LASSERT(lu_device_is_mgs(&d->dd_lu_dev));
+       return container_of0(d, struct mgs_device, mgs_dt_dev);
+}
+
+static inline struct mgs_object *lu2mgs_obj(struct lu_object *o)
+{
+       LASSERT(ergo(o != NULL, lu_device_is_mgs(o->lo_dev)));
+       return container_of0(o, struct mgs_object, mgo_obj.do_lu);
+}
+
+static inline struct lu_object *mgs2lu_obj(struct mgs_object *obj)
+{
+       return &obj->mgo_obj.do_lu;
 }
 
+static inline struct mgs_object *mgs_obj(const struct lu_object *o)
+{
+       LASSERT(lu_device_is_mgs(o->lo_dev));
+       return container_of0(o, struct mgs_object, mgo_obj.do_lu);
+}
+
+static inline struct mgs_object *dt2mgs_obj(const struct dt_object *d)
+{
+       return mgs_obj(&d->do_lu);
+}
+
+static inline struct dt_object* mgs_object_child(struct mgs_object *o)
+{
+       return container_of0(lu_object_next(mgs2lu_obj(o)),
+                            struct dt_object, do_lu);
+}
+
+static inline struct dt_object *dt_object_child(struct dt_object *o)
+{
+       return container_of0(lu_object_next(&(o)->do_lu),
+                            struct dt_object, do_lu);
+}
+struct mgs_direntry {
+       cfs_list_t  list;
+       char       *name;
+       int         len;
+};
+
+static inline void mgs_direntry_free(struct mgs_direntry *de)
+{
+       if (de) {
+               LASSERT(de->len);
+               OBD_FREE(de->name, de->len);
+               OBD_FREE_PTR(de);
+       }
+}
+
+static inline struct mgs_direntry *mgs_direntry_alloc(int len)
+{
+       struct mgs_direntry *de;
+
+       OBD_ALLOC_PTR(de);
+       if (de == NULL)
+               return NULL;
+
+       OBD_ALLOC(de->name, len);
+       if (de->name == NULL) {
+               OBD_FREE_PTR(de);
+               return NULL;
+       }
+
+       de->len = len;
+
+       return de;
+}
+
+/* mgs_llog.c */
+int class_dentry_readdir(const struct lu_env *env, struct mgs_device *mgs,
+                        cfs_list_t *list);
+
 #endif /* _MGS_INTERNAL_H */