static void print_llog_hdr(struct llog_log_hdr *h) { CDEBUG(D_OTHER, "llog header: %p\n", h); CDEBUG(D_OTHER, "\tllh_hdr.lrh_index: %#x\n", h->llh_hdr.lrh_index); CDEBUG(D_OTHER, "\tllh_hdr.lrh_len: %#x\n", h->llh_hdr.lrh_len); CDEBUG(D_OTHER, "\tllh_hdr.lrh_type: %#x\n", h->llh_hdr.lrh_type); CDEBUG(D_OTHER, "\tllh_timestamp: %#llx\n", h->llh_timestamp); CDEBUG(D_OTHER, "\tllh_count: %#x\n", h->llh_count); CDEBUG(D_OTHER, "\tllh_bitmap_offset: %#x\n", h->llh_bitmap_offset); CDEBUG(D_OTHER, "\tllh_flags: %#x\n", h->llh_flags); CDEBUG(D_OTHER, "\tllh_size: %#x\n", h->llh_size); CDEBUG(D_OTHER, "\tllh_cat_idx: %#x\n", h->llh_cat_idx); CDEBUG(D_OTHER, "\tllh_tail.lrt_index: %#x\n", LLOG_HDR_TAIL(h)->lrt_index); CDEBUG(D_OTHER, "\tllh_tail.lrt_len: %#x\n", LLOG_HDR_TAIL(h)->lrt_len); }
int llog_read_header(const struct lu_env *env, struct llog_handle *handle, const struct obd_uuid *uuid) { struct llog_operations *lop; int rc; ENTRY; rc = llog_handle2ops(handle, &lop); if (rc) RETURN(rc); if (lop->lop_read_header == NULL) RETURN(-EOPNOTSUPP); rc = lop->lop_read_header(env, handle); if (rc == LLOG_EEMPTY) { struct llog_log_hdr *llh = handle->lgh_hdr; /* lrh_len should be initialized in llog_init_handle */ handle->lgh_last_idx = 0; /* header is record with index 0 */ handle->lgh_write_offset = 0; llh->llh_count = 1; /* for the header record */ llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC; LASSERT(handle->lgh_ctxt->loc_chunk_size >= LLOG_MIN_CHUNK_SIZE); llh->llh_hdr.lrh_len = handle->lgh_ctxt->loc_chunk_size; llh->llh_hdr.lrh_index = 0; llh->llh_timestamp = cfs_time_current_sec(); if (uuid) memcpy(&llh->llh_tgtuuid, uuid, sizeof(llh->llh_tgtuuid)); llh->llh_bitmap_offset = offsetof(typeof(*llh), llh_bitmap); /* Since update llog header might also call this function, * let's reset the bitmap to 0 here */ memset(LLOG_HDR_BITMAP(llh), 0, llh->llh_hdr.lrh_len - llh->llh_bitmap_offset - sizeof(llh->llh_tail)); ext2_set_bit(0, LLOG_HDR_BITMAP(llh)); LLOG_HDR_TAIL(llh)->lrt_len = llh->llh_hdr.lrh_len; LLOG_HDR_TAIL(llh)->lrt_index = llh->llh_hdr.lrh_index; rc = 0; } RETURN(rc); }
void lustre_swab_llog_rec(struct llog_rec_hdr *rec) { struct llog_rec_tail *tail = NULL; __swab32s(&rec->lrh_len); __swab32s(&rec->lrh_index); __swab32s(&rec->lrh_type); __swab32s(&rec->lrh_id); switch (rec->lrh_type) { case OST_SZ_REC: { struct llog_size_change_rec *lsc = (struct llog_size_change_rec *)rec; lustre_swab_ll_fid(&lsc->lsc_fid); __swab32s(&lsc->lsc_ioepoch); tail = &lsc->lsc_tail; break; } case MDS_UNLINK_REC: { struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec; __swab64s(&lur->lur_oid); __swab32s(&lur->lur_oseq); __swab32s(&lur->lur_count); tail = &lur->lur_tail; break; } case MDS_UNLINK64_REC: { struct llog_unlink64_rec *lur = (struct llog_unlink64_rec *)rec; lustre_swab_lu_fid(&lur->lur_fid); __swab32s(&lur->lur_count); tail = &lur->lur_tail; break; } case CHANGELOG_REC: { struct llog_changelog_rec *cr = (struct llog_changelog_rec *)rec; __swab16s(&cr->cr.cr_namelen); __swab16s(&cr->cr.cr_flags); __swab32s(&cr->cr.cr_type); __swab64s(&cr->cr.cr_index); __swab64s(&cr->cr.cr_prev); __swab64s(&cr->cr.cr_time); lustre_swab_lu_fid(&cr->cr.cr_tfid); lustre_swab_lu_fid(&cr->cr.cr_pfid); if (cr->cr.cr_flags & CLF_RENAME) { struct changelog_ext_rename *rnm = changelog_rec_rename(&cr->cr); lustre_swab_lu_fid(&rnm->cr_sfid); lustre_swab_lu_fid(&rnm->cr_spfid); } /* * Because the tail follows a variable-length structure we need * to compute its location at runtime */ tail = (struct llog_rec_tail *)((char *)&cr->cr + changelog_rec_size(&cr->cr) + cr->cr.cr_namelen); break; } case CHANGELOG_USER_REC: { struct llog_changelog_user_rec *cur = (struct llog_changelog_user_rec *)rec; __swab32s(&cur->cur_id); __swab64s(&cur->cur_endrec); tail = &cur->cur_tail; break; } case HSM_AGENT_REC: { struct llog_agent_req_rec *arr = (struct llog_agent_req_rec *)rec; __swab32s(&arr->arr_hai.hai_len); __swab32s(&arr->arr_hai.hai_action); lustre_swab_lu_fid(&arr->arr_hai.hai_fid); lustre_swab_lu_fid(&arr->arr_hai.hai_dfid); __swab64s(&arr->arr_hai.hai_cookie); __swab64s(&arr->arr_hai.hai_extent.offset); __swab64s(&arr->arr_hai.hai_extent.length); __swab64s(&arr->arr_hai.hai_gid); /* no swabing for opaque data */ /* hai_data[0]; */ break; } case MDS_SETATTR64_REC: { struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec; lustre_swab_ost_id(&lsr->lsr_oi); __swab32s(&lsr->lsr_uid); __swab32s(&lsr->lsr_uid_h); __swab32s(&lsr->lsr_gid); __swab32s(&lsr->lsr_gid_h); __swab64s(&lsr->lsr_valid); tail = &lsr->lsr_tail; break; } case OBD_CFG_REC: /* these are swabbed as they are consumed */ break; case LLOG_HDR_MAGIC: { struct llog_log_hdr *llh = (struct llog_log_hdr *)rec; __swab64s(&llh->llh_timestamp); __swab32s(&llh->llh_count); __swab32s(&llh->llh_bitmap_offset); __swab32s(&llh->llh_flags); __swab32s(&llh->llh_size); __swab32s(&llh->llh_cat_idx); tail = LLOG_HDR_TAIL(llh); break; } case LLOG_LOGID_MAGIC: { struct llog_logid_rec *lid = (struct llog_logid_rec *)rec; lustre_swab_llog_id(&lid->lid_id); tail = &lid->lid_tail; break; } case LLOG_GEN_REC: { struct llog_gen_rec *lgr = (struct llog_gen_rec *)rec; __swab64s(&lgr->lgr_gen.mnt_cnt); __swab64s(&lgr->lgr_gen.conn_cnt); tail = &lgr->lgr_tail; break; } case LLOG_PAD_MAGIC: break; default: CERROR("Unknown llog rec type %#x swabbing rec %p\n", rec->lrh_type, rec); } if (tail) { __swab32s(&tail->lrt_len); __swab32s(&tail->lrt_index); } }
static int llog_client_read_header(const struct lu_env *env, struct llog_handle *handle) { struct obd_import *imp; struct ptlrpc_request *req = NULL; struct llogd_body *body; struct llog_log_hdr *hdr; struct llog_rec_hdr *llh_hdr; int rc; LLOG_CLIENT_ENTRY(handle->lgh_ctxt, imp); req = ptlrpc_request_alloc_pack(imp, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER, LUSTRE_LOG_VERSION, LLOG_ORIGIN_HANDLE_READ_HEADER); if (!req) { rc = -ENOMEM; goto err_exit; } body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY); body->lgd_logid = handle->lgh_id; body->lgd_ctxt_idx = handle->lgh_ctxt->loc_idx - 1; body->lgd_llh_flags = handle->lgh_hdr->llh_flags; ptlrpc_request_set_replen(req); rc = ptlrpc_queue_wait(req); if (rc) goto out; hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR); if (!hdr) { rc = -EFAULT; goto out; } if (handle->lgh_hdr_size < hdr->llh_hdr.lrh_len) { rc = -EFAULT; goto out; } memcpy(handle->lgh_hdr, hdr, hdr->llh_hdr.lrh_len); handle->lgh_last_idx = LLOG_HDR_TAIL(handle->lgh_hdr)->lrt_index; /* sanity checks */ llh_hdr = &handle->lgh_hdr->llh_hdr; if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) { CERROR("bad log header magic: %#x (expecting %#x)\n", llh_hdr->lrh_type, LLOG_HDR_MAGIC); rc = -EIO; } else if (llh_hdr->lrh_len != LLOG_HDR_TAIL(handle->lgh_hdr)->lrt_len || (llh_hdr->lrh_len & (llh_hdr->lrh_len - 1)) || llh_hdr->lrh_len < LLOG_MIN_CHUNK_SIZE || llh_hdr->lrh_len > handle->lgh_hdr_size) { CERROR("incorrectly sized log header: %#x (expecting %#x) (power of two > 8192)\n", llh_hdr->lrh_len, LLOG_HDR_TAIL(handle->lgh_hdr)->lrt_len); CERROR("you may need to re-run lconf --write_conf.\n"); rc = -EIO; } out: ptlrpc_req_finished(req); err_exit: LLOG_CLIENT_EXIT(handle->lgh_ctxt, imp); return rc; }