* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED))
RETURN(-ENOSPC);
+ if (loghandle->lgh_hdr != NULL) {
+ /* If llog object is remote and creation is failed, lgh_hdr
+ * might be left over here, free it first */
+ LASSERT(!llog_exist(loghandle));
+ OBD_FREE_PTR(loghandle->lgh_hdr);
+ loghandle->lgh_hdr = NULL;
+ }
+
rc = llog_create(env, loghandle, th);
/* if llog is already created, no need to initialize it */
if (rc == -EEXIST) {
down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
llh = loghandle->lgh_hdr;
if (llh == NULL ||
- loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
+ loghandle->lgh_last_idx < LLOG_HDR_BITMAP_SIZE(llh) - 1) {
up_read(&cathandle->lgh_lock);
RETURN(loghandle);
} else {
down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
llh = loghandle->lgh_hdr;
LASSERT(llh);
- if (loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
+ if (loghandle->lgh_last_idx < LLOG_HDR_BITMAP_SIZE(llh) - 1) {
up_write(&cathandle->lgh_lock);
- RETURN(loghandle);
- } else {
+ RETURN(loghandle);
+ } else {
up_write(&loghandle->lgh_lock);
- }
+ }
}
CDEBUG(D_INODE, "use next log\n");
int rc;
ENTRY;
- LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
+ LASSERT(rec->lrh_len <= cathandle->lgh_ctxt->loc_chunk_size);
loghandle = llog_cat_current_log(cathandle, th);
LASSERT(!IS_ERR(loghandle));
}
EXPORT_SYMBOL(llog_cat_cancel_records);
-int llog_cat_process_cb(const struct lu_env *env, struct llog_handle *cat_llh,
- struct llog_rec_hdr *rec, void *data)
+static int llog_cat_process_cb(const struct lu_env *env,
+ struct llog_handle *cat_llh,
+ struct llog_rec_hdr *rec, void *data)
{
struct llog_process_data *d = data;
struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
}
/* clean old empty llogs, do not consider current llog in use */
+ /* ignore remote (lgh_obj=NULL) llogs */
hdr = llh->lgh_hdr;
if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
- hdr->llh_count == 1 &&
+ hdr->llh_count == 1 && cat_llh->lgh_obj != NULL &&
llh != cat_llh->u.chd.chd_current_log) {
rc = llog_destroy(env, llh);
if (rc)
RETURN(rc);
}
-EXPORT_SYMBOL(llog_cat_process_or_fork);
int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
llog_cb_t cb, void *data, int startcat, int startidx)
}
EXPORT_SYMBOL(llog_cat_reverse_process);
-int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
+static int llog_cat_set_first_idx(struct llog_handle *cathandle, int idx)
{
- struct llog_log_hdr *llh = cathandle->lgh_hdr;
- int i, bitmap_size, idx;
- ENTRY;
+ struct llog_log_hdr *llh = cathandle->lgh_hdr;
+ int bitmap_size;
- bitmap_size = LLOG_BITMAP_SIZE(llh);
- if (llh->llh_cat_idx == (index - 1)) {
- idx = llh->llh_cat_idx + 1;
- llh->llh_cat_idx = idx;
- if (idx == cathandle->lgh_last_idx)
- goto out;
- for (i = (index + 1) % bitmap_size;
- i != cathandle->lgh_last_idx;
- i = (i + 1) % bitmap_size) {
- if (!ext2_test_bit(i, llh->llh_bitmap)) {
- idx = llh->llh_cat_idx + 1;
- llh->llh_cat_idx = idx;
- } else if (i == 0) {
- llh->llh_cat_idx = 0;
- } else {
- break;
- }
- }
-out:
- CDEBUG(D_RPCTRACE, "set catlog "DOSTID" first idx %u\n",
- POSTID(&cathandle->lgh_id.lgl_oi), llh->llh_cat_idx);
+ ENTRY;
+
+ bitmap_size = LLOG_HDR_BITMAP_SIZE(llh);
+ /*
+ * The llh_cat_idx equals to the first used index minus 1
+ * so if we canceled the first index then llh_cat_idx
+ * must be renewed.
+ */
+ if (llh->llh_cat_idx == (idx - 1)) {
+ llh->llh_cat_idx = idx;
+
+ do {
+ idx = (idx + 1) % bitmap_size;
+ if (!ext2_test_bit(idx, LLOG_HDR_BITMAP(llh))) {
+ /* update llh_cat_idx for each unset bit,
+ * expecting the*/
+ llh->llh_cat_idx = idx;
+ } else if (idx == 0) {
+ /* skip header bit */
+ continue;
+ } else {
+ /* the first index is found */
+ break;
+ }
+ } while (idx != cathandle->lgh_last_idx);
+
+ CDEBUG(D_RPCTRACE, "Set catlog "DOSTID" first idx %u,"
+ " (last_idx %u)\n", POSTID(&cathandle->lgh_id.lgl_oi),
+ llh->llh_cat_idx, cathandle->lgh_last_idx);
}
RETURN(0);
/* llog was opened and keep in a list, close it now */
llog_close(env, loghandle);
}
+
+ /* do not attempt to cleanup on-disk llog if on client side */
+ if (cathandle->lgh_obj == NULL)
+ return 0;
+
/* remove plain llog entry from catalog by index */
llog_cat_set_first_idx(cathandle, index);
rc = llog_cancel_rec(env, cathandle, index);
return rc;
}
-int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
- struct llog_rec_hdr *rec, void *data)
-{
- struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
- struct llog_handle *loghandle;
- struct llog_log_hdr *llh;
- int rc;
-
- ENTRY;
-
- if (rec->lrh_type != LLOG_LOGID_MAGIC) {
- CERROR("invalid record in catalog\n");
- RETURN(-EINVAL);
- }
-
- CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
- DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
- rec->lrh_index, POSTID(&cathandle->lgh_id.lgl_oi));
-
- rc = llog_cat_id2handle(env, cathandle, &loghandle, &lir->lid_id);
- if (rc) {
- CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
- cathandle->lgh_ctxt->loc_obd->obd_name,
- POSTID(&lir->lid_id.lgl_oi), rc);
- if (rc == -ENOENT || rc == -ESTALE) {
- /* remove index from catalog */
- llog_cat_cleanup(env, cathandle, NULL, rec->lrh_index);
- }
- RETURN(rc);
- }
-
- llh = loghandle->lgh_hdr;
- if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
- (llh->llh_count == 1)) {
- rc = llog_destroy(env, loghandle);
- if (rc)
- CERROR("%s: fail to destroy empty log: rc = %d\n",
- loghandle->lgh_ctxt->loc_obd->obd_name, rc);
-
- llog_cat_cleanup(env, cathandle, loghandle,
- loghandle->u.phd.phd_cookie.lgc_index);
- }
- llog_handle_put(loghandle);
-
- RETURN(rc);
-}
-EXPORT_SYMBOL(cat_cancel_cb);
-
/* helper to initialize catalog llog and process it to cancel */
int llog_cat_init_and_process(const struct lu_env *env,
struct llog_handle *llh)
RETURN(0);
}
EXPORT_SYMBOL(llog_cat_init_and_process);
-