#define OUT_UPDATE_BUFFER_SIZE_ADD 4096
#define OUT_UPDATE_BUFFER_SIZE_MAX (256 * 4096) /* 1MB update size now */
-/**
- * resize update buffer
- *
- * Extend the update buffer by new_size.
- *
- * \param[in] ubuf update buffer to be extended
- * \param[in] new_size new size of the update buffer
- *
- * \retval 0 if extending succeeds.
- * \retval negative errno if extending fails.
- */
-static int update_buffer_resize(struct update_buffer *ubuf, size_t new_size)
-{
- struct object_update_request *ureq;
-
- if (new_size > ubuf->ub_req_size)
- return 0;
-
- OBD_ALLOC_LARGE(ureq, new_size);
- if (ureq == NULL)
- return -ENOMEM;
-
- memcpy(ureq, ubuf->ub_req, ubuf->ub_req_size);
- OBD_FREE_LARGE(ubuf->ub_req, ubuf->ub_req_size);
-
- ubuf->ub_req = ureq;
- ubuf->ub_req_size = new_size;
-
- return 0;
+const char *update_op_str(__u16 opc)
+{
+ static const char *opc_str[] = {
+ [OUT_START] = "start",
+ [OUT_CREATE] = "create",
+ [OUT_DESTROY] = "destroy",
+ [OUT_REF_ADD] = "ref_add",
+ [OUT_REF_DEL] = "ref_del" ,
+ [OUT_ATTR_SET] = "attr_set",
+ [OUT_ATTR_GET] = "attr_get",
+ [OUT_XATTR_SET] = "xattr_set",
+ [OUT_XATTR_GET] = "xattr_get",
+ [OUT_INDEX_LOOKUP] = "lookup",
+ [OUT_INDEX_INSERT] = "insert",
+ [OUT_INDEX_DELETE] = "delete",
+ [OUT_WRITE] = "write",
+ [OUT_XATTR_DEL] = "xattr_del",
+ };
+
+ if (opc < ARRAY_SIZE(opc_str) && opc_str[opc] != NULL)
+ return opc_str[opc];
+ else
+ return "unknown";
}
+EXPORT_SYMBOL(update_op_str);
/**
- * Pack the header of object_update_request
+ * Fill object update header
*
- * Packs updates into the update_buffer header, which will either be sent to
- * the remote MDT or stored in the local update log. The maximum update buffer
- * size is 1MB for now.
+ * Only fill the object update header, and parameters will be filled later
+ * in other functions.
*
- * \param[in] env execution environment
- * \param[in] ubuf update bufer which it will pack the update in
- * \param[in] op update operation
- * \param[in] fid object FID for this update
- * \param[in] param_count parameters count for this update
- * \param[in] lens each parameters length of this update
- * \param[in] batchid batchid(transaction no) of this update
+ * \params[in] env execution environment
+ * \params[in] update object update to be filled
+ * \params[in] max_update_size maximum object update size, if the current
+ * update length equals or exceeds the size, it
+ * will return -E2BIG.
+ * \params[in] update_op update type
+ * \params[in] fid object FID of the update
+ * \params[in] params_count the count of the update parameters
+ * \params[in] params_sizes the length of each parameters
*
- * \retval 0 pack update succeed.
- * \retval negative errno pack update failed.
- **/
-static struct object_update *
-out_update_header_pack(const struct lu_env *env, struct update_buffer *ubuf,
- enum update_type op, const struct lu_fid *fid,
- int params_count, __u16 *param_sizes, __u64 batchid)
+ * \retval 0 if packing succeeds.
+ * \retval -E2BIG if packing exceeds the maximum length.
+ */
+int out_update_header_pack(const struct lu_env *env,
+ struct object_update *update, size_t max_update_size,
+ enum update_type update_op, const struct lu_fid *fid,
+ unsigned int param_count, __u16 *params_sizes)
{
- struct object_update_request *ureq = ubuf->ub_req;
- size_t ureq_size = ubuf->ub_req_size;
- struct object_update *obj_update;
struct object_update_param *param;
- size_t update_size;
- int rc = 0;
unsigned int i;
- ENTRY;
-
- /* Check update size to make sure it can fit into the buffer */
- ureq_size = object_update_request_size(ureq);
- update_size = offsetof(struct object_update, ou_params[0]);
- for (i = 0; i < params_count; i++)
- update_size += cfs_size_round(param_sizes[i] + sizeof(*param));
-
- if (unlikely(cfs_size_round(ureq_size + update_size) >
- ubuf->ub_req_size)) {
- size_t new_size = ubuf->ub_req_size;
-
- /* enlarge object update request size */
- while (new_size <
- cfs_size_round(ureq_size + update_size))
- new_size += OUT_UPDATE_BUFFER_SIZE_ADD;
- if (new_size >= OUT_UPDATE_BUFFER_SIZE_MAX)
- RETURN(ERR_PTR(-E2BIG));
+ size_t update_size;
- rc = update_buffer_resize(ubuf, new_size);
- if (rc < 0)
- RETURN(ERR_PTR(rc));
+ /* Check whether the packing exceeding the maxima update length */
+ update_size = sizeof(*update);
+ for (i = 0; i < param_count; i++)
+ update_size += cfs_size_round(sizeof(*param) + params_sizes[i]);
- ureq = ubuf->ub_req;
- }
+ if (unlikely(update_size >= max_update_size))
+ return -E2BIG;
- /* fill the update into the update buffer */
- obj_update = (struct object_update *)((char *)ureq + ureq_size);
- obj_update->ou_fid = *fid;
- obj_update->ou_type = op;
- obj_update->ou_params_count = (__u16)params_count;
- obj_update->ou_batchid = batchid;
- param = &obj_update->ou_params[0];
- for (i = 0; i < params_count; i++) {
- param->oup_len = param_sizes[i];
+ update->ou_fid = *fid;
+ update->ou_type = update_op;
+ update->ou_params_count = param_count;
+ param = &update->ou_params[0];
+ for (i = 0; i < param_count; i++) {
+ param->oup_len = params_sizes[i];
param = (struct object_update_param *)((char *)param +
object_update_param_size(param));
}
- CDEBUG(D_INFO, "%p "DFID" idx %u: op %d params %d:%d\n",
- ureq, PFID(fid), ureq->ourq_count, op, params_count,
- (int)update_size);
- ureq->ourq_count++;
-
- RETURN(obj_update);
+ return 0;
}
/**
* Packs one update into the update_buffer.
*
* \param[in] env execution environment
- * \param[in] ubuf bufer where update will be packed
+ * \param[in] update update to be packed
+ * \param[in] max_update_size *maximum size of \a update
* \param[in] op update operation (enum update_type)
* \param[in] fid object FID for this update
* \param[in] param_count number of parameters for this update
* \param[in] param_sizes array of parameters length of this update
* \param[in] param_bufs parameter buffers
- * \param[in] batchid transaction no of this update, plus mdt_index, which
- * will be globally unique
*
* \retval = 0 if updates packing succeeds
* \retval negative errno if updates packing fails
**/
-int out_update_pack(const struct lu_env *env, struct update_buffer *ubuf,
- enum update_type op, const struct lu_fid *fid,
- int params_count, __u16 *param_sizes,
- const void **param_bufs, __u64 batchid)
+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 param_count,
+ __u16 *param_sizes, const void **param_bufs)
{
- struct object_update *update;
struct object_update_param *param;
unsigned int i;
+ int rc;
ENTRY;
- update = out_update_header_pack(env, ubuf, op, fid, params_count,
- param_sizes, batchid);
- if (IS_ERR(update))
- RETURN(PTR_ERR(update));
+ rc = out_update_header_pack(env, update, max_update_size, op, fid,
+ param_count, param_sizes);
+ if (rc != 0)
+ RETURN(rc);
param = &update->ou_params[0];
- for (i = 0; i < params_count; i++) {
+ for (i = 0; i < param_count; i++) {
memcpy(¶m->oup_buf[0], param_bufs[i], param_sizes[i]);
param = (struct object_update_param *)((char *)param +
object_update_param_size(param));
* \param[in] env execution environment
* \param[in] ubuf update buffer
* \param[in] fid fid of this object for the update
- * \param[in] batchid batch id of this update
*
* \retval 0 if insertion succeeds.
* \retval negative errno if insertion fails.
*/
-int out_create_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, struct lu_attr *attr,
- struct dt_allocation_hint *hint,
- struct dt_object_format *dof, __u64 batchid)
+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)
{
struct obdo *obdo;
__u16 sizes[2] = {sizeof(*obdo), 0};
int buf_count = 1;
- const struct lu_fid *fid1 = NULL;
- struct object_update *update;
+ const struct lu_fid *parent_fid = NULL;
+ int rc;
ENTRY;
if (hint != NULL && hint->dah_parent) {
- fid1 = lu_object_fid(&hint->dah_parent->do_lu);
- sizes[1] = sizeof(*fid1);
+ parent_fid = lu_object_fid(&hint->dah_parent->do_lu);
+ sizes[1] = sizeof(*parent_fid);
buf_count++;
}
- update = out_update_header_pack(env, ubuf, OUT_CREATE, fid,
- buf_count, sizes, batchid);
- if (IS_ERR(update))
- RETURN(PTR_ERR(update));
+ rc = out_update_header_pack(env, update, max_update_size, OUT_CREATE,
+ fid, buf_count, sizes);
+ if (rc != 0)
+ RETURN(rc);
obdo = object_update_param_get(update, 0, NULL);
+ LASSERT(obdo != NULL);
obdo->o_valid = 0;
obdo_from_la(obdo, attr, attr->la_valid);
lustre_set_wire_obdo(NULL, obdo, obdo);
- if (fid1 != NULL) {
- struct lu_fid *fid;
- fid = object_update_param_get(update, 1, NULL);
- fid_cpu_to_le(fid, fid1);
+
+ if (parent_fid != NULL) {
+ struct lu_fid *tmp;
+
+ tmp = object_update_param_get(update, 1, NULL);
+ LASSERT(tmp != NULL);
+ fid_cpu_to_le(tmp, parent_fid);
}
RETURN(0);
}
EXPORT_SYMBOL(out_create_pack);
-int out_ref_del_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, __u64 batchid)
+int out_ref_del_pack(const struct lu_env *env, struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid)
{
- return out_update_pack(env, ubuf, OUT_REF_DEL, fid, 0, NULL, NULL,
- batchid);
+ return out_update_pack(env, update, max_update_size, OUT_REF_DEL, fid,
+ 0, NULL, NULL);
}
EXPORT_SYMBOL(out_ref_del_pack);
-int out_ref_add_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, __u64 batchid)
+int out_ref_add_pack(const struct lu_env *env, struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid)
{
- return out_update_pack(env, ubuf, OUT_REF_ADD, fid, 0, NULL, NULL,
- batchid);
+ return out_update_pack(env, update, max_update_size, OUT_REF_ADD, fid,
+ 0, NULL, NULL);
}
EXPORT_SYMBOL(out_ref_add_pack);
-int out_attr_set_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const struct lu_attr *attr,
- __u64 batchid)
+int out_attr_set_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 object_update *update;
struct obdo *obdo;
__u16 size = sizeof(*obdo);
+ int rc;
ENTRY;
- update = out_update_header_pack(env, ubuf, OUT_ATTR_SET, fid, 1,
- &size, batchid);
- if (IS_ERR(update))
- RETURN(PTR_ERR(update));
+ rc = out_update_header_pack(env, update, max_update_size,
+ OUT_ATTR_SET, fid, 1, &size);
+ if (rc != 0)
+ RETURN(rc);
obdo = object_update_param_get(update, 0, NULL);
+ LASSERT(obdo != NULL);
obdo->o_valid = 0;
obdo_from_la(obdo, attr, attr->la_valid);
lustre_set_wire_obdo(NULL, obdo, obdo);
}
EXPORT_SYMBOL(out_attr_set_pack);
-int out_xattr_set_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const struct lu_buf *buf,
- const char *name, int flag, __u64 batchid)
+int out_xattr_set_pack(const struct lu_env *env, struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid,
+ const struct lu_buf *buf, const char *name, __u32 flag)
{
__u16 sizes[3] = {strlen(name) + 1, buf->lb_len, sizeof(flag)};
const void *bufs[3] = {(char *)name, (char *)buf->lb_buf,
(char *)&flag};
- return out_update_pack(env, ubuf, OUT_XATTR_SET, fid,
- ARRAY_SIZE(sizes), sizes, bufs, batchid);
+ return out_update_pack(env, update, max_update_size, OUT_XATTR_SET,
+ fid, ARRAY_SIZE(sizes), sizes, bufs);
}
EXPORT_SYMBOL(out_xattr_set_pack);
-int out_xattr_del_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const char *name,
- __u64 batchid)
+int out_xattr_del_pack(const struct lu_env *env, struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid,
+ const char *name)
{
__u16 size = strlen(name) + 1;
- return out_update_pack(env, ubuf, OUT_XATTR_DEL, fid, 1, &size,
- (const void **)&name, batchid);
+ return out_update_pack(env, update, max_update_size, OUT_XATTR_DEL,
+ fid, 1, &size, (const void **)&name);
}
EXPORT_SYMBOL(out_xattr_del_pack);
-int out_index_insert_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const struct dt_rec *rec,
- const struct dt_key *key, __u64 batchid)
+int out_index_insert_pack(const struct lu_env *env,
+ struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid,
+ const struct dt_rec *rec, const struct dt_key *key)
{
struct dt_insert_rec *rec1 = (struct dt_insert_rec *)rec;
struct lu_fid rec_fid;
fid_cpu_to_le(&rec_fid, rec1->rec_fid);
- return out_update_pack(env, ubuf, OUT_INDEX_INSERT, fid,
- ARRAY_SIZE(sizes), sizes, bufs, batchid);
+ return out_update_pack(env, update, max_update_size, OUT_INDEX_INSERT,
+ fid, ARRAY_SIZE(sizes), sizes, bufs);
}
EXPORT_SYMBOL(out_index_insert_pack);
-int out_index_delete_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const struct dt_key *key,
- __u64 batchid)
+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)
{
__u16 size = strlen((char *)key) + 1;
const void *buf = key;
- return out_update_pack(env, ubuf, OUT_INDEX_DELETE, fid, 1, &size,
- &buf, batchid);
+ return out_update_pack(env, update, max_update_size, OUT_INDEX_DELETE,
+ fid, 1, &size, &buf);
}
EXPORT_SYMBOL(out_index_delete_pack);
int out_object_destroy_pack(const struct lu_env *env,
- struct update_buffer *ubuf,
- const struct lu_fid *fid, __u64 batchid)
+ struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid)
{
- return out_update_pack(env, ubuf, OUT_DESTROY, fid, 0, NULL, NULL,
- batchid);
+ return out_update_pack(env, update, max_update_size, OUT_DESTROY, fid,
+ 0, NULL, NULL);
}
EXPORT_SYMBOL(out_object_destroy_pack);
-int out_write_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const struct lu_buf *buf,
- loff_t pos, __u64 batchid)
+int out_write_pack(const struct lu_env *env, struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid,
+ const struct lu_buf *buf, __u64 pos)
{
__u16 sizes[2] = {buf->lb_len, sizeof(pos)};
const void *bufs[2] = {(char *)buf->lb_buf, (char *)&pos};
pos = cpu_to_le64(pos);
- rc = out_update_pack(env, ubuf, OUT_WRITE, fid, ARRAY_SIZE(sizes),
- sizes, bufs, batchid);
+ rc = out_update_pack(env, update, max_update_size, OUT_WRITE, fid,
+ ARRAY_SIZE(sizes), sizes, bufs);
return rc;
}
EXPORT_SYMBOL(out_write_pack);
* \param[in] fid fid of this object for the update
* \param[in] ubuf update buffer
*
- * \retval 0 if packing succeeds.
- * \retval negative errno if packing fails.
- */
-int out_index_lookup_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, struct dt_rec *rec,
- const struct dt_key *key)
+ * \retval = 0 pack succeed.
+ * < 0 pack failed.
+ **/
+int out_index_lookup_pack(const struct lu_env *env,
+ struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid,
+ struct dt_rec *rec, const struct dt_key *key)
{
const void *name = key;
__u16 size = strlen((char *)name) + 1;
- return out_update_pack(env, ubuf, OUT_INDEX_LOOKUP, fid, 1, &size,
- &name, 0);
+ return out_update_pack(env, update, max_update_size, OUT_INDEX_LOOKUP,
+ fid, 1, &size, &name);
}
EXPORT_SYMBOL(out_index_lookup_pack);
-int out_attr_get_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid)
+int out_attr_get_pack(const struct lu_env *env, struct object_update *update,
+ size_t max_update_size, const struct lu_fid *fid)
{
- return out_update_pack(env, ubuf, OUT_ATTR_GET, fid, 0, NULL, NULL, 0);
+ return out_update_pack(env, update, max_update_size, OUT_ATTR_GET,
+ fid, 0, NULL, NULL);
}
EXPORT_SYMBOL(out_attr_get_pack);
-int out_xattr_get_pack(const struct lu_env *env, struct update_buffer *ubuf,
- const struct lu_fid *fid, const char *name)
+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)
{
__u16 size;
LASSERT(name != NULL);
size = strlen(name) + 1;
- return out_update_pack(env, ubuf, OUT_XATTR_GET, fid, 1, &size,
- (const void **)&name, 0);
+
+ return out_update_pack(env, update, max_update_size, OUT_XATTR_GET,
+ fid, 1, &size, (const void **)&name);
}
EXPORT_SYMBOL(out_xattr_get_pack);