X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_recovery.c;h=170933366f636ac6f15c53046b8cc8812963ecad;hb=5cdc35aa8411c5369b4018748aaaabdf7b1952e4;hp=3a6ab9f1e811922dbe494c3873dbbecd873c339e;hpb=857874862ddffa816593e8d1c1f65587ca226bb7;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_recovery.c b/lustre/mdt/mdt_recovery.c index 3a6ab9f..1709333 100644 --- a/lustre/mdt/mdt_recovery.c +++ b/lustre/mdt/mdt_recovery.c @@ -1,31 +1,46 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * linux/mdt/mdt_recovery.c - * Lustre Metadata Target (mdt) recovery-related methods + * GPL HEADER START * - * Copyright (C) 2002-2006 Cluster File Systems, Inc. - * Author: Huang Hua - * Author: Pershin Mike + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * This file is part of the Lustre file system, http://www.lustre.org - * Lustre is a trademark of Cluster File Systems, Inc. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * 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. + * This program 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 version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * 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 + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * - * 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. + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/mdt/mdt_recovery.c + * + * Lustre Metadata Target (mdt) recovery-related methods + * + * Author: Huang Hua + * Author: Pershin Mike */ + #ifndef EXPORT_SYMTAB # define EXPORT_SYMTAB #endif @@ -62,52 +77,48 @@ const struct lu_buf *mdt_buf_const(const struct lu_env *env, return buf; } -int mdt_record_read(const struct lu_env *env, - struct dt_object *dt, struct lu_buf *buf, loff_t *pos) +static inline int mdt_trans_credit_get(const struct lu_env *env, + struct mdt_device *mdt, + enum mdt_txn_op op) { - int rc; - - LASSERTF(dt != NULL, "dt is NULL when we want to read record\n"); - - rc = dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA); - - if (rc == buf->lb_len) - rc = 0; - else if (rc >= 0) - rc = -EFAULT; - return rc; + struct dt_device *dev = mdt->mdt_bottom; + int cr; + switch (op) { + case MDT_TXN_CAPA_KEYS_WRITE_OP: + case MDT_TXN_LAST_RCVD_WRITE_OP: + cr = dev->dd_ops->dt_credit_get(env, + dev, + DTO_WRITE_BLOCK); + break; + default: + LBUG(); + } + return cr; } -int mdt_record_write(const struct lu_env *env, - struct dt_object *dt, const struct lu_buf *buf, - loff_t *pos, struct thandle *th) +void mdt_trans_credit_init(const struct lu_env *env, + struct mdt_device *mdt, + enum mdt_txn_op op) { - int rc; + struct mdt_thread_info *mti; + struct txn_param *p; + int cr; - LASSERTF(dt != NULL, "dt is NULL when we want to write record\n"); - LASSERT(th != NULL); - rc = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, BYPASS_CAPA); - if (rc == buf->lb_len) - rc = 0; - else if (rc >= 0) - rc = -EFAULT; - return rc; -} -/* only one record write */ + mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); + p = &mti->mti_txn_param; -enum { - MDT_TXN_LAST_RCVD_WRITE_CREDITS = 3 -}; + cr = mdt_trans_credit_get(env, mdt, op); + txn_param_init(p, cr); +} struct thandle* mdt_trans_start(const struct lu_env *env, - struct mdt_device *mdt, int credits) + struct mdt_device *mdt) { struct mdt_thread_info *mti; struct txn_param *p; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); p = &mti->mti_txn_param; - txn_param_init(p, credits); /* export can require sync operations */ if (mti->mti_exp != NULL) @@ -122,61 +133,6 @@ void mdt_trans_stop(const struct lu_env *env, mdt->mdt_bottom->dd_ops->dt_trans_stop(env, th); } -/* last_rcvd handling */ -static inline void lsd_le_to_cpu(struct lr_server_data *buf, - struct lr_server_data *lsd) -{ - memcpy(lsd->lsd_uuid, buf->lsd_uuid, sizeof (lsd->lsd_uuid)); - lsd->lsd_last_transno = le64_to_cpu(buf->lsd_last_transno); - lsd->lsd_mount_count = le64_to_cpu(buf->lsd_mount_count); - lsd->lsd_feature_compat = le32_to_cpu(buf->lsd_feature_compat); - lsd->lsd_feature_rocompat = le32_to_cpu(buf->lsd_feature_rocompat); - lsd->lsd_feature_incompat = le32_to_cpu(buf->lsd_feature_incompat); - lsd->lsd_server_size = le32_to_cpu(buf->lsd_server_size); - lsd->lsd_client_start = le32_to_cpu(buf->lsd_client_start); - lsd->lsd_client_size = le16_to_cpu(buf->lsd_client_size); -} - -static inline void lsd_cpu_to_le(struct lr_server_data *lsd, - struct lr_server_data *buf) -{ - memcpy(buf->lsd_uuid, lsd->lsd_uuid, sizeof (lsd->lsd_uuid)); - buf->lsd_last_transno = cpu_to_le64(lsd->lsd_last_transno); - buf->lsd_mount_count = cpu_to_le64(lsd->lsd_mount_count); - buf->lsd_feature_compat = cpu_to_le32(lsd->lsd_feature_compat); - buf->lsd_feature_rocompat = cpu_to_le32(lsd->lsd_feature_rocompat); - buf->lsd_feature_incompat = cpu_to_le32(lsd->lsd_feature_incompat); - buf->lsd_server_size = cpu_to_le32(lsd->lsd_server_size); - buf->lsd_client_start = cpu_to_le32(lsd->lsd_client_start); - buf->lsd_client_size = cpu_to_le16(lsd->lsd_client_size); -} - -static inline void lcd_le_to_cpu(struct lsd_client_data *buf, - struct lsd_client_data *lcd) -{ - memcpy(lcd->lcd_uuid, buf->lcd_uuid, sizeof (lcd->lcd_uuid)); - lcd->lcd_last_transno = le64_to_cpu(buf->lcd_last_transno); - lcd->lcd_last_xid = le64_to_cpu(buf->lcd_last_xid); - lcd->lcd_last_result = le32_to_cpu(buf->lcd_last_result); - lcd->lcd_last_data = le32_to_cpu(buf->lcd_last_data); - lcd->lcd_last_close_transno = le64_to_cpu(buf->lcd_last_close_transno); - lcd->lcd_last_close_xid = le64_to_cpu(buf->lcd_last_close_xid); - lcd->lcd_last_close_result = le32_to_cpu(buf->lcd_last_close_result); -} - -static inline void lcd_cpu_to_le(struct lsd_client_data *lcd, - struct lsd_client_data *buf) -{ - memcpy(buf->lcd_uuid, lcd->lcd_uuid, sizeof (lcd->lcd_uuid)); - buf->lcd_last_transno = cpu_to_le64(lcd->lcd_last_transno); - buf->lcd_last_xid = cpu_to_le64(lcd->lcd_last_xid); - buf->lcd_last_result = cpu_to_le32(lcd->lcd_last_result); - buf->lcd_last_data = cpu_to_le32(lcd->lcd_last_data); - buf->lcd_last_close_transno = cpu_to_le64(lcd->lcd_last_close_transno); - buf->lcd_last_close_xid = cpu_to_le64(lcd->lcd_last_close_xid); - buf->lcd_last_close_result = cpu_to_le32(lcd->lcd_last_close_result); -} - static inline int mdt_last_rcvd_header_read(const struct lu_env *env, struct mdt_device *mdt) { @@ -186,53 +142,46 @@ static inline int mdt_last_rcvd_header_read(const struct lu_env *env, mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); mti->mti_off = 0; - rc = mdt_record_read(env, mdt->mdt_last_rcvd, - mdt_buf(env, &mti->mti_lsd, sizeof(mti->mti_lsd)), - &mti->mti_off); + rc = dt_record_read(env, mdt->mdt_last_rcvd, + mdt_buf(env, &mti->mti_lsd, sizeof(mti->mti_lsd)), + &mti->mti_off); if (rc == 0) lsd_le_to_cpu(&mti->mti_lsd, &mdt->mdt_lsd); - CDEBUG(D_INFO, "read last_rcvd header rc = %d:\n" - "uuid = %s\n" - "last_transno = "LPU64"\n", - rc, mdt->mdt_lsd.lsd_uuid, - mdt->mdt_lsd.lsd_last_transno); + CDEBUG(D_INFO, "read last_rcvd header rc = %d, uuid = %s, " + "last_transno = "LPU64"\n", rc, mdt->mdt_lsd.lsd_uuid, + mdt->mdt_lsd.lsd_last_transno); return rc; } -static inline int mdt_last_rcvd_header_write(const struct lu_env *env, - struct mdt_device *mdt) +static int mdt_last_rcvd_header_write(const struct lu_env *env, + struct mdt_device *mdt, + struct thandle *th) { struct mdt_thread_info *mti; - struct thandle *th; int rc; ENTRY; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); - th = mdt_trans_start(env, mdt, MDT_TXN_LAST_RCVD_WRITE_CREDITS); - if (IS_ERR(th)) - RETURN(PTR_ERR(th)); - - mti->mti_off = 0; + mti->mti_off = 0; lsd_cpu_to_le(&mdt->mdt_lsd, &mti->mti_lsd); - rc = mdt_record_write(env, mdt->mdt_last_rcvd, - mdt_buf_const(env, &mti->mti_lsd, sizeof(mti->mti_lsd)), - &mti->mti_off, th); + rc = dt_record_write(env, mdt->mdt_last_rcvd, + mdt_buf_const(env, &mti->mti_lsd, + sizeof(mti->mti_lsd)), + &mti->mti_off, th); - mdt_trans_stop(env, mdt, th); + CDEBUG(D_INFO, "write last_rcvd header rc = %d, uuid = %s, " + "last_transno = "LPU64"\n", rc, mdt->mdt_lsd.lsd_uuid, + mdt->mdt_lsd.lsd_last_transno); - CDEBUG(D_INFO, "write last_rcvd header rc = %d:\n" - "uuid = %s\nlast_transno = "LPU64"\n", - rc, mdt->mdt_lsd.lsd_uuid, mdt->mdt_lsd.lsd_last_transno); - RETURN(rc); } -static int mdt_last_rcvd_read(const struct lu_env *env, - struct mdt_device *mdt, - struct lsd_client_data *lcd, loff_t *off) +static int mdt_last_rcvd_read(const struct lu_env *env, struct mdt_device *mdt, + struct lsd_client_data *lcd, loff_t *off, + int index) { struct mdt_thread_info *mti; struct lsd_client_data *tmp; @@ -240,30 +189,21 @@ static int mdt_last_rcvd_read(const struct lu_env *env, mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); tmp = &mti->mti_lcd; - rc = mdt_record_read(env, mdt->mdt_last_rcvd, - mdt_buf(env, tmp, sizeof(*tmp)), off); - if (rc == 0) + rc = dt_record_read(env, mdt->mdt_last_rcvd, + mdt_buf(env, tmp, sizeof(*tmp)), off); + if (rc == 0) { + check_lcd(mdt2obd_dev(mdt)->obd_name, index, tmp); lcd_le_to_cpu(tmp, lcd); + } - CDEBUG(D_INFO, "read lcd @%d rc = %d:\n" - "uuid = %s\n" - "last_transno = "LPU64"\n" - "last_xid = "LPU64"\n" - "last_result = %u\n" - "last_data = %u\n" - "last_close_transno = "LPU64"\n" - "last_close_xid = "LPU64"\n" - "last_close_result = %u\n", - (int)(*off - sizeof(*tmp)), - rc, - lcd->lcd_uuid, - lcd->lcd_last_transno, - lcd->lcd_last_xid, - lcd->lcd_last_result, - lcd->lcd_last_data, - lcd->lcd_last_close_transno, - lcd->lcd_last_close_xid, - lcd->lcd_last_close_result); + CDEBUG(D_INFO, "read lcd @%d rc = %d, uuid = %s, last_transno = "LPU64 + ", last_xid = "LPU64", last_result = %u, last_data = %u, " + "last_close_transno = "LPU64", last_close_xid = "LPU64", " + "last_close_result = %u\n", (int)(*off - sizeof(*tmp)), + rc, lcd->lcd_uuid, lcd->lcd_last_transno, lcd->lcd_last_xid, + lcd->lcd_last_result, lcd->lcd_last_data, + lcd->lcd_last_close_transno, lcd->lcd_last_close_xid, + lcd->lcd_last_close_result); return rc; } @@ -282,39 +222,27 @@ static int mdt_last_rcvd_write(const struct lu_env *env, lcd_cpu_to_le(lcd, tmp); - rc = mdt_record_write(env, mdt->mdt_last_rcvd, - mdt_buf_const(env, tmp, sizeof(*tmp)), off, th); - - CDEBUG(D_INFO, "write lcd @%d rc = %d:\n" - "uuid = %s\n" - "last_transno = "LPU64"\n" - "last_xid = "LPU64"\n" - "last_result = %u\n" - "last_data = %u\n" - "last_close_transno = "LPU64"\n" - "last_close_xid = "LPU64"\n" - "last_close_result = %u\n", - (int)(*off - sizeof(*tmp)), - rc, - lcd->lcd_uuid, - lcd->lcd_last_transno, - lcd->lcd_last_xid, - lcd->lcd_last_result, - lcd->lcd_last_data, - lcd->lcd_last_close_transno, - lcd->lcd_last_close_xid, - lcd->lcd_last_close_result); + rc = dt_record_write(env, mdt->mdt_last_rcvd, + mdt_buf_const(env, tmp, sizeof(*tmp)), off, th); + + CDEBUG(D_INFO, "write lcd @%d rc = %d, uuid = %s, last_transno = "LPU64 + ", last_xid = "LPU64", last_result = %u, last_data = %u, " + "last_close_transno = "LPU64", last_close_xid = "LPU64" ," + "last_close_result = %u\n", (int)(*off - sizeof(*tmp)), + rc, lcd->lcd_uuid, lcd->lcd_last_transno, lcd->lcd_last_xid, + lcd->lcd_last_result, lcd->lcd_last_data, + lcd->lcd_last_close_transno, lcd->lcd_last_close_xid, + lcd->lcd_last_close_result); return rc; } - static int mdt_clients_data_init(const struct lu_env *env, struct mdt_device *mdt, unsigned long last_size) { struct lr_server_data *lsd = &mdt->mdt_lsd; struct lsd_client_data *lcd = NULL; - struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd; + struct obd_device *obd = mdt2obd_dev(mdt); loff_t off; int cl_idx; int rc = 0; @@ -338,7 +266,7 @@ static int mdt_clients_data_init(const struct lu_env *env, off = lsd->lsd_client_start + cl_idx * lsd->lsd_client_size; - rc = mdt_last_rcvd_read(env, mdt, lcd, &off); + rc = mdt_last_rcvd_read(env, mdt, lcd, &off, cl_idx); if (rc) { CERROR("error reading MDS %s idx %d, off %llu: rc %d\n", LAST_RCVD, cl_idx, off, rc); @@ -367,18 +295,21 @@ static int mdt_clients_data_init(const struct lu_env *env, if (IS_ERR(exp)) { if (PTR_ERR(exp) == -EALREADY) { /* export already exists, zero out this one */ - lcd->lcd_uuid[0] = '\0'; - } else + lcd->lcd_uuid[0] = '\0'; + } else { GOTO(err_client, rc = PTR_ERR(exp)); + } } else { - struct mdt_thread_info *mti; + struct mdt_thread_info *mti; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); LASSERT(mti != NULL); mti->mti_exp = exp; exp->exp_mdt_data.med_lcd = lcd; rc = mdt_client_add(env, mdt, cl_idx); /* can't fail existing */ - LASSERTF(rc == 0, "rc = %d\n", rc); + LASSERTF(rc == 0, "rc = %d\n", rc); + /* VBR: set export last committed version */ + exp->exp_last_committed = last_transno; lcd = NULL; spin_lock(&exp->exp_lock); exp->exp_connecting = 0; @@ -404,14 +335,16 @@ err_client: } static int mdt_server_data_init(const struct lu_env *env, - struct mdt_device *mdt) + struct mdt_device *mdt, + struct lustre_sb_info *lsi) { struct lr_server_data *lsd = &mdt->mdt_lsd; struct lsd_client_data *lcd = NULL; - struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd; + struct obd_device *obd = mdt2obd_dev(mdt); struct mdt_thread_info *mti; struct dt_object *obj; struct lu_attr *la; + struct lustre_disk_data *ldd; unsigned long last_rcvd_size; __u64 mount_count; int rc; @@ -444,9 +377,10 @@ static int mdt_server_data_init(const struct lu_env *env, lsd->lsd_server_size = LR_SERVER_SIZE; lsd->lsd_client_start = LR_CLIENT_START; lsd->lsd_client_size = LR_CLIENT_SIZE; + lsd->lsd_feature_compat = OBD_COMPAT_MDT; lsd->lsd_feature_rocompat = OBD_ROCOMPAT_LOVOBJID; lsd->lsd_feature_incompat = OBD_INCOMPAT_MDT | - OBD_INCOMPAT_COMMON_LR; + OBD_INCOMPAT_COMMON_LR; } else { LCONSOLE_WARN("%s: used disk, loading\n", obd->obd_name); rc = mdt_last_rcvd_header_read(env, mdt); @@ -461,10 +395,43 @@ static int mdt_server_data_init(const struct lu_env *env, obd->obd_uuid.uuid, lsd->lsd_uuid); GOTO(out, rc = -EINVAL); } + lsd->lsd_feature_compat |= OBD_COMPAT_MDT; + lsd->lsd_feature_incompat |= OBD_INCOMPAT_MDT | + OBD_INCOMPAT_COMMON_LR; } mount_count = lsd->lsd_mount_count; - lsd->lsd_feature_compat = OBD_COMPAT_MDT; + ldd = lsi->lsi_ldd; + + if (lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP) { + CERROR("%s: unsupported incompat filesystem feature(s) %x\n", + obd->obd_name, + lsd->lsd_feature_incompat & ~MDT_INCOMPAT_SUPP); + GOTO(out, rc = -EINVAL); + } + if (lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP) { + CERROR("%s: unsupported read-only filesystem feature(s) %x\n", + obd->obd_name, + lsd->lsd_feature_rocompat & ~MDT_ROCOMPAT_SUPP); + /* XXX: Do something like remount filesystem read-only */ + GOTO(out, rc = -EINVAL); + } + /** Interop: evict all clients at first boot with 1.8 last_rcvd */ + if (!(lsd->lsd_feature_compat & OBD_COMPAT_20)) { + LCONSOLE_WARN("Mounting %s at first time on 1.8 FS, remove all" + " clients for interop needs\n", obd->obd_name); + simple_truncate(lsi->lsi_srv_mnt->mnt_sb->s_root, + lsi->lsi_srv_mnt, LAST_RCVD, + lsd->lsd_client_start); + last_rcvd_size = lsd->lsd_client_start; + /** set 2.0 flag to upgrade/downgrade between 1.8 and 2.0 */ + lsd->lsd_feature_compat |= OBD_COMPAT_20; + } + + if (ldd->ldd_flags & LDD_F_IAM_DIR) + lsd->lsd_feature_incompat |= OBD_INCOMPAT_IAM_DIR; + + lsd->lsd_feature_incompat |= OBD_INCOMPAT_FID; spin_lock(&mdt->mdt_transno_lock); mdt->mdt_last_transno = lsd->lsd_last_transno; @@ -505,7 +472,7 @@ static int mdt_server_data_init(const struct lu_env *env, obd->obd_last_committed = mdt->mdt_last_transno; spin_unlock(&mdt->mdt_transno_lock); - mdt->mdt_mount_count++; + mdt->mdt_mount_count = mount_count + 1; lsd->lsd_mount_count = mdt->mdt_mount_count; /* save it, so mount count and last_transno is current */ @@ -516,7 +483,7 @@ static int mdt_server_data_init(const struct lu_env *env, RETURN(0); err_client: - target_recovery_fini(obd); + class_disconnect_exports(obd); out: return rc; } @@ -524,8 +491,16 @@ out: static int mdt_server_data_update(const struct lu_env *env, struct mdt_device *mdt) { - int rc = 0; - ENTRY; + struct mdt_thread_info *mti; + struct thandle *th; + int rc; + + mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); + + mdt_trans_credit_init(env, mdt, MDT_TXN_LAST_RCVD_WRITE_OP); + th = mdt_trans_start(env, mdt); + if (IS_ERR(th)) + RETURN(PTR_ERR(th)); CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n", mdt->mdt_mount_count, mdt->mdt_last_transno); @@ -534,22 +509,11 @@ static int mdt_server_data_update(const struct lu_env *env, mdt->mdt_lsd.lsd_last_transno = mdt->mdt_last_transno; spin_unlock(&mdt->mdt_transno_lock); - /* - * This may be called from difficult reply handler and - * mdt->mdt_last_rcvd may be NULL that time. - */ - if (mdt->mdt_last_rcvd != NULL) - rc = mdt_last_rcvd_header_write(env, mdt); - RETURN(rc); + rc = mdt_last_rcvd_header_write(env, mdt, th); + mdt_trans_stop(env, mdt, th); + return rc; } -void mdt_cb_new_client(const struct mdt_device *mdt, __u64 transno, - void *data, int err) -{ - struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd; - - target_client_add_cb(obd, transno, data, err); -} int mdt_client_new(const struct lu_env *env, struct mdt_device *mdt) { @@ -558,7 +522,7 @@ int mdt_client_new(const struct lu_env *env, struct mdt_device *mdt) struct mdt_export_data *med; struct lsd_client_data *lcd; struct lr_server_data *lsd = &mdt->mdt_lsd; - struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd; + struct obd_device *obd = mdt2obd_dev(mdt); struct thandle *th; loff_t off; int rc; @@ -599,22 +563,29 @@ int mdt_client_new(const struct lu_env *env, struct mdt_device *mdt) init_mutex(&med->med_lcd_lock); LASSERTF(med->med_lr_off > 0, "med_lr_off = %llu\n", med->med_lr_off); - /* write new client data */ + + /* Write new client data. */ off = med->med_lr_off; - th = mdt_trans_start(env, mdt, MDT_TXN_LAST_RCVD_WRITE_CREDITS); + mdt_trans_credit_init(env, mdt, MDT_TXN_LAST_RCVD_WRITE_OP); + + th = mdt_trans_start(env, mdt); if (IS_ERR(th)) RETURN(PTR_ERR(th)); - /* until this operations will be committed the sync is needed for this - * export */ - mdt_trans_add_cb(th, mdt_cb_new_client, mti->mti_exp); + /* + * Until this operations will be committed the sync is needed + * for this export. This should be done _after_ starting the + * transaction so that many connecting clients will not bring + * server down with lots of sync writes. + */ + mdt_trans_add_cb(th, lut_cb_client, class_export_cb_get(mti->mti_exp)); spin_lock(&mti->mti_exp->exp_lock); mti->mti_exp->exp_need_sync = 1; spin_unlock(&mti->mti_exp->exp_lock); rc = mdt_last_rcvd_write(env, mdt, lcd, &off, th); - CDEBUG(D_INFO, "wrote client lcd at idx %u off %llu (len "LPSZ")\n", - cl_idx, med->med_lr_off, sizeof(*lcd)); + CDEBUG(D_INFO, "wrote client lcd at idx %u off %llu (len %u)\n", + cl_idx, med->med_lr_off, (int)sizeof(*lcd)); mdt_trans_stop(env, mdt, th); RETURN(rc); @@ -634,7 +605,7 @@ int mdt_client_add(const struct lu_env *env, struct mdt_thread_info *mti; struct mdt_export_data *med; unsigned long *bitmap = mdt->mdt_client_bitmap; - struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd; + struct obd_device *obd = mdt2obd_dev(mdt); struct lr_server_data *lsd = &mdt->mdt_lsd; int rc = 0; ENTRY; @@ -676,22 +647,24 @@ int mdt_client_del(const struct lu_env *env, struct mdt_device *mdt) struct mdt_thread_info *mti; struct mdt_export_data *med; struct lsd_client_data *lcd; - struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd; - struct thandle *th; - loff_t off; - int rc = 0; + struct obd_device *obd = mdt2obd_dev(mdt); + struct obd_export *exp; + struct thandle *th; + loff_t off; + int rc = 0; ENTRY; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); LASSERT(mti != NULL); - med = &mti->mti_exp->exp_mdt_data; + exp = mti->mti_exp; + med = &exp->exp_mdt_data; lcd = med->med_lcd; if (!lcd) RETURN(0); /* XXX: If lcd_uuid were a real obd_uuid, I could use obd_uuid_equals */ - if (!strcmp(med->med_lcd->lcd_uuid, obd->obd_uuid.uuid)) + if (!strcmp(lcd->lcd_uuid, obd->obd_uuid.uuid)) GOTO(free, 0); CDEBUG(D_INFO, "freeing client at idx %u, offset %lld\n", @@ -719,40 +692,36 @@ int mdt_client_del(const struct lu_env *env, struct mdt_device *mdt) LBUG(); } - /* - * This may be called from difficult reply handler path and - * mdt->mdt_last_rcvd may be NULL that time. - */ - if (mdt->mdt_last_rcvd != NULL) { - th = mdt_trans_start(env, mdt, MDT_TXN_LAST_RCVD_WRITE_CREDITS); - if (IS_ERR(th)) - GOTO(free, rc = PTR_ERR(th)); - - mutex_down(&med->med_lcd_lock); - memset(lcd, 0, sizeof *lcd); + /* Make sure the server's last_transno is up to date. + * This should be done before zeroing client slot so last_transno will + * be in server data or in client data in case of failure */ + mdt_server_data_update(env, mdt); - rc = mdt_last_rcvd_write(env, mdt, lcd, &off, th); - mutex_up(&med->med_lcd_lock); - mdt_trans_stop(env, mdt, th); - } + mdt_trans_credit_init(env, mdt, MDT_TXN_LAST_RCVD_WRITE_OP); + th = mdt_trans_start(env, mdt); + if (IS_ERR(th)) + GOTO(free, rc = PTR_ERR(th)); - CDEBUG(rc == 0 ? D_INFO : D_ERROR, "Zeroing out client idx %u in " - "%s rc %d\n", med->med_lr_idx, LAST_RCVD, rc); + mutex_down(&med->med_lcd_lock); + memset(lcd, 0, sizeof *lcd); + rc = mdt_last_rcvd_write(env, mdt, lcd, &off, th); + med->med_lcd = NULL; + mutex_up(&med->med_lcd_lock); + mdt_trans_stop(env, mdt, th); spin_lock(&mdt->mdt_client_bitmap_lock); clear_bit(med->med_lr_idx, mdt->mdt_client_bitmap); spin_unlock(&mdt->mdt_client_bitmap_lock); - /* - * Make sure the server's last_transno is up to date. Do this after the - * client is freed so we know all the client's transactions have been - * committed. - */ - mdt_server_data_update(env, mdt); - EXIT; -free: + CDEBUG(rc == 0 ? D_INFO : D_ERROR, "Zeroing out client idx %u in " + "%s, rc %d\n", med->med_lr_idx, LAST_RCVD, rc); OBD_FREE_PTR(lcd); + RETURN(0); +free: + mutex_down(&med->med_lcd_lock); med->med_lcd = NULL; + mutex_up(&med->med_lcd_lock); + OBD_FREE_PTR(lcd); return 0; } @@ -769,7 +738,6 @@ static int mdt_last_rcvd_update(struct mdt_thread_info *mti, loff_t off; int err; __s32 rc = th->th_result; - __u64 *transno_p; ENTRY; LASSERT(req); @@ -777,25 +745,38 @@ static int mdt_last_rcvd_update(struct mdt_thread_info *mti, LASSERT(mdt); med = &req->rq_export->exp_mdt_data; LASSERT(med); + + mutex_down(&med->med_lcd_lock); lcd = med->med_lcd; - /* if the export has already been failed, we have no last_rcvd slot */ - if (req->rq_export->exp_failed) { + /* if the export has already been disconnected, we have no last_rcvd slot, + * update server data with latest transno then */ + if (lcd == NULL) { + mutex_up(&med->med_lcd_lock); CWARN("commit transaction for disconnected client %s: rc %d\n", req->rq_export->exp_client_uuid.uuid, rc); - if (rc == 0) - rc = -ENOTCONN; - RETURN(rc); + err = mdt_last_rcvd_header_write(mti->mti_env, mdt, th); + RETURN(err); } off = med->med_lr_off; - mutex_down(&med->med_lcd_lock); + LASSERT(ergo(mti->mti_transno == 0, rc != 0)); if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_CLOSE || lustre_msg_get_opc(req->rq_reqmsg) == MDS_DONE_WRITING) { - transno_p = &lcd->lcd_last_close_transno; + if (mti->mti_transno != 0) + lcd->lcd_last_close_transno = mti->mti_transno; lcd->lcd_last_close_xid = req->rq_xid; lcd->lcd_last_close_result = rc; } else { - transno_p = &lcd->lcd_last_transno; + /* VBR: save versions in last_rcvd for reconstruct. */ + __u64 *pre_versions = lustre_msg_get_versions(req->rq_repmsg); + if (pre_versions) { + lcd->lcd_pre_versions[0] = pre_versions[0]; + lcd->lcd_pre_versions[1] = pre_versions[1]; + lcd->lcd_pre_versions[2] = pre_versions[2]; + lcd->lcd_pre_versions[3] = pre_versions[3]; + } + if (mti->mti_transno != 0) + lcd->lcd_last_transno = mti->mti_transno; lcd->lcd_last_xid = req->rq_xid; lcd->lcd_last_result = rc; /*XXX: save intent_disposition in mdt_thread_info? @@ -804,18 +785,6 @@ static int mdt_last_rcvd_update(struct mdt_thread_info *mti, lcd->lcd_last_data = mti->mti_opdata; } - /* - * When we store zero transno in lcd we can lost last transno value - * because lcd contains 0, but lsd is not yet written - * The server data should be updated also if the latest - * transno is rewritten by zero. See the bug 11125 for details. - */ - if (mti->mti_transno == 0 && - *transno_p == mdt->mdt_last_transno) - mdt_server_data_update(mti->mti_env, mdt); - - *transno_p = mti->mti_transno; - if (off <= 0) { CERROR("client idx %d has offset %lld\n", med->med_lr_idx, off); err = -EINVAL; @@ -832,10 +801,24 @@ extern struct lu_context_key mdt_thread_key; static int mdt_txn_start_cb(const struct lu_env *env, struct txn_param *param, void *cookie) { - param->tp_credits += MDT_TXN_LAST_RCVD_WRITE_CREDITS; + struct mdt_device *mdt = cookie; + + param->tp_credits += mdt_trans_credit_get(env, mdt, + MDT_TXN_LAST_RCVD_WRITE_OP); return 0; } +/* Set new object versions */ +static void mdt_versions_set(struct mdt_thread_info *info) +{ + int i; + for (i = 0; i < PTLRPC_NUM_VERSIONS; i++) + if (info->mti_mos[i] != NULL) + mo_version_set(info->mti_env, + mdt_object_child(info->mti_mos[i]), + info->mti_transno); +} + /* Update last_rcvd records with latests transaction data */ static int mdt_txn_stop_cb(const struct lu_env *env, struct thandle *txn, void *cookie) @@ -859,7 +842,8 @@ static int mdt_txn_stop_cb(const struct lu_env *env, if (mti->mti_has_trans) { /* XXX: currently there are allowed cases, but the wrong cases * are also possible, so better check is needed here */ - CDEBUG(D_INFO, "More than one transaction "LPU64"\n", mti->mti_transno); + CDEBUG(D_INFO, "More than one transaction "LPU64"\n", + mti->mti_transno); return 0; } @@ -869,7 +853,6 @@ static int mdt_txn_stop_cb(const struct lu_env *env, if (mti->mti_transno != 0) { CERROR("Replay transno "LPU64" failed: rc %i\n", mti->mti_transno, txn->th_result); - mti->mti_transno = 0; } } else if (mti->mti_transno == 0) { mti->mti_transno = ++ mdt->mdt_last_transno; @@ -878,59 +861,52 @@ static int mdt_txn_stop_cb(const struct lu_env *env, if (mti->mti_transno > mdt->mdt_last_transno) mdt->mdt_last_transno = mti->mti_transno; } - + spin_unlock(&mdt->mdt_transno_lock); /* sometimes the reply message has not been successfully packed */ LASSERT(req != NULL && req->rq_repmsg != NULL); + /** VBR: set new versions */ + if (txn->th_result == 0) + mdt_versions_set(mti); + /* filling reply data */ CDEBUG(D_INODE, "transno = %llu, last_committed = %llu\n", mti->mti_transno, req->rq_export->exp_obd->obd_last_committed); req->rq_transno = mti->mti_transno; lustre_msg_set_transno(req->rq_repmsg, mti->mti_transno); - lustre_msg_set_last_xid(req->rq_repmsg, - lcd_last_xid(req->rq_export->exp_mdt_data.med_lcd)); /* save transno for the commit callback */ txi->txi_transno = mti->mti_transno; - spin_unlock(&mdt->mdt_transno_lock); + + /* add separate commit callback for transaction handling because we need + * export as parameter */ + mdt_trans_add_cb(txn, lut_cb_last_committed, + class_export_cb_get(mti->mti_exp)); return mdt_last_rcvd_update(mti, txn); } -/* commit callback, need to update last_commited value */ +/* commit callback, need to update last_committed value */ static int mdt_txn_commit_cb(const struct lu_env *env, struct thandle *txn, void *cookie) { struct mdt_device *mdt = cookie; - struct obd_device *obd = md2lu_dev(&mdt->mdt_md_dev)->ld_obd; struct mdt_txn_info *txi; int i; txi = lu_context_key_get(&txn->th_ctx, &mdt_txn_key); - /* copy of obd_transno_commit_cb() but with locking */ - spin_lock(&mdt->mdt_transno_lock); - if (txi->txi_transno > obd->obd_last_committed) { - obd->obd_last_committed = txi->txi_transno; - spin_unlock(&mdt->mdt_transno_lock); - ptlrpc_commit_replies(obd); - } else - spin_unlock(&mdt->mdt_transno_lock); - - if (txi->txi_transno) - CDEBUG(D_HA, "%s: transno "LPD64" is committed\n", - obd->obd_name, txi->txi_transno); - /* iterate through all additional callbacks */ for (i = 0; i < txi->txi_cb_count; i++) { - txi->txi_cb[i].mdt_cb_func(mdt, txi->txi_transno, - txi->txi_cb[i].mdt_cb_data, 0); + txi->txi_cb[i].lut_cb_func(&mdt->mdt_lut, txi->txi_transno, + txi->txi_cb[i].lut_cb_data, 0); } return 0; } int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt, - struct obd_device *obd) + struct obd_device *obd, + struct lustre_sb_info *lsi) { struct lu_fid fid; struct dt_object *o; @@ -945,23 +921,16 @@ int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt, mdt->mdt_txn_cb.dtc_txn_stop = mdt_txn_stop_cb; mdt->mdt_txn_cb.dtc_txn_commit = mdt_txn_commit_cb; mdt->mdt_txn_cb.dtc_cookie = mdt; + mdt->mdt_txn_cb.dtc_tag = LCT_MD_THREAD; CFS_INIT_LIST_HEAD(&mdt->mdt_txn_cb.dtc_linkage); dt_txn_callback_add(mdt->mdt_bottom, &mdt->mdt_txn_cb); - o = dt_store_open(env, mdt->mdt_bottom, LAST_RCVD, &fid); - if (!IS_ERR(o)) { - mdt->mdt_last_rcvd = o; - rc = mdt_server_data_init(env, mdt); - if (rc) - GOTO(put_last_rcvd, rc); - } else { - rc = PTR_ERR(o); - CERROR("cannot open %s: rc = %d\n", LAST_RCVD, rc); + rc = mdt_server_data_init(env, mdt, lsi); + if (rc) RETURN(rc); - } - o = dt_store_open(env, mdt->mdt_bottom, CAPA_KEYS, &fid); + o = dt_store_open(env, mdt->mdt_bottom, "", CAPA_KEYS, &fid); if (!IS_ERR(o)) { mdt->mdt_ck_obj = o; rc = mdt_capa_keys_init(env, mdt); @@ -970,29 +939,24 @@ int mdt_fs_setup(const struct lu_env *env, struct mdt_device *mdt, } else { rc = PTR_ERR(o); CERROR("cannot open %s: rc = %d\n", CAPA_KEYS, rc); - GOTO(put_last_rcvd, rc); + GOTO(disconnect_exports, rc); } RETURN(0); put_ck_object: lu_object_put(env, &o->do_lu); mdt->mdt_ck_obj = NULL; -put_last_rcvd: - lu_object_put(env, &mdt->mdt_last_rcvd->do_lu); - mdt->mdt_last_rcvd = NULL; +disconnect_exports: + class_disconnect_exports(obd); return rc; } - void mdt_fs_cleanup(const struct lu_env *env, struct mdt_device *mdt) { ENTRY; /* Remove transaction callback */ dt_txn_callback_del(mdt->mdt_bottom, &mdt->mdt_txn_cb); - if (mdt->mdt_last_rcvd) - lu_object_put(env, &mdt->mdt_last_rcvd->do_lu); - mdt->mdt_last_rcvd = NULL; if (mdt->mdt_ck_obj) lu_object_put(env, &mdt->mdt_ck_obj->do_lu); mdt->mdt_ck_obj = NULL; @@ -1016,12 +980,11 @@ static void mdt_steal_ack_locks(struct ptlrpc_request *req) if (oldrep->rs_xid != req->rq_xid) continue; - if (lustre_msg_get_opc(oldrep->rs_msg) != - lustre_msg_get_opc(req->rq_reqmsg)) - CERROR ("Resent req xid "LPX64" has mismatched opc: " + if (oldrep->rs_opc != lustre_msg_get_opc(req->rq_reqmsg)) + CERROR ("Resent req xid "LPU64" has mismatched opc: " "new %d old %d\n", req->rq_xid, lustre_msg_get_opc(req->rq_reqmsg), - lustre_msg_get_opc(oldrep->rs_msg)); + oldrep->rs_opc); svc = oldrep->rs_service; spin_lock (&svc->srv_lock); @@ -1031,18 +994,18 @@ static void mdt_steal_ack_locks(struct ptlrpc_request *req) CWARN("Stealing %d locks from rs %p x"LPD64".t"LPD64 " o%d NID %s\n", oldrep->rs_nlocks, oldrep, - oldrep->rs_xid, oldrep->rs_transno, - lustre_msg_get_opc(oldrep->rs_msg), + oldrep->rs_xid, oldrep->rs_transno, oldrep->rs_opc, libcfs_nid2str(exp->exp_connection->c_peer.nid)); for (i = 0; i < oldrep->rs_nlocks; i++) - ptlrpc_save_lock(req, - &oldrep->rs_locks[i], - oldrep->rs_modes[i]); + ptlrpc_save_lock(req, &oldrep->rs_locks[i], + oldrep->rs_modes[i], 0); oldrep->rs_nlocks = 0; DEBUG_REQ(D_HA, req, "stole locks for"); + spin_lock(&oldrep->rs_lock); ptlrpc_schedule_difficult_reply (oldrep); + spin_unlock(&oldrep->rs_lock); spin_unlock (&svc->srv_lock); break; @@ -1050,6 +1013,20 @@ static void mdt_steal_ack_locks(struct ptlrpc_request *req) spin_unlock(&exp->exp_lock); } +/** + * VBR: restore versions + */ +void mdt_vbr_reconstruct(struct ptlrpc_request *req, + struct lsd_client_data *lcd) +{ + __u64 pre_versions[4] = {0}; + pre_versions[0] = lcd->lcd_pre_versions[0]; + pre_versions[1] = lcd->lcd_pre_versions[1]; + pre_versions[2] = lcd->lcd_pre_versions[2]; + pre_versions[3] = lcd->lcd_pre_versions[3]; + lustre_msg_set_versions(req->rq_repmsg, pre_versions); +} + void mdt_req_from_lcd(struct ptlrpc_request *req, struct lsd_client_data *lcd) { @@ -1060,14 +1037,18 @@ void mdt_req_from_lcd(struct ptlrpc_request *req, lustre_msg_get_opc(req->rq_repmsg) == MDS_DONE_WRITING) { req->rq_transno = lcd->lcd_last_close_transno; req->rq_status = lcd->lcd_last_close_result; - lustre_msg_set_transno(req->rq_repmsg, req->rq_transno); - lustre_msg_set_status(req->rq_repmsg, req->rq_status); } else { req->rq_transno = lcd->lcd_last_transno; req->rq_status = lcd->lcd_last_result; - lustre_msg_set_transno(req->rq_repmsg, req->rq_transno); - lustre_msg_set_status(req->rq_repmsg, req->rq_status); + mdt_vbr_reconstruct(req, lcd); } + if (req->rq_status != 0) + req->rq_transno = 0; + lustre_msg_set_transno(req->rq_repmsg, req->rq_transno); + lustre_msg_set_status(req->rq_repmsg, req->rq_status); + DEBUG_REQ(D_RPCTRACE, req, "restoring transno "LPD64"/status %d", + req->rq_transno, req->rq_status); + mdt_steal_ack_locks(req); } @@ -1110,13 +1091,16 @@ static void mdt_reconstruct_create(struct mdt_thread_info *mti, } body = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY); + mti->mti_attr.ma_need = MA_INODE; + mti->mti_attr.ma_valid = 0; rc = mo_attr_get(mti->mti_env, mdt_object_child(child), &mti->mti_attr); if (rc == -EREMOTE) { /* object was created on remote server */ req->rq_status = rc; body->valid |= OBD_MD_MDS; } - mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr, mdt_object_fid(child)); + mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr, + mdt_object_fid(child)); mdt_object_put(mti->mti_env, child); } @@ -1147,6 +1131,8 @@ static void mdt_reconstruct_setattr(struct mdt_thread_info *mti, EXIT; return; } + mti->mti_attr.ma_need = MA_INODE; + mti->mti_attr.ma_valid = 0; mo_attr_get(mti->mti_env, mdt_object_child(obj), &mti->mti_attr); mdt_pack_attr2body(mti, body, &mti->mti_attr.ma_attr, mdt_object_fid(obj)); @@ -1169,13 +1155,6 @@ static void mdt_reconstruct_setattr(struct mdt_thread_info *mti, mdt_object_put(mti->mti_env, obj); } -static void mdt_reconstruct_setxattr(struct mdt_thread_info *mti, - struct mdt_lock_handle *lhc) -{ - /* reply nothing */ - req_capsule_shrink(mti->mti_pill, &RMF_EADATA, 0, RCL_SERVER); -} - typedef void (*mdt_reconstructor)(struct mdt_thread_info *mti, struct mdt_lock_handle *lhc); @@ -1186,7 +1165,7 @@ static mdt_reconstructor reconstructors[REINT_MAX] = { [REINT_UNLINK] = mdt_reconstruct_generic, [REINT_RENAME] = mdt_reconstruct_generic, [REINT_OPEN] = mdt_reconstruct_open, - [REINT_SETXATTR] = mdt_reconstruct_setxattr + [REINT_SETXATTR] = mdt_reconstruct_generic }; void mdt_reconstruct(struct mdt_thread_info *mti,