Whamcloud - gitweb
- landing of b_fid after merge with b_hd_cleanup_merge.
[fs/lustre-release.git] / lustre / lmv / lmv_intent.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_LMV
26 #ifdef __KERNEL__
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 #else
35 #include <liblustre.h>
36 #endif
37
38 #include <linux/obd_support.h>
39 #include <linux/lustre_lib.h>
40 #include <linux/lustre_net.h>
41 #include <linux/lustre_idl.h>
42 #include <linux/lustre_dlm.h>
43 #include <linux/lustre_mds.h>
44 #include <linux/obd_class.h>
45 #include <linux/obd_ost.h>
46 #include <linux/lprocfs_status.h>
47 #include <linux/lustre_fsfilt.h>
48 #include <linux/obd_lmv.h>
49 #include "lmv_internal.h"
50
51
52 static inline void lmv_drop_intent_lock(struct lookup_intent *it)
53 {
54         if (it->d.lustre.it_lock_mode != 0)
55                 ldlm_lock_decref((void *)&it->d.lustre.it_lock_handle,
56                                  it->d.lustre.it_lock_mode);
57 }
58
59 int lmv_handle_remote_inode(struct obd_export *exp, void *lmm,
60                             int lmmsize, struct lookup_intent *it,
61                             int flags, struct ptlrpc_request **reqp,
62                             ldlm_blocking_callback cb_blocking)
63 {
64         struct obd_device *obd = exp->exp_obd;
65         struct lmv_obd *lmv = &obd->u.lmv;
66         struct mds_body *body = NULL;
67         int rc = 0;
68         ENTRY;
69
70         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
71         LASSERT(body != NULL);
72
73         if (body->valid & OBD_MD_MDS) {
74                 /*
75                  * oh, MDS reports that this is remote inode case i.e. we have
76                  * to ask for real attrs on another MDS.
77                  */
78                 struct ptlrpc_request *req = NULL;
79                 struct lustre_handle plock;
80                 struct lustre_id nid;
81                 int pmode;
82
83                 if (it->it_op == IT_LOOKUP) {
84                         /*
85                          * unfortunately, we have to lie to MDC/MDS to retrieve
86                          * attributes llite needs.
87                          */
88                         it->it_op = IT_GETATTR;
89                 }
90
91                 /* we got LOOKUP lock, but we really need attrs */
92                 pmode = it->d.lustre.it_lock_mode;
93                 if (pmode) {
94                         memcpy(&plock, &it->d.lustre.it_lock_handle,
95                                sizeof(plock));
96                         it->d.lustre.it_lock_mode = 0;
97                 }
98
99                 nid = body->id1;
100                 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
101                 rc = md_intent_lock(lmv->tgts[id_group(&nid)].ltd_exp, &nid,
102                                     NULL, 0, lmm, lmmsize, NULL, it, flags,
103                                     &req, cb_blocking);
104
105                 /*
106                  * llite needs LOOKUP lock to track dentry revocation in order
107                  * to maintain dcache consistency. Thus drop UPDATE lock here
108                  * and put LOOKUP in request.
109                  */
110                 if (rc == 0) {
111                         lmv_drop_intent_lock(it);
112                         memcpy(&it->d.lustre.it_lock_handle, &plock,
113                                sizeof(plock));
114                         it->d.lustre.it_lock_mode = pmode;
115                         
116                 } else if (pmode)
117                         ldlm_lock_decref(&plock, pmode);
118
119                 ptlrpc_req_finished(*reqp);
120                 *reqp = req;
121         }
122         RETURN(rc);
123 }
124
125 int lmv_intent_open(struct obd_export *exp, struct lustre_id *pid,
126                     const char *name, int len, void *lmm, int lmmsize,
127                     struct lustre_id *cid, struct lookup_intent *it,
128                     int flags, struct ptlrpc_request **reqp,
129                     ldlm_blocking_callback cb_blocking)
130 {
131         struct obd_device *obd = exp->exp_obd;
132         struct lmv_obd *lmv = &obd->u.lmv;
133         struct mds_body *body = NULL;
134         struct lustre_id rpid = *pid;
135         struct lmv_obj *obj;
136         struct mea *mea;
137         int rc, mds, loop = 0;
138         ENTRY;
139
140         /* IT_OPEN is intended to open (and create, possible) an object. Parent
141          * (pid) may be splitted dir */
142
143 repeat:
144         LASSERT(++loop <= 2);
145         mds = id_group(&rpid);
146         obj = lmv_grab_obj(obd, &rpid);
147         if (obj) {
148                 /* directory is already splitted, so we have to forward
149                  * request to the right MDS */
150                 mds = raw_name2idx(obj->hashtype, obj->objcount, 
151                                    (char *)name, len);
152                 
153                 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n",
154                        mds, OLID4(&rpid));
155                 rpid = obj->objs[mds].id;
156                 lmv_put_obj(obj);
157         }
158
159         rc = md_intent_lock(lmv->tgts[id_group(&rpid)].ltd_exp, &rpid, name,
160                             len, lmm, lmmsize, cid, it, flags, reqp,
161                             cb_blocking);
162         if (rc == -ERESTART) {
163                 /* directory got splitted. time to update local object and
164                  * repeat the request with proper MDS */
165                 LASSERT(lmv_id_equal(pid, &rpid));
166                 rc = lmv_get_mea_and_update_object(exp, &rpid);
167                 if (rc == 0) {
168                         ptlrpc_req_finished(*reqp);
169                         goto repeat;
170                 }
171         }
172         if (rc != 0)
173                 RETURN(rc);
174
175         /* okay, MDS has returned success. Probably name has been resolved in
176          * remote inode */
177         rc = lmv_handle_remote_inode(exp, lmm, lmmsize, it,
178                                      flags, reqp, cb_blocking);
179         if (rc != 0) {
180                 LASSERT(rc < 0);
181                 CERROR("can't handle remote %s: dir "DLID4"("DLID4"):"
182                        "%*s: %d\n", LL_IT2STR(it), OLID4(pid), OLID4(&rpid),
183                        len, name, rc);
184                 RETURN(rc);
185         }
186
187         /* caller may use attrs MDS returns on IT_OPEN lock request so, we have
188          * to update them for splitted dir */
189         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
190         LASSERT(body != NULL);
191
192         cid = &body->id1;
193         obj = lmv_grab_obj(obd, cid);
194         if (!obj && (mea = lmv_splitted_dir_body(*reqp, 1))) {
195                 /* wow! this is splitted dir, we'd like to handle it */
196                 obj = lmv_create_obj(exp, &body->id1, mea);
197                 if (IS_ERR(obj))
198                         RETURN(PTR_ERR(obj));
199         }
200
201         if (obj) {
202                 /* this is splitted dir and we'd want to get attrs */
203                 CDEBUG(D_OTHER, "attrs from slaves for "DLID4"\n",
204                        OLID4(cid));
205                 
206                 rc = lmv_revalidate_slaves(exp, reqp, cid, it, 1,
207                                            cb_blocking);
208         } else if (S_ISDIR(body->mode)) {
209                 CDEBUG(D_OTHER, "object "DLID4" has not lmv obj?\n",
210                        OLID4(cid));
211         }
212         
213         if (obj)
214                 lmv_put_obj(obj);
215         
216         RETURN(rc);
217 }
218
219 int lmv_intent_getattr(struct obd_export *exp, struct lustre_id *pid,
220                        const char *name, int len, void *lmm, int lmmsize,
221                        struct lustre_id *cid, struct lookup_intent *it,
222                        int flags, struct ptlrpc_request **reqp,
223                        ldlm_blocking_callback cb_blocking)
224 {
225         struct obd_device *obd = exp->exp_obd;
226         struct lmv_obd *lmv = &obd->u.lmv;
227         struct mds_body *body = NULL;
228         struct lustre_id rpid = *pid;
229         struct lmv_obj *obj, *obj2;
230         struct mea *mea;
231         int rc = 0, mds;
232         ENTRY;
233
234         if (cid) {
235                 /* caller wants to revalidate attrs of obj we have to revalidate
236                  * slaves if requested object is splitted directory */
237                 CDEBUG(D_OTHER, "revalidate attrs for "DLID4"\n", OLID4(cid));
238                 mds = id_group(cid);
239                 obj = lmv_grab_obj(obd, cid);
240                 if (obj) {
241                         /* in fact, we need not this with current intent_lock(),
242                          * but it may change some day */
243                         if (!lmv_id_equal(pid, cid)){
244                                 rpid = obj->objs[mds].id;
245                                 mds = id_group(&rpid);
246                         }
247                         lmv_put_obj(obj);
248                }
249         } else {
250                 CDEBUG(D_OTHER, "INTENT getattr for %*s on "DLID4"\n",
251                        len, name, OLID4(pid));
252                 mds = id_group(pid);
253                 obj = lmv_grab_obj(obd, pid);
254                 if (obj && len) {
255                         /* directory is already splitted. calculate mds */
256                         mds = raw_name2idx(obj->hashtype, obj->objcount, 
257                                            (char *) name, len);
258                         rpid = obj->objs[mds].id;
259                         mds = id_group(&rpid);
260                         lmv_put_obj(obj);
261
262                         CDEBUG(D_OTHER, "forward to MDS #%u (slave "DLID4")\n",
263                                mds, OLID4(&rpid));
264                 }
265         } 
266         rc = md_intent_lock(lmv->tgts[mds].ltd_exp, &rpid, name,
267                             len, lmm, lmmsize, cid, it, flags, reqp,
268                             cb_blocking);
269         if (rc < 0)
270                 RETURN(rc);
271        
272         if (obj && rc > 0) {
273                 /* this is splitted dir. In order to optimize things a
274                  * bit, we consider obj valid updating missing parts.
275
276                  * FIXME: do we need to return any lock here? It would
277                  * be fine if we don't. this means that nobody should
278                  * use UPDATE lock to notify about object * removal */
279                 CDEBUG(D_OTHER,
280                        "revalidate slaves for "DLID4", rc %d\n",
281                        OLID4(cid), rc);
282                 
283                 LASSERT(cid != 0);
284                 rc = lmv_revalidate_slaves(exp, reqp, cid, it, rc,
285                                            cb_blocking);
286                 RETURN(rc);
287         }
288
289         if (*reqp == NULL)
290                 RETURN(rc);
291  
292         /* okay, MDS has returned success. probably name has been
293          * resolved in remote inode */
294         rc = lmv_handle_remote_inode(exp, lmm, lmmsize, it,
295                                      flags, reqp, cb_blocking);
296         if (rc < 0)
297                 RETURN(rc);
298
299         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
300         LASSERT(body != NULL);
301         
302         cid = &body->id1;
303         obj2 = lmv_grab_obj(obd, cid);
304
305         if (!obj2 && (mea = lmv_splitted_dir_body(*reqp, 1))) {
306                 /* wow! this is splitted dir, we'd like to handle it. */
307                 body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
308                 LASSERT(body != NULL);
309
310                 obj2 = lmv_create_obj(exp, &body->id1, mea);
311                 if (IS_ERR(obj2))
312                         RETURN(PTR_ERR(obj2));
313         }
314
315         if (obj2) {
316                 /* this is splitted dir and we'd want to get attrs */
317                 CDEBUG(D_OTHER, "attrs from slaves for "DLID4", rc %d\n",
318                        OLID4(cid), rc);
319                 
320                 rc = lmv_revalidate_slaves(exp, reqp, cid, it, 1, cb_blocking);
321                 lmv_put_obj(obj2);
322         }
323         RETURN(rc);
324 }
325
326 void lmv_update_body_from_obj(struct mds_body *body, struct lmv_inode *obj)
327 {
328         /* update size */
329         body->size += obj->size;
330 }
331
332 int lmv_lookup_slaves(struct obd_export *exp, struct ptlrpc_request **reqp)
333 {
334         struct obd_device *obd = exp->exp_obd;
335         struct lmv_obd *lmv = &obd->u.lmv;
336         struct mds_body *body = NULL;
337         struct lustre_handle *lockh;
338         struct ldlm_lock *lock;
339         struct mds_body *body2;
340         struct lmv_obj *obj;
341         int i, rc = 0;
342         ENTRY;
343
344         LASSERT(reqp);
345         LASSERT(*reqp);
346
347         /* master is locked. we'd like to take locks on slaves and update
348          * attributes to be returned from the slaves it's important that lookup
349          * is called in two cases:
350          
351          *  - for first time (dcache has no such a resolving yet).
352          *  - ->d_revalidate() returned false.
353          
354          * last case possible only if all the objs (master and all slaves aren't
355          * valid */
356
357         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
358         LASSERT(body != NULL);
359
360         obj = lmv_grab_obj(obd, &body->id1);
361         LASSERT(obj != NULL);
362
363         CDEBUG(D_OTHER, "lookup slaves for "DLID4"\n", 
364                OLID4(&body->id1));
365
366         lmv_lock_obj(obj);
367         
368         for (i = 0; i < obj->objcount; i++) {
369                 struct lustre_id id = obj->objs[i].id;
370                 struct ptlrpc_request *req = NULL;
371                 struct lookup_intent it;
372
373                 if (lmv_id_equal(&id, &obj->id))
374                         /* skip master obj */
375                         continue;
376
377                 CDEBUG(D_OTHER, "lookup slave "DLID4"\n", OLID4(&id));
378
379                 /* is obj valid? */
380                 memset(&it, 0, sizeof(it));
381                 it.it_op = IT_GETATTR;
382                 rc = md_intent_lock(lmv->tgts[id_group(&id)].ltd_exp, &id,
383                                     NULL, 0, NULL, 0, &id, &it, 0, &req,
384                                     lmv_dirobj_blocking_ast);
385                 
386                 lockh = (struct lustre_handle *)&it.d.lustre.it_lock_handle;
387                 if (rc > 0 && req == NULL) {
388                         /* nice, this slave is valid */
389                         LASSERT(req == NULL);
390                         CDEBUG(D_OTHER, "cached\n");
391                         goto release_lock;
392                 }
393
394                 if (rc < 0)
395                         /* error during lookup */
396                         GOTO(cleanup, rc);
397                 
398                 lock = ldlm_handle2lock(lockh);
399                 LASSERT(lock);
400
401                 lock->l_ast_data = lmv_get_obj(obj);
402
403                 body2 = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body2));
404                 LASSERT(body2);
405
406                 obj->objs[i].size = body2->size;
407                 
408                 CDEBUG(D_OTHER, "fresh: %lu\n",
409                        (unsigned long)obj->objs[i].size);
410
411                 LDLM_LOCK_PUT(lock);
412
413                 if (req)
414                         ptlrpc_req_finished(req);
415 release_lock:
416                 lmv_update_body_from_obj(body, obj->objs + i);
417
418                 if (it.d.lustre.it_lock_mode)
419                         ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
420         }
421 cleanup:
422         lmv_unlock_obj(obj);
423         lmv_put_obj(obj);
424         RETURN(rc);
425 }
426
427 int lmv_intent_lookup(struct obd_export *exp, struct lustre_id *pid,
428                       const char *name, int len, void *lmm, int lmmsize,
429                       struct lustre_id *cid, struct lookup_intent *it,
430                       int flags, struct ptlrpc_request **reqp,
431                       ldlm_blocking_callback cb_blocking)
432 {
433         struct obd_device *obd = exp->exp_obd;
434         struct lmv_obd *lmv = &obd->u.lmv;
435         struct mds_body *body = NULL;
436         struct lustre_id rpid = *pid;
437         struct lmv_obj *obj;
438         struct mea *mea;
439         int rc, mds, loop = 0;
440         ENTRY;
441
442         /*
443          * IT_LOOKUP is intended to produce name -> id resolving (let's call
444          * this lookup below) or to confirm requested resolving is still valid
445          * (let's call this revalidation) cid != NULL specifies revalidation.
446          */
447
448         if (cid) {
449                 /*
450                  * this is revalidation: we have to check is LOOKUP lock still
451                  * valid for given id. Very important part is that we have to
452                  * choose right mds because namespace is per mds.
453                  */
454                 rpid = *pid;
455                 obj = lmv_grab_obj(obd, pid);
456                 if (obj) {
457                         mds = raw_name2idx(obj->hashtype, obj->objcount,
458                                            (char *)name, len);
459                         rpid = obj->objs[mds].id;
460                         lmv_put_obj(obj);
461                 }
462                 mds = id_group(&rpid);
463
464                 CDEBUG(D_OTHER, "revalidate lookup for "DLID4" to %d MDS\n",
465                        OLID4(cid), mds);
466
467         } else {
468                 mds = id_group(pid);
469 repeat:
470                 LASSERT(++loop <= 2);
471                 /* this is lookup. during lookup we have to update all the 
472                  * attributes, because returned values will be put in struct 
473                  * inode */
474
475                 obj = lmv_grab_obj(obd, pid);
476                 if (obj) {
477                         if (len) {
478                                 /* directory is already splitted. calculate mds */
479                                 mds = raw_name2idx(obj->hashtype, obj->objcount, 
480                                                    (char *)name, len);
481                                 rpid = obj->objs[mds].id;
482                                 mds = id_group(&rpid);
483                         }
484                         lmv_put_obj(obj);
485                 }
486         }
487         rc = md_intent_lock(lmv->tgts[mds].ltd_exp, pid, name,
488                             len, lmm, lmmsize, cid, it, flags, reqp, 
489                             cb_blocking);
490         if (rc > 0) {
491                 LASSERT(cid != 0);
492                 RETURN(rc);
493         }
494         if (rc > 0) {
495                 /* very interesting. it seems object is still valid but for some
496                  * reason llite calls lookup, not revalidate */
497                 CDEBUG(D_OTHER, "lookup for "DLID4" and data should be uptodate\n",
498                       OLID4(&rpid));
499                 LASSERT(*reqp == NULL);
500                 RETURN(rc);
501         }
502
503         if (rc == 0 && *reqp == NULL) {
504                 /* once again, we're asked for lookup, not revalidate */
505                 CDEBUG(D_OTHER, "lookup for "DLID4" and data should be uptodate\n",
506                       OLID4(&rpid));
507                 RETURN(rc);
508         }
509        
510         if (rc == -ERESTART) {
511                 /* directory got splitted since last update. this shouldn't be
512                  * becasue splitting causes lock revocation, so revalidate had
513                  * to fail and lookup on dir had to return mea */
514                 CWARN("we haven't knew about directory splitting!\n");
515                 LASSERT(obj == NULL);
516
517                 obj = lmv_create_obj(exp, &rpid, NULL);
518                 if (IS_ERR(obj))
519                         RETURN(PTR_ERR(obj));
520                 lmv_put_obj(obj);
521                 goto repeat;
522         }
523
524         if (rc < 0)
525                 RETURN(rc);
526
527         /* okay, MDS has returned success. probably name has been resolved in
528          * remote inode */
529         rc = lmv_handle_remote_inode(exp, lmm, lmmsize, it, flags,
530                                      reqp, cb_blocking);
531
532         if (rc == 0 && (mea = lmv_splitted_dir_body(*reqp, 1))) {
533                 /* wow! this is splitted dir, we'd like to handle it */
534                 body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
535                 LASSERT(body != NULL);
536                 
537                 obj = lmv_grab_obj(obd, &body->id1);
538                 if (!obj) {
539                         obj = lmv_create_obj(exp, &body->id1, mea);
540                         if (IS_ERR(obj))
541                                 RETURN(PTR_ERR(obj));
542                 }
543                 lmv_put_obj(obj);
544         }
545
546         RETURN(rc);
547 }
548
549 int lmv_intent_lock(struct obd_export *exp, struct lustre_id *pid,
550                     const char *name, int len, void *lmm, int lmmsize,
551                     struct lustre_id *cid, struct lookup_intent *it,
552                     int flags, struct ptlrpc_request **reqp,
553                     ldlm_blocking_callback cb_blocking)
554 {
555         struct obd_device *obd = exp->exp_obd;
556         int rc = 0;
557         ENTRY;
558
559         LASSERT(it);
560         LASSERT(pid);
561
562         CDEBUG(D_OTHER, "INTENT LOCK '%s' for '%*s' on %lu/%lu -> %lu\n",
563                LL_IT2STR(it), len, name, (unsigned long)id_ino(pid),
564                (unsigned long)id_gen(pid), (unsigned long)id_group(pid));
565
566         rc = lmv_check_connect(obd);
567         if (rc)
568                 RETURN(rc);
569
570         if (it->it_op == IT_LOOKUP)
571                 rc = lmv_intent_lookup(exp, pid, name, len, lmm,
572                                        lmmsize, cid, it, flags, reqp,
573                                        cb_blocking);
574         else if (it->it_op & IT_OPEN)
575                 rc = lmv_intent_open(exp, pid, name, len, lmm,
576                                      lmmsize, cid, it, flags, reqp,
577                                      cb_blocking);
578         else if (it->it_op == IT_GETATTR || it->it_op == IT_CHDIR)
579                 rc = lmv_intent_getattr(exp, pid, name, len, lmm,
580                                         lmmsize, cid, it, flags, reqp,
581                                         cb_blocking);
582         else
583                 LBUG();
584         RETURN(rc);
585 }
586
587 int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
588                           struct lustre_id *mid, struct lookup_intent *oit,
589                           int master_valid, ldlm_blocking_callback cb_blocking)
590 {
591         struct obd_device *obd = exp->exp_obd;
592         struct ptlrpc_request *mreq = *reqp;
593         struct lmv_obd *lmv = &obd->u.lmv;
594         struct lustre_handle master_lockh;
595         struct ldlm_lock *lock;
596         unsigned long size = 0;
597         struct mds_body *body;
598         struct lmv_obj *obj;
599         int master_lock_mode;
600         int i, rc = 0;
601         ENTRY;
602
603         /* we have to loop over the subobjects, check validity and update them
604          * from MDSs if needed. it's very useful that we need not to update all
605          * the fields. say, common fields (that are equal on all the subojects
606          * need not to be update, another fields (i_size, for example) are
607          * cached all the time */
608         obj = lmv_grab_obj(obd, mid);
609         LASSERT(obj != NULL);
610
611         master_lock_mode = 0;
612
613         lmv_lock_obj(obj);
614         
615         for (i = 0; i < obj->objcount; i++) {
616                 struct lustre_id id = obj->objs[i].id;
617                 struct lustre_handle *lockh = NULL;
618                 struct ptlrpc_request *req = NULL;
619                 ldlm_blocking_callback cb;
620                 struct lookup_intent it;
621                 int master = 0;
622
623                 CDEBUG(D_OTHER, "revalidate subobj "DLID4"\n",
624                        OLID4(&id));
625
626                 memset(&it, 0, sizeof(it));
627                 it.it_op = IT_GETATTR;
628                 cb = lmv_dirobj_blocking_ast;
629
630                 if (lmv_id_equal(&id, &obj->id)) {
631                         if (master_valid) {
632                                 /* lmv_intent_getattr() already checked
633                                  * validness and took the lock */
634                                 if (mreq) {
635                                         /* it even got the reply refresh attrs
636                                          * from that reply */
637                                         body = lustre_msg_buf(mreq->rq_repmsg,
638                                                               1, sizeof(*body));
639                                         LASSERT(body != NULL);
640                                         goto update; 
641                                 }
642                                 /* take already cached attrs into account */
643                                 CDEBUG(D_OTHER,
644                                        "master is locked and cached\n");
645                                 goto release_lock;
646                         }
647                         master = 1;
648                         cb = cb_blocking;
649                 }
650
651                 /* is obj valid? */
652                 rc = md_intent_lock(lmv->tgts[id_group(&id)].ltd_exp,
653                                     &id, NULL, 0, NULL, 0, &id, &it, 0, 
654                                     &req, cb);
655                 lockh = (struct lustre_handle *) &it.d.lustre.it_lock_handle;
656                 if (rc > 0 && req == NULL) {
657                         /* nice, this slave is valid */
658                         LASSERT(req == NULL);
659                         CDEBUG(D_OTHER, "cached\n");
660                         goto release_lock;
661                 }
662
663                 if (rc < 0)
664                         /* error during revalidation */
665                         GOTO(cleanup, rc);
666
667                 if (master) {
668                         LASSERT(master_valid == 0);
669                         /* save lock on master to be returned to the caller */
670                         CDEBUG(D_OTHER, "no lock on master yet\n");
671                         memcpy(&master_lockh, lockh, sizeof(master_lockh));
672                         master_lock_mode = it.d.lustre.it_lock_mode;
673                         it.d.lustre.it_lock_mode = 0;
674                 } else {
675                         /* this is slave. we want to control it */
676                         lock = ldlm_handle2lock(lockh);
677                         LASSERT(lock);
678                         lock->l_ast_data = lmv_get_obj(obj);
679                         LDLM_LOCK_PUT(lock);
680                 }
681
682                 if (*reqp == NULL) {
683                         /* this is first reply, we'll use it to return updated
684                          * data back to the caller */
685                         LASSERT(req);
686                         ptlrpc_request_addref(req);
687                         *reqp = req;
688
689                 }
690
691                 body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body));
692                 LASSERT(body);
693                 
694 update:
695                 obj->objs[i].size = body->size;
696                 
697                 CDEBUG(D_OTHER, "fresh: %lu\n",
698                        (unsigned long)obj->objs[i].size);
699
700                 if (req)
701                         ptlrpc_req_finished(req);
702 release_lock:
703                 size += obj->objs[i].size;
704
705                 if (it.d.lustre.it_lock_mode)
706                         ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
707         }
708
709         if (*reqp) {
710                 /* some attrs got refreshed, we have reply and it's time to put
711                  * fresh attrs to it */
712                 CDEBUG(D_OTHER, "return refreshed attrs: size = %lu\n",
713                        (unsigned long)size);
714                 
715                 body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
716                 LASSERT(body);
717
718                 /* FIXME: what about other attributes? */
719                 body->size = size;
720                 
721                 if (mreq == NULL) {
722                         /* very important to maintain lli->mds the same because
723                          * of revalidation. mreq == NULL means that caller has
724                          * no reply and the only attr we can return is size */
725                         body->valid = OBD_MD_FLSIZE;
726 //                        body->mds = id_group(&obj->id);
727                 }
728                 if (master_valid == 0) {
729                         memcpy(&oit->d.lustre.it_lock_handle,
730                                &master_lockh, sizeof(master_lockh));
731                         oit->d.lustre.it_lock_mode = master_lock_mode;
732                 }
733                 rc = 0;
734         } else {
735                 /* it seems all the attrs are fresh and we did no request */
736                 CDEBUG(D_OTHER, "all the attrs were fresh\n");
737                 if (master_valid == 0)
738                         oit->d.lustre.it_lock_mode = master_lock_mode;
739                 rc = 1;
740         }
741 cleanup:
742         lmv_unlock_obj(obj);
743         lmv_put_obj(obj);
744         RETURN(rc);
745 }