Whamcloud - gitweb
- mds->lmv->mdc propagate lower timeout down to import
[fs/lustre-release.git] / lustre / lmv / lmv_obd.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 #else
34 #include <liblustre.h>
35 #endif
36 #include <linux/ext2_fs.h>
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/seq_file.h>
47 #include <linux/lprocfs_status.h>
48 #include <linux/lustre_fsfilt.h>
49 #include <linux/obd_lmv.h>
50 #include "lmv_internal.h"
51
52 int lmv_attach(struct obd_device *dev, obd_count len, void *data)
53 {
54         struct lprocfs_static_vars lvars;
55         struct proc_dir_entry *entry;
56         int rc;
57         ENTRY;
58
59         lprocfs_init_vars(lmv, &lvars);
60         rc = lprocfs_obd_attach(dev, lvars.obd_vars);
61         if (rc)
62                 RETURN (rc);
63
64         entry = create_proc_entry("target_obd", 0444, dev->obd_proc_entry);
65         if (entry == NULL)
66                 RETURN(-ENOMEM);
67         /* entry->proc_fops = &lmv_proc_target_fops; */
68         entry->data = dev;
69
70         RETURN (rc);
71 }
72
73 int lmv_detach(struct obd_device *dev)
74 {
75         return lprocfs_obd_detach(dev);
76 }
77
78 static int lmv_connect_fake(struct lustre_handle *conn,
79                             struct obd_device *obd,
80                             struct obd_uuid *cluuid)
81 {
82         struct lmv_obd *lmv = &obd->u.lmv;
83         struct obd_export *exp;
84         int rc;
85         ENTRY;
86
87         rc = class_connect(conn, obd, cluuid);
88         if (rc) {
89                 CERROR("class_connection() returned %d\n", rc);
90                 RETURN(rc);
91         }
92
93         exp = class_conn2export(conn);
94         /* We don't want to actually do the underlying connections more than
95          * once, so keep track. */
96         lmv->refcount++;
97         if (lmv->refcount > 1) {
98                 class_export_put(exp);
99                 RETURN(0);
100         }
101
102         lmv->cluuid = *cluuid;
103         lmv->connected = 0;
104         lmv->exp = exp;
105
106         RETURN(0);
107 }
108
109 void lmv_set_timeouts(struct obd_device *obd)
110 {
111         struct lmv_tgt_desc *tgts;
112         struct lmv_obd *lmv;
113         int i;
114
115         lmv = &obd->u.lmv;
116         if (lmv->server_timeout == 0)
117                 return;
118
119         if (lmv->connected == 0)
120                 return;
121
122         for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
123                 if (tgts->exp == NULL)
124                         continue;
125                 obd_set_info(tgts->exp, strlen("inter_mds"),
126                              "inter_mds", 0, NULL);
127         }
128 }
129
130 int lmv_connect(struct obd_device *obd)
131 {
132         struct lmv_obd *lmv = &obd->u.lmv;
133         struct obd_uuid *cluuid;
134         struct lmv_tgt_desc *tgts;
135         struct obd_export *exp;
136         int rc, i;
137         ENTRY;
138
139         if (lmv->connected)
140                 RETURN(0);
141       
142         lmv->connected = 1;
143         cluuid = &lmv->cluuid;
144         exp = lmv->exp;
145         CDEBUG(D_OTHER, "time to connect %s to %s\n",
146                         cluuid->uuid, obd->obd_name);
147
148         for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
149                 struct obd_device *tgt_obd;
150                 struct obd_uuid lmv_osc_uuid = { "LMV_OSC_UUID" };
151                 struct lustre_handle conn = {0, };
152
153                 LASSERT(tgts != NULL);
154
155                 tgt_obd = class_find_client_obd(&tgts->uuid, LUSTRE_MDC_NAME, 
156                                                 &obd->obd_uuid);
157                 if (!tgt_obd) {
158                         CERROR("Target %s not attached\n", tgts->uuid.uuid);
159                         GOTO(out_disc, rc = -EINVAL);
160                 }
161
162                 /* for MDS: don't connect to yourself */
163                 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
164                         CDEBUG(D_OTHER, "don't connect back to %s\n",
165                                cluuid->uuid);
166                         tgts->exp = NULL;
167                         continue;
168                 }
169
170                 CDEBUG(D_OTHER, "connect to %s(%s) - %s, %s FOR %s\n",
171                         tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
172                         tgts->uuid.uuid, obd->obd_uuid.uuid,
173                         cluuid->uuid);
174
175                 if (!tgt_obd->obd_set_up) {
176                         CERROR("Target %s not set up\n", tgts->uuid.uuid);
177                         GOTO(out_disc, rc = -EINVAL);
178                 }
179                 
180                 rc = obd_connect(&conn, tgt_obd, &lmv_osc_uuid);
181                 if (rc) {
182                         CERROR("Target %s connect error %d\n",
183                                 tgts->uuid.uuid, rc);
184                         GOTO(out_disc, rc);
185                 }
186                 tgts->exp = class_conn2export(&conn);
187
188                 obd_init_ea_size(tgts->exp, lmv->max_easize,
189                                         lmv->max_cookiesize);
190                 
191                 rc = obd_register_observer(tgt_obd, obd);
192                 if (rc) {
193                         CERROR("Target %s register_observer error %d\n",
194                                tgts->uuid.uuid, rc);
195                         obd_disconnect(tgts->exp, 0);
196                         GOTO(out_disc, rc);
197                 }
198
199                 CDEBUG(D_OTHER, "connected to %s(%s) successfully (%d)\n",
200                         tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
201                         atomic_read(&obd->obd_refcount));
202         }
203
204         lmv_set_timeouts(obd);
205
206         class_export_put(exp);
207         RETURN (0);
208
209  out_disc:
210         /* FIXME: cleanup here */
211         class_disconnect(exp, 0);
212         RETURN (rc);
213 }
214
215 static int lmv_disconnect(struct obd_export *exp, int flags)
216 {
217         struct obd_device *obd = class_exp2obd(exp);
218         struct lmv_obd *lmv = &obd->u.lmv;
219         int rc, i;
220         ENTRY;
221
222         if (!lmv->tgts)
223                 goto out_local;
224
225         /* Only disconnect the underlying layers on the final disconnect. */
226         lmv->refcount--;
227         if (lmv->refcount != 0)
228                 goto out_local;
229
230         for (i = 0; i < lmv->count; i++) {
231                 if (lmv->tgts[i].exp == NULL)
232                         continue;
233
234                 if (obd->obd_no_recov) {
235                         /* Pass it on to our clients.
236                          * XXX This should be an argument to disconnect,
237                          * XXX not a back-door flag on the OBD.  Ah well.
238                          */
239                         struct obd_device *mdc_obd;
240                         mdc_obd = class_exp2obd(lmv->tgts[i].exp);
241                         if (mdc_obd)
242                                 mdc_obd->obd_no_recov = 1;
243                 }
244
245                 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
246                         lmv->tgts[i].exp->exp_obd->obd_name,
247                         lmv->tgts[i].exp->exp_obd->obd_uuid.uuid);
248
249                 obd_register_observer(lmv->tgts[i].exp->exp_obd, NULL);
250
251                 rc = obd_disconnect(lmv->tgts[i].exp, flags);
252                 lmv->tgts[i].exp = NULL;
253         }
254
255  out_local:
256         /* FIXME: cleanup here */
257         if (!lmv->connected)
258                 class_export_put(exp);
259         rc = class_disconnect(exp, 0);
260         RETURN(rc);
261 }
262
263 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
264 {
265         struct lustre_cfg *lcfg = buf;
266         struct lmv_desc *desc;
267         struct lmv_obd *lmv = &obd->u.lmv;
268         struct obd_uuid *uuids;
269         struct lmv_tgt_desc *tgts;
270         int i;
271         int count;
272         int rc = 0;
273         ENTRY;
274
275         if (lcfg->lcfg_inllen1 < 1) {
276                 CERROR("LMV setup requires a descriptor\n");
277                 RETURN(-EINVAL);
278         }
279
280         if (lcfg->lcfg_inllen2 < 1) {
281                 CERROR("LMV setup requires an OST UUID list\n");
282                 RETURN(-EINVAL);
283         }
284
285         desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1;
286         if (sizeof(*desc) > lcfg->lcfg_inllen1) {
287                 CERROR("descriptor size wrong: %d > %d\n",
288                        (int)sizeof(*desc), lcfg->lcfg_inllen1);
289                 RETURN(-EINVAL);
290         }
291
292         count = desc->ld_count;
293         uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2;
294         if (sizeof(*uuids) * count != lcfg->lcfg_inllen2) {
295                 CERROR("UUID array size wrong: %u * %u != %u\n",
296                        sizeof(*uuids), count, lcfg->lcfg_inllen2);
297                 RETURN(-EINVAL);
298         }
299
300         lmv->bufsize = sizeof(struct lmv_tgt_desc) * count;
301         OBD_ALLOC(lmv->tgts, lmv->bufsize);
302         if (lmv->tgts == NULL) {
303                 CERROR("Out of memory\n");
304                 RETURN(-EINVAL);
305         }
306
307         for (i = 0, tgts = lmv->tgts; i < count; i++, tgts++) {
308                 tgts->uuid = uuids[i];
309                 lmv->count++;
310         }
311
312         lmv->max_easize = sizeof(struct ll_fid) * lmv->count
313                                         + sizeof(struct mea);
314         lmv->max_cookiesize = 0;
315
316         RETURN(rc);
317 }
318
319 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
320                       unsigned long max_age)
321 {
322         struct lmv_obd *lmv = &obd->u.lmv;
323         struct obd_statfs temp;
324         int rc = 0, i;
325         ENTRY;
326         lmv_connect(obd);
327         for (i = 0; i < lmv->count; i++) {
328                 rc = obd_statfs(lmv->tgts[i].exp->exp_obd, &temp, max_age);
329                 if (rc) {
330                         CERROR("can't stat MDS #%d (%s)\n", i,
331                                lmv->tgts[i].exp->exp_obd->obd_name);
332                         RETURN(rc);
333                 }
334                 if (i == 0) {
335                         memcpy(osfs, &temp, sizeof(temp));
336                 } else {
337                         osfs->os_bavail += temp.os_bavail;
338                         osfs->os_blocks += temp.os_blocks;
339                         osfs->os_ffree += temp.os_ffree;
340                         osfs->os_files += temp.os_files;
341                 }
342         }
343         RETURN(rc);
344 }
345
346 static int lmv_cleanup(struct obd_device *obd, int flags) 
347 {
348         struct lmv_obd *lmv = &obd->u.lmv;
349         ENTRY;
350         lmv_cleanup_objs(obd);
351         OBD_FREE(lmv->tgts, lmv->bufsize);
352         RETURN(0);
353 }
354
355 static int lmv_getstatus(struct obd_export *exp, struct ll_fid *fid)
356 {
357         struct obd_device *obd = exp->exp_obd;
358         struct lmv_obd *lmv = &obd->u.lmv;
359         int rc;
360         ENTRY;
361         lmv_connect(obd);
362         rc = md_getstatus(lmv->tgts[0].exp, fid);
363         fid->mds = 0;
364         RETURN(rc);
365 }
366
367 static int lmv_getattr(struct obd_export *exp, struct ll_fid *fid,
368                 unsigned long valid, unsigned int ea_size,
369                 struct ptlrpc_request **request)
370 {
371         struct obd_device *obd = exp->exp_obd;
372         struct lmv_obd *lmv = &obd->u.lmv;
373         int rc, i = fid->mds;
374         struct lmv_obj *obj;
375         ENTRY;
376         lmv_connect(obd);
377         obj = lmv_grab_obj(obd, fid, 0);
378         CDEBUG(D_OTHER, "GETATTR for %lu/%lu/%lu %s\n",
379                (unsigned long) fid->mds,
380                (unsigned long) fid->id,
381                (unsigned long) fid->generation,
382                obj ? "(splitted)" : "");
383
384         LASSERT(fid->mds < lmv->count);
385         rc = md_getattr(lmv->tgts[i].exp, fid,
386                              valid, ea_size, request);
387         if (rc == 0 && obj) {
388                 /* we have to loop over dirobjs here and gather attrs
389                  * for all the slaves */
390 #warning "attrs gathering here"
391         }
392         lmv_put_obj(obj);
393         RETURN(rc);
394 }
395
396 static int lmv_change_cbdata(struct obd_export *exp,
397                                  struct ll_fid *fid, 
398                                  ldlm_iterator_t it, void *data)
399 {
400         struct obd_device *obd = exp->exp_obd;
401         struct lmv_obd *lmv = &obd->u.lmv;
402         int rc = 0;
403         ENTRY;
404         lmv_connect(obd);
405         CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu\n",
406                (unsigned long) fid->mds,
407                (unsigned long) fid->id,
408                (unsigned long) fid->generation);
409         LASSERT(fid->mds < lmv->count);
410         rc = md_change_cbdata(lmv->tgts[fid->mds].exp, fid, it, data);
411         RETURN(rc);
412 }
413
414 static int lmv_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
415                                   char *name, int len, struct ll_fid *cfid,
416                                   ldlm_iterator_t it, void *data)
417 {
418         struct obd_device *obd = exp->exp_obd;
419         struct lmv_obd *lmv = &obd->u.lmv;
420         struct lmv_obj *obj;
421         int rc = 0, mds;
422         ENTRY;
423         lmv_connect(obd);
424         LASSERT(pfid->mds < lmv->count);
425         LASSERT(cfid->mds < lmv->count);
426         CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu:%*s -> %lu/%lu/%lu\n",
427                (unsigned long) pfid->mds, (unsigned long) pfid->id,
428                (unsigned long) pfid->generation, len, name,
429                (unsigned long) cfid->mds, (unsigned long) cfid->id,
430                (unsigned long) cfid->generation);
431
432         /* this is default mds for directory name belongs to */
433         mds = pfid->mds;
434         obj = lmv_grab_obj(obd, pfid, 0);
435         if (obj) {
436                 /* directory is splitted. look for right mds for this name */
437                 mds = raw_name2idx(obj->objcount, name, len);
438                 lmv_put_obj(obj);
439         }
440         rc = md_change_cbdata(lmv->tgts[mds].exp, cfid, it, data);
441         RETURN(rc);
442 }
443
444 static int lmv_valid_attrs(struct obd_export *exp, struct ll_fid *fid) 
445 {
446         struct obd_device *obd = exp->exp_obd;
447         struct lmv_obd *lmv = &obd->u.lmv;
448         int rc = 0;
449         ENTRY;
450         lmv_connect(obd);
451         CDEBUG(D_OTHER, "validate %lu/%lu/%lu\n",
452                (unsigned long) fid->mds,
453                (unsigned long) fid->id,
454                (unsigned long) fid->generation);
455         LASSERT(fid->mds < lmv->count);
456         rc = md_valid_attrs(lmv->tgts[fid->mds].exp, fid);
457         RETURN(rc);
458 }
459
460 int lmv_close(struct obd_export *exp, struct obdo *obdo,
461                   struct obd_client_handle *och,
462                   struct ptlrpc_request **request)
463 {
464         struct obd_device *obd = exp->exp_obd;
465         struct lmv_obd *lmv = &obd->u.lmv;
466         int rc, i = obdo->o_mds;
467         ENTRY;
468         lmv_connect(obd);
469         LASSERT(i < lmv->count);
470         CDEBUG(D_OTHER, "CLOSE %lu/%lu/%lu\n", (unsigned long) obdo->o_mds,
471                (unsigned long) obdo->o_id, (unsigned long) obdo->o_generation);
472         rc = md_close(lmv->tgts[i].exp, obdo, och, request);
473         RETURN(rc);
474 }
475
476 int lmv_get_mea_and_update_object(struct obd_export *exp, struct ll_fid *fid)
477 {
478         struct obd_device *obd = exp->exp_obd;
479         struct lmv_obd *lmv = &obd->u.lmv;
480         struct ptlrpc_request *req = NULL;
481         struct lustre_md md;
482         int mealen, rc;
483
484         md.mea = NULL;
485         mealen = MEA_SIZE_LMV(lmv);
486
487         /* time to update mea of parent fid */
488         rc = md_getattr(lmv->tgts[fid->mds].exp, fid,
489                         OBD_MD_FLEASIZE, mealen, &req);
490         if (rc)
491                 GOTO(cleanup, rc);
492         rc = mdc_req2lustre_md(req, 0, NULL, exp, &md);
493         if (rc)
494                 GOTO(cleanup, rc);
495         if (md.mea == NULL)
496                 GOTO(cleanup, rc = -ENODATA);
497         rc = lmv_create_obj_from_attrs(exp, fid, md.mea);
498         obd_free_memmd(exp, (struct lov_stripe_md **) &md.mea);
499
500 cleanup:
501         if (req)
502                 ptlrpc_req_finished(req);
503         RETURN(rc);
504 }
505
506 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
507                    const void *data, int datalen, int mode, __u32 uid,
508                    __u32 gid, __u64 rdev, struct ptlrpc_request **request)
509 {
510         struct obd_device *obd = exp->exp_obd;
511         struct lmv_obd *lmv = &obd->u.lmv;
512         struct mds_body *mds_body;
513         struct lmv_obj *obj;
514         int rc, mds;
515         ENTRY;
516
517         lmv_connect(obd);
518 repeat:
519         obj = lmv_grab_obj(obd, &op_data->fid1, 0);
520         if (obj) {
521                 mds = raw_name2idx(obj->objcount, op_data->name,
522                                         op_data->namelen);
523                 op_data->fid1 = obj->objs[mds].fid;
524                 lmv_put_obj(obj);
525         }
526
527         CDEBUG(D_OTHER, "CREATE '%*s' on %lu/%lu/%lu\n",
528                         op_data->namelen, op_data->name,
529                         (unsigned long) op_data->fid1.mds,
530                         (unsigned long) op_data->fid1.id,
531                         (unsigned long) op_data->fid1.generation);
532         rc = md_create(lmv->tgts[op_data->fid1.mds].exp, op_data, data,
533                        datalen, mode, uid, gid, rdev, request);
534         if (rc == 0) {
535                 if (*request == NULL)
536                      RETURN(rc);
537                 mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
538                                           sizeof(*mds_body));
539                 LASSERT(mds_body != NULL);
540                 CDEBUG(D_OTHER, "created. id = %lu, generation = %lu, mds = %d\n",
541                        (unsigned long) mds_body->fid1.id,
542                        (unsigned long) mds_body->fid1.generation,
543                        op_data->fid1.mds);
544                 LASSERT(mds_body->valid & OBD_MD_MDS ||
545                                 mds_body->mds == op_data->fid1.mds);
546         } else if (rc == -ERESTART) {
547                 /* directory got splitted. time to update local object
548                  * and repeat the request with proper MDS */
549                 rc = lmv_get_mea_and_update_object(exp, &op_data->fid1);
550                 if (rc == 0) {
551                         ptlrpc_req_finished(*request);
552                         goto repeat;
553                 }
554         }
555         RETURN(rc);
556 }
557
558 int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
559 {
560         struct obd_device *obd = exp->exp_obd;
561         struct lmv_obd *lmv = &obd->u.lmv;
562         int rc;
563         ENTRY;
564         lmv_connect(obd);
565         /* FIXME: choose right MDC here */
566         rc = md_done_writing(lmv->tgts[0].exp, obdo);
567         RETURN(rc);
568 }
569
570 int lmv_enqueue(struct obd_export *exp, int lock_type,
571                     struct lookup_intent *it, int lock_mode,
572                     struct mdc_op_data *data, struct lustre_handle *lockh,
573                     void *lmm, int lmmsize,
574                     ldlm_completion_callback cb_completion,
575                     ldlm_blocking_callback cb_blocking, void *cb_data)
576 {
577         struct obd_device *obd = exp->exp_obd;
578         struct lmv_obd *lmv = &obd->u.lmv;
579         struct lmv_obj *obj;
580         int rc, mds;
581         ENTRY;
582         lmv_connect(obd);
583         if (data->namelen) {
584                 obj = lmv_grab_obj(obd, &data->fid1, 0);
585                 if (obj) {
586                         /* directory is splitted. look for
587                          * right mds for this name */
588                         mds = raw_name2idx(obj->objcount, data->name,
589                                                 data->namelen);
590                         data->fid1 = obj->objs[mds].fid;
591                         lmv_put_obj(obj);
592                 }
593         }
594         CDEBUG(D_OTHER, "ENQUEUE '%s' on %lu/%lu\n",
595                LL_IT2STR(it), (unsigned long) data->fid1.id,
596                (unsigned long) data->fid1.generation);
597         rc = md_enqueue(lmv->tgts[data->fid1.mds].exp, lock_type, it,
598                         lock_mode, data, lockh, lmm, lmmsize, cb_completion,
599                         cb_blocking, cb_data);
600
601         RETURN(rc);
602 }
603
604 int lmv_getattr_name(struct obd_export *exp, struct ll_fid *fid,
605                          char *filename, int namelen, unsigned long valid,
606                          unsigned int ea_size, struct ptlrpc_request **request)
607 {
608         struct obd_device *obd = exp->exp_obd;
609         struct lmv_obd *lmv = &obd->u.lmv;
610         struct ll_fid rfid = *fid;
611         int rc, mds = fid->mds;
612         struct mds_body *body;
613         struct lmv_obj *obj;
614         ENTRY;
615         lmv_connect(obd);
616         obj = lmv_grab_obj(obd, fid, 0);
617         if (obj) {
618                 /* directory is splitted. look for right mds for this name */
619                 mds = raw_name2idx(obj->objcount, filename, namelen - 1);
620                 rfid = obj->objs[mds].fid;
621                 lmv_put_obj(obj);
622         }
623         CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu -> %lu/%lu/%lu\n",
624                namelen, filename, (unsigned long) fid->mds,
625                (unsigned long) fid->id, (unsigned long) fid->generation,
626                (unsigned long) rfid.mds, (unsigned long) rfid.id,
627                (unsigned long) rfid.generation);
628         rc = md_getattr_name(lmv->tgts[mds].exp, &rfid, filename, namelen,
629                                   valid, ea_size, request);
630         if (rc == 0) {
631                 /* this could be cross-node reference. in this case all
632                  * we have right now is mds/ino/generation triple. we'd
633                  * like to find other attributes */
634                 body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body));
635                 LASSERT(body != NULL);
636                 if (body->valid & OBD_MD_MDS) {
637                         struct ptlrpc_request *req = NULL;
638                         rfid = body->fid1;
639                         CDEBUG(D_OTHER, "request attrs for %lu/%lu/%lu\n",
640                                (unsigned long) rfid.mds,
641                                (unsigned long) rfid.id,
642                                (unsigned long) rfid.generation);
643                         rc = md_getattr_name(lmv->tgts[rfid.mds].exp, &rfid,
644                                              NULL, 1, valid, ea_size, &req);
645                         ptlrpc_req_finished(*request);
646                         *request = req;
647                 }
648         }
649         RETURN(rc);
650 }
651
652
653 /*
654  * llite passes fid of an target inode in data->fid1 and
655  * fid of directory in data->fid2
656  */
657 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
658              struct ptlrpc_request **request)
659 {
660         struct obd_device *obd = exp->exp_obd;
661         struct lmv_obd *lmv = &obd->u.lmv;
662         struct lmv_obj *obj;
663         int rc;
664         ENTRY;
665         lmv_connect(obd);
666         if (data->namelen != 0) {
667                 /* usual link request */
668                 obj = lmv_grab_obj(obd, &data->fid1, 0);
669                 if (obj) {
670                         rc = raw_name2idx(obj->objcount, data->name,
671                                          data->namelen);
672                         data->fid1 = obj->objs[rc].fid;
673                         lmv_put_obj(obj);
674                 }
675                 CDEBUG(D_OTHER,"link %u/%u/%u:%*s to %u/%u/%u mds %d\n",
676                        (unsigned) data->fid2.mds, (unsigned) data->fid2.id,
677                        (unsigned) data->fid2.generation, data->namelen,
678                        data->name, (unsigned) data->fid1.mds,
679                        (unsigned) data->fid1.id,
680                        (unsigned) data->fid1.generation, data->fid1.mds);
681         } else {
682                 /* request from MDS to acquire i_links for inode by fid1 */
683                 CDEBUG(D_OTHER, "inc i_nlinks for %u/%u/%u\n",
684                        (unsigned) data->fid1.mds, (unsigned) data->fid1.id,
685                        (unsigned) data->fid1.generation);
686         }
687                         
688         rc = md_link(lmv->tgts[data->fid1.mds].exp, data, request);
689         RETURN(rc);
690 }
691
692 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
693                const char *old, int oldlen, const char *new, int newlen,
694                struct ptlrpc_request **request)
695 {
696         struct obd_device *obd = exp->exp_obd;
697         struct lmv_obd *lmv = &obd->u.lmv;
698         struct lmv_obj *obj;
699         int rc, mds;
700         ENTRY;
701
702         CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
703                oldlen, old, (unsigned long) data->fid1.mds,
704                (unsigned long) data->fid1.id,
705                (unsigned long) data->fid1.generation,
706                newlen, new, (unsigned long) data->fid2.mds,
707                (unsigned long) data->fid2.id,
708                (unsigned long) data->fid2.generation);
709         if (!fid_equal(&data->fid1, &data->fid2))
710                 CWARN("cross-node rename %lu/%lu/%lu:%*s to %lu/%lu/%lu:%*s\n",
711                       (unsigned long) data->fid1.mds,
712                       (unsigned long) data->fid1.id,
713                       (unsigned long) data->fid1.generation, oldlen, old,
714                       (unsigned long) data->fid2.mds,
715                       (unsigned long) data->fid2.id,
716                       (unsigned long) data->fid2.generation, newlen, new);
717
718         lmv_connect(obd);
719
720         if (oldlen == 0) {
721                 /* MDS with old dir entry is asking another MDS
722                  * to create name there */
723                 CDEBUG(D_OTHER,
724                        "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
725                        newlen, new, oldlen, newlen,
726                        (unsigned long) data->fid2.mds,
727                        (unsigned long) data->fid2.id,
728                        (unsigned long) data->fid2.generation,
729                        (unsigned long) data->fid1.mds,
730                        (unsigned long) data->fid1.id,
731                        (unsigned long) data->fid1.generation);
732                 mds = data->fid2.mds;
733                 goto request;
734         }
735
736         obj = lmv_grab_obj(obd, &data->fid1, 0);
737         if (obj) {
738                 /* directory is already splitted, so we have to forward
739                  * request to the right MDS */
740                 mds = raw_name2idx(obj->objcount, old, oldlen);
741                 data->fid1 = obj->objs[mds].fid;
742                 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
743                        (unsigned long) obj->objs[mds].fid.mds,
744                        (unsigned long) obj->objs[mds].fid.id,
745                        (unsigned long) obj->objs[mds].fid.generation);
746         }
747         lmv_put_obj(obj);
748
749         obj = lmv_grab_obj(obd, &data->fid2, 0);
750         if (obj) {
751                 /* directory is already splitted, so we have to forward
752                  * request to the right MDS */
753                 mds = raw_name2idx(obj->objcount, new, newlen);
754                 data->fid2 = obj->objs[mds].fid;
755                 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
756                        (unsigned long) obj->objs[mds].fid.mds,
757                        (unsigned long) obj->objs[mds].fid.id,
758                        (unsigned long) obj->objs[mds].fid.generation);
759         }
760         lmv_put_obj(obj);
761         
762         mds = data->fid1.mds;
763
764 request:
765         rc = md_rename(lmv->tgts[mds].exp, data, old, oldlen,
766                             new, newlen, request); 
767         RETURN(rc);
768 }
769
770 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
771                 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
772                 struct ptlrpc_request **request)
773 {
774         struct obd_device *obd = exp->exp_obd;
775         struct lmv_obd *lmv = &obd->u.lmv;
776         int rc = 0, i = data->fid1.mds;
777         struct ptlrpc_request *req;
778         struct mds_body *mds_body;
779         struct lmv_obj *obj;
780         ENTRY;
781         lmv_connect(obd);
782         obj = lmv_grab_obj(obd, &data->fid1, 0);
783         CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
784                (unsigned long) data->fid1.mds,
785                (unsigned long) data->fid1.id,
786                (unsigned long) data->fid1.generation, iattr->ia_valid,
787                obj ? ", splitted" : "");
788         if (obj) {
789                 for (i = 0; i < obj->objcount; i++) {
790                         data->fid1 = obj->objs[i].fid;
791                         rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea,
792                                         ealen, ea2, ea2len, &req);
793                         LASSERT(rc == 0);
794                         if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
795                                 /* this is master object and this request
796                                  * should be returned back to llite */
797                                 *request = req;
798                         } else {
799                                 ptlrpc_req_finished(req);
800                         }
801                 }
802                 lmv_put_obj(obj);
803         } else {
804                 LASSERT(data->fid1.mds < lmv->count);
805                 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea, ealen,
806                                 ea2, ea2len, request); 
807                 if (rc == 0) {
808                         mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
809                                         sizeof(*mds_body));
810                         LASSERT(mds_body != NULL);
811                         LASSERT(mds_body->mds == i);
812                 }
813         }
814         RETURN(rc);
815 }
816
817 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
818              struct ptlrpc_request **request)
819 {
820         struct obd_device *obd = exp->exp_obd;
821         struct lmv_obd *lmv = &obd->u.lmv;
822         int rc;
823         ENTRY;
824         lmv_connect(obd);
825         rc = md_sync(lmv->tgts[0].exp, fid, request); 
826         RETURN(rc);
827 }
828
829 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
830                             struct ldlm_lock_desc *desc, void *data, int flag)
831 {
832         struct lustre_handle lockh;
833         struct lmv_obj *obj;
834         int rc;
835         ENTRY;
836
837         switch (flag) {
838         case LDLM_CB_BLOCKING:
839                 ldlm_lock2handle(lock, &lockh);
840                 rc = ldlm_cli_cancel(&lockh);
841                 if (rc < 0) {
842                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
843                         RETURN(rc);
844                 }
845                 break;
846         case LDLM_CB_CANCELING:
847                 /* time to drop cached attrs for dirobj */
848                 obj = lock->l_ast_data;
849                 if (!obj)
850                         break;
851
852                 CDEBUG(D_OTHER, "cancel %s on %lu/%lu, master %lu/%lu/%lu\n",
853                        lock->l_resource->lr_name.name[3] == 1 ?
854                                 "LOOKUP" : "UPDATE",
855                        (unsigned long) lock->l_resource->lr_name.name[0],
856                        (unsigned long) lock->l_resource->lr_name.name[1],
857                        (unsigned long) obj->fid.mds,
858                        (unsigned long) obj->fid.id,
859                        (unsigned long) obj->fid.generation);
860                 break;
861         default:
862                 LBUG();
863         }
864         RETURN(0);
865 }
866
867 void lmv_remove_dots(struct page *page)
868 {
869         char *kaddr = page_address(page);
870         unsigned limit = PAGE_CACHE_SIZE;
871         unsigned offs, rec_len;
872         struct ext2_dir_entry_2 *p;
873
874         for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
875                 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
876                 rec_len = le16_to_cpu(p->rec_len);
877
878                 if ((p->name_len == 1 && p->name[0] == '.') ||
879                     (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
880                         p->inode = 0;
881         }
882 }
883
884 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
885                  __u64 offset, struct page *page,
886                  struct ptlrpc_request **request)
887 {
888         struct obd_device *obd = exp->exp_obd;
889         struct lmv_obd *lmv = &obd->u.lmv;
890         struct ll_fid rfid = *mdc_fid;
891         struct lmv_obj *obj;
892         int rc, i;
893         ENTRY;
894         lmv_connect(obd);
895        
896         LASSERT(mdc_fid->mds < lmv->count);
897         CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
898                offset, (unsigned long) rfid.mds,
899                (unsigned long) rfid.id,
900                (unsigned long) rfid.generation);
901
902         obj = lmv_grab_obj(obd, mdc_fid, 0);
903         if (obj) {
904                 /* find dirobj containing page with requested offset */
905                 /* FIXME: what about protecting cached attrs here? */
906                 for (i = 0; i < obj->objcount; i++) {
907                         if (offset < obj->objs[i].size)
908                                 break;
909                         offset -= obj->objs[i].size;
910                 }
911                 rfid = obj->objs[i].fid;
912                 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
913                        (unsigned long) rfid.mds,
914                        (unsigned long) rfid.id,
915                        (unsigned long) rfid.generation,
916                        (unsigned long) offset);
917         }
918         rc = md_readpage(lmv->tgts[rfid.mds].exp, &rfid, offset, page, request);
919         if (rc == 0 && !fid_equal(&rfid, mdc_fid)) {
920                 /* this page isn't from master object. to avoid
921                  * ./.. duplication in directory, we have to remove them
922                  * from all slave objects */
923                 lmv_remove_dots(page);
924         }
925       
926         lmv_put_obj(obj);
927
928         RETURN(rc);
929 }
930
931 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
932                struct ptlrpc_request **request)
933 {
934         struct obd_device *obd = exp->exp_obd;
935         struct lmv_obd *lmv = &obd->u.lmv;
936         int rc, i = 0;
937         ENTRY;
938         lmv_connect(obd);
939         if (data->namelen != 0) {
940                 struct lmv_obj *obj;
941                 obj = lmv_grab_obj(obd, &data->fid1, 0);
942                 if (obj) {
943                         i = raw_name2idx(obj->objcount, data->name,
944                                          data->namelen);
945                         data->fid1 = obj->objs[i].fid;
946                         lmv_put_obj(obj);
947                 }
948                 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
949                        data->namelen, data->name,
950                        (unsigned long) data->fid1.mds,
951                        (unsigned long) data->fid1.id,
952                        (unsigned long) data->fid1.generation, i);
953         } else {
954                 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
955                        (unsigned long) data->fid1.mds,
956                        (unsigned long) data->fid1.id,
957                        (unsigned long) data->fid1.generation);
958         }
959         rc = md_unlink(lmv->tgts[data->fid1.mds].exp, data, request); 
960         RETURN(rc);
961 }
962
963 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
964                                         char *name, int len)
965 {
966         struct obd_device *obd = exp->exp_obd;
967         struct lmv_obd *lmv = &obd->u.lmv;
968         ENTRY;
969         lmv_connect(obd);
970         obd = lmv->tgts[0].exp->exp_obd;
971         EXIT;
972         return obd;
973 }
974
975 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
976 {
977         struct obd_device *obd = exp->exp_obd;
978         struct lmv_obd *lmv = &obd->u.lmv;
979         int i, rc = 0, change = 0;
980         ENTRY;
981
982         if (lmv->max_easize < easize) {
983                 lmv->max_easize = easize;
984                 change = 1;
985         }
986         if (lmv->max_cookiesize < cookiesize) {
987                 lmv->max_cookiesize = cookiesize;
988                 change = 1;
989         }
990         if (change == 0)
991                 RETURN(0);
992         
993         if (lmv->connected == 0)
994                 RETURN(0);
995
996         /* FIXME: error handling? */
997         for (i = 0; i < lmv->count; i++)
998                 rc = obd_init_ea_size(lmv->tgts[i].exp, easize, cookiesize);
999         RETURN(rc);
1000 }
1001
1002 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
1003                           struct lov_stripe_md **ea, struct obd_trans_info *oti)
1004 {
1005         struct obd_device *obd = exp->exp_obd;
1006         struct lmv_obd *lmv = &obd->u.lmv;
1007         struct lov_stripe_md obj_md;
1008         struct lov_stripe_md *obj_mdp = &obj_md;
1009         int rc = 0;
1010         ENTRY;
1011         lmv_connect(obd);
1012
1013         LASSERT(ea == NULL);
1014         LASSERT(oa->o_mds < lmv->count);
1015
1016         rc = obd_create(lmv->tgts[oa->o_mds].exp, oa, &obj_mdp, oti);
1017         LASSERT(rc == 0);
1018
1019         RETURN(rc);
1020 }
1021
1022 /*
1023  * to be called from MDS only
1024  */
1025 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
1026                struct lov_stripe_md **ea, struct obd_trans_info *oti)
1027 {
1028         struct obd_device *obd = exp->exp_obd;
1029         struct lmv_obd *lmv = &obd->u.lmv;
1030         struct mea *mea;
1031         int i, c, rc = 0;
1032         struct ll_fid mfid;
1033         ENTRY;
1034         lmv_connect(obd);
1035
1036         LASSERT(oa != NULL);
1037         
1038         if (ea == NULL) {
1039                 rc = lmv_obd_create_single(exp, oa, NULL, oti);
1040                 RETURN(rc);
1041         }
1042
1043         if (*ea == NULL) {
1044                 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **) ea);
1045                 LASSERT(*ea != NULL);
1046         }
1047
1048         mea = (struct mea *) *ea;
1049         mfid.id = oa->o_id;
1050         mfid.generation = oa->o_generation;
1051         rc = 0;
1052         if (!mea->mea_count || mea->mea_count > lmv->count)
1053                 mea->mea_count = lmv->count;
1054
1055         mea->mea_master = -1;
1056         
1057         /* FIXME: error handling? */
1058         for (i = 0, c = 0; c < mea->mea_count && i < lmv->count; i++) {
1059                 struct lov_stripe_md obj_md;
1060                 struct lov_stripe_md *obj_mdp = &obj_md;
1061                
1062                 if (lmv->tgts[i].exp == NULL) {
1063                         /* this is master MDS */
1064                         mea->mea_fids[c].id = mfid.id;
1065                         mea->mea_fids[c].generation = mfid.generation;
1066                         mea->mea_fids[c].mds = i;
1067                         mea->mea_master = i;
1068                         c++;
1069                         continue;
1070                 }
1071
1072                 /* "Master" MDS should always be part of stripped dir, so
1073                    scan for it */
1074                 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1075                         continue;
1076
1077                 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1078                                 | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1079
1080                 rc = obd_create(lmv->tgts[c].exp, oa, &obj_mdp, oti);
1081                 /* FIXME: error handling here */
1082                 LASSERT(rc == 0);
1083
1084                 mea->mea_fids[c].id = oa->o_id;
1085                 mea->mea_fids[c].generation = oa->o_generation;
1086                 mea->mea_fids[c].mds = i;
1087                 c++;
1088                 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1089                        i, oa->o_id, oa->o_generation);
1090         }
1091         LASSERT(c == mea->mea_count);
1092         CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1093
1094         RETURN(rc);
1095 }
1096
1097 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1098                            void *key, __u32 *vallen, void *val)
1099 {
1100         struct obd_device *obd;
1101         struct lmv_obd *lmv;
1102         ENTRY;
1103
1104         obd = class_exp2obd(exp);
1105         if (obd == NULL) {
1106                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1107                        exp->exp_handle.h_cookie);
1108                 RETURN(-EINVAL);
1109         }
1110
1111         lmv = &obd->u.lmv;
1112         if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1113                 __u32 *mdsize = val;
1114                 *vallen = sizeof(__u32);
1115                 *mdsize = sizeof(struct ll_fid) * lmv->count
1116                                 + sizeof(struct mea);
1117                 RETURN(0);
1118         } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1119                 struct obd_uuid *cluuid = &lmv->cluuid;
1120                 struct lmv_tgt_desc *tgts;
1121                 __u32 *mdsnum = val;
1122                 int i;
1123
1124                 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1125                         if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1126                                 *vallen = sizeof(__u32);
1127                                 *mdsnum = i;
1128                                 RETURN(0);
1129                         }
1130                 }
1131                 LASSERT(0);
1132         }
1133
1134         CDEBUG(D_IOCTL, "invalid key\n");
1135         RETURN(-EINVAL);
1136 }
1137
1138 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1139                  void *key, obd_count vallen, void *val)
1140 {
1141         struct obd_device *obd;
1142         struct lmv_obd *lmv;
1143         ENTRY;
1144
1145         obd = class_exp2obd(exp);
1146         if (obd == NULL) {
1147                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1148                        exp->exp_handle.h_cookie);
1149                 RETURN(-EINVAL);
1150         }
1151         lmv = &obd->u.lmv;
1152
1153         if (keylen >= strlen("client") && strcmp(key, "client") == 0) {
1154                 struct lmv_tgt_desc *tgts;
1155                 int i, rc;
1156
1157                 lmv_connect(obd);
1158                 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1159                         rc = obd_set_info(tgts->exp, keylen, key, vallen, val);
1160                         if (rc)
1161                                 RETURN(rc);
1162                 }
1163                 RETURN(0);
1164         } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1165                 lmv->server_timeout = 1;
1166                 lmv_set_timeouts(obd);
1167                 RETURN(0);
1168         }
1169         
1170         RETURN(-EINVAL);
1171 }
1172
1173 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1174                struct lov_stripe_md *lsm)
1175 {
1176         struct obd_device *obd = class_exp2obd(exp);
1177         struct lmv_obd *lmv = &obd->u.lmv;
1178         int mea_size;
1179         ENTRY;
1180
1181         mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1182         if (!lmmp)
1183                 RETURN(mea_size);
1184
1185         if (*lmmp && !lsm) {
1186                 OBD_FREE(*lmmp, mea_size);
1187                 *lmmp = NULL;
1188                 RETURN(0);
1189         }
1190
1191         if (!*lmmp) {
1192                 OBD_ALLOC(*lmmp, mea_size);
1193                 if (!*lmmp)
1194                         RETURN(-ENOMEM);
1195         }
1196
1197         if (!lsm)
1198                 RETURN(mea_size);
1199
1200 #warning "MEA packing/convertation must be here! -bzzz"
1201         memcpy(*lmmp, lsm, mea_size);
1202         RETURN(mea_size);
1203 }
1204
1205 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1206                         struct lov_mds_md *disk_src, int mdsize)
1207 {
1208         struct obd_device *obd = class_exp2obd(exp);
1209         struct lmv_obd *lmv = &obd->u.lmv;
1210         struct mea **tmea = (struct mea **) mem_tgt;
1211         struct mea *mea = (void *) disk_src;
1212         int mea_size;
1213         ENTRY;
1214
1215         mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1216         if (mem_tgt == NULL)
1217                 return mea_size;
1218
1219         if (*mem_tgt != NULL && disk_src == NULL) {
1220                 OBD_FREE(*tmea, mea_size);
1221                 RETURN(0);
1222         }
1223
1224         LASSERT(mea_size == mdsize);
1225
1226         OBD_ALLOC(*tmea, mea_size);
1227         /* FIXME: error handling here */
1228         LASSERT(*tmea != NULL);
1229
1230         if (!disk_src)
1231                 RETURN(mea_size);
1232
1233 #warning "MEA unpacking/convertation must be here! -bzzz"
1234         memcpy(*tmea, mea, mdsize);
1235         RETURN(mea_size);
1236 }
1237
1238 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1239                 struct lov_stripe_md *ea, obd_count oa_bufs,
1240                 struct brw_page *pgarr, struct obd_trans_info *oti)
1241 {
1242         struct obd_device *obd = exp->exp_obd;
1243         struct lmv_obd *lmv = &obd->u.lmv;
1244         struct mea *mea = (struct mea *) ea;
1245         int err;
1246       
1247         LASSERT(oa != NULL);
1248         LASSERT(ea != NULL);
1249         LASSERT(pgarr != NULL);
1250         LASSERT(oa->o_mds < lmv->count);
1251
1252         oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1253         oa->o_id = mea->mea_fids[oa->o_mds].id;
1254         oa->o_valid =  OBD_MD_FLID | OBD_MD_FLGROUP;
1255         err = obd_brw(rw, lmv->tgts[oa->o_mds].exp, oa,
1256                         NULL, oa_bufs, pgarr, oti);
1257         RETURN(err);
1258 }
1259
1260 struct obd_ops lmv_obd_ops = {
1261         o_owner:                THIS_MODULE,
1262         o_attach:               lmv_attach,
1263         o_detach:               lmv_detach,
1264         o_setup:                lmv_setup,
1265         o_cleanup:              lmv_cleanup,
1266         o_connect:              lmv_connect_fake,
1267         o_disconnect:           lmv_disconnect,
1268         o_statfs:               lmv_statfs,
1269         o_get_info:             lmv_get_info,
1270         o_set_info:             lmv_set_info,
1271         o_create:               lmv_obd_create,
1272         o_packmd:               lmv_packmd,
1273         o_unpackmd:             lmv_unpackmd,
1274         o_brw:                  lmv_brw,
1275         o_init_ea_size:         lmv_init_ea_size,
1276 };
1277
1278 struct md_ops lmv_md_ops = {
1279         m_getstatus:            lmv_getstatus,
1280         m_getattr:              lmv_getattr,
1281         m_change_cbdata:        lmv_change_cbdata,
1282         m_change_cbdata_name:   lmv_change_cbdata_name,
1283         m_close:                lmv_close,
1284         m_create:               lmv_create,
1285         m_done_writing:         lmv_done_writing,
1286         m_enqueue:              lmv_enqueue,
1287         m_getattr_name:         lmv_getattr_name,
1288         m_intent_lock:          lmv_intent_lock,
1289         m_link:                 lmv_link,
1290         m_rename:               lmv_rename,
1291         m_setattr:              lmv_setattr,
1292         m_sync:                 lmv_sync,
1293         m_readpage:             lmv_readpage,
1294         m_unlink:               lmv_unlink,
1295         m_get_real_obd:         lmv_get_real_obd,
1296         m_valid_attrs:          lmv_valid_attrs,
1297 };
1298
1299 //#ifndef LPROCFS
1300 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
1301 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
1302 //#else
1303 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)
1304
1305 int __init lmv_init(void)
1306 {
1307         struct lprocfs_static_vars lvars;
1308         int rc;
1309
1310         lprocfs_init_vars(lmv, &lvars);
1311         rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1312                                  lvars.module_vars, OBD_LMV_DEVICENAME);
1313         RETURN(rc);
1314 }
1315
1316 static void lmv_exit(void)
1317 {
1318         class_unregister_type(OBD_LMV_DEVICENAME);
1319 }
1320
1321 #ifdef __KERNEL__
1322 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1323 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1324 MODULE_LICENSE("GPL");
1325
1326 module_init(lmv_init);
1327 module_exit(lmv_exit);
1328 #endif
1329