-}
-
-int lmv_handle_remote_inode(struct obd_export *exp, struct ll_uctxt *uctxt,
- void *lmm, int lmmsize,
- struct lookup_intent *it, int flags,
- struct ptlrpc_request **reqp,
- ldlm_blocking_callback cb_blocking)
-{
- struct obd_device *obd = exp->exp_obd;
- struct lmv_obd *lmv = &obd->u.lmv;
- struct mds_body *body = NULL;
- int rc = 0;
- ENTRY;
-
- body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
- LASSERT(body != NULL);
-
- if (body->valid & OBD_MD_MDS) {
- /* oh, MDS reports that this is remote inode case
- * i.e. we have to ask for real attrs on another MDS */
- struct ptlrpc_request *req;
- struct ll_fid nfid;
- struct lustre_handle plock;
- int pmode;
-
- if (it->it_op == IT_LOOKUP) {
- /* unfortunately, we have to lie to MDC/MDS to
- * retrieve attributes llite needs */
- it->it_op = IT_GETATTR;
- }
-
- /* we got LOOKUP lock, but we really need attrs */
- pmode = it->d.lustre.it_lock_mode;
- if (pmode) {
- memcpy(&plock, &it->d.lustre.it_lock_handle,
- sizeof(plock));
- it->d.lustre.it_lock_mode = 0;
- }
-
- nfid = body->fid1;
- it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
- rc = md_intent_lock(lmv->tgts[nfid.mds].ltd_exp, uctxt, &nfid,
- NULL, 0, lmm, lmmsize, NULL, it, flags,
- &req, cb_blocking);
-
- /* llite needs LOOKUP lock to track dentry revocation in
- * order to maintain dcache consistency. thus drop UPDATE
- * lock here and put LOOKUP in request */
- if (rc == 0) {
- lmv_drop_intent_lock(it);
- memcpy(&it->d.lustre.it_lock_handle, &plock,
- sizeof(plock));
- it->d.lustre.it_lock_mode = pmode;
-
- } else if (pmode)
- ldlm_lock_decref(&plock, pmode);
-
- ptlrpc_req_finished(*reqp);
- *reqp = req;
- }
- RETURN(rc);
-}
-
-int lmv_intent_open(struct obd_export *exp, struct ll_uctxt *uctxt,
- struct ll_fid *pfid, const char *name, int len,
- void *lmm, int lmmsize, struct ll_fid *cfid,
- struct lookup_intent *it, int flags,
- struct ptlrpc_request **reqp,
- ldlm_blocking_callback cb_blocking)
-{
- struct obd_device *obd = exp->exp_obd;
- struct lmv_obd *lmv = &obd->u.lmv;
- struct mds_body *body = NULL;
- struct ll_fid rpfid = *pfid;
- struct lmv_obj *obj;
- struct mea *mea;
- int rc, mds;
- ENTRY;
-
- /* IT_OPEN is intended to open (and create, possible) an object. Parent
- * (pfid) may be splitted dir */
-
-repeat:
- mds = rpfid.mds;
- obj = lmv_grab_obj(obd, &rpfid);
- if (obj) {
- /* directory is already splitted, so we have to forward
- * request to the right MDS */
- mds = raw_name2idx(obj->objcount, (char *)name, len);
- CDEBUG(D_OTHER, "forward to MDS #%u\n", mds);
-
- rpfid = obj->objs[mds].fid;
- lmv_put_obj(obj);
- }
-
- rc = md_intent_lock(lmv->tgts[mds].ltd_exp, uctxt, &rpfid, name,
- len, lmm, lmmsize, cfid, it, flags, reqp,
- cb_blocking);
- if (rc == -ERESTART) {
- /* directory got splitted. time to update local object
- * and repeat the request with proper MDS */
- LASSERT(fid_equal(pfid, &rpfid));
- rc = lmv_get_mea_and_update_object(exp, &rpfid);
- if (rc == 0) {
- ptlrpc_req_finished(*reqp);
- goto repeat;
- }
- }
- if (rc != 0)
- RETURN(rc);
-
- /* okay, MDS has returned success. Probably name has been resolved in
- * remote inode */
- rc = lmv_handle_remote_inode(exp, uctxt, lmm, lmmsize, it,
- flags, reqp, cb_blocking);
- if (rc != 0) {
- LASSERT(rc < 0);
- RETURN(rc);
- }
-
- /* caller may use attrs MDS returns on IT_OPEN lock request so, we have
- * to update them for splitted dir */
- body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
- LASSERT(body != NULL);
-
- cfid = &body->fid1;
- obj = lmv_grab_obj(obd, cfid);
- if (!obj && (mea = body_of_splitted_dir(*reqp, 1))) {
- /* wow! this is splitted dir, we'd like to handle it */
- obj = lmv_create_obj(exp, &body->fid1, mea);
- if (IS_ERR(obj))
- RETURN(PTR_ERR(obj));
- }
-
- if (obj) {
- /* this is splitted dir and we'd want to get attrs */
- CDEBUG(D_OTHER, "attrs from slaves for %lu/%lu/%lu\n",
- (unsigned long)cfid->mds, (unsigned long)cfid->id,
- (unsigned long)cfid->generation);
- rc = lmv_revalidate_slaves(exp, reqp, cfid,
- it, 1, cb_blocking);
- } else if (S_ISDIR(body->mode)) {
- /*CWARN("hmmm, %lu/%lu/%lu has not lmv obj?!\n",
- (unsigned long) cfid->mds,
- (unsigned long) cfid->id,
- (unsigned long) cfid->generation);*/
- }
-
- if (obj)
- lmv_put_obj(obj);
-
- RETURN(rc);
-}
-
-int lmv_intent_getattr(struct obd_export *exp, struct ll_uctxt *uctxt,
- struct ll_fid *pfid, const char *name, int len,
- void *lmm, int lmmsize, struct ll_fid *cfid,
- struct lookup_intent *it, int flags,
- struct ptlrpc_request **reqp,
- ldlm_blocking_callback cb_blocking)
-{
- struct obd_device *obd = exp->exp_obd;
- struct lmv_obd *lmv = &obd->u.lmv;
- struct mds_body *body = NULL;
- struct ll_fid rpfid = *pfid;
- struct lmv_obj *obj, *obj2;
- struct mea *mea;
- int rc = 0, mds;
- ENTRY;
-
- if (cfid) {
- /* caller wants to revalidate attrs of obj we have to revalidate
- * slaves if requested object is splitted directory */
- CDEBUG(D_OTHER, "revalidate attrs for %lu/%lu/%lu\n",
- (unsigned long)cfid->mds, (unsigned long)cfid->id,
- (unsigned long)cfid->generation);
- mds = cfid->mds;
- obj = lmv_grab_obj(obd, cfid);
- if (obj) {
- /* in fact, we need not this with current intent_lock(),
- * but it may change some day */
- rpfid = obj->objs[mds].fid;
- lmv_put_obj(obj);
- }
- rc = md_intent_lock(lmv->tgts[mds].ltd_exp, uctxt, &rpfid, name,
- len, lmm, lmmsize, cfid, it, flags, reqp,
- cb_blocking);
- if (obj && rc >= 0) {
- /* this is splitted 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 if we don't. this means that nobody should
- * use UPDATE lock to notify about object * removal */
- CDEBUG(D_OTHER,
- "revalidate slaves for %lu/%lu/%lu, rc %d\n",
- (unsigned long)cfid->mds, (unsigned long)cfid->id,
- (unsigned long)cfid->generation, rc);
-
- rc = lmv_revalidate_slaves(exp, reqp, cfid, it, rc,
- cb_blocking);
- }
-
- RETURN(rc);
- }
-
- CDEBUG(D_OTHER, "INTENT getattr for %*s on %lu/%lu/%lu\n",
- len, name, (unsigned long)pfid->mds, (unsigned long)pfid->id,
- (unsigned long)pfid->generation);
-
- mds = pfid->mds;
- obj = lmv_grab_obj(obd, pfid);
- if (obj && len) {
- /* directory is already splitted. calculate mds */
- mds = raw_name2idx(obj->objcount, (char *) name, len);
- rpfid = obj->objs[mds].fid;
- lmv_put_obj(obj);
-
- CDEBUG(D_OTHER, "forward to MDS #%u (slave %lu/%lu/%lu)\n",
- mds, (unsigned long)rpfid.mds, (unsigned long)rpfid.id,
- (unsigned long)rpfid.generation);
- }
-
- rc = md_intent_lock(lmv->tgts[mds].ltd_exp, uctxt, &rpfid, name,
- len, lmm, lmmsize, NULL, it, flags, reqp,
- cb_blocking);
-
- if (rc < 0)
- RETURN(rc);
-
- LASSERT(rc == 0);
-
- /* okay, MDS has returned success. probably name has been
- * resolved in remote inode */
- rc = lmv_handle_remote_inode(exp, uctxt, lmm, lmmsize, it,
- flags, reqp, cb_blocking);
- if (rc < 0)
- RETURN(rc);
-
- body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
- LASSERT(body != NULL);
-
- cfid = &body->fid1;
- obj2 = lmv_grab_obj(obd, cfid);
-
- if (!obj2 && (mea = body_of_splitted_dir(*reqp, 1))) {
- /* wow! this is splitted dir, we'd like to handle it. */
- body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
- LASSERT(body != NULL);
-
- obj2 = lmv_create_obj(exp, &body->fid1, mea);
- if (IS_ERR(obj2))
- RETURN(PTR_ERR(obj2));