/** * Helper function to get the llog size in records. It is used by MGS * mostly to check that config llog exists and contains data. * * \param[in] env execution environment * \param[in] ctxt llog context * \param[in] name llog name * * \retval true if there are records in llog besides a header * \retval false on error or llog without records */ int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt, char *name) { struct llog_handle *llh; int rc = 0; rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS); if (rc < 0) { if (likely(rc == -ENOENT)) rc = 0; GOTO(out, rc); } rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL); if (rc) GOTO(out_close, rc); rc = llog_get_size(llh); out_close: llog_close(env, llh); out: /* The header is record 1, the llog is still considered as empty * if there is only header */ return (rc <= 1); }
int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt, char *name) { struct llog_handle *llh; int rc = 0; rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS); if (rc < 0) { if (likely(rc == -ENOENT)) rc = 0; goto out; } rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL); if (rc) goto out_close; rc = llog_get_size(llh); out_close: llog_close(env, llh); out: /* header is record 1 */ return rc <= 1; }