Whamcloud - gitweb
LU-1302 llog: pass lu_env as parametr in llog functions
[fs/lustre-release.git] / lustre / obdfilter / filter_log.c
index 2e1faf0..d997ae8 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -42,9 +42,6 @@
 
 #define DEBUG_SUBSYSTEM S_FILTER
 
-#ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
-#endif
 #include <linux/module.h>
 #include <linux/version.h>
 
@@ -65,29 +62,29 @@ int filter_log_sz_change(struct llog_handle *cathandle,
         struct ost_filterdata *ofd;
         ENTRY;
 
-        LOCK_INODE_MUTEX(inode);
-        ofd = inode->i_filterdata;
-
-        if (ofd && ofd->ofd_epoch >= ioepoch) {
-                if (ofd->ofd_epoch > ioepoch)
-                        CERROR("client sent old epoch %d for obj ino %ld\n",
-                               ioepoch, inode->i_ino);
-                UNLOCK_INODE_MUTEX(inode);
-                RETURN(0);
-        }
-
-        if (ofd && ofd->ofd_epoch < ioepoch) {
-                ofd->ofd_epoch = ioepoch;
-        } else if (!ofd) {
-                OBD_ALLOC(ofd, sizeof(*ofd));
-                if (!ofd)
-                        GOTO(out, rc = -ENOMEM);
-                igrab(inode);
-                inode->i_filterdata = ofd;
-                ofd->ofd_epoch = ioepoch;
-        }
-        /* the decision to write a record is now made, unlock */
-        UNLOCK_INODE_MUTEX(inode);
+       mutex_lock(&inode->i_mutex);
+       ofd = inode->i_private;
+
+       if (ofd && ofd->ofd_epoch >= ioepoch) {
+               if (ofd->ofd_epoch > ioepoch)
+                       CERROR("client sent old epoch %d for obj ino %ld\n",
+                              ioepoch, inode->i_ino);
+               mutex_unlock(&inode->i_mutex);
+               RETURN(0);
+       }
+
+       if (ofd && ofd->ofd_epoch < ioepoch) {
+               ofd->ofd_epoch = ioepoch;
+       } else if (!ofd) {
+               OBD_ALLOC(ofd, sizeof(*ofd));
+               if (!ofd)
+                       GOTO(out, rc = -ENOMEM);
+               igrab(inode);
+               inode->i_private = ofd;
+               ofd->ofd_epoch = ioepoch;
+       }
+       /* the decision to write a record is now made, unlock */
+       mutex_unlock(&inode->i_mutex);
 
         OBD_ALLOC(lsc, sizeof(*lsc));
         if (lsc == NULL)
@@ -97,7 +94,7 @@ int filter_log_sz_change(struct llog_handle *cathandle,
         lsc->lsc_fid = *mds_fid;
         lsc->lsc_ioepoch = ioepoch;
 
-        rc = llog_cat_add_rec(cathandle, &lsc->lsc_hdr, logcookie, NULL);
+       rc = llog_cat_add_rec(NULL, cathandle, &lsc->lsc_hdr, logcookie, NULL);
         OBD_FREE(lsc, sizeof(*lsc));
 
         if (rc > 0) {
@@ -117,7 +114,7 @@ void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
         struct obd_llog_group *olg;
         struct llog_ctxt *ctxt;
         int rc;
-        
+
         /* we have to find context for right group */
         if (error != 0 || obd->obd_stopping) {
                 CDEBUG(D_INODE, "not cancel logcookie err %d stopping %d \n",
@@ -125,22 +122,22 @@ void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
                 GOTO (out, rc = 0);
         }
 
-        olg = filter_find_olg(obd, cookie->lgc_lgl.lgl_ogr);
-        if (!olg) { 
-                CDEBUG(D_HA, "unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_ogr);
+        olg = filter_find_olg(obd, cookie->lgc_lgl.lgl_oseq);
+        if (!olg) {
+                CDEBUG(D_HA, "unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_oseq);
                 GOTO(out, rc = 0);
         }
-        
+
         ctxt = llog_group_get_ctxt(olg, cookie->lgc_subsys + 1);
         if (!ctxt) {
                 CERROR("no valid context for group "LPU64"\n",
-                        cookie->lgc_lgl.lgl_ogr);
+                        cookie->lgc_lgl.lgl_oseq);
                 GOTO(out, rc = 0);
         }
 
         OBD_FAIL_TIMEOUT(OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT, 30);
 
-        rc = llog_cancel(ctxt, NULL, 1, cookie, 0);
+       rc = llog_cancel(NULL, ctxt, NULL, 1, cookie, 0);
         if (rc)
                 CERROR("error cancelling log cookies: rc = %d\n", rc);
         llog_ctxt_put(ctxt);
@@ -148,41 +145,55 @@ out:
         OBD_FREE(cookie, sizeof(*cookie));
 }
 
-/* Callback for processing the unlink log record received from MDS by 
+/* Callback for processing the unlink log record received from MDS by
  * llog_client_api. */
 static int filter_recov_log_unlink_cb(struct llog_ctxt *ctxt,
                                       struct llog_rec_hdr *rec,
                                       struct llog_cookie *cookie)
 {
-        struct obd_device *obd = ctxt->loc_obd;
-        struct obd_export *exp = obd->obd_self_export;
+        struct obd_export *exp = ctxt->loc_obd->obd_self_export;
         struct llog_unlink_rec *lur;
         struct obdo *oa;
         obd_id oid;
+        obd_count count;
         int rc = 0;
         ENTRY;
 
         lur = (struct llog_unlink_rec *)rec;
         OBDO_ALLOC(oa);
-        if (oa == NULL) 
+        if (oa == NULL)
                 RETURN(-ENOMEM);
         oa->o_valid |= OBD_MD_FLCOOKIE;
         oa->o_id = lur->lur_oid;
-        oa->o_gr = lur->lur_ogen;
+        oa->o_seq = lur->lur_oseq;
         oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
         oa->o_lcookie = *cookie;
         oid = oa->o_id;
-
-        rc = filter_destroy(exp, oa, NULL, NULL, NULL);
-        OBDO_FREE(oa);
-        if (rc == -ENOENT) {
-                CDEBUG(D_RPCTRACE, "object already removed, send cookie\n");
-                llog_cancel(ctxt, NULL, 1, cookie, 0);
-                RETURN(0);
+        /* objid gap may require to destroy several objects in row */
+        count = lur->lur_count + 1;
+
+        /* This check is only valid before FID-on-OST and it should
+         * be removed after FID-on-OST is implemented */
+        if (oa->o_seq > FID_SEQ_OST_MAX) {
+                CERROR("%s: invalid group number "LPU64" > MAX_CMD_GROUP %u\n",
+                        exp->exp_obd->obd_name, oa->o_seq, FID_SEQ_OST_MAX);
+                RETURN(-EINVAL);
         }
 
-        if (rc == 0)
-                CDEBUG(D_RPCTRACE, "object "LPU64" is destroyed\n", oid);
+        while (count > 0) {
+                rc = filter_destroy(NULL, exp, oa, NULL, NULL, NULL, NULL);
+                if (rc == 0)
+                        CDEBUG(D_RPCTRACE, "object "LPU64" is destroyed\n",
+                               oid);
+                else if (rc != -ENOENT)
+                        CEMERG("error destroying object "LPU64": %d\n",
+                               oid, rc);
+                else
+                        rc = 0;
+                count--;
+                oid++;
+        }
+        OBDO_FREE(oa);
 
         RETURN(rc);
 }
@@ -195,33 +206,40 @@ static int filter_recov_log_setattr_cb(struct llog_ctxt *ctxt,
 {
         struct obd_device *obd = ctxt->loc_obd;
         struct obd_export *exp = obd->obd_self_export;
-        struct llog_setattr_rec *lsr;
         struct obd_info oinfo = { { { 0 } } };
         obd_id oid;
         int rc = 0;
         ENTRY;
 
-        lsr = (struct llog_setattr_rec *)rec;
         OBDO_ALLOC(oinfo.oi_oa);
         if (oinfo.oi_oa == NULL)
                 RETURN(-ENOMEM);
 
+       if (rec->lrh_type == MDS_SETATTR64_REC) {
+                struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
+
+                oinfo.oi_oa->o_id = lsr->lsr_oid;
+                oinfo.oi_oa->o_seq = lsr->lsr_oseq;
+                oinfo.oi_oa->o_uid = lsr->lsr_uid;
+                oinfo.oi_oa->o_gid = lsr->lsr_gid;
+       } else {
+               CERROR("%s: wrong llog type %#x\n", obd->obd_name,
+                      rec->lrh_type);
+               RETURN(-EINVAL);
+       }
+
         oinfo.oi_oa->o_valid |= (OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID |
                                  OBD_MD_FLCOOKIE);
-        oinfo.oi_oa->o_id = lsr->lsr_oid;
-        oinfo.oi_oa->o_gr = lsr->lsr_ogen;
         oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
-        oinfo.oi_oa->o_uid = lsr->lsr_uid;
-        oinfo.oi_oa->o_gid = lsr->lsr_gid;
         oinfo.oi_oa->o_lcookie = *cookie;
         oid = oinfo.oi_oa->o_id;
 
-        rc = filter_setattr(exp, &oinfo, NULL);
+        rc = filter_setattr(NULL, exp, &oinfo, NULL);
         OBDO_FREE(oinfo.oi_oa);
 
         if (rc == -ENOENT) {
                 CDEBUG(D_RPCTRACE, "object already removed, send cookie\n");
-                llog_cancel(ctxt, NULL, 1, cookie, 0);
+               llog_cancel(NULL, ctxt, NULL, 1, cookie, 0);
                 RETURN(0);
         }
 
@@ -231,8 +249,9 @@ static int filter_recov_log_setattr_cb(struct llog_ctxt *ctxt,
         RETURN(rc);
 }
 
-int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
-                                struct llog_rec_hdr *rec, void *data)
+int filter_recov_log_mds_ost_cb(const struct lu_env *env,
+                               struct llog_handle *llh,
+                               struct llog_rec_hdr *rec, void *data)
 {
         struct llog_ctxt *ctxt = llh->lgh_ctxt;
         struct llog_cookie cookie;
@@ -242,6 +261,13 @@ int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
         if (ctxt->loc_obd->obd_stopping)
                 RETURN(LLOG_PROC_BREAK);
 
+        if (rec == NULL) {
+                cfs_spin_lock(&ctxt->loc_obd->u.filter.fo_flags_lock);
+                ctxt->loc_obd->u.filter.fo_mds_ost_sync = 0;
+                cfs_spin_unlock(&ctxt->loc_obd->u.filter.fo_flags_lock);
+                RETURN(0);
+        }
+
         if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
                 CERROR("log is not plain\n");
                 RETURN(-EINVAL);
@@ -256,17 +282,18 @@ int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
         case MDS_UNLINK_REC:
                 rc = filter_recov_log_unlink_cb(ctxt, rec, &cookie);
                 break;
-        case MDS_SETATTR_REC:
+        case MDS_SETATTR64_REC:
                 rc = filter_recov_log_setattr_cb(ctxt, rec, &cookie);
                 break;
         case LLOG_GEN_REC: {
                 struct llog_gen_rec *lgr = (struct llog_gen_rec *)rec;
+
                 if (llog_gen_lt(lgr->lgr_gen, ctxt->loc_gen))
                         rc = 0;
                 else
                         rc = LLOG_PROC_BREAK;
                 CDEBUG(D_HA, "fetch generation log, send cookie\n");
-                llog_cancel(ctxt, NULL, 1, &cookie, 0);
+               llog_cancel(NULL, ctxt, NULL, 1, &cookie, 0);
                 RETURN(rc);
                 }
                 break;