Whamcloud - gitweb
LU-10092 First phase of persistent client cache project merging
[fs/lustre-release.git] / lustre / include / lustre_update.h
index c2994b1..78cd3d4 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2013, 2014, Intel Corporation.
+ * Copyright (c) 2013, 2017, Intel Corporation.
  */
 /*
  * lustre/include/lustre_update.h
 
 #ifndef _LUSTRE_UPDATE_H
 #define _LUSTRE_UPDATE_H
-#include <lustre_net.h>
 #include <dt_object.h>
+#include <lustre_net.h>
+#include <obj_update.h>
 
-#define OUT_UPDATE_INIT_BUFFER_SIZE    4096
-/* 16KB, the current biggest size is llog header(8KB) */
-#define OUT_UPDATE_REPLY_SIZE          16384
+#define OUT_UPDATE_REPLY_SIZE          4096
+#define OUT_BULK_BUFFER_SIZE           4096
 
 struct dt_key;
 struct dt_rec;
 struct object_update_param;
-
-struct update_params {
-       struct object_update_param      up_params[0];
-};
+struct llog_update_record;
 
 static inline size_t update_params_size(const struct update_params *params,
                                        unsigned int param_count)
@@ -98,13 +95,6 @@ update_params_get_param_buf(const struct update_params *params, __u16 index,
        return param->oup_buf;
 }
 
-struct update_op {
-       struct lu_fid uop_fid;
-       __u16   uop_type;
-       __u16   uop_param_count;
-       __u16   uop_params_off[0];
-};
-
 static inline size_t
 update_op_size(unsigned int param_count)
 {
@@ -118,11 +108,6 @@ update_op_next_op(const struct update_op *uop)
                                update_op_size(uop->uop_param_count));
 }
 
-/* All of updates in the mulitple_update_record */
-struct update_ops {
-       struct update_op        uops_op[0];
-};
-
 static inline size_t update_ops_size(const struct update_ops *ops,
                                     unsigned int update_count)
 {
@@ -137,41 +122,6 @@ static inline size_t update_ops_size(const struct update_ops *ops,
        return total_size;
 }
 
-/*
- * This is the update record format used to store the updates in
- * disk. All updates of the operation will be stored in ur_ops.
- * All of parameters for updates of the operation will be stored
- * in ur_params.
- * To save the space of the record, parameters in ur_ops will only
- * remember their offset in ur_params, so to avoid storing duplicate
- * parameters in ur_params, which can help us save a lot space for
- * operation like creating striped directory.
- */
-struct update_records {
-       __u64                   ur_master_transno;
-       __u64                   ur_batchid;
-       __u32                   ur_flags;
-       __u32                   ur_param_count;
-       __u32                   ur_update_count;
-       struct update_ops       ur_ops;
-        /* Note ur_ops has a variable size, so comment out
-         * the following ur_params, in case some use it directly
-         * update_records->ur_params
-         *
-         * struct update_params        ur_params;
-         */
-};
-
-struct llog_update_record {
-       struct llog_rec_hdr     lur_hdr;
-       struct update_records   lur_update_rec;
-       /* Note ur_update_rec has a variable size, so comment out
-        * the following ur_tail, in case someone use it directly
-        *
-        * struct llog_rec_tail lur_tail;
-        */
-};
-
 static inline struct update_params *
 update_records_get_params(const struct update_records *record)
 {
@@ -180,26 +130,54 @@ update_records_get_params(const struct update_records *record)
                update_ops_size(&record->ur_ops, record->ur_update_count));
 }
 
+static inline struct update_param *
+update_param_next_param(const struct update_param *param)
+{
+       return (struct update_param *)((char *)param +
+                                      object_update_param_size(
+                                         (struct object_update_param *)param));
+}
+
+static inline size_t
+__update_records_size(size_t raw_size)
+{
+       return cfs_size_round(offsetof(struct update_records, ur_ops) +
+                             raw_size);
+}
+
 static inline size_t
 update_records_size(const struct update_records *record)
 {
-       struct update_params *params;
+       size_t op_size = 0;
+       size_t param_size = 0;
 
-       params = update_records_get_params(record);
+       if (record->ur_update_count > 0)
+               op_size = update_ops_size(&record->ur_ops,
+                                         record->ur_update_count);
+       if (record->ur_param_count > 0) {
+               struct update_params *params;
 
-       return cfs_size_round(offsetof(struct update_records, ur_ops) +
-              update_ops_size(&record->ur_ops, record->ur_update_count) +
-              update_params_size(params, record->ur_param_count));
+               params = update_records_get_params(record);
+               param_size = update_params_size(params, record->ur_param_count);
+       }
+
+       return __update_records_size(op_size + param_size);
 }
 
 static inline size_t
-llog_update_record_size(const struct llog_update_record *lur)
+__llog_update_record_size(size_t records_size)
 {
-       return cfs_size_round(sizeof(lur->lur_hdr) +
-                             update_records_size(&lur->lur_update_rec) +
+       return cfs_size_round(sizeof(struct llog_rec_hdr) + records_size +
                              sizeof(struct llog_rec_tail));
 }
 
+static inline size_t
+llog_update_record_size(const struct llog_update_record *lur)
+{
+       return __llog_update_record_size(
+                       update_records_size(&lur->lur_update_rec));
+}
+
 static inline struct update_op *
 update_ops_get_op(const struct update_ops *ops, unsigned int index,
                  unsigned int update_count)
@@ -236,7 +214,7 @@ static inline void
                *size = param->oup_len;
 
        if (param->oup_len == 0)
-               return NULL;
+               return ERR_PTR(-ENODATA);
 
        return (void *)&param->oup_buf[0];
 }
@@ -263,18 +241,15 @@ object_update_result_insert(struct object_update_reply *reply,
                            int rc)
 {
        struct object_update_result *update_result;
-       char *ptr;
 
        update_result = object_update_result_get(reply, index, NULL);
-       LASSERT(update_result != NULL);
+       LASSERT(update_result);
 
        update_result->our_rc = ptlrpc_status_hton(rc);
-       if (data_len > 0) {
-               LASSERT(data != NULL);
-               ptr = (char *)update_result +
-                       cfs_size_round(sizeof(struct object_update_reply));
+       if (rc >= 0) {
+               if (data_len > 0 && data)
+                       memcpy(update_result->our_data, data, data_len);
                update_result->our_datalen = data_len;
-               memcpy(ptr, data, data_len);
        }
 
        reply->ourp_lens[index] = cfs_size_round(data_len +
@@ -303,7 +278,7 @@ object_update_result_data_get(const struct object_update_reply *reply,
        lbuf->lb_buf = update_result->our_data;
        lbuf->lb_len = update_result->our_datalen;
 
-       return 0;
+       return result;
 }
 
 /**
@@ -311,11 +286,11 @@ object_update_result_data_get(const struct object_update_reply *reply,
  * distribution.
  */
 struct thandle_update_records {
-       /* All of updates for the cross-MDT operation. */
+       /* All of updates for the cross-MDT operation, vmalloc'd. */
        struct llog_update_record       *tur_update_records;
        size_t                          tur_update_records_buf_size;
 
-       /* All of parameters for the cross-MDT operation */
+       /* All of parameters for the cross-MDT operation, vmalloc'd */
        struct update_params    *tur_update_params;
        unsigned int            tur_update_param_count;
        size_t                  tur_update_params_buf_size;
@@ -327,6 +302,7 @@ struct top_multiple_thandle {
        atomic_t                tmt_refcount;
        /* Other sub transactions will be listed here. */
        struct list_head        tmt_sub_thandle_list;
+       spinlock_t              tmt_sub_lock;
 
        struct list_head        tmt_commit_list;
        /* All of update records will packed here */
@@ -336,6 +312,7 @@ struct top_multiple_thandle {
        __u64                   tmt_batchid;
        int                     tmt_result;
        __u32                   tmt_magic;
+       size_t                  tmt_record_size;
        __u32                   tmt_committed:1;
 };
 
@@ -350,12 +327,17 @@ struct top_thandle {
        struct top_multiple_thandle *tt_multiple_thandle;
 };
 
+struct sub_thandle_cookie {
+       struct llog_cookie      stc_cookie;
+       struct list_head        stc_list;
+};
+
 /* Sub thandle is used to track multiple sub thandles under one parent
  * thandle */
 struct sub_thandle {
        struct thandle          *st_sub_th;
        struct dt_device        *st_dt;
-       struct llog_cookie      st_cookie;
+       struct list_head        st_cookie_list;
        struct dt_txn_commit_cb st_commit_dcb;
        struct dt_txn_commit_cb st_stop_dcb;
        int                     st_result;
@@ -365,7 +347,8 @@ struct sub_thandle {
 
        /* If this sub thandle is committed */
        bool                    st_committed:1,
-                               st_stopped:1;
+                               st_stopped:1,
+                               st_started:1;
 };
 
 struct tx_arg;
@@ -425,15 +408,14 @@ struct thandle_exec_args {
 int out_update_pack(const struct lu_env *env, struct object_update *update,
                    size_t *max_update_size, enum update_type op,
                    const struct lu_fid *fid, unsigned int params_count,
-                   __u16 *param_sizes, const void **param_bufs);
+                   __u16 *param_sizes, const void **param_bufs,
+                   __u32 reply_size);
 int out_create_pack(const struct lu_env *env, struct object_update *update,
                    size_t *max_update_size, const struct lu_fid *fid,
                    const struct lu_attr *attr, struct dt_allocation_hint *hint,
                    struct dt_object_format *dof);
-int out_object_destroy_pack(const struct lu_env *env,
-                           struct object_update *update,
-                           size_t *max_update_size,
-                           const struct lu_fid *fid);
+int out_destroy_pack(const struct lu_env *env, struct object_update *update,
+                    size_t *max_update_size, const struct lu_fid *fid);
 int out_index_delete_pack(const struct lu_env *env,
                          struct object_update *update, size_t *max_update_size,
                          const struct lu_fid *fid, const struct dt_key *key);
@@ -470,7 +452,11 @@ int out_index_lookup_pack(const struct lu_env *env,
                          const struct dt_key *key);
 int out_xattr_get_pack(const struct lu_env *env,
                       struct object_update *update, size_t *max_update_size,
-                      const struct lu_fid *fid, const char *name);
+                      const struct lu_fid *fid, const char *name,
+                      const int bufsize);
+int out_xattr_list_pack(const struct lu_env *env, struct object_update *update,
+                      size_t *max_update_size, const struct lu_fid *fid,
+                      const int bufsize);
 int out_read_pack(const struct lu_env *env, struct object_update *update,
                  size_t *max_update_length, const struct lu_fid *fid,
                  size_t size, loff_t pos);
@@ -515,6 +501,43 @@ int sub_thandle_trans_create(const struct lu_env *env,
                             struct sub_thandle *st);
 
 /* update_records.c */
+size_t update_records_create_size(const struct lu_env *env,
+                                 const struct lu_fid *fid,
+                                 const struct lu_attr *attr,
+                                 const struct dt_allocation_hint *hint,
+                                 struct dt_object_format *dof);
+size_t update_records_attr_set_size(const struct lu_env *env,
+                                   const struct lu_fid *fid,
+                                   const struct lu_attr *attr);
+size_t update_records_ref_add_size(const struct lu_env *env,
+                                  const struct lu_fid *fid);
+size_t update_records_ref_del_size(const struct lu_env *env,
+                                  const struct lu_fid *fid);
+size_t update_records_destroy_size(const struct lu_env *env,
+                                  const struct lu_fid *fid);
+size_t update_records_index_insert_size(const struct lu_env *env,
+                                       const struct lu_fid *fid,
+                                       const struct dt_rec *rec,
+                                       const struct dt_key *key);
+size_t update_records_index_delete_size(const struct lu_env *env,
+                                       const struct lu_fid *fid,
+                                       const struct dt_key *key);
+size_t update_records_xattr_set_size(const struct lu_env *env,
+                                    const struct lu_fid *fid,
+                                    const struct lu_buf *buf,
+                                    const char *name,
+                                    __u32 flag);
+size_t update_records_xattr_del_size(const struct lu_env *env,
+                                    const struct lu_fid *fid,
+                                    const char *name);
+size_t update_records_write_size(const struct lu_env *env,
+                                const struct lu_fid *fid,
+                                const struct lu_buf *buf,
+                                __u64 pos);
+size_t update_records_punch_size(const struct lu_env *env,
+                                const struct lu_fid *fid,
+                                __u64 start, __u64 end);
+
 int update_records_create_pack(const struct lu_env *env,
                               struct update_ops *ops,
                               unsigned int *op_count,
@@ -551,14 +574,13 @@ int update_records_ref_del_pack(const struct lu_env *env,
                                unsigned int *param_count,
                                size_t *max_param_size,
                                const struct lu_fid *fid);
-int update_records_object_destroy_pack(const struct lu_env *env,
-                                      struct update_ops *ops,
-                                      unsigned int *op_count,
-                                      size_t *max_ops_size,
-                                      struct update_params *params,
-                                      unsigned int *param_count,
-                                      size_t *max_param_size,
-                                      const struct lu_fid *fid);
+int update_records_destroy_pack(const struct lu_env *env,
+                               struct update_ops *ops, unsigned int *op_count,
+                               size_t *max_ops_size,
+                               struct update_params *params,
+                               unsigned int *param_count,
+                               size_t *max_param_size,
+                               const struct lu_fid *fid);
 int update_records_index_insert_pack(const struct lu_env *env,
                                     struct update_ops *ops,
                                     unsigned int *op_count,
@@ -616,6 +638,14 @@ int update_records_punch_pack(const struct lu_env *env,
                              size_t *max_param_size,
                              const struct lu_fid *fid,
                              __u64 start, __u64 end);
+int update_records_noop_pack(const struct lu_env *env,
+                            struct update_ops *ops,
+                            unsigned int *op_count,
+                            size_t *max_ops_size,
+                            struct update_params *params,
+                            unsigned int *param_count,
+                            size_t *max_param_size,
+                            const struct lu_fid *fid);
 
 int tur_update_records_extend(struct thandle_update_records *tur,
                              size_t new_size);
@@ -663,4 +693,17 @@ int tur_update_extend(struct thandle_update_records *tur,
        }                                                               \
        ret;                                                            \
 })
+
+#define update_record_size(env, name, th, ...)                         \
+({                                                                     \
+       struct top_thandle *top_th;                                     \
+       struct top_multiple_thandle *tmt;                               \
+                                                                       \
+       top_th = container_of(th, struct top_thandle, tt_super);        \
+                                                                       \
+       LASSERT(top_th->tt_multiple_thandle != NULL);                   \
+       tmt = top_th->tt_multiple_thandle;                              \
+       tmt->tmt_record_size +=                                         \
+               update_records_##name##_size(env, __VA_ARGS__);         \
+})
 #endif