static int out_index_insert(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct dt_insert_rec *rec = &tti->tti_rec; struct lu_fid *fid; char *name; __u32 *ptype; int rc = 0; size_t size; ENTRY; name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for index insert: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } fid = object_update_param_get(update, 1, &size); if (IS_ERR(fid) || size != sizeof(*fid)) { CERROR("%s: invalid fid: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(fid)); RETURN(PTR_ERR(fid)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) lustre_swab_lu_fid(fid); if (!fid_is_sane(fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO); RETURN(-EPROTO); } ptype = object_update_param_get(update, 2, &size); if (IS_ERR(ptype) || size != sizeof(*ptype)) { CERROR("%s: invalid type for index insert: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(ptype)); RETURN(PTR_ERR(ptype)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) __swab32s(ptype); rec->rec_fid = fid; rec->rec_type = *ptype; rc = out_tx_index_insert(tsi->tsi_env, obj, (const struct dt_rec *)rec, (const struct dt_key *)name, &tti->tti_tea, tti->tti_tea.ta_handle, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_create(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct dt_object_format *dof = &tti->tti_u.update.tti_update_dof; struct obdo *lobdo = &tti->tti_u.update.tti_obdo; struct lu_attr *attr = &tti->tti_attr; struct lu_fid *fid = NULL; struct obdo *wobdo; int size; int rc; ENTRY; wobdo = object_update_param_get(update, 0, &size); if (wobdo == NULL || size != sizeof(*wobdo)) { CERROR("%s: obdo is NULL, invalid RPC: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } obdo_le_to_cpu(wobdo, wobdo); lustre_get_wire_obdo(NULL, lobdo, wobdo); la_from_obdo(attr, lobdo, lobdo->o_valid); dof->dof_type = dt_mode_to_dft(attr->la_mode); if (update->ou_params_count > 1) { int size; fid = object_update_param_get(update, 1, &size); if (fid == NULL || size != sizeof(*fid)) { CERROR("%s: invalid fid: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) lustre_swab_lu_fid(fid); if (!fid_is_sane(fid)) { CERROR("%s: invalid fid "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO); RETURN(err_serious(-EPROTO)); } } if (lu_object_exists(&obj->do_lu)) RETURN(-EEXIST); rc = out_tx_create(tsi->tsi_env, obj, attr, fid, dof, &tti->tti_tea, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_xattr_set(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct lu_buf *lbuf = &tti->tti_buf; char *name; char *buf; char *tmp; int buf_len = 0; int flag; int rc; ENTRY; name = object_update_param_get(update, 0, NULL); if (name == NULL) { CERROR("%s: empty name for xattr set: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } buf = object_update_param_get(update, 1, &buf_len); if (buf == NULL || buf_len == 0) { CERROR("%s: empty buf for xattr set: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } lbuf->lb_buf = buf; lbuf->lb_len = buf_len; tmp = (char *)object_update_param_get(update, 2, NULL); if (tmp == NULL) { CERROR("%s: empty flag for xattr set: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) __swab32s((__u32 *)tmp); flag = *(int *)tmp; rc = out_tx_xattr_set(tsi->tsi_env, obj, lbuf, name, flag, &tti->tti_tea, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_attr_set(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct lu_attr *attr = &tti->tti_attr; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct obdo *lobdo = &tti->tti_u.update.tti_obdo; struct obdo *wobdo; size_t size; int rc; ENTRY; wobdo = object_update_param_get(update, 0, &size); if (IS_ERR(wobdo) || size != sizeof(*wobdo)) { CERROR("%s: empty obdo in the update: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(wobdo)); RETURN(PTR_ERR(wobdo)); } attr->la_valid = 0; attr->la_valid = 0; if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) lustre_swab_obdo(wobdo); lustre_get_wire_obdo(NULL, lobdo, wobdo); la_from_obdo(attr, lobdo, lobdo->o_valid); rc = out_tx_attr_set(tsi->tsi_env, obj, attr, &tti->tti_tea, tti->tti_tea.ta_handle, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_attr_set(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct lu_attr *attr = &tti->tti_attr; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct obdo *lobdo = &tti->tti_u.update.tti_obdo; struct obdo *wobdo; int size; int rc; ENTRY; wobdo = object_update_param_get(update, 0, &size); if (wobdo == NULL || size != sizeof(*wobdo)) { CERROR("%s: empty obdo in the update: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } attr->la_valid = 0; attr->la_valid = 0; obdo_le_to_cpu(wobdo, wobdo); lustre_get_wire_obdo(NULL, lobdo, wobdo); la_from_obdo(attr, lobdo, lobdo->o_valid); rc = out_tx_attr_set(tsi->tsi_env, obj, attr, &tti->tti_tea, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_xattr_set(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct lu_buf *lbuf = &tti->tti_buf; char *name; char *buf; __u32 *tmp; size_t buf_len = 0; int flag; size_t size = 0; int rc; ENTRY; name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for xattr set: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } /* If buffer == NULL (-ENODATA), then it might mean delete xattr */ buf = object_update_param_get(update, 1, &buf_len); if (IS_ERR(buf) && PTR_ERR(buf) != -ENODATA) RETURN(PTR_ERR(buf)); lbuf->lb_buf = buf; lbuf->lb_len = buf_len; tmp = object_update_param_get(update, 2, &size); if (IS_ERR(tmp) || size != sizeof(*tmp)) { CERROR("%s: emptry or wrong size %zu flag: rc = %ld\n", tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp)); RETURN(PTR_ERR(tmp)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) __swab32s(tmp); flag = *tmp; rc = out_tx_xattr_set(tsi->tsi_env, obj, lbuf, name, flag, &tti->tti_tea, tti->tti_tea.ta_handle, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_xattr_get(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct object_update *update = tti->tti_u.update.tti_update; struct lu_buf *lbuf = &tti->tti_buf; struct object_update_reply *reply = tti->tti_u.update.tti_update_reply; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; struct object_update_result *update_result; int idx = tti->tti_u.update.tti_update_reply_index; int rc; ENTRY; if (!lu_object_exists(&obj->do_lu)) { set_bit(LU_OBJECT_HEARD_BANSHEE, &obj->do_lu.lo_header->loh_flags); RETURN(-ENOENT); } name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for xattr get: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } update_result = object_update_result_get(reply, 0, NULL); if (update_result == NULL) { CERROR("%s: empty name for xattr get: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(-EPROTO); } lbuf->lb_len = (int)tti->tti_u.update.tti_update->ou_result_size; lbuf->lb_buf = update_result->our_data; if (lbuf->lb_len == 0) lbuf->lb_buf = 0; dt_read_lock(env, obj, MOR_TGT_CHILD); rc = dt_xattr_get(env, obj, lbuf, name); dt_read_unlock(env, obj); if (rc < 0) lbuf->lb_len = 0; CDEBUG(D_INFO, "%s: "DFID" get xattr %s len %d\n", tgt_name(tsi->tsi_tgt), PFID(lu_object_fid(&obj->do_lu)), name, (int)lbuf->lb_len); GOTO(out, rc); out: object_update_result_insert(reply, lbuf->lb_buf, lbuf->lb_len, idx, rc); RETURN(0); }
static int out_index_insert(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct lu_fid *fid; char *name; int rc = 0; int size; ENTRY; name = object_update_param_get(update, 0, NULL); if (name == NULL) { CERROR("%s: empty name for index insert: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } fid = object_update_param_get(update, 1, &size); if (fid == NULL || size != sizeof(*fid)) { CERROR("%s: invalid fid: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) lustre_swab_lu_fid(fid); if (!fid_is_sane(fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(fid), -EPROTO); RETURN(err_serious(-EPROTO)); } rc = out_tx_index_insert(tsi->tsi_env, obj, name, fid, &tti->tti_tea, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_index_lookup(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; int rc; ENTRY; if (unlikely(update->ou_result_size < sizeof(tti->tti_fid1))) return -EPROTO; if (!lu_object_exists(&obj->do_lu)) RETURN(-ENOENT); name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for lookup: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } dt_read_lock(env, obj, MOR_TGT_CHILD); if (!dt_try_as_dir(env, obj)) GOTO(out_unlock, rc = -ENOTDIR); rc = dt_lookup(env, obj, (struct dt_rec *)&tti->tti_fid1, (struct dt_key *)name); if (rc < 0) GOTO(out_unlock, rc); if (rc == 0) rc += 1; out_unlock: dt_read_unlock(env, obj); CDEBUG(D_INFO, "lookup "DFID" %s get "DFID" rc %d\n", PFID(lu_object_fid(&obj->do_lu)), name, PFID(&tti->tti_fid1), rc); CDEBUG(D_INFO, "%s: insert lookup reply %p index %d: rc = %d\n", tgt_name(tsi->tsi_tgt), tti->tti_u.update.tti_update_reply, 0, rc); object_update_result_insert(tti->tti_u.update.tti_update_reply, &tti->tti_fid1, sizeof(tti->tti_fid1), tti->tti_u.update.tti_update_reply_index, rc); RETURN(rc); }
static int out_write(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct lu_buf *lbuf = &tti->tti_buf; char *buf; __u64 *tmp; size_t size = 0; size_t buf_len = 0; loff_t pos; int rc; ENTRY; buf = object_update_param_get(update, 0, &buf_len); if (IS_ERR(buf) || buf_len == 0) { CERROR("%s: empty buf for xattr set: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(buf)); RETURN(PTR_ERR(buf)); } lbuf->lb_buf = buf; lbuf->lb_len = buf_len; tmp = object_update_param_get(update, 1, &size); if (IS_ERR(tmp) || size != sizeof(*tmp)) { CERROR("%s: empty or wrong size %zu pos: rc = %ld\n", tgt_name(tsi->tsi_tgt), size, PTR_ERR(tmp)); RETURN(PTR_ERR(tmp)); } if (ptlrpc_req_need_swab(tsi->tsi_pill->rc_req)) __swab64s(tmp); pos = *tmp; rc = out_tx_write(tsi->tsi_env, obj, lbuf, pos, &tti->tti_tea, tti->tti_tea.ta_handle, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_xattr_del(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; int rc; ENTRY; name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for xattr set: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } rc = out_tx_xattr_del(tsi->tsi_env, obj, name, &tti->tti_tea, tti->tti_tea.ta_handle, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_index_delete(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; int rc = 0; if (!lu_object_exists(&obj->do_lu)) RETURN(-ENOENT); name = object_update_param_get(update, 0, NULL); if (name == NULL) { CERROR("%s: empty name for index delete: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } rc = out_tx_index_delete(tsi->tsi_env, obj, name, &tti->tti_tea, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_index_delete(struct tgt_session_info *tsi) { struct tgt_thread_info *tti = tgt_th_info(tsi->tsi_env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; int rc = 0; if (!lu_object_exists(&obj->do_lu)) RETURN(-ENOENT); name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for index delete: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } rc = out_tx_index_delete(tsi->tsi_env, obj, (const struct dt_key *)name, &tti->tti_tea, tti->tti_tea.ta_handle, tti->tti_u.update.tti_update_reply, tti->tti_u.update.tti_update_reply_index); RETURN(rc); }
static int out_read(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct object_update *update = tti->tti_u.update.tti_update; struct dt_object *obj = tti->tti_u.update.tti_dt_object; struct object_update_reply *reply = tti->tti_u.update.tti_update_reply; int index = tti->tti_u.update.tti_update_reply_index; struct lu_rdbuf *rdbuf; struct object_update_result *update_result; struct out_read_reply *orr; void *tmp; size_t size; size_t total_size = 0; __u64 pos; unsigned int i; unsigned int nbufs; int rc = 0; ENTRY; update_result = object_update_result_get(reply, index, NULL); LASSERT(update_result != NULL); update_result->our_datalen = sizeof(*orr); if (!lu_object_exists(&obj->do_lu)) GOTO(out, rc = -ENOENT); tmp = object_update_param_get(update, 0, NULL); if (IS_ERR(tmp)) { CERROR("%s: empty size for read: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(tmp)); GOTO(out, rc = PTR_ERR(tmp)); } size = le64_to_cpu(*(size_t *)(tmp)); tmp = object_update_param_get(update, 1, NULL); if (IS_ERR(tmp)) { CERROR("%s: empty pos for read: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(tmp)); GOTO(out, rc = PTR_ERR(tmp)); } pos = le64_to_cpu(*(__u64 *)(tmp)); /* Put the offset into the begining of the buffer in reply */ orr = (struct out_read_reply *)update_result->our_data; nbufs = (size + OUT_BULK_BUFFER_SIZE - 1) / OUT_BULK_BUFFER_SIZE; OBD_ALLOC(rdbuf, sizeof(struct lu_rdbuf) + nbufs * sizeof(rdbuf->rb_bufs[0])); if (rdbuf == NULL) GOTO(out, rc = -ENOMEM); rdbuf->rb_nbufs = 0; total_size = 0; for (i = 0; i < nbufs; i++) { __u32 read_size; read_size = size > OUT_BULK_BUFFER_SIZE ? OUT_BULK_BUFFER_SIZE : size; OBD_ALLOC(rdbuf->rb_bufs[i].lb_buf, read_size); if (rdbuf->rb_bufs[i].lb_buf == NULL) GOTO(out_free, rc = -ENOMEM); rdbuf->rb_bufs[i].lb_len = read_size; dt_read_lock(env, obj, MOR_TGT_CHILD); rc = dt_read(env, obj, &rdbuf->rb_bufs[i], &pos); dt_read_unlock(env, obj); total_size += rc < 0 ? 0 : rc; if (rc <= 0) break; rdbuf->rb_nbufs++; size -= read_size; } /* send pages to client */ rc = tgt_send_buffer(tsi, rdbuf); if (rc < 0) GOTO(out_free, rc); orr->orr_size = total_size; orr->orr_offset = pos; orr_cpu_to_le(orr, orr); update_result->our_datalen += orr->orr_size; out_free: for (i = 0; i < nbufs; i++) { if (rdbuf->rb_bufs[i].lb_buf != NULL) { OBD_FREE(rdbuf->rb_bufs[i].lb_buf, rdbuf->rb_bufs[i].lb_len); } } OBD_FREE(rdbuf, sizeof(struct lu_rdbuf) + nbufs * sizeof(rdbuf->rb_bufs[0])); out: /* Insert read buffer */ update_result->our_rc = ptlrpc_status_hton(rc); reply->ourp_lens[index] = cfs_size_round(update_result->our_datalen + sizeof(*update_result)); RETURN(rc); }