Whamcloud - gitweb
b=6427
[fs/lustre-release.git] / lustre / mds / mds_lmv.c
index 23d18d5..ce81bc0 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/lustre_lib.h>
 #include <linux/lustre_fsfilt.h>
 #include <linux/lustre_lite.h>
+#include <asm/div64.h>
 
 #include "mds_internal.h"
 
@@ -52,7 +53,8 @@ int mds_md_connect(struct obd_device *obd, char *md_name)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct lustre_handle conn = {0};
-        int rc, valsize, value;
+        int rc, value;
+        __u32 valsize;
         ENTRY;
 
         if (IS_ERR(mds->mds_md_obd))
@@ -75,8 +77,8 @@ int mds_md_connect(struct obd_device *obd, char *md_name)
                 GOTO(err_last, rc = -ENOTCONN);
         }
 
-        rc = obd_connect(&conn, mds->mds_md_obd,
-                         &obd->obd_uuid, OBD_OPT_MDS_CONNECTION);
+        rc = obd_connect(&conn, mds->mds_md_obd, &obd->obd_uuid, NULL,
+                         OBD_OPT_MDS_CONNECTION);
         if (rc) {
                 CERROR("MDS cannot connect to MD(LMV) %s (%d)\n",
                        md_name, rc);
@@ -208,6 +210,28 @@ int mds_md_disconnect(struct obd_device *obd, int flags)
         RETURN(rc);
 }
 
+int mds_md_reconnect(struct obd_device *obd)
+{
+        struct mds_obd *mds = &obd->u.mds;
+        struct obd_statfs osfs;
+        int err;
+        ENTRY;
+
+        /* We don't know state of connections to another MDSes
+         * before the failure. If MDS we were connected to before
+         * the failure gets failed, then it will wait for us to
+         * reconnect and will timed recovery out. bug 4920 */
+        if (mds->mds_md_connected == 0)
+                RETURN(0);
+        if (mds->mds_md_obd == NULL)
+                RETURN(0);
+
+        err = obd_statfs(mds->mds_md_obd, &osfs, jiffies - HZ);
+        if (err)
+                CERROR("can't reconnect to MDSes after recovery: %d\n", err);
+        RETURN(0);
+}
+
 int mds_md_get_attr(struct obd_device *obd, struct inode *inode,
                     struct mea **mea, int *mea_size)
 {
@@ -690,7 +714,7 @@ int mds_try_to_split_dir(struct obd_device *obd, struct dentry *dentry,
         CDEBUG(D_OTHER, "%s: create subdirs with mode %o, uid %u, gid %u\n",
                obd->obd_name, dir->i_mode, dir->i_uid, dir->i_gid);
                         
-        rc = obd_create(mds->mds_md_exp, oa,
+        rc = obd_create(mds->mds_md_exp, oa, NULL, 0,
                         (struct lov_stripe_md **)mea, NULL);
         if (rc) {
                 CERROR("Can't create remote inode, rc = %d\n", rc);
@@ -893,14 +917,28 @@ int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
         RETURN(rc);
 }
 
-int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int flags)
+int mds_choose_mdsnum(struct obd_device *obd, const char *name, int len, int flags,
+                        struct ptlrpc_peer *peer, struct inode *parent)
 {
-        struct lmv_obd *lmv;
         struct mds_obd *mds = &obd->u.mds;
+        struct lmv_obd *lmv;
         int i = mds->mds_num;
-
+        char peer_str[PTL_NALFMT_SIZE];
         if (flags & REC_REINT_CREATE) { 
                 i = mds->mds_num;
+        } else if (mds->mds_md_exp != NULL && peer != NULL) {
+                LASSERT(parent != NULL);
+                /* distribute only at root level */
+                lmv = &mds->mds_md_exp->exp_obd->u.lmv;
+                if (parent->i_ino != id_ino(&mds->mds_rootid)) {
+                        i = mds->mds_num;
+                } else {
+                        __u64 nid = peer->peer_id.nid;
+                        __u64 count = lmv->desc.ld_tgt_count;
+                        i = do_div(nid, count);
+                        CWARN("client from %s creates top dir %*s on mds #%d\n",
+                              ptlrpc_peernid2str(peer,peer_str), len, name, i+1);
+                }
         } else if (mds->mds_md_exp) {
                 lmv = &mds->mds_md_exp->exp_obd->u.lmv;
                 i = raw_name2idx(MEA_MAGIC_LAST_CHAR, lmv->desc.ld_tgt_count, name, len);
@@ -1179,7 +1217,6 @@ int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req,
 
         rc = mds_init_ucred(&uc, req, rsd);
         if (rc) {
-                CERROR("can't init ucred\n");
                 GOTO(cleanup, rc);
         }