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