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