* 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/
#define DEBUG_SUBSYSTEM S_LOG
-#ifndef __KERNEL__
-#include <liblustre.h>
-#endif
#include <obd_class.h>
struct llog_handle **res, struct llog_logid *logid)
{
struct llog_handle *loghandle;
+ enum llog_flag fmt;
int rc = 0;
ENTRY;
if (cathandle == NULL)
RETURN(-EBADF);
+ fmt = cathandle->lgh_hdr->llh_flags & LLOG_F_EXT_MASK;
down_write(&cathandle->lgh_lock);
- cfs_list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
- u.phd.phd_entry) {
+ list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
+ u.phd.phd_entry) {
struct llog_logid *cgl = &loghandle->lgh_id;
if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
RETURN(rc);
}
- rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, NULL);
+ rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN | fmt, NULL);
if (rc < 0) {
llog_close(env, loghandle);
loghandle = NULL;
}
down_write(&cathandle->lgh_lock);
- cfs_list_add(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
+ list_add_tail(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
up_write(&cathandle->lgh_lock);
loghandle->u.phd.phd_cat_handle = cathandle;
ENTRY;
- cfs_list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
- u.phd.phd_entry) {
+ list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
+ u.phd.phd_entry) {
struct llog_log_hdr *llh = loghandle->lgh_hdr;
int index;
/* unlink open-not-created llogs */
- cfs_list_del_init(&loghandle->u.phd.phd_entry);
+ list_del_init(&loghandle->u.phd.phd_entry);
llh = loghandle->lgh_hdr;
if (loghandle->lgh_obj != NULL && llh != NULL &&
(llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
NULL, NULL, LLOG_OPEN_NEW);
if (rc == 0) {
cathandle->u.chd.chd_current_log = loghandle;
- cfs_list_add_tail(&loghandle->u.phd.phd_entry,
- &cathandle->u.chd.chd_head);
+ list_add_tail(&loghandle->u.phd.phd_entry,
+ &cathandle->u.chd.chd_head);
}
}
up_write(&cathandle->lgh_lock);
NULL, NULL, LLOG_OPEN_NEW);
if (rc == 0) {
cathandle->u.chd.chd_next_log = loghandle;
- cfs_list_add_tail(&loghandle->u.phd.phd_entry,
- &cathandle->u.chd.chd_head);
+ list_add_tail(&loghandle->u.phd.phd_entry,
+ &cathandle->u.chd.chd_head);
}
}
up_write(&cathandle->lgh_lock);
}
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;
struct llog_handle *llh;
+ struct llog_log_hdr *hdr;
int rc;
ENTRY;
CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
cat_llh->lgh_ctxt->loc_obd->obd_name,
POSTID(&lir->lid_id.lgl_oi), rc);
+ if (rc == -ENOENT || rc == -ESTALE) {
+ /* After a server crash, a stub of index
+ * record in catlog could be kept, because
+ * plain log destroy + catlog index record
+ * deletion are not atomic. So we end up with
+ * an index but no actual record. Destroy the
+ * index and move on. */
+ rc = llog_cat_cleanup(env, cat_llh, NULL,
+ rec->lrh_index);
+ }
+
RETURN(rc);
}
+ /* 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 && cat_llh->lgh_obj != NULL &&
+ llh != cat_llh->u.chd.chd_current_log) {
+ rc = llog_destroy(env, llh);
+ if (rc)
+ CERROR("%s: fail to destroy empty log: rc = %d\n",
+ llh->lgh_ctxt->loc_obd->obd_name, rc);
+ GOTO(out, rc = LLOG_DEL_PLAIN);
+ }
+
if (rec->lrh_index < d->lpd_startcat) {
/* Skip processing of the logs until startcat */
rc = 0;
NULL, false);
}
+out:
/* The empty plain log was destroyed while processing */
if (rc == LLOG_DEL_PLAIN)
rc = llog_cat_cleanup(env, cat_llh, llh,
struct llog_process_data *d = data;
struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
struct llog_handle *llh;
+ struct llog_log_hdr *hdr;
int rc;
if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
cat_llh->lgh_ctxt->loc_obd->obd_name,
POSTID(&lir->lid_id.lgl_oi), rc);
+ if (rc == -ENOENT || rc == -ESTALE) {
+ /* After a server crash, a stub of index
+ * record in catlog could be kept, because
+ * plain log destroy + catlog index record
+ * deletion are not atomic. So we end up with
+ * an index but no actual record. Destroy the
+ * index and move on. */
+ rc = llog_cat_cleanup(env, cat_llh, NULL,
+ rec->lrh_index);
+ }
+
RETURN(rc);
}
+ /* clean old empty llogs, do not consider current llog in use */
+ hdr = llh->lgh_hdr;
+ if ((hdr->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
+ hdr->llh_count == 1 &&
+ llh != cat_llh->u.chd.chd_current_log) {
+ rc = llog_destroy(env, llh);
+ if (rc)
+ CERROR("%s: fail to destroy empty log: rc = %d\n",
+ llh->lgh_ctxt->loc_obd->obd_name, rc);
+ GOTO(out, rc = LLOG_DEL_PLAIN);
+ }
+
rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
+out:
/* The empty plain was destroyed while processing */
if (rc == LLOG_DEL_PLAIN)
rc = llog_cat_cleanup(env, cat_llh, llh,
}
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 index)
{
struct llog_log_hdr *llh = cathandle->lgh_hdr;
int i, bitmap_size, idx;
down_write(&cathandle->lgh_lock);
if (cathandle->u.chd.chd_current_log == loghandle)
cathandle->u.chd.chd_current_log = NULL;
- cfs_list_del_init(&loghandle->u.phd.phd_entry);
+ list_del_init(&loghandle->u.phd.phd_entry);
up_write(&cathandle->lgh_lock);
LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
/* llog was opened and keep in a list, close it now */
return rc;
}
-int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
+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;
if (rc)
RETURN(rc);
- rc = llog_process_or_fork(env, llh, cat_cancel_cb, NULL, NULL, false);
- if (rc)
- CERROR("%s: llog_process() with cat_cancel_cb failed: rc = "
- "%d\n", llh->lgh_ctxt->loc_obd->obd_name, rc);
RETURN(0);
}
EXPORT_SYMBOL(llog_cat_init_and_process);
-