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