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);
53 it->d.lustre.it_lock_mode = 0;
57 int lmv_intent_remote(struct obd_export *exp, void *lmm,
58 int lmmsize, struct lookup_intent *it,
59 int flags, struct ptlrpc_request **reqp,
60 ldlm_blocking_callback cb_blocking,
63 struct obd_device *obd = exp->exp_obd;
64 struct lmv_obd *lmv = &obd->u.lmv;
65 struct ptlrpc_request *req = NULL;
66 struct mdt_body *body = NULL;
67 struct lustre_handle plock;
68 struct md_op_data *op_data;
69 struct obd_export *tgt_exp;
73 body = lustre_msg_buf((*reqp)->rq_repmsg,
74 DLM_REPLY_REC_OFF, sizeof(*body));
75 LASSERT(body != NULL);
77 if (!(body->valid & OBD_MD_MDS))
80 tgt_exp = lmv_get_export(lmv, &body->fid1);
82 RETURN(PTR_ERR(tgt_exp));
85 * oh, MDS reports that this is remote inode case i.e. we have to ask
86 * for real attrs on another MDS.
88 if (it->it_op & IT_LOOKUP) {
90 * unfortunately, we have to lie to MDC/MDS to retrieve
91 * attributes llite needs.
93 it->it_op = IT_GETATTR;
96 /* we got LOOKUP lock, but we really need attrs */
97 pmode = it->d.lustre.it_lock_mode;
99 plock.cookie = it->d.lustre.it_lock_handle;
100 it->d.lustre.it_lock_mode = 0;
101 it->d.lustre.it_data = 0;
104 LASSERT(fid_is_sane(&body->fid1));
106 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
108 OBD_ALLOC_PTR(op_data);
110 GOTO(out, rc = -ENOMEM);
112 op_data->fid1 = body->fid1;
114 rc = md_intent_lock(tgt_exp, op_data, lmm, lmmsize, it, flags,
115 &req, cb_blocking, extra_lock_flags);
118 * llite needs LOOKUP lock to track dentry revocation in order to
119 * maintain dcache consistency. Thus drop UPDATE lock here and put
123 lmv_drop_intent_lock(it);
124 it->d.lustre.it_lock_handle = plock.cookie;
125 it->d.lustre.it_lock_mode = pmode;
128 OBD_FREE_PTR(op_data);
132 ldlm_lock_decref(&plock, pmode);
134 ptlrpc_req_finished(*reqp);
139 int lmv_alloc_fid_for_split(struct obd_device *obd, struct lu_fid *pid,
140 struct md_op_data *op, struct lu_fid *fid)
142 struct lmv_obd *lmv = &obd->u.lmv;
149 obj = lmv_obj_grab(obd, pid);
152 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
153 (char *)op->name, op->namelen);
154 rpid = &obj->lo_inodes[mds].li_fid;
155 rc = lmv_fld_lookup(lmv, rpid, &mds);
159 rc = obd_fid_alloc(lmv->tgts[mds].ltd_exp, fid, NULL);
163 LASSERT(fid_is_sane(fid));
164 rc = fld_client_create(&lmv->lmv_fld,
165 fid_seq(fid), mds, NULL);
167 CERROR("can't create fld rc%d\n", rc);
171 CDEBUG(D_INFO, "Allocate new fid"DFID"for split obj\n",PFID(fid));
178 * IT_OPEN is intended to open (and create, possible) an object. Parent (pid)
181 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
182 void *lmm, int lmmsize, struct lookup_intent *it,
183 int flags, struct ptlrpc_request **reqp,
184 ldlm_blocking_callback cb_blocking,
185 int extra_lock_flags)
187 struct obd_device *obd = exp->exp_obd;
188 struct lu_fid rpid = op_data->fid1;
189 struct lmv_obd *lmv = &obd->u.lmv;
190 struct mdt_body *body = NULL;
191 struct md_op_data *sop_data;
192 struct lmv_stripe_md *mea;
198 OBD_ALLOC_PTR(sop_data);
199 if (sop_data == NULL)
202 /* save op_data fro repeat case */
203 *sop_data = *op_data;
206 LASSERT(++loop <= 2);
207 rc = lmv_fld_lookup(lmv, &rpid, &mds);
209 GOTO(out_free_sop_data, rc);
211 obj = lmv_obj_grab(obd, &rpid);
214 * Directory is already split, so we have to forward request to
217 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
218 (char *)op_data->name, op_data->namelen);
220 rpid = obj->lo_inodes[mds].li_fid;
221 rc = lmv_fld_lookup(lmv, &rpid, &mds);
224 GOTO(out_free_sop_data, rc);
226 CDEBUG(D_OTHER, "forward to MDS #"LPU64" ("DFID")\n",
230 sop_data->fid1 = rpid;
232 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, sop_data,
233 lmm, lmmsize, it, flags, reqp,
234 cb_blocking, extra_lock_flags);
236 if (rc == -ERESTART) {
238 * Directory got split. Time to update local object and repeat
239 * the request with proper MDS.
241 LASSERT(lu_fid_eq(&op_data->fid1, &rpid));
242 rc = lmv_handle_split(exp, &rpid);
244 ptlrpc_req_finished(*reqp);
247 * Zero out reqp to not confuse client. In many cases it
248 * tries to free req even if error is returned.
250 it->d.lustre.it_data = 0;
253 /* We shoudld reallocate the FID for the object */
254 rc = lmv_alloc_fid_for_split(obd, &rpid, op_data,
257 GOTO(out_free_sop_data, rc);
263 GOTO(out_free_sop_data, rc);
266 * Okay, MDS has returned success. Probably name has been resolved in
269 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
270 cb_blocking, extra_lock_flags);
275 * This is possible, that some userspace application will try to
276 * open file as directory and we will have -ENOTDIR here. As
277 * this is "usual" situation, we should not print error here,
280 CDEBUG(D_OTHER, "can't handle remote %s: dir "DFID"("DFID"):"
281 "%*s: %d\n", LL_IT2STR(it), PFID(&op_data->fid2),
282 PFID(&rpid), op_data->namelen, op_data->name, rc);
283 GOTO(out_free_sop_data, rc);
287 * nothing is found, do not access body->fid1 as it is zero and thus
290 if ((it->d.lustre.it_disposition & DISP_LOOKUP_NEG) &&
291 !(it->d.lustre.it_disposition & DISP_OPEN_CREATE) &&
292 !(it->d.lustre.it_disposition & DISP_OPEN_OPEN))
293 GOTO(out_free_sop_data, rc = 0);
295 /* caller may use attrs MDS returns on IT_OPEN lock request so, we have
296 * to update them for split dir */
297 body = lustre_msg_buf((*reqp)->rq_repmsg,
298 DLM_REPLY_REC_OFF, sizeof(*body));
299 LASSERT(body != NULL);
301 /* could not find object, FID is not present in response. */
302 if (!(body->valid & OBD_MD_FLID))
303 GOTO(out_free_sop_data, rc = 0);
305 obj = lmv_obj_grab(obd, &body->fid1);
306 if (!obj && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
308 /* FIXME: capability for remote! */
309 /* wow! this is split dir, we'd like to handle it */
310 obj = lmv_obj_create(exp, &body->fid1, mea);
312 GOTO(out_free_sop_data, rc = (int)PTR_ERR(obj));
316 /* This is split dir and we'd want to get attrs. */
317 CDEBUG(D_OTHER, "attrs from slaves for "DFID"\n",
320 rc = lmv_revalidate_slaves(exp, reqp, &body->fid1, it, 1,
321 cb_blocking, extra_lock_flags);
322 } else if (S_ISDIR(body->mode)) {
323 CDEBUG(D_OTHER, "object "DFID" has not lmv obj?\n",
332 OBD_FREE_PTR(sop_data);
336 int lmv_intent_getattr(struct obd_export *exp, struct md_op_data *op_data,
337 void *lmm, int lmmsize, struct lookup_intent *it,
338 int flags, struct ptlrpc_request **reqp,
339 ldlm_blocking_callback cb_blocking,
340 int extra_lock_flags)
342 struct lmv_obj *obj = NULL, *obj2 = NULL;
343 struct obd_device *obd = exp->exp_obd;
344 struct lu_fid rpid = op_data->fid1;
345 struct lmv_obd *lmv = &obd->u.lmv;
346 struct mdt_body *body = NULL;
347 struct md_op_data *sop_data;
348 struct lmv_stripe_md *mea;
353 OBD_ALLOC_PTR(sop_data);
354 if (sop_data == NULL)
357 /* save op_data fro repeat case */
358 *sop_data = *op_data;
360 if (fid_is_sane(&op_data->fid2)) {
362 * Caller wants to revalidate attrs of obj we have to revalidate
363 * slaves if requested object is split directory.
365 CDEBUG(D_OTHER, "revalidate attrs for "DFID"\n",
366 PFID(&op_data->fid2));
368 rc = lmv_fld_lookup(lmv, &op_data->fid2, &mds);
370 GOTO(out_free_sop_data, rc);
373 * In fact, we do not need this with current intent_lock(), but
374 * it may change some day.
376 obj = lmv_obj_grab(obd, &op_data->fid2);
378 if (!lu_fid_eq(&op_data->fid1, &op_data->fid2)){
379 rpid = obj->lo_inodes[mds].li_fid;
380 rc = lmv_fld_lookup(lmv, &rpid, &mds);
383 GOTO(out_free_sop_data, rc);
390 CDEBUG(D_OTHER, "INTENT getattr for %*s on "DFID"\n",
391 op_data->namelen, op_data->name,
392 PFID(&op_data->fid1));
394 rc = lmv_fld_lookup(lmv, &op_data->fid1, &mds);
396 GOTO(out_free_sop_data, rc);
397 obj = lmv_obj_grab(obd, &op_data->fid1);
398 if (obj && op_data->namelen) {
399 /* directory is already split. calculate mds */
400 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
401 (char *)op_data->name,
404 rpid = obj->lo_inodes[mds].li_fid;
405 rc = lmv_fld_lookup(lmv, &rpid, &mds);
408 GOTO(out_free_sop_data, rc);
412 CDEBUG(D_OTHER, "forward to MDS #"LPU64" (slave "DFID")\n",
417 sop_data->fid1 = rpid;
419 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, sop_data, lmm,
420 lmmsize, it, flags, reqp, cb_blocking,
423 GOTO(out_free_sop_data, rc);
427 * This is split dir. In order to optimize things a bit, we
428 * consider obj valid updating missing parts.
430 * FIXME: do we need to return any lock here? It would be fine
431 * if we don't. This means that nobody should use UPDATE lock to
432 * notify about object * removal.
435 "revalidate slaves for "DFID", rc %d\n",
436 PFID(&op_data->fid2), rc);
438 LASSERT(fid_is_sane(&op_data->fid2));
439 rc = lmv_revalidate_slaves(exp, reqp, &op_data->fid2, it, rc,
440 cb_blocking, extra_lock_flags);
441 GOTO(out_free_sop_data, rc);
445 GOTO(out_free_sop_data, rc);
448 * okay, MDS has returned success. Probably name has been resolved in
451 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags,
452 reqp, cb_blocking, extra_lock_flags);
454 GOTO(out_free_sop_data, rc);
457 * Nothing is found, do not access body->fid1 as it is zero and thus
460 if (it->d.lustre.it_disposition & DISP_LOOKUP_NEG)
461 GOTO(out_free_sop_data, rc = 0);
464 LASSERT((*reqp)->rq_repmsg);
465 body = lustre_msg_buf((*reqp)->rq_repmsg,
466 DLM_REPLY_REC_OFF, sizeof(*body));
467 LASSERT(body != NULL);
469 /* could not find object, FID is not present in response. */
470 if (!(body->valid & OBD_MD_FLID))
471 GOTO(out_free_sop_data, rc = 0);
473 obj2 = lmv_obj_grab(obd, &body->fid1);
475 if (!obj2 && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
477 /* FIXME remote capability! */
478 /* wow! this is split dir, we'd like to handle it. */
479 obj2 = lmv_obj_create(exp, &body->fid1, mea);
481 GOTO(out_free_sop_data, rc = (int)PTR_ERR(obj2));
485 /* this is split dir and we'd want to get attrs */
486 CDEBUG(D_OTHER, "attrs from slaves for "DFID", rc %d\n",
487 PFID(&body->fid1), rc);
489 rc = lmv_revalidate_slaves(exp, reqp, &body->fid1, it, 1,
490 cb_blocking, extra_lock_flags);
496 OBD_FREE_PTR(sop_data);
500 void lmv_update_body(struct mdt_body *body, struct lmv_inode *lino)
503 body->size += lino->li_size;
506 /* this is not used currently */
507 int lmv_lookup_slaves(struct obd_export *exp, struct ptlrpc_request **reqp)
509 struct obd_device *obd = exp->exp_obd;
510 struct lmv_obd *lmv = &obd->u.lmv;
511 struct mdt_body *body = NULL;
512 struct lustre_handle *lockh;
513 struct md_op_data *op_data;
514 struct ldlm_lock *lock;
515 struct mdt_body *body2;
523 /* master is locked. we'd like to take locks on slaves and update
524 * attributes to be returned from the slaves it's important that lookup
525 * is called in two cases:
527 * - for first time (dcache has no such a resolving yet). -
528 * ->d_revalidate() returned false.
530 * last case possible only if all the objs (master and all slaves aren't
533 body = lustre_msg_buf((*reqp)->rq_repmsg,
534 DLM_REPLY_REC_OFF, sizeof(*body));
535 LASSERT(body != NULL);
536 LASSERT((body->valid & OBD_MD_FLID) != 0);
538 obj = lmv_obj_grab(obd, &body->fid1);
539 LASSERT(obj != NULL);
541 CDEBUG(D_OTHER, "lookup slaves for "DFID"\n",
544 OBD_ALLOC_PTR(op_data);
550 for (i = 0; i < obj->lo_objcount; i++) {
551 struct lu_fid fid = obj->lo_inodes[i].li_fid;
552 struct ptlrpc_request *req = NULL;
553 struct obd_export *tgt_exp;
554 struct lookup_intent it;
556 if (lu_fid_eq(&fid, &obj->lo_fid))
557 /* skip master obj */
560 CDEBUG(D_OTHER, "lookup slave "DFID"\n", PFID(&fid));
563 memset(&it, 0, sizeof(it));
564 it.it_op = IT_GETATTR;
566 memset(op_data, 0, sizeof(*op_data));
570 tgt_exp = lmv_get_export(lmv, &fid);
572 GOTO(cleanup, rc = PTR_ERR(tgt_exp));
574 rc = md_intent_lock(tgt_exp, op_data, NULL, 0, &it, 0, &req,
575 lmv_blocking_ast, 0);
577 lockh = (struct lustre_handle *)&it.d.lustre.it_lock_handle;
578 if (rc > 0 && req == NULL) {
579 /* nice, this slave is valid */
580 LASSERT(req == NULL);
581 CDEBUG(D_OTHER, "cached\n");
586 /* error during lookup */
589 lock = ldlm_handle2lock(lockh);
592 lock->l_ast_data = lmv_obj_get(obj);
594 body2 = lustre_msg_buf(req->rq_repmsg,
595 DLM_REPLY_REC_OFF, sizeof(*body2));
598 obj->lo_inodes[i].li_size = body2->size;
600 CDEBUG(D_OTHER, "fresh: %lu\n",
601 (unsigned long)obj->lo_inodes[i].li_size);
606 ptlrpc_req_finished(req);
608 lmv_update_body(body, obj->lo_inodes + i);
610 if (it.d.lustre.it_lock_mode) {
611 ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
612 it.d.lustre.it_lock_mode = 0;
618 OBD_FREE_PTR(op_data);
624 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
625 void *lmm, int lmmsize, struct lookup_intent *it,
626 int flags, struct ptlrpc_request **reqp,
627 ldlm_blocking_callback cb_blocking,
628 int extra_lock_flags)
630 struct obd_device *obd = exp->exp_obd;
631 struct lu_fid rpid = op_data->fid1;
632 struct lmv_obd *lmv = &obd->u.lmv;
633 struct mdt_body *body = NULL;
634 struct md_op_data *sop_data;
635 struct lmv_stripe_md *mea;
641 OBD_ALLOC_PTR(sop_data);
642 if (sop_data == NULL)
645 /* save op_data fro repeat case */
646 *sop_data = *op_data;
649 * IT_LOOKUP is intended to produce name -> fid resolving (let's call
650 * this lookup below) or to confirm requested resolving is still valid
651 * (let's call this revalidation) fid_is_sane(&sop_data->fid2) specifies
654 if (fid_is_sane(&op_data->fid2)) {
656 * This is revalidate: we have to check is LOOKUP lock still
657 * valid for given fid. Very important part is that we have to
658 * choose right mds because namespace is per mds.
660 rpid = op_data->fid1;
661 obj = lmv_obj_grab(obd, &rpid);
663 mds = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
664 (char *)op_data->name,
666 rpid = obj->lo_inodes[mds].li_fid;
669 rc = lmv_fld_lookup(lmv, &rpid, &mds);
671 GOTO(out_free_sop_data, rc);
673 CDEBUG(D_OTHER, "revalidate lookup for "DFID" to #"LPU64" MDS\n",
674 PFID(&op_data->fid2), mds);
676 rc = lmv_fld_lookup(lmv, &op_data->fid1, &mds);
678 GOTO(out_free_sop_data, rc);
680 LASSERT(++loop <= 2);
683 * This is lookup. During lookup we have to update all the
684 * attributes, because returned values will be put in struct
687 obj = lmv_obj_grab(obd, &op_data->fid1);
689 if (op_data->namelen) {
690 /* directory is already split. calculate mds */
691 mds = raw_name2idx(obj->lo_hashtype,
693 (char *)op_data->name,
695 rpid = obj->lo_inodes[mds].li_fid;
696 rc = lmv_fld_lookup(lmv, &rpid, &mds);
699 GOTO(out_free_sop_data, rc);
704 fid_zero(&op_data->fid2);
707 sop_data->fid1 = rpid;
709 rc = md_intent_lock(lmv->tgts[mds].ltd_exp, sop_data, lmm, lmmsize,
710 it, flags, reqp, cb_blocking, extra_lock_flags);
712 LASSERT(fid_is_sane(&op_data->fid2));
713 GOTO(out_free_sop_data, rc);
717 * Very interesting. it seems object is still valid but for some
718 * reason llite calls lookup, not revalidate.
720 CDEBUG(D_OTHER, "lookup for "DFID" and data should be uptodate\n",
722 LASSERT(*reqp == NULL);
723 GOTO(out_free_sop_data, rc);
726 if (rc == 0 && *reqp == NULL) {
727 /* once again, we're asked for lookup, not revalidate */
728 CDEBUG(D_OTHER, "lookup for "DFID" and data should be uptodate\n",
730 GOTO(out_free_sop_data, rc);
733 if (rc == -ERESTART) {
735 * Directory got split since last update. This shouldn't be
736 * becasue splitting causes lock revocation, so revalidate had
737 * to fail and lookup on dir had to return mea.
739 CWARN("we haven't knew about directory splitting!\n");
740 LASSERT(obj == NULL);
742 obj = lmv_obj_create(exp, &rpid, NULL);
744 RETURN((int)PTR_ERR(obj));
750 GOTO(out_free_sop_data, rc);
753 * Okay, MDS has returned success. Probably name has been resolved in
756 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
757 cb_blocking, extra_lock_flags);
759 if (rc == 0 && (mea = lmv_get_mea(*reqp, DLM_REPLY_REC_OFF))) {
760 /* wow! this is split dir, we'd like to handle it */
761 body = lustre_msg_buf((*reqp)->rq_repmsg,
762 DLM_REPLY_REC_OFF, sizeof(*body));
763 LASSERT(body != NULL);
764 LASSERT((body->valid & OBD_MD_FLID) != 0);
766 body = lustre_msg_buf((*reqp)->rq_repmsg,
767 DLM_REPLY_REC_OFF, sizeof(*body));
768 LASSERT(body != NULL);
769 LASSERT((body->valid & OBD_MD_FLID) != 0);
771 obj = lmv_obj_grab(obd, &body->fid1);
773 /* FIXME: remote capability */
774 obj = lmv_obj_create(exp, &body->fid1, mea);
776 GOTO(out_free_sop_data, rc = (int)PTR_ERR(obj));
783 OBD_FREE_PTR(sop_data);
787 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
788 void *lmm, int lmmsize, struct lookup_intent *it,
789 int flags, struct ptlrpc_request **reqp,
790 ldlm_blocking_callback cb_blocking,
791 int extra_lock_flags)
793 struct obd_device *obd = exp->exp_obd;
798 LASSERT(fid_is_sane(&op_data->fid1));
800 CDEBUG(D_OTHER, "INTENT LOCK '%s' for '%*s' on "DFID"\n",
801 LL_IT2STR(it), op_data->namelen, op_data->name,
802 PFID(&op_data->fid1));
804 rc = lmv_check_connect(obd);
808 if (it->it_op & IT_LOOKUP)
809 rc = lmv_intent_lookup(exp, op_data, lmm, lmmsize, it,
810 flags, reqp, cb_blocking,
812 else if (it->it_op & IT_OPEN)
813 rc = lmv_intent_open(exp, op_data, lmm, lmmsize, it,
814 flags, reqp, cb_blocking,
816 else if (it->it_op & IT_GETATTR)
817 rc = lmv_intent_getattr(exp, op_data,lmm, lmmsize, it,
818 flags, reqp, cb_blocking,
825 int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
826 const struct lu_fid *mid, struct lookup_intent *oit,
827 int master_valid, ldlm_blocking_callback cb_blocking,
828 int extra_lock_flags)
830 struct obd_device *obd = exp->exp_obd;
831 struct ptlrpc_request *mreq = *reqp;
832 struct lmv_obd *lmv = &obd->u.lmv;
833 struct lustre_handle master_lockh;
834 struct obd_export *tgt_exp;
835 struct md_op_data *op_data;
836 struct ldlm_lock *lock;
837 unsigned long size = 0;
838 struct mdt_body *body;
840 int master_lock_mode;
844 OBD_ALLOC_PTR(op_data);
849 * We have to loop over the subobjects, check validity and update them
850 * from MDSs if needed. it's very useful that we need not to update all
851 * the fields. say, common fields (that are equal on all the subojects
852 * need not to be update, another fields (i_size, for example) are
853 * cached all the time.
855 obj = lmv_obj_grab(obd, mid);
856 LASSERT(obj != NULL);
858 master_lock_mode = 0;
862 for (i = 0; i < obj->lo_objcount; i++) {
863 struct lu_fid fid = obj->lo_inodes[i].li_fid;
864 struct lustre_handle *lockh = NULL;
865 struct ptlrpc_request *req = NULL;
866 ldlm_blocking_callback cb;
867 struct lookup_intent it;
870 CDEBUG(D_OTHER, "revalidate subobj "DFID"\n",
873 memset(op_data, 0, sizeof(*op_data));
874 memset(&it, 0, sizeof(it));
875 it.it_op = IT_GETATTR;
877 cb = lmv_blocking_ast;
879 if (lu_fid_eq(&fid, &obj->lo_fid)) {
881 /* lmv_intent_getattr() already checked
882 * validness and took the lock */
884 /* it even got the reply refresh attrs
886 body = lustre_msg_buf(mreq->rq_repmsg,
889 LASSERT(body != NULL);
892 /* take already cached attrs into account */
894 "master is locked and cached\n");
905 tgt_exp = lmv_get_export(lmv, &fid);
907 GOTO(out_free_op_data, rc = PTR_ERR(tgt_exp));
909 rc = md_intent_lock(tgt_exp, op_data, NULL, 0, &it, 0, &req, cb,
912 lockh = (struct lustre_handle *)&it.d.lustre.it_lock_handle;
913 if (rc > 0 && req == NULL) {
914 /* nice, this slave is valid */
915 LASSERT(req == NULL);
916 CDEBUG(D_OTHER, "cached\n");
924 LASSERT(master_valid == 0);
925 /* save lock on master to be returned to the caller */
926 CDEBUG(D_OTHER, "no lock on master yet\n");
927 memcpy(&master_lockh, lockh, sizeof(master_lockh));
928 master_lock_mode = it.d.lustre.it_lock_mode;
929 it.d.lustre.it_lock_mode = 0;
931 /* this is slave. we want to control it */
932 lock = ldlm_handle2lock(lockh);
934 lock->l_ast_data = lmv_obj_get(obj);
939 /* this is first reply, we'll use it to return updated
940 * data back to the caller */
942 ptlrpc_request_addref(req);
947 body = lustre_msg_buf(req->rq_repmsg,
948 DLM_REPLY_REC_OFF, sizeof(*body));
952 obj->lo_inodes[i].li_size = body->size;
954 CDEBUG(D_OTHER, "fresh: %lu\n",
955 (unsigned long)obj->lo_inodes[i].li_size);
958 ptlrpc_req_finished(req);
960 size += obj->lo_inodes[i].li_size;
962 if (it.d.lustre.it_lock_mode) {
963 ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
964 it.d.lustre.it_lock_mode = 0;
969 /* some attrs got refreshed, we have reply and it's time to put
970 * fresh attrs to it */
971 CDEBUG(D_OTHER, "return refreshed attrs: size = %lu\n",
972 (unsigned long)size);
974 body = lustre_msg_buf((*reqp)->rq_repmsg,
975 DLM_REPLY_REC_OFF, sizeof(*body));
982 * Very important to maintain mds num the same because
983 * of revalidation. mreq == NULL means that caller has
984 * no reply and the only attr we can return is size.
986 body->valid = OBD_MD_FLSIZE;
989 rc = lmv_fld_lookup(lmv, &obj->lo_fid, &body->mds);
994 if (master_valid == 0) {
995 memcpy(&oit->d.lustre.it_lock_handle,
996 &master_lockh, sizeof(master_lockh));
997 oit->d.lustre.it_lock_mode = master_lock_mode;
1001 /* it seems all the attrs are fresh and we did no request */
1002 CDEBUG(D_OTHER, "all the attrs were fresh\n");
1003 if (master_valid == 0)
1004 oit->d.lustre.it_lock_mode = master_lock_mode;
1010 lmv_obj_unlock(obj);
1013 OBD_FREE_PTR(op_data);