Whamcloud - gitweb
LU-8066 obd_type: discard obd_types linked list.
[fs/lustre-release.git] / lustre / include / obd_class.h
index 8350cb1..11ddb0e 100644 (file)
 extern rwlock_t obd_dev_lock;
 
 /* OBD Operations Declarations */
-extern struct obd_device *class_conn2obd(struct lustre_handle *);
 extern struct obd_device *class_exp2obd(struct obd_export *);
 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
 int lustre_get_jobid(char *jobid, size_t len);
 void lustre_jobid_clear(const char *jobid);
 void jobid_cache_fini(void);
 int jobid_cache_init(void);
+char *jobid_current(void);
+int jobid_set_current(char *jobid);
 
 struct lu_device_type;
 
 /* genops.c */
 struct obd_export *class_conn2export(struct lustre_handle *);
-struct kobject *class_setup_tunables(const char *name);
+#ifdef HAVE_SERVER_SUPPORT
+struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
+#endif
 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
                        struct lprocfs_vars *module_vars,
                        const char *nm, struct lu_device_type *ldt);
@@ -83,7 +86,7 @@ int class_uuid2dev(struct obd_uuid *uuid);
 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
 void class_obd_list(void);
 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
-                                          const char * typ_name,
+                                         const char *type_name,
                                           struct obd_uuid *grp_uuid);
 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
                                            int *next);
@@ -155,8 +158,6 @@ int class_process_config(struct lustre_cfg *lcfg);
 ssize_t class_set_global(const char *param);
 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
                            struct kobject *kobj);
-int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
-                            struct lustre_cfg *lcfg, void *data);
 int class_attach(struct lustre_cfg *lcfg);
 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
@@ -190,8 +191,7 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
 
 /* Passed as data param to class_config_parse_llog */
 struct config_llog_instance {
-       char                    *cfg_obdname;
-       void                    *cfg_instance;
+       unsigned long            cfg_instance;
        struct super_block      *cfg_sb;
        struct obd_uuid          cfg_uuid;
        llog_cb_t                cfg_callback;
@@ -203,6 +203,19 @@ struct config_llog_instance {
 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
                            char *name, struct config_llog_instance *cfg);
 
+/**
+ * Generate a unique configuration instance for this mount
+ *
+ * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
+ * For now, use the same value as before - the superblock pointer value.
+ *
+ * Using the client UUID would be an option, but it needs more testing.
+ */
+static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
+{
+       return (unsigned long)sb;
+}
+
 #define CONFIG_SUB_SPTLRPC     0x01
 #define CONFIG_SUB_RECOVER     0x02
 #define CONFIG_SUB_PARAMS      0x04
@@ -346,8 +359,10 @@ void class_import_put(struct obd_import *);
 struct obd_import *class_new_import(struct obd_device *obd);
 void class_destroy_import(struct obd_import *exp);
 
+#ifdef HAVE_SERVER_SUPPORT
 struct obd_type *class_search_type(const char *name);
 struct obd_type *class_get_type(const char *name);
+#endif
 void class_put_type(struct obd_type *type);
 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
                   struct obd_uuid *cluuid);
@@ -358,6 +373,7 @@ void class_disconnect_exports(struct obd_device *obddev);
 int class_manual_cleanup(struct obd_device *obd);
 void class_disconnect_stale_exports(struct obd_device *,
                                     int (*test_export)(struct obd_export *));
+
 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
 {
         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
@@ -395,20 +411,22 @@ void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
 
-/* Ensure obd_setup: used for cleanup which must be called
-   while obd is stopping */
-#define OBD_CHECK_DEV(obd)                                      \
-do {                                                            \
-        if (!(obd)) {                                           \
-                CERROR("NULL device\n");                        \
-                RETURN(-ENODEV);                                \
-        }                                                       \
-} while (0)
+static inline int obd_check_dev(struct obd_device *obd)
+{
+       if (!obd) {
+               CERROR("NULL device\n");
+               return -ENODEV;
+       }
+       return 0;
+}
 
 /* ensure obd_setup and !obd_stopping */
 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
 do {                                                            \
-        OBD_CHECK_DEV(obd);                                     \
+       rc = obd_check_dev(obd);                                \
+       if (rc)                                                 \
+               return rc;                                      \
+                                                               \
         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
                 CERROR("Device %d not setup\n",                 \
                        (obd)->obd_minor);                       \
@@ -560,12 +578,19 @@ static inline int obd_precleanup(struct obd_device *obd)
        ENTRY;
 
        if (ldt != NULL && d != NULL) {
-               struct lu_env env;
-
-               rc = lu_env_init(&env, ldt->ldt_ctx_tags);
-               if (rc == 0) {
-                       ldt->ldt_ops->ldto_device_fini(&env, d);
-                       lu_env_fini(&env);
+               struct lu_env *env = lu_env_find();
+               struct lu_env _env;
+
+               if (!env) {
+                       env = &_env;
+                       rc = lu_env_init(env, ldt->ldt_ctx_tags);
+                       LASSERT(rc == 0);
+                       lu_env_add(env);
+               }
+               ldt->ldt_ops->ldto_device_fini(env, d);
+               if (env == &_env) {
+                       lu_env_remove(env);
+                       lu_env_fini(env);
                }
        }
 
@@ -897,19 +922,6 @@ static inline int obd_fid_alloc(const struct lu_env *env,
        RETURN(rc);
 }
 
-static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
-{
-        int rc;
-        ENTRY;
-
-       if (!exp->exp_obd->obd_type ||
-           !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
-               RETURN(0);
-
-        rc = OBP(exp->exp_obd, ping)(env, exp);
-        RETURN(rc);
-}
-
 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
 {
         int rc;
@@ -996,8 +1008,8 @@ static inline int obd_statfs_async(struct obd_export *exp,
                                   time64_t max_age,
                                   struct ptlrpc_request_set *rqset)
 {
-       int rc = 0;
        struct obd_device *obd;
+       int rc = 0;
 
        ENTRY;
 
@@ -1006,28 +1018,15 @@ static inline int obd_statfs_async(struct obd_export *exp,
 
        obd = exp->exp_obd;
        if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
-               CERROR("%s: no %s operation\n", obd->obd_name, __func__);
-               RETURN(-EOPNOTSUPP);
+               rc = -EOPNOTSUPP;
+               CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
+               RETURN(rc);
        }
 
-       CDEBUG(D_SUPER, "%s: osfs %p age %lld, max_age %lld\n",
-              obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
-       if (obd->obd_osfs_age < max_age) {
-               rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
-       } else {
-               CDEBUG(D_SUPER,
-                      "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
-                      obd->obd_name, &obd->obd_osfs,
-                      obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
-                      obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
-               spin_lock(&obd->obd_osfs_lock);
-               memcpy(oinfo->oi_osfs, &obd->obd_osfs,
-                      sizeof(*oinfo->oi_osfs));
-               spin_unlock(&obd->obd_osfs_lock);
-               oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
-               if (oinfo->oi_cb_up)
-                       oinfo->oi_cb_up(oinfo, 0);
-       }
+       CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
+              obd->obd_name, obd->obd_osfs_age, max_age);
+       rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
+
        RETURN(rc);
 }
 
@@ -1037,38 +1036,56 @@ static inline int obd_statfs_async(struct obd_export *exp,
  */
 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
                             struct obd_statfs *osfs, time64_t max_age,
-                             __u32 flags)
+                            __u32 flags)
 {
-        int rc = 0;
-        struct obd_device *obd = exp->exp_obd;
-        ENTRY;
+       struct obd_device *obd = exp->exp_obd;
+       int rc = 0;
 
-        if (obd == NULL)
-                RETURN(-EINVAL);
+       ENTRY;
+       if (unlikely(obd == NULL))
+               RETURN(-EINVAL);
 
        OBD_CHECK_DEV_ACTIVE(obd);
 
-       if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
+       if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
                CERROR("%s: no %s operation\n", obd->obd_name, __func__);
                RETURN(-EOPNOTSUPP);
        }
 
-       CDEBUG(D_SUPER, "osfs %lld, max_age %lld\n",
-               obd->obd_osfs_age, max_age);
+       CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
+              obd->obd_name, obd->obd_osfs_age, max_age);
        /* ignore cache if aggregated isn't expected */
        if (obd->obd_osfs_age < max_age ||
            ((obd->obd_osfs.os_state & OS_STATE_SUM) &&
             !(flags & OBD_STATFS_SUM))) {
-                rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
-                if (rc == 0) {
+               bool update_age = false;
+               /* the RPC will block anyway, so avoid sending many at once */
+               rc = mutex_lock_interruptible(&obd->obd_dev_mutex);
+               if (rc)
+                       RETURN(rc);
+               if (obd->obd_osfs_age < max_age ||
+                   ((obd->obd_osfs.os_state & OS_STATE_SUM) &&
+                    !(flags & OBD_STATFS_SUM))) {
+                       rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
+                       update_age = true;
+               } else {
+                       CDEBUG(D_SUPER,
+                              "%s: new %p cache blocks %llu/%llu objects %llu/%llu\n",
+                              obd->obd_name, &obd->obd_osfs,
+                              obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
+                              obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
+               }
+               if (rc == 0) {
                        spin_lock(&obd->obd_osfs_lock);
                        memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
-                       obd->obd_osfs_age = ktime_get_seconds();
+                       if (update_age)
+                               obd->obd_osfs_age = ktime_get_seconds();
                        spin_unlock(&obd->obd_osfs_lock);
                }
+               mutex_unlock(&obd->obd_dev_mutex);
        } else {
-               CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
-                      " objects %llu/%llu\n",
+               CDEBUG(D_SUPER,
+                      "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
                       obd->obd_name, &obd->obd_osfs,
                       obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
                       obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
@@ -1109,8 +1126,9 @@ static inline int obd_commitrw(const struct lu_env *env, int cmd,
                               struct obd_export *exp, struct obdo *oa,
                               int objcount, struct obd_ioobj *obj,
                               struct niobuf_remote *rnb, int pages,
-                              struct niobuf_local *local, int rc)
+                              struct niobuf_local *local, const int orig_rc)
 {
+       int rc;
        ENTRY;
 
        rc = exp_check_ops(exp);
@@ -1124,7 +1142,7 @@ static inline int obd_commitrw(const struct lu_env *env, int cmd,
        }
 
        rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
-                                        rnb, pages, local, rc);
+                                        rnb, pages, local, orig_rc);
 
        RETURN(rc);
 }
@@ -1172,7 +1190,10 @@ static inline int obd_notify(struct obd_device *obd,
 {
        int rc;
        ENTRY;
-       OBD_CHECK_DEV(obd);
+
+       rc = obd_check_dev(obd);
+       if (rc)
+               return rc;
 
        if (!obd->obd_set_up) {
                CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
@@ -1261,8 +1282,13 @@ static inline int obd_health_check(const struct lu_env *env,
 static inline int obd_register_observer(struct obd_device *obd,
                                         struct obd_device *observer)
 {
+       int rc;
         ENTRY;
-        OBD_CHECK_DEV(obd);
+
+       rc = obd_check_dev(obd);
+       if (rc)
+               return rc;
+
        down_write(&obd->obd_observer_link_sem);
         if (obd->obd_observer && observer) {
                up_write(&obd->obd_observer_link_sem);
@@ -1757,24 +1783,22 @@ static inline int md_unpackmd(struct obd_export *exp,
        return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
 }
 
-/* OBD Metadata Support */
-
-extern int obd_init_caches(void);
-extern void obd_cleanup_caches(void);
+static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
+                          int *rcs, struct ptlrpc_request_set *set)
+{
+       int rc;
 
-/* support routines */
-extern struct kmem_cache *obdo_cachep;
+       rc = exp_check_ops(exp);
+       if (rc)
+               return rc;
 
-#define OBDO_ALLOC(ptr)                                                       \
-do {                                                                          \
-       OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS);             \
-} while(0)
+       return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
+}
 
-#define OBDO_FREE(ptr)                                                        \
-do {                                                                          \
-        OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
-} while(0)
+/* OBD Metadata Support */
 
+extern int obd_init_caches(void);
+extern void obd_cleanup_caches(void);
 
 typedef int (*register_lwp_cb)(void *data);
 
@@ -1806,15 +1830,6 @@ int lustre_register_fs(void);
 int lustre_unregister_fs(void);
 int lustre_check_exclusion(struct super_block *sb, char *svname);
 
-typedef __u8 class_uuid_t[16];
-static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
-{
-       snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
-                "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-                uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
-                uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
-}
-
 /* lustre_peer.c    */
 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
 int class_add_uuid(const char *uuid, __u64 nid);
@@ -1824,21 +1839,17 @@ int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
 /* class_obd.c */
 extern char obd_jobid_name[];
 
-/* prng.c */
-#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
-
 /* statfs_pack.c */
 struct kstatfs;
 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
 
 /* root squash info */
-struct rw_semaphore;
 struct root_squash_info {
        uid_t                   rsi_uid;
        gid_t                   rsi_gid;
        struct list_head        rsi_nosquash_nids;
-       struct rw_semaphore     rsi_sem;
+       spinlock_t              rsi_lock;
 };
 
 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
@@ -1848,4 +1859,15 @@ extern struct miscdevice obd_psdev;
 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
 int class_procfs_init(void);
 int class_procfs_clean(void);
+
+extern void obd_heat_add(struct obd_heat_instance *instance,
+                        unsigned int time_second, __u64 count,
+                        unsigned int weight, unsigned int period_second);
+extern void obd_heat_decay(struct obd_heat_instance *instance,
+                          __u64 time_second, unsigned int weight,
+                          unsigned int period_second);
+extern __u64 obd_heat_get(struct obd_heat_instance *instance,
+                         unsigned int time_second, unsigned int weight,
+                         unsigned int period_second);
+extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
 #endif /* __LINUX_OBD_CLASS_H */