X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdfilter%2Ffilter_log.c;h=8cda0481572f625cf73ab9add89afa47e3696841;hb=824c90baa518327065ba74ac138160304c969d81;hp=825748726f2e7842ee3d0e011692bc45c9754f7d;hpb=2dc9c16e770415d56839e1996015fec5fab93f29;p=fs%2Flustre-release.git diff --git a/lustre/obdfilter/filter_log.c b/lustre/obdfilter/filter_log.c index 8257487..8cda048 100644 --- a/lustre/obdfilter/filter_log.c +++ b/lustre/obdfilter/filter_log.c @@ -8,39 +8,44 @@ * Author: Andreas Dilger * Author: Phil Schwan * - * This file is part of Lustre, http://www.lustre.org. + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. */ #define DEBUG_SUBSYSTEM S_FILTER +#ifdef HAVE_KERNEL_CONFIG_H #include +#endif #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "filter_internal.h" -int filter_log_sz_change(struct llog_handle *cathandle, +int filter_log_sz_change(struct llog_handle *cathandle, struct ll_fid *mds_fid, __u32 io_epoch, - struct llog_cookie *logcookie, + struct llog_cookie *logcookie, struct inode *inode) { struct llog_size_change_rec *lsc; @@ -48,14 +53,14 @@ int filter_log_sz_change(struct llog_handle *cathandle, struct ost_filterdata *ofd; ENTRY; - down(&inode->i_sem); + LOCK_INODE_MUTEX(inode); ofd = inode->i_filterdata; - + if (ofd && ofd->ofd_epoch >= io_epoch) { if (ofd->ofd_epoch > io_epoch) - CERROR("client sent old epoch %d for obj ino %ld\n", + CERROR("client sent old epoch %d for obj ino %ld\n", io_epoch, inode->i_ino); - up(&inode->i_sem); + UNLOCK_INODE_MUTEX(inode); RETURN(0); } @@ -70,7 +75,7 @@ int filter_log_sz_change(struct llog_handle *cathandle, ofd->ofd_epoch = io_epoch; } /* the decision to write a record is now made, unlock */ - up(&inode->i_sem); + UNLOCK_INODE_MUTEX(inode); OBD_ALLOC(lsc, sizeof(*lsc)); if (lsc == NULL) @@ -91,73 +96,40 @@ int filter_log_sz_change(struct llog_handle *cathandle, out: RETURN(rc); } -struct obd_llogs * filter_grab_llog_for_group(struct obd_device *, int); /* When this (destroy) operation is committed, return the cancel cookie */ void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno, void *cb_data, int error) { struct llog_cookie *cookie = cb_data; - struct obd_llogs *llogs = NULL; - struct llog_ctxt *ctxt; - - /* we have to find context for right group */ - llogs = filter_grab_llog_for_group(obd, cookie->lgc_lgl.lgl_ogr); - - if (llogs) { - ctxt = llog_get_context(llogs, cookie->lgc_subsys + 1); - if (ctxt) { - llog_cancel(ctxt, 1, cookie, 0, NULL); - } else - CERROR("no valid context for group "LPU64"\n", - cookie->lgc_lgl.lgl_ogr); - } else - CERROR("unknown group "LPU64"!\n", cookie->lgc_lgl.lgl_ogr); - - OBD_FREE(cb_data, sizeof(struct llog_cookie)); + int rc; + + if (error != 0) { + CDEBUG(D_INODE, "not cancelling llog cookie on error %d\n", + error); + return; + } + + rc = llog_cancel(llog_get_context(obd, cookie->lgc_subsys + 1), + NULL, 1, cookie, 0); + if (rc) + CERROR("error cancelling log cookies: rc = %d\n", rc); + OBD_FREE(cookie, sizeof(*cookie)); } /* Callback for processing the unlink log record received from MDS by - * llog_client_api. - */ -int filter_recov_log_unlink_cb(struct llog_handle *llh, - struct llog_rec_hdr *rec, void *data) + * llog_client_api. */ +static int filter_recov_log_unlink_cb(struct llog_ctxt *ctxt, + struct llog_rec_hdr *rec, + struct llog_cookie *cookie) { - struct llog_ctxt *ctxt = llh->lgh_ctxt; struct obd_device *obd = ctxt->loc_obd; struct obd_export *exp = obd->obd_self_export; - struct llog_cookie cookie; - struct llog_gen_rec *lgr; struct llog_unlink_rec *lur; struct obdo *oa; obd_id oid; int rc = 0; ENTRY; - - if (!(le32_to_cpu(llh->lgh_hdr->llh_flags) & LLOG_F_IS_PLAIN)) { - CERROR("log is not plain\n"); - RETURN(-EINVAL); - } - if (rec->lrh_type != MDS_UNLINK_REC && - rec->lrh_type != LLOG_GEN_REC) { - CERROR("log record type error\n"); - RETURN(-EINVAL); - } - - cookie.lgc_lgl = llh->lgh_id; - cookie.lgc_subsys = LLOG_UNLINK_ORIG_CTXT; - cookie.lgc_index = le32_to_cpu(rec->lrh_index); - - if (rec->lrh_type == 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; - CWARN("fetch generation log, send cookie\n"); - llog_cancel(ctxt, 1, &cookie, 0, NULL); - RETURN(rc); - } lur = (struct llog_unlink_rec *)rec; oa = obdo_alloc(); @@ -166,15 +138,14 @@ int filter_recov_log_unlink_cb(struct llog_handle *llh, oa->o_valid |= OBD_MD_FLCOOKIE; oa->o_id = lur->lur_oid; oa->o_gr = lur->lur_ogen; - oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP; - memcpy(obdo_logcookie(oa), &cookie, sizeof(cookie)); + memcpy(obdo_logcookie(oa), cookie, sizeof(*cookie)); oid = oa->o_id; - rc = obd_destroy(exp, oa, NULL, NULL); + rc = filter_destroy(exp, oa, NULL, NULL, NULL); obdo_free(oa); if (rc == -ENOENT) { CDEBUG(D_HA, "object already removed, send cookie\n"); - llog_cancel(ctxt, 1, &cookie, 0, NULL); + llog_cancel(ctxt, NULL, 1, cookie, 0); RETURN(0); } @@ -183,3 +154,88 @@ int filter_recov_log_unlink_cb(struct llog_handle *llh, RETURN(rc); } + +/* Callback for processing the setattr log record received from MDS by + * llog_client_api. */ +static int filter_recov_log_setattr_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 llog_setattr_rec *lsr; + struct obd_info oinfo = { { { 0 } } }; + obd_id oid; + int rc = 0; + ENTRY; + + lsr = (struct llog_setattr_rec *)rec; + oinfo.oi_oa = obdo_alloc(); + + 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_uid = lsr->lsr_uid; + oinfo.oi_oa->o_gid = lsr->lsr_gid; + memcpy(obdo_logcookie(oinfo.oi_oa), cookie, sizeof(*cookie)); + oid = oinfo.oi_oa->o_id; + + rc = filter_setattr(exp, &oinfo, NULL); + obdo_free(oinfo.oi_oa); + + if (rc == -ENOENT) { + CDEBUG(D_HA, "object already removed, send cookie\n"); + llog_cancel(ctxt, NULL, 1, cookie, 0); + RETURN(0); + } + + if (rc == 0) + CDEBUG(D_HA, "object: "LPU64" in record is chown/chgrp\n", oid); + + RETURN(rc); +} + +int filter_recov_log_mds_ost_cb(struct llog_handle *llh, + struct llog_rec_hdr *rec, void *data) +{ + struct llog_ctxt *ctxt = llh->lgh_ctxt; + struct llog_cookie cookie; + int rc = 0; + ENTRY; + + if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) { + CERROR("log is not plain\n"); + RETURN(-EINVAL); + } + + cookie.lgc_lgl = llh->lgh_id; + cookie.lgc_subsys = LLOG_MDS_OST_ORIG_CTXT; + cookie.lgc_index = rec->lrh_index; + + switch (rec->lrh_type) { + case MDS_UNLINK_REC: + rc = filter_recov_log_unlink_cb(ctxt, rec, &cookie); + break; + case MDS_SETATTR_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); + RETURN(rc); + } + break; + default: + CERROR("log record type %08x unknown\n", rec->lrh_type); + RETURN(-EINVAL); + break; + } + + RETURN(rc); +}