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