- struct obd_export *exp = req->rq_export;
- struct obd_device *obd = exp->exp_obd;
- struct llog_handle *loghandle;
- struct llogd_body *body;
- struct lvfs_run_ctxt saved;
- struct llog_ctxt *ctxt;
- __u32 flags;
- __u8 *buf;
- void * ptr;
- int rc, rc2, size[] = {sizeof (*body), LLOG_CHUNK_SIZE};
- ENTRY;
-
- body = lustre_swab_reqbuf(req, 0, sizeof(*body),
- lustre_swab_llogd_body);
- if (body == NULL) {
- CERROR ("Can't unpack llogd_body\n");
- GOTO(out, rc =-EFAULT);
- }
-
- OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
- if (!buf)
- GOTO(out, rc = -ENOMEM);
-
- ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
- LASSERT(ctxt != NULL);
- push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
-
- rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
- if (rc)
- GOTO(out_pop, rc);
-
- flags = body->lgd_llh_flags;
- rc = llog_init_handle(loghandle, flags, NULL);
- if (rc)
- GOTO(out_close, rc);
-
- memset(buf, 0, LLOG_CHUNK_SIZE);
- rc = llog_prev_block(loghandle, body->lgd_index, buf, LLOG_CHUNK_SIZE);
- if (rc)
- GOTO(out_close, rc);
-
-
- rc = lustre_pack_reply(req, 2, size, NULL);
- if (rc)
- GOTO(out_close, rc = -ENOMEM);
-
- ptr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (body));
- memcpy(ptr, body, sizeof(*body));
-
- ptr = lustre_msg_buf(req->rq_repmsg, 1, LLOG_CHUNK_SIZE);
- memcpy(ptr, buf, LLOG_CHUNK_SIZE);
-
-out_close:
- rc2 = llog_close(loghandle);
- if (!rc)
- rc = rc2;
-
-out_pop:
- pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
- OBD_FREE(buf, LLOG_CHUNK_SIZE);
-out:
- RETURN(rc);
+ struct obd_export *exp = req->rq_export;
+ struct obd_device *obd = exp->exp_obd;
+ struct llog_handle *loghandle;
+ struct llogd_body *body;
+ struct llog_logid *logid = NULL;
+ struct llog_ctxt *ctxt;
+ char *name = NULL;
+ int rc;
+
+ ENTRY;
+
+ body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
+ if (body == NULL)
+ RETURN(err_serious(-EFAULT));
+
+ rc = req_capsule_server_pack(&req->rq_pill);
+ if (rc)
+ RETURN(err_serious(-ENOMEM));
+
+ if (ostid_id(&body->lgd_logid.lgl_oi) > 0)
+ logid = &body->lgd_logid;
+
+ if (req_capsule_field_present(&req->rq_pill, &RMF_NAME, RCL_CLIENT)) {
+ name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
+ if (name == NULL)
+ RETURN(-EFAULT);
+ CDEBUG(D_INFO, "%s: opening log %s\n", obd->obd_name, name);
+ }
+
+ if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
+ CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d name=%s\n",
+ obd->obd_name, body->lgd_ctxt_idx, name);
+ RETURN(-EPROTO);
+ }
+
+ ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
+ if (ctxt == NULL) {
+ CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
+ obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
+ RETURN(-ENODEV);
+ }
+
+ rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle, logid,
+ name, LLOG_OPEN_EXISTS);
+ if (rc)
+ GOTO(out_ctxt, rc);
+
+ body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
+ body->lgd_logid = loghandle->lgh_id;
+
+ llog_origin_close(req->rq_svc_thread->t_env, loghandle);
+ EXIT;
+out_ctxt:
+ llog_ctxt_put(ctxt);
+ return rc;