Whamcloud - gitweb
LU-7934 osp: fix tr->otr_next_id overflow
[fs/lustre-release.git] / lustre / osp / osp_internal.h
index d6cf452..3714dc2 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) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -55,8 +55,8 @@
  */
 struct osp_id_tracker {
        spinlock_t               otr_lock;
-       __u32                    otr_next_id;
-       __u32                    otr_committed_id;
+       __u64                    otr_next_id;
+       __u64                    otr_committed_id;
        /* callback is register once per diskfs -- that's the whole point */
        struct dt_txn_callback   otr_tx_cb;
        /* single node can run many clusters */
@@ -84,35 +84,46 @@ struct osp_precreate {
        wait_queue_head_t                osp_pre_user_waitq;
        /* current precreation status: working, failed, stopping? */
        int                              osp_pre_status;
-       /* how many to precreate next time */
-       int                              osp_pre_grow_count;
-       int                              osp_pre_min_grow_count;
-       int                              osp_pre_max_grow_count;
-       /* whether to grow precreation window next time or not */
-       int                              osp_pre_grow_slow;
+       /* how many objects to precreate next time */
+       int                              osp_pre_create_count;
+       int                              osp_pre_min_create_count;
+       int                              osp_pre_max_create_count;
+       /* whether to increase precreation window next time or not */
+       int                              osp_pre_create_slow;
        /* cleaning up orphans or recreating missing objects */
        int                              osp_pre_recovering;
 };
 
-/**
- * Tracking the updates being executed on this dt_device.
- */
+struct osp_update_request_sub {
+       struct object_update_request    *ours_req; /* may be vmalloc'd */
+       size_t                          ours_req_size;
+       /* Linked to osp_update_request->our_req_list */
+       struct list_head                ours_list;
+};
+
 struct osp_update_request {
        int                             our_flags;
        /* update request result */
        int                             our_rc;
 
-       /* Holding object updates sent to the remote target */
-       struct object_update_request    *our_req;
-       size_t                          our_req_size;
+       /* List of osp_update_request_sub */
+       struct list_head                our_req_list;
+       int                             our_req_nr;
+       int                             our_update_nr;
 
        struct list_head                our_cb_items;
 
        /* points to thandle if this update request belongs to one */
        struct osp_thandle              *our_th;
+
+       __u64                           our_version;
+       /* protect our_list and flag */
+       spinlock_t                      our_list_lock;
        /* linked to the list(ou_list) in osp_updates */
        struct list_head                our_list;
-       __u32                           our_req_sent:1;
+       __u32                           our_batchid;
+       __u32                           our_req_ready:1;
+
 };
 
 struct osp_updates {
@@ -189,6 +200,8 @@ struct osp_device {
        /* found records */
        struct ptlrpc_thread             opd_syn_thread;
        wait_queue_head_t                opd_syn_waitq;
+       /* list of inflight rpc */
+       struct list_head                 opd_syn_inflight_list;
        /* list of remotely committed rpc */
        struct list_head                 opd_syn_committed_there;
        /* number of changes being under sync */
@@ -202,12 +215,12 @@ struct osp_device {
        /* osd api's commit cb control structure */
        struct dt_txn_callback           opd_syn_txn_cb;
        /* last used change number -- semantically similar to transno */
-       unsigned long                    opd_syn_last_used_id;
+       __u64                            opd_syn_last_used_id;
        /* last committed change number -- semantically similar to
         * last_committed */
-       unsigned long                    opd_syn_last_committed_id;
+       __u64                            opd_syn_last_committed_id;
        /* last processed (taken from llog) id */
-       unsigned long                    opd_syn_last_processed_id;
+       __u64                            opd_syn_last_processed_id;
        struct osp_id_tracker           *opd_syn_tracker;
        struct list_head                 opd_syn_ontrack;
        /* stop processing new requests until barrier=0 */
@@ -245,10 +258,10 @@ struct osp_device {
 #define opd_pre_reserved               opd_pre->osp_pre_reserved
 #define opd_pre_user_waitq             opd_pre->osp_pre_user_waitq
 #define opd_pre_status                 opd_pre->osp_pre_status
-#define opd_pre_grow_count             opd_pre->osp_pre_grow_count
-#define opd_pre_min_grow_count         opd_pre->osp_pre_min_grow_count
-#define opd_pre_max_grow_count         opd_pre->osp_pre_max_grow_count
-#define opd_pre_grow_slow              opd_pre->osp_pre_grow_slow
+#define opd_pre_create_count           opd_pre->osp_pre_create_count
+#define opd_pre_min_create_count       opd_pre->osp_pre_min_create_count
+#define opd_pre_max_create_count       opd_pre->osp_pre_max_create_count
+#define opd_pre_create_slow            opd_pre->osp_pre_create_slow
 #define opd_pre_recovering             opd_pre->osp_pre_recovering
 
 extern struct kmem_cache *osp_object_kmem;
@@ -277,7 +290,8 @@ struct osp_object {
        struct lu_object_header opo_header;
        struct dt_object        opo_obj;
        unsigned int            opo_reserved:1,
-                               opo_non_exist:1;
+                               opo_non_exist:1,
+                               opo_stale:1;
 
        /* read/write lock for md osp object */
        struct rw_semaphore     opo_sem;
@@ -342,7 +356,6 @@ struct osp_thandle {
        struct list_head         ot_stop_dcb_list;
        struct osp_update_request *ot_our;
        atomic_t                 ot_refcount;
-       __u64                    ot_version;
 };
 
 static inline struct osp_thandle *
@@ -407,7 +420,7 @@ static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
 }
 
 struct osp_txn_info {
-       __u32   oti_current_id;
+       __u64   oti_current_id;
 };
 
 extern struct lu_context_key osp_txn_key;
@@ -583,36 +596,50 @@ update_buffer_get_update(struct object_update_request *request,
 int osp_extend_update_buffer(const struct lu_env *env,
                             struct osp_update_request *our);
 
-#define osp_update_rpc_pack(env, name, update, op, ...)                \
-({                                                             \
-       struct object_update    *object_update;                 \
-       size_t                  max_update_length;              \
-       struct object_update_request *ureq;                     \
-       int                     ret;                            \
-                                                               \
+struct osp_update_request_sub *
+osp_current_object_update_request(struct osp_update_request *our);
+
+int osp_object_update_request_create(struct osp_update_request *our,
+                                    size_t size);
+
+#define osp_update_rpc_pack(env, name, our, op, ...)                   \
+({                                                                     \
+       struct object_update    *object_update;                         \
+       size_t                  max_update_length;                      \
+       struct osp_update_request_sub *ours;                            \
+       int ret;                                                        \
+                                                                       \
        while (1) {                                                     \
-               ureq = update->our_req;                                 \
-               max_update_length = update->our_req_size -              \
-                                   object_update_request_size(ureq);   \
+               ours = osp_current_object_update_request(our);          \
+               LASSERT(ours != NULL);                                  \
+               max_update_length = ours->ours_req_size -               \
+                           object_update_request_size(ours->ours_req); \
                                                                        \
-               object_update = update_buffer_get_update(ureq,          \
-                                                ureq->ourq_count);     \
+               object_update = update_buffer_get_update(ours->ours_req,\
+                                        ours->ours_req->ourq_count);   \
                ret = out_##name##_pack(env, object_update,             \
-                                       max_update_length,              \
+                                       &max_update_length,             \
                                       __VA_ARGS__);                    \
                if (ret == -E2BIG) {                                    \
                        int rc1;                                        \
-                       /* extend the buffer and retry */               \
-                       rc1 = osp_extend_update_buffer(env, update);    \
+                       /* Create new object update request */          \
+                       rc1 = osp_object_update_request_create(our,     \
+                               max_update_length  +                    \
+                               offsetof(struct object_update_request,  \
+                                        ourq_updates[0]) + 1);         \
                        if (rc1 != 0) {                                 \
                                ret = rc1;                              \
                                break;                                  \
                        }                                               \
+                       continue;                                       \
                } else {                                                \
                        if (ret == 0) {                                 \
+                               ours->ours_req->ourq_count++;           \
+                               (our)->our_update_nr++;                 \
+                               object_update->ou_batchid =             \
+                                                    (our)->our_batchid;\
                                object_update->ou_flags |=              \
-                                                    update->our_flags; \
-                               ureq->ourq_count++;                     \
+                                                    (our)->our_flags;  \
                        }                                               \
                        break;                                          \
                }                                                       \
@@ -643,7 +670,7 @@ extern struct llog_operations osp_mds_ost_orig_logops;
 /* osp_trans.c */
 int osp_insert_async_request(const struct lu_env *env, enum update_type op,
                             struct osp_object *obj, int count, __u16 *lens,
-                            const void **bufs, void *data,
+                            const void **bufs, void *data, __u32 repsize,
                             osp_update_interpreter_t interpreter);
 
 int osp_unplug_async_request(const struct lu_env *env,
@@ -663,7 +690,8 @@ struct osp_update_request *osp_update_request_create(struct dt_device *dt);
 void osp_update_request_destroy(struct osp_update_request *update);
 
 int osp_send_update_thread(void *arg);
-int osp_check_and_set_rpc_version(struct osp_thandle *oth);
+int osp_check_and_set_rpc_version(struct osp_thandle *oth,
+                                 struct osp_object *obj);
 
 void osp_thandle_destroy(struct osp_thandle *oth);
 static inline void osp_thandle_get(struct osp_thandle *oth)
@@ -678,7 +706,7 @@ static inline void osp_thandle_put(struct osp_thandle *oth)
 }
 
 int osp_prep_update_req(const struct lu_env *env, struct obd_import *imp,
-                       const struct object_update_request *ureq,
+                       struct osp_update_request *our,
                        struct ptlrpc_request **reqp);
 int osp_remote_sync(const struct lu_env *env, struct osp_device *osp,
                    struct osp_update_request *update,
@@ -689,6 +717,7 @@ struct thandle *osp_get_storage_thandle(const struct lu_env *env,
                                        struct osp_device *osp);
 void osp_trans_callback(const struct lu_env *env,
                        struct osp_thandle *oth, int rc);
+void osp_invalidate_request(struct osp_device *osp);
 /* osp_object.c */
 int osp_attr_get(const struct lu_env *env, struct dt_object *dt,
                 struct lu_attr *attr);