static int fld_handle_query(struct tgt_session_info *tsi) { int rc; ENTRY; req_capsule_set(tsi->tsi_pill, &RQF_FLD_QUERY); rc = fld_handle_lookup(tsi); RETURN(rc); }
/* Setinfo coming from Server (eg MDT) to Client (eg MDC)! */ static int ldlm_handle_setinfo(struct ptlrpc_request *req) { struct obd_device *obd = req->rq_export->exp_obd; char *key; void *val; int keylen, vallen; int rc = -ENOSYS; DEBUG_REQ(D_HSM, req, "%s: handle setinfo\n", obd->obd_name); req_capsule_set(&req->rq_pill, &RQF_OBD_SET_INFO); key = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY); if (key == NULL) { DEBUG_REQ(D_IOCTL, req, "no set_info key"); return -EFAULT; } keylen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_KEY, RCL_CLIENT); val = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL); if (val == NULL) { DEBUG_REQ(D_IOCTL, req, "no set_info val"); return -EFAULT; } vallen = req_capsule_get_size(&req->rq_pill, &RMF_SETINFO_VAL, RCL_CLIENT); /* We are responsible for swabbing contents of val */ if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) /* Pass it on to mdc (the "export" in this case) */ rc = obd_set_info_async(req->rq_svc_thread->t_env, req->rq_export, sizeof(KEY_HSM_COPYTOOL_SEND), KEY_HSM_COPYTOOL_SEND, vallen, val, NULL); else DEBUG_REQ(D_WARNING, req, "ignoring unknown key %s", key); return rc; }
/* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */ static int ldlm_callback_handler(struct ptlrpc_request *req) { struct ldlm_namespace *ns; struct ldlm_request *dlm_req; struct ldlm_lock *lock; int rc; /* Requests arrive in sender's byte order. The ptlrpc service * handler has already checked and, if necessary, byte-swapped the * incoming request message body, but I am responsible for the * message buffers. */ /* do nothing for sec context finalize */ if (lustre_msg_get_opc(req->rq_reqmsg) == SEC_CTX_FINI) return 0; req_capsule_init(&req->rq_pill, req, RCL_SERVER); if (req->rq_export == NULL) { rc = ldlm_callback_reply(req, -ENOTCONN); ldlm_callback_errmsg(req, "Operate on unconnected server", rc, NULL); return 0; } LASSERT(req->rq_export != NULL); LASSERT(req->rq_export->exp_obd != NULL); switch (lustre_msg_get_opc(req->rq_reqmsg)) { case LDLM_BL_CALLBACK: if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_BL_CALLBACK_NET)) return 0; break; case LDLM_CP_CALLBACK: if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CP_CALLBACK_NET)) return 0; break; case LDLM_GL_CALLBACK: if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_GL_CALLBACK_NET)) return 0; break; case LDLM_SET_INFO: rc = ldlm_handle_setinfo(req); ldlm_callback_reply(req, rc); return 0; case OBD_LOG_CANCEL: /* remove this eventually - for 1.4.0 compat */ CERROR("shouldn't be handling OBD_LOG_CANCEL on DLM thread\n"); req_capsule_set(&req->rq_pill, &RQF_LOG_CANCEL); if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_NET)) return 0; rc = llog_origin_handle_cancel(req); if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOG_CANCEL_REP)) return 0; ldlm_callback_reply(req, rc); return 0; case LLOG_ORIGIN_HANDLE_CREATE: req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE); if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET)) return 0; rc = llog_origin_handle_open(req); ldlm_callback_reply(req, rc); return 0; case LLOG_ORIGIN_HANDLE_NEXT_BLOCK: req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK); if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET)) return 0; rc = llog_origin_handle_next_block(req); ldlm_callback_reply(req, rc); return 0; case LLOG_ORIGIN_HANDLE_READ_HEADER: req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER); if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET)) return 0; rc = llog_origin_handle_read_header(req); ldlm_callback_reply(req, rc); return 0; case LLOG_ORIGIN_HANDLE_CLOSE: if (OBD_FAIL_CHECK(OBD_FAIL_OBD_LOGD_NET)) return 0; rc = llog_origin_handle_close(req); ldlm_callback_reply(req, rc); return 0; case OBD_QC_CALLBACK: req_capsule_set(&req->rq_pill, &RQF_QC_CALLBACK); if (OBD_FAIL_CHECK(OBD_FAIL_OBD_QC_CALLBACK_NET)) return 0; rc = ldlm_handle_qc_callback(req); ldlm_callback_reply(req, rc); return 0; default: CERROR("unknown opcode %u\n", lustre_msg_get_opc(req->rq_reqmsg)); ldlm_callback_reply(req, -EPROTO); return 0; } ns = req->rq_export->exp_obd->obd_namespace; LASSERT(ns != NULL); req_capsule_set(&req->rq_pill, &RQF_LDLM_CALLBACK); dlm_req = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ); if (dlm_req == NULL) { rc = ldlm_callback_reply(req, -EPROTO); ldlm_callback_errmsg(req, "Operate without parameter", rc, NULL); return 0; } /* Force a known safe race, send a cancel to the server for a lock * which the server has already started a blocking callback on. */ if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE) && lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) { rc = ldlm_cli_cancel(&dlm_req->lock_handle[0], 0); if (rc < 0) CERROR("ldlm_cli_cancel: %d\n", rc); } lock = ldlm_handle2lock_long(&dlm_req->lock_handle[0], 0); if (!lock) { CDEBUG(D_DLMTRACE, "callback on lock "LPX64" - lock " "disappeared\n", dlm_req->lock_handle[0].cookie); rc = ldlm_callback_reply(req, -EINVAL); ldlm_callback_errmsg(req, "Operate with invalid parameter", rc, &dlm_req->lock_handle[0]); return 0; } if ((lock->l_flags & LDLM_FL_FAIL_LOC) && lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE); /* Copy hints/flags (e.g. LDLM_FL_DISCARD_DATA) from AST. */ lock_res_and_lock(lock); lock->l_flags |= ldlm_flags_from_wire(dlm_req->lock_flags & LDLM_AST_FLAGS); if (lustre_msg_get_opc(req->rq_reqmsg) == LDLM_BL_CALLBACK) { /* If somebody cancels lock and cache is already dropped, * or lock is failed before cp_ast received on client, * we can tell the server we have no lock. Otherwise, we * should send cancel after dropping the cache. */ if (((lock->l_flags & LDLM_FL_CANCELING) && (lock->l_flags & LDLM_FL_BL_DONE)) || (lock->l_flags & LDLM_FL_FAILED)) { LDLM_DEBUG(lock, "callback on lock " LPX64" - lock disappeared\n", dlm_req->lock_handle[0].cookie); unlock_res_and_lock(lock); LDLM_LOCK_RELEASE(lock); rc = ldlm_callback_reply(req, -EINVAL); ldlm_callback_errmsg(req, "Operate on stale lock", rc, &dlm_req->lock_handle[0]); return 0; } /* BL_AST locks are not needed in LRU. * Let ldlm_cancel_lru() be fast. */ ldlm_lock_remove_from_lru(lock); lock->l_flags |= LDLM_FL_BL_AST; } unlock_res_and_lock(lock); /* We want the ost thread to get this reply so that it can respond * to ost requests (write cache writeback) that might be triggered * in the callback. * * But we'd also like to be able to indicate in the reply that we're * cancelling right now, because it's unused, or have an intent result * in the reply, so we might have to push the responsibility for sending * the reply down into the AST handlers, alas. */ switch (lustre_msg_get_opc(req->rq_reqmsg)) { case LDLM_BL_CALLBACK: CDEBUG(D_INODE, "blocking ast\n"); req_capsule_extend(&req->rq_pill, &RQF_LDLM_BL_CALLBACK); if (!(lock->l_flags & LDLM_FL_CANCEL_ON_BLOCK)) { rc = ldlm_callback_reply(req, 0); if (req->rq_no_reply || rc) ldlm_callback_errmsg(req, "Normal process", rc, &dlm_req->lock_handle[0]); } if (ldlm_bl_to_thread_lock(ns, &dlm_req->lock_desc, lock)) ldlm_handle_bl_callback(ns, &dlm_req->lock_desc, lock); break; case LDLM_CP_CALLBACK: CDEBUG(D_INODE, "completion ast\n"); req_capsule_extend(&req->rq_pill, &RQF_LDLM_CP_CALLBACK); ldlm_callback_reply(req, 0); ldlm_handle_cp_callback(req, ns, dlm_req, lock); break; case LDLM_GL_CALLBACK: CDEBUG(D_INODE, "glimpse ast\n"); req_capsule_extend(&req->rq_pill, &RQF_LDLM_GL_CALLBACK); ldlm_handle_gl_callback(req, ns, dlm_req, lock); break; default: LBUG(); /* checked above */ } return 0; }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates at sender side, so OUT will * call OSD API directly to execute these updates. * * In DNE phase I all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct thandle_exec_args *ta = &tti->tti_tea; struct req_capsule *pill = tsi->tsi_pill; struct dt_device *dt = tsi->tsi_tgt->lut_bottom; struct update_buf *ubuf; struct update *update; struct update_reply *update_reply; int bufsize; int count; int old_batchid = -1; unsigned off; int i; int rc = 0; int rc1 = 0; ENTRY; req_capsule_set(pill, &RQF_UPDATE_OBJ); bufsize = req_capsule_get_size(pill, &RMF_UPDATE, RCL_CLIENT); if (bufsize != UPDATE_BUFFER_SIZE) { CERROR("%s: invalid bufsize %d: rc = %d\n", tgt_name(tsi->tsi_tgt), bufsize, -EPROTO); RETURN(err_serious(-EPROTO)); } ubuf = req_capsule_client_get(pill, &RMF_UPDATE); if (ubuf == NULL) { CERROR("%s: No buf!: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } if (le32_to_cpu(ubuf->ub_magic) != UPDATE_BUFFER_MAGIC) { CERROR("%s: invalid magic %x expect %x: rc = %d\n", tgt_name(tsi->tsi_tgt), le32_to_cpu(ubuf->ub_magic), UPDATE_BUFFER_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } count = le32_to_cpu(ubuf->ub_count); if (count <= 0) { CERROR("%s: No update!: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_UPDATE_REPLY, RCL_SERVER, UPDATE_BUFFER_SIZE); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", tgt_name(tsi->tsi_tgt), rc); RETURN(rc); } /* Prepare the update reply buffer */ update_reply = req_capsule_server_get(pill, &RMF_UPDATE_REPLY); if (update_reply == NULL) RETURN(err_serious(-EPROTO)); update_init_reply_buf(update_reply, count); tti->tti_u.update.tti_update_reply = update_reply; rc = out_tx_start(env, dt, ta); if (rc != 0) RETURN(rc); tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); /* Walk through updates in the request to execute them synchronously */ off = cfs_size_round(offsetof(struct update_buf, ub_bufs[0])); for (i = 0; i < count; i++) { struct tgt_handler *h; struct dt_object *dt_obj; update = (struct update *)((char *)ubuf + off); if (old_batchid == -1) { old_batchid = update->u_batchid; } else if (old_batchid != update->u_batchid) { /* Stop the current update transaction, * create a new one */ rc = out_tx_end(env, ta); if (rc != 0) RETURN(rc); rc = out_tx_start(env, dt, ta); if (rc != 0) RETURN(rc); old_batchid = update->u_batchid; } fid_le_to_cpu(&update->u_fid, &update->u_fid); if (!fid_is_sane(&update->u_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(&update->u_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } dt_obj = dt_locate(env, dt, &update->u_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); tti->tti_u.update.tti_dt_object = dt_obj; tti->tti_u.update.tti_update = update; tti->tti_u.update.tti_update_reply_index = i; h = out_handler_find(update->u_type); if (likely(h != NULL)) { /* For real modification RPC, check if the update * has been executed */ if (h->th_flags & MUTABOR) { struct ptlrpc_request *req = tgt_ses_req(tsi); if (out_check_resent(env, dt, dt_obj, req, out_reconstruct, update_reply, i)) GOTO(next, rc); } rc = h->th_act(tsi); } else { CERROR("%s: The unsupported opc: 0x%x\n", tgt_name(tsi->tsi_tgt), update->u_type); lu_object_put(env, &dt_obj->do_lu); GOTO(out, rc = -ENOTSUPP); } next: lu_object_put(env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); off += cfs_size_round(update_size(update)); } out: rc1 = out_tx_end(env, ta); if (rc == 0) rc = rc1; RETURN(rc); }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates at sender side, so OUT will * call OSD API directly to execute these updates. * * In DNE phase I all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct thandle_exec_args *ta = &tti->tti_tea; struct req_capsule *pill = tsi->tsi_pill; struct dt_device *dt = tsi->tsi_tgt->lut_bottom; struct out_update_header *ouh; struct out_update_buffer *oub = NULL; struct object_update *update; struct object_update_reply *reply; struct ptlrpc_bulk_desc *desc = NULL; struct l_wait_info lwi; void **update_bufs; int current_batchid = -1; __u32 update_buf_count; unsigned int i; unsigned int reply_index = 0; int rc = 0; int rc1 = 0; int ouh_size, reply_size; int updates; ENTRY; req_capsule_set(pill, &RQF_OUT_UPDATE); ouh_size = req_capsule_get_size(pill, &RMF_OUT_UPDATE_HEADER, RCL_CLIENT); if (ouh_size <= 0) RETURN(err_serious(-EPROTO)); ouh = req_capsule_client_get(pill, &RMF_OUT_UPDATE_HEADER); if (ouh == NULL) RETURN(err_serious(-EPROTO)); if (ouh->ouh_magic != OUT_UPDATE_HEADER_MAGIC) { CERROR("%s: invalid update buffer magic %x expect %x: " "rc = %d\n", tgt_name(tsi->tsi_tgt), ouh->ouh_magic, UPDATE_REQUEST_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } update_buf_count = ouh->ouh_count; if (update_buf_count == 0) RETURN(err_serious(-EPROTO)); OBD_ALLOC(update_bufs, sizeof(*update_bufs) * update_buf_count); if (update_bufs == NULL) RETURN(err_serious(-ENOMEM)); if (ouh->ouh_inline_length > 0) { update_bufs[0] = ouh->ouh_inline_data; } else { struct out_update_buffer *tmp; oub = req_capsule_client_get(pill, &RMF_OUT_UPDATE_BUF); if (oub == NULL) GOTO(out_free, rc = err_serious(-EPROTO)); desc = ptlrpc_prep_bulk_exp(pill->rc_req, update_buf_count, PTLRPC_BULK_OPS_COUNT, PTLRPC_BULK_GET_SINK | PTLRPC_BULK_BUF_KVEC, MDS_BULK_PORTAL, &ptlrpc_bulk_kvec_ops); if (desc == NULL) GOTO(out_free, rc = err_serious(-ENOMEM)); tmp = oub; for (i = 0; i < update_buf_count; i++, tmp++) { if (tmp->oub_size >= OUT_MAXREQSIZE) GOTO(out_free, rc = err_serious(-EPROTO)); OBD_ALLOC(update_bufs[i], tmp->oub_size); if (update_bufs[i] == NULL) GOTO(out_free, rc = err_serious(-ENOMEM)); desc->bd_frag_ops->add_iov_frag(desc, update_bufs[i], tmp->oub_size); } pill->rc_req->rq_bulk_write = 1; rc = sptlrpc_svc_prep_bulk(pill->rc_req, desc); if (rc != 0) GOTO(out_free, rc = err_serious(rc)); rc = target_bulk_io(pill->rc_req->rq_export, desc, &lwi); if (rc < 0) GOTO(out_free, rc = err_serious(rc)); } /* validate the request and calculate the total update count and * set it to reply */ reply_size = 0; updates = 0; for (i = 0; i < update_buf_count; i++) { struct object_update_request *our; int j; our = update_bufs[i]; if (ptlrpc_req_need_swab(pill->rc_req)) lustre_swab_object_update_request(our); if (our->ourq_magic != UPDATE_REQUEST_MAGIC) { CERROR("%s: invalid update buffer magic %x" " expect %x: rc = %d\n", tgt_name(tsi->tsi_tgt), our->ourq_magic, UPDATE_REQUEST_MAGIC, -EPROTO); GOTO(out_free, rc = err_serious(-EPROTO)); } updates += our->ourq_count; /* need to calculate reply size */ for (j = 0; j < our->ourq_count; j++) { update = object_update_request_get(our, j, NULL); if (update == NULL) GOTO(out, rc = err_serious(-EPROTO)); if (ptlrpc_req_need_swab(pill->rc_req)) lustre_swab_object_update(update); if (!fid_is_sane(&update->ou_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(&update->ou_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } /* XXX: what ou_result_size can be considered safe? */ reply_size += sizeof(reply->ourp_lens[0]); reply_size += sizeof(struct object_update_result); reply_size += update->ou_result_size; } } reply_size += sizeof(*reply); if (unlikely(reply_size > ouh->ouh_reply_size)) { CERROR("%s: too small reply buf %u for %u, need %u at least\n", tgt_name(tsi->tsi_tgt), ouh->ouh_reply_size, updates, reply_size); GOTO(out_free, rc = err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_OUT_UPDATE_REPLY, RCL_SERVER, ouh->ouh_reply_size); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", tgt_name(tsi->tsi_tgt), rc); GOTO(out_free, rc = err_serious(-EPROTO)); } /* Prepare the update reply buffer */ reply = req_capsule_server_get(pill, &RMF_OUT_UPDATE_REPLY); if (reply == NULL) GOTO(out_free, rc = -EPROTO); reply->ourp_magic = UPDATE_REPLY_MAGIC; reply->ourp_count = updates; tti->tti_u.update.tti_update_reply = reply; tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); /* Walk through updates in the request to execute them */ for (i = 0; i < update_buf_count; i++) { struct tgt_handler *h; struct dt_object *dt_obj; int update_count; struct object_update_request *our; int j; our = update_bufs[i]; update_count = our->ourq_count; for (j = 0; j < update_count; j++) { update = object_update_request_get(our, j, NULL); dt_obj = dt_locate(env, dt, &update->ou_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); if (dt->dd_record_fid_accessed) { lfsck_pack_rfa(&tti->tti_lr, lu_object_fid(&dt_obj->do_lu), LE_FID_ACCESSED, LFSCK_TYPE_LAYOUT); tgt_lfsck_in_notify(env, dt, &tti->tti_lr, NULL); } tti->tti_u.update.tti_dt_object = dt_obj; tti->tti_u.update.tti_update = update; tti->tti_u.update.tti_update_reply_index = reply_index; h = out_handler_find(update->ou_type); if (unlikely(h == NULL)) { CERROR("%s: unsupported opc: 0x%x\n", tgt_name(tsi->tsi_tgt), update->ou_type); GOTO(next, rc = -ENOTSUPP); } /* Check resend case only for modifying RPC */ if (h->th_flags & MUTABOR) { struct ptlrpc_request *req = tgt_ses_req(tsi); if (out_check_resent(env, dt, dt_obj, req, out_reconstruct, reply, reply_index)) GOTO(next, rc = 0); } /* start transaction for modification RPC only */ if (h->th_flags & MUTABOR && current_batchid == -1) { current_batchid = update->ou_batchid; rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) GOTO(next, rc); if (update->ou_flags & UPDATE_FL_SYNC) ta->ta_handle->th_sync = 1; } /* Stop the current update transaction, if the update * has different batchid, or read-only update */ if (((current_batchid != update->ou_batchid) || !(h->th_flags & MUTABOR)) && ta->ta_handle != NULL) { rc = out_tx_end(env, ta, rc); current_batchid = -1; if (rc != 0) GOTO(next, rc); /* start a new transaction if needed */ if (h->th_flags & MUTABOR) { rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) GOTO(next, rc); if (update->ou_flags & UPDATE_FL_SYNC) ta->ta_handle->th_sync = 1; current_batchid = update->ou_batchid; } } rc = h->th_act(tsi); next: reply_index++; lu_object_put(env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); } } out: if (current_batchid != -1) { rc1 = out_tx_end(env, ta, rc); if (rc == 0) rc = rc1; } out_free: if (update_bufs != NULL) { if (oub != NULL) { for (i = 0; i < update_buf_count; i++, oub++) { if (update_bufs[i] != NULL) OBD_FREE(update_bufs[i], oub->oub_size); } } OBD_FREE(update_bufs, sizeof(*update_bufs) * update_buf_count); } if (desc != NULL) ptlrpc_free_bulk(desc); RETURN(rc); }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates at sender side, so OUT will * call OSD API directly to execute these updates. * * In DNE phase I all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct thandle_exec_args *ta = &tti->tti_tea; struct req_capsule *pill = tsi->tsi_pill; struct dt_device *dt = tsi->tsi_tgt->lut_bottom; struct object_update_request *ureq; struct object_update *update; struct object_update_reply *reply; int bufsize; int count; int old_batchid = -1; int i; int rc = 0; int rc1 = 0; ENTRY; req_capsule_set(pill, &RQF_OUT_UPDATE); ureq = req_capsule_client_get(pill, &RMF_OUT_UPDATE); if (ureq == NULL) { CERROR("%s: No buf!: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } bufsize = req_capsule_get_size(pill, &RMF_OUT_UPDATE, RCL_CLIENT); if (bufsize != object_update_request_size(ureq)) { CERROR("%s: invalid bufsize %d: rc = %d\n", tgt_name(tsi->tsi_tgt), bufsize, -EPROTO); RETURN(err_serious(-EPROTO)); } if (ureq->ourq_magic != UPDATE_REQUEST_MAGIC) { CERROR("%s: invalid update buffer magic %x expect %x: " "rc = %d\n", tgt_name(tsi->tsi_tgt), ureq->ourq_magic, UPDATE_REQUEST_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } count = ureq->ourq_count; if (count <= 0) { CERROR("%s: empty update: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_OUT_UPDATE_REPLY, RCL_SERVER, OUT_UPDATE_REPLY_SIZE); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", tgt_name(tsi->tsi_tgt), rc); RETURN(rc); } /* Prepare the update reply buffer */ reply = req_capsule_server_get(pill, &RMF_OUT_UPDATE_REPLY); if (reply == NULL) RETURN(err_serious(-EPROTO)); object_update_reply_init(reply, count); tti->tti_u.update.tti_update_reply = reply; rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) RETURN(rc); tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); /* Walk through updates in the request to execute them synchronously */ for (i = 0; i < count; i++) { struct tgt_handler *h; struct dt_object *dt_obj; update = object_update_request_get(ureq, i, NULL); if (update == NULL) GOTO(out, rc = -EPROTO); if (ptlrpc_req_need_swab(pill->rc_req)) lustre_swab_object_update(update); if (old_batchid == -1) { old_batchid = update->ou_batchid; } else if (old_batchid != update->ou_batchid) { /* Stop the current update transaction, * create a new one */ rc = out_tx_end(env, ta); if (rc < 0) RETURN(rc); rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) RETURN(rc); old_batchid = update->ou_batchid; } if (!fid_is_sane(&update->ou_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(&update->ou_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } dt_obj = dt_locate(env, dt, &update->ou_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); if (dt->dd_record_fid_accessed) { lfsck_pack_rfa(&tti->tti_lr, lu_object_fid(&dt_obj->do_lu)); tgt_lfsck_in_notify(env, dt, &tti->tti_lr); } tti->tti_u.update.tti_dt_object = dt_obj; tti->tti_u.update.tti_update = update; tti->tti_u.update.tti_update_reply_index = i; h = out_handler_find(update->ou_type); if (likely(h != NULL)) { /* For real modification RPC, check if the update * has been executed */ if (h->th_flags & MUTABOR) { struct ptlrpc_request *req = tgt_ses_req(tsi); if (out_check_resent(env, dt, dt_obj, req, out_reconstruct, reply, i)) GOTO(next, rc); } rc = h->th_act(tsi); } else { CERROR("%s: The unsupported opc: 0x%x\n", tgt_name(tsi->tsi_tgt), update->ou_type); lu_object_put(env, &dt_obj->do_lu); GOTO(out, rc = -ENOTSUPP); } next: lu_object_put(env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); } out: rc1 = out_tx_end(env, ta); if (rc == 0) rc = rc1; RETURN(rc); }
/* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */ int mgs_handle(struct ptlrpc_request *req) { int fail = OBD_FAIL_MGS_ALL_REPLY_NET; int opc, rc = 0; ENTRY; req_capsule_init(&req->rq_pill, req, RCL_SERVER); CFS_FAIL_TIMEOUT_MS(OBD_FAIL_MGS_PAUSE_REQ, cfs_fail_val); if (CFS_FAIL_CHECK(OBD_FAIL_MGS_ALL_REQUEST_NET)) RETURN(0); LASSERT(current->journal_info == NULL); opc = lustre_msg_get_opc(req->rq_reqmsg); if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT || opc == SEC_CTX_FINI) GOTO(out, rc = 0); if (opc != MGS_CONNECT) { if (!class_connected_export(req->rq_export)) { DEBUG_REQ(D_MGS, req, "operation on unconnected MGS\n"); req->rq_status = -ENOTCONN; GOTO(out, rc = -ENOTCONN); } } switch (opc) { case MGS_CONNECT: DEBUG_REQ(D_MGS, req, "connect"); /* MGS and MDS have same request format for connect */ req_capsule_set(&req->rq_pill, &RQF_MDS_CONNECT); rc = target_handle_connect(req); if (rc == 0) rc = mgs_connect_check_sptlrpc(req); if (!rc && (lustre_msg_get_conn_cnt(req->rq_reqmsg) > 1)) /* Make clients trying to reconnect after a MGS restart happy; also requires obd_replayable */ lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECONNECT); break; case MGS_DISCONNECT: DEBUG_REQ(D_MGS, req, "disconnect"); /* MGS and MDS have same request format for disconnect */ req_capsule_set(&req->rq_pill, &RQF_MDS_DISCONNECT); rc = target_handle_disconnect(req); req->rq_status = rc; /* superfluous? */ break; case MGS_EXCEPTION: DEBUG_REQ(D_MGS, req, "exception"); rc = mgs_handle_exception(req); break; case MGS_TARGET_REG: DEBUG_REQ(D_MGS, req, "target add"); req_capsule_set(&req->rq_pill, &RQF_MGS_TARGET_REG); rc = mgs_handle_target_reg(req); break; case MGS_TARGET_DEL: DEBUG_REQ(D_MGS, req, "target del"); rc = mgs_handle_target_del(req); break; case MGS_SET_INFO: DEBUG_REQ(D_MGS, req, "set_info"); req_capsule_set(&req->rq_pill, &RQF_MGS_SET_INFO); rc = mgs_set_info_rpc(req); break; case MGS_CONFIG_READ: DEBUG_REQ(D_MGS, req, "read config"); req_capsule_set(&req->rq_pill, &RQF_MGS_CONFIG_READ); rc = mgs_config_read(req); break; case LDLM_ENQUEUE: DEBUG_REQ(D_MGS, req, "enqueue"); req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE); rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast, ldlm_server_blocking_ast, NULL); break; case LDLM_BL_CALLBACK: case LDLM_CP_CALLBACK: DEBUG_REQ(D_MGS, req, "callback"); CERROR("callbacks should not happen on MGS\n"); LBUG(); break; case OBD_PING: DEBUG_REQ(D_INFO, req, "ping"); req_capsule_set(&req->rq_pill, &RQF_OBD_PING); rc = target_handle_ping(req); break; case OBD_LOG_CANCEL: DEBUG_REQ(D_MGS, req, "log cancel"); rc = -ENOTSUPP; /* la la la */ break; case LLOG_ORIGIN_HANDLE_CREATE: DEBUG_REQ(D_MGS, req, "llog_init"); req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE); rc = llog_origin_handle_create(req); if (rc == 0) (void)mgs_handle_fslog_hack(req); break; case LLOG_ORIGIN_HANDLE_NEXT_BLOCK: DEBUG_REQ(D_MGS, req, "llog next block"); req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK); rc = llog_origin_handle_next_block(req); break; case LLOG_ORIGIN_HANDLE_READ_HEADER: DEBUG_REQ(D_MGS, req, "llog read header"); req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER); rc = llog_origin_handle_read_header(req); break; case LLOG_ORIGIN_HANDLE_CLOSE: DEBUG_REQ(D_MGS, req, "llog close"); rc = llog_origin_handle_close(req); break; case LLOG_CATINFO: DEBUG_REQ(D_MGS, req, "llog catinfo"); req_capsule_set(&req->rq_pill, &RQF_LLOG_CATINFO); rc = llog_catinfo(req); break; default: req->rq_status = -ENOTSUPP; rc = ptlrpc_error(req); RETURN(rc); } LASSERT(current->journal_info == NULL); if (rc) CERROR("MGS handle cmd=%d rc=%d\n", opc, rc); out: target_send_reply(req, rc, fail); RETURN(0); }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates in master MDD layer, so out * will skip MDD layer, and call OSD API directly to execute these * updates. * * In phase I, all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct mdt_thread_info *info) { struct req_capsule *pill = info->mti_pill; struct update_buf *ubuf; struct update *update; struct thandle_exec_args *th = &info->mti_handle; int bufsize; int count; unsigned off; int i; int rc = 0; int rc1 = 0; ENTRY; req_capsule_set(pill, &RQF_UPDATE_OBJ); bufsize = req_capsule_get_size(pill, &RMF_UPDATE, RCL_CLIENT); if (bufsize != UPDATE_BUFFER_SIZE) { CERROR("%s: invalid bufsize %d: rc = %d\n", mdt_obd_name(info->mti_mdt), bufsize, -EPROTO); RETURN(err_serious(-EPROTO)); } ubuf = req_capsule_client_get(pill, &RMF_UPDATE); if (ubuf == NULL) { CERROR("%s: No buf!: rc = %d\n", mdt_obd_name(info->mti_mdt), -EPROTO); RETURN(err_serious(-EPROTO)); } if (le32_to_cpu(ubuf->ub_magic) != UPDATE_BUFFER_MAGIC) { CERROR("%s: invalid magic %x expect %x: rc = %d\n", mdt_obd_name(info->mti_mdt), le32_to_cpu(ubuf->ub_magic), UPDATE_BUFFER_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } count = le32_to_cpu(ubuf->ub_count); if (count <= 0) { CERROR("%s: No update!: rc = %d\n", mdt_obd_name(info->mti_mdt), -EPROTO); RETURN(err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_UPDATE_REPLY, RCL_SERVER, UPDATE_BUFFER_SIZE); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", mdt_obd_name(info->mti_mdt), rc); RETURN(rc); } /* Prepare the update reply buffer */ info->mti_u.update.mti_update_reply = req_capsule_server_get(pill, &RMF_UPDATE_REPLY); update_init_reply_buf(info->mti_u.update.mti_update_reply, count); rc = out_tx_start(info->mti_env, info->mti_mdt, th); if (rc != 0) RETURN(rc); /* Walk through updates in the request to execute them synchronously */ off = cfs_size_round(offsetof(struct update_buf, ub_bufs[0])); for (i = 0; i < count; i++) { struct out_handler *h; struct dt_object *dt_obj; update = (struct update *)((char *)ubuf + off); fid_le_to_cpu(&update->u_fid, &update->u_fid); if (!fid_is_sane(&update->u_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", mdt_obd_name(info->mti_mdt), PFID(&update->u_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } dt_obj = out_object_find(info, &update->u_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); info->mti_u.update.mti_dt_object = dt_obj; info->mti_u.update.mti_update = update; info->mti_u.update.mti_update_reply_index = i; h = mdt_handler_find(update->u_type, out_handlers); if (likely(h != NULL)) { rc = h->mh_act(info); } else { CERROR("%s: The unsupported opc: 0x%x\n", mdt_obd_name(info->mti_mdt), update->u_type); lu_object_put(info->mti_env, &dt_obj->do_lu); GOTO(out, rc = -ENOTSUPP); } lu_object_put(info->mti_env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); off += cfs_size_round(update_size(update)); } out: rc1 = out_tx_end(info, th); rc = rc == 0 ? rc1 : rc; info->mti_fail_id = OBD_FAIL_UPDATE_OBJ_NET; RETURN(rc); }