Whamcloud - gitweb
7ab2c430d411b4702bca6e791bbfe8c4cd719b74
[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 lmv_obj *obj;
590         ENTRY;
591         lmv_connect(obd);
592         CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu\n",
593                namelen, filename, (unsigned long) fid->mds,
594                (unsigned long) fid->id, (unsigned long) fid->generation);
595         obj = lmv_grab_obj(obd, fid, 0);
596         if (obj) {
597                 /* directory is splitted. look for right mds for this name */
598                 mds = raw_name2idx(obj->objcount, filename, namelen);
599                 rfid = obj->objs[mds].fid;
600                 lmv_put_obj(obj);
601         }
602         rc = md_getattr_name(lmv->tgts[mds].exp, &rfid, filename, namelen,
603                                   valid, ea_size, request);
604         RETURN(rc);
605 }
606
607
608 /*
609  * llite passes fid of an target inode in data->fid1 and
610  * fid of directory in data->fid2
611  */
612 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
613              struct ptlrpc_request **request)
614 {
615         struct obd_device *obd = exp->exp_obd;
616         struct lmv_obd *lmv = &obd->u.lmv;
617         struct lmv_obj *obj;
618         int rc;
619         ENTRY;
620         lmv_connect(obd);
621         if (data->namelen != 0) {
622                 /* usual link request */
623                 obj = lmv_grab_obj(obd, &data->fid1, 0);
624                 if (obj) {
625                         rc = raw_name2idx(obj->objcount, data->name,
626                                          data->namelen);
627                         data->fid1 = obj->objs[rc].fid;
628                         lmv_put_obj(obj);
629                 }
630                 CDEBUG(D_OTHER,"link %u/%u/%u:%*s to %u/%u/%u mds %d\n",
631                        (unsigned) data->fid2.mds, (unsigned) data->fid2.id,
632                        (unsigned) data->fid2.generation, data->namelen,
633                        data->name, (unsigned) data->fid1.mds,
634                        (unsigned) data->fid1.id,
635                        (unsigned) data->fid1.generation, data->fid1.mds);
636         } else {
637                 /* request from MDS to acquire i_links for inode by fid1 */
638                 CDEBUG(D_OTHER, "inc i_nlinks for %u/%u/%u\n",
639                        (unsigned) data->fid1.mds, (unsigned) data->fid1.id,
640                        (unsigned) data->fid1.generation);
641         }
642                         
643         rc = md_link(lmv->tgts[data->fid1.mds].exp, data, request);
644         RETURN(rc);
645 }
646
647 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
648                const char *old, int oldlen, const char *new, int newlen,
649                struct ptlrpc_request **request)
650 {
651         struct obd_device *obd = exp->exp_obd;
652         struct lmv_obd *lmv = &obd->u.lmv;
653         struct lmv_obj *obj;
654         int rc, mds;
655         ENTRY;
656
657         CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
658                oldlen, old, (unsigned long) data->fid1.mds,
659                (unsigned long) data->fid1.id,
660                (unsigned long) data->fid1.generation,
661                newlen, new, (unsigned long) data->fid2.mds,
662                (unsigned long) data->fid2.id,
663                (unsigned long) data->fid2.generation);
664
665         lmv_connect(obd);
666
667         if (oldlen == 0) {
668                 /* MDS with old dir entry is asking another MDS
669                  * to create name there */
670                 CDEBUG(D_OTHER,
671                        "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
672                        newlen, new, oldlen, newlen,
673                        (unsigned long) data->fid2.mds,
674                        (unsigned long) data->fid2.id,
675                        (unsigned long) data->fid2.generation,
676                        (unsigned long) data->fid1.mds,
677                        (unsigned long) data->fid1.id,
678                        (unsigned long) data->fid1.generation);
679                 mds = data->fid2.mds;
680                 goto request;
681         }
682
683         obj = lmv_grab_obj(obd, &data->fid1, 0);
684         if (obj) {
685                 /* directory is already splitted, so we have to forward
686                  * request to the right MDS */
687                 mds = raw_name2idx(obj->objcount, old, oldlen);
688                 data->fid1 = obj->objs[mds].fid;
689                 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
690                        (unsigned long) obj->objs[mds].fid.mds,
691                        (unsigned long) obj->objs[mds].fid.id,
692                        (unsigned long) obj->objs[mds].fid.generation);
693         }
694         lmv_put_obj(obj);
695
696         obj = lmv_grab_obj(obd, &data->fid2, 0);
697         if (obj) {
698                 /* directory is already splitted, so we have to forward
699                  * request to the right MDS */
700                 mds = raw_name2idx(obj->objcount, new, newlen);
701                 data->fid2 = obj->objs[mds].fid;
702                 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
703                        (unsigned long) obj->objs[mds].fid.mds,
704                        (unsigned long) obj->objs[mds].fid.id,
705                        (unsigned long) obj->objs[mds].fid.generation);
706         }
707         lmv_put_obj(obj);
708         
709         mds = data->fid1.mds;
710
711 request:
712         rc = md_rename(lmv->tgts[mds].exp, data, old, oldlen,
713                             new, newlen, request); 
714         RETURN(rc);
715 }
716
717 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
718                 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
719                 struct ptlrpc_request **request)
720 {
721         struct obd_device *obd = exp->exp_obd;
722         struct lmv_obd *lmv = &obd->u.lmv;
723         int rc = 0, i = data->fid1.mds;
724         struct ptlrpc_request *req;
725         struct mds_body *mds_body;
726         struct lmv_obj *obj;
727         ENTRY;
728         lmv_connect(obd);
729         obj = lmv_grab_obj(obd, &data->fid1, 0);
730         CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
731                (unsigned long) data->fid1.mds,
732                (unsigned long) data->fid1.id,
733                (unsigned long) data->fid1.generation, iattr->ia_valid,
734                obj ? ", splitted" : "");
735         if (obj) {
736                 for (i = 0; i < obj->objcount; i++) {
737                         data->fid1 = obj->objs[i].fid;
738                         rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea,
739                                         ealen, ea2, ea2len, &req);
740                         LASSERT(rc == 0);
741                         if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
742                                 /* this is master object and this request
743                                  * should be returned back to llite */
744                                 *request = req;
745                         } else {
746                                 ptlrpc_req_finished(req);
747                         }
748                 }
749                 lmv_put_obj(obj);
750         } else {
751                 LASSERT(data->fid1.mds < lmv->count);
752                 rc = md_setattr(lmv->tgts[i].exp, data, iattr, ea, ealen,
753                                 ea2, ea2len, request); 
754                 if (rc == 0) {
755                         mds_body = lustre_msg_buf((*request)->rq_repmsg, 0,
756                                         sizeof(*mds_body));
757                         LASSERT(mds_body != NULL);
758                         LASSERT(mds_body->mds == i);
759                 }
760         }
761         RETURN(rc);
762 }
763
764 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
765              struct ptlrpc_request **request)
766 {
767         struct obd_device *obd = exp->exp_obd;
768         struct lmv_obd *lmv = &obd->u.lmv;
769         int rc;
770         ENTRY;
771         lmv_connect(obd);
772         rc = md_sync(lmv->tgts[0].exp, fid, request); 
773         RETURN(rc);
774 }
775
776 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
777                             struct ldlm_lock_desc *desc, void *data, int flag)
778 {
779         struct lustre_handle lockh;
780         struct lmv_obj *obj;
781         int rc;
782         ENTRY;
783
784         switch (flag) {
785         case LDLM_CB_BLOCKING:
786                 ldlm_lock2handle(lock, &lockh);
787                 rc = ldlm_cli_cancel(&lockh);
788                 if (rc < 0) {
789                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
790                         RETURN(rc);
791                 }
792                 break;
793         case LDLM_CB_CANCELING:
794                 /* time to drop cached attrs for dirobj */
795                 obj = lock->l_ast_data;
796                 if (!obj)
797                         break;
798
799                 CDEBUG(D_OTHER, "cancel %s on %lu/%lu, master %lu/%lu/%lu\n",
800                        lock->l_resource->lr_name.name[3] == 1 ?
801                                 "LOOKUP" : "UPDATE",
802                        (unsigned long) lock->l_resource->lr_name.name[0],
803                        (unsigned long) lock->l_resource->lr_name.name[1],
804                        (unsigned long) obj->fid.mds,
805                        (unsigned long) obj->fid.id,
806                        (unsigned long) obj->fid.generation);
807                 break;
808         default:
809                 LBUG();
810         }
811         RETURN(0);
812 }
813
814 void lmv_remove_dots(struct page *page)
815 {
816         char *kaddr = page_address(page);
817         unsigned limit = PAGE_CACHE_SIZE;
818         unsigned offs, rec_len;
819         struct ext2_dir_entry_2 *p;
820
821         for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
822                 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
823                 rec_len = le16_to_cpu(p->rec_len);
824
825                 if ((p->name_len == 1 && p->name[0] == '.') ||
826                     (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
827                         p->inode = 0;
828         }
829 }
830
831 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
832                  __u64 offset, struct page *page,
833                  struct ptlrpc_request **request)
834 {
835         struct obd_device *obd = exp->exp_obd;
836         struct lmv_obd *lmv = &obd->u.lmv;
837         struct ll_fid rfid = *mdc_fid;
838         struct lmv_obj *obj;
839         int rc, i;
840         ENTRY;
841         lmv_connect(obd);
842        
843         LASSERT(mdc_fid->mds < lmv->count);
844         CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
845                offset, (unsigned long) rfid.mds,
846                (unsigned long) rfid.id,
847                (unsigned long) rfid.generation);
848
849         obj = lmv_grab_obj(obd, mdc_fid, 0);
850         if (obj) {
851                 /* find dirobj containing page with requested offset */
852                 /* FIXME: what about protecting cached attrs here? */
853                 for (i = 0; i < obj->objcount; i++) {
854                         if (offset < obj->objs[i].size)
855                                 break;
856                         offset -= obj->objs[i].size;
857                 }
858                 rfid = obj->objs[i].fid;
859                 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
860                        (unsigned long) rfid.mds,
861                        (unsigned long) rfid.id,
862                        (unsigned long) rfid.generation,
863                        (unsigned long) offset);
864         }
865         rc = md_readpage(lmv->tgts[rfid.mds].exp, &rfid, offset, page, request);
866         if (rc == 0 && !fid_equal(&rfid, mdc_fid)) {
867                 /* this page isn't from master object. to avoid
868                  * ./.. duplication in directory, we have to remove them
869                  * from all slave objects */
870                 lmv_remove_dots(page);
871         }
872       
873         lmv_put_obj(obj);
874
875         RETURN(rc);
876 }
877
878 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
879                struct ptlrpc_request **request)
880 {
881         struct obd_device *obd = exp->exp_obd;
882         struct lmv_obd *lmv = &obd->u.lmv;
883         int rc, i = 0;
884         ENTRY;
885         lmv_connect(obd);
886         if (data->namelen != 0) {
887                 struct lmv_obj *obj;
888                 obj = lmv_grab_obj(obd, &data->fid1, 0);
889                 if (obj) {
890                         i = raw_name2idx(obj->objcount, data->name,
891                                          data->namelen);
892                         data->fid1 = obj->objs[i].fid;
893                         lmv_put_obj(obj);
894                 }
895                 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
896                        data->namelen, data->name,
897                        (unsigned long) data->fid1.mds,
898                        (unsigned long) data->fid1.id,
899                        (unsigned long) data->fid1.generation, i);
900         } else {
901                 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
902                        (unsigned long) data->fid1.mds,
903                        (unsigned long) data->fid1.id,
904                        (unsigned long) data->fid1.generation);
905         }
906         rc = md_unlink(lmv->tgts[data->fid1.mds].exp, data, request); 
907         RETURN(rc);
908 }
909
910 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
911                                         char *name, int len)
912 {
913         struct obd_device *obd = exp->exp_obd;
914         struct lmv_obd *lmv = &obd->u.lmv;
915         ENTRY;
916         lmv_connect(obd);
917         obd = lmv->tgts[0].exp->exp_obd;
918         EXIT;
919         return obd;
920 }
921
922 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
923 {
924         struct obd_device *obd = exp->exp_obd;
925         struct lmv_obd *lmv = &obd->u.lmv;
926         int i, rc = 0, change = 0;
927         ENTRY;
928
929         if (lmv->max_easize < easize) {
930                 lmv->max_easize = easize;
931                 change = 1;
932         }
933         if (lmv->max_cookiesize < cookiesize) {
934                 lmv->max_cookiesize = cookiesize;
935                 change = 1;
936         }
937         if (change == 0)
938                 RETURN(0);
939         
940         if (lmv->connected == 0)
941                 RETURN(0);
942
943         /* FIXME: error handling? */
944         for (i = 0; i < lmv->count; i++)
945                 rc = obd_init_ea_size(lmv->tgts[i].exp, easize, cookiesize);
946         RETURN(rc);
947 }
948
949 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
950                           struct lov_stripe_md **ea, struct obd_trans_info *oti)
951 {
952         struct obd_device *obd = exp->exp_obd;
953         struct lmv_obd *lmv = &obd->u.lmv;
954         struct lov_stripe_md obj_md;
955         struct lov_stripe_md *obj_mdp = &obj_md;
956         int rc = 0;
957         ENTRY;
958         lmv_connect(obd);
959
960         LASSERT(ea == NULL);
961         LASSERT(oa->o_mds < lmv->count);
962
963         rc = obd_create(lmv->tgts[oa->o_mds].exp, oa, &obj_mdp, oti);
964         LASSERT(rc == 0);
965
966         RETURN(rc);
967 }
968
969 /*
970  * to be called from MDS only
971  */
972 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
973                struct lov_stripe_md **ea, struct obd_trans_info *oti)
974 {
975         struct obd_device *obd = exp->exp_obd;
976         struct lmv_obd *lmv = &obd->u.lmv;
977         struct mea *mea;
978         int i, c, rc = 0;
979         struct ll_fid mfid;
980         ENTRY;
981         lmv_connect(obd);
982
983         LASSERT(oa != NULL);
984         
985         if (ea == NULL) {
986                 rc = lmv_obd_create_single(exp, oa, NULL, oti);
987                 RETURN(rc);
988         }
989
990         if (*ea == NULL) {
991                 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **) ea);
992                 LASSERT(*ea != NULL);
993         }
994
995         mea = (struct mea *) *ea;
996         mfid.id = oa->o_id;
997         mfid.generation = oa->o_generation;
998         rc = 0;
999         if (!mea->mea_count || mea->mea_count > lmv->count)
1000                 mea->mea_count = lmv->count;
1001
1002         mea->mea_master = -1;
1003         
1004         /* FIXME: error handling? */
1005         for (i = 0, c = 0; c < mea->mea_count && i < lmv->count; i++) {
1006                 struct lov_stripe_md obj_md;
1007                 struct lov_stripe_md *obj_mdp = &obj_md;
1008                
1009                 if (lmv->tgts[i].exp == NULL) {
1010                         /* this is master MDS */
1011                         mea->mea_fids[c].id = mfid.id;
1012                         mea->mea_fids[c].generation = mfid.generation;
1013                         mea->mea_fids[c].mds = i;
1014                         mea->mea_master = i;
1015                         c++;
1016                         continue;
1017                 }
1018
1019                 /* "Master" MDS should always be part of stripped dir, so
1020                    scan for it */
1021                 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1022                         continue;
1023
1024                 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1025                                 | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1026
1027                 rc = obd_create(lmv->tgts[c].exp, oa, &obj_mdp, oti);
1028                 /* FIXME: error handling here */
1029                 LASSERT(rc == 0);
1030
1031                 mea->mea_fids[c].id = oa->o_id;
1032                 mea->mea_fids[c].generation = oa->o_generation;
1033                 mea->mea_fids[c].mds = i;
1034                 c++;
1035                 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1036                        i, oa->o_id, oa->o_generation);
1037         }
1038         LASSERT(c == mea->mea_count);
1039         CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1040
1041         RETURN(rc);
1042 }
1043
1044 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1045                            void *key, __u32 *vallen, void *val)
1046 {
1047         struct obd_device *obd;
1048         struct lmv_obd *lmv;
1049         ENTRY;
1050
1051         obd = class_exp2obd(exp);
1052         if (obd == NULL) {
1053                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1054                        exp->exp_handle.h_cookie);
1055                 RETURN(-EINVAL);
1056         }
1057
1058         lmv = &obd->u.lmv;
1059         if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1060                 __u32 *mdsize = val;
1061                 *vallen = sizeof(__u32);
1062                 *mdsize = sizeof(struct ll_fid) * lmv->count
1063                                 + sizeof(struct mea);
1064                 RETURN(0);
1065         } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1066                 struct obd_uuid *cluuid = &lmv->cluuid;
1067                 struct lmv_tgt_desc *tgts;
1068                 __u32 *mdsnum = val;
1069                 int i;
1070
1071                 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1072                         if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1073                                 *vallen = sizeof(__u32);
1074                                 *mdsnum = i;
1075                                 RETURN(0);
1076                         }
1077                 }
1078                 LASSERT(0);
1079         }
1080
1081         CDEBUG(D_IOCTL, "invalid key\n");
1082         RETURN(-EINVAL);
1083 }
1084
1085 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1086                  void *key, obd_count vallen, void *val)
1087 {
1088         struct obd_device *obd;
1089         struct lmv_obd *lmv;
1090         ENTRY;
1091
1092         obd = class_exp2obd(exp);
1093         if (obd == NULL) {
1094                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1095                        exp->exp_handle.h_cookie);
1096                 RETURN(-EINVAL);
1097         }
1098         lmv = &obd->u.lmv;
1099         lmv_connect(obd);
1100
1101         if (keylen >= strlen("client") && strcmp(key, "client") == 0) {
1102                 struct lmv_tgt_desc *tgts;
1103                 int i, rc;
1104
1105                 for (i = 0, tgts = lmv->tgts; i < lmv->count; i++, tgts++) {
1106                         rc = obd_set_info(tgts->exp, keylen, key, vallen, val);
1107                         if (rc)
1108                                 RETURN(rc);
1109                 }
1110                 RETURN(0);
1111         }
1112         
1113         RETURN(-EINVAL);
1114 }
1115
1116 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1117                struct lov_stripe_md *lsm)
1118 {
1119         struct obd_device *obd = class_exp2obd(exp);
1120         struct lmv_obd *lmv = &obd->u.lmv;
1121         int mea_size;
1122         ENTRY;
1123
1124         mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1125         if (!lmmp)
1126                 RETURN(mea_size);
1127
1128         if (*lmmp && !lsm) {
1129                 OBD_FREE(*lmmp, mea_size);
1130                 *lmmp = NULL;
1131                 RETURN(0);
1132         }
1133
1134         if (!*lmmp) {
1135                 OBD_ALLOC(*lmmp, mea_size);
1136                 if (!*lmmp)
1137                         RETURN(-ENOMEM);
1138         }
1139
1140         if (!lsm)
1141                 RETURN(mea_size);
1142
1143 #warning "MEA packing/convertation must be here! -bzzz"
1144         memcpy(*lmmp, lsm, mea_size);
1145         RETURN(mea_size);
1146 }
1147
1148 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1149                         struct lov_mds_md *disk_src, int mdsize)
1150 {
1151         struct obd_device *obd = class_exp2obd(exp);
1152         struct lmv_obd *lmv = &obd->u.lmv;
1153         struct mea **tmea = (struct mea **) mem_tgt;
1154         struct mea *mea = (void *) disk_src;
1155         int mea_size;
1156         ENTRY;
1157
1158         mea_size = sizeof(struct ll_fid) * lmv->count + sizeof(struct mea);
1159         if (mem_tgt == NULL)
1160                 return mea_size;
1161
1162         if (*mem_tgt != NULL && disk_src == NULL) {
1163                 OBD_FREE(*tmea, mea_size);
1164                 RETURN(0);
1165         }
1166
1167         LASSERT(mea_size == mdsize);
1168
1169         OBD_ALLOC(*tmea, mea_size);
1170         /* FIXME: error handling here */
1171         LASSERT(*tmea != NULL);
1172
1173         if (!disk_src)
1174                 RETURN(mea_size);
1175
1176 #warning "MEA unpacking/convertation must be here! -bzzz"
1177         memcpy(*tmea, mea, mdsize);
1178         RETURN(mea_size);
1179 }
1180
1181 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1182                 struct lov_stripe_md *ea, obd_count oa_bufs,
1183                 struct brw_page *pgarr, struct obd_trans_info *oti)
1184 {
1185         struct obd_device *obd = exp->exp_obd;
1186         struct lmv_obd *lmv = &obd->u.lmv;
1187         struct mea *mea = (struct mea *) ea;
1188         int err;
1189       
1190         LASSERT(oa != NULL);
1191         LASSERT(ea != NULL);
1192         LASSERT(pgarr != NULL);
1193         LASSERT(oa->o_mds < lmv->count);
1194
1195         oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1196         oa->o_id = mea->mea_fids[oa->o_mds].id;
1197         oa->o_valid =  OBD_MD_FLID | OBD_MD_FLGROUP;
1198         err = obd_brw(rw, lmv->tgts[oa->o_mds].exp, oa,
1199                         NULL, oa_bufs, pgarr, oti);
1200         RETURN(err);
1201 }
1202
1203 struct obd_ops lmv_obd_ops = {
1204         o_owner:                THIS_MODULE,
1205         o_attach:               lmv_attach,
1206         o_detach:               lmv_detach,
1207         o_setup:                lmv_setup,
1208         o_cleanup:              lmv_cleanup,
1209         o_connect:              lmv_connect_fake,
1210         o_disconnect:           lmv_disconnect,
1211         o_statfs:               lmv_statfs,
1212         o_get_info:             lmv_get_info,
1213         o_set_info:             lmv_set_info,
1214         o_create:               lmv_obd_create,
1215         o_packmd:               lmv_packmd,
1216         o_unpackmd:             lmv_unpackmd,
1217         o_brw:                  lmv_brw,
1218         o_init_ea_size:         lmv_init_ea_size,
1219 };
1220
1221 struct md_ops lmv_md_ops = {
1222         m_getstatus:            lmv_getstatus,
1223         m_getattr:              lmv_getattr,
1224         m_change_cbdata:        lmv_change_cbdata,
1225         m_change_cbdata_name:   lmv_change_cbdata_name,
1226         m_close:                lmv_close,
1227         m_create:               lmv_create,
1228         m_done_writing:         lmv_done_writing,
1229         m_enqueue:              lmv_enqueue,
1230         m_getattr_name:         lmv_getattr_name,
1231         m_intent_lock:          lmv_intent_lock,
1232         m_link:                 lmv_link,
1233         m_rename:               lmv_rename,
1234         m_setattr:              lmv_setattr,
1235         m_sync:                 lmv_sync,
1236         m_readpage:             lmv_readpage,
1237         m_unlink:               lmv_unlink,
1238         m_get_real_obd:         lmv_get_real_obd,
1239         m_valid_attrs:          lmv_valid_attrs,
1240 };
1241
1242 //#ifndef LPROCFS
1243 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
1244 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
1245 //#else
1246 LPROCFS_INIT_VARS(lmv, lprocfs_module_vars, lprocfs_obd_vars)
1247
1248 int __init lmv_init(void)
1249 {
1250         struct lprocfs_static_vars lvars;
1251         int rc;
1252
1253         lprocfs_init_vars(lmv, &lvars);
1254         rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1255                                  lvars.module_vars, OBD_LMV_DEVICENAME);
1256         RETURN(rc);
1257 }
1258
1259 static void lmv_exit(void)
1260 {
1261         class_unregister_type(OBD_LMV_DEVICENAME);
1262 }
1263
1264 #ifdef __KERNEL__
1265 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1266 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1267 MODULE_LICENSE("GPL");
1268
1269 module_init(lmv_init);
1270 module_exit(lmv_exit);
1271 #endif
1272