Whamcloud - gitweb
- fixes about recovery in mds. Added asserts.
[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 || it->it_op == IT_CHDIR) {
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         int rc, mds, loop = 0;
136         struct lmv_obj *obj;
137         struct mea *mea;
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(id_equal_fid(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
182                 /* 
183                  * this is possible, that some userspace application will try to
184                  * open file as directory and we will have error -20 here. As
185                  * this is "usual" situation, we should not print error here,
186                  * only debug info.
187                  */
188                 CDEBUG(D_OTHER, "can't handle remote %s: dir "DLID4"("DLID4"):"
189                        "%*s: %d\n", LL_IT2STR(it), OLID4(pid), OLID4(&rpid),
190                        len, name, rc);
191                 RETURN(rc);
192         }
193
194         /* caller may use attrs MDS returns on IT_OPEN lock request so, we have
195          * to update them for splitted dir */
196         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
197         LASSERT(body != NULL);
198
199         cid = &body->id1;
200         obj = lmv_grab_obj(obd, cid);
201         if (!obj && (mea = lmv_splitted_dir_body(*reqp, 1))) {
202                 /* wow! this is splitted dir, we'd like to handle it */
203                 obj = lmv_create_obj(exp, &body->id1, mea);
204                 if (IS_ERR(obj))
205                         RETURN(PTR_ERR(obj));
206         }
207
208         if (obj) {
209                 /* this is splitted dir and we'd want to get attrs */
210                 CDEBUG(D_OTHER, "attrs from slaves for "DLID4"\n",
211                        OLID4(cid));
212                 
213                 rc = lmv_revalidate_slaves(exp, reqp, cid, it, 1,
214                                            cb_blocking);
215         } else if (S_ISDIR(body->mode)) {
216                 CDEBUG(D_OTHER, "object "DLID4" has not lmv obj?\n",
217                        OLID4(cid));
218         }
219         
220         if (obj)
221                 lmv_put_obj(obj);
222         
223         RETURN(rc);
224 }
225
226 int lmv_intent_getattr(struct obd_export *exp, struct lustre_id *pid,
227                        const char *name, int len, void *lmm, int lmmsize,
228                        struct lustre_id *cid, struct lookup_intent *it,
229                        int flags, struct ptlrpc_request **reqp,
230                        ldlm_blocking_callback cb_blocking)
231 {
232         struct obd_device *obd = exp->exp_obd;
233         struct lmv_obd *lmv = &obd->u.lmv;
234         struct mds_body *body = NULL;
235         struct lustre_id rpid = *pid;
236         struct lmv_obj *obj = NULL, *obj2 = NULL;
237         struct mea *mea;
238         int rc = 0, mds;
239         ENTRY;
240
241         if (cid) {
242                 /* caller wants to revalidate attrs of obj we have to revalidate
243                  * slaves if requested object is splitted directory */
244                 CDEBUG(D_OTHER, "revalidate attrs for "DLID4"\n", OLID4(cid));
245                 mds = id_group(cid);
246 #if 0
247                 obj = lmv_grab_obj(obd, cid);
248                 if (obj) {
249                         /* in fact, we need not this with current intent_lock(),
250                          * but it may change some day */
251                         if (!id_equal_fid(pid, cid)){
252                                 rpid = obj->objs[mds].id;
253                                 mds = id_group(&rpid);
254                         }
255                         lmv_put_obj(obj);
256                 }
257 #endif
258         } else {
259                 CDEBUG(D_OTHER, "INTENT getattr for %*s on "DLID4"\n",
260                        len, name, OLID4(pid));
261                 mds = id_group(pid);
262                 obj = lmv_grab_obj(obd, pid);
263                 if (obj && len) {
264                         /* directory is already splitted. calculate mds */
265                         mds = raw_name2idx(obj->hashtype, obj->objcount, 
266                                            (char *)name, len);
267                         rpid = obj->objs[mds].id;
268                         mds = id_group(&rpid);
269                         lmv_put_obj(obj);
270
271                         CDEBUG(D_OTHER, "forward to MDS #%u (slave "DLID4")\n",
272                                mds, OLID4(&rpid));
273                 }
274         }
275         rc = md_intent_lock(lmv->tgts[mds].ltd_exp, &rpid, name,
276                             len, lmm, lmmsize, cid, it, flags, reqp,
277                             cb_blocking);
278         if (rc < 0)
279                 RETURN(rc);
280        
281         if (obj && rc > 0) {
282                 /* this is splitted dir. In order to optimize things a
283                  * bit, we consider obj valid updating missing parts.
284
285                  * FIXME: do we need to return any lock here? It would
286                  * be fine if we don't. this means that nobody should
287                  * use UPDATE lock to notify about object * removal */
288                 CDEBUG(D_OTHER,
289                        "revalidate slaves for "DLID4", rc %d\n",
290                        OLID4(cid), rc);
291                 
292                 LASSERT(cid != 0);
293                 rc = lmv_revalidate_slaves(exp, reqp, cid, it, rc,
294                                            cb_blocking);
295                 RETURN(rc);
296         }
297
298         if (*reqp == NULL)
299                 RETURN(rc);
300  
301         /* okay, MDS has returned success. probably name has been
302          * resolved in remote inode */
303         rc = lmv_handle_remote_inode(exp, lmm, lmmsize, it,
304                                      flags, reqp, cb_blocking);
305         if (rc < 0)
306                 RETURN(rc);
307
308         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
309         LASSERT(body != NULL);
310         
311         cid = &body->id1;
312         obj2 = lmv_grab_obj(obd, cid);
313
314         if (!obj2 && (mea = lmv_splitted_dir_body(*reqp, 1))) {
315                 /* wow! this is splitted dir, we'd like to handle it. */
316                 body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
317                 LASSERT(body != NULL);
318
319                 obj2 = lmv_create_obj(exp, &body->id1, mea);
320                 if (IS_ERR(obj2))
321                         RETURN(PTR_ERR(obj2));
322         }
323
324         if (obj2) {
325                 /* this is splitted dir and we'd want to get attrs */
326                 CDEBUG(D_OTHER, "attrs from slaves for "DLID4", rc %d\n",
327                        OLID4(cid), rc);
328                 
329                 rc = lmv_revalidate_slaves(exp, reqp, cid, it, 1, cb_blocking);
330                 lmv_put_obj(obj2);
331         }
332         RETURN(rc);
333 }
334
335 void lmv_update_body_from_obj(struct mds_body *body, struct lmv_inode *obj)
336 {
337         /* update size */
338         body->size += obj->size;
339 }
340
341 int lmv_lookup_slaves(struct obd_export *exp, struct ptlrpc_request **reqp)
342 {
343         struct obd_device *obd = exp->exp_obd;
344         struct lmv_obd *lmv = &obd->u.lmv;
345         struct mds_body *body = NULL;
346         struct lustre_handle *lockh;
347         struct ldlm_lock *lock;
348         struct mds_body *body2;
349         struct lmv_obj *obj;
350         int i, rc = 0;
351         ENTRY;
352
353         LASSERT(reqp);
354         LASSERT(*reqp);
355
356         /* master is locked. we'd like to take locks on slaves and update
357          * attributes to be returned from the slaves it's important that lookup
358          * is called in two cases:
359          
360          *  - for first time (dcache has no such a resolving yet).
361          *  - ->d_revalidate() returned false.
362          
363          * last case possible only if all the objs (master and all slaves aren't
364          * valid */
365
366         body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
367         LASSERT(body != NULL);
368
369         obj = lmv_grab_obj(obd, &body->id1);
370         LASSERT(obj != NULL);
371
372         CDEBUG(D_OTHER, "lookup slaves for "DLID4"\n", 
373                OLID4(&body->id1));
374
375         lmv_lock_obj(obj);
376         
377         for (i = 0; i < obj->objcount; i++) {
378                 struct lustre_id id = obj->objs[i].id;
379                 struct ptlrpc_request *req = NULL;
380                 struct lookup_intent it;
381
382                 if (id_equal_fid(&id, &obj->id))
383                         /* skip master obj */
384                         continue;
385
386                 CDEBUG(D_OTHER, "lookup slave "DLID4"\n", OLID4(&id));
387
388                 /* is obj valid? */
389                 memset(&it, 0, sizeof(it));
390                 it.it_op = IT_GETATTR;
391                 rc = md_intent_lock(lmv->tgts[id_group(&id)].ltd_exp, &id,
392                                     NULL, 0, NULL, 0, &id, &it, 0, &req,
393                                     lmv_dirobj_blocking_ast);
394                 
395                 lockh = (struct lustre_handle *)&it.d.lustre.it_lock_handle;
396                 if (rc > 0 && req == NULL) {
397                         /* nice, this slave is valid */
398                         LASSERT(req == NULL);
399                         CDEBUG(D_OTHER, "cached\n");
400                         goto release_lock;
401                 }
402
403                 if (rc < 0)
404                         /* error during lookup */
405                         GOTO(cleanup, rc);
406                 
407                 lock = ldlm_handle2lock(lockh);
408                 LASSERT(lock);
409
410                 lock->l_ast_data = lmv_get_obj(obj);
411
412                 body2 = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body2));
413                 LASSERT(body2);
414
415                 obj->objs[i].size = body2->size;
416                 
417                 CDEBUG(D_OTHER, "fresh: %lu\n",
418                        (unsigned long)obj->objs[i].size);
419
420                 LDLM_LOCK_PUT(lock);
421
422                 if (req)
423                         ptlrpc_req_finished(req);
424 release_lock:
425                 lmv_update_body_from_obj(body, obj->objs + i);
426
427                 if (it.d.lustre.it_lock_mode)
428                         ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
429         }
430
431         EXIT;
432 cleanup:
433         lmv_unlock_obj(obj);
434         lmv_put_obj(obj);
435         return rc;
436 }
437
438 int lmv_intent_lookup(struct obd_export *exp, struct lustre_id *pid,
439                       const char *name, int len, void *lmm, int lmmsize,
440                       struct lustre_id *cid, struct lookup_intent *it,
441                       int flags, struct ptlrpc_request **reqp,
442                       ldlm_blocking_callback cb_blocking)
443 {
444         struct obd_device *obd = exp->exp_obd;
445         struct lmv_obd *lmv = &obd->u.lmv;
446         struct mds_body *body = NULL;
447         struct lustre_id rpid = *pid;
448         struct lmv_obj *obj;
449         struct mea *mea;
450         int rc, mds, loop = 0;
451         ENTRY;
452
453         /*
454          * IT_LOOKUP is intended to produce name -> id resolving (let's call
455          * this lookup below) or to confirm requested resolving is still valid
456          * (let's call this revalidation) cid != NULL specifies revalidation.
457          */
458         if (cid) {
459                 /*
460                  * this is revalidation: we have to check is LOOKUP lock still
461                  * valid for given id. Very important part is that we have to
462                  * choose right mds because namespace is per mds.
463                  */
464                 rpid = *pid;
465                 obj = lmv_grab_obj(obd, pid);
466                 if (obj) {
467                         mds = raw_name2idx(obj->hashtype, obj->objcount,
468                                            (char *)name, len);
469                         rpid = obj->objs[mds].id;
470                         lmv_put_obj(obj);
471                 }
472                 mds = id_group(&rpid);
473
474                 CDEBUG(D_OTHER, "revalidate lookup for "DLID4" to %d MDS\n",
475                        OLID4(cid), mds);
476
477         } else {
478                 mds = id_group(pid);
479 repeat:
480                 LASSERT(++loop <= 2);
481                 
482                 /* this is lookup. during lookup we have to update all the
483                  * attributes, because returned values will be put in struct
484                  * inode */
485
486                 obj = lmv_grab_obj(obd, pid);
487                 if (obj) {
488                         if (len) {
489                                 /* directory is already splitted. calculate mds */
490                                 mds = raw_name2idx(obj->hashtype, obj->objcount, 
491                                                    (char *)name, len);
492                                 rpid = obj->objs[mds].id;
493                                 mds = id_group(&rpid);
494                         }
495                         lmv_put_obj(obj);
496                 }
497         }
498         rc = md_intent_lock(lmv->tgts[mds].ltd_exp, &rpid, name,
499                             len, lmm, lmmsize, cid, it, flags, reqp, 
500                             cb_blocking);
501         if (rc > 0) {
502                 LASSERT(cid != 0);
503                 RETURN(rc);
504         }
505         if (rc > 0) {
506                 /* very interesting. it seems object is still valid but for some
507                  * reason llite calls lookup, not revalidate */
508                 CDEBUG(D_OTHER, "lookup for "DLID4" and data should be uptodate\n",
509                       OLID4(&rpid));
510                 LASSERT(*reqp == NULL);
511                 RETURN(rc);
512         }
513
514         if (rc == 0 && *reqp == NULL) {
515                 /* once again, we're asked for lookup, not revalidate */
516                 CDEBUG(D_OTHER, "lookup for "DLID4" and data should be uptodate\n",
517                       OLID4(&rpid));
518                 RETURN(rc);
519         }
520        
521         if (rc == -ERESTART) {
522                 /* directory got splitted since last update. this shouldn't be
523                  * becasue splitting causes lock revocation, so revalidate had
524                  * to fail and lookup on dir had to return mea */
525                 CWARN("we haven't knew about directory splitting!\n");
526                 LASSERT(obj == NULL);
527
528                 obj = lmv_create_obj(exp, &rpid, NULL);
529                 if (IS_ERR(obj))
530                         RETURN(PTR_ERR(obj));
531                 lmv_put_obj(obj);
532                 goto repeat;
533         }
534
535         if (rc < 0)
536                 RETURN(rc);
537
538         /* okay, MDS has returned success. Probably name has been resolved in
539          * remote inode. */
540         rc = lmv_handle_remote_inode(exp, lmm, lmmsize, it, flags,
541                                      reqp, cb_blocking);
542
543         if (rc == 0 && (mea = lmv_splitted_dir_body(*reqp, 1))) {
544                 /* wow! this is splitted dir, we'd like to handle it */
545                 body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
546                 LASSERT(body != NULL);
547                 
548                 obj = lmv_grab_obj(obd, &body->id1);
549                 if (!obj) {
550                         obj = lmv_create_obj(exp, &body->id1, mea);
551                         if (IS_ERR(obj))
552                                 RETURN(PTR_ERR(obj));
553                 }
554                 lmv_put_obj(obj);
555         }
556
557         RETURN(rc);
558 }
559
560 int lmv_intent_lock(struct obd_export *exp, struct lustre_id *pid,
561                     const char *name, int len, void *lmm, int lmmsize,
562                     struct lustre_id *cid, struct lookup_intent *it,
563                     int flags, struct ptlrpc_request **reqp,
564                     ldlm_blocking_callback cb_blocking)
565 {
566         struct obd_device *obd = exp->exp_obd;
567         int rc = 0;
568         ENTRY;
569
570         LASSERT(it);
571         LASSERT(pid);
572
573         CDEBUG(D_OTHER, "INTENT LOCK '%s' for '%*s' on %lu/%lu -> %lu\n",
574                LL_IT2STR(it), len, name, (unsigned long)id_ino(pid),
575                (unsigned long)id_gen(pid), (unsigned long)id_group(pid));
576
577         rc = lmv_check_connect(obd);
578         if (rc)
579                 RETURN(rc);
580
581         if (it->it_op == IT_LOOKUP)
582                 rc = lmv_intent_lookup(exp, pid, name, len, lmm,
583                                        lmmsize, cid, it, flags, reqp,
584                                        cb_blocking);
585         else if (it->it_op & IT_OPEN)
586                 rc = lmv_intent_open(exp, pid, name, len, lmm,
587                                      lmmsize, cid, it, flags, reqp,
588                                      cb_blocking);
589         else if (it->it_op == IT_GETATTR || it->it_op == IT_CHDIR)
590                 rc = lmv_intent_getattr(exp, pid, name, len, lmm,
591                                         lmmsize, cid, it, flags, reqp,
592                                         cb_blocking);
593         else
594                 LBUG();
595         RETURN(rc);
596 }
597
598 int lmv_revalidate_slaves(struct obd_export *exp, struct ptlrpc_request **reqp,
599                           struct lustre_id *mid, struct lookup_intent *oit,
600                           int master_valid, ldlm_blocking_callback cb_blocking)
601 {
602         struct obd_device *obd = exp->exp_obd;
603         struct ptlrpc_request *mreq = *reqp;
604         struct lmv_obd *lmv = &obd->u.lmv;
605         struct lustre_handle master_lockh;
606         struct ldlm_lock *lock;
607         unsigned long size = 0;
608         struct mds_body *body;
609         struct lmv_obj *obj;
610         int master_lock_mode;
611         int i, rc = 0;
612         ENTRY;
613
614         /* we have to loop over the subobjects, check validity and update them
615          * from MDSs if needed. it's very useful that we need not to update all
616          * the fields. say, common fields (that are equal on all the subojects
617          * need not to be update, another fields (i_size, for example) are
618          * cached all the time */
619         obj = lmv_grab_obj(obd, mid);
620         LASSERT(obj != NULL);
621
622         master_lock_mode = 0;
623
624         lmv_lock_obj(obj);
625         
626         for (i = 0; i < obj->objcount; i++) {
627                 struct lustre_id id = obj->objs[i].id;
628                 struct lustre_handle *lockh = NULL;
629                 struct ptlrpc_request *req = NULL;
630                 ldlm_blocking_callback cb;
631                 struct lookup_intent it;
632                 int master = 0;
633
634                 CDEBUG(D_OTHER, "revalidate subobj "DLID4"\n",
635                        OLID4(&id));
636
637                 memset(&it, 0, sizeof(it));
638                 it.it_op = IT_GETATTR;
639                 cb = lmv_dirobj_blocking_ast;
640
641                 if (id_equal_fid(&id, &obj->id)) {
642                         if (master_valid) {
643                                 /* lmv_intent_getattr() already checked
644                                  * validness and took the lock */
645                                 if (mreq) {
646                                         /* it even got the reply refresh attrs
647                                          * from that reply */
648                                         body = lustre_msg_buf(mreq->rq_repmsg,
649                                                               1, sizeof(*body));
650                                         LASSERT(body != NULL);
651                                         goto update; 
652                                 }
653                                 /* take already cached attrs into account */
654                                 CDEBUG(D_OTHER,
655                                        "master is locked and cached\n");
656                                 goto release_lock;
657                         }
658                         master = 1;
659                         cb = cb_blocking;
660                 }
661
662                 /* is obj valid? */
663                 rc = md_intent_lock(lmv->tgts[id_group(&id)].ltd_exp,
664                                     &id, NULL, 0, NULL, 0, &id, &it, 0, 
665                                     &req, cb);
666                 lockh = (struct lustre_handle *) &it.d.lustre.it_lock_handle;
667                 if (rc > 0 && req == NULL) {
668                         /* nice, this slave is valid */
669                         LASSERT(req == NULL);
670                         CDEBUG(D_OTHER, "cached\n");
671                         goto release_lock;
672                 }
673
674                 if (rc < 0)
675                         /* error during revalidation */
676                         GOTO(cleanup, rc);
677
678                 if (master) {
679                         LASSERT(master_valid == 0);
680                         /* save lock on master to be returned to the caller */
681                         CDEBUG(D_OTHER, "no lock on master yet\n");
682                         memcpy(&master_lockh, lockh, sizeof(master_lockh));
683                         master_lock_mode = it.d.lustre.it_lock_mode;
684                         it.d.lustre.it_lock_mode = 0;
685                 } else {
686                         /* this is slave. we want to control it */
687                         lock = ldlm_handle2lock(lockh);
688                         LASSERT(lock);
689                         lock->l_ast_data = lmv_get_obj(obj);
690                         LDLM_LOCK_PUT(lock);
691                 }
692
693                 if (*reqp == NULL) {
694                         /* this is first reply, we'll use it to return updated
695                          * data back to the caller */
696                         LASSERT(req);
697                         ptlrpc_request_addref(req);
698                         *reqp = req;
699
700                 }
701
702                 body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body));
703                 LASSERT(body);
704                 
705 update:
706                 obj->objs[i].size = body->size;
707                 
708                 CDEBUG(D_OTHER, "fresh: %lu\n",
709                        (unsigned long)obj->objs[i].size);
710
711                 if (req)
712                         ptlrpc_req_finished(req);
713 release_lock:
714                 size += obj->objs[i].size;
715
716                 if (it.d.lustre.it_lock_mode)
717                         ldlm_lock_decref(lockh, it.d.lustre.it_lock_mode);
718         }
719
720         if (*reqp) {
721                 /* some attrs got refreshed, we have reply and it's time to put
722                  * fresh attrs to it */
723                 CDEBUG(D_OTHER, "return refreshed attrs: size = %lu\n",
724                        (unsigned long)size);
725                 
726                 body = lustre_msg_buf((*reqp)->rq_repmsg, 1, sizeof(*body));
727                 LASSERT(body);
728
729                 /* FIXME: what about other attributes? */
730                 body->size = size;
731                 
732                 if (mreq == NULL) {
733                         /* very important to maintain id_group(lli->lli_id) the
734                          * same because of revalidation. mreq == NULL means that
735                          * caller has no reply and the only attr we can return
736                          * is size */
737                         body->valid = OBD_MD_FLSIZE;
738 //                        body->mds = id_group(&obj->id);
739                 }
740                 if (master_valid == 0) {
741                         memcpy(&oit->d.lustre.it_lock_handle,
742                                &master_lockh, sizeof(master_lockh));
743                         oit->d.lustre.it_lock_mode = master_lock_mode;
744                 }
745                 rc = 0;
746         } else {
747                 /* it seems all the attrs are fresh and we did no request */
748                 CDEBUG(D_OTHER, "all the attrs were fresh\n");
749                 if (master_valid == 0)
750                         oit->d.lustre.it_lock_mode = master_lock_mode;
751                 rc = 1;
752         }
753
754         EXIT;
755 cleanup:
756         lmv_unlock_obj(obj);
757         lmv_put_obj(obj);
758         return rc;
759 }