1:基于S3协议的put操作说明
2:rgw处理client的请求的入口
3:下次分析put obj 的execute流程
int process_request(rgw::sal::RGWRadosStore* const store, RGWREST* const rest, RGWRequest* const req,
const std::string& frontend_prefix, const rgw_auth_registry_t& auth_registry,
RGWRestfulIO* const client_io, OpsLogSocket* const olog, optional_yield yield,
rgw::dmclock::Scheduler *scheduler, int* http_ret) {
// ClientIO::init_env 一些信息保存到 ClientIO::env的env_map中
int ret = client_io->init(g_ceph_context);
perfcounter->inc(l_rgw_req);
RGWEnv& rgw_env = client_io->get_env();
rgw::sal::RGWRadosUser user;
// clientIo的env初始化到req_state中,同时 req_info::req_info
struct req_state rstate(g_ceph_context, &rgw_env, &user, req->id);
struct req_state *s = &rstate;
// s初始化
RGWObjectCtx rados_ctx(store, s);
s->obj_ctx = &rados_ctx;
auto sysobj_ctx = store->svc()->sysobj->init_obj_ctx();
s->sysobj_ctx = &sysobj_ctx;
........
// RGWREST::get_handler ----- 01
RGWHandler_REST *handler = rest->get_handler(store, s, auth_registry, frontend_prefix, client_io, &mgr, &init_error);
rgw::dmclock::SchedulerCompleter c;
should_log = mgr->get_logging();
// 以写对象为例,RGWHandler_REST::get_op ---> RGWHandler_REST_Obj_S3::op_put ---> RGWPutObj_ObjStore_S3 ,
// 然后初始化:op->init(store, s, this); *this 为 RGWRESTMgr_S3
op = handler->get_op();
// 调度
std::tie(ret,c) = schedule_request(scheduler, s, op);
req->op = op;
s->op_type = op->get_type();
try {
// 认证(对比auth) RGWHandler_REST_S3::authorize ---> RGW_Auth_S3::authorize(认证后续单独梳理)
ret = op->verify_requester(auth_registry);
// RGWHandler_REST_S3::postauth_init 验证参数,如果存在MFA则校验MFA
ret = handler->postauth_init();
// ---- 02
ret = rgw_process_authenticated(handler, op, req, s);
}
return (ret < 0 ? ret : s->err.ret);
} /* process_request */
----------------------------------------------------------------------------------------------- 01
RGWHandler_REST* RGWREST::get_handler(rgw::sal::RGWRadosStore * const store, struct req_state* const s, const rgw::auth::StrategyRegistry& auth_registry,
const std::string& frontend_prefix, RGWRestfulIO* const rio, RGWRESTMgr** const pmgr, int* const init_error) {
// struct req_state rstate(g_ceph_context, &rgw_env, &user, req->id);这个时候会将clientIo中的信息进行解析,
// 同时初始req_info,用于参数检查
*init_error = preprocess(s, rio);
// rgw_main.cc中初始化rest,工厂模式。此时为s3协议,*m = RGWRESTMgr_S3
RGWRESTMgr *m = mgr.get_manager(s, frontend_prefix, s->decoded_uri, &s->relative_uri);
if (pmgr) *pmgr = m;
// RGWRESTMgr_S3::get_handler 假设为s3 put_obj 返回 RGWHandler_REST_Obj_S3 。
// RGWHandler_REST_S3::init_from_header 参数解析
RGWHandler_REST* handler = m->get_handler(s, auth_registry, frontend_prefix);
// RGWHandler_REST_S3::init 解析:acl、grent、存储类型。如果存在copy_source且不是(range&&分片上传),则检查copy需要的参数
*init_error = handler->init(store, s, rio);
return handler;
}
----------------------------------------------------------------------------------------------- 02
// RGWHandler_REST_Obj_S3 RGWPutObj_ObjStore_S3
int rgw_process_authenticated(RGWHandler_REST* const handler, RGWOp*& op,
RGWRequest* const req, req_state* const s, const bool skip_retarget) {
// 获取bucket信息,用户acl/iam,桶acl(policy?)初始化 ------ 03
int ret = handler->init_permissions(op);
// 某些情况下需要检查对象的acl
ret = handler->read_permissions(op);
// quota检查
ret = op->init_processing();
// RGWOp::verify_op_mask 对象读写删除权限检查
ret = op->verify_op_mask();
// OPA
if (s->cct->_conf->rgw_use_opa_authz) ret = rgw_opa_authorize(op, s);
// RGWPutObj::verify_permission ---> RGWPutObj_ObjStore_S3::get_params ---- 04
ret = op->verify_permission();
ret = op->verify_params();
op->pre_exec();
// RGWPutObj::execute ---- 05
op->execute();
// 返回rsp
op->complete();
}