Whamcloud - gitweb
- cleanups on client after Nikita's inspection.
authoryury <yury>
Mon, 21 Aug 2006 17:32:18 +0000 (17:32 +0000)
committeryury <yury>
Mon, 21 Aug 2006 17:32:18 +0000 (17:32 +0000)
13 files changed:
lustre/include/obd.h
lustre/include/obd_class.h
lustre/llite/llite_nfs.c
lustre/lmv/lmv_fld.c
lustre/lmv/lmv_intent.c
lustre/lmv/lmv_internal.h
lustre/lmv/lmv_obd.c
lustre/lmv/lmv_object.c
lustre/lov/lov_pack.c
lustre/mdc/mdc_internal.h
lustre/mdc/mdc_lib.c
lustre/mdc/mdc_locks.c
lustre/mdc/mdc_request.c

index 327ea0b..6b029ed 100644 (file)
@@ -952,7 +952,7 @@ struct obd_ops {
         int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
                            struct lu_placement_hint *hint);
 
-        int (*o_fid_delete)(struct obd_export *exp, struct lu_fid *fid);
+        int (*o_fid_delete)(struct obd_export *exp, const struct lu_fid *fid);
 
         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
                         __u64 max_age);
@@ -1068,7 +1068,7 @@ struct obd_ops {
         int (*o_llog_finish)(struct obd_device *obd, int count);
 
         /* metadata-only methods */
-        int (*o_pin)(struct obd_export *, struct lu_fid *fid,
+        int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
                      struct obd_client_handle *, int flag);
         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
 
@@ -1093,7 +1093,7 @@ struct obd_ops {
 
 struct md_ops {
         int (*m_getstatus)(struct obd_export *, struct lu_fid *);
-        int (*m_change_cbdata)(struct obd_export *, struct lu_fid *,
+        int (*m_change_cbdata)(struct obd_export *, const struct lu_fid *,
                                ldlm_iterator_t, void *);
         int (*m_close)(struct obd_export *, struct md_op_data *,
                        struct obd_client_handle *, struct ptlrpc_request **);
@@ -1105,9 +1105,9 @@ struct md_ops {
                          int, struct md_op_data *, struct lustre_handle *,
                          void *, int, ldlm_completion_callback,
                          ldlm_blocking_callback, void *, int);
-        int (*m_getattr)(struct obd_export *, struct lu_fid *,
+        int (*m_getattr)(struct obd_export *, const struct lu_fid *,
                          obd_valid, int, struct ptlrpc_request **);
-        int (*m_getattr_name)(struct obd_export *, struct lu_fid *,
+        int (*m_getattr_name)(struct obd_export *, const struct lu_fid *,
                               const char *, int, obd_valid,
                               int, struct ptlrpc_request **);
         int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
@@ -1122,18 +1122,18 @@ struct md_ops {
         int (*m_setattr)(struct obd_export *, struct md_op_data *,
                          struct iattr *, void *, int , void *, int,
                          struct ptlrpc_request **);
-        int (*m_sync)(struct obd_export *, struct lu_fid *,
+        int (*m_sync)(struct obd_export *, const struct lu_fid *,
                       struct ptlrpc_request **);
-        int (*m_readpage)(struct obd_export *, struct lu_fid *,
+        int (*m_readpage)(struct obd_export *, const struct lu_fid *,
                           __u64, struct page *, struct ptlrpc_request **);
         int (*m_unlink)(struct obd_export *, struct md_op_data *,
                         struct ptlrpc_request **);
 
-        int (*m_setxattr)(struct obd_export *, struct lu_fid *,
+        int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
                           obd_valid, const char *, const char *,
                           int, int, int, struct ptlrpc_request **);
 
-        int (*m_getxattr)(struct obd_export *, struct lu_fid *,
+        int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
                           obd_valid, const char *, const char *,
                           int, int, int, struct ptlrpc_request **);
 
@@ -1151,11 +1151,11 @@ struct md_ops {
                                         struct obd_client_handle *);
         int (*m_set_lock_data)(struct obd_export *, __u64 *, void *);
 
-        int (*m_lock_match)(struct obd_export *, int, struct lu_fid *,
+        int (*m_lock_match)(struct obd_export *, int, const struct lu_fid *,
                             ldlm_type_t, ldlm_policy_data_t *, ldlm_mode_t,
                             struct lustre_handle *);
 
-        int (*m_cancel_unused)(struct obd_export *, struct lu_fid *,
+        int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
                                int flags, void *opaque);
 
         /*
index 2f2bddc..7e36cbb 100644 (file)
@@ -819,7 +819,7 @@ static inline int obd_fid_alloc(struct obd_export *exp,
 }
 
 static inline int obd_fid_delete(struct obd_export *exp,
-                                 struct lu_fid *fid)
+                                 const struct lu_fid *fid)
 {
         int rc;
         ENTRY;
@@ -1402,7 +1402,7 @@ static inline int obd_san_preprw(int cmd, struct obd_export *exp,
         return(rc);
 }
 
-static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
+static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
                           struct obd_client_handle *handle, int flag)
 {
         int rc;
@@ -1557,7 +1557,8 @@ static inline int obd_register_observer(struct obd_device *obd,
 }
 
 /* metadata helpers */
-static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
+static inline int md_getstatus(struct obd_export *exp,
+                               struct lu_fid *fid)
 {
         int rc;
         ENTRY;
@@ -1568,7 +1569,8 @@ static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
         RETURN(rc);
 }
 
-static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_getattr(struct obd_export *exp,
+                             const struct lu_fid *fid,
                              obd_valid valid, int ea_size,
                              struct ptlrpc_request **request)
 {
@@ -1581,7 +1583,8 @@ static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
         RETURN(rc);
 }
 
-static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_change_cbdata(struct obd_export *exp,
+                                   const struct lu_fid *fid,
                                    ldlm_iterator_t it, void *data)
 {
         int rc;
@@ -1650,7 +1653,8 @@ static inline int md_enqueue(struct obd_export *exp, int lock_type,
         RETURN(rc);
 }
 
-static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_getattr_name(struct obd_export *exp,
+                                  const struct lu_fid *fid,
                                   const char *filename, int namelen,
                                   obd_valid valid, int ea_size,
                                   struct ptlrpc_request **request)
@@ -1722,7 +1726,8 @@ static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
         RETURN(rc);
 }
 
-static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_sync(struct obd_export *exp,
+                          const struct lu_fid *fid,
                           struct ptlrpc_request **request)
 {
         int rc;
@@ -1733,7 +1738,8 @@ static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
         RETURN(rc);
 }
 
-static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_readpage(struct obd_export *exp,
+                              const struct lu_fid *fid,
                               __u64 offset, struct page *page,
                               struct ptlrpc_request **request)
 {
@@ -1777,7 +1783,8 @@ static inline int md_free_lustre_md(struct obd_export *exp,
         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
 }
 
-static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_setxattr(struct obd_export *exp,
+                              const struct lu_fid *fid,
                               obd_valid valid, const char *name,
                               const char *input, int input_size,
                               int output_size, int flags,
@@ -1791,7 +1798,8 @@ static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
                                            request));
 }
 
-static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
+static inline int md_getxattr(struct obd_export *exp,
+                              const struct lu_fid *fid,
                               obd_valid valid, const char *name,
                               const char *input, int input_size,
                               int output_size, int flags,
@@ -1834,7 +1842,7 @@ static inline int md_set_lock_data(struct obd_export *exp,
 }
 
 static inline int md_cancel_unused(struct obd_export *exp,
-                                   struct lu_fid *fid,
+                                   const struct lu_fid *fid,
                                    int flags, void *opaque)
 {
         int rc;
@@ -1848,7 +1856,7 @@ static inline int md_cancel_unused(struct obd_export *exp,
 }
 
 static inline int md_lock_match(struct obd_export *exp, int flags,
-                                struct lu_fid *fid, ldlm_type_t type,
+                                const struct lu_fid *fid, ldlm_type_t type,
                                 ldlm_policy_data_t *policy, ldlm_mode_t mode,
                                 struct lustre_handle *lockh)
 {
index 80ab9d8..0cc0e6d 100644 (file)
@@ -51,7 +51,7 @@ static int ll_nfs_test_inode(struct inode *inode, void *opaque)
         struct lu_fid *ifid = &ll_i2info(inode)->lli_fid;
         struct lu_fid *lfid = opaque;
 
-        if (memcmp(ifid, lfid, sizeof(struct lu_fid)) == 0)
+        if (lu_fid_eq(ifid, lfid))
                 return 1;
 
         return 0;
@@ -175,10 +175,12 @@ static void ll_fh_to_fid(struct lu_fid *fid, __u32 *mode, __u32 *datap)
 
 static void ll_fid_to_fh(struct lu_fid *fid, __u32 *mode, __u32 *datap)
 {
+        __u64 *seq = (__u64 *)datap;
+        
         /* packing ->f_seq */
-        *datap++ = (__u32)(fid_seq(fid) >> 32);
-        *datap++ = (__u32)(fid_seq(fid) & 0x00000000ffffffff);
-
+        *seq = fid_seq(fid);
+        datap += 2;
+        
         /* packing ->f_num */
         *datap++ = fid_ver(fid);
         *datap++ = fid_oid(fid);
index 29ec8d6..d30c0ec 100644 (file)
 #include <lprocfs_status.h>
 #include "lmv_internal.h"
 
-int lmv_fld_lookup(struct obd_device *obd, const struct lu_fid *fid)
+int lmv_fld_lookup(struct obd_device *obd,
+                   const struct lu_fid *fid,
+                   mdsno_t *mds)
 {
         struct lmv_obd *lmv = &obd->u.lmv;
-        mdsno_t mds;
         int rc;
         ENTRY;
 
         LASSERT(fid_is_sane(fid));
-        rc = fld_client_lookup(&lmv->lmv_fld, fid_seq(fid), &mds);
+        rc = fld_client_lookup(&lmv->lmv_fld, fid_seq(fid), mds);
         if (rc) {
-                CERROR("can't find mds by seq "LPU64", rc %d\n",
-                       fid_seq(fid), rc);
+                CERROR("error while looking for mds number. Seq "LPU64
+                       ", rc %d\n", fid_seq(fid), rc);
                 RETURN(rc);
         }
-        CDEBUG(D_INFO, "LMV: got MDS "LPU64" for sequence: "LPU64"\n",
-               mds, fid_seq(fid));
-        if (mds >= lmv->desc.ld_tgt_count) {
-                CERROR("Got invalid mdsno: "LPU64" (max: %d)\n",
-                       mds, lmv->desc.ld_tgt_count);
-                mds = (__u64)-EINVAL;
+        
+        CDEBUG(D_INFO, "got mds "LPU64" for sequence: "LPU64"\n",
+               *mds, fid_seq(fid));
+
+        if (*mds >= lmv->desc.ld_tgt_count) {
+                CERROR("got invalid mds: "LPU64" (max: %d)\n",
+                       *mds, lmv->desc.ld_tgt_count);
+                rc = -EINVAL;
         }
-        RETURN((int)mds);
+        RETURN(rc);
 }
index ce0e3a8..ceffb09 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
@@ -65,7 +65,8 @@ int lmv_intent_remote(struct obd_export *exp, void *lmm,
         struct lustre_handle plock;
         struct md_op_data *op_data;
         struct lu_fid nid;
-        int pmode, i, rc = 0;
+        int pmode, rc = 0;
+        mdsno_t mds;
         ENTRY;
 
         body = lustre_msg_buf((*reqp)->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
@@ -105,10 +106,10 @@ int lmv_intent_remote(struct obd_export *exp, void *lmm,
                 GOTO(out, rc = -ENOMEM);
         
         op_data->fid1 = nid;
-        i = lmv_fld_lookup(obd, &nid);
-        if (i < 0)
-                RETURN(i);
-        rc = md_intent_lock(lmv->tgts[i].ltd_exp, op_data,
+        rc = lmv_fld_lookup(obd, &nid, &mds);
+        if (rc)
+                RETURN(rc);
+        rc = md_intent_lock(lmv->tgts[mds].ltd_exp, op_data,
                             lmm, lmmsize, it, flags, &req,
                             cb_blocking, extra_lock_flags);
 
@@ -135,9 +136,9 @@ out:
         return rc;
 }
 
-int lmv_intent_open(struct obd_export *exp, struct lu_fid *pid,
+int lmv_intent_open(struct obd_export *exp, const struct lu_fid *pid,
                     const char *name, int len, void *lmm, int lmmsize,
-                    struct lu_fid *cid, struct lookup_intent *it,
+                    const struct lu_fid *cid, struct lookup_intent *it,
                     int flags, struct ptlrpc_request **reqp,
                     ldlm_blocking_callback cb_blocking,
                     int extra_lock_flags)
@@ -148,30 +149,33 @@ int lmv_intent_open(struct obd_export *exp, struct lu_fid *pid,
         struct md_op_data *op_data;
         struct lmv_stripe_md *mea;
         struct lu_fid rpid = *pid;
-        int rc, mds, loop = 0;
         struct lmv_obj *obj;
+        int rc, loop = 0;
+        mdsno_t mds;
         ENTRY;
 
         OBD_ALLOC_PTR(op_data);
         if (op_data == NULL)
                 RETURN(-ENOMEM);
         
-        /* IT_OPEN is intended to open (and create, possible) an object. Parent
-         * (pid) may be splitted dir */
+        /*
+         * IT_OPEN is intended to open (and create, possible) an object. Parent
+         * (pid) may be split dir.
+         */
 
 repeat:
         LASSERT(++loop <= 2);
-        mds = lmv_fld_lookup(obd, &rpid);
-        if (mds < 0)
-                GOTO(out_free_op_data, rc = mds);
+        rc = lmv_fld_lookup(obd, &rpid, &mds);
+        if (rc)
+                GOTO(out_free_op_data, rc);
         obj = lmv_obj_grab(obd, &rpid);
         if (obj) {
-                /* directory is already splitted, so we have to forward
-                 * request to the right MDS */
+                /* directory is already split, so we have to forward request to
+                 * the right MDS. */
                 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                    (char *)name, len);
 
-                CDEBUG(D_OTHER, "forward to MDS #%u ("DFID")\n",
+                CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n",
                        mds, PFID(&rpid));
                 rpid = obj->lo_inodes[mds].li_fid;
                 lmv_obj_put(obj);
@@ -184,12 +188,11 @@ repeat:
         op_data->name = name;
         op_data->namelen = len;
 
-        //mds = lmv_fld_lookup(obd, &rpid);
         rc = md_intent_lock(lmv->tgts[mds].ltd_exp, op_data,
                             lmm, lmmsize, it, flags, reqp,
                             cb_blocking, extra_lock_flags);
         if (rc == -ERESTART) {
-                /* directory got splitted. time to update local object and
+                /* directory got split. time to update local object and
                  * repeat the request with proper MDS */
                 LASSERT(lu_fid_eq(pid, &rpid));
                 rc = lmv_handle_split(exp, &rpid);
@@ -231,7 +234,7 @@ repeat:
                 GOTO(out_free_op_data, rc = 0);
 
         /* caller may use attrs MDS returns on IT_OPEN lock request so, we have
-         * to update them for splitted dir */
+         * to update them for split dir */
         body = lustre_msg_buf((*reqp)->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
         LASSERT(body != NULL);
 
@@ -242,14 +245,14 @@ repeat:
         cid = &body->fid1;
         obj = lmv_obj_grab(obd, cid);
         if (!obj && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
-                /* wow! this is splitted dir, we'd like to handle it */
+                /* wow! this is split dir, we'd like to handle it */
                 obj = lmv_obj_create(exp, &body->fid1, mea);
                 if (IS_ERR(obj))
                         GOTO(out_free_op_data, rc = (int)PTR_ERR(obj));
         }
 
         if (obj) {
-                /* this is splitted dir and we'd want to get attrs */
+                /* this is split dir and we'd want to get attrs */
                 CDEBUG(D_OTHER, "attrs from slaves for "DFID"\n",
                        PFID(cid));
 
@@ -269,9 +272,9 @@ out_free_op_data:
         return rc;
 }
 
-int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
+int lmv_intent_getattr(struct obd_export *exp, const struct lu_fid *pid,
                        const char *name, int len, void *lmm, int lmmsize,
-                       struct lu_fid *cid, struct lookup_intent *it,
+                       const struct lu_fid *cid, struct lookup_intent *it,
                        int flags, struct ptlrpc_request **reqp,
                        ldlm_blocking_callback cb_blocking,
                        int extra_lock_flags)
@@ -283,7 +286,8 @@ int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
         struct md_op_data *op_data;
         struct lu_fid rpid = *pid;
         struct lmv_stripe_md *mea;
-        int rc = 0, mds;
+        mdsno_t mds;
+        int rc = 0;
         ENTRY;
 
         OBD_ALLOC_PTR(op_data);
@@ -292,21 +296,21 @@ int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
         
         if (cid) {
                 /* caller wants to revalidate attrs of obj we have to revalidate
-                 * slaves if requested object is splitted directory */
+                 * slaves if requested object is split directory */
                 CDEBUG(D_OTHER, "revalidate attrs for "DFID"\n", PFID(cid));
-                mds = lmv_fld_lookup(obd, cid);
-                if (mds < 0)
-                        GOTO(out_free_op_data, rc = mds);
+                rc = lmv_fld_lookup(obd, cid, &mds);
+                if (rc)
+                        GOTO(out_free_op_data, rc);
 #if 0
                 obj = lmv_obj_grab(obd, cid);
                 if (obj) {
-                        /* in fact, we need not this with current intent_lock(),
-                         * but it may change some day */
+                        /* in fact, we do not need this with current
+                         * intent_lock(), but it may change some day */
                         if (!lu_fid_eq(pid, cid)){
                                 rpid = obj->lo_inodes[mds].li_fid;
-                                mds = lmv_fld_lookup(obd, &rpid);
-                                if (mds < 0)
-                                        GOTO(out_free_op_data, rc = mds);
+                                rc = lmv_fld_lookup(obd, &rpid, &mds);
+                                if (rc)
+                                        GOTO(out_free_op_data, rc);
                         }
                         lmv_obj_put(obj);
                 }
@@ -315,19 +319,21 @@ int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
         } else {
                 CDEBUG(D_OTHER, "INTENT getattr for %*s on "DFID"\n",
                        len, name, PFID(pid));
-                mds = lmv_fld_lookup(obd, pid);
-                if (mds < 0)
-                        GOTO(out_free_op_data, rc = mds);
+                rc = lmv_fld_lookup(obd, pid, &mds);
+                if (rc)
+                        GOTO(out_free_op_data, rc);
                 obj = lmv_obj_grab(obd, pid);
                 if (obj && len) {
-                        /* directory is already splitted. calculate mds */
+                        /* directory is already split. calculate mds */
                         mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                            (char *)name, len);
                         rpid = obj->lo_inodes[mds].li_fid;
-                        mds = lmv_fld_lookup(obd, &rpid);
+                        rc = lmv_fld_lookup(obd, &rpid, &mds);
+                        if (rc)
+                                GOTO(out_free_op_data, rc);
                         lmv_obj_put(obj);
 
-                        CDEBUG(D_OTHER, "forward to MDS #%u (slave "DFID")\n",
+                        CDEBUG(D_OTHER, "forward to MDS #"LPU64" (slave "DFID")\n",
                                mds, PFID(&rpid));
                 }
         }
@@ -345,7 +351,7 @@ int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
 
         if (obj && rc > 0) {
                 /*
-                 * this is splitted dir. In order to optimize things a bit, we
+                 * this is split dir. In order to optimize things a bit, we
                  * consider obj valid updating missing parts.
 
                  * FIXME: do we need to return any lock here? It would be fine
@@ -392,7 +398,7 @@ int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
         obj2 = lmv_obj_grab(obd, cid);
 
         if (!obj2 && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
-                /* wow! this is splitted dir, we'd like to handle it. */
+                /* wow! this is split dir, we'd like to handle it. */
                 body = lustre_msg_buf((*reqp)->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
                 LASSERT(body != NULL);
 
@@ -402,7 +408,7 @@ int lmv_intent_getattr(struct obd_export *exp, struct lu_fid *pid,
         }
 
         if (obj2) {
-                /* this is splitted dir and we'd want to get attrs */
+                /* this is split dir and we'd want to get attrs */
                 CDEBUG(D_OTHER, "attrs from slaves for "DFID", rc %d\n",
                        PFID(cid), rc);
 
@@ -470,7 +476,7 @@ int lmv_lookup_slaves(struct obd_export *exp, struct ptlrpc_request **reqp)
                 struct lu_fid fid = obj->lo_inodes[i].li_fid;
                 struct ptlrpc_request *req = NULL;
                 struct lookup_intent it;
-                int mds;
+                mdsno_t mds;
 
                 if (lu_fid_eq(&fid, &obj->lo_fid))
                         /* skip master obj */
@@ -486,9 +492,9 @@ int lmv_lookup_slaves(struct obd_export *exp, struct ptlrpc_request **reqp)
                 op_data->fid1 = fid;
                 op_data->fid2 = fid;
 
-                mds = lmv_fld_lookup(obd, &fid);
-                if (mds < 0)
-                        GOTO(cleanup, rc = mds);
+                rc = lmv_fld_lookup(obd, &fid, &mds);
+                if (rc)
+                        GOTO(cleanup, rc);
                 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, op_data,
                                     NULL, 0, &it, 0, &req,
                                     lmv_blocking_ast, 0);
@@ -537,9 +543,9 @@ cleanup:
         return rc;
 }
 
-int lmv_intent_lookup(struct obd_export *exp, struct lu_fid *pid,
+int lmv_intent_lookup(struct obd_export *exp, const struct lu_fid *pid,
                       const char *name, int len, void *lmm, int lmmsize,
-                      struct lu_fid *cid, struct lookup_intent *it,
+                      const struct lu_fid *cid, struct lookup_intent *it,
                       int flags, struct ptlrpc_request **reqp,
                       ldlm_blocking_callback cb_blocking,
                       int extra_lock_flags)
@@ -550,8 +556,9 @@ int lmv_intent_lookup(struct obd_export *exp, struct lu_fid *pid,
         struct lu_fid rpid = *pid;
         struct md_op_data *op_data;
         struct lmv_stripe_md *mea;
-        int rc, mds, loop = 0;
         struct lmv_obj *obj;
+        int rc, loop = 0;
+        mdsno_t mds;
         ENTRY;
 
         OBD_ALLOC_PTR(op_data);
@@ -577,18 +584,18 @@ int lmv_intent_lookup(struct obd_export *exp, struct lu_fid *pid,
                         rpid = obj->lo_inodes[mds].li_fid;
                         lmv_obj_put(obj);
                 }
-                mds = lmv_fld_lookup(obd, &rpid);
-                if (mds < 0)
-                        GOTO(out_free_op_data, rc = mds);
+                rc = lmv_fld_lookup(obd, &rpid, &mds);
+                if (rc)
+                        GOTO(out_free_op_data, rc);
 
-                CDEBUG(D_OTHER, "revalidate lookup for "DFID" to %d MDS\n",
+                CDEBUG(D_OTHER, "revalidate lookup for "DFID" to #"LPU64" MDS\n",
                        PFID(cid), mds);
 
                 op_data->fid2 = *cid;
         } else {
-                mds = lmv_fld_lookup(obd, pid);
-                if (mds < 0)
-                        GOTO(out_free_op_data, rc = mds);
+                rc = lmv_fld_lookup(obd, pid, &mds);
+                if (rc)
+                        GOTO(out_free_op_data, rc);
 repeat:
                 LASSERT(++loop <= 2);
 
@@ -600,13 +607,13 @@ repeat:
                 obj = lmv_obj_grab(obd, pid);
                 if (obj) {
                         if (len) {
-                                /* directory is already splitted. calculate mds */
+                                /* directory is already split. calculate mds */
                                 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                                    (char *)name, len);
                                 rpid = obj->lo_inodes[mds].li_fid;
-                                mds = lmv_fld_lookup(obd, &rpid);
-                                if (mds < 0)
-                                        GOTO(out_free_op_data, rc = mds);
+                                rc = lmv_fld_lookup(obd, &rpid, &mds);
+                                if (rc)
+                                        GOTO(out_free_op_data, rc);
                         }
                         lmv_obj_put(obj);
                 }
@@ -642,7 +649,7 @@ repeat:
         }
 
         if (rc == -ERESTART) {
-                /* directory got splitted since last update. this shouldn't be
+                /* directory got split since last update. this shouldn't be
                  * becasue splitting causes lock revocation, so revalidate had
                  * to fail and lookup on dir had to return mea */
                 CWARN("we haven't knew about directory splitting!\n");
@@ -665,7 +672,7 @@ repeat:
                                cb_blocking, extra_lock_flags);
 
         if (rc == 0 && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
-                /* wow! this is splitted dir, we'd like to handle it */
+                /* wow! this is split dir, we'd like to handle it */
                 body = lustre_msg_buf((*reqp)->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
                 LASSERT(body != NULL);
                 LASSERT((body->valid & OBD_MD_FLID) != 0);
@@ -695,7 +702,8 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
         const char *name = op_data->name;
         int len = op_data->namelen;
         struct lu_fid *pid, *cid;
-        int rc, i = 0;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         LASSERT(it);
@@ -703,11 +711,11 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
         pid = fid_is_sane(&op_data->fid1) ? &op_data->fid1 : NULL;
         cid = fid_is_sane(&op_data->fid2) ? &op_data->fid2 : NULL;
 
-        i = lmv_fld_lookup(obd, pid);
-        if (i < 0)
-                RETURN(i);
-        CDEBUG(D_OTHER, "INTENT LOCK '%s' for '%*s' on "DFID" -> %d\n",
-               LL_IT2STR(it), len, name, PFID(pid), i);
+        rc = lmv_fld_lookup(obd, pid, &mds);
+        if (rc)
+                RETURN(rc);
+        CDEBUG(D_OTHER, "INTENT LOCK '%s' for '%*s' on "DFID" -> #"LPU64"\n",
+               LL_IT2STR(it), len, name, PFID(pid), mds);
 
         rc = lmv_check_connect(obd);
         if (rc)
@@ -731,7 +739,7 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
 }
 
 int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
-                          struct lu_fid *mid, struct lookup_intent *oit,
+                          const struct lu_fid *mid, struct lookup_intent *oit,
                           int master_valid, ldlm_blocking_callback cb_blocking,
                           int extra_lock_flags)
 {
@@ -745,7 +753,8 @@ int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
         struct mdt_body *body;
         struct lmv_obj *obj;
         int master_lock_mode;
-        int i, mds, rc = 0;
+        int i, rc = 0;
+        mdsno_t mds;
         ENTRY;
 
         OBD_ALLOC_PTR(op_data);
@@ -807,9 +816,9 @@ int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
                 op_data->fid2 = fid;
 
                 /* is obj valid? */
-                mds = lmv_fld_lookup(obd, &fid);
-                if (mds < 0)
-                        GOTO(out_free_op_data, rc = mds);
+                rc = lmv_fld_lookup(obd, &fid, &mds);
+                if (rc)
+                        GOTO(out_free_op_data, rc);
                 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, op_data,
                                     NULL, 0, &it, 0, &req, cb, extra_lock_flags);
                 lockh = (struct lustre_handle *) &it.d.lustre.it_lock_handle;
@@ -876,7 +885,6 @@ release_lock:
                                       DLM_REPLY_REC_OFF, sizeof(*body));
                 LASSERT(body);
 
-                /* FIXME: what about other attributes? */
                 body->size = size;
 
                 if (mreq == NULL) {
@@ -886,7 +894,12 @@ release_lock:
                          * no reply and the only attr we can return is size.
                          */
                         body->valid = OBD_MD_FLSIZE;
-//                        body->mds = lmv_fld_lookup(obd, &obj->lo_fid);
+                        
+#if 0
+                        rc = lmv_fld_lookup(obd, &obj->lo_fid, &body->mds);
+                        if (rc)
+                                GOTO(cleanup, rc);
+#endif
                 }
                 if (master_valid == 0) {
                         memcpy(&oit->d.lustre.it_lock_handle,
index b5b850e..992db96 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002, 2003, 2004 Cluster File Systems, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
@@ -41,10 +41,6 @@ struct qstr {
 #define LL_IT2STR(it)                                  \
        ((it) ? ldlm_it2str((it)->it_op) : "0")
 
-#define MEA_SIZE_LMV(lmv)                              \
-        ((lmv)->desc.ld_tgt_count *                    \
-        sizeof(struct lu_fid) + sizeof(struct lmv_stripe_md))
-        
 struct lmv_inode {
         struct lu_fid      li_fid;        /* id of dirobj */
         unsigned long      li_size;       /* slave size value */
@@ -92,17 +88,18 @@ void lmv_obj_free(struct lmv_obj *obj);
 struct lmv_obj *lmv_obj_get(struct lmv_obj *obj);
 
 struct lmv_obj *lmv_obj_grab(struct obd_device *obd,
-                            struct lu_fid *fid);
+                            const struct lu_fid *fid);
 
 struct lmv_obj *lmv_obj_alloc(struct obd_device *obd,
-                             struct lu_fid *fid,
+                             const struct lu_fid *fid,
                              struct lmv_stripe_md *mea);
 
 struct lmv_obj *lmv_obj_create(struct obd_export *exp,
-                              struct lu_fid *fid,
+                              const struct lu_fid *fid,
                               struct lmv_stripe_md *mea);
 
-int lmv_obj_delete(struct obd_export *exp, struct lu_fid *fid);
+int lmv_obj_delete(struct obd_export *exp,
+                   const struct lu_fid *fid);
 
 int lmv_check_connect(struct obd_device *obd);
 
@@ -112,31 +109,32 @@ int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
                     ldlm_blocking_callback cb_blocking,
                     int extra_lock_flags);
 
-int lmv_intent_lookup(struct obd_export *, struct lu_fid *, 
+int lmv_intent_lookup(struct obd_export *, const struct lu_fid *, 
                      const char *, int, void *, int,
-                     struct lu_fid *, struct lookup_intent *, int,
+                     const struct lu_fid *, struct lookup_intent *, int,
                      struct ptlrpc_request **, ldlm_blocking_callback,
                       int extra_lock_flags);
 
-int lmv_intent_getattr(struct obd_export *, struct lu_fid *, const char *,
-                       int, void *, int, struct lu_fid *, struct lookup_intent *,
+int lmv_intent_getattr(struct obd_export *, const struct lu_fid *, const char *,
+                       int, void *, int, const struct lu_fid *, struct lookup_intent *,
                        int, struct ptlrpc_request **, ldlm_blocking_callback,
                        int extra_lock_flags);
 
-int lmv_intent_open(struct obd_export *, struct lu_fid *, const char *, 
-                   int, void *, int, struct lu_fid *, struct lookup_intent *, 
+int lmv_intent_open(struct obd_export *, const struct lu_fid *, const char *, 
+                   int, void *, int, const struct lu_fid *, struct lookup_intent *, 
                    int, struct ptlrpc_request **, ldlm_blocking_callback,
                     int extra_lock_flags);
 
 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
-                          struct lu_fid *, struct lookup_intent *, int,
+                          const struct lu_fid *, struct lookup_intent *, int,
                          ldlm_blocking_callback cb_blocking,
                           int extra_lock_flags);
 
-int lmv_handle_split(struct obd_export *, struct lu_fid *);
+int lmv_handle_split(struct obd_export *, const struct lu_fid *);
 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
                     void *, int);
-int lmv_fld_lookup(struct obd_device *obd, const struct lu_fid *fid);
+int lmv_fld_lookup(struct obd_device *obd, const struct lu_fid *fid,
+                   mdsno_t *mds);
 
 static inline struct lmv_stripe_md * 
 lmv_get_mea(struct ptlrpc_request *req, int offset)
@@ -161,6 +159,13 @@ lmv_get_mea(struct ptlrpc_request *req, int offset)
        return mea;
 }
 
+static inline int lmv_get_easize(struct lmv_obd *lmv)
+{
+        return sizeof(struct lmv_stripe_md) +
+                lmv->desc.ld_tgt_count *
+                sizeof(struct lu_fid);
+}
+
 /* lproc_lmv.c */
 extern struct file_operations lmv_proc_target_fops;
 
index 637c4a6..b32251d 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
@@ -193,9 +193,8 @@ static int lmv_connect(const struct lu_context *ctx,
         lmv->connected = 0;
         lmv->cluuid = *cluuid;
 
-        /* saving */
         if (data)
-                memcpy(&lmv->conn_data, data, sizeof(*data));
+                lmv->conn_data = *data;
 
 #ifdef __KERNEL__
         lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
@@ -496,8 +495,7 @@ int lmv_check_connect(struct obd_device *obd)
         lmv_set_timeouts(obd);
         class_export_put(lmv->exp);
         lmv->connected = 1;
-        easize = lmv->desc.ld_tgt_count * sizeof(struct lu_fid) +
-                 sizeof(struct lmv_stripe_md);
+        easize = lmv_get_easize(lmv);
         lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
         lmv_init_unlock(lmv);
         RETURN(0);
@@ -643,10 +641,10 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
         RETURN(rc);
 }
 
+/* assume all is balanced for now */
 static int lmv_fids_balanced(struct obd_device *obd)
 {
         ENTRY;
-        /* assume all is balansed for now */
         RETURN(1);
 }
 
@@ -661,41 +659,45 @@ static int lmv_all_chars_policy(int count, struct qstr *name)
         return c;
 }
 
-/* returns number of target where new fid should be allocated using passed @hint
- * as input data for making decision. */
 static int lmv_placement_policy(struct obd_device *obd,
-                                struct lu_placement_hint *hint)
+                                struct lu_placement_hint *hint,
+                                mdsno_t *mds)
 {
         struct lmv_obd *lmv = &obd->u.lmv;
-        int tgt;
+        int rc;
         ENTRY;
 
+        LASSERT(mds != NULL);
+
         /* here are some policies to allocate new fid */
         if (lmv_fids_balanced(obd)) {
                 /* allocate new fid basing on its name in the case fids are
                  * balanced, that is all sequences have more or less equal
                  * number of objects created. */
-                if (hint->ph_cname && (hint->ph_opc == LUSTRE_OPC_MKDIR))
-                        tgt = lmv_all_chars_policy(lmv->desc.ld_tgt_count,
-                                                   hint->ph_cname);
-                else {
+                if (hint->ph_cname && (hint->ph_opc == LUSTRE_OPC_MKDIR)) {
+                        *mds = lmv_all_chars_policy(lmv->desc.ld_tgt_count,
+                                                    hint->ph_cname);
+                        rc = 0;
+                } else {
                         /* default policy is to use parent MDS */
                         LASSERT(fid_is_sane(hint->ph_pfid));
-                        tgt = lmv_fld_lookup(obd, hint->ph_pfid);
+                        rc = lmv_fld_lookup(obd, hint->ph_pfid, mds);
                 }
         } else {
                 /* sequences among all tgts are not well balanced, allocate new
-                 * fid taking this into account to balance them. */
-                tgt = -EINVAL;
+                 * fid taking this into account to balance them. Not implemented
+                 * yet! */
+                *mds = 0;
+                rc = -EINVAL;
         }
 
-        /* if cannot get proper MDS, use master one */
-        if (tgt < 0) {
-                CERROR("Cannot choose MDS, err = %i\n", tgt);
-                tgt = 0;
+        if (rc) {
+                CERROR("cannot choose MDS, err = %d\n", rc);
+        } else {
+                LASSERT(*mds < lmv->desc.ld_tgt_count);
         }
 
-        RETURN(tgt);
+        RETURN(rc);
 }
 
 static int lmv_fid_init(struct obd_export *exp)
@@ -739,16 +741,18 @@ static int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
 {
         struct obd_device *obd = class_exp2obd(exp);
         struct lmv_obd *lmv = &obd->u.lmv;
-        int rc = 0, mds;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         LASSERT(fid != NULL);
         LASSERT(hint != NULL);
 
-        mds = lmv_placement_policy(obd, hint);
-        if (mds < 0 || mds >= lmv->desc.ld_tgt_count) {
-                CERROR("can't get target for allocating fid\n");
-                RETURN(-EINVAL);
+        rc = lmv_placement_policy(obd, hint, &mds);
+        if (rc) {
+                CERROR("can't get target for allocating fid, "
+                       "rc %d\n", rc);
+                RETURN(rc);
         }
 
         /* asking underlaying tgt layer to allocate new fid */
@@ -758,19 +762,18 @@ static int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
         if (rc > 0) {
                 LASSERT(fid_is_sane(fid));
                 
-                rc = fld_client_create(&lmv->lmv_fld,
-                                       fid_seq(fid),
+                rc = fld_client_create(&lmv->lmv_fld, fid_seq(fid),
                                        mds);
                 if (rc) {
-                        CERROR("can't create fld entry, "
-                               "rc %d\n", rc);
+                        CERROR("can't create fld entry, rc %d\n", rc);
+                        RETURN(rc);
                 }
         }
 
         RETURN(rc);
 }
 
-static int lmv_fid_delete(struct obd_export *exp, struct lu_fid *fid)
+static int lmv_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
 {
         ENTRY;
 
@@ -872,9 +875,9 @@ static int lmv_cleanup(struct obd_device *obd)
         struct lmv_obd *lmv = &obd->u.lmv;
         ENTRY;
 
+        fld_client_fini(&lmv->lmv_fld);
         lprocfs_obd_cleanup(obd);
         lmv_mgr_cleanup(obd);
-        fld_client_fini(&lmv->lmv_fld);
         OBD_FREE(lmv->datas, lmv->datas_size);
         OBD_FREE(lmv->tgts, lmv->tgts_size);
 
@@ -933,7 +936,7 @@ static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
                         GOTO(out_free_temp, rc);
                 }
                 if (i == 0) {
-                        memcpy(osfs, temp, sizeof(*temp));
+                        *osfs = *temp;
                 } else {
                         osfs->os_bavail += temp->os_bavail;
                         osfs->os_blocks += temp->os_blocks;
@@ -948,7 +951,8 @@ out_free_temp:
         return rc;
 }
 
-static int lmv_getstatus(struct obd_export *exp, struct lu_fid *fid)
+static int lmv_getstatus(struct obd_export *exp,
+                         struct lu_fid *fid)
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
@@ -963,7 +967,9 @@ static int lmv_getstatus(struct obd_export *exp, struct lu_fid *fid)
 
         RETURN(rc);
 }
-static int lmv_getxattr(struct obd_export *exp, struct lu_fid *fid,
+
+static int lmv_getxattr(struct obd_export *exp,
+                        const struct lu_fid *fid,
                         obd_valid valid, const char *name,
                         const char *input, int input_size,
                         int output_size, int flags,
@@ -971,26 +977,26 @@ static int lmv_getxattr(struct obd_export *exp, struct lu_fid *fid,
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
-        int rc, i;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
         if (rc)
                 RETURN(rc);
 
-        i = lmv_fld_lookup(obd, fid);
-        if (i < 0)
-                RETURN(i);
-
-        LASSERT(i < lmv->desc.ld_tgt_count);
+        rc = lmv_fld_lookup(obd, fid, &mds);
+        if (rc)
+                RETURN(rc);
 
-        rc = md_getxattr(lmv->tgts[i].ltd_exp, fid, valid, name,
+        rc = md_getxattr(lmv->tgts[mds].ltd_exp, fid, valid, name,
                          input, input_size, output_size, flags, request);
 
         RETURN(rc);
 }
 
-static int lmv_setxattr(struct obd_export *exp, struct lu_fid *fid,
+static int lmv_setxattr(struct obd_export *exp,
+                        const struct lu_fid *fid,
                         obd_valid valid, const char *name,
                         const char *input, int input_size,
                         int output_size, int flags,
@@ -998,32 +1004,33 @@ static int lmv_setxattr(struct obd_export *exp, struct lu_fid *fid,
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
-        int rc, i;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
         if (rc)
                 RETURN(rc);
 
-        i = lmv_fld_lookup(obd, fid);
-        if (i < 0)
-                RETURN(i);
-
-        LASSERT(i < lmv->desc.ld_tgt_count);
+        rc = lmv_fld_lookup(obd, fid, &mds);
+        if (rc)
+                RETURN(rc);
 
-        rc = md_setxattr(lmv->tgts[i].ltd_exp, fid, valid, name,
+        rc = md_setxattr(lmv->tgts[mds].ltd_exp, fid, valid, name,
                          input, input_size, output_size, flags, request);
         
         RETURN(rc);
 }
 
-static int lmv_getattr(struct obd_export *exp, struct lu_fid *fid,
+static int lmv_getattr(struct obd_export *exp,
+                       const struct lu_fid *fid,
                        obd_valid valid, int ea_size,
                        struct ptlrpc_request **request)
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_obj *obj;
+        mdsno_t mds;
         int rc, i;
         ENTRY;
 
@@ -1031,13 +1038,11 @@ static int lmv_getattr(struct obd_export *exp, struct lu_fid *fid,
         if (rc)
                 RETURN(rc);
 
-        i = lmv_fld_lookup(obd, fid);
-        if (i < 0)
-                RETURN(i);
-
-        LASSERT(i < lmv->desc.ld_tgt_count);
+        rc = lmv_fld_lookup(obd, fid, &mds);
+        if (rc)
+                RETURN(rc);
 
-        rc = md_getattr(lmv->tgts[i].ltd_exp, fid, valid,
+        rc = md_getattr(lmv->tgts[mds].ltd_exp, fid, valid,
                         ea_size, request);
         if (rc)
                 RETURN(rc);
@@ -1045,11 +1050,11 @@ static int lmv_getattr(struct obd_export *exp, struct lu_fid *fid,
         obj = lmv_obj_grab(obd, fid);
 
         CDEBUG(D_OTHER, "GETATTR for "DFID" %s\n",
-               PFID(fid), obj ? "(splitted)" : "");
+               PFID(fid), obj ? "(split)" : "");
 
-        /* if object is splitted, then we loop over all the slaves and gather
-         * size attribute. In ideal world we would have to gather also mds field
-         * from all slaves, as object is spread over the cluster and this is
+        /* if object is split, then we loop over all the slaves and gather size
+         * attribute. In ideal world we would have to gather also mds field from
+         * all slaves, as object is spread over the cluster and this is
          * definitely interesting information and it is not good to loss it,
          * but... */
         if (obj) {
@@ -1067,7 +1072,6 @@ static int lmv_getattr(struct obd_export *exp, struct lu_fid *fid,
                 lmv_obj_lock(obj);
 
                 for (i = 0; i < obj->lo_objcount; i++) {
-
                         if (lmv->tgts[i].ltd_exp == NULL) {
                                 CWARN("%s: NULL export for %d\n",
                                       obd->obd_name, i);
@@ -1089,7 +1093,7 @@ static int lmv_getattr(struct obd_export *exp, struct lu_fid *fid,
 }
 
 static int lmv_change_cbdata(struct obd_export *exp,
-                             struct lu_fid *fid,
+                             const struct lu_fid *fid,
                              ldlm_iterator_t it,
                              void *data)
 {
@@ -1120,56 +1124,55 @@ static int lmv_close(struct obd_export *exp,
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
-        int rc, i;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
         if (rc)
                 RETURN(rc);
 
-        i = lmv_fld_lookup(obd, &op_data->fid1);
-        if (i < 0)
-                RETURN(i);
+        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+        if (rc)
+                RETURN(rc);
 
-        LASSERT(i < lmv->desc.ld_tgt_count);
         CDEBUG(D_OTHER, "CLOSE "DFID"\n", PFID(&op_data->fid1));
-        rc = md_close(lmv->tgts[i].ltd_exp, op_data, och, request);
+        rc = md_close(lmv->tgts[mds].ltd_exp, op_data, och, request);
         RETURN(rc);
 }
 
 /* called in the case MDS returns -ERESTART on create on open, what means that
- * directory is splitted and its LMV presentation object has to be updated. */
-int lmv_handle_split(struct obd_export *exp, struct lu_fid *fid)
+ * directory is split and its LMV presentation object has to be updated. */
+int lmv_handle_split(struct obd_export *exp, const struct lu_fid *fid)
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
         struct ptlrpc_request *req = NULL;
         struct lmv_obj *obj;
         struct lustre_md md;
-        int mealen, rc, i;
+        int mealen, rc;
+        mdsno_t mds;
         __u64 valid;
         ENTRY;
 
         md.mea = NULL;
-        mealen = MEA_SIZE_LMV(lmv);
+        mealen = lmv_get_easize(lmv);
 
         valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
 
-        i = lmv_fld_lookup(obd, fid);
-        if (i < 0)
-                RETURN(i);
-
-        LASSERT(i < lmv->desc.ld_tgt_count);
+        rc = lmv_fld_lookup(obd, fid, &mds);
+        if (rc)
+                RETURN(rc);
 
         /* time to update mea of parent fid */
-        rc = md_getattr(lmv->tgts[i].ltd_exp, fid, valid,
+        rc = md_getattr(lmv->tgts[mds].ltd_exp, fid, valid,
                         mealen, &req);
         if (rc) {
                 CERROR("md_getattr() failed, error %d\n", rc);
                 GOTO(cleanup, rc);
         }
 
-        rc = md_get_lustre_md(lmv->tgts[i].ltd_exp, req, 0,
+        rc = md_get_lustre_md(lmv->tgts[mds].ltd_exp, req, 0,
                               NULL, &md);
         if (rc) {
                 CERROR("mdc_get_lustre_md() failed, error %d\n", rc);
@@ -1203,7 +1206,8 @@ int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
         struct lmv_obd *lmv = &obd->u.lmv;
         struct mdt_body *body;
         struct lmv_obj *obj;
-        int rc, mds, loop = 0;
+        int rc, loop = 0;
+        mdsno_t mds;
         ENTRY;
 
         rc = lmv_check_connect(obd);
@@ -1225,9 +1229,9 @@ repeat:
         CDEBUG(D_OTHER, "CREATE '%*s' on "DFID"\n", op_data->namelen,
                op_data->name, PFID(&op_data->fid1));
 
-        mds = lmv_fld_lookup(obd, &op_data->fid1);
-        if (mds < 0)
-                RETURN(mds);
+        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+        if (rc)
+                RETURN(rc);
 
         rc = md_create(lmv->tgts[mds].ltd_exp, op_data, data, datalen,
                        mode, uid, gid, cap_effective, rdev, request);
@@ -1242,8 +1246,8 @@ repeat:
 
                 CDEBUG(D_OTHER, "created. "DFID"\n", PFID(&op_data->fid1));
         } else if (rc == -ERESTART) {
-                /* directory got splitted. time to update local object and
-                 * repeat the request with proper MDS. */
+                /* directory got split. time to update local object and repeat
+                 * the request with proper MDS. */
                 rc = lmv_handle_split(exp, &op_data->fid1);
                 if (rc == 0) {
                         ptlrpc_req_finished(*request);
@@ -1258,16 +1262,17 @@ static int lmv_done_writing(struct obd_export *exp,
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
-        int rc, mds;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
         if (rc)
                 RETURN(rc);
 
-        mds = lmv_fld_lookup(obd, &op_data->fid1);
-        if (mds < 0)
-                RETURN(mds);
+        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+        if (rc)
+                RETURN(rc);
         rc = md_done_writing(lmv->tgts[mds].ltd_exp, op_data);
         RETURN(rc);
 }
@@ -1283,7 +1288,8 @@ lmv_enqueue_slaves(struct obd_export *exp, int locktype,
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_stripe_md *mea = op_data->mea1;
         struct md_op_data *op_data2;
-        int i, rc = 0, mds;
+        int i, rc = 0;
+        mdsno_t mds;
         ENTRY;
 
         OBD_ALLOC_PTR(op_data2);
@@ -1294,9 +1300,9 @@ lmv_enqueue_slaves(struct obd_export *exp, int locktype,
         for (i = 0; i < mea->mea_count; i++) {
                 memset(op_data2, 0, sizeof(*op_data2));
                 op_data2->fid1 = mea->mea_ids[i];
-                mds = lmv_fld_lookup(obd, &op_data2->fid1);
-                if (mds < 0)
-                        GOTO(cleanup, rc = mds);
+                rc = lmv_fld_lookup(obd, &op_data2->fid1, &mds);
+                if (rc)
+                        GOTO(cleanup, rc);
 
                 if (lmv->tgts[mds].ltd_exp == NULL)
                         continue;
@@ -1348,7 +1354,8 @@ lmv_enqueue_remote(struct obd_export *exp, int lock_type,
         struct mdt_body *body = NULL;
         struct lustre_handle plock;
         struct md_op_data *rdata;
-        int i, rc = 0, pmode;
+        int rc = 0, pmode;
+        mdsno_t mds;
         ENTRY;
 
         body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
@@ -1377,10 +1384,10 @@ lmv_enqueue_remote(struct obd_export *exp, int lock_type,
         it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
         ptlrpc_req_finished(req);
 
-        i = lmv_fld_lookup(obd, &rdata->fid1);
-        if (i < 0)
-                GOTO(out_free_rdata, rc = i);
-        rc = md_enqueue(lmv->tgts[i].ltd_exp,
+        rc = lmv_fld_lookup(obd, &rdata->fid1, &mds);
+        if (rc)
+                GOTO(out_free_rdata, rc);
+        rc = md_enqueue(lmv->tgts[mds].ltd_exp,
                         lock_type, it, lock_mode, rdata, lockh, lmm,
                         lmmsize, cb_compl, cb_blocking, cb_data,
                         extra_lock_flags);
@@ -1403,7 +1410,8 @@ lmv_enqueue(struct obd_export *exp, int lock_type,
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_obj *obj;
-        int rc, mds;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
@@ -1420,7 +1428,7 @@ lmv_enqueue(struct obd_export *exp, int lock_type,
         if (op_data->namelen) {
                 obj = lmv_obj_grab(obd, &op_data->fid1);
                 if (obj) {
-                        /* directory is splitted. look for right mds for this
+                        /* directory is split. look for right mds for this
                          * name */
                         mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                            (char *)op_data->name, op_data->namelen);
@@ -1431,9 +1439,9 @@ lmv_enqueue(struct obd_export *exp, int lock_type,
         CDEBUG(D_OTHER, "ENQUEUE '%s' on "DFID"\n", LL_IT2STR(it),
                PFID(&op_data->fid1));
 
-        mds = lmv_fld_lookup(obd, &op_data->fid1);
-        if (mds < 0)
-                RETURN(mds);
+        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+        if (rc)
+                RETURN(rc);
         rc = md_enqueue(lmv->tgts[mds].ltd_exp,
                         lock_type, it, lock_mode, op_data, lockh, lmm,
                         lmmsize, cb_compl, cb_blocking, cb_data,
@@ -1447,30 +1455,31 @@ lmv_enqueue(struct obd_export *exp, int lock_type,
 }
 
 static int
-lmv_getattr_name(struct obd_export *exp, struct lu_fid *fid,
+lmv_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
                  const char *filename, int namelen, obd_valid valid,
                  int ea_size, struct ptlrpc_request **request)
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lu_fid rid = *fid;
-        int rc, mds, loop = 0;
+        int rc, loop = 0;
         struct mdt_body *body;
         struct lmv_obj *obj;
+        mdsno_t mds;
         ENTRY;
 
         rc = lmv_check_connect(obd);
        if (rc)
                RETURN(rc);
 
-        mds = lmv_fld_lookup(obd, fid);
-        if (mds < 0)
-                RETURN(mds);
+        rc = lmv_fld_lookup(obd, fid, &mds);
+        if (rc)
+                RETURN(rc);
 repeat:
         LASSERT(++loop <= 2);
         obj = lmv_obj_grab(obd, fid);
         if (obj) {
-                /* directory is splitted. look for right mds for this name */
+                /* directory is split. look for right mds for this name */
                 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                    filename, namelen - 1);
                 rid = obj->lo_inodes[mds].li_fid;
@@ -1480,9 +1489,9 @@ repeat:
         CDEBUG(D_OTHER, "getattr_lock for %*s on "DFID" -> "DFID"\n",
                namelen, filename, PFID(fid), PFID(&rid));
 
-        mds = lmv_fld_lookup(obd, &rid);
-        if (mds < 0)
-                RETURN(mds);
+        rc = lmv_fld_lookup(obd, &rid, &mds);
+        if (rc)
+                RETURN(rc);
 
         rc = md_getattr_name(lmv->tgts[mds].ltd_exp,
                              &rid, filename, namelen,
@@ -1497,18 +1506,20 @@ repeat:
                         rid = body->fid1;
                         CDEBUG(D_OTHER, "request attrs for "DFID"\n", PFID(&rid));
 
-                        /*
-                         * XXX check for error.
-                         */
-                        mds = lmv_fld_lookup(obd, &rid);
+                        rc = lmv_fld_lookup(obd, &rid, &mds);
+                        if (rc) {
+                                ptlrpc_req_finished(*request);
+                                RETURN(rc);
+                        }
+                        
                         rc = md_getattr_name(lmv->tgts[mds].ltd_exp,
                                              &rid, NULL, 1, valid, ea_size, &req);
                         ptlrpc_req_finished(*request);
                         *request = req;
                 }
         } else if (rc == -ERESTART) {
-                /* directory got splitted. time to update local object and
-                 * repeat the request with proper MDS */
+                /* directory got split. time to update local object and repeat
+                 * the request with proper MDS */
                 rc = lmv_handle_split(exp, &rid);
                 if (rc == 0) {
                         ptlrpc_req_finished(*request);
@@ -1528,7 +1539,8 @@ static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_obj *obj;
-        int rc, mds;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
@@ -1545,24 +1557,24 @@ static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
                         lmv_obj_put(obj);
                 }
 
-                mds = lmv_fld_lookup(obd, &op_data->fid2);
-                if (mds < 0)
-                        RETURN(mds);
+                rc = lmv_fld_lookup(obd, &op_data->fid2, &mds);
+                if (rc)
+                        RETURN(rc);
 
                 CDEBUG(D_OTHER,"link "DFID":%*s to "DFID"\n",
                        PFID(&op_data->fid2), op_data->namelen,
                        op_data->name, PFID(&op_data->fid1));
         } else {
-                mds = lmv_fld_lookup(obd, &op_data->fid1);
-                if (mds < 0)
-                        RETURN(mds);
+                rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+                if (rc)
+                        RETURN(rc);
 
                 /* request from MDS to acquire i_links for inode by fid1 */
                 CDEBUG(D_OTHER, "inc i_nlinks for "DFID"\n",
                        PFID(&op_data->fid1));
         }
 
-        CDEBUG(D_OTHER, "forward to MDS #%u ("DFID")\n",
+        CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n",
                mds, PFID(&op_data->fid1));
         rc = md_link(lmv->tgts[mds].ltd_exp, op_data, request);
 
@@ -1576,7 +1588,8 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_obj *obj;
-        int rc, mds, mds2;
+        mdsno_t mds, mds2;
+        int rc;
         ENTRY;
 
         CDEBUG(D_OTHER, "rename %*s in "DFID" to %*s in "DFID"\n",
@@ -1597,20 +1610,20 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
                        "to "DFID"\n", newlen, new, oldlen, newlen,
                        PFID(&op_data->fid2), PFID(&op_data->fid1));
 
-                mds = lmv_fld_lookup(obd, &op_data->fid2);
-                if (mds < 0)
-                        RETURN(mds);
+                rc = lmv_fld_lookup(obd, &op_data->fid2, &mds);
+                if (rc)
+                        RETURN(rc);
 
                 /*
-                 * target directory can be splitted, sowe should forward request
-                 * to the right MDS.
+                 * target directory can be split, sowe should forward request to
+                 * the right MDS.
                  */
                 obj = lmv_obj_grab(obd, &op_data->fid2);
                 if (obj) {
                         mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                            (char *)new, newlen);
                         op_data->fid2 = obj->lo_inodes[mds].li_fid;
-                        CDEBUG(D_OTHER, "forward to MDS #%u ("DFID")\n", mds,
+                        CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n", mds,
                                PFID(&op_data->fid2));
                         lmv_obj_put(obj);
                 }
@@ -1620,13 +1633,13 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
         obj = lmv_obj_grab(obd, &op_data->fid1);
         if (obj) {
                 /*
-                 * directory is already splitted, so we have to forward request
-                 * to the right MDS.
+                 * directory is already split, so we have to forward request to
+                 * the right MDS.
                  */
                 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                    (char *)old, oldlen);
                 op_data->fid1 = obj->lo_inodes[mds].li_fid;
-                CDEBUG(D_OTHER, "forward to MDS #%u ("DFID")\n", mds,
+                CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n", mds,
                        PFID(&op_data->fid1));
                 lmv_obj_put(obj);
         }
@@ -1634,27 +1647,27 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
         obj = lmv_obj_grab(obd, &op_data->fid2);
         if (obj) {
                 /*
-                 * directory is already splitted, so we have to forward request
-                 * to the right MDS.
+                 * directory is already split, so we have to forward request to
+                 * the right MDS.
                  */
                 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                    (char *)new, newlen);
 
                 op_data->fid2 = obj->lo_inodes[mds].li_fid;
-                CDEBUG(D_OTHER, "forward to MDS #%u ("DFID")\n", mds,
+                CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n", mds,
                        PFID(&op_data->fid2));
                 lmv_obj_put(obj);
         }
 
-        mds = lmv_fld_lookup(obd, &op_data->fid1);
-        if (mds < 0)
-                RETURN(mds);
+        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+        if (rc)
+                RETURN(rc);
 
 
 request:
-        mds2 = lmv_fld_lookup(obd, &op_data->fid2);
-        if (mds2 < 0)
-                RETURN(mds2);
+        rc = lmv_fld_lookup(obd, &op_data->fid2, &mds2);
+        if (rc)
+                RETURN(rc);
 
         if (mds != mds2) {
                 CDEBUG(D_OTHER,"cross-node rename "DFID"/%*s to "DFID"/%*s\n",
@@ -1676,7 +1689,8 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
         struct ptlrpc_request *req;
         struct mdt_body *body;
         struct lmv_obj *obj;
-        int rc = 0, i, mds;
+        int rc = 0, i;
+        mdsno_t mds;
         ENTRY;
 
         rc = lmv_check_connect(obd);
@@ -1686,17 +1700,15 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
         obj = lmv_obj_grab(obd, &op_data->fid1);
 
         CDEBUG(D_OTHER, "SETATTR for "DFID", valid 0x%x%s\n",
-               PFID(&op_data->fid1), iattr->ia_valid, obj ? ", splitted" : "");
+               PFID(&op_data->fid1), iattr->ia_valid, obj ? ", split" : "");
 
         if (obj) {
                 for (i = 0; i < obj->lo_objcount; i++) {
                         op_data->fid1 = obj->lo_inodes[i].li_fid;
 
-                        mds = lmv_fld_lookup(obd, &op_data->fid1);
-                        if (mds < 0) {
-                                rc = mds;
+                        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+                        if (rc)
                                 break;
-                        }
 
                         rc = md_setattr(lmv->tgts[mds].ltd_exp,
                                         op_data, iattr, ea, ealen, ea2,
@@ -1717,10 +1729,10 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
                 }
                 lmv_obj_put(obj);
         } else {
-                mds = lmv_fld_lookup(obd, &op_data->fid1);
-                if (mds < 0)
-                        RETURN(mds);
-                LASSERT(mds < lmv->desc.ld_tgt_count);
+                rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+                if (rc)
+                        RETURN(rc);
+
                 rc = md_setattr(lmv->tgts[mds].ltd_exp, op_data, iattr, ea,
                                 ealen, ea2, ea2len, request);
                 if (rc == 0) {
@@ -1732,29 +1744,29 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
         RETURN(rc);
 }
 
-static int lmv_sync(struct obd_export *exp, struct lu_fid *fid,
+static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
                     struct ptlrpc_request **request)
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
-        int i, rc;
+        mdsno_t mds;
+        int rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
        if (rc)
                RETURN(rc);
 
-        i = lmv_fld_lookup(obd, fid);
-        if (i < 0)
-                RETURN(i);
-        rc = md_sync(lmv->tgts[i].ltd_exp,
+        rc = lmv_fld_lookup(obd, fid, &mds);
+        if (rc)
+                RETURN(rc);
+        rc = md_sync(lmv->tgts[mds].ltd_exp,
                      fid, request);
         RETURN(rc);
 }
 
-/* main purpose of LMV blocking ast is to remove splitted directory
- * LMV presentation object (struct lmv_obj) attached to the lock
- * being revoked. */
+/* main purpose of LMV blocking ast is to remove split directory LMV
+ * presentation object (struct lmv_obj) attached to the lock being revoked. */
 int lmv_blocking_ast(struct ldlm_lock *lock,
                      struct ldlm_lock_desc *desc,
                      void *data, int flag)
@@ -1810,7 +1822,8 @@ static void lmv_remove_dots(struct page *page)
         }
 }
 
-static int lmv_readpage(struct obd_export *exp, struct lu_fid *fid,
+static int lmv_readpage(struct obd_export *exp,
+                        const struct lu_fid *fid,
                         __u64 offset, struct page *page,
                         struct ptlrpc_request **request)
 {
@@ -1818,17 +1831,14 @@ static int lmv_readpage(struct obd_export *exp, struct lu_fid *fid,
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lu_fid rid = *fid;
         struct lmv_obj *obj;
-        int rc, i;
+        mdsno_t mds;
+        int i, rc;
         ENTRY;
 
         rc = lmv_check_connect(obd);
        if (rc)
                RETURN(rc);
 
-        i = lmv_fld_lookup(obd, fid);
-        if (i < 0)
-                RETURN(i);
-        LASSERT(i < lmv->desc.ld_tgt_count);
         CDEBUG(D_OTHER, "READPAGE at %llu from "DFID"\n",
                offset, PFID(&rid));
 
@@ -1850,14 +1860,17 @@ static int lmv_readpage(struct obd_export *exp, struct lu_fid *fid,
                 CDEBUG(D_OTHER, "forward to "DFID" with offset %lu\n",
                        PFID(&rid), (unsigned long)offset);
         }
-        i = lmv_fld_lookup(obd, &rid);
-        if (i < 0)
-                RETURN(i);
-        rc = md_readpage(lmv->tgts[i].ltd_exp, &rid,
+        
+        rc = lmv_fld_lookup(obd, &rid, &mds);
+        if (rc)
+                RETURN(rc);
+        
+        rc = md_readpage(lmv->tgts[mds].ltd_exp, &rid,
                          offset, page, request);
 
         if (0 && rc == 0 && !lu_fid_eq(&rid, fid))
-                /* this page isn't from master object. To avoid "." and ".."
+                /*
+                 * This page isn't from master object. To avoid "." and ".."
                  * duplication in directory, we have to remove them from all
                  * slave objects
                  *
@@ -1877,7 +1890,8 @@ static int lmv_unlink_slaves(struct obd_export *exp,
         struct lmv_obd *lmv = &obd->u.lmv;
         struct lmv_stripe_md *mea = op_data->mea1;
         struct md_op_data *op_data2;
-        int i, mds, rc = 0;
+        int i, rc = 0;
+        mdsno_t mds;
         ENTRY;
 
         OBD_ALLOC_PTR(op_data2);
@@ -1890,9 +1904,9 @@ static int lmv_unlink_slaves(struct obd_export *exp,
                 op_data2->fid1 = mea->mea_ids[i];
                 op_data2->create_mode = MDS_MODE_DONT_LOCK | S_IFDIR;
 
-                mds = lmv_fld_lookup(obd, &op_data2->fid1);
-                if (mds < 0)
-                        GOTO(out_free_op_data2, rc = mds);
+                rc = lmv_fld_lookup(obd, &op_data2->fid1, &mds);
+                if (rc)
+                        GOTO(out_free_op_data2, rc);
                 if (lmv->tgts[mds].ltd_exp == NULL)
                         continue;
 
@@ -1921,7 +1935,8 @@ static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obd *lmv = &obd->u.lmv;
-        int rc, i = 0;
+        mdsno_t mds;
+        int rc, i;
         ENTRY;
 
        rc = lmv_check_connect(obd);
@@ -1951,10 +1966,10 @@ static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
                 CDEBUG(D_OTHER, "drop i_nlink on "DFID"\n",
                        PFID(&op_data->fid1));
         }
-        i = lmv_fld_lookup(obd, &op_data->fid1);
-        if (i < 0)
-                RETURN(i);
-        rc = md_unlink(lmv->tgts[i].ltd_exp, op_data, request);
+        rc = lmv_fld_lookup(obd, &op_data->fid1, &mds);
+        if (rc)
+                RETURN(rc);
+        rc = md_unlink(lmv->tgts[mds].ltd_exp, op_data, request);
         RETURN(rc);
 }
 
@@ -2023,8 +2038,7 @@ static int lmv_get_info(struct obd_export *exp, __u32 keylen,
         if (keylen == strlen("mdsize") && !strcmp(key, "mdsize")) {
                 __u32 *mdsize = val;
                 *vallen = sizeof(__u32);
-                *mdsize = sizeof(struct lu_fid) * lmv->desc.ld_tgt_count
-                       + sizeof(struct lmv_stripe_md);
+                *mdsize = lmv_get_easize(lmv);
                 RETURN(0);
         } else if (keylen == strlen("mdsnum") && !strcmp(key, "mdsnum")) {
                 struct obd_uuid *cluuid = &lmv->cluuid;
@@ -2202,16 +2216,16 @@ int lmv_set_info_async(struct obd_export *exp, obd_count keylen,
 
         if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
                 struct lu_fid *fid = (struct lu_fid *)val;
-                int i;
+                mdsno_t mds;
 
                 rc = lmv_check_connect(obd);
                 if (rc)
                         RETURN(rc);
 
-                i = lmv_fld_lookup(obd, fid);
-                if (i < 0)
-                        RETURN(i);
-                rc = obd_set_info_async(lmv->tgts[i].ltd_exp,
+                rc = lmv_fld_lookup(obd, fid, &mds);
+                if (rc)
+                        RETURN(rc);
+                rc = obd_set_info_async(lmv->tgts[mds].ltd_exp,
                                         keylen, key, vallen, val,
                                         set);
                 RETURN(rc);
@@ -2235,8 +2249,7 @@ int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
         int mea_size, i;
         ENTRY;
 
-       mea_size = (sizeof(struct lu_fid) *
-                    lmv->desc.ld_tgt_count) + sizeof(struct lmv_stripe_md);
+        mea_size = lmv_get_easize(lmv);
         if (!lmmp)
                 RETURN(mea_size);
 
@@ -2285,9 +2298,7 @@ int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
         __u32 magic;
         ENTRY;
 
-        mea_size = sizeof(struct lu_fid) *
-                lmv->desc.ld_tgt_count + sizeof(struct lmv_stripe_md);
-
+        mea_size = lmv_get_easize(lmv);
         if (lsmp == NULL)
                 return mea_size;
 
@@ -2388,7 +2399,7 @@ int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
                         RETURN(-ENOMEM);
         }
 
-        /* here we should take care about splitted dir, so store cookie and fid
+        /* here we should take care about split dir, so store cookie and fid
          * for "master" object should already be allocated and passed in @oa. */
         LASSERT(oa->o_id != 0);
         LASSERT(oa->o_fid != 0);
@@ -2486,7 +2497,7 @@ int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
 #endif
 
 static int lmv_cancel_unused(struct obd_export *exp,
-                             struct lu_fid *fid,
+                             const struct lu_fid *fid,
                              int flags, void *opaque)
 {
         struct obd_device *obd = exp->exp_obd;
@@ -2518,7 +2529,7 @@ int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data)
 }
 
 int lmv_lock_match(struct obd_export *exp, int flags,
-                   struct lu_fid *fid, ldlm_type_t type,
+                   const struct lu_fid *fid, ldlm_type_t type,
                    ldlm_policy_data_t *policy, ldlm_mode_t mode,
                    struct lustre_handle *lockh)
 {
@@ -2623,7 +2634,7 @@ struct md_ops lmv_md_ops = {
         .m_link                 = lmv_link,
         .m_rename               = lmv_rename,
         .m_setattr              = lmv_setattr,
-        .m_setxattr              = lmv_setxattr,
+        .m_setxattr             = lmv_setxattr,
         .m_sync                 = lmv_sync,
         .m_readpage             = lmv_readpage,
         .m_unlink               = lmv_unlink,
index ef45993..274e7b1 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
@@ -55,7 +55,7 @@ static spinlock_t obj_list_lock = SPIN_LOCK_UNLOCKED;
 /* creates new obj on passed @fid and @mea. */
 struct lmv_obj *
 lmv_obj_alloc(struct obd_device *obd,
-              struct lu_fid *fid,
+              const struct lu_fid *fid,
               struct lmv_stripe_md *mea)
 {
         int i;
@@ -192,7 +192,7 @@ lmv_obj_put(struct lmv_obj *obj)
 }
 
 static struct lmv_obj *
-__lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
+__lmv_obj_grab(struct obd_device *obd, const struct lu_fid *fid)
 {
         struct lmv_obj *obj;
         struct list_head *cur;
@@ -210,7 +210,7 @@ __lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
                  * passed obd. It is possible that, object manager will have two
                  * objects with the same fid belong to different obds, if client
                  * and mds runs on the same host. May be it is good idea to have
-                 * objects list assosiated with obd.
+                 * objects list associated with obd.
                  */
                 if (obj->lo_obd != obd)
                         continue;
@@ -224,7 +224,7 @@ __lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
 }
 
 struct lmv_obj *
-lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
+lmv_obj_grab(struct obd_device *obd, const struct lu_fid *fid)
 {
         struct lmv_obj *obj;
         ENTRY;
@@ -239,7 +239,7 @@ lmv_obj_grab(struct obd_device *obd, struct lu_fid *fid)
 /* looks in objects list for an object that matches passed @fid. If it is not
  * found -- creates it using passed @mea and puts onto list. */
 static struct lmv_obj *
-__lmv_obj_create(struct obd_device *obd, struct lu_fid *fid,
+__lmv_obj_create(struct obd_device *obd, const struct lu_fid *fid,
                  struct lmv_stripe_md *mea)
 {
         struct lmv_obj *new, *obj;
@@ -260,8 +260,8 @@ __lmv_obj_create(struct obd_device *obd, struct lu_fid *fid,
         obj = __lmv_obj_grab(obd, fid);
         if (obj) {
                 /* someone created it already - put @obj and getting out. */
-                lmv_obj_free(new);
                 spin_unlock(&obj_list_lock);
+                lmv_obj_free(new);
                 RETURN(obj);
         }
 
@@ -280,7 +280,7 @@ __lmv_obj_create(struct obd_device *obd, struct lu_fid *fid,
 /* creates object from passed @fid and @mea. If @mea is NULL, it will be
  * obtained from correct MDT and used for constructing the object. */
 struct lmv_obj *
-lmv_obj_create(struct obd_export *exp, struct lu_fid *fid,
+lmv_obj_create(struct obd_export *exp, const struct lu_fid *fid,
                struct lmv_stripe_md *mea)
 {
         struct obd_device *obd = exp->exp_obd;
@@ -288,7 +288,8 @@ lmv_obj_create(struct obd_export *exp, struct lu_fid *fid,
         struct ptlrpc_request *req = NULL;
         struct lmv_obj *obj;
         struct lustre_md md;
-        int mealen, rc, mds;
+        int mealen, rc;
+        mdsno_t mds;
         ENTRY;
 
         CDEBUG(D_OTHER, "get mea for "DFID" and create lmv obj\n",
@@ -300,15 +301,15 @@ lmv_obj_create(struct obd_export *exp, struct lu_fid *fid,
                 __u64 valid;
 
                 CDEBUG(D_OTHER, "mea isn't passed in, get it now\n");
-                mealen = MEA_SIZE_LMV(lmv);
+                mealen = lmv_get_easize(lmv);
 
                 /* time to update mea of parent fid */
                 md.mea = NULL;
                 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
 
-                mds = lmv_fld_lookup(obd, fid);
-                if (mds < 0)
-                        GOTO(cleanup, obj = ERR_PTR(mds));
+                rc = lmv_fld_lookup(obd, fid, &mds);
+                if (rc)
+                        GOTO(cleanup, obj = ERR_PTR(rc));
 
                 rc = md_getattr(lmv->tgts[mds].ltd_exp, fid, valid, mealen, &req);
                 if (rc) {
@@ -353,7 +354,7 @@ cleanup:
  * for subsequent callers of lmv_obj_grab().
  */
 int
-lmv_obj_delete(struct obd_export *exp, struct lu_fid *fid)
+lmv_obj_delete(struct obd_export *exp, const struct lu_fid *fid)
 {
         struct obd_device *obd = exp->exp_obd;
         struct lmv_obj *obj;
index 8e3b72c..3599cf2 100644 (file)
@@ -295,13 +295,17 @@ int lov_setstripe(struct obd_export *exp, struct lov_stripe_md **lsmp,
         int rc;
         ENTRY;
 
+#if __KERNEL__
         if ((unsigned long)lump < USER_SPACE_TOP) {
                 rc = copy_from_user(&lum, lump, sizeof(lum));
                 if (rc)
                         RETURN(-EFAULT);
         } else {
+#endif
                 memcpy(&lum, lump, sizeof(lum));
+#if __KERNEL__
         }
+#endif
 
         if (lum.lmm_magic != LOV_USER_MAGIC) {
                 if (lum.lmm_magic == __swab32(LOV_USER_MAGIC)) {
@@ -415,14 +419,18 @@ int lov_getstripe(struct obd_export *exp, struct lov_stripe_md *lsm,
         if (!lsm)
                 RETURN(-ENODATA);
 
+#if __KERNEL__
         if ((unsigned long)lump < USER_SPACE_TOP) {
                 rc = copy_from_user(&lum, lump, sizeof(lum));
                 if (rc)
                         RETURN(-EFAULT);
         } else {
+#endif
                 memcpy(&lum, lump, sizeof(lum));
+#if __KERNEL__
         }
-
+#endif
+        
         if (lum.lmm_magic != LOV_USER_MAGIC)
                 RETURN(-EINVAL);
 
@@ -438,21 +446,29 @@ int lov_getstripe(struct obd_export *exp, struct lov_stripe_md *lsm,
 
         /* User wasn't expecting this many OST entries */
         if (lum.lmm_stripe_count == 0) {
+#if __KERNEL__
                 if ((unsigned long)lump < USER_SPACE_TOP) {
                         if (copy_to_user(lump, lmmk, sizeof(lum)))
                                 rc = -EFAULT;
                 } else {
+#endif
                         memcpy(lump, lmmk, sizeof(lum));
+#if __KERNEL__
                 }
+#endif
         } else if (lum.lmm_stripe_count < lmmk->lmm_stripe_count) {
                 rc = -EOVERFLOW;
         } else {
+#if __KERNEL__
                 if ((unsigned long)lump < USER_SPACE_TOP) {
                         if (copy_to_user(lump, lmmk, sizeof(lum)))
                                 rc = -EFAULT;
                 } else {
+#endif
                         memcpy(lump, lmmk, sizeof(lum));
+#if __KERNEL__
                 }
+#endif
         }
 
         obd_free_diskmd(exp, &lmmk);
index ceab76f..e1c73a0 100644 (file)
 #include <lustre_mdc.h>
 
 void mdc_pack_req_body(struct ptlrpc_request *req, int offset,
-                       __u64 valid, struct lu_fid *fid, int ea_size, int flags);
+                       __u64 valid, const struct lu_fid *fid,
+                       int ea_size, int flags);
 void mdc_pack_rep_body(struct ptlrpc_request *);
 void mdc_readdir_pack(struct ptlrpc_request *req, int pos, __u64 offset,
-                     __u32 size, struct lu_fid *fid);
+                     __u32 size, const struct lu_fid *fid);
 void mdc_getattr_pack(struct ptlrpc_request *req, int offset, int valid,
                       int flags, struct md_op_data *data);
 void mdc_setattr_pack(struct ptlrpc_request *req, int offset,
@@ -105,8 +106,9 @@ extern quota_interface_t *quota_interface;
 int mdc_set_lock_data(struct obd_export *exp,
                       __u64 *lockh, void *data);
 
-int mdc_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
+int mdc_change_cbdata(struct obd_export *exp, const struct lu_fid *fid,
                       ldlm_iterator_t it, void *data);
+
 int mdc_intent_lock(struct obd_export *exp,
                     struct md_op_data *,
                     void *lmm, int lmmsize,
@@ -130,21 +132,21 @@ int mdc_init_ea_size(struct obd_export *exp, int easize, int def_easzie,
                      int cookiesize);
 
 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid);
-int mdc_getattr(struct obd_export *exp, struct lu_fid *fid,
+int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
                 obd_valid valid, int ea_size,
                 struct ptlrpc_request **request);
-int mdc_getattr_name(struct obd_export *exp, struct lu_fid *fid,
+int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
                      const char *filename, int namelen, obd_valid valid,
                      int ea_size, struct ptlrpc_request **request);
 int mdc_setattr(struct obd_export *exp, struct md_op_data *op_data,
                 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
                 struct ptlrpc_request **request);
-int mdc_setxattr(struct obd_export *exp, struct lu_fid *fid,
+int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
                  obd_valid valid, const char *xattr_name,
                  const char *input, int input_size,
                  int output_size, int flags,
                  struct ptlrpc_request **request);
-int mdc_getxattr(struct obd_export *exp, struct lu_fid *fid,
+int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
                  obd_valid valid, const char *xattr_name,
                  const char *input, int input_size,
                  int output_size, int flags, struct ptlrpc_request **request);
@@ -169,7 +171,7 @@ int mdc_clear_open_replay_data(struct obd_export *exp,
 int mdc_close(struct obd_export *, struct md_op_data *,
               struct obd_client_handle *, struct ptlrpc_request **);
 
-int mdc_readpage(struct obd_export *exp, struct lu_fid *fid,
+int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
                  __u64 offset,  struct page *, struct ptlrpc_request **);
 
 int mdc_create(struct obd_export *exp, struct md_op_data *op_data,
@@ -187,15 +189,15 @@ int mdc_rename(struct obd_export *exp, struct md_op_data *op_data,
                const char *old, int oldlen, const char *new, int newlen,
                struct ptlrpc_request **request);
 
-int mdc_sync(struct obd_export *exp, struct lu_fid *fid,
+int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
              struct ptlrpc_request **);
 
 int mdc_lock_match(struct obd_export *exp, int flags,
-                   struct lu_fid *fid, ldlm_type_t type,
+                   const struct lu_fid *fid, ldlm_type_t type,
                    ldlm_policy_data_t *policy, ldlm_mode_t mode,
                    struct lustre_handle *lockh);
 
-int mdc_cancel_unused(struct obd_export *exp, struct lu_fid *fid,
+int mdc_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
                       int flags, void *opaque);
 
 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data);
index 2c423c0..19accd5 100644 (file)
@@ -39,7 +39,7 @@
 #endif
 
 void mdc_readdir_pack(struct ptlrpc_request *req, int pos, __u64 offset,
-                      __u32 size, struct lu_fid *fid)
+                      __u32 size, const struct lu_fid *fid)
 {
         struct mdt_body *b;
 
@@ -63,7 +63,8 @@ static void mdc_pack_body(struct mdt_body *b)
 }
 
 void mdc_pack_req_body(struct ptlrpc_request *req, int offset,
-                       __u64 valid, struct lu_fid *fid, int ea_size, int flags)
+                       __u64 valid, const struct lu_fid *fid,
+                       int ea_size, int flags)
 {
         struct mdt_body *b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*b));
 
index f31df4f..af0a150 100644 (file)
@@ -143,7 +143,7 @@ int mdc_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data)
 }
 
 int mdc_lock_match(struct obd_export *exp, int flags,
-                   struct lu_fid *fid, ldlm_type_t type,
+                   const struct lu_fid *fid, ldlm_type_t type,
                    ldlm_policy_data_t *policy, ldlm_mode_t mode,
                    struct lustre_handle *lockh)
 {
@@ -162,7 +162,7 @@ int mdc_lock_match(struct obd_export *exp, int flags,
 }
 
 int mdc_cancel_unused(struct obd_export *exp,
-                      struct lu_fid *fid,
+                      const struct lu_fid *fid,
                       int flags, void *opaque)
 {
         struct ldlm_res_id res_id =
@@ -179,7 +179,8 @@ int mdc_cancel_unused(struct obd_export *exp,
         RETURN(rc);
 }
 
-int mdc_change_cbdata(struct obd_export *exp, struct lu_fid *fid, 
+int mdc_change_cbdata(struct obd_export *exp,
+                      const struct lu_fid *fid, 
                       ldlm_iterator_t it, void *data)
 {
         struct ldlm_res_id res_id = { .name = {0} };
index c0b0ac3..2e75328 100644 (file)
@@ -100,8 +100,8 @@ static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
 /* This should be mdc_get_info("rootfid") */
 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid)
 {
-        return send_getstatus(class_exp2cliimp(exp), rootfid, LUSTRE_IMP_FULL,
-                              0);
+        return send_getstatus(class_exp2cliimp(exp), rootfid,
+                              LUSTRE_IMP_FULL, 0);
 }
 
 static
@@ -164,9 +164,8 @@ int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
         RETURN (0);
 }
 
-int mdc_getattr(struct obd_export *exp, struct lu_fid *fid,
-                obd_valid valid, int ea_size,
-                struct ptlrpc_request **request)
+int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
+                obd_valid valid, int ea_size, struct ptlrpc_request **request)
 {
         struct ptlrpc_request *req;
         int size[2] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
@@ -204,7 +203,7 @@ int mdc_getattr(struct obd_export *exp, struct lu_fid *fid,
         RETURN (rc);
 }
 
-int mdc_getattr_name(struct obd_export *exp, struct lu_fid *fid,
+int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
                      const char *filename, int namelen, obd_valid valid,
                      int ea_size, struct ptlrpc_request **request)
 {
@@ -236,7 +235,7 @@ int mdc_getattr_name(struct obd_export *exp, struct lu_fid *fid,
 }
 
 static
-int mdc_xattr_common(struct obd_export *exp, struct lu_fid *fid,
+int mdc_xattr_common(struct obd_export *exp, const struct lu_fid *fid,
                      int opcode, obd_valid valid, const char *xattr_name,
                      const char *input, int input_size, int output_size,
                      int flags, struct ptlrpc_request **request)
@@ -317,7 +316,7 @@ err_out:
         goto out;
 }
 
-int mdc_setxattr(struct obd_export *exp, struct lu_fid *fid,
+int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
                  obd_valid valid, const char *xattr_name,
                  const char *input, int input_size,
                  int output_size, int flags,
@@ -327,7 +326,7 @@ int mdc_setxattr(struct obd_export *exp, struct lu_fid *fid,
                                 input, input_size, output_size, flags, request);
 }
 
-int mdc_getxattr(struct obd_export *exp, struct lu_fid *fid,
+int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
                  obd_valid valid, const char *xattr_name,
                  const char *input, int input_size,
                  int output_size, int flags, struct ptlrpc_request **request)
@@ -729,8 +728,9 @@ int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data)
         RETURN(rc);
 }
 
-int mdc_readpage(struct obd_export *exp, struct lu_fid *fid, __u64 offset,
-                 struct page *page, struct ptlrpc_request **request)
+int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
+                 __u64 offset, struct page *page,
+                 struct ptlrpc_request **request)
 {
         struct obd_import *imp = class_exp2cliimp(exp);
         struct ptlrpc_request *req = NULL;
@@ -971,7 +971,7 @@ out:
         return rc;
 }
 
-static int mdc_pin(struct obd_export *exp, struct lu_fid *fid,
+static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
                    struct obd_client_handle *handle, int flag)
 {
         struct ptlrpc_request *req;
@@ -1053,7 +1053,7 @@ static int mdc_unpin(struct obd_export *exp,
         RETURN(rc);
 }
 
-int mdc_sync(struct obd_export *exp, struct lu_fid *fid,
+int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
              struct ptlrpc_request **request)
 {
         struct ptlrpc_request *req;