1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_LMV
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/pagemap.h>
32 #include <asm/div64.h>
33 #include <linux/seq_file.h>
34 #include <linux/namei.h>
36 #include <liblustre.h>
39 #include <lustre/lustre_idl.h>
40 #include <obd_support.h>
41 #include <lustre_lib.h>
42 #include <lustre_net.h>
43 #include <lustre_dlm.h>
44 #include <obd_class.h>
45 #include <lprocfs_status.h>
46 #include "lmv_internal.h"
48 static inline void lmv_drop_intent_lock(struct lookup_intent *it)
50 if (it->d.lustre.it_lock_mode != 0)
51 ldlm_lock_decref((void *)&it->d.lustre.it_lock_handle,
52 it->d.lustre.it_lock_mode);
55 int lmv_intent_remote(struct obd_export *exp, void *lmm,
56 int lmmsize, struct lookup_intent *it,
57 int flags, struct ptlrpc_request **reqp,
58 ldlm_blocking_callback cb_blocking,
61 struct obd_device *obd = exp->exp_obd;
62 struct lmv_obd *lmv = &obd->u.lmv;
63 struct ptlrpc_request *req = NULL;
64 struct mdt_body *body = NULL;
65 struct lustre_handle plock;
66 struct md_op_data *op_data;
67 struct obd_export *tgt_exp;
71 body = lustre_msg_buf((*reqp)->rq_repmsg,
72 DLM_REPLY_REC_OFF, sizeof(*body));
73 LASSERT(body != NULL);
75 if (!(body->valid & OBD_MD_MDS))
79 * oh, MDS reports that this is remote inode case i.e. we have to ask
80 * for real attrs on another MDS.
82 if (it->it_op & IT_LOOKUP) {
84 * unfortunately, we have to lie to MDC/MDS to retrieve
85 * attributes llite needs.
87 it->it_op = IT_GETATTR;
90 /* we got LOOKUP lock, but we really need attrs */
91 pmode = it->d.lustre.it_lock_mode;
93 memcpy(&plock, &it->d.lustre.it_lock_handle, sizeof(plock));
94 it->d.lustre.it_lock_mode = 0;
95 it->d.lustre.it_data = 0;
98 LASSERT(fid_is_sane(&body->fid1));
100 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
102 OBD_ALLOC_PTR(op_data);
104 GOTO(out, rc = -ENOMEM);
106 op_data->fid1 = body->fid1;
108 tgt_exp = lmv_get_export(lmv, &body->fid1);
110 RETURN(PTR_ERR(tgt_exp));
112 rc = md_intent_lock(tgt_exp, op_data, lmm, lmmsize, it, flags,
113 &req, cb_blocking, extra_lock_flags);
116 * llite needs LOOKUP lock to track dentry revocation in order to
117 * maintain dcache consistency. Thus drop UPDATE lock here and put
121 lmv_drop_intent_lock(it);
122 memcpy(&it->d.lustre.it_lock_handle, &plock, sizeof(plock));
123 it->d.lustre.it_lock_mode = pmode;
126 OBD_FREE_PTR(op_data);
130 ldlm_lock_decref(&plock, pmode);
132 ptlrpc_req_finished(*reqp);
137 int lmv_alloc_fid_for_split(struct obd_device *obd, struct lu_fid *pid,
138 struct md_op_data *op, struct lu_fid *fid)
141 struct lmv_obd *lmv = &obd->u.lmv;
147 obj = lmv_obj_grab(obd, pid);
150 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
151 (char *)op->name, op->namelen);
152 rpid = &obj->lo_inodes[mds].li_fid;
153 rc = lmv_fld_lookup(lmv, rpid, &mds);
157 rc = obd_fid_alloc(lmv->tgts[mds].ltd_exp, fid, NULL);
161 LASSERT(fid_is_sane(fid));
162 rc = fld_client_create(&lmv->lmv_fld,
163 fid_seq(fid), mds, NULL);
165 CERROR("can't create fld rc%d\n", rc);
169 CDEBUG(D_INFO, "Allocate new fid"DFID"for split obj\n",PFID(fid));
176 * IT_OPEN is intended to open (and create, possible) an object. Parent (pid)
179 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
180 void *lmm, int lmmsize, struct lookup_intent *it,
181 int flags, struct ptlrpc_request **reqp,
182 ldlm_blocking_callback cb_blocking,
183 int extra_lock_flags)
185 struct obd_device *obd = exp->exp_obd;
186 struct lu_fid rpid = op_data->fid1;
187 struct lmv_obd *lmv = &obd->u.lmv;
188 struct mdt_body *body = NULL;
189 struct md_op_data *sop_data;
190 struct lmv_stripe_md *mea;
196 OBD_ALLOC_PTR(sop_data);
197 if (sop_data == NULL)
200 /* save op_data fro repeat case */
201 *sop_data = *op_data;
204 LASSERT(++loop <= 2);
205 rc = lmv_fld_lookup(lmv, &rpid, &mds);
207 GOTO(out_free_sop_data, rc);
209 obj = lmv_obj_grab(obd, &rpid);
212 * Directory is already split, so we have to forward request to
215 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
216 (char *)op_data->name, op_data->namelen);
218 rpid = obj->lo_inodes[mds].li_fid;
219 rc = lmv_fld_lookup(lmv, &rpid, &mds);
222 GOTO(out_free_sop_data, rc);
224 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n",
228 sop_data->fid1 = rpid;
230 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, sop_data,
231 lmm, lmmsize, it, flags, reqp,
232 cb_blocking, extra_lock_flags);
234 if (rc == -ERESTART) {
236 * Directory got split. Time to update local object and repeat
237 * the request with proper MDS.
239 LASSERT(lu_fid_eq(&op_data->fid1, &rpid));
240 rc = lmv_handle_split(exp, &rpid);
242 ptlrpc_req_finished(*reqp);
243 /* We shoudld reallocate the FID for the object */
244 rc = lmv_alloc_fid_for_split(obd, &rpid, op_data,
247 GOTO(out_free_sop_data, rc);
248 /* client switches to new sequence, setup fld */
251 } else if (rc == -ESTALE && it->d.lustre.it_lock_mode) {
252 struct lustre_handle *handle;
253 /* cross-ref open can have lookup lock on child */
254 handle = (struct lustre_handle *)&it->d.lustre.it_lock_handle;
255 ldlm_lock_decref(handle, it->d.lustre.it_lock_mode);
259 GOTO(out_free_sop_data, rc);
262 * Okay, MDS has returned success. Probably name has been resolved in
265 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
266 cb_blocking, extra_lock_flags);
271 * This is possible, that some userspace application will try to
272 * open file as directory and we will have -ENOTDIR here. As
273 * this is "usual" situation, we should not print error here,
276 CDEBUG(D_OTHER, "can't handle remote %s: dir "DFID"("DFID"):"
277 "%*s: %d\n", LL_IT2STR(it), PFID(&op_data->fid2),
278 PFID(&rpid), op_data->namelen, op_data->name, rc);
279 GOTO(out_free_sop_data, rc);
283 * nothing is found, do not access body->fid1 as it is zero and thus
286 if ((it->d.lustre.it_disposition & DISP_LOOKUP_NEG) &&
287 !(it->d.lustre.it_disposition & DISP_OPEN_CREATE) &&
288 !(it->d.lustre.it_disposition & DISP_OPEN_OPEN))
289 GOTO(out_free_sop_data, rc = 0);
291 /* caller may use attrs MDS returns on IT_OPEN lock request so, we have
292 * to update them for split dir */
293 body = lustre_msg_buf((*reqp)->rq_repmsg,
294 DLM_REPLY_REC_OFF, sizeof(*body));
295 LASSERT(body != NULL);
297 /* could not find object, FID is not present in response. */
298 if (!(body->valid & OBD_MD_FLID))
299 GOTO(out_free_sop_data, rc = 0);
301 obj = lmv_obj_grab(obd, &body->fid1);
302 if (!obj && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
303 /* wow! this is split dir, we'd like to handle it */
304 obj = lmv_obj_create(exp, &body->fid1, mea);
306 GOTO(out_free_sop_data, rc = (int)PTR_ERR(obj));
310 /* this is split dir and we'd want to get attrs */
311 CDEBUG(D_OTHER, "attrs from slaves for "DFID"\n",
314 rc = lmv_revalidate_slaves(exp, reqp, &body->fid1, it, 1,
315 cb_blocking, extra_lock_flags);
316 } else if (S_ISDIR(body->mode)) {
317 CDEBUG(D_OTHER, "object "DFID" has not lmv obj?\n",
326 OBD_FREE_PTR(sop_data);
330 int lmv_intent_getattr(struct obd_export *exp, struct md_op_data *op_data,
331 void *lmm, int lmmsize, struct lookup_intent *it,
332 int flags, struct ptlrpc_request **reqp,
333 ldlm_blocking_callback cb_blocking,
334 int extra_lock_flags)
336 struct lmv_obj *obj = NULL, *obj2 = NULL;
337 struct obd_device *obd = exp->exp_obd;
338 struct lu_fid rpid = op_data->fid1;
339 struct lmv_obd *lmv = &obd->u.lmv;
340 struct mdt_body *body = NULL;
341 struct md_op_data *sop_data;
342 struct lmv_stripe_md *mea;
347 OBD_ALLOC_PTR(sop_data);
348 if (sop_data == NULL)
351 /* save op_data fro repeat case */
352 *sop_data = *op_data;
354 if (fid_is_sane(&op_data->fid2)) {
356 * Caller wants to revalidate attrs of obj we have to revalidate
357 * slaves if requested object is split directory.
359 CDEBUG(D_OTHER, "revalidate attrs for "DFID"\n",
360 PFID(&op_data->fid2));
362 rc = lmv_fld_lookup(lmv, &op_data->fid2, &mds);
364 GOTO(out_free_sop_data, rc);
367 * In fact, we do not need this with current intent_lock(), but
368 * it may change some day.
370 obj = lmv_obj_grab(obd, &op_data->fid2);
372 if (!lu_fid_eq(&op_data->fid1, &op_data->fid2)){
373 rpid = obj->lo_inodes[mds].li_fid;
374 rc = lmv_fld_lookup(lmv, &rpid, &mds);
377 GOTO(out_free_sop_data, rc);
384 CDEBUG(D_OTHER, "INTENT getattr for %*s on "DFID"\n",
385 op_data->namelen, op_data->name,
386 PFID(&op_data->fid1));
388 rc = lmv_fld_lookup(lmv, &op_data->fid1, &mds);
390 GOTO(out_free_sop_data, rc);
391 obj = lmv_obj_grab(obd, &op_data->fid1);
392 if (obj && op_data->namelen) {
393 /* directory is already split. calculate mds */
394 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
395 (char *)op_data->name,
398 rpid = obj->lo_inodes[mds].li_fid;
399 rc = lmv_fld_lookup(lmv, &rpid, &mds);
402 GOTO(out_free_sop_data, rc);
406 CDEBUG(D_OTHER, "forward to MDS #"LPU64" (slave "DFID")\n",
411 sop_data->fid1 = rpid;
413 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, sop_data, lmm,
414 lmmsize, it, flags, reqp, cb_blocking,
417 GOTO(out_free_sop_data, rc);
421 * This is split dir. In order to optimize things a bit, we
422 * consider obj valid updating missing parts.
424 * FIXME: do we need to return any lock here? It would be fine
425 * if we don't. This means that nobody should use UPDATE lock to
426 * notify about object * removal.
429 "revalidate slaves for "DFID", rc %d\n",
430 PFID(&op_data->fid2), rc);
432 LASSERT(fid_is_sane(&op_data->fid2));
433 rc = lmv_revalidate_slaves(exp, reqp, &op_data->fid2, it, rc,
434 cb_blocking, extra_lock_flags);
435 GOTO(out_free_sop_data, rc);
439 GOTO(out_free_sop_data, rc);
442 * okay, MDS has returned success. Probably name has been resolved in
445 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags,
446 reqp, cb_blocking, extra_lock_flags);
448 GOTO(out_free_sop_data, rc);
451 * Nothing is found, do not access body->fid1 as it is zero and thus
454 if (it->d.lustre.it_disposition & DISP_LOOKUP_NEG)
455 GOTO(out_free_sop_data, rc = 0);
458 LASSERT((*reqp)->rq_repmsg);
459 body = lustre_msg_buf((*reqp)->rq_repmsg,
460 DLM_REPLY_REC_OFF, sizeof(*body));
461 LASSERT(body != NULL);
463 /* could not find object, FID is not present in response. */
464 if (!(body->valid & OBD_MD_FLID))
465 GOTO(out_free_sop_data, rc = 0);
467 obj2 = lmv_obj_grab(obd, &body->fid1);
469 if (!obj2 && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
470 /* wow! this is split dir, we'd like to handle it. */
471 obj2 = lmv_obj_create(exp, &body->fid1, mea);
473 GOTO(out_free_sop_data, rc = (int)PTR_ERR(obj2));
477 /* this is split dir and we'd want to get attrs */
478 CDEBUG(D_OTHER, "attrs from slaves for "DFID", rc %d\n",
479 PFID(&body->fid1), rc);
481 rc = lmv_revalidate_slaves(exp, reqp, &body->fid1, it, 1,
482 cb_blocking, extra_lock_flags);
488 OBD_FREE_PTR(sop_data);
492 void lmv_update_body(struct mdt_body *body, struct lmv_inode *lino)
495 body->size += lino->li_size;
498 /* this is not used currently */
499 int lmv_lookup_slaves(struct obd_export *exp, struct ptlrpc_request **reqp)
501 struct obd_device *obd = exp->exp_obd;
502 struct lmv_obd *lmv = &obd->u.lmv;
503 struct mdt_body *body = NULL;
504 struct lustre_handle *lockh;
505 struct md_op_data *op_data;
506 struct ldlm_lock *lock;
507 struct mdt_body *body2;
515 /* master is locked. we'd like to take locks on slaves and update
516 * attributes to be returned from the slaves it's important that lookup
517 * is called in two cases:
519 * - for first time (dcache has no such a resolving yet). -
520 * ->d_revalidate() returned false.
522 * last case possible only if all the objs (master and all slaves aren't
525 body = lustre_msg_buf((*reqp)->rq_repmsg,
526 DLM_REPLY_REC_OFF, sizeof(*body));
527 LASSERT(body != NULL);
528 LASSERT((body->valid & OBD_MD_FLID) != 0);
530 obj = lmv_obj_grab(obd, &body->fid1);
531 LASSERT(obj != NULL);
533 CDEBUG(D_OTHER, "lookup slaves for "DFID"\n",
536 OBD_ALLOC_PTR(op_data);
542 for (i = 0; i < obj->lo_objcount; i++) {
543 struct lu_fid fid = obj->lo_inodes[i].li_fid;
544 struct ptlrpc_request *req = NULL;
545 struct obd_export *tgt_exp;
546 struct lookup_intent it;
548 if (lu_fid_eq(&fid, &obj->lo_fid))
549 /* skip master obj */
552 CDEBUG(D_OTHER, "lookup slave "DFID"\n", PFID(&fid));
555 memset(&it, 0, sizeof(it));
556 it.it_op = IT_GETATTR;
558 memset(op_data, 0, sizeof(*op_data));
562 tgt_exp = lmv_get_export(lmv, &fid);
564 GOTO(cleanup, rc = PTR_ERR(tgt_exp));
566 rc = md_intent_lock(tgt_exp, op_data, NULL, 0, &it, 0, &req,
567 lmv_blocking_ast, 0);
569 lockh = (struct lustre_handle *)&it.d.lustre.it_lock_handle;
570 if (rc > 0 && req == NULL) {
571 /* nice, this slave is valid */
572 LASSERT(req == NULL);
573 CDEBUG(D_OTHER, "cached\n");
578 /* error during lookup */
581 lock = ldlm_handle2lock(lockh);
584 lock->l_ast_data = lmv_obj_get(obj);
586 body2 = lustre_msg_buf(req->rq_repmsg,
587 DLM_REPLY_REC_OFF, sizeof(*body2));
590 obj->lo_inodes[i].li_size = body2->size;
592 CDEBUG(D_OTHER, "fresh: %lu\n",
593 (unsigned long)obj->lo_inodes[i].li_size);
598 ptlrpc_req_finished(req);
600 lmv_update_body(body, obj->lo_inodes + i);
602 if (it.d.lustre.it_lock_mode)
603 ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
608 OBD_FREE_PTR(op_data);
614 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
615 void *lmm, int lmmsize, struct lookup_intent *it,
616 int flags, struct ptlrpc_request **reqp,
617 ldlm_blocking_callback cb_blocking,
618 int extra_lock_flags)
620 struct obd_device *obd = exp->exp_obd;
621 struct lu_fid rpid = op_data->fid1;
622 struct lmv_obd *lmv = &obd->u.lmv;
623 struct mdt_body *body = NULL;
624 struct md_op_data *sop_data;
625 struct lmv_stripe_md *mea;
631 OBD_ALLOC_PTR(sop_data);
632 if (sop_data == NULL)
635 /* save op_data fro repeat case */
636 *sop_data = *op_data;
639 * IT_LOOKUP is intended to produce name -> fid resolving (let's call
640 * this lookup below) or to confirm requested resolving is still valid
641 * (let's call this revalidation) fid_is_sane(&sop_data->fid2) specifies
644 if (fid_is_sane(&op_data->fid2)) {
646 * This is revalidate: we have to check is LOOKUP lock still
647 * valid for given fid. Very important part is that we have to
648 * choose right mds because namespace is per mds.
650 rpid = op_data->fid1;
651 obj = lmv_obj_grab(obd, &rpid);
653 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
654 (char *)op_data->name,
656 rpid = obj->lo_inodes[mds].li_fid;
659 rc = lmv_fld_lookup(lmv, &rpid, &mds);
661 GOTO(out_free_sop_data, rc);
663 CDEBUG(D_OTHER, "revalidate lookup for "DFID" to #"LPU64" MDS\n",
664 PFID(&op_data->fid2), mds);
666 rc = lmv_fld_lookup(lmv, &op_data->fid1, &mds);
668 GOTO(out_free_sop_data, rc);
670 LASSERT(++loop <= 2);
673 * This is lookup. During lookup we have to update all the
674 * attributes, because returned values will be put in struct
677 obj = lmv_obj_grab(obd, &op_data->fid1);
679 if (op_data->namelen) {
680 /* directory is already split. calculate mds */
681 mds = raw_name2idx(obj->lo_hashtype,
683 (char *)op_data->name,
685 rpid = obj->lo_inodes[mds].li_fid;
686 rc = lmv_fld_lookup(lmv, &rpid, &mds);
689 GOTO(out_free_sop_data, rc);
694 fid_zero(&op_data->fid2);
697 sop_data->fid1 = rpid;
699 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, sop_data, lmm, lmmsize,
700 it, flags, reqp, cb_blocking, extra_lock_flags);
702 LASSERT(fid_is_sane(&op_data->fid2));
703 GOTO(out_free_sop_data, rc);
707 * Very interesting. it seems object is still valid but for some
708 * reason llite calls lookup, not revalidate.
710 CDEBUG(D_OTHER, "lookup for "DFID" and data should be uptodate\n",
712 LASSERT(*reqp == NULL);
713 GOTO(out_free_sop_data, rc);
716 if (rc == 0 && *reqp == NULL) {
717 /* once again, we're asked for lookup, not revalidate */
718 CDEBUG(D_OTHER, "lookup for "DFID" and data should be uptodate\n",
720 GOTO(out_free_sop_data, rc);
723 if (rc == -ERESTART) {
725 * Directory got split since last update. This shouldn't be
726 * becasue splitting causes lock revocation, so revalidate had
727 * to fail and lookup on dir had to return mea.
729 CWARN("we haven't knew about directory splitting!\n");
730 LASSERT(obj == NULL);
732 obj = lmv_obj_create(exp, &rpid, NULL);
734 RETURN((int)PTR_ERR(obj));
740 GOTO(out_free_sop_data, rc);
743 * Okay, MDS has returned success. Probably name has been resolved in
746 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
747 cb_blocking, extra_lock_flags);
749 if (rc == 0 && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
750 /* wow! this is split dir, we'd like to handle it */
751 body = lustre_msg_buf((*reqp)->rq_repmsg,
752 DLM_REPLY_REC_OFF, sizeof(*body));
753 LASSERT(body != NULL);
754 LASSERT((body->valid & OBD_MD_FLID) != 0);
756 obj = lmv_obj_grab(obd, &body->fid1);
758 obj = lmv_obj_create(exp, &body->fid1, mea);
760 GOTO(out_free_sop_data, rc = (int)PTR_ERR(obj));
767 OBD_FREE_PTR(sop_data);
771 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
772 void *lmm, int lmmsize, struct lookup_intent *it,
773 int flags, struct ptlrpc_request **reqp,
774 ldlm_blocking_callback cb_blocking,
775 int extra_lock_flags)
777 struct obd_device *obd = exp->exp_obd;
782 LASSERT(fid_is_sane(&op_data->fid1));
784 CDEBUG(D_OTHER, "INTENT LOCK '%s' for '%*s' on "DFID"\n",
785 LL_IT2STR(it), op_data->namelen, op_data->name,
786 PFID(&op_data->fid1));
788 rc = lmv_check_connect(obd);
792 if (it->it_op & IT_LOOKUP)
793 rc = lmv_intent_lookup(exp, op_data, lmm, lmmsize, it,
794 flags, reqp, cb_blocking,
796 else if (it->it_op & IT_OPEN)
797 rc = lmv_intent_open(exp, op_data, lmm, lmmsize, it,
798 flags, reqp, cb_blocking,
800 else if (it->it_op & IT_GETATTR)
801 rc = lmv_intent_getattr(exp, op_data,lmm, lmmsize, it,
802 flags, reqp, cb_blocking,
809 int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
810 const struct lu_fid *mid, struct lookup_intent *oit,
811 int master_valid, ldlm_blocking_callback cb_blocking,
812 int extra_lock_flags)
814 struct obd_device *obd = exp->exp_obd;
815 struct ptlrpc_request *mreq = *reqp;
816 struct lmv_obd *lmv = &obd->u.lmv;
817 struct lustre_handle master_lockh;
818 struct obd_export *tgt_exp;
819 struct md_op_data *op_data;
820 struct ldlm_lock *lock;
821 unsigned long size = 0;
822 struct mdt_body *body;
824 int master_lock_mode;
828 OBD_ALLOC_PTR(op_data);
832 /* we have to loop over the subobjects, check validity and update them
833 * from MDSs if needed. it's very useful that we need not to update all
834 * the fields. say, common fields (that are equal on all the subojects
835 * need not to be update, another fields (i_size, for example) are
836 * cached all the time */
837 obj = lmv_obj_grab(obd, mid);
838 LASSERT(obj != NULL);
840 master_lock_mode = 0;
844 for (i = 0; i < obj->lo_objcount; i++) {
845 struct lu_fid fid = obj->lo_inodes[i].li_fid;
846 struct lustre_handle *lockh = NULL;
847 struct ptlrpc_request *req = NULL;
848 ldlm_blocking_callback cb;
849 struct lookup_intent it;
852 CDEBUG(D_OTHER, "revalidate subobj "DFID"\n",
855 memset(op_data, 0, sizeof(*op_data));
856 memset(&it, 0, sizeof(it));
857 it.it_op = IT_GETATTR;
859 cb = lmv_blocking_ast;
861 if (lu_fid_eq(&fid, &obj->lo_fid)) {
863 /* lmv_intent_getattr() already checked
864 * validness and took the lock */
866 /* it even got the reply refresh attrs
868 body = lustre_msg_buf(mreq->rq_repmsg,
871 LASSERT(body != NULL);
874 /* take already cached attrs into account */
876 "master is locked and cached\n");
887 tgt_exp = lmv_get_export(lmv, &fid);
889 GOTO(out_free_op_data, rc = PTR_ERR(tgt_exp));
891 rc = md_intent_lock(tgt_exp, op_data, NULL, 0, &it, 0, &req, cb,
894 lockh = (struct lustre_handle *) &it.d.lustre.it_lock_handle;
895 if (rc > 0 && req == NULL) {
896 /* nice, this slave is valid */
897 LASSERT(req == NULL);
898 CDEBUG(D_OTHER, "cached\n");
903 /* error during revalidation */
907 LASSERT(master_valid == 0);
908 /* save lock on master to be returned to the caller */
909 CDEBUG(D_OTHER, "no lock on master yet\n");
910 memcpy(&master_lockh, lockh, sizeof(master_lockh));
911 master_lock_mode = it.d.lustre.it_lock_mode;
912 it.d.lustre.it_lock_mode = 0;
914 /* this is slave. we want to control it */
915 lock = ldlm_handle2lock(lockh);
917 lock->l_ast_data = lmv_obj_get(obj);
922 /* this is first reply, we'll use it to return updated
923 * data back to the caller */
925 ptlrpc_request_addref(req);
930 body = lustre_msg_buf(req->rq_repmsg,
931 DLM_REPLY_REC_OFF, sizeof(*body));
935 obj->lo_inodes[i].li_size = (MAX_HASH_SIZE/obj->lo_objcount) *
938 CDEBUG(D_OTHER, "fresh: %lu\n",
939 (unsigned long)obj->lo_inodes[i].li_size);
942 ptlrpc_req_finished(req);
944 size += obj->lo_inodes[i].li_size;
946 if (it.d.lustre.it_lock_mode)
947 ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
951 /* some attrs got refreshed, we have reply and it's time to put
952 * fresh attrs to it */
953 CDEBUG(D_OTHER, "return refreshed attrs: size = %lu\n",
954 (unsigned long)size);
956 body = lustre_msg_buf((*reqp)->rq_repmsg,
957 DLM_REPLY_REC_OFF, sizeof(*body));
964 * very important to maintain mds num the same because
965 * of revalidation. mreq == NULL means that caller has
966 * no reply and the only attr we can return is size.
968 body->valid = OBD_MD_FLSIZE;
971 rc = lmv_fld_lookup(lmv, &obj->lo_fid, &body->mds);
976 if (master_valid == 0) {
977 memcpy(&oit->d.lustre.it_lock_handle,
978 &master_lockh, sizeof(master_lockh));
979 oit->d.lustre.it_lock_mode = master_lock_mode;
983 /* it seems all the attrs are fresh and we did no request */
984 CDEBUG(D_OTHER, "all the attrs were fresh\n");
985 if (master_valid == 0)
986 oit->d.lustre.it_lock_mode = master_lock_mode;
995 OBD_FREE_PTR(op_data);