static int llog_lvfs_read_header(struct llog_handle *handle) { struct obd_device *obd; int rc; ENTRY; LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE); obd = handle->lgh_ctxt->loc_exp->exp_obd; if (i_size_read(handle->lgh_file->f_dentry->d_inode) == 0) { CDEBUG(D_HA, "not reading header from 0-byte log\n"); RETURN(LLOG_EEMPTY); } rc = llog_lvfs_read_blob(obd, handle->lgh_file, handle->lgh_hdr, LLOG_CHUNK_SIZE, 0); if (rc) { CERROR("error reading log header from %.*s\n", handle->lgh_file->f_dentry->d_name.len, handle->lgh_file->f_dentry->d_name.name); } else { struct llog_rec_hdr *llh_hdr = &handle->lgh_hdr->llh_hdr; if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr)) lustre_swab_llog_hdr(handle->lgh_hdr); if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) { CERROR("bad log %.*s header magic: %#x (expected %#x)\n", handle->lgh_file->f_dentry->d_name.len, handle->lgh_file->f_dentry->d_name.name, llh_hdr->lrh_type, LLOG_HDR_MAGIC); rc = -EIO; } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) { CERROR("incorrectly sized log %.*s header: %#x " "(expected %#x)\n", handle->lgh_file->f_dentry->d_name.len, handle->lgh_file->f_dentry->d_name.name, llh_hdr->lrh_len, LLOG_CHUNK_SIZE); CERROR("you may need to re-run lconf --write_conf.\n"); rc = -EIO; } } handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index; handle->lgh_file->f_pos = i_size_read(handle->lgh_file->f_dentry->d_inode); RETURN(rc); }
/** * Implementation of the llog_operations::lop_read_header * * This function reads the current llog header from the bottom storage * device. * * \param[in] env execution environment * \param[in] handle llog handle of the current llog * * \retval 0 on successful header read * \retval negative error if read failed */ static int llog_osd_read_header(const struct lu_env *env, struct llog_handle *handle) { struct llog_rec_hdr *llh_hdr; struct dt_object *o; struct llog_thread_info *lgi; int rc; ENTRY; LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE); o = handle->lgh_obj; LASSERT(o); lgi = llog_info(env); rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL); if (rc) RETURN(rc); LASSERT(lgi->lgi_attr.la_valid & LA_SIZE); if (lgi->lgi_attr.la_size == 0) { CDEBUG(D_HA, "not reading header from 0-byte log\n"); RETURN(LLOG_EEMPTY); } lgi->lgi_off = 0; lgi->lgi_buf.lb_buf = handle->lgh_hdr; lgi->lgi_buf.lb_len = LLOG_CHUNK_SIZE; rc = dt_record_read(env, o, &lgi->lgi_buf, &lgi->lgi_off); if (rc) { CERROR("%s: error reading log header from "DFID": rc = %d\n", o->do_lu.lo_dev->ld_obd->obd_name, PFID(lu_object_fid(&o->do_lu)), rc); RETURN(rc); } llh_hdr = &handle->lgh_hdr->llh_hdr; if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr)) lustre_swab_llog_hdr(handle->lgh_hdr); if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) { CERROR("%s: bad log %s "DFID" header magic: %#x " "(expected %#x)\n", o->do_lu.lo_dev->ld_obd->obd_name, handle->lgh_name ? handle->lgh_name : "", PFID(lu_object_fid(&o->do_lu)), llh_hdr->lrh_type, LLOG_HDR_MAGIC); RETURN(-EIO); } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) { CERROR("%s: incorrectly sized log %s "DFID" header: " "%#x (expected %#x)\n" "you may need to re-run lconf --write_conf.\n", o->do_lu.lo_dev->ld_obd->obd_name, handle->lgh_name ? handle->lgh_name : "", PFID(lu_object_fid(&o->do_lu)), llh_hdr->lrh_len, LLOG_CHUNK_SIZE); RETURN(-EIO); } handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index; RETURN(0); }