Whamcloud - gitweb
LU-13437 mdt: don't fetch LOOKUP lock for remote object
[fs/lustre-release.git] / lustre / include / obd_class.h
index 359e7ef..2b2f2fa 100644 (file)
@@ -58,15 +58,18 @@ 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 *);
 #ifdef HAVE_SERVER_SUPPORT
-struct obd_type *class_setup_tunables(const char *name);
+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,
+int class_register_type(const struct obd_ops *dt_ops,
+                       const struct md_ops *md_ops, bool enable_proc,
                        struct lprocfs_vars *module_vars,
                        const char *nm, struct lu_device_type *ldt);
 int class_unregister_type(const char *nm);
@@ -83,12 +86,12 @@ struct obd_device *class_name2obd(const char *name);
 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,
-                                          struct obd_uuid *grp_uuid);
-struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
-                                           int *next);
-struct obd_device * class_num2obd(int num);
+struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
+                                        const char *type_name,
+                                        struct obd_uuid *grp_uuid);
+struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
+                                         int *next);
+struct obd_device *class_num2obd(int num);
 int get_devices_count(void);
 
 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
@@ -127,10 +130,8 @@ __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
 
-__u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
-                          struct lookup_intent *it);
-void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
-                         struct lookup_intent *it, __u16 tag);
+__u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
+void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
 
 struct llog_handle;
 struct llog_rec_hdr;
@@ -156,8 +157,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);
@@ -249,6 +248,7 @@ static inline bool logname_is_barrier(const char *logname)
 /* list of active configuration logs  */
 struct config_llog_data {
        struct ldlm_res_id          cld_resid;
+       struct lustre_handle        cld_lockh;
        struct config_llog_instance cld_cfg;
        struct list_head            cld_list_chain;/* on config_llog_list */
        atomic_t                    cld_refcount;
@@ -348,7 +348,7 @@ extern void (*class_export_dump_hook)(struct obd_export *);
 /* genops.c */
 struct obd_export *class_export_get(struct obd_export *exp);
 void class_export_put(struct obd_export *exp);
-struct obd_export *class_new_export(struct obd_device *obddev,
+struct obd_export *class_new_export(struct obd_device *obd,
                                     struct obd_uuid *cluuid);
 struct obd_export *class_new_export_self(struct obd_device *obd,
                                         struct obd_uuid *uuid);
@@ -359,15 +359,17 @@ 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);
 int class_disconnect(struct obd_export *exp);
 void class_fail_export(struct obd_export *exp);
 int class_connected_export(struct obd_export *exp);
-void class_disconnect_exports(struct obd_device *obddev);
+void class_disconnect_exports(struct obd_device *obd);
 int class_manual_cleanup(struct obd_device *obd);
 void class_disconnect_stale_exports(struct obd_device *,
                                     int (*test_export)(struct obd_export *));
@@ -529,42 +531,46 @@ static inline int obd_set_info_async(const struct lu_env *env,
 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
 {
         int rc;
-       struct lu_device_type *ldt = obd->obd_type->typ_lu;
-       struct lu_device *d;
+       struct obd_type *type = obd->obd_type;
+       struct lu_device_type *ldt;
 
-        ENTRY;
+       ENTRY;
 
-        if (ldt != NULL) {
-                struct lu_context  session_ctx;
-                struct lu_env env;
-                lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
-                session_ctx.lc_thread = NULL;
-                lu_context_enter(&session_ctx);
+       wait_var_event(&type->typ_lu,
+                      smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
+       ldt = type->typ_lu;
+       if (ldt != NULL) {
+               struct lu_context session_ctx;
+               struct lu_env env;
 
-                rc = lu_env_init(&env, ldt->ldt_ctx_tags);
-                if (rc == 0) {
-                        env.le_ses = &session_ctx;
-                        d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
-                        lu_env_fini(&env);
-                        if (!IS_ERR(d)) {
-                                obd->obd_lu_dev = d;
-                                d->ld_obd = obd;
-                                rc = 0;
-                        } else
-                                rc = PTR_ERR(d);
-                }
-                lu_context_exit(&session_ctx);
-                lu_context_fini(&session_ctx);
+               lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
+               session_ctx.lc_thread = NULL;
+               lu_context_enter(&session_ctx);
 
-        } else {
+               rc = lu_env_init(&env, ldt->ldt_ctx_tags);
+               if (rc == 0) {
+                       struct lu_device *dev;
+                       env.le_ses = &session_ctx;
+                       dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
+                       lu_env_fini(&env);
+                       if (!IS_ERR(dev)) {
+                               obd->obd_lu_dev = dev;
+                               dev->ld_obd = obd;
+                               rc = 0;
+                       } else
+                               rc = PTR_ERR(dev);
+               }
+               lu_context_exit(&session_ctx);
+               lu_context_fini(&session_ctx);
+       } else {
                if (!obd->obd_type->typ_dt_ops->o_setup) {
                        CERROR("%s: no %s operation\n", obd->obd_name,
                               __func__);
                        RETURN(-EOPNOTSUPP);
                }
-                rc = OBP(obd, setup)(obd, cfg);
-        }
-        RETURN(rc);
+               rc = OBP(obd, setup)(obd, cfg);
+       }
+       RETURN(rc);
 }
 
 static inline int obd_precleanup(struct obd_device *obd)
@@ -576,12 +582,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);
                }
        }
 
@@ -1016,21 +1029,8 @@ static inline int obd_statfs_async(struct obd_export *exp,
 
        CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
               obd->obd_name, 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);
-       }
+       rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
+
        RETURN(rc);
 }
 
@@ -1060,16 +1060,35 @@ static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
               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) &&
+           ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
             !(flags & OBD_STATFS_SUM))) {
-               rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
+               /* 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_STATFS_SUM) &&
+                    !(flags & OBD_STATFS_SUM))) {
+                       rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
+               } else {
+                       mutex_unlock(&obd->obd_dev_mutex);
+                       GOTO(cached, rc = 0);
+               }
                if (rc == 0) {
+                       CDEBUG(D_SUPER,
+                              "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
+                              obd->obd_name, &obd->obd_osfs,
+                              osfs->os_bavail, osfs->os_blocks,
+                              osfs->os_ffree, osfs->os_files);
+
                        spin_lock(&obd->obd_osfs_lock);
                        memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
                        obd->obd_osfs_age = ktime_get_seconds();
                        spin_unlock(&obd->obd_osfs_lock);
                }
+               mutex_unlock(&obd->obd_dev_mutex);
        } else {
+cached:
                CDEBUG(D_SUPER,
                       "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
                       obd->obd_name, &obd->obd_osfs,
@@ -1572,6 +1591,7 @@ static inline int md_free_lustre_md(struct obd_export *exp,
 }
 
 static inline int md_merge_attr(struct obd_export *exp,
+                               const struct lu_fid *fid,
                                const struct lmv_stripe_md *lsm,
                                struct cl_attr *attr,
                                ldlm_blocking_callback cb)
@@ -1582,7 +1602,7 @@ static inline int md_merge_attr(struct obd_export *exp,
        if (rc)
                return rc;
 
-       return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
+       return MDP(exp->exp_obd, merge_attr)(exp, fid, lsm, attr, cb);
 }
 
 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
@@ -1769,6 +1789,18 @@ static inline int md_unpackmd(struct obd_export *exp,
        return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
 }
 
+static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
+                          int *rcs, struct ptlrpc_request_set *set)
+{
+       int rc;
+
+       rc = exp_check_ops(exp);
+       if (rc)
+               return rc;
+
+       return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
+}
+
 /* OBD Metadata Support */
 
 extern int obd_init_caches(void);
@@ -1819,12 +1851,11 @@ 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);