-#include <libcfs/list.h>
-#include <lustre_fsfilt.h>
-
-#if defined(__KERNEL__) && defined(LUSTRE_LOG_SERVER)
-
-int llog_origin_handle_create(struct ptlrpc_request *req)
-{
- struct obd_export *exp = req->rq_export;
- struct obd_device *obd = exp->exp_obd;
- struct obd_device *disk_obd;
- struct llog_handle *loghandle;
- struct llogd_body *body;
- struct lvfs_run_ctxt saved;
- struct llog_logid *logid = NULL;
- struct llog_ctxt *ctxt;
- char *name = NULL;
- int rc, rc2;
- ENTRY;
-
- body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
- if (body == NULL)
- RETURN(-EFAULT);
-
- if (body->lgd_logid.lgl_oid > 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);
- }
-
- 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);
- }
- disk_obd = ctxt->loc_exp->exp_obd;
- push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
-
- rc = llog_create(ctxt, &loghandle, logid, name);
- if (rc)
- GOTO(out_pop, rc);
-
- rc = req_capsule_server_pack(&req->rq_pill);
- if (rc)
- GOTO(out_close, rc = -ENOMEM);
-
- body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
- body->lgd_logid = loghandle->lgh_id;
-
- GOTO(out_close, rc);
-out_close:
- rc2 = llog_close(loghandle);
- if (!rc)
- rc = rc2;
-out_pop:
- pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-int llog_origin_handle_destroy(struct ptlrpc_request *req)
-{
- struct obd_export *exp = req->rq_export;
- struct obd_device *obd = exp->exp_obd;
- struct obd_device *disk_obd;
- struct llog_handle *loghandle;
- struct llogd_body *body;
- struct lvfs_run_ctxt saved;
- struct llog_logid *logid = NULL;
- struct llog_ctxt *ctxt;
- __u32 flags;
- int rc;
- ENTRY;
-
- body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
- if (body == NULL)
- RETURN(-EFAULT);
-
- if (body->lgd_logid.lgl_oid > 0)
- logid = &body->lgd_logid;
-
- ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
- if (ctxt == NULL)
- RETURN(-ENODEV);
-
- disk_obd = ctxt->loc_exp->exp_obd;
- push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
-
- rc = llog_create(ctxt, &loghandle, logid, NULL);
- if (rc)
- GOTO(out_pop, rc);
-
- rc = req_capsule_server_pack(&req->rq_pill);
- if (rc)
- GOTO(out_close, rc = -ENOMEM);
-
- body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
- body->lgd_logid = loghandle->lgh_id;
- flags = body->lgd_llh_flags;
- rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
- if (rc)
- GOTO(out_close, rc);
- rc = llog_destroy(loghandle);
- if (rc)
- GOTO(out_close, rc);
- llog_free_handle(loghandle);
- GOTO(out_close, rc);
-out_close:
- if (rc)
- llog_close(loghandle);
-out_pop:
- pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
- llog_ctxt_put(ctxt);
- return rc;
-}